Skip to content

Commit e730408

Browse files
committed
cpumask: relax sanity checking constraints
The cpumask_check() was unnecessarily tight, and causes problems for the users of cpumask_next(). We have a number of users that take the previous return value of one of the bit scanning functions and subtract one to keep it in "range". But since the scanning functions end up returning up to 'small_cpumask_bits' instead of the tighter 'nr_cpumask_bits', the range really needs to be using that widened form. [ This "previous-1" behavior is also the reason we have all those comments about /* -1 is a legal arg here. */ and separate checks for that being ok. So we could have just made "small_cpumask_bits-1" be a similar special "don't check this" value. Tetsuo Handa even suggested a patch that only does that for cpumask_next(), since that seems to be the only actual case that triggers, but that all makes it even _more_ magical and special. So just relax the check ] One example of this kind of pattern being the 'c_start()' function in arch/x86/kernel/cpu/proc.c, but also duplicated in various forms on other architectures. Reported-by: [email protected] Link: https://syzkaller.appspot.com/bug?extid=96cae094d90877641f32 Reported-by: Tetsuo Handa <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Fixes: 596ff4a ("cpumask: re-introduce constant-sized cpumask optimizations") Signed-off-by: Linus Torvalds <[email protected]>
1 parent 81ff855 commit e730408

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/linux/cpumask.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static __always_inline void cpu_max_bits_warn(unsigned int cpu, unsigned int bit
147147
/* verify cpu argument to cpumask_* operators */
148148
static __always_inline unsigned int cpumask_check(unsigned int cpu)
149149
{
150-
cpu_max_bits_warn(cpu, nr_cpumask_bits);
150+
cpu_max_bits_warn(cpu, small_cpumask_bits);
151151
return cpu;
152152
}
153153

0 commit comments

Comments
 (0)