]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/numa: Store extra copy of numa_nodes_parsed
authorPeter Zijlstra <peterz@infradead.org>
Tue, 3 Mar 2026 10:55:40 +0000 (11:55 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 4 Mar 2026 15:35:08 +0000 (16:35 +0100)
The topology setup code needs to know the total number of physical
nodes enumerated in SRAT; however NUMA_EMU can cause the existing
numa_nodes_parsed bitmap to be fictitious. Therefore, keep a copy of
the bitmap specifically to retain the physical node count.

Suggested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Tested-by: Chen Yu <yu.c.chen@intel.com>
Tested-by: Kyle Meyer <kyle.meyer@hpe.com>
Link: https://patch.msgid.link/20260303110059.889884023@infradead.org
arch/x86/include/asm/numa.h
arch/x86/mm/numa.c
arch/x86/mm/srat.c

index 53ba39ce010cda8dd1e53ea3e5122cdffb992e40..a9063f332fa6e5cb0480afb0b14dbf06a4dce3f2 100644 (file)
@@ -22,6 +22,7 @@ extern int numa_off;
  */
 extern s16 __apicid_to_node[MAX_LOCAL_APIC];
 extern nodemask_t numa_nodes_parsed __initdata;
+extern nodemask_t numa_phys_nodes_parsed __initdata;
 
 static inline void set_apicid_to_node(int apicid, s16 node)
 {
@@ -48,6 +49,7 @@ extern void __init init_cpu_to_node(void);
 extern void numa_add_cpu(unsigned int cpu);
 extern void numa_remove_cpu(unsigned int cpu);
 extern void init_gi_nodes(void);
+extern int num_phys_nodes(void);
 #else  /* CONFIG_NUMA */
 static inline void numa_set_node(int cpu, int node)    { }
 static inline void numa_clear_node(int cpu)            { }
@@ -55,6 +57,10 @@ static inline void init_cpu_to_node(void)            { }
 static inline void numa_add_cpu(unsigned int cpu)      { }
 static inline void numa_remove_cpu(unsigned int cpu)   { }
 static inline void init_gi_nodes(void)                 { }
+static inline int num_phys_nodes(void)
+{
+       return 1;
+}
 #endif /* CONFIG_NUMA */
 
 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
index 7a97327140df89c09b2943336ae6b1978d06c27f..99d0a9332c1459e242060fc178ef3dbbed923fdc 100644 (file)
@@ -48,6 +48,8 @@ s16 __apicid_to_node[MAX_LOCAL_APIC] = {
        [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
 };
 
+nodemask_t numa_phys_nodes_parsed __initdata;
+
 int numa_cpu_node(int cpu)
 {
        u32 apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
@@ -57,6 +59,11 @@ int numa_cpu_node(int cpu)
        return NUMA_NO_NODE;
 }
 
+int __init num_phys_nodes(void)
+{
+       return bitmap_weight(numa_phys_nodes_parsed.bits, MAX_NUMNODES);
+}
+
 cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
 EXPORT_SYMBOL(node_to_cpumask_map);
 
@@ -210,6 +217,7 @@ static int __init dummy_numa_init(void)
               0LLU, PFN_PHYS(max_pfn) - 1);
 
        node_set(0, numa_nodes_parsed);
+       node_set(0, numa_phys_nodes_parsed);
        numa_add_memblk(0, 0, PFN_PHYS(max_pfn));
 
        return 0;
index 6f8e0f21c7103de38a346ee980f5de575e8008d1..44ca66651756170091dd1bf279aedea84e1e50a6 100644 (file)
@@ -57,6 +57,7 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
        }
        set_apicid_to_node(apic_id, node);
        node_set(node, numa_nodes_parsed);
+       node_set(node, numa_phys_nodes_parsed);
        pr_debug("SRAT: PXM %u -> APIC 0x%04x -> Node %u\n", pxm, apic_id, node);
 }
 
@@ -97,6 +98,7 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
 
        set_apicid_to_node(apic_id, node);
        node_set(node, numa_nodes_parsed);
+       node_set(node, numa_phys_nodes_parsed);
        pr_debug("SRAT: PXM %u -> APIC 0x%02x -> Node %u\n", pxm, apic_id, node);
 }