Make cpumask_of_node() robust against NUMA_NO_NODE
Subsystems (6)
v2 cover Make cpumask_of_node() robust against NUMA_NO_NODE
This series aims to remedy an issue that not all per-arch versions of cpumask_of_node() are robust against NUMA_NO_NODE.
In my view, cpumask_of_node() should be able to handle NUMA_NO_NODE. This is because NUMA_NO_NODE is a valid index from the following flow, where the device NUMA node is not set (from default):
device_initialize(dev)
set_dev_node(dev, NUMA_NO_NODE);
mask = cpumask_of_node(dev_to_node(dev));
The CONFIG_DEBUG_PER_CPU_MAPS=n x86 version cpumask_of_node() would produce an array out-of-index issue (when passed NUMA_NO_NODE), which I think is attempted to be worked around here:
https://lore.kernel.org/linux-scsi/[email protected]/T/#mdedb68052e419b4bfca9ce45bb33b58988018945
I also see a CVE which also looks related:
https://nvd.nist.gov/vuln/detail/cve-2024-39277
Each per-arch version could be picked up separately, as can the asm-generic change.
Differences to v1:
- Put mips and loongarch definition on a single line (Huacai)
John Garry (4):
include/asm-generic/topology.h: Remove unused definition of
cpumask_of_node()
LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE
MIPS: Loongson: Make cpumask_of_node() robust against NUMA_NO_NODE x86/cpu/topology: Make cpumask_of_node() robust against NUMA_NO_NODE
arch/loongarch/include/asm/topology.h | 2 +- arch/mips/include/asm/mach-loongson64/topology.h | 2 +- arch/x86/include/asm/topology.h | 2 ++ arch/x86/mm/numa.c | 2 ++ include/asm-generic/topology.h | 8 ++------ 5 files changed, 8 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.5
PATCH v2 1/4 include/asm-generic/topology.h: Remove unused definition of cpumask_of_node()
The definition of cpumask_of_node() in question is guarded by conflicting CONFIG_NUMA and !CONFIG_NUMA checks, so remove it.
--- include/asm-generic/topology.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
include/asm-generic/topology.h +2 -6
@@ -45,11 +45,7 @@#endif #ifndef cpumask_of_node -#ifdef CONFIG_NUMA -#define cpumask_of_node (node) ((node) == 0 ? cpu_online_mask : cpu_none_mask) -#else -#define cpumask_of_node (node) ((void)(node), cpu_online_mask) -#endif +#define cpumask_of_node (node) ((void)(node), cpu_online_mask)#endif #ifndef pcibus_to_node#define pcibus_to_node (bus) ((void)(bus), -1)
@@ -61,7 +57,7 @@ cpumask_of_node(pcibus_to_node(bus)))#endif -#endif /* CONFIG_NUMA */ +#endif /* !CONFIG_NUMA */ #if !defined(CONFIG_NUMA ) || !defined(CONFIG_HAVE_MEMORYLESS_NODES )
Signature · 1 line
2.43.5
Re: [PATCH v2 1/4] include/asm-generic/topology.h: Remove unused definition of cpumask_of_node()
Quoted 2 lines · John Garry
The definition of
cpumask_of_node()in question is guarded by conflictingCONFIG_NUMAand !CONFIG_NUMA checks, so remove it.
Arnd, can you consider picking this up please?
Thanks
Quoted 32 lines
Signed-off-by John Garry <[email protected]>--- include/asm-generic/topology.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)include/asm-generic/topology.h +2
-6@@ -45,11 +45,7 @@#endif #ifndef cpumask_of_node -#ifdef CONFIG_NUMA -#define cpumask_of_node (node) ((node) == 0 ? cpu_online_mask : cpu_none_mask) -#else -#define cpumask_of_node (node) ((void)(node), cpu_online_mask) -#endif +#define cpumask_of_node (node) ((void)(node), cpu_online_mask)#endif #ifndef pcibus_to_node#define pcibus_to_node (bus) ((void)(bus), -1)@@ -61,7 +57,7 @@ cpumask_of_node(pcibus_to_node(bus)))#endif -#endif /* CONFIG_NUMA */ +#endif /* !CONFIG_NUMA */ #if !defined(CONFIG_NUMA ) || !defined(CONFIG_HAVE_MEMORYLESS_NODES )
Arnd Bergmann
maintainerRe: [PATCH v2 1/4] include/asm-generic/topology.h: Remove unused definition of cpumask_of_node()
Quoted 5 lines · John Garry
Quoted 2 lines · John Garry
The definition of
cpumask_of_node()in question is guarded by conflictingCONFIG_NUMAand !CONFIG_NUMA checks, so remove it.Arnd, can you consider picking this up please?
Merged now, sorry missing this earlier.
Arnd
PATCH v2 2/4 LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE
In reply to John GarryThe arch definition of cpumask_of_node() cannot handle NUMA_NO_NODE - which is a valid index - so add a check for this.
--- arch/loongarch/include/asm/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/loongarch/include/asm/topology.h +1 -1
@@ -12,7 +12,7 @@extern cpumask_t cpus_on_node[]; -#define cpumask_of_node (node) (&cpus_on_node[node]) +#define cpumask_of_node (node) ((node) == NUMA_NO_NODE ? cpu_all_mask : &cpus_on_node[node])struct pci_bus ;extern int pcibus_to_node (struct pci_bus *);
Signature · 1 line
2.43.5
Re: [PATCH v2 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE
Quoted 25 lines · John Garry
The arch definition of
cpumask_of_node()cannot handleNUMA_NO_NODE- which is a valid index - so add a check for this.Signed-off-by John Garry <[email protected]>--- arch/loongarch/include/asm/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/loongarch/include/asm/topology.h +1
-2@@ -12,7 +12,7 @@extern cpumask_t cpus_on_node[]; -#define cpumask_of_node (node) (&cpus_on_node[node]) +#define cpumask_of_node (node) ((node) == NUMA_NO_NODE ? cpu_all_mask : &cpus_on_node[node])struct pci_bus ;extern int pcibus_to_node (struct pci_bus *); --2.43.5
Re: [PATCH v2 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE
Quoted 1 line · Huacai Chen
Reviewed-by Huacai Chen <[email protected]>
Thanks
So can a loongarch maintainer pick this up please?
Quoted 27 lines · John Garry
Quoted 25 lines
The arch definition of
cpumask_of_node()cannot handleNUMA_NO_NODE- which is a valid index - so add a check for this.Signed-off-by John Garry <[email protected]>--- arch/loongarch/include/asm/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/loongarch/include/asm/topology.h +1
-2@@ -12,7 +12,7 @@extern cpumask_t cpus_on_node[]; -#define cpumask_of_node (node) (&cpus_on_node[node]) +#define cpumask_of_node (node) ((node) == NUMA_NO_NODE ? cpu_all_mask : &cpus_on_node[node])struct pci_bus ;extern int pcibus_to_node (struct pci_bus *); --2.43.5
Huacai Chen
maintainerRe: [PATCH v2 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE
Quoted 7 lines · John Garry
Quoted 1 line · Huacai Chen
Reviewed-by Huacai Chen <[email protected]>Thanks
So can a loongarch maintainer pick this up please?
OK, applied.
Huacai
Quoted 29 lines
Quoted 28 lines · John Garry
Quoted 25 lines
The arch definition of
cpumask_of_node()cannot handleNUMA_NO_NODE- which is a valid index - so add a check for this.Signed-off-by John Garry <[email protected]>--- arch/loongarch/include/asm/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/loongarch/include/asm/topology.h +1
-2@@ -12,7 +12,7 @@extern cpumask_t cpus_on_node[]; -#define cpumask_of_node (node) (&cpus_on_node[node]) +#define cpumask_of_node (node) ((node) == NUMA_NO_NODE ? cpu_all_mask : &cpus_on_node[node])struct pci_bus ;extern int pcibus_to_node (struct pci_bus *); --2.43.5
PATCH v2 3/4 MIPS: Loongson: Make cpumask_of_node() robust against NUMA_NO_NODE
In reply to John GarryThe arch definition of cpumask_of_node() cannot handle NUMA_NO_NODE - which is a valid index - so add a check for this.
--- arch/mips/include/asm/mach-loongson64/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/mach-loongson64/topology.h +1 -1
@@ -7,7 +7,7 @@#define cpu_to_node (cpu) (cpu_logical_map(cpu) >> 2)extern cpumask_t __node_cpumask[]; -#define cpumask_of_node (node) (&__node_cpumask[node]) +#define cpumask_of_node (node) ((node) == NUMA_NO_NODE ? cpu_all_mask : &__node_cpumask[node])struct pci_bus ;extern int pcibus_to_node (struct pci_bus *);
Signature · 1 line
2.43.5
Re: [PATCH v2 3/4] MIPS: Loongson: Make cpumask_of_node() robust against NUMA_NO_NODE
Quoted 25 lines · John Garry
The arch definition of
cpumask_of_node()cannot handleNUMA_NO_NODE- which is a valid index - so add a check for this.Signed-off-by John Garry <[email protected]>--- arch/mips/include/asm/mach-loongson64/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/mips/include/asm/mach-loongson64/topology.h +1
-2@@ -7,7 +7,7 @@#define cpu_to_node (cpu) (cpu_logical_map(cpu) >> 2)extern cpumask_t __node_cpumask[]; -#define cpumask_of_node (node) (&__node_cpumask[node]) +#define cpumask_of_node (node) ((node) == NUMA_NO_NODE ? cpu_all_mask : &__node_cpumask[node])struct pci_bus ;extern int pcibus_to_node (struct pci_bus *); --2.43.5
Re: [PATCH v2 3/4] MIPS: Loongson: Make cpumask_of_node() robust against NUMA_NO_NODE
Quoted 1 line · Huacai Chen
Reviewed-by Huacai Chen <[email protected]>
Thanks
So can a loongarch or mips maintainer pick this up please?
Quoted 27 lines · John Garry
Quoted 25 lines
The arch definition of
cpumask_of_node()cannot handleNUMA_NO_NODE- which is a valid index - so add a check for this.Signed-off-by John Garry <[email protected]>--- arch/mips/include/asm/mach-loongson64/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/mips/include/asm/mach-loongson64/topology.h +1
-2@@ -7,7 +7,7 @@#define cpu_to_node (cpu) (cpu_logical_map(cpu) >> 2)extern cpumask_t __node_cpumask[]; -#define cpumask_of_node (node) (&__node_cpumask[node]) +#define cpumask_of_node (node) ((node) == NUMA_NO_NODE ? cpu_all_mask : &__node_cpumask[node])struct pci_bus ;extern int pcibus_to_node (struct pci_bus *); --2.43.5
Thomas Bogendoerfer
maintainerRe: [PATCH v2 3/4] MIPS: Loongson: Make cpumask_of_node() robust against NUMA_NO_NODE
Quoted 6 lines · John Garry
Quoted 1 line · Huacai Chen
Reviewed-by Huacai Chen <[email protected]>Thanks
So can a loongarch or mips maintainer pick this up please?
I'll take MIPS patch.
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]
Re: [PATCH v2 3/4] MIPS: Loongson: Make cpumask_of_node() robust against NUMA_NO_NODE
In reply to John GarryQuoted 23 lines · John Garry
The arch definition of
cpumask_of_node()cannot handleNUMA_NO_NODE- which is a valid index - so add a check for this.Signed-off-by John Garry <[email protected]>--- arch/mips/include/asm/mach-loongson64/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/mips/include/asm/mach-loongson64/topology.h +1
-1@@ -7,7 +7,7 @@#define cpu_to_node (cpu) (cpu_logical_map(cpu) >> 2)extern cpumask_t __node_cpumask[]; -#define cpumask_of_node (node) (&__node_cpumask[node]) +#define cpumask_of_node (node) ((node) == NUMA_NO_NODE ? cpu_all_mask : &__node_cpumask[node])struct pci_bus ;extern int pcibus_to_node (struct pci_bus *);Signature · 1 line
2.43.5
applied to mips-next
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]
PATCH v2 4/4 x86/cpu/topology: Make cpumask_of_node() robust against NUMA_NO_NODE
In reply to John GarryThe arch definitions of cpumask_of_node() cannot handle NUMA_NO_NODE - which is a valid index - so add checks for this.
--- arch/x86/include/asm/topology.h | 2 ++ arch/x86/mm/numa.c | 2 ++ 2 files changed, 4 insertions(+)
arch/x86/include/asm/topology.h +2 -0
@@ -69,6 +69,8 @@ extern const struct cpumask *cpumask_of_node(int node);/* Returns a pointer to the cpumask of CPUs on Node 'node'. */ static inline const struct cpumask *cpumask_of_node (int node) { +if (node ==NUMA_NO_NODE ) +return cpu_all_mask;return node_to_cpumask_map[node]; }#endif
arch/x86/mm/numa.c +2 -0
@@ -408,6 +408,8 @@ void numa_remove_cpu(unsigned int cpu)*/ const struct cpumask *cpumask_of_node (int node) { +if (node ==NUMA_NO_NODE ) +return cpu_all_mask;if ((unsigned )node >= nr_node_ids) { printk(KERN_WARNING "cpumask_of_node(%d): (unsigned)node >= nr_node_ids(%u)\n",
Signature · 1 line
2.43.5
On 07/01/2026 09:40, John Garry wrote:
A friendly reminder on this one.
Thanks
Quoted 40 lines
This series aims to remedy an issue that not all per-arch versions of
cpumask_of_node()are robust againstNUMA_NO_NODE.In my view,
cpumask_of_node()should be able to handleNUMA_NO_NODE. This is becauseNUMA_NO_NODEis a valid index from the following flow, where the device NUMA node is not set (from default):
device_initialize(dev)set_dev_node(dev, NUMA_NO_NODE);mask = cpumask_of_node(dev_to_node(dev));
The
CONFIG_DEBUG_PER_CPU_MAPS=nx86 versioncpumask_of_node()would produce an array out-of-index issue (when passedNUMA_NO_NODE), which I think is attempted to be worked around here:
https://lore.kernel.org/linux-scsi/[email protected]/T/#mdedb68052e419b4bfca9ce45bb33b58988018945I also see a CVE which also looks related:
https://nvd.nist.gov/vuln/detail/cve-2024-39277Each per-arch version could be picked up separately, as can the asm-generic change.
Differences to v1:
- Put mips and loongarch definition on a single line (Huacai)John Garry (4):
include/asm-generic/topology.h: Remove unused definition of
cpumask_of_node()
LoongArch: Makecpumask_of_node()robust againstNUMA_NO_NODE
MIPS: Loongson: Makecpumask_of_node()robust againstNUMA_NO_NODEx86/cpu/topology: Makecpumask_of_node()robust againstNUMA_NO_NODEarch/loongarch/include/asm/topology.h | 2 +- arch/mips/include/asm/mach-loongson64/topology.h | 2 +- arch/x86/include/asm/topology.h | 2 ++ arch/x86/mm/numa.c | 2 ++ include/asm-generic/topology.h | 8 ++------ 5 files changed, 8 insertions(+), 8 deletions(-)