rcuscale: Fix smp_processor_id()-in-preemptible warnings
authorZqiang <qiang1.zhang@intel.com>
Sat, 21 May 2022 06:56:26 +0000 (14:56 +0800)
committerPaul E. McKenney <paulmck@kernel.org>
Tue, 21 Jun 2022 22:57:04 +0000 (15:57 -0700)
Systems built with CONFIG_DEBUG_PREEMPT=y can trigger the following
BUG while running the rcuscale performance test:

BUG: using smp_processor_id() in preemptible [00000000] code: rcu_scale_write/69
CPU: 0 PID: 66 Comm: rcu_scale_write Not tainted 5.18.0-rc7-next-20220517-yoctodev-standard+
caller is debug_smp_processor_id+0x17/0x20
Call Trace:
<TASK>
dump_stack_lvl+0x49/0x5e
dump_stack+0x10/0x12
check_preemption_disabled+0xdf/0xf0
debug_smp_processor_id+0x17/0x20
rcu_scale_writer+0x2b5/0x580
kthread+0x177/0x1b0
ret_from_fork+0x22/0x30
</TASK>

Reproduction method:
runqemu kvm slirp nographic qemuparams="-m 4096 -smp 8" bootparams="isolcpus=2,3
nohz_full=2,3 rcu_nocbs=2,3 rcutree.dump_tree=1 rcuscale.shutdown=false
rcuscale.gp_async=true" -d

The problem is that the rcu_scale_writer() kthreads fail to set the
PF_NO_SETAFFINITY flags, which causes is_percpu_thread() to assume
that the kthread's affinity might change at any time, thus the BUG
noted above.

This commit therefore causes rcu_scale_writer() to set PF_NO_SETAFFINITY
in its kthread's ->flags field, thus preventing this BUG.

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/rcuscale.c

index 277a5bfb37d4830bfbc1bdf7407e49548dec3fbe..3ef02d4a810855f9fdc2befcc251e6134da0b8f4 100644 (file)
@@ -419,6 +419,7 @@ rcu_scale_writer(void *arg)
        VERBOSE_SCALEOUT_STRING("rcu_scale_writer task started");
        WARN_ON(!wdpp);
        set_cpus_allowed_ptr(current, cpumask_of(me % nr_cpu_ids));
+       current->flags |= PF_NO_SETAFFINITY;
        sched_set_fifo_low(current);
 
        if (holdoff)