* [PATCH 0/4] Make cpumask_of_node() robust against NUMA_NO_NODE
@ 2026-01-05 10:05 John Garry
2026-01-05 10:05 ` [PATCH 1/4] include/asm-generic/topology.h: Remove unused definition of cpumask_of_node() John Garry
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: John Garry @ 2026-01-05 10:05 UTC (permalink / raw)
To: chenhuacai, kernel, jiaxun.yang, tsbogend, tglx, mingo, bp,
dave.hansen, hpa, luto, peterz, arnd, x86
Cc: loongarch, linux-kernel, linux-mips, linux-arch, vulab, gregkh,
rafael, dakr, John Garry
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/cf0f9085-6c87-4dd5-9114-925723e68495@oracle.com/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.
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 | 4 +++-
arch/mips/include/asm/mach-loongson64/topology.h | 4 +++-
arch/x86/include/asm/topology.h | 2 ++
arch/x86/mm/numa.c | 2 ++
include/asm-generic/topology.h | 8 ++------
5 files changed, 12 insertions(+), 8 deletions(-)
--
2.43.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] include/asm-generic/topology.h: Remove unused definition of cpumask_of_node()
2026-01-05 10:05 [PATCH 0/4] Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
@ 2026-01-05 10:05 ` John Garry
2026-01-05 10:05 ` [PATCH 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: John Garry @ 2026-01-05 10:05 UTC (permalink / raw)
To: chenhuacai, kernel, jiaxun.yang, tsbogend, tglx, mingo, bp,
dave.hansen, hpa, luto, peterz, arnd, x86
Cc: loongarch, linux-kernel, linux-mips, linux-arch, vulab, gregkh,
rafael, dakr, John Garry
The definition of cpumask_of_node() in question is guarded by conflicting
CONFIG_NUMA and !CONFIG_NUMA checks, so remove it.
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
include/asm-generic/topology.h | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/include/asm-generic/topology.h b/include/asm-generic/topology.h
index 4dbe715be65b4..9865ba48c5b16 100644
--- a/include/asm-generic/topology.h
+++ b/include/asm-generic/topology.h
@@ -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)
--
2.43.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE
2026-01-05 10:05 [PATCH 0/4] Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
2026-01-05 10:05 ` [PATCH 1/4] include/asm-generic/topology.h: Remove unused definition of cpumask_of_node() John Garry
@ 2026-01-05 10:05 ` John Garry
2026-01-05 12:54 ` Huacai Chen
2026-01-05 10:05 ` [PATCH 3/4] MIPS: Loongson: " John Garry
2026-01-05 10:05 ` [PATCH 4/4] x86/cpu/topology: " John Garry
3 siblings, 1 reply; 7+ messages in thread
From: John Garry @ 2026-01-05 10:05 UTC (permalink / raw)
To: chenhuacai, kernel, jiaxun.yang, tsbogend, tglx, mingo, bp,
dave.hansen, hpa, luto, peterz, arnd, x86
Cc: loongarch, linux-kernel, linux-mips, linux-arch, vulab, gregkh,
rafael, dakr, John Garry
The arch definition of cpumask_of_node() cannot handle NUMA_NO_NODE - which
is a valid index - so add a check for this.
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
arch/loongarch/include/asm/topology.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/include/asm/topology.h b/arch/loongarch/include/asm/topology.h
index f06e7ff25bb7c..9857e4c20023c 100644
--- a/arch/loongarch/include/asm/topology.h
+++ b/arch/loongarch/include/asm/topology.h
@@ -12,7 +12,9 @@
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/4] MIPS: Loongson: Make cpumask_of_node() robust against NUMA_NO_NODE
2026-01-05 10:05 [PATCH 0/4] Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
2026-01-05 10:05 ` [PATCH 1/4] include/asm-generic/topology.h: Remove unused definition of cpumask_of_node() John Garry
2026-01-05 10:05 ` [PATCH 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
@ 2026-01-05 10:05 ` John Garry
2026-01-05 10:05 ` [PATCH 4/4] x86/cpu/topology: " John Garry
3 siblings, 0 replies; 7+ messages in thread
From: John Garry @ 2026-01-05 10:05 UTC (permalink / raw)
To: chenhuacai, kernel, jiaxun.yang, tsbogend, tglx, mingo, bp,
dave.hansen, hpa, luto, peterz, arnd, x86
Cc: loongarch, linux-kernel, linux-mips, linux-arch, vulab, gregkh,
rafael, dakr, John Garry
The arch definition of cpumask_of_node() cannot handle NUMA_NO_NODE - which
is a valid index - so add a check for this.
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
arch/mips/include/asm/mach-loongson64/topology.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/mips/include/asm/mach-loongson64/topology.h b/arch/mips/include/asm/mach-loongson64/topology.h
index 3414a1fd17835..e897dddc1366e 100644
--- a/arch/mips/include/asm/mach-loongson64/topology.h
+++ b/arch/mips/include/asm/mach-loongson64/topology.h
@@ -7,7 +7,9 @@
#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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/4] x86/cpu/topology: Make cpumask_of_node() robust against NUMA_NO_NODE
2026-01-05 10:05 [PATCH 0/4] Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
` (2 preceding siblings ...)
2026-01-05 10:05 ` [PATCH 3/4] MIPS: Loongson: " John Garry
@ 2026-01-05 10:05 ` John Garry
3 siblings, 0 replies; 7+ messages in thread
From: John Garry @ 2026-01-05 10:05 UTC (permalink / raw)
To: chenhuacai, kernel, jiaxun.yang, tsbogend, tglx, mingo, bp,
dave.hansen, hpa, luto, peterz, arnd, x86
Cc: loongarch, linux-kernel, linux-mips, linux-arch, vulab, gregkh,
rafael, dakr, John Garry
The arch definitions of cpumask_of_node() cannot handle NUMA_NO_NODE -
which is a valid index - so add checks for this.
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
arch/x86/include/asm/topology.h | 2 ++
arch/x86/mm/numa.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index 1fadf0cf520c5..b51f2e771a582 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -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
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 7a97327140df8..0be94f4682232 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -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",
--
2.43.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE
2026-01-05 10:05 ` [PATCH 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
@ 2026-01-05 12:54 ` Huacai Chen
2026-01-05 14:09 ` John Garry
0 siblings, 1 reply; 7+ messages in thread
From: Huacai Chen @ 2026-01-05 12:54 UTC (permalink / raw)
To: John Garry
Cc: kernel, jiaxun.yang, tsbogend, tglx, mingo, bp, dave.hansen, hpa,
luto, peterz, arnd, x86, loongarch, linux-kernel, linux-mips,
linux-arch, vulab, gregkh, rafael, dakr
Hi, John,
On Mon, Jan 5, 2026 at 6:07 PM John Garry <john.g.garry@oracle.com> wrote:
>
> The arch definition of cpumask_of_node() cannot handle NUMA_NO_NODE - which
> is a valid index - so add a check for this.
>
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
> arch/loongarch/include/asm/topology.h | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/include/asm/topology.h b/arch/loongarch/include/asm/topology.h
> index f06e7ff25bb7c..9857e4c20023c 100644
> --- a/arch/loongarch/include/asm/topology.h
> +++ b/arch/loongarch/include/asm/topology.h
> @@ -12,7 +12,9 @@
>
> 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])
You can define it in one line, so does the MIPS version.
Huacai
>
> struct pci_bus;
> extern int pcibus_to_node(struct pci_bus *);
> --
> 2.43.5
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE
2026-01-05 12:54 ` Huacai Chen
@ 2026-01-05 14:09 ` John Garry
0 siblings, 0 replies; 7+ messages in thread
From: John Garry @ 2026-01-05 14:09 UTC (permalink / raw)
To: Huacai Chen
Cc: kernel, jiaxun.yang, tsbogend, tglx, mingo, bp, dave.hansen, hpa,
luto, peterz, arnd, x86, loongarch, linux-kernel, linux-mips,
linux-arch, vulab, gregkh, rafael, dakr
On 05/01/2026 12:54, Huacai Chen wrote:
> Hi, John,
>
> On Mon, Jan 5, 2026 at 6:07 PM John Garry <john.g.garry@oracle.com> wrote:
>>
>> The arch definition of cpumask_of_node() cannot handle NUMA_NO_NODE - which
>> is a valid index - so add a check for this.
>>
>> Signed-off-by: John Garry <john.g.garry@oracle.com>
>> ---
>> arch/loongarch/include/asm/topology.h | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/loongarch/include/asm/topology.h b/arch/loongarch/include/asm/topology.h
>> index f06e7ff25bb7c..9857e4c20023c 100644
>> --- a/arch/loongarch/include/asm/topology.h
>> +++ b/arch/loongarch/include/asm/topology.h
>> @@ -12,7 +12,9 @@
>>
>> 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])
> You can define it in one line, so does the MIPS version.
>
ok, I can do it that way if you prefer. The reason I had it in flow was:
- a single line will overflow 80 characters, which some people still
prefer not doing
- following example of other archs and general coding style to split
macros functions across multiple lines.
Thanks,
John
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-01-05 14:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05 10:05 [PATCH 0/4] Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
2026-01-05 10:05 ` [PATCH 1/4] include/asm-generic/topology.h: Remove unused definition of cpumask_of_node() John Garry
2026-01-05 10:05 ` [PATCH 2/4] LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE John Garry
2026-01-05 12:54 ` Huacai Chen
2026-01-05 14:09 ` John Garry
2026-01-05 10:05 ` [PATCH 3/4] MIPS: Loongson: " John Garry
2026-01-05 10:05 ` [PATCH 4/4] x86/cpu/topology: " John Garry
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®