Re: [PATCH v2] sched/topology: Add a cpus_read_lock to rebuild_sched_domains()

From: Shrikanth Hegde

Date: Wed Aug 19 2026 - 14:23:27 EST




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@xxxxxxxxxxxxx>
---
v1…v2: https://lore.kernel.org/all/20260812095800.gl06ANul@xxxxxxxxxxxxx/
   - 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@xxxxxxxxxxxxx>