Skip to contentSkip to conversation

arm64: irq: set the correct node for VMAP stack

PATCH Superseded Huang Shijie 5 participants 10 messages Nov 14, 2023 – Dec 5, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: irq: set the correct node for VMAP stack

In current code, init_irq_stacks() will call cpu_to_node(). The cpu_to_node() depends on percpu "numa_node" which is initialized in:

     arch_call_rest_init() --> rest_init() -- kernel_init()
	--> kernel_init_freeable() --> smp_prepare_cpus()

But init_irq_stacks() is called in init_IRQ() which is before arch_call_rest_init().

So in init_irq_stacks(), the cpu_to_node() does not work, it always return 0. In NUMA, it makes the node 1 cpu accesses the IRQ stack which is in the node 0.

This patch fixes it by exporting the early_cpu_to_node(), and use it in the init_irq_stacks().

---
 arch/arm64/kernel/irq.c    | 2 +-
 drivers/base/arch_numa.c   | 2 +-
 include/asm-generic/numa.h | 1 +
 3 files changed, 3 insertions(+), 2 deletions(-)
arch/arm64/kernel/irq.c +1 -1
index 6ad5c6ef5329..e62d3cb3f74c 100644
@@ -57,7 +57,7 @@ static void init_irq_stacks(void)
 	unsigned long *p;
 
 	for_each_possible_cpu(cpu) {
-		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu));
+		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
 		per_cpu(irq_stack_ptr, cpu) = p;
 	}
 }
drivers/base/arch_numa.c +1 -1
index eaa31e567d1e..90519d981471 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-static int __init early_cpu_to_node(int cpu)
+int early_cpu_to_node(int cpu)
 {
 	return cpu_to_node_map[cpu];
 }
include/asm-generic/numa.h +1 -0
index 1a3ad6d29833..fc8a9bd6a444 100644
@@ -38,6 +38,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid);
 void numa_store_cpu_info(unsigned int cpu);
 void numa_add_cpu(unsigned int cpu);
 void numa_remove_cpu(unsigned int cpu);
+int early_cpu_to_node(int cpu);
 
 #else	/* CONFIG_NUMA */
 
Signature · 1 line
2.40.1
#1 lore raw
kernel test robot noticed the following build errors:

Hi Huang,

kernel test robot noticed the following build errors:

[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on driver-core/driver-core-testing driver-core/driver-core-next driver-core/driver-core-linus arnd-asm-generic/master linus/master v6.7-rc1 next-20231115] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Huang-Shijie/arm64-irq-set-the-correct-node-for-VMAP-stack/20231114-171932
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
patch link:    https://lore.kernel.org/r/20231114091643.59530-1-shijie%40os.amperecomputing.com
patch subject: [PATCH] arm64: irq: set the correct node for VMAP stack
config: arm64-randconfig-001-20231115 (https://download.01.org/0day-ci/archive/20231115/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231115/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

arch/arm64/kernel/irq.c: In function 'init_irq_stacks':

>> arch/arm64/kernel/irq.c:60:59: error: implicit declaration of function 'early_cpu_to_node'; did you mean 'early_pfn_to_nid'? [-Werror=implicit-function-declaration]
      60 |                 p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
         |                                                           ^~~~~~~~~~~~~~~~~
         |                                                           early_pfn_to_nid

cc1: some warnings being treated as errors

vim +60 arch/arm64/kernel/irq.c

    52	
    53	#ifdef CONFIG_VMAP_STACK
    54	static void init_irq_stacks(void)
    55	{
    56		int cpu;
    57		unsigned long *p;
    58	
    59		for_each_possible_cpu(cpu) {
  > 60			p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
    61			per_cpu(irq_stack_ptr, cpu) = p;
    62		}
    63	}
    64	#else
    65	/* irq stack only needs to be 16 byte aligned - not IRQ_STACK_SIZE aligned. */
    66	DEFINE_PER_CPU_ALIGNED(unsigned long [IRQ_STACK_SIZE/sizeof(long)], irq_stack);
    67	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#2 lore raw
In reply to Huang Shijie

arch/arm64/kernel/irq.c static void init_irq_stacks(void) · line 63

Quoted 13 lines · Huang Shijie
arch/arm64/kernel/irq.c +1 -1
index 6ad5c6ef5329..e62d3cb3f74c 100644
@@ -57,7 +57,7 @@ static void init_irq_stacks(void)
 	unsigned long *p;
 
 	for_each_possible_cpu(cpu) {
-		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu));
+		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
 		per_cpu(irq_stack_ptr, cpu) = p;
 	}
 }

This looks alright to me, I don't have a better suggestion. The generic code already has the cpu_to_node_map[] array populated by early_map_cpu_to_node(), so let's reuse it.

Quoted 18 lines
drivers/base/arch_numa.c +1 -1
index eaa31e567d1e..90519d981471 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-static int __init early_cpu_to_node(int cpu)
+int early_cpu_to_node(int cpu)
 {
 	return cpu_to_node_map[cpu];
 }
include/asm-generic/numa.h +0 -0
index 1a3ad6d29833..fc8a9bd6a444 100644

include/asm-generic/numa.h void __init early_map_cpu_to_node(unsigned int cpu, int nid); · line 41

Quoted 4 lines
include/asm-generic/numa.h +1 -0
@@ -38,6 +38,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid);
 void numa_store_cpu_info(unsigned int cpu);
 void numa_add_cpu(unsigned int cpu);
 void numa_remove_cpu(unsigned int cpu);
+int early_cpu_to_node(int cpu);

Here I'd move this just below early_map_cpu_to_node() and, for completeness, also add the dummy static inline for the !NUMA case.

Signature · 1 line
Catalin
#3 lore raw

Hi Catalin,

Quoted 26 lines · Catalin Marinas

arch/arm64/kernel/irq.c static void init_irq_stacks(void) · line 63

Quoted 13 lines · Huang Shijie
arch/arm64/kernel/irq.c +1 -1
index 6ad5c6ef5329..e62d3cb3f74c 100644
@@ -57,7 +57,7 @@ static void init_irq_stacks(void)
  	unsigned long *p;
 
  	for_each_possible_cpu(cpu) {
-		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu));
+		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
  		per_cpu(irq_stack_ptr, cpu) = p;
  	}
  }

This looks alright to me, I don't have a better suggestion. The generic code already has the cpu_to_node_map[] array populated by early_map_cpu_to_node(), so let's reuse it.

Quoted 8 lines
drivers/base/arch_numa.c +0 -0
index eaa31e567d1e..90519d981471 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
  unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
  EXPORT_SYMBOL(__per_cpu_offset);
 
Quoted 16 lines
Quoted 10 lines
drivers/base/arch_numa.c +1 -1
-static int __init early_cpu_to_node(int cpu)
+int early_cpu_to_node(int cpu)
  {
  	return cpu_to_node_map[cpu];
  }
include/asm-generic/numa.h +0 -0
index 1a3ad6d29833..fc8a9bd6a444 100644

include/asm-generic/numa.h void __init early_map_cpu_to_node(unsigned int cpu, int nid); · line 41

Quoted 4 lines
include/asm-generic/numa.h +1 -0
@@ -38,6 +38,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid);
  void numa_store_cpu_info(unsigned int cpu);
  void numa_add_cpu(unsigned int cpu);
  void numa_remove_cpu(unsigned int cpu);
+int early_cpu_to_node(int cpu);

Here I'd move this just below early_map_cpu_to_node() and, for completeness, also add the dummy static inline for the !NUMA case.

Thanks a lot.  It seems there is no need for me to send the V2 for this.

Thanks

Huang Shijie

#4 lore raw

PATCH v2 1/1 arm64: irq: set the correct node for VMAP stack

In reply to Catalin Marinas

In current code, init_irq_stacks() will call cpu_to_node(). The cpu_to_node() depends on percpu "numa_node" which is initialized in:

     arch_call_rest_init() --> rest_init() -- kernel_init()
	--> kernel_init_freeable() --> smp_prepare_cpus()

But init_irq_stacks() is called in init_IRQ() which is before arch_call_rest_init().

So in init_irq_stacks(), the cpu_to_node() does not work, it always return 0. In NUMA, it makes the node 1 cpu accesses the IRQ stack which is in the node 0.

This patch fixes it by exporting the early_cpu_to_node(), and use it in the init_irq_stacks().

---
v1 --> v2:
fix the !NUMA compiling error.

---
 arch/arm64/kernel/irq.c    | 3 ++-
 drivers/base/arch_numa.c   | 2 +-
 include/asm-generic/numa.h | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
arch/arm64/kernel/irq.c +2 -1
index 6ad5c6ef5329..5226030979ae 100644
@@ -25,6 +25,7 @@
 #include <asm/softirq_stack.h>
 #include <asm/stacktrace.h>
 #include <asm/vmap_stack.h>
+#include <asm/numa.h>
 
 /* Only access this in an NMI enter/exit */
 DEFINE_PER_CPU(struct nmi_ctx, nmi_contexts);
@@ -57,7 +58,7 @@ static void init_irq_stacks(void)
 	unsigned long *p;
 
 	for_each_possible_cpu(cpu) {
-		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu));
+		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
 		per_cpu(irq_stack_ptr, cpu) = p;
 	}
 }
drivers/base/arch_numa.c +1 -1
index eaa31e567d1e..90519d981471 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-static int __init early_cpu_to_node(int cpu)
+int early_cpu_to_node(int cpu)
 {
 	return cpu_to_node_map[cpu];
 }
include/asm-generic/numa.h +2 -0
index 1a3ad6d29833..16073111bffc 100644
@@ -35,6 +35,7 @@ int __init numa_add_memblk(int nodeid, u64 start, u64 end);
 void __init numa_set_distance(int from, int to, int distance);
 void __init numa_free_distance(void);
 void __init early_map_cpu_to_node(unsigned int cpu, int nid);
+int early_cpu_to_node(int cpu);
 void numa_store_cpu_info(unsigned int cpu);
 void numa_add_cpu(unsigned int cpu);
 void numa_remove_cpu(unsigned int cpu);
@@ -46,6 +47,7 @@ static inline void numa_add_cpu(unsigned int cpu) { }
 static inline void numa_remove_cpu(unsigned int cpu) { }
 static inline void arch_numa_init(void) { }
 static inline void early_map_cpu_to_node(unsigned int cpu, int nid) { }
+static inline int early_cpu_to_node(int cpu) { return 0; }
 
 #endif	/* CONFIG_NUMA */
 
Signature · 1 line
2.40.1
#5 lore raw

PATCH v3 1/1 arm64: irq: set the correct node for VMAP stack

In reply to Catalin Marinas

In current code, init_irq_stacks() will call cpu_to_node(). The cpu_to_node() depends on percpu "numa_node" which is initialized in:

     arch_call_rest_init() --> rest_init() -- kernel_init()
	--> kernel_init_freeable() --> smp_prepare_cpus()

But init_irq_stacks() is called in init_IRQ() which is before arch_call_rest_init().

So in init_irq_stacks(), the cpu_to_node() does not work, it always return 0. In NUMA, it makes the node 1 cpu accesses the IRQ stack which is in the node 0.

This patch fixes it by exporting the early_cpu_to_node(), and use it in the init_irq_stacks().

---
v2 --> v3:
move the "numa.h" to the right position.

---
 arch/arm64/kernel/irq.c    | 3 ++-
 drivers/base/arch_numa.c   | 2 +-
 include/asm-generic/numa.h | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
arch/arm64/kernel/irq.c +2 -1
index 6ad5c6ef5329..d9ee14723478 100644
@@ -22,6 +22,7 @@
 #include <linux/vmalloc.h>
 #include <asm/daifflags.h>
 #include <asm/exception.h>
+#include <asm/numa.h>
 #include <asm/softirq_stack.h>
 #include <asm/stacktrace.h>
 #include <asm/vmap_stack.h>
@@ -57,7 +58,7 @@ static void init_irq_stacks(void)
 	unsigned long *p;
 
 	for_each_possible_cpu(cpu) {
-		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu));
+		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
 		per_cpu(irq_stack_ptr, cpu) = p;
 	}
 }
drivers/base/arch_numa.c +1 -1
index eaa31e567d1e..90519d981471 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-static int __init early_cpu_to_node(int cpu)
+int early_cpu_to_node(int cpu)
 {
 	return cpu_to_node_map[cpu];
 }
include/asm-generic/numa.h +2 -0
index 1a3ad6d29833..16073111bffc 100644
@@ -35,6 +35,7 @@ int __init numa_add_memblk(int nodeid, u64 start, u64 end);
 void __init numa_set_distance(int from, int to, int distance);
 void __init numa_free_distance(void);
 void __init early_map_cpu_to_node(unsigned int cpu, int nid);
+int early_cpu_to_node(int cpu);
 void numa_store_cpu_info(unsigned int cpu);
 void numa_add_cpu(unsigned int cpu);
 void numa_remove_cpu(unsigned int cpu);
@@ -46,6 +47,7 @@ static inline void numa_add_cpu(unsigned int cpu) { }
 static inline void numa_remove_cpu(unsigned int cpu) { }
 static inline void arch_numa_init(void) { }
 static inline void early_map_cpu_to_node(unsigned int cpu, int nid) { }
+static inline int early_cpu_to_node(int cpu) { return 0; }
 
 #endif	/* CONFIG_NUMA */
 
Signature · 1 line
2.40.1
maintainer Reviewed-by on v3 1/1
#6 lore raw

drivers/base/arch_numa.c void __init early_map_cpu_to_node(unsigned int cpu, int nid) · line 150

Quoted 13 lines · Huang Shijie
drivers/base/arch_numa.c +1 -1
index eaa31e567d1e..90519d981471 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-static int __init early_cpu_to_node(int cpu)
+int early_cpu_to_node(int cpu)
 {
 	return cpu_to_node_map[cpu];
 }

I don't think we need this change, let's make the arm64 init_irq_stacks() an __init function instead.

include/asm-generic/numa.h int __init numa_add_memblk(int nodeid, u64 start, u64 end); · line 38

Quoted 9 lines
include/asm-generic/numa.h +1 -0
index 1a3ad6d29833..16073111bffc 100644
@@ -35,6 +35,7 @@ int __init numa_add_memblk(int nodeid, u64 start, u64 end);
 void __init numa_set_distance(int from, int to, int distance);
 void __init numa_free_distance(void);
 void __init early_map_cpu_to_node(unsigned int cpu, int nid);
+int early_cpu_to_node(int cpu);

And add __init here.

With these changes:

Happy to take this patch through the arm64 tree if I get an ack from Greg or Rafael on the drivers/* change.

#7 lore raw

PATCH v4 1/1 arm64: irq: set the correct node for VMAP stack

In current code, init_irq_stacks() will call cpu_to_node(). The cpu_to_node() depends on percpu "numa_node" which is initialized in:

     arch_call_rest_init() --> rest_init() -- kernel_init()
	--> kernel_init_freeable() --> smp_prepare_cpus()

But init_irq_stacks() is called in init_IRQ() which is before arch_call_rest_init().

So in init_irq_stacks(), the cpu_to_node() does not work, it always return 0. In NUMA, it makes the node 1 cpu accesses the IRQ stack which is in the node 0.

This patch fixes it by:
1.) export the early_cpu_to_node(), and use it in the init_irq_stacks(). 2.) change init_irq_stacks() to __init function.

---
v3 --> v4:
1.) keep early_cpu_to_node() as __init function. 2.) change init_irq_stacks() to __init function.

---
 arch/arm64/kernel/irq.c    | 5 +++--
 drivers/base/arch_numa.c   | 2 +-
 include/asm-generic/numa.h | 2 ++
 3 files changed, 6 insertions(+), 3 deletions(-)
arch/arm64/kernel/irq.c +3 -2
index 6ad5c6ef5329..9f253d8efe90 100644
@@ -22,6 +22,7 @@
 #include <linux/vmalloc.h>
 #include <asm/daifflags.h>
 #include <asm/exception.h>
+#include <asm/numa.h>
 #include <asm/softirq_stack.h>
 #include <asm/stacktrace.h>
 #include <asm/vmap_stack.h>
@@ -51,13 +52,13 @@ static void init_irq_scs(void)
 }
 
 #ifdef CONFIG_VMAP_STACK
-static void init_irq_stacks(void)
+static void __init init_irq_stacks(void)
 {
 	int cpu;
 	unsigned long *p;
 
 	for_each_possible_cpu(cpu) {
-		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, cpu_to_node(cpu));
+		p = arch_alloc_vmap_stack(IRQ_STACK_SIZE, early_cpu_to_node(cpu));
 		per_cpu(irq_stack_ptr, cpu) = p;
 	}
 }
drivers/base/arch_numa.c +1 -1
index eaa31e567d1e..5b59d133b6af 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-static int __init early_cpu_to_node(int cpu)
+int __init early_cpu_to_node(int cpu)
 {
 	return cpu_to_node_map[cpu];
 }
include/asm-generic/numa.h +2 -0
index 1a3ad6d29833..c32e0cf23c90 100644
@@ -35,6 +35,7 @@ int __init numa_add_memblk(int nodeid, u64 start, u64 end);
 void __init numa_set_distance(int from, int to, int distance);
 void __init numa_free_distance(void);
 void __init early_map_cpu_to_node(unsigned int cpu, int nid);
+int __init early_cpu_to_node(int cpu);
 void numa_store_cpu_info(unsigned int cpu);
 void numa_add_cpu(unsigned int cpu);
 void numa_remove_cpu(unsigned int cpu);
@@ -46,6 +47,7 @@ static inline void numa_add_cpu(unsigned int cpu) { }
 static inline void numa_remove_cpu(unsigned int cpu) { }
 static inline void arch_numa_init(void) { }
 static inline void early_map_cpu_to_node(unsigned int cpu, int nid) { }
+static inline int early_cpu_to_node(int cpu) { return 0; }
 
 #endif	/* CONFIG_NUMA */
 
Signature · 1 line
2.40.1
maintainer
#8 lore raw
Quoted 23 lines · Huang Shijie

In current code, init_irq_stacks() will call cpu_to_node(). The cpu_to_node() depends on percpu "numa_node" which is initialized in:

     arch_call_rest_init() --> rest_init() -- kernel_init()
	--> kernel_init_freeable() --> smp_prepare_cpus()

But init_irq_stacks() is called in init_IRQ() which is before arch_call_rest_init().

So in init_irq_stacks(), the cpu_to_node() does not work, it always return 0. In NUMA, it makes the node 1 cpu accesses the IRQ stack which is in the node 0.

This patch fixes it by:
1.) export the early_cpu_to_node(), and use it in the init_irq_stacks(). 2.) change init_irq_stacks() to __init function.

---
v3 --> v4:
1.) keep early_cpu_to_node() as __init function. 2.) change init_irq_stacks() to __init function.

Quoted 5 lines
---
 arch/arm64/kernel/irq.c    | 5 +++--
 drivers/base/arch_numa.c   | 2 +-
 include/asm-generic/numa.h | 2 ++
 3 files changed, 6 insertions(+), 3 deletions(-)

Greg, Rafael - any objections to taking this patch through the arm64 tree?

Signature · 1 line
Catalin
maintainer Applied
#9 lore raw
In reply to Huang Shijie
Quoted 9 lines · Huang Shijie

In current code, init_irq_stacks() will call cpu_to_node(). The cpu_to_node() depends on percpu "numa_node" which is initialized in:

     arch_call_rest_init() --> rest_init() -- kernel_init()
	--> kernel_init_freeable() --> smp_prepare_cpus()

But init_irq_stacks() is called in init_IRQ() which is before arch_call_rest_init().

[...]

Applied to arm64 (for-next/mm), thanks!

[1/1] arm64: irq: set the correct node for VMAP stack

      https://git.kernel.org/arm64/c/75b5e0bf90bf

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev