[1/2] powerpc: export the CPU node count

Message ID 20221028160034.44400-2-ldufour@linux.ibm.com
State New
Headers
Series Consider the size of the added CPU nodes in the kexec FDT |

Commit Message

Laurent Dufour Oct. 28, 2022, 4 p.m. UTC
  At boot time, the FDT is parsed to compute the number of CPUs.
In addition count the number of CPU nodes and export it.

This is useful when building the FDT for a kexeced kernel since we need to
take in account the CPU node added since the boot time during CPU hotplug
operations.

Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
---
 arch/powerpc/include/asm/kexec_ranges.h | 2 ++
 arch/powerpc/kernel/prom.c              | 4 ++++
 2 files changed, 6 insertions(+)
  

Comments

kernel test robot Oct. 28, 2022, 6:02 p.m. UTC | #1
Hi Laurent,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on linus/master v6.1-rc2 next-20221028]
[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/Laurent-Dufour/Consider-the-size-of-the-added-CPU-nodes-in-the-kexec-FDT/20221029-000955
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
patch link:    https://lore.kernel.org/r/20221028160034.44400-2-ldufour%40linux.ibm.com
patch subject: [PATCH 1/2] powerpc: export the CPU node count
config: powerpc-allyesconfig
compiler: powerpc-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/938849fa462143b321353bdd62acfd2c5e2b517b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Laurent-Dufour/Consider-the-size-of-the-added-CPU-nodes-in-the-kexec-FDT/20221029-000955
        git checkout 938849fa462143b321353bdd62acfd2c5e2b517b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/kernel/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from arch/powerpc/kernel/prom.c:59:
>> arch/powerpc/include/asm/kexec_ranges.h:7:32: warning: 'struct crash_mem' declared inside parameter list will not be visible outside of this definition or declaration
       7 | void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
         |                                ^~~~~~~~~


vim +7 arch/powerpc/include/asm/kexec_ranges.h

180adfc532a83c Hari Bathini            2020-07-29   6  
180adfc532a83c Hari Bathini            2020-07-29  @7  void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
180adfc532a83c Hari Bathini            2020-07-29   8  struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges);
180adfc532a83c Hari Bathini            2020-07-29   9  int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
b8e55a3e5c2088 Hari Bathini            2020-07-29  10  int add_tce_mem_ranges(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  11  int add_initrd_mem_range(struct crash_mem **mem_ranges);
58dbe9b373df28 Murilo Opsfelder Araujo 2022-03-01  12  #ifdef CONFIG_PPC_64S_HASH_MMU
b8e55a3e5c2088 Hari Bathini            2020-07-29  13  int add_htab_mem_range(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  14  #else
b8e55a3e5c2088 Hari Bathini            2020-07-29  15  static inline int add_htab_mem_range(struct crash_mem **mem_ranges)
b8e55a3e5c2088 Hari Bathini            2020-07-29  16  {
b8e55a3e5c2088 Hari Bathini            2020-07-29  17  	return 0;
b8e55a3e5c2088 Hari Bathini            2020-07-29  18  }
b8e55a3e5c2088 Hari Bathini            2020-07-29  19  #endif
b8e55a3e5c2088 Hari Bathini            2020-07-29  20  int add_kernel_mem_range(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  21  int add_rtas_mem_range(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  22  int add_opal_mem_range(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  23  int add_reserved_mem_ranges(struct crash_mem **mem_ranges);
180adfc532a83c Hari Bathini            2020-07-29  24
  
kernel test robot Oct. 29, 2022, 11:31 p.m. UTC | #2
Hi Laurent,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on linus/master v6.1-rc2 next-20221028]
[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/Laurent-Dufour/Consider-the-size-of-the-added-CPU-nodes-in-the-kexec-FDT/20221029-000955
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
patch link:    https://lore.kernel.org/r/20221028160034.44400-2-ldufour%40linux.ibm.com
patch subject: [PATCH 1/2] powerpc: export the CPU node count
config: powerpc-gamecube_defconfig
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install powerpc cross compiling tool for clang build
        # apt-get install binutils-powerpc-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/938849fa462143b321353bdd62acfd2c5e2b517b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Laurent-Dufour/Consider-the-size-of-the-added-CPU-nodes-in-the-kexec-FDT/20221029-000955
        git checkout 938849fa462143b321353bdd62acfd2c5e2b517b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from include/linux/pci.h:38:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:45:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:119:1: note: expanded from here
   __do_insw
   ^
   arch/powerpc/include/asm/io.h:578:56: note: expanded from macro '__do_insw'
   #define __do_insw(p, b, n)      readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/kernel/prom.c:20:
   In file included from include/linux/pci.h:38:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:47:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:121:1: note: expanded from here
   __do_insl
   ^
   arch/powerpc/include/asm/io.h:579:56: note: expanded from macro '__do_insl'
   #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/kernel/prom.c:20:
   In file included from include/linux/pci.h:38:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:49:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:123:1: note: expanded from here
   __do_outsb
   ^
   arch/powerpc/include/asm/io.h:580:58: note: expanded from macro '__do_outsb'
   #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/kernel/prom.c:20:
   In file included from include/linux/pci.h:38:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:51:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:125:1: note: expanded from here
   __do_outsw
   ^
   arch/powerpc/include/asm/io.h:581:58: note: expanded from macro '__do_outsw'
   #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/kernel/prom.c:20:
   In file included from include/linux/pci.h:38:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:640:
   arch/powerpc/include/asm/io-defs.h:53:1: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:637:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:127:1: note: expanded from here
   __do_outsl
   ^
   arch/powerpc/include/asm/io.h:582:58: note: expanded from macro '__do_outsl'
   #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/kernel/prom.c:59:
>> arch/powerpc/include/asm/kexec_ranges.h:7:32: error: declaration of 'struct crash_mem' will not be visible outside of this function [-Werror,-Wvisibility]
   void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
                                  ^
   7 errors generated.


vim +7 arch/powerpc/include/asm/kexec_ranges.h

180adfc532a83c Hari Bathini            2020-07-29   6  
180adfc532a83c Hari Bathini            2020-07-29  @7  void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
180adfc532a83c Hari Bathini            2020-07-29   8  struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges);
180adfc532a83c Hari Bathini            2020-07-29   9  int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
b8e55a3e5c2088 Hari Bathini            2020-07-29  10  int add_tce_mem_ranges(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  11  int add_initrd_mem_range(struct crash_mem **mem_ranges);
58dbe9b373df28 Murilo Opsfelder Araujo 2022-03-01  12  #ifdef CONFIG_PPC_64S_HASH_MMU
b8e55a3e5c2088 Hari Bathini            2020-07-29  13  int add_htab_mem_range(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  14  #else
b8e55a3e5c2088 Hari Bathini            2020-07-29  15  static inline int add_htab_mem_range(struct crash_mem **mem_ranges)
b8e55a3e5c2088 Hari Bathini            2020-07-29  16  {
b8e55a3e5c2088 Hari Bathini            2020-07-29  17  	return 0;
b8e55a3e5c2088 Hari Bathini            2020-07-29  18  }
b8e55a3e5c2088 Hari Bathini            2020-07-29  19  #endif
b8e55a3e5c2088 Hari Bathini            2020-07-29  20  int add_kernel_mem_range(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  21  int add_rtas_mem_range(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  22  int add_opal_mem_range(struct crash_mem **mem_ranges);
b8e55a3e5c2088 Hari Bathini            2020-07-29  23  int add_reserved_mem_ranges(struct crash_mem **mem_ranges);
180adfc532a83c Hari Bathini            2020-07-29  24
  
Nicholas Piggin Nov. 7, 2022, 12:11 p.m. UTC | #3
On Sat Oct 29, 2022 at 2:00 AM AEST, Laurent Dufour wrote:
> At boot time, the FDT is parsed to compute the number of CPUs.
> In addition count the number of CPU nodes and export it.
>
> This is useful when building the FDT for a kexeced kernel since we need to
> take in account the CPU node added since the boot time during CPU hotplug
> operations.

It would be nice if it just realloced memory in this case, but that
looks like a bigger change.

But these patches look okay to me, if you can solve the compile bug.

Thanks,
Nick

>
> Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
> ---
>  arch/powerpc/include/asm/kexec_ranges.h | 2 ++
>  arch/powerpc/kernel/prom.c              | 4 ++++
>  2 files changed, 6 insertions(+)
>
> diff --git a/arch/powerpc/include/asm/kexec_ranges.h b/arch/powerpc/include/asm/kexec_ranges.h
> index f83866a19e87..bf35d00ddd09 100644
> --- a/arch/powerpc/include/asm/kexec_ranges.h
> +++ b/arch/powerpc/include/asm/kexec_ranges.h
> @@ -22,4 +22,6 @@ int add_rtas_mem_range(struct crash_mem **mem_ranges);
>  int add_opal_mem_range(struct crash_mem **mem_ranges);
>  int add_reserved_mem_ranges(struct crash_mem **mem_ranges);
>  
> +extern unsigned int boot_cpu_node_count;
> +
>  #endif /* _ASM_POWERPC_KEXEC_RANGES_H */
> diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
> index 1eed87d954ba..d326148fd5a4 100644
> --- a/arch/powerpc/kernel/prom.c
> +++ b/arch/powerpc/kernel/prom.c
> @@ -56,6 +56,7 @@
>  #include <asm/drmem.h>
>  #include <asm/ultravisor.h>
>  #include <asm/prom.h>
> +#include <asm/kexec_ranges.h>
>  
>  #include <mm/mmu_decl.h>
>  
> @@ -72,6 +73,7 @@ int __initdata iommu_is_off;
>  int __initdata iommu_force_on;
>  unsigned long tce_alloc_start, tce_alloc_end;
>  u64 ppc64_rma_size;
> +unsigned int boot_cpu_node_count __ro_after_init;
>  #endif
>  static phys_addr_t first_memblock_size;
>  static int __initdata boot_cpu_count;
> @@ -335,6 +337,8 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
>  	if (type == NULL || strcmp(type, "cpu") != 0)
>  		return 0;
>  
> +	boot_cpu_node_count++;
> +
>  	/* Get physical cpuid */
>  	intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len);
>  	if (!intserv)
> -- 
> 2.38.1
  
Laurent Dufour Nov. 7, 2022, 4:06 p.m. UTC | #4
On 07/11/2022 13:11:17, Nicholas Piggin wrote:
> On Sat Oct 29, 2022 at 2:00 AM AEST, Laurent Dufour wrote:
>> At boot time, the FDT is parsed to compute the number of CPUs.
>> In addition count the number of CPU nodes and export it.
>>
>> This is useful when building the FDT for a kexeced kernel since we need to
>> take in account the CPU node added since the boot time during CPU hotplug
>> operations.
> 
> It would be nice if it just realloced memory in this case, but that
> looks like a bigger change.

I agree, and I think the best option in long term would be the series 
Sourabh Jain sent in June, updating the crash kernel FDT without reloading
it (https://lore.kernel.org/linuxppc-dev/20220620070106.93141-1-sourabhjain@linux.ibm.com/)

In the meantime, this solves the issue.

> 
> But these patches look okay to me, if you can solve the compile bug.

Indeed, the compile bugs are raised because I added the definition of the new variable 
'boot_cpu_node_count' in kexec_ranges.h, and add the inclusion of that file in prom.c.

I was not confident putting this new variable definition in that header file, but I 
didn't find a better option.

Do you have a better idea of header file to use?

Could I just declare this variable "extern" in arch/powerpc/kexec/file_load_64.c? This looks
ugly to me.

Thanks,
Laurent.


> Thanks,
> Nick
> 
>>
>> Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
>> ---
>>  arch/powerpc/include/asm/kexec_ranges.h | 2 ++
>>  arch/powerpc/kernel/prom.c              | 4 ++++
>>  2 files changed, 6 insertions(+)
>>
>> diff --git a/arch/powerpc/include/asm/kexec_ranges.h b/arch/powerpc/include/asm/kexec_ranges.h
>> index f83866a19e87..bf35d00ddd09 100644
>> --- a/arch/powerpc/include/asm/kexec_ranges.h
>> +++ b/arch/powerpc/include/asm/kexec_ranges.h
>> @@ -22,4 +22,6 @@ int add_rtas_mem_range(struct crash_mem **mem_ranges);
>>  int add_opal_mem_range(struct crash_mem **mem_ranges);
>>  int add_reserved_mem_ranges(struct crash_mem **mem_ranges);
>>  
>> +extern unsigned int boot_cpu_node_count;
>> +
>>  #endif /* _ASM_POWERPC_KEXEC_RANGES_H */
>> diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
>> index 1eed87d954ba..d326148fd5a4 100644
>> --- a/arch/powerpc/kernel/prom.c
>> +++ b/arch/powerpc/kernel/prom.c
>> @@ -56,6 +56,7 @@
>>  #include <asm/drmem.h>
>>  #include <asm/ultravisor.h>
>>  #include <asm/prom.h>
>> +#include <asm/kexec_ranges.h>
>>  
>>  #include <mm/mmu_decl.h>
>>  
>> @@ -72,6 +73,7 @@ int __initdata iommu_is_off;
>>  int __initdata iommu_force_on;
>>  unsigned long tce_alloc_start, tce_alloc_end;
>>  u64 ppc64_rma_size;
>> +unsigned int boot_cpu_node_count __ro_after_init;
>>  #endif
>>  static phys_addr_t first_memblock_size;
>>  static int __initdata boot_cpu_count;
>> @@ -335,6 +337,8 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
>>  	if (type == NULL || strcmp(type, "cpu") != 0)
>>  		return 0;
>>  
>> +	boot_cpu_node_count++;
>> +
>>  	/* Get physical cpuid */
>>  	intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len);
>>  	if (!intserv)
>> -- 
>> 2.38.1
>
  

Patch

diff --git a/arch/powerpc/include/asm/kexec_ranges.h b/arch/powerpc/include/asm/kexec_ranges.h
index f83866a19e87..bf35d00ddd09 100644
--- a/arch/powerpc/include/asm/kexec_ranges.h
+++ b/arch/powerpc/include/asm/kexec_ranges.h
@@ -22,4 +22,6 @@  int add_rtas_mem_range(struct crash_mem **mem_ranges);
 int add_opal_mem_range(struct crash_mem **mem_ranges);
 int add_reserved_mem_ranges(struct crash_mem **mem_ranges);
 
+extern unsigned int boot_cpu_node_count;
+
 #endif /* _ASM_POWERPC_KEXEC_RANGES_H */
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 1eed87d954ba..d326148fd5a4 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -56,6 +56,7 @@ 
 #include <asm/drmem.h>
 #include <asm/ultravisor.h>
 #include <asm/prom.h>
+#include <asm/kexec_ranges.h>
 
 #include <mm/mmu_decl.h>
 
@@ -72,6 +73,7 @@  int __initdata iommu_is_off;
 int __initdata iommu_force_on;
 unsigned long tce_alloc_start, tce_alloc_end;
 u64 ppc64_rma_size;
+unsigned int boot_cpu_node_count __ro_after_init;
 #endif
 static phys_addr_t first_memblock_size;
 static int __initdata boot_cpu_count;
@@ -335,6 +337,8 @@  static int __init early_init_dt_scan_cpus(unsigned long node,
 	if (type == NULL || strcmp(type, "cpu") != 0)
 		return 0;
 
+	boot_cpu_node_count++;
+
 	/* Get physical cpuid */
 	intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len);
 	if (!intserv)