The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
@ 2026-08-13  7:38 Sebastian Andrzej Siewior
  2026-08-13  7:48 ` Sebastian Andrzej Siewior
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-08-13  7:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ben Segall, Dietmar Eggemann, Ingo Molnar, Juri Lelli,
	K Prateek Nayak, Mel Gorman, Peter Zijlstra, Steven Rostedt,
	Tim Chen, Valentin Schneider, Vincent Guittot, chen.yu@linux.dev,
	Chen, Yu C

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")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
  - 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(+)

diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
index 65d76a38974ba..bf3999daa080a 100644
--- a/include/linux/cpuset.h
+++ b/include/linux/cpuset.h
@@ -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);
 }
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:38 [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains() Sebastian Andrzej Siewior
@ 2026-08-13  7:48 ` Sebastian Andrzej Siewior
  2026-08-13  9:20   ` Chen Yu
                     ` (2 more replies)
  2026-08-14 14:46 ` Valentin Schneider
                   ` (4 subsequent siblings)
  5 siblings, 3 replies; 12+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-08-13  7:48 UTC (permalink / raw)
  To: linux-kernel, cgroups
  Cc: Ben Segall, Dietmar Eggemann, Ingo Molnar, Juri Lelli,
	K Prateek Nayak, Mel Gorman, Peter Zijlstra, Steven Rostedt,
	Tim Chen, Valentin Schneider, Vincent Guittot, chen.yu@linux.dev,
	Chen, Yu C, Waiman Long, Ridong Chen

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

On 2026-08-13 09:38:56 [+0200], To linux-kernel@vger.kernel.org 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")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
>   - 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(+)
> 
> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> index 65d76a38974ba..bf3999daa080a 100644
> --- a/include/linux/cpuset.h
> +++ b/include/linux/cpuset.h
> @@ -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);
>  }
>  
> -- 
> 2.55.0
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:48 ` Sebastian Andrzej Siewior
@ 2026-08-13  9:20   ` Chen Yu
  2026-08-13  9:43   ` Ridong Chen
  2026-08-19 18:52   ` Waiman Long
  2 siblings, 0 replies; 12+ messages in thread
From: Chen Yu @ 2026-08-13  9:20 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-kernel, cgroups, Ben Segall, Dietmar Eggemann, Ingo Molnar,
	Juri Lelli, K Prateek Nayak, Mel Gorman, Peter Zijlstra,
	Steven Rostedt, Tim Chen, Valentin Schneider, Vincent Guittot,
	Chen, Yu C, Waiman Long, Ridong Chen

On Thu, Aug 13, 2026 at 09:48:17AM +0200, Sebastian Andrzej Siewior wrote:
> 
> + CPUSET maintainer which I missed because re-used the CCs from v1.
> 
> On 2026-08-13 09:38:56 [+0200], To linux-kernel@vger.kernel.org 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")
> > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Reviewed-by: Chen Yu <yu.c.chen@intel.com>

thanks,
Chenyu

> > ---
> > v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
> >   - 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(+)
> > 
> > diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> > index 65d76a38974ba..bf3999daa080a 100644
> > --- a/include/linux/cpuset.h
> > +++ b/include/linux/cpuset.h
> > @@ -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);
> >  }
> >  
> > -- 
> > 2.55.0
> > 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:48 ` Sebastian Andrzej Siewior
  2026-08-13  9:20   ` Chen Yu
@ 2026-08-13  9:43   ` Ridong Chen
  2026-08-19 17:14     ` Tim Chen
  2026-08-19 18:52   ` Waiman Long
  2 siblings, 1 reply; 12+ messages in thread
From: Ridong Chen @ 2026-08-13  9:43 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel, cgroups
  Cc: Ben Segall, Dietmar Eggemann, Ingo Molnar, Juri Lelli,
	K Prateek Nayak, Mel Gorman, Peter Zijlstra, Steven Rostedt,
	Tim Chen, Valentin Schneider, Vincent Guittot, chen.yu@linux.dev,
	Chen, Yu C, Waiman Long



On 8/13/2026 3:48 PM, Sebastian Andrzej Siewior wrote:
> + CPUSET maintainer which I missed because re-used the CCs from v1.
> 
> On 2026-08-13 09:38:56 [+0200], To linux-kernel@vger.kernel.org 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")
>> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> ---
>> v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
>>    - 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(+)
>>
>> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
>> index 65d76a38974ba..bf3999daa080a 100644
>> --- a/include/linux/cpuset.h
>> +++ b/include/linux/cpuset.h
>> @@ -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);
>>   }
>>   
>> -- 
>> 2.55.0
>>

LGTM. Thanks.

Reivewed-by: Ridong Chen <ridong.chen@linux.dev>

-- 
Best regards
Ridong


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:38 [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains() Sebastian Andrzej Siewior
  2026-08-13  7:48 ` Sebastian Andrzej Siewior
@ 2026-08-14 14:46 ` Valentin Schneider
  2026-08-19 10:19 ` Dietmar Eggemann
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Valentin Schneider @ 2026-08-14 14:46 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel
  Cc: Ben Segall, Dietmar Eggemann, Ingo Molnar, Juri Lelli,
	K Prateek Nayak, Mel Gorman, Peter Zijlstra, Steven Rostedt,
	Tim Chen, Vincent Guittot, chen.yu@linux.dev, Chen, Yu C

On 13/08/26 09:38, Sebastian Andrzej Siewior wrote:
> Fixes: a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Reviewed-by: Valentin Schneider <vschneid@redhat.com>

> @@ -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.

>  	partition_sched_domains(1, NULL, NULL);
>  }
>  
> -- 
> 2.55.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:38 [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains() Sebastian Andrzej Siewior
  2026-08-13  7:48 ` Sebastian Andrzej Siewior
  2026-08-14 14:46 ` Valentin Schneider
@ 2026-08-19 10:19 ` Dietmar Eggemann
  2026-08-19 17:54 ` Shrikanth Hegde
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Dietmar Eggemann @ 2026-08-19 10:19 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel
  Cc: Ben Segall, Ingo Molnar, Juri Lelli, K Prateek Nayak, Mel Gorman,
	Peter Zijlstra, Steven Rostedt, Tim Chen, Valentin Schneider,
	Vincent Guittot, chen.yu@linux.dev, Chen, Yu C

On 13.08.26 09:38, Sebastian Andrzej Siewior 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")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
>   - 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(+)
> 
> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> index 65d76a38974ba..bf3999daa080a 100644
> --- a/include/linux/cpuset.h
> +++ b/include/linux/cpuset.h
> @@ -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
...

Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  9:43   ` Ridong Chen
@ 2026-08-19 17:14     ` Tim Chen
  0 siblings, 0 replies; 12+ messages in thread
From: Tim Chen @ 2026-08-19 17:14 UTC (permalink / raw)
  To: Ridong Chen, Sebastian Andrzej Siewior, linux-kernel, cgroups
  Cc: Ben Segall, Dietmar Eggemann, Ingo Molnar, Juri Lelli,
	K Prateek Nayak, Mel Gorman, Peter Zijlstra, Steven Rostedt,
	Valentin Schneider, Vincent Guittot, chen.yu@linux.dev,
	Chen, Yu C, Waiman Long

On Thu, 2026-08-13 at 17:43 +0800, Ridong Chen wrote:
> 
> On 8/13/2026 3:48 PM, Sebastian Andrzej Siewior wrote:
> > + CPUSET maintainer which I missed because re-used the CCs from v1.
> > 
> > On 2026-08-13 09:38:56 [+0200], To linux-kernel@vger.kernel.org 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")
> > > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> > > ---
> > > v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
> > >    - 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(+)
> > > 
> > > diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> > > index 65d76a38974ba..bf3999daa080a 100644
> > > --- a/include/linux/cpuset.h
> > > +++ b/include/linux/cpuset.h
> > > @@ -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);
> > >   }
> > >   
> > > -- 
> > > 2.55.0
> > > 
> 
> LGTM. Thanks.
> 
> Reivewed-by: Ridong Chen <ridong.chen@linux.dev>

Thanks for the  patch.

Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:38 [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains() Sebastian Andrzej Siewior
                   ` (2 preceding siblings ...)
  2026-08-19 10:19 ` Dietmar Eggemann
@ 2026-08-19 17:54 ` Shrikanth Hegde
  2026-08-19 18:22   ` Shrikanth Hegde
  2026-08-19 21:29 ` Aaron Tomlin
  2026-08-20  9:10 ` [tip: sched/urgent] " tip-bot2 for Sebastian Andrzej Siewior
  5 siblings, 1 reply; 12+ messages in thread
From: Shrikanth Hegde @ 2026-08-19 17:54 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel
  Cc: Ben Segall, Dietmar Eggemann, Ingo Molnar, Juri Lelli,
	K Prateek Nayak, Mel Gorman, Peter Zijlstra, Steven Rostedt,
	Tim Chen, Valentin Schneider, Vincent Guittot, chen.yu@linux.dev,
	Chen, Yu C

Hi Sebastian.

On 8/13/26 1:08 PM, Sebastian Andrzej Siewior 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")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
>    - 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(+)
> 
> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> index 65d76a38974ba..bf3999daa080a 100644
> --- a/include/linux/cpuset.h
> +++ b/include/linux/cpuset.h
> @@ -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();
}


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-19 17:54 ` Shrikanth Hegde
@ 2026-08-19 18:22   ` Shrikanth Hegde
  0 siblings, 0 replies; 12+ messages in thread
From: Shrikanth Hegde @ 2026-08-19 18:22 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel
  Cc: Ben Segall, Dietmar Eggemann, Ingo Molnar, Juri Lelli,
	K Prateek Nayak, Mel Gorman, Peter Zijlstra, Steven Rostedt,
	Tim Chen, Valentin Schneider, Vincent Guittot, chen.yu@linux.dev,
	Chen, Yu C



On 8/19/26 11:24 PM, Shrikanth Hegde wrote:
> Hi Sebastian.
> 
> On 8/13/26 1:08 PM, Sebastian Andrzej Siewior 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")
>> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> ---
>> v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
>>    - 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(+)
>>
>> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
>> index 65d76a38974ba..bf3999daa080a 100644
>> --- a/include/linux/cpuset.h
>> +++ b/include/linux/cpuset.h
>> @@ -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.

> 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: Shrikanth Hegde <sshegde@linux.ibm.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:48 ` Sebastian Andrzej Siewior
  2026-08-13  9:20   ` Chen Yu
  2026-08-13  9:43   ` Ridong Chen
@ 2026-08-19 18:52   ` Waiman Long
  2 siblings, 0 replies; 12+ messages in thread
From: Waiman Long @ 2026-08-19 18:52 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel, cgroups
  Cc: Ben Segall, Dietmar Eggemann, Ingo Molnar, Juri Lelli,
	K Prateek Nayak, Mel Gorman, Peter Zijlstra, Steven Rostedt,
	Tim Chen, Valentin Schneider, Vincent Guittot, chen.yu@linux.dev,
	Chen, Yu C, Ridong Chen

On 8/13/26 3:48 AM, Sebastian Andrzej Siewior wrote:
> + CPUSET maintainer which I missed because re-used the CCs from v1.
>
> On 2026-08-13 09:38:56 [+0200], To linux-kernel@vger.kernel.org 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")
>> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> ---
>> v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
>>    - 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(+)
>>
>> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
>> index 65d76a38974ba..bf3999daa080a 100644
>> --- a/include/linux/cpuset.h
>> +++ b/include/linux/cpuset.h
>> @@ -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);
>>   }
>>   
>> -- 
>> 2.55.0

LKTM

Reviewed-by:  Waiman Long <longman@redhat.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:38 [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains() Sebastian Andrzej Siewior
                   ` (3 preceding siblings ...)
  2026-08-19 17:54 ` Shrikanth Hegde
@ 2026-08-19 21:29 ` Aaron Tomlin
  2026-08-20  9:10 ` [tip: sched/urgent] " tip-bot2 for Sebastian Andrzej Siewior
  5 siblings, 0 replies; 12+ messages in thread
From: Aaron Tomlin @ 2026-08-19 21:29 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-kernel, Ben Segall, Dietmar Eggemann, Ingo Molnar,
	Juri Lelli, K Prateek Nayak, Mel Gorman, Peter Zijlstra,
	Steven Rostedt, Tim Chen, Valentin Schneider, Vincent Guittot,
	chen.yu@linux.dev, Chen, Yu C

On Thu, Aug 13, 2026 at 09:38:55AM +0200, Sebastian Andrzej Siewior 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")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@linutronix.de/
>   - 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(+)
> 
> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> index 65d76a38974ba..bf3999daa080a 100644
> --- a/include/linux/cpuset.h
> +++ b/include/linux/cpuset.h
> @@ -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);
>  }
>  
> -- 
> 2.55.0
> 

LGTM.

Reviewed-by: Aaron Tomlin <atomlin@atomlin.com>

-- 
Aaron Tomlin

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [tip: sched/urgent] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()
  2026-08-13  7:38 [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains() Sebastian Andrzej Siewior
                   ` (4 preceding siblings ...)
  2026-08-19 21:29 ` Aaron Tomlin
@ 2026-08-20  9:10 ` tip-bot2 for Sebastian Andrzej Siewior
  5 siblings, 0 replies; 12+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2026-08-20  9:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Peter Zijlstra (Intel), Chen Yu,
	Tim Chen, Waiman Long, Valentin Schneider, Shrikanth Hegde,
	Aaron Tomlin, Dietmar Eggemann, x86, linux-kernel

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 <bigeasy@linutronix.de>
AuthorDate:    Thu, 13 Aug 2026 09:38:55 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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.

Fixes: a7660ce1590fc ("sched/cache: Fix has_multi_llcs iff at least one partition has multiple LLCs")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reivewed-by: Ridong Chen <ridong.chen@linux.dev>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Chen Yu <yu.c.chen@intel.com>
Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
Reviewed-by: Waiman Long <longman@redhat.com>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Reviewed-by: Aaron Tomlin <atomlin@atomlin.com>
Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Link: https://patch.msgid.link/20260813073855.ji2UrtVh@linutronix.de
---
 include/linux/cpuset.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
index 9db2d4f..6a3f4d4 100644
--- a/include/linux/cpuset.h
+++ b/include/linux/cpuset.h
@@ -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);
 }
 

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-08-20  9:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-13  7:38 [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains() Sebastian Andrzej Siewior
2026-08-13  7:48 ` Sebastian Andrzej Siewior
2026-08-13  9:20   ` Chen Yu
2026-08-13  9:43   ` Ridong Chen
2026-08-19 17:14     ` Tim Chen
2026-08-19 18:52   ` Waiman Long
2026-08-14 14:46 ` Valentin Schneider
2026-08-19 10:19 ` Dietmar Eggemann
2026-08-19 17:54 ` Shrikanth Hegde
2026-08-19 18:22   ` Shrikanth Hegde
2026-08-19 21:29 ` Aaron Tomlin
2026-08-20  9:10 ` [tip: sched/urgent] " tip-bot2 for Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox