Sched_ext development
 help / color / mirror / Atom feed
* [PATCH RESEND sched_ext/for-7.2] sched_ext: Use offsetofend on both sides of the ops_cid layout assert
@ 2026-05-08 16:06 Tejun Heo
  2026-05-08 16:13 ` Tejun Heo
  2026-05-08 21:52 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Tejun Heo @ 2026-05-08 16:06 UTC (permalink / raw)
  To: David Vernet, Andrea Righi, Changwoo Min, sched-ext
  Cc: Tejun Heo, Emil Tsalapatis, kernel test robot, linux-kernel

sizeof() includes trailing struct pad, offsetofend() doesn't. On
32-bit PPC, sched_ext_ops_cid tail-pads 4 bytes past @priv and the
assert trips. Use offsetofend() on both sides.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202605081637.DbH4SZ1E-lkp@intel.com/
Fixes: 7e655ed7b953 ("sched_ext: Add bpf_sched_ext_ops_cid struct_ops type")
Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/sched/ext.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 7ac7d10a41be..f86ee15be7cb 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -10380,9 +10380,11 @@ static int __init scx_init(void)
 	/*
 	 * cid-form must end exactly at @priv - validate_ops() skips
 	 * cpu_acquire/cpu_release for cid-form because reading those fields
-	 * past the BPF allocation would be UB.
+	 * past the BPF allocation would be UB. offsetofend() on both sides
+	 * instead of sizeof() on sched_ext_ops_cid to sidestep trailing
+	 * struct padding (e.g. 32-bit PPC tail-pads ops_cid past @priv).
 	 */
-	BUILD_BUG_ON(sizeof(struct sched_ext_ops_cid) !=
+	BUILD_BUG_ON(offsetofend(struct sched_ext_ops_cid, priv) !=
 		     offsetofend(struct sched_ext_ops, priv));
 #undef CID_OFFSET_MATCH
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND sched_ext/for-7.2] sched_ext: Use offsetofend on both sides of the ops_cid layout assert
  2026-05-08 16:06 [PATCH RESEND sched_ext/for-7.2] sched_ext: Use offsetofend on both sides of the ops_cid layout assert Tejun Heo
@ 2026-05-08 16:13 ` Tejun Heo
  2026-05-08 21:52 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2026-05-08 16:13 UTC (permalink / raw)
  To: David Vernet, Andrea Righi, Changwoo Min, sched-ext
  Cc: Emil Tsalapatis, kernel test robot, linux-kernel

Hello,

Applied to sched_ext/for-7.2.

Thanks.

--
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND sched_ext/for-7.2] sched_ext: Use offsetofend on both sides of the ops_cid layout assert
  2026-05-08 16:06 [PATCH RESEND sched_ext/for-7.2] sched_ext: Use offsetofend on both sides of the ops_cid layout assert Tejun Heo
  2026-05-08 16:13 ` Tejun Heo
@ 2026-05-08 21:52 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-05-08 21:52 UTC (permalink / raw)
  To: Tejun Heo; +Cc: sched-ext

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The modified BUILD_BUG_ON assertion is tautological and no longer enforces the requirement that sched_ext_ops_cid ends exactly at @priv.
--

commit 5445ec05ee0d3c461f6dab131ab56481c5c2fc81
Author: Tejun Heo <tj@kernel.org>

sched_ext: Use offsetofend on both sides of the ops_cid layout assert

This commit modifies the layout assertion for sched_ext_ops_cid to use
offsetofend() instead of sizeof(). This change was made to avoid build
failures caused by trailing struct padding on 32-bit PPC architectures.

Closes: https://lore.kernel.org/oe-kbuild-all/202605081637.DbH4SZ1E-lkp@intel.com/
Fixes: 7e655ed7b953 ("sched_ext: Add bpf_sched_ext_ops_cid struct_ops type")

> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 1d7f206941f0c..5eece6c95cf5a 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -10451,9 +10451,11 @@ static int __init scx_init(void)
>  	/*
>  	 * cid-form must end exactly at @priv - validate_ops() skips
>  	 * cpu_acquire/cpu_release for cid-form because reading those fields
> -	 * past the BPF allocation would be UB.
> +	 * past the BPF allocation would be UB. offsetofend() on both sides
> +	 * instead of sizeof() on sched_ext_ops_cid to sidestep trailing
> +	 * struct padding (e.g. 32-bit PPC tail-pads ops_cid past @priv).
>  	 */
> -	BUILD_BUG_ON(sizeof(struct sched_ext_ops_cid) !=
> +	BUILD_BUG_ON(offsetofend(struct sched_ext_ops_cid, priv) !=
>  		     offsetofend(struct sched_ext_ops, priv));

Does this modification inadvertently make the assertion a tautology?

The preceding CID_OFFSET_MATCH(priv, priv) already enforces that the offset
of the priv field is identical in both structures. Because offsetofend()
is defined as offsetof() plus sizeof_field(), and the type of priv is the
same in both structures, this BUILD_BUG_ON() check will always evaluate
to false.

If a new field were accidentally added to sched_ext_ops_cid after priv,
would this check fail to catch it since it no longer evaluates the overall
size of the structure?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260508160651.4030241-1-tj@kernel.org?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-08 21:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-08 16:06 [PATCH RESEND sched_ext/for-7.2] sched_ext: Use offsetofend on both sides of the ops_cid layout assert Tejun Heo
2026-05-08 16:13 ` Tejun Heo
2026-05-08 21:52 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox