sched_ext: Use offsetofend on both sides of the ops_cid layout assert
Subsystems (2)
Tejun Heo
reviewerPATCH RESEND 1/1 sched_ext: Use offsetofend on both sides of the ops_cid layout assert
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.
--- kernel/sched/ext.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/sched/ext.c +4 -2
@@ -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
Signature · 1 line
2.54.0
Hello,
Applied to sched_ext/for-7.2.
Thanks.
--
tejun
[email protected]
AI reviewThank 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…
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 <[email protected]>
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.
Quoted 6 lines
kernel/sched/ext.c +0
-0@@ -10451,9 +10451,11 @@ static int __init scx_init(void)/*
kernel/sched/ext.c static int __init scx_init(void) · line 10459
Quoted 10 lines
kernel/sched/ext.c +4
-2* 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?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1