Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/numa: Store extra copy of numa_nodes_parsed

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

+16
+6
arch/x86/include/asm/numa.h
··· 22 22 */ 23 23 extern s16 __apicid_to_node[MAX_LOCAL_APIC]; 24 24 extern nodemask_t numa_nodes_parsed __initdata; 25 + extern nodemask_t numa_phys_nodes_parsed __initdata; 25 26 26 27 static inline void set_apicid_to_node(int apicid, s16 node) 27 28 { ··· 49 48 extern void numa_add_cpu(unsigned int cpu); 50 49 extern void numa_remove_cpu(unsigned int cpu); 51 50 extern void init_gi_nodes(void); 51 + extern int num_phys_nodes(void); 52 52 #else /* CONFIG_NUMA */ 53 53 static inline void numa_set_node(int cpu, int node) { } 54 54 static inline void numa_clear_node(int cpu) { } ··· 57 55 static inline void numa_add_cpu(unsigned int cpu) { } 58 56 static inline void numa_remove_cpu(unsigned int cpu) { } 59 57 static inline void init_gi_nodes(void) { } 58 + static inline int num_phys_nodes(void) 59 + { 60 + return 1; 61 + } 60 62 #endif /* CONFIG_NUMA */ 61 63 62 64 #ifdef CONFIG_DEBUG_PER_CPU_MAPS
+8
arch/x86/mm/numa.c
··· 48 48 [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE 49 49 }; 50 50 51 + nodemask_t numa_phys_nodes_parsed __initdata; 52 + 51 53 int numa_cpu_node(int cpu) 52 54 { 53 55 u32 apicid = early_per_cpu(x86_cpu_to_apicid, cpu); ··· 57 55 if (apicid != BAD_APICID) 58 56 return __apicid_to_node[apicid]; 59 57 return NUMA_NO_NODE; 58 + } 59 + 60 + int __init num_phys_nodes(void) 61 + { 62 + return bitmap_weight(numa_phys_nodes_parsed.bits, MAX_NUMNODES); 60 63 } 61 64 62 65 cpumask_var_t node_to_cpumask_map[MAX_NUMNODES]; ··· 217 210 0LLU, PFN_PHYS(max_pfn) - 1); 218 211 219 212 node_set(0, numa_nodes_parsed); 213 + node_set(0, numa_phys_nodes_parsed); 220 214 numa_add_memblk(0, 0, PFN_PHYS(max_pfn)); 221 215 222 216 return 0;
+2
arch/x86/mm/srat.c
··· 57 57 } 58 58 set_apicid_to_node(apic_id, node); 59 59 node_set(node, numa_nodes_parsed); 60 + node_set(node, numa_phys_nodes_parsed); 60 61 pr_debug("SRAT: PXM %u -> APIC 0x%04x -> Node %u\n", pxm, apic_id, node); 61 62 } 62 63 ··· 98 97 99 98 set_apicid_to_node(apic_id, node); 100 99 node_set(node, numa_nodes_parsed); 100 + node_set(node, numa_phys_nodes_parsed); 101 101 pr_debug("SRAT: PXM %u -> APIC 0x%02x -> Node %u\n", pxm, apic_id, node); 102 102 } 103 103