Re: [Patch v4 12/16] sched/cache: Fix race condition during sched domain rebuild

From: Chen, Yu C

Date: Tue May 19 2026 - 01:42:15 EST


On 5/18/2026 10:34 PM, Peter Zijlstra wrote:
On Wed, May 13, 2026 at 01:39:23PM -0700, Tim Chen wrote:
/*
* Enable/disable cache aware scheduling according to
* user input and the presence of hardware support.
+ * Expected to be protected by cpus_read_lock() and
+ * sched_domains_mutex_lock()
*/
-static void sched_cache_active_set(bool locked)
+static void _sched_cache_active_set(void)

Like so?


Yes, I think this is OK. One case is that the _sched_cache_active_set()
might be called via sched_init_smp() -> sched_init_domains() -> build_sched_domains()
where only sched_domains_mutex was hold. But since it is during boot
up thus system_state < SYSTEM_RUNNING and lockdep_assert_cpus_held() will
not trigger the assert.

thanks,
Chenyu


--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -920,11 +920,12 @@ static bool alloc_sd_llc(const struct cp
/*
* Enable/disable cache aware scheduling according to
* user input and the presence of hardware support.
- * Expected to be protected by cpus_read_lock() and
- * sched_domains_mutex_lock()
*/
static void _sched_cache_active_set(void)
{
+ lockdep_assert_cpus_held();
+ lockdep_assert_held(&sched_domains_mutex);
+
/* hardware does not support */
if (!static_branch_likely(&sched_cache_present)) {
static_branch_disable_cpuslocked(&sched_cache_active);