sched/isolation: Fix suspicious RCU usage without CONFIG_CPUSETS
PATCH 1/1 sched/isolation: Fix suspicious RCU usage without CONFIG_CPUSETS
Since commit 03ff73510169 ("cpuset: Update HK_TYPE_DOMAIN cpumask from cpuset"), cpuset can change the HK_TYPE_DOMAIN mask at run time. Readers use RCU. housekeeping_dereference_check() also accepts readers that hold a lock which keeps cpuset partitions from changing: the CPU hotplug write lock or cpuset_mutex. During boot, before cpuset is writable, it accepts all readers.
Without CONFIG_CPUSETS, nothing changes the mask after boot. But the check still asks for one of these locks. In that configuration, rebuild_sched_domains() holds only cpus_read_lock(). It calls partition_sched_domains(1, NULL, NULL). That reads housekeeping_cpumask(HK_TYPE_DOMAIN). sched_rt_handler() calls rebuild_sched_domains() on each read or write of sched_rt_period_us and sched_rt_runtime_us. So with isolcpus=domain, a read of /proc/sys/kernel/sched_rt_runtime_us gives:
WARNING: suspicious RCU usage
kernel/sched/isolation.c:62 suspicious rcu_dereference_check() usage! [...]
locks held by cat/91: 3, last CPU#3:
[...]
#1: (cpu_hotplug_lock){++++}-{0:0}, at: sched_rt_handler+0xb5/0xf0 #2: (sched_domains_mutex){+.+.}-{4:4}, at: partition_sched_domains+0x37/0x990
[...]
Call Trace: lockdep_rcu_suspicious.cold+0x4e/0x9f housekeeping_cpumask+0xaa/0xb0 partition_sched_domains+0x8e6/0x990 sched_rt_handler+0xc3/0xf0 proc_sys_call_handler+0x1cf/0x250
The report is a false positive. It needs CONFIG_PROVE_RCU and isolcpus= with the domain flag, which is also the default when no flag is given. Test runs that check the kernel log for lockdep reports flag it.
Fix this by accepting all readers when CONFIG_CPUSETS is off.
This change was developed with assistance from an LLM.
---
This patch was first posted inside the bug report linked above. Since then, it has Waiman's Reviewed-by. The code is unchanged.
kernel/sched/isolation.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/sched/isolation.c +4 -0
@@ -43,6 +43,10 @@ static bool housekeeping_dereference_check(enum hk_type type)if (system_state <=SYSTEM_SCHEDULING )return true; +/* No cpuset, so the mask never changes after boot */ +if (!IS_ENABLED (CONFIG_CPUSETS )) +return true; +/* CPU hotplug write locked, so cpuset partition can't be overwritten */ if (IS_ENABLED (CONFIG_HOTPLUG_CPU ) &&lockdep_is_cpus_write_held ())return true;
base-commit: 006991aa89974378ee579416dba87adc22cd60fd
Signature · 1 line
2.47.3