From nobody Mon Oct 05 23:22:09 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hzFlm1mg8z6vb4k; Mon, 05 Oct 2026 23:22:12 +0000 (UTC) (envelope-from markj@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hzFlm1K1qz3PHh; Mon, 05 Oct 2026 23:22:12 +0000 (UTC) (envelope-from markj@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791242532; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GUX18+8b60HabjAyMAfXvmqNLCoikbArQyU9fcOv1t0=; b=jpSFKuswaMw/MUcl63rfD3XsnWBiJ0YLRQLmNfoKNHYwFGuaKOSaYY3vqzW48l/ubP+maa mtRB01UgYoRXojtAI1G4Bfn5NNCOh/SeVwBzaygUAHf4bRG91MxOAQAVDeE/IVJ761rCM4 jWYErunynJHTmkQCwT2P8bvDNlPSGWcAWSSDYo15xaLXVQe2PEU8idtPso9Y79xaWDK5Dr qRlcu/h/nHZL2u3+jBlUwwhLZCv6BYH4fjxcZ1tdURPk7gx9y2yUwg6KUViX9S1QJg6am1 xLHCWIBOOuGjM5pbudyc+6RXE7B263STf0Zg5fcYxynOLN9CBiJElOr+djyt1A== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791242532; b=NaSZNweVB7QHP2qgJP8Jn6gMk4OG/TUYecl4pWmZdOl5gRyjwC+rRrSJR2t/joypY+sy5j g/DeVmGaamhJpMn/csOrVo++B8g8y7puQiGzuudFvkX1Zi6GoUZ/d0bbRwvBHRYn6Czmck w6p/YDd2oGmW14KXrH+4bbrZA7OzwyQkQ/6OjU6InjR6nRmz5WZ+HXYSsbZtxlgzOf8LZZ 9yqcbcChAoZMDuZg3+A/X1YfsAnWb90nwbiWcXb0N+V3CisA9eneLpMFOhwWPVAZiBat6s ZAkzlZZB+e0NaX+sjZZPZ7xSzEiU05JMrynobo7UYV2qi03jWqlozuZ44zUGUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791242532; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GUX18+8b60HabjAyMAfXvmqNLCoikbArQyU9fcOv1t0=; b=KqXLpeLjVbyYGkfkHWHq4xwAdXQRENwQysDfo8Z6SwINChDVhuo0RTIkwuU5WbHjz37fyQ 1y230VFHPzOP2Q5ttOd7taI7OrouzCEx5os+UA9dKuL+vWHaMSZomMvceA4taUSacBY0TK uV8EhnDOu/gqA0RB5biAZ52D/LF181j/l8L70fAy2V4pgLelMtj5pEwrQT9+shayRR/Hco i+0feSr5wMno1KAL2ex6DtYV6wXpedZogElpkE2yjXB45Snh6joJsYx2XYFOyajUd1Iv1m 2aMzr/sSafpeVOINt/jCQgnCaCu2KgweLdKmglHV1vD6Wz0i3PACD+GXHCf8NA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from nuc (198-84-224-249.cpe.teksavvy.com [198.84.224.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: markj) by smtp.freebsd.org (Postfix) with ESMTPSA id 4hzFll5qPhzmqr; Mon, 05 Oct 2026 23:22:11 +0000 (UTC) (envelope-from markj@freebsd.org) Date: Mon, 5 Oct 2026 19:22:09 -0400 From: Mark Johnston To: Enji Cooper Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: bb5f10e51bd5 - main - linux: implement sched_getattr() Message-ID: References: <6ac42979.2608d.d368a5e@gitrepo.freebsd.org> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6ac42979.2608d.d368a5e@gitrepo.freebsd.org> On Mon, Oct 05, 2026 at 10:49:29PM +0000, Enji Cooper wrote: > The branch main has been updated by ngie: > > URL: https://cgit.FreeBSD.org/src/commit/?id=bb5f10e51bd53771f1a438f36f554256fcbd7d08 > > commit bb5f10e51bd53771f1a438f36f554256fcbd7d08 > Author: Enji Cooper > AuthorDate: 2026-10-05 22:48:22 +0000 > Commit: Enji Cooper > CommitDate: 2026-10-05 22:49:09 +0000 > > linux: implement sched_getattr() > > This change adds the necessary glue to translate Linux scheduler policy > and priority from FreeBSD so this information is available to Linux > applications. > > This unbreaks using the Linux version of Chromium on FreeBSD. > > This change was originally submitted via [freebsd/freebsd-src#2370][github-pr]. > > MFC after: 2 weeks > PR: 297468 > Co-Authored-By: Enji Cooper The commit author is already set to you. > Signed-off-by: Joao Bonifacio > > [github-pr]: https://github.com/freebsd/freebsd-src/pull/2370 > > Differential Revision: https://reviews.freebsd.org/D60214 https://docs.freebsd.org/en/articles/committers-guide/#_include_appropriate_metadata_in_a_footer documents the right way to label commits with pull request metadata. Please follow it instead of inventing your own format. > --- > sys/compat/linux/linux_dummy.c | 1 - > sys/compat/linux/linux_misc.c | 89 ++++++++++++++++++++++++++++++++++++++++++ > sys/compat/linux/linux_misc.h | 19 ++++++++- > 3 files changed, 106 insertions(+), 3 deletions(-) > > diff --git a/sys/compat/linux/linux_dummy.c b/sys/compat/linux/linux_dummy.c > index dfb1c90e9abf..873e2cef3879 100644 > --- a/sys/compat/linux/linux_dummy.c > +++ b/sys/compat/linux/linux_dummy.c > @@ -97,7 +97,6 @@ DUMMY(process_vm_writev); > /* Linux 3.8: */ > DUMMY(finit_module); > DUMMY(sched_setattr); > -DUMMY(sched_getattr); > /* Linux 3.18: */ > DUMMY(bpf); > /* Linux 3.19: */ > diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c > index 65c9044dd3bd..9e7f6411df17 100644 > --- a/sys/compat/linux/linux_misc.c > +++ b/sys/compat/linux/linux_misc.c > @@ -29,6 +29,7 @@ > * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > */ > > +#include > #include > #include > #include > @@ -116,6 +117,39 @@ struct l_pselect6arg { > l_size_t ss_len; > }; > > +/** > + * `SCHED_ATTR_SIZE_VER0` represents the size of the initial published structure. > + * > + * See `linux/kernel/sched/syscalls.c` for more details. > + */ > +#define LINUX_SCHED_ATTR_SIZE_VER0 48 > +/** > + * Linux struct sched_attr > + */ > +struct linux_sched_attr { > + l_uint size; > + l_uint sched_policy; > + uint64_t sched_flags; > + int32_t sched_nice; > + l_uint sched_priority; > + > + uint64_t sched_runtime; > + uint64_t sched_deadline; > + uint64_t sched_period; > + > + l_uint sched_util_min; > + l_uint sched_util_max; > +}; > +/** > + * `.size` must be checked at runtime as well in the syscall to match the > + * Linux implementation. > + * > + * This `_Static_assert(..)` is a sanity check to ensure that the structure > + * meets the minimum expected bar. > + */ > +_Static_assert(sizeof(struct linux_sched_attr) >= LINUX_SCHED_ATTR_SIZE_VER0, > + "struct linux_sched_attr size"); > + > static int linux_utimensat_lts_to_ts(struct l_timespec *, > struct timespec *); > #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) > @@ -1350,6 +1384,61 @@ linux_sched_getscheduler(struct thread *td, > return (error); > } > > +int > +linux_sched_getattr(struct thread *td, struct linux_sched_getattr_args *args) > +{ > + struct linux_sched_attr attr; > + struct sched_param sched_param; > + struct thread *tdt; > + int error, policy; > + > + if (args->attr == NULL || args->pid < 0 || args->flags != 0 || > + args->size < LINUX_SCHED_ATTR_SIZE_VER0 || args->size > PAGE_SIZE) > + return (EINVAL); > + > + tdt = linux_tdfind(td, args->pid, -1); > + if (tdt == NULL) > + return (ESRCH); > + > + error = kern_sched_getscheduler(td, tdt, &policy); > + if (error) { > + PROC_UNLOCK(tdt->td_proc); > + return (error); > + } > + > + error = kern_sched_getparam(td, tdt, &sched_param); > + PROC_UNLOCK(tdt->td_proc); > + if (error) > + return (error); > + > + memset(&attr, 0, sizeof(attr)); > + > + attr.size = MIN(args->size, sizeof(attr)); > + > + if (linux_map_sched_prio) { > + switch (policy) { > + case SCHED_OTHER: > + sched_param.sched_priority = 0; > + break; > + case SCHED_FIFO: > + case SCHED_RR: > + /** > + * Map [0, RTP_PRIO_MAX - RTP_PRIO_MIN] to > + * [1, LINUX_MAX_RT_PRIO - 1] (rounding up). > + */ > + sched_param.sched_priority = > + (sched_param.sched_priority * > + (LINUX_MAX_RT_PRIO - 1) + > + (RTP_PRIO_MAX - RTP_PRIO_MIN - 1)) / > + (RTP_PRIO_MAX - RTP_PRIO_MIN) + 1; > + break; > + } > + } > + attr.sched_priority = sched_param.sched_priority; > + > + return (copyout(&attr, args->attr, args->size)); So, this lets the caller decide how much stack data they want to copy out, independent of sizeof(attr). The only constraint is the `args->size > PAGE_SIZE` check at the beginning of the function. In fact, the original author of this commit got this bit right, and the bug was introduced when you modified their patch. Please revert, and in the future be sure to obtain review from kernel developers before making changes to the syscall layer. Yes, sometimes patches go unreviewed for longer than we'd like, but that's not an excuse to simply go ahead and commit if you aren't familiar with the code being modified. If you're having trouble getting review, please feel free to reach out to srcmgr@. > +} > + > int > linux_sched_get_priority_max(struct thread *td, > struct linux_sched_get_priority_max_args *args) > diff --git a/sys/compat/linux/linux_misc.h b/sys/compat/linux/linux_misc.h > index fb77784ddea8..44dd8e06fcb7 100644 > --- a/sys/compat/linux/linux_misc.h > +++ b/sys/compat/linux/linux_misc.h > @@ -109,10 +109,25 @@ > #define __LINUX_NPXCW__ 0x37f > #endif > > -/* Scheduling policies */ > -#define LINUX_SCHED_OTHER 0 > +/** > + * Linux scheduling policies. > + * > + * Ref: `linux/include/uapi/linux/sched.h` > + */ > +#define LINUX_SCHED_NORMAL 0 > +/* `SCHED_OTHER` is a legacy alias for `SCHED_NORMAL`. */ > +#define LINUX_SCHED_OTHER LINUX_SCHED_NORMAL > #define LINUX_SCHED_FIFO 1 > #define LINUX_SCHED_RR 2 > +/** > + * FreeBSD does not implement analogs for these Linux scheduling policies. This > + * is mostly here for reference and to be self-documenting in `sched_set*()`. > + */ > +#define LINUX_SCHED_BATCH 3 > +/* LINUX_SCHED_ISO: slot reserved, but not implemented upstream. */ > +#define LINUX_SCHED_IDLE 5 > +#define LINUX_SCHED_DEADLINE 6 > +#define LINUX_SCHED_EXT 7 > > #define LINUX_MAX_RT_PRIO 100 > >