From: sashiko-bot@kernel.org
To: "Tejun Heo" <tj@kernel.org>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 3/4] sched_ext: Add scx_cmask_test() and scx_cmask_for_each_cid()
Date: Thu, 04 Jun 2026 02:10:10 +0000 [thread overview]
Message-ID: <20260604021011.42A771F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260604020032.3536466-4-tj@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The `scx_cmask_for_each_cid` macro expands into two nested `for` loops, breaking standard C iteration semantics for `break` statements. If a caller uses a `break` statement to terminate the iteration early, it will only exit the inner loop (terminating the scan for the current 64-bit word). The outer loop will then increment, fetch the next word, and continue iterating. This creates a trap where developers intending to completely abort the loop will inadvertently only skip the rest of the current word and silently resume on the next one.
--
commit e9a4307d205f9de4f9da9f425dd9329d36d47094
Author: Tejun Heo <tj@kernel.org>
sched_ext: Add scx_cmask_test() and scx_cmask_for_each_cid()
Adds a single-bit test and an iterator over set cids in an scx_cmask.
The iterator is bounded to the active span.
> diff --git a/kernel/sched/ext_cid.h b/kernel/sched/ext_cid.h
> index 46fd8eda04435..5745e5785e897 100644
> --- a/kernel/sched/ext_cid.h
> +++ b/kernel/sched/ext_cid.h
[ ... ]
> +/**
> + * scx_cmask_for_each_cid - iterate set cids in @m
> + * @cid: s32 loop var that receives each set cid in turn
> + * @m: cmask to iterate
> + *
> + * Visits set bits within @m's active range in ascending order. Scans only the
> + * words the active range spans, where head and tail padding is kept zero, so
> + * no per-cid range check is needed.
> + */
> +#define scx_cmask_for_each_cid(cid, m) \
> + for (u64 __bs = (m)->base & ~63u, __wi = 0, \
> + __nw = scx_cmask_nr_used_words(m); \
> + __wi < __nw; __wi++) \
> + for (u64 __w = READ_ONCE((m)->bits[__wi]); \
> + __w && ((cid) = __bs + __wi * 64 + __ffs64(__w), true); \
> + __w &= __w - 1)
[Severity: High]
Since this macro expands into two nested for loops, what happens if a caller
uses a break statement to terminate the iteration early?
It appears a break will only exit the inner loop, terminating the scan for
the current 64-bit word. The outer loop will then increment, fetch the next
word, and continue iterating.
Could this create a trap where a standard break statement inadvertently skips
the rest of the current word but silently resumes yielding items on the next
word, violating standard C iteration semantics?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604020032.3536466-1-tj@kernel.org?part=3
next prev parent reply other threads:[~2026-06-04 2:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 2:00 [PATCHSET v2 sched_ext/for-7.2] sched_ext: cid/cmask interface prep Tejun Heo
2026-06-04 2:00 ` [PATCH 1/4] sched_ext: Order single-cid cmask helpers as (cid, mask) Tejun Heo
2026-06-04 2:00 ` [PATCH 2/4] tools/sched_ext: " Tejun Heo
2026-06-04 2:00 ` [PATCH 3/4] sched_ext: Add scx_cmask_test() and scx_cmask_for_each_cid() Tejun Heo
2026-06-04 2:10 ` sashiko-bot [this message]
2026-06-04 2:00 ` [PATCH 4/4] sched_ext: Make scx_bpf_kick_cid() return s32 Tejun Heo
2026-06-04 6:18 ` [PATCHSET v2 sched_ext/for-7.2] sched_ext: cid/cmask interface prep Andrea Righi
2026-06-04 8:32 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260604021011.42A771F00898@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox