linux/tools/sched_ext/include/scx
Tejun Heo e6979d05c6 tools/sched_ext: scx - Fix cmask_subset(), cmask_equal() and cmask_weight()
cmask_equal(), cmask_weight() and cmask_subset() bounded their word walks
with CMASK_NR_WORDS(nr_cids), which pads by one word and can't tell the last
word in use without @base. The walks could thus cover a slack word past the
active range, which cmask_reframe() leaves non-zero: a stale bit there gave
cmask_equal() a spurious mismatch, cmask_weight() an inflated count, and
cmask_subset() a spurious violation. cmask_subset() could also read
@b->bits[] one word past its allocation (within the arena's fault-recovered
range, so harmless), and deviated from the kernel scx_cmask_subset() by
failing any @a range that doesn't nest inside @b's even when the overhanging
bits are all clear.

Bound the cmask_equal() and cmask_weight() walks by the words the range
actually spans, with early returns for empty ranges. Rewrite cmask_subset()
to match the kernel semantics: scan @a's overhangs for set bits with
cmask_next_set() and walk the words of the range intersection.
cmask_subset() moves below cmask_next_set(), which it now uses. Padding bits
don't need masking as every cmask helper keeps them clear.

Fixes: a58e6b79b4 ("sched_ext: Add cmask, a base-windowed bitmap over cid space")
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
2026-07-09 11:08:41 -10:00
..
bpf_arena_common.bpf.h tools/sched_ext/include: Sync bpf_arena_common.bpf.h with scx repo 2026-03-07 22:45:12 -10:00
bpf_arena_common.h tools/sched_ext: Receive updates from SCX repo 2025-08-11 08:21:57 -10:00
cid.bpf.h tools/sched_ext: scx - Fix cmask_subset(), cmask_equal() and cmask_weight() 2026-07-09 11:08:41 -10:00
common.bpf.h sched_ext: Make scx_bpf_kick_cid() return s32 2026-06-03 15:46:56 -10:00
common.h tools/sched_ext: Add explicit cast from void* in RESIZE_ARRAY() 2026-04-13 06:14:11 -10:00
compat.bpf.h sched_ext: Add bpf_sched_ext_ops_cid struct_ops type 2026-04-29 08:25:07 -10:00
compat.h sched_ext: Document the ops compat strategy in compat.h/compat.bpf.h 2026-04-19 07:47:47 -10:00
enum_defs.autogen.h tools/sched_ext: Regenerate autogen enum headers 2026-03-25 05:58:08 -10:00
enums.autogen.bpf.h tools/sched_ext: Regenerate autogen enum headers 2026-03-25 05:58:08 -10:00
enums.autogen.h tools/sched_ext: Regenerate autogen enum headers 2026-03-25 05:58:08 -10:00
enums.bpf.h tools/sched_ext: Receive updates from SCX repo 2024-12-12 16:16:57 -10:00
enums.h sched_ext: Make string params of __ENUM_set() const 2026-04-13 06:14:05 -10:00
user_exit_info_common.h sched_ext: Expose exit_cpu to BPF and userspace 2026-04-28 22:44:34 -10:00
user_exit_info.bpf.h sched_ext: Expose exit_cpu to BPF and userspace 2026-04-28 22:44:34 -10:00
user_exit_info.h sched_ext: Expose exit_cpu to BPF and userspace 2026-04-28 22:44:34 -10:00