Skip to contentSkip to conversation

sched/topology: Provide arch_llc_mask for cache aware scheduling

PATCH Applied Shrikanth Hegde 4 participants 4 messages May 29

Subsystems (3)
lore
Share & tools
lore

Shrikanth Hegde

author reviewer
#0 lore raw

PATCH 1/1 sched/topology: Provide arch_llc_mask for cache aware scheduling

Venkat Reported a boot kernel panic next-20260522. Git bisect pointed to b5ea300a17e3 ("sched/cache: Make LLC id continuous")

Stacktrace points to llc_mask being null.

NIP [c000000000e58504] _find_first_bit+0x44/0x130
LR [c000000000e58500] _find_first_bit+0x40/0x130

Call Trace:
build_sched_domains+0xad8/0xe50
sched_init_smp+0xa8/0x164
kernel_init_freeable+0x250/0x370
ret_from_kernel_user_thread+0x14/0x1c

On powerpc, cpu_coregroup_mask is available only when the underlying hardware support coregroup. In shared LPAR, QEMU guest or power9 etc coregroup isn't supported. In such cases llc_mask was being referenced when it was null leading to panic.

On powerpc, LLC is at SMT core level. So assumption that coregroup(MC) domain point to LLC is wrong. Provide a way for archs to say where its LLC is if it not at MC domain.

Based on tip/master at 5c89783224e9 ("Merge branch into tip/master: 'x86/tdx'")
Cc: [email protected]

---
 arch/powerpc/include/asm/topology.h |  6 ++++++
 kernel/sched/topology.c             | 13 +++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/topology.h +6 -0
index 66ed5fe1b718..e3de0f3d8b86 100644
@@ -135,6 +135,12 @@ struct cpumask *cpu_coregroup_mask(int cpu);
 const struct cpumask *cpu_die_mask(int cpu);
 int cpu_die_id(int cpu);
 
+/* Points to where the LLC is. On power9 this will point at CACHE
+ * domain, On others it will point to SMT domain. In all cases
+ * cpu_l2_cache_mask points to where LLC is
+ */
+#define arch_llc_mask(cpu)     cpu_l2_cache_mask(cpu)
+
 #ifdef CONFIG_PPC64
 #include <asm/smp.h>
 
kernel/sched/topology.c +11 -2
index df2ceb54c970..622e2e01974c 100644
@@ -2063,12 +2063,21 @@ const struct cpumask *tl_mc_mask(struct sched_domain_topology_level *tl, int cpu
 	return cpu_coregroup_mask(cpu);
 }
 
-#define llc_mask(cpu) cpu_coregroup_mask(cpu)
+/*
+ * Majority of architectures have LLC at MC domain level with exception
+ * such as powerpc. Provide a way for arch to specify where its LLC is
+ * if it falls in exception category
+ */
+# ifndef arch_llc_mask
+#define arch_llc_mask(cpu) cpu_coregroup_mask(cpu)
+# endif
 
 #else
-#define llc_mask(cpu) cpumask_of(cpu)
+#define arch_llc_mask(cpu) cpumask_of(cpu)
 #endif
 
+#define llc_mask(cpu) arch_llc_mask(cpu)
+
 const struct cpumask *tl_pkg_mask(struct sched_domain_topology_level *tl, int cpu)
 {
 	return cpu_node_mask(cpu);
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 18 lines · Shrikanth Hegde

Venkat Reported a boot kernel panic next-20260522. Git bisect pointed to b5ea300a17e3 ("sched/cache: Make LLC id continuous")

Stacktrace points to llc_mask being null.

NIP [c000000000e58504] _find_first_bit+0x44/0x130
LR [c000000000e58500] _find_first_bit+0x40/0x130

Call Trace:
build_sched_domains+0xad8/0xe50
sched_init_smp+0xa8/0x164
kernel_init_freeable+0x250/0x370
ret_from_kernel_user_thread+0x14/0x1c

On powerpc, cpu_coregroup_mask is available only when the underlying hardware support coregroup. In shared LPAR, QEMU guest or power9 etc coregroup isn't supported. In such cases llc_mask was being referenced when it was null leading to panic.

Quoted 6 lines

On powerpc, LLC is at SMT core level. So assumption that coregroup(MC) domain point to LLC is wrong. Provide a way for archs to say where its LLC is if it not at MC domain.

Based on tip/master at 5c89783224e9 ("Merge branch into tip/master: 'x86/tdx'")
Cc: [email protected]

This seems unwarranted, the patch breaking stuff is in tip:sched/core.

Quoted 8 lines

Thanks all! I'll stick this in tip:sched/core to go along with the patches that broke stuff.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Shrikanth Hegde
Quoted 43 lines · Shrikanth Hegde

Venkat Reported a boot kernel panic next-20260522. Git bisect pointed to b5ea300a17e3 ("sched/cache: Make LLC id continuous")

Stacktrace points to llc_mask being null.

NIP [c000000000e58504] _find_first_bit+0x44/0x130
LR [c000000000e58500] _find_first_bit+0x40/0x130

Call Trace:
build_sched_domains+0xad8/0xe50
sched_init_smp+0xa8/0x164
kernel_init_freeable+0x250/0x370
ret_from_kernel_user_thread+0x14/0x1c

On powerpc, cpu_coregroup_mask is available only when the underlying hardware support coregroup. In shared LPAR, QEMU guest or power9 etc coregroup isn't supported. In such cases llc_mask was being referenced when it was null leading to panic.

On powerpc, LLC is at SMT core level. So assumption that coregroup(MC) domain point to LLC is wrong. Provide a way for archs to say where its LLC is if it not at MC domain.

Based on tip/master at 5c89783224e9 ("Merge branch into tip/master: 'x86/tdx'")
Cc: [email protected]

---
 arch/powerpc/include/asm/topology.h |  6 ++++++
 kernel/sched/topology.c             | 13 +++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/topology.h +0 -0
index 66ed5fe1b718..e3de0f3d8b86 100644

arch/powerpc/include/asm/topology.h struct cpumask *cpu_coregroup_mask(int cpu); · line 141

Quoted 7 lines
arch/powerpc/include/asm/topology.h +4 -0
@@ -135,6 +135,12 @@ struct cpumask *cpu_coregroup_mask(int cpu);
 const struct cpumask *cpu_die_mask(int cpu);
 int cpu_die_id(int cpu);
 
+/* Points to where the LLC is. On power9 this will point at CACHE
+ * domain, On others it will point to SMT domain. In all cases
+ * cpu_l2_cache_mask points to where LLC is
+ */

Nit: Regular comment style could have been better.

Quoted 20 lines
arch/powerpc/include/asm/topology.h +2 -0
+#define arch_llc_mask(cpu)     cpu_l2_cache_mask(cpu)
+
 #ifdef CONFIG_PPC64
 #include <asm/smp.h>
 
kernel/sched/topology.c +6 -1
index df2ceb54c970..622e2e01974c 100644
@@ -2063,12 +2063,21 @@ const struct cpumask *tl_mc_mask(struct sched_domain_topology_level *tl, int cpu
 	return cpu_coregroup_mask(cpu);
 }
 
-#define llc_mask(cpu) cpu_coregroup_mask(cpu)
+/*
+ * Majority of architectures have LLC at MC domain level with exception
+ * such as powerpc. Provide a way for arch to specify where its LLC is
+ * if it falls in exception category
+ */
+# ifndef arch_llc_mask

kernel/sched/topology.c const struct cpumask *tl_mc_mask(struct sched_domain_topology_level *tl, int cpu · line 2080

Quoted 10 lines
kernel/sched/topology.c +5 -1
+#define arch_llc_mask(cpu) cpu_coregroup_mask(cpu)
+# endif
 
 #else
-#define llc_mask(cpu) cpumask_of(cpu)
+#define arch_llc_mask(cpu) cpumask_of(cpu)
 #endif
 
+#define llc_mask(cpu) arch_llc_mask(cpu)
+

Instead of having another define, could we have modified current users of llc_mask() to arch_llc_mask()? Again its not a problem, but why have 2 defines since both point to the same thing.

Quoted 6 lines
kernel/sched/topology.c +0 -0
 const struct cpumask *tl_pkg_mask(struct sched_domain_topology_level *tl, int cpu)
 {
 	return cpu_node_mask(cpu);
Signature · 1 line
2.47.3

Otherwise, looks good to me.

Signature · 2 lines
Thanks and Regards
Srikar Dronamraju
#3 lore raw
In reply to Shrikanth Hegde
The following commit has been merged into the sched/core branch of tip:

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

Commit-ID:     1eae219ea0e80eed83c129e8cae0f007843f1893
Gitweb:        https://git.kernel.org/tip/1eae219ea0e80eed83c129e8cae0f007843f1893
Author:        Shrikanth Hegde <[email protected]>
AuthorDate:    Fri, 29 May 2026 13:27:12 +05:30
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Fri, 29 May 2026 12:43:15 +02:00

sched/topology: Provide arch_llc_mask for cache aware scheduling

Venkat Reported a boot kernel panic next-20260522. Git bisect pointed to b5ea300a17e3 ("sched/cache: Make LLC id continuous")

Stacktrace points to llc_mask being null.

NIP [c000000000e58504] _find_first_bit+0x44/0x130 LR [c000000000e58500] _find_first_bit+0x40/0x130

  Call Trace:
  build_sched_domains+0xad8/0xe50
  sched_init_smp+0xa8/0x164
  kernel_init_freeable+0x250/0x370
  ret_from_kernel_user_thread+0x14/0x1c

On powerpc, cpu_coregroup_mask is available only when the underlying hardware support coregroup. In shared LPAR, QEMU guest or power9 etc coregroup isn't supported. In such cases llc_mask was being referenced when it was null leading to panic.

On powerpc, LLC is at SMT core level. So assumption that coregroup(MC) domain point to LLC is wrong. Provide a way for archs to say where its LLC is if it not at MC domain.

---
 arch/powerpc/include/asm/topology.h |  7 +++++++
 kernel/sched/topology.c             | 13 +++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/topology.h +7 -0
index 66ed5fe..44ec416 100644
@@ -135,6 +135,13 @@ struct cpumask *cpu_coregroup_mask(int cpu);
 const struct cpumask *cpu_die_mask(int cpu);
 int cpu_die_id(int cpu);
 
+/*
+ * Points to where the LLC is. On power9 this will point at CACHE
+ * domain, On others it will point to SMT domain. In all cases
+ * cpu_l2_cache_mask points to where LLC is
+ */
+#define arch_llc_mask(cpu)     cpu_l2_cache_mask(cpu)
+
 #ifdef CONFIG_PPC64
 #include <asm/smp.h>
 
kernel/sched/topology.c +11 -2
index df2ceb5..622e2e0 100644
@@ -2063,12 +2063,21 @@ const struct cpumask *tl_mc_mask(struct sched_domain_topology_level *tl, int cpu
 	return cpu_coregroup_mask(cpu);
 }
 
-#define llc_mask(cpu) cpu_coregroup_mask(cpu)
+/*
+ * Majority of architectures have LLC at MC domain level with exception
+ * such as powerpc. Provide a way for arch to specify where its LLC is
+ * if it falls in exception category
+ */
+# ifndef arch_llc_mask
+#define arch_llc_mask(cpu) cpu_coregroup_mask(cpu)
+# endif
 
 #else
-#define llc_mask(cpu) cpumask_of(cpu)
+#define arch_llc_mask(cpu) cpumask_of(cpu)
 #endif
 
+#define llc_mask(cpu) arch_llc_mask(cpu)
+
 const struct cpumask *tl_pkg_mask(struct sched_domain_topology_level *tl, int cpu)
 {
 	return cpu_node_mask(cpu);