From ab6e10de9d51b681557a390fe272ec026d5c0cce Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Mon, 1 Mar 2021 16:37:22 +0000 Subject: [PATCH] ANDROID: cgroup/cpuset: Fix suspicous RCU usage WARNING task_cs() is called from cpuset_cpus_allowed_fallback() without holding the read_rcu_lock() causing the below splat. Fix by holding the rcu_read_lock(). [ 0.090199] ============================= [ 0.090399] WARNING: suspicious RCU usage [ 0.090600] 5.10.19-00939-gc3bf09a68b63-dirty #368 Not tainted [ 0.090837] ----------------------------- [ 0.091000] include/linux/cgroup.h:494 suspicious rcu_dereference_check() usage! [ 0.091246] [ 0.091246] other info that might help us debug this: [ 0.091246] [ 0.091499] [ 0.091499] rcu_scheduler_active = 1, debug_locks = 1 [ 0.091738] 4 locks held by swapper/0/1: [ 0.091902] #0: ffff800014e3f510 (cpu_add_remove_lock){+.+.}-{3:3}, at: cpu_up+0x100/0x190 [ 0.092726] #1: ffff800014e3f6b0 (cpu_hotplug_lock){++++}-{0:0}, at: _cpu_up+0x4c/0x1c8 [ 0.093540] #2: ffff800014e47478 (smpboot_threads_lock){+.+.}-{3:3}, at: smpboot_create_threads+0x34/0xc0 [ 0.094399] #3: ffff0008001d0878 (&p->pi_lock){....}-{2:2}, at: try_to_wake_up+0x58/0x828 [ 0.095199] [ 0.095199] stack backtrace: [ 0.095425] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.10.19-00939-gc3bf09a68b63-dirty #368 [ 0.095670] Hardware name: Foundation-v8A (DT) [ 0.095834] Call trace: [ 0.096099] dump_backtrace+0x0/0x1a8 [ 0.096353] show_stack+0x18/0x68 [ 0.096571] dump_stack+0xf8/0x168 [ 0.096817] lockdep_rcu_suspicious+0xe4/0xf8 [ 0.097063] cpuset_cpus_allowed_fallback+0x184/0x1f8 [ 0.097299] select_fallback_rq+0x24c/0x2c0 [ 0.097526] try_to_wake_up+0x1e4/0x828 [ 0.097740] wake_up_process+0x18/0x28 [ 0.097999] kthread_park+0x74/0xc8 [ 0.098209] __smpboot_create_thread.part.0+0x90/0x168 [ 0.098486] smpboot_create_threads+0x84/0xc0 [ 0.098699] cpuhp_invoke_callback+0xe8/0xe50 [ 0.098947] _cpu_up+0xe0/0x1c8 [ 0.099126] cpu_up+0x120/0x190 [ 0.099399] bringup_nonboot_cpus+0x94/0xd0 [ 0.099659] smp_init+0x30/0x8c [ 0.099873] kernel_init_freeable+0x1d4/0x328 [ 0.100099] kernel_init+0x14/0x118 [ 0.100339] ret_from_fork+0x10/0x34 Bug: 178507149 Fixes: 210463b39ccc ("FROMLIST: cpuset: Don't use the cpu_possible_mask as a last resort for cgroup v1") Signed-off-by: Qais Yousef Change-Id: Ib7688e7d0c37cbf119d806ce79157a467b9e35f6 --- kernel/cgroup/cpuset.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 55db72dae219..2ecf089a9ecb 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3341,14 +3341,17 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) void cpuset_cpus_allowed_fallback(struct task_struct *tsk) { - const struct cpumask *cs_mask = task_cs(tsk)->cpus_allowed; const struct cpumask *possible_mask = task_cpu_possible_mask(tsk); - - if (!is_in_v2_mode() || !cpumask_subset(cs_mask, possible_mask)) - return; /* select_fallback_rq will try harder */ + const struct cpumask *cs_mask; rcu_read_lock(); + cs_mask = task_cs(tsk)->cpus_allowed; + + if (!is_in_v2_mode() || !cpumask_subset(cs_mask, possible_mask)) + goto unlock; /* select_fallback_rq will try harder */ + do_set_cpus_allowed(tsk, cs_mask); +unlock: rcu_read_unlock(); /*