Skip to contentSkip to conversation

sched/topology: Add a cpus_read_lock to rebuild_sched_domains()

PATCH Applied Sebastian Andrzej Siewior 10 participants 12 messages Aug 13 – Aug 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sched/topology: Add a cpus_read_lock to rebuild_sched_domains()

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

 include/linux/cpuset.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/cpuset.h +1 -0
index 65d76a38974ba..bf3999daa080a 100644
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
 static inline void rebuild_sched_domains(void)
 {
+	guard(cpus_read_lock)();
 	partition_sched_domains(1, NULL, NULL);
 }
 
Signature · 1 line
2.55.0
#1 lore raw

+ CPUSET maintainer which I missed because re-used the CCs from v1.

Quoted 46 lines · On 2026-08-13 09:38:56 [+0200], To [email protected] wrote:

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

 include/linux/cpuset.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/cpuset.h +1 -0
index 65d76a38974ba..bf3999daa080a 100644
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
 static inline void rebuild_sched_domains(void)
 {
+	guard(cpus_read_lock)();
 	partition_sched_domains(1, NULL, NULL);
 }
 
Signature · 1 line
2.55.0
Reviewed-by
#2 lore raw
Quoted 26 lines · Sebastian Andrzej Siewior

+ CPUSET maintainer which I missed because re-used the CCs from v1.

Quoted 22 lines · On 2026-08-13 09:38:56 [+0200], To [email protected] wrote:

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

thanks,
Chenyu

Quoted 24 lines
Quoted 24 lines

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

 include/linux/cpuset.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/cpuset.h +1 -0
index 65d76a38974ba..bf3999daa080a 100644
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
 static inline void rebuild_sched_domains(void)
 {
+	guard(cpus_read_lock)();
 	partition_sched_domains(1, NULL, NULL);
 }
 
Signature · 1 line
2.55.0
reviewer
#3 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 46 lines · Sebastian Andrzej Siewior

+ CPUSET maintainer which I missed because re-used the CCs from v1.

Quoted 43 lines · On 2026-08-13 09:38:56 [+0200], To [email protected] wrote:

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

  include/linux/cpuset.h | 1 +
  1 file changed, 1 insertion(+)
include/linux/cpuset.h +1 -0
index 65d76a38974ba..bf3999daa080a 100644
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
  static inline void rebuild_sched_domains(void)
  {
+	guard(cpus_read_lock)();
  	partition_sched_domains(1, NULL, NULL);
  }
 
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.55.0

LGTM. Thanks.

Signature · 2 lines
Best regards
Ridong
Reviewed-by
#4 lore raw
Quoted 48 lines · Ridong Chen
Quoted 46 lines · Sebastian Andrzej Siewior

+ CPUSET maintainer which I missed because re-used the CCs from v1.

Quoted 43 lines · On 2026-08-13 09:38:56 [+0200], To [email protected] wrote:

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

  include/linux/cpuset.h | 1 +
  1 file changed, 1 insertion(+)
include/linux/cpuset.h +1 -0
index 65d76a38974ba..bf3999daa080a 100644
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
  static inline void rebuild_sched_domains(void)
  {
+	guard(cpus_read_lock)();
  	partition_sched_domains(1, NULL, NULL);
  }
 
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.55.0

LGTM. Thanks.

Thanks for the patch.

maintainer Reviewed-by
#5 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 40 lines · Sebastian Andrzej Siewior

+ CPUSET maintainer which I missed because re-used the CCs from v1.

Quoted 37 lines · On 2026-08-13 09:38:56 [+0200], To [email protected] wrote:

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

  include/linux/cpuset.h | 1 +
  1 file changed, 1 insertion(+)
include/linux/cpuset.h +0 -0
index 65d76a38974ba..bf3999daa080a 100644
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
Quoted 8 lines
Quoted 8 lines
include/linux/cpuset.h +1 -0
  static inline void rebuild_sched_domains(void)
  {
+	guard(cpus_read_lock)();
  	partition_sched_domains(1, NULL, NULL);
  }
 
Signature · 1 line
2.55.0

LKTM

Reviewed-by on v2 1/1
#6 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 2 lines · Sebastian Andrzej Siewior
Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

include/linux/cpuset.h static inline void dl_rebuild_rd_accounting(void) · line 276

Quoted 5 lines
include/linux/cpuset.h +1 -0
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
 static inline void rebuild_sched_domains(void)
 {
+	guard(cpus_read_lock)();

Nit: When the indentation allows it I prefer scoped_guard()'s as I find them more readable, but that's all personal preference so YMMV.

Quoted 5 lines
include/linux/cpuset.h +0 -0
 	partition_sched_domains(1, NULL, NULL);
 }
 
Signature · 1 line
2.55.0
Tested-by on v2 1/1
#7 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 36 lines · Sebastian Andrzej Siewior

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

 include/linux/cpuset.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/cpuset.h +0 -0
index 65d76a38974ba..bf3999daa080a 100644

include/linux/cpuset.h static inline void dl_rebuild_rd_accounting(void) · line 279

Quoted 7 lines
include/linux/cpuset.h +1 -0
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
 static inline void rebuild_sched_domains(void)
 {
+	guard(cpus_read_lock)();
 	partition_sched_domains(1, NULL, NULL);
 }
 

This also fixes the EAS specific rebuild_sched_domains_energy() case which gets invoked when we start/stop EAS e.g. while doing a CPUfreq governor change: schedutil to any other governor (e.g. ondemand).

grep -h . /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor schedutil
schedutil
schedutil
schedutil
schedutil
schedutil

for f in /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_governor; do echo ondemand > "$f"; done

[  142.900976] ------------[ cut here ]------------
[  142.900990] WARNING: kernel/cpu.c:527 at lockdep_assert_cpus_held+0x44/0x60, CPU#5: kworker/5:1/90
[  142.918755] Modules linked in: 
[  142.921841] CPU: 5 UID: 0 PID: 90 Comm: kworker/5:1 Not tainted 7.2.0-rc7-00035-g68e37487810a-dirty #87 PREEMPT 
[  142.932059] Hardware name: ARM Juno development board (r0) (DT)
[  142.938003] Workqueue: events rebuild_sd_workfn
[  142.942572] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[  142.949563] pc : lockdep_assert_cpus_held+0x44/0x60
[  142.954473] lr : lockdep_assert_cpus_held+0x40/0x60
...
[  143.034566] Call trace:
[  143.037025]  lockdep_assert_cpus_held+0x44/0x60 (P) 
[  143.041939]  static_key_enable_cpuslocked+0x24/0xc8
[  143.046857]  partition_sched_domains+0x36c/0xb60
[  143.051509]  rebuild_sched_domains_energy+0x5c/0x78
...
[  143.110230] ---[ end trace 0000000000000000 ]---
[  143.115374] ------------[ cut here ]------------
[  143.115384] WARNING: kernel/cpu.c:527 at lockdep_assert_cpus_held+0x44/0x60, CPU#5: kworker/5:1/90
[  143.133300] Modules linked in: 
[  143.136383] CPU: 5 UID: 0 PID: 90 Comm: kworker/5:1 Tainted: G W 7.2.0-rc7-00035-g68e37487810a-dirty #87 PREEMPT 
[  143.148167] Tainted: [W]=WARN
[  143.151147] Hardware name: ARM Juno development board (r0) (DT)
[  143.157088] Workqueue: events rebuild_sd_workfn
[  143.161654] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[  143.168644] pc : lockdep_assert_cpus_held+0x44/0x60
[  143.173554] lr : lockdep_assert_cpus_held+0x40/0x60
[  143.253643] Call trace:
[  143.256100]  lockdep_assert_cpus_held+0x44/0x60 (P) 
[  143.261013]  _sched_cache_active_set+0x2c/0xec
[  143.265490]  partition_sched_domains+0x370/0xb60
[  143.270141]  rebuild_sched_domains_energy+0x5c/0x78

...

#8 lore raw
In reply to Sebastian Andrzej Siewior

Hi Sebastian.

Quoted 36 lines · Sebastian Andrzej Siewior

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

  include/linux/cpuset.h | 1 +
  1 file changed, 1 insertion(+)
include/linux/cpuset.h +0 -0
index 65d76a38974ba..bf3999daa080a 100644

include/linux/cpuset.h static inline void dl_rebuild_rd_accounting(void) · line 279

Quoted 7 lines
include/linux/cpuset.h +1 -0
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
  static inline void rebuild_sched_domains(void)
  {
+	guard(cpus_read_lock)();
  	partition_sched_domains(1, NULL, NULL);
  }
 

Now, both rebuild_sched_domains have the same code. I guess it is worth moving it out of CONFIG_CPUSETS.

kernel/cgroup/cpuset.c:
void rebuild_sched_domains(void)

{
        cpus_read_lock();
        rebuild_sched_domains_cpuslocked();
        cpus_read_unlock();
}
Reviewed-by
#9 lore raw
Quoted 34 lines · Shrikanth Hegde

Hi Sebastian.

Quoted 31 lines · Sebastian Andrzej Siewior

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
   - Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

  include/linux/cpuset.h | 1 +

  1 file changed, 1 insertion(+)
Quoted 14 lines

include/linux/cpuset.h static inline void dl_rebuild_rd_accounting(void) · line 277

Quoted 10 lines
include/linux/cpuset.h +1 -0
index 65d76a38974ba..bf3999daa080a 100644
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
   static inline void rebuild_sched_domains(void)
   {
+    guard(cpus_read_lock)();
       partition_sched_domains(1, NULL, NULL);
   }

Now, both rebuild_sched_domains have the same code. I guess it is worth moving it out of CONFIG_CPUSETS.

Ignore my comments. I clearly need to get rest.

Quoted 8 lines

kernel/cgroup/cpuset.c:
void rebuild_sched_domains(void)
{
        cpus_read_lock();
        rebuild_sched_domains_cpuslocked();
        cpus_read_unlock();
}

Sorry for the noise.
Looks good to me.

Reviewed-by on v2 1/1
#10 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 46 lines · Sebastian Andrzej Siewior

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

Fixes a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")

---
v1…v2: https://lore.kernel.org/all/[email protected]/
- Move the lock from partition_sched_domains() to rebuild_sched_domains() in the CONFIG_CPUSETS=n since this is the only affected case. Noticed by Yu C Chen and Tim Chen.

 include/linux/cpuset.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/cpuset.h +1 -0
index 65d76a38974ba..bf3999daa080a 100644
@@ -273,6 +273,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
 static inline void rebuild_sched_domains(void)
 {
+	guard(cpus_read_lock)();
 	partition_sched_domains(1, NULL, NULL);
 }
 
Signature · 1 line
2.55.0

LGTM.

Signature · 1 line
Aaron Tomlin
#11 lore raw
In reply to Sebastian Andrzej Siewior
The following commit has been merged into the sched/urgent branch of tip:

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     666a32836c8f9daf9b0067c49b04d5201fb8f3ba
Gitweb:        https://git.kernel.org/tip/666a32836c8f9daf9b0067c49b04d5201fb8f3ba
Author:        Sebastian Andrzej Siewior <[email protected]>
AuthorDate:    Thu, 13 Aug 2026 09:38:55 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Thu, 20 Aug 2026 11:01:34 +02:00

sched/topology: Add a cpus_read_lock to rebuild_sched_domains()

A read from /proc/sys/kernel/sched_rt_runtime_us leads to backtrace due to missing cpu_hotplug_lock with CONFIG_CPUSETS=n. The callchain is sched_rt_handler() -> partition_sched_domains() -> sched_cache_set() -> static_key_enable_cpuslocked(&sched_cache_present).

sched_cache_set() itself is also invoked from sched_init_domains() which is early during the boot, holding just the sched_domains_mutex_lock(). Here is no warning because it happens before user space is running (and hotplug operations are not possible).

There is also sched_cache_active_set() which acquires the hotplug lock before invoking any of the _cpuslocked() functions.

This is only a problem with CONFIG_CPUSETS=n because in the =y case the other implementation of rebuild_sched_domains acquires the CPU-hotplug lock.

Acquire CPU hotplug lock before in rebuild_sched_domains(), before partition_sched_domains() is invoked for the CONFIG_CPUSETS=n case.

---
 include/linux/cpuset.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/cpuset.h +1 -0
index 9db2d4f..6a3f4d4 100644
@@ -279,6 +279,7 @@ static inline void dl_rebuild_rd_accounting(void)
 
 static inline void rebuild_sched_domains(void)
 {
+	guard(cpus_read_lock)();
 	partition_sched_domains(1, NULL, NULL);
 }