Bug 249469 - [Linuxulator] linux_sched_setscheduler fails: Operation not permitted
Summary: [Linuxulator] linux_sched_setscheduler fails: Operation not permitted
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 12.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Olivier Certner
URL:
Keywords:
Depends on:
Blocks: 247219
  Show dependency treegraph
 
Reported: 2020-09-19 23:41 UTC by Yuri Victorovich
Modified: 2023-12-29 22:25 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2020-09-19 23:41:17 UTC
It looks like some pthread* functions call sched_setscheduler() that fails:
>  13331 zoom     CALL  linux_sched_setscheduler(0x1917f,0x2,0x7fffffffbc60)
>  13331 zoom     RET   linux_sched_setscheduler -1 errno -1 Operation not permitted

Unfortunately ktrace doesn't show more detailed information about the arguments.

12.2-STABLE r365688
Comment 1 Alex S 2021-02-01 19:24:21 UTC
Also affects Beyond Compare: https://forums.freebsd.org/threads/a-linux-program-fails-to-create-thread-without-root-permissions.76332/.

I see a few warnings from Steam as well (they are harmless, though):

  Warning: failed to init scheduler: failed to get rlimit
  Warning: failed to set thread priority: per-thread setup failed
  Warning: failed to set thread priority: set failed for priority 4
  Warning: support for elevated priorities is most likely unavailable, suppressing future warnings
Comment 2 Edward Tomasz Napierala freebsd_committer freebsd_triage 2021-02-03 19:59:03 UTC
Is there a relatively small application that can be used to reproduce this?

Also: ktrace and truss can't decode Linux-specific parameters, but Linux strace can, and this might also work with sched_setscheduler.  Could you perhaps try that?
Comment 3 Alex S 2021-02-04 04:13:41 UTC
(In reply to Edward Tomasz Napierala from comment #2)

% cat sched.c 
#define _GNU_SOURCE

#include <assert.h>
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>

void* thread_start(void* arg) {
  return 0;
}

int main() {

  {
    pthread_attr_t attr;
    assert(pthread_attr_init(&attr) == 0);
    assert(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0);

    pthread_t t;
    int err = pthread_create(&t, &attr, &thread_start, NULL);
    if (err != 0) {
      fprintf(stderr, "pthread_create: %s\n", strerror(err));
    }

    pthread_attr_destroy(&attr);
  }

  {
    struct sched_param p;
    p.sched_priority = 0;
    if (sched_setscheduler(0, SCHED_RESET_ON_FORK, &p) == -1) {
      perror("sched_setscheduler");
    }
  }

  {
    struct rlimit rl;
    int err = getrlimit(RLIMIT_RTTIME, &rl);
    if (err == -1) {
      perror("rlimit");
    }
  }

  return 0;
}
% /compat/linux/bin/gcc sched.c -pthread -o sched
% ./sched 
pthread_create: Operation not permitted
sched_setscheduler: Invalid argument
rlimit: Invalid argument
Comment 4 Alex S 2021-02-07 00:47:51 UTC
(In reply to Alex S from comment #3)

Ah, so RLIMIT_RTTIME is actually fixed in 13: https://cgit.freebsd.org/src/commit/?id=139c09788bab89163a0378b753bc02f744b7ae10. Don't mind it then :)
Comment 5 Dmitry Chagin freebsd_committer freebsd_triage 2023-11-06 18:46:07 UTC
(In reply to Alex S from comment #4)
So, should it be closed?
Comment 6 Alex S 2023-11-06 19:58:02 UTC
(In reply to Dmitry Chagin from comment #5)

> So, should it be closed?

My comment definitely doesn't imply that.
Comment 7 Yuri Victorovich freebsd_committer freebsd_triage 2023-11-06 20:18:11 UTC
My bad.
Comment 8 Mark Linimon freebsd_committer freebsd_triage 2023-12-26 05:01:52 UTC
^Triage: canonicalize assignment.
Comment 9 Olivier Certner freebsd_committer freebsd_triage 2023-12-29 22:25:13 UTC
Hi,

Working on a revamp of priorities, including the Linuxulator part.  The problem you're encountering is probably fixed in the new code I have, but I've yet to actually test.

Taking the bug, and will give news during January.

Thanks.