diff mbox series

powerpc/cpu: nr_cpu_ids should be aligned on threads_per_core

Message ID 1526278438-10519-1-git-send-email-kernelfans@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series powerpc/cpu: nr_cpu_ids should be aligned on threads_per_core | expand

Commit Message

Pingfan Liu May 14, 2018, 6:13 a.m. UTC
With p8 subcore mode, if nr_cpus is not aligned on threads_per_core,
then we will hit the following panic:
  [    0.310006] Unpacking initramfs...
  [    1.105015] Freeing initrd memory: 35968K
  [    1.105466] rtas_flash: no firmware flash support
  [    1.105688] Unable to handle kernel paging request for data at address 0x00001035
  [    1.105768] Faulting instruction address: 0xc000000000099bb8
  [    1.105837] Oops: Kernel access of bad area, sig: 11 [#1]
  [    1.105890] LE SMP NR_CPUS=2048 NUMA PowerNV
  [    1.105947] Modules linked in:
  [    1.105992] CPU: 8 PID: 11 Comm: migration/8 Not tainted 4.17.0-rc4+ #26
  [    1.106059] NIP:  c000000000099bb8 LR: c0000000000ac554 CTR: c000000000099b70
  [    1.106139] REGS: c000000ff649f860 TRAP: 0380   Not tainted  (4.17.0-rc4+)
  [    1.106205] MSR:  9000000000001033 <SF,HV,ME,IR,DR,RI,LE>  CR: 28004022  XER: 00000000
  [    1.106293] CFAR: c0000000000ac550 SOFTE: 3
  [    1.106293] GPR00: c0000000000ac554 c000000ff649fae0 c0000000012e6d00 0000000000000060
  [    1.106293] GPR04: 0000000000000001 c0000000000ac914 9000000000001033 c000003fffffff80
  [    1.106293] GPR08: 0000000000000000 0000000000000001 0000000000000000 9000000000001003
  [    1.106293] GPR12: c000000000099b70 c000000001700000 c000000000141c28 c000000ffa201180
  [    1.106293] GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
  [    1.106293] GPR20: 0000000000000000 0000000000000000 0000000000000001 c000000fffd13840
  [    1.106293] GPR24: c000000fffd13838 0000000000000000 0000000000000001 0000000000000010
  [    1.106293] GPR28: 0000000000000008 0000000000000001 c000000001370548 000000000000000c
  [    1.106984] NIP [c000000000099bb8] icp_native_cause_ipi+0x48/0x70
  [    1.107053] LR [c0000000000ac554] pnv_cause_ipi+0x54/0x80
  [    1.107106] Call Trace:
  [    1.107137] [c000000ff649fae0] [c0000000000478b4] doorbell_try_core_ipi+0x74/0x90 (unreliable)
  [    1.107232] [c000000ff649fb10] [c0000000000ac554] pnv_cause_ipi+0x54/0x80
  [    1.107301] [c000000ff649fb40] [c00000000004ccfc] smp_muxed_ipi_message_pass+0x6c/0x90
  [    1.107384] [c000000ff649fb80] [c0000000000acbe8] cpu_do_split+0x2b8/0x2f0
  [    1.107453] [c000000ff649fbf0] [c0000000000acdb8] cpu_update_split_mode+0x68/0x204
  [    1.107536] [c000000ff649fc40] [c000000000204ab8] multi_cpu_stop+0x1c8/0x200
  [    1.107617] [c000000ff649fca0] [c000000000204eb4] cpu_stopper_thread+0x114/0x1f0
  [    1.107699] [c000000ff649fd60] [c000000000148650] smpboot_thread_fn+0x290/0x2a0
  [    1.107780] [c000000ff649fdc0] [c000000000141d84] kthread+0x164/0x1b0
  [    1.107850] [c000000ff649fe30] [c00000000000b628] ret_from_kernel_thread+0x5c/0xb4
  [    1.107929] Instruction dump:
  [    1.107971] 7c7f1b78 60000000 60000000 3d420004 394ab070 7be31f24 39200001 e90a0000
  [    1.108058] 3d42001b 394a2650 7d08182a 7d4a182a <99281035> 39000004 7c0004ac 990a000c
  [    1.108150] ---[ end trace 83dad19c162dc306 ]---
  [    1.110137]
  [    2.110227] Kernel panic - not syncing: Fatal exception

This is caused by that during subcore_init, it IPIs all cpu inside the core, but due to the limitation
imposed by nr_cpus, there are no mem allocated for percpu cpu_sibling_map.
To avoid a complicated fix, this patch just forces the nr_cpu_ids to be aligned on thread_per_code
at the cost of a bit more memory.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
---
 arch/powerpc/kernel/prom.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

kernel test robot May 14, 2018, 9:22 a.m. UTC | #1
Hi Pingfan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.17-rc5 next-20180511]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Pingfan-Liu/powerpc-cpu-nr_cpu_ids-should-be-aligned-on-threads_per_core/20180514-141629
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-allnoconfig (attached as .config)
compiler: powerpc-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/kernel/prom.c: In function 'early_init_dt_scan_cpus':
>> arch/powerpc/kernel/prom.c:370:14: error: lvalue required as left operand of assignment
      nr_cpu_ids = nr_cpus_aligned;
                 ^

vim +370 arch/powerpc/kernel/prom.c

   306	
   307	static int __init early_init_dt_scan_cpus(unsigned long node,
   308						  const char *uname, int depth,
   309						  void *data)
   310	{
   311		const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
   312		const __be32 *prop;
   313		const __be32 *intserv;
   314		int i, nthreads;
   315		int len;
   316		int found = -1;
   317		int found_thread = 0;
   318		unsigned int nr_cpus_aligned;
   319	
   320		/* We are scanning "cpu" nodes only */
   321		if (type == NULL || strcmp(type, "cpu") != 0)
   322			return 0;
   323	
   324		/* Get physical cpuid */
   325		intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len);
   326		if (!intserv)
   327			intserv = of_get_flat_dt_prop(node, "reg", &len);
   328	
   329		nthreads = len / sizeof(int);
   330	
   331		/*
   332		 * Now see if any of these threads match our boot cpu.
   333		 * NOTE: This must match the parsing done in smp_setup_cpu_maps.
   334		 */
   335		for (i = 0; i < nthreads; i++) {
   336			/*
   337			 * version 2 of the kexec param format adds the phys cpuid of
   338			 * booted proc.
   339			 */
   340			if (fdt_version(initial_boot_params) >= 2) {
   341				if (be32_to_cpu(intserv[i]) ==
   342				    fdt_boot_cpuid_phys(initial_boot_params)) {
   343					found = boot_cpu_count;
   344					found_thread = i;
   345				}
   346			} else {
   347				/*
   348				 * Check if it's the boot-cpu, set it's hw index now,
   349				 * unfortunately this format did not support booting
   350				 * off secondary threads.
   351				 */
   352				if (of_get_flat_dt_prop(node,
   353						"linux,boot-cpu", NULL) != NULL)
   354					found = boot_cpu_count;
   355			}
   356	#ifdef CONFIG_SMP
   357			/* logical cpu id is always 0 on UP kernels */
   358			boot_cpu_count++;
   359	#endif
   360		}
   361	
   362		/* Not the boot CPU */
   363		if (found < 0)
   364			return 0;
   365		/* to work around p8 subcore mode */
   366		nr_cpus_aligned = _ALIGN_UP(nr_cpu_ids, nthreads);
   367		if (nr_cpus_aligned != nr_cpu_ids) {
   368			pr_info("nr_cpus is forced to align up on threads_per_core,"
   369				"from %u to %u\n", nr_cpu_ids, nr_cpus_aligned);
 > 370			nr_cpu_ids = nr_cpus_aligned;
   371		}
   372		DBG("boot cpu: logical %d physical %d\n", found,
   373		    be32_to_cpu(intserv[found_thread]));
   374		boot_cpuid = found;
   375	
   376		/*
   377		 * PAPR defines "logical" PVR values for cpus that
   378		 * meet various levels of the architecture:
   379		 * 0x0f000001	Architecture version 2.04
   380		 * 0x0f000002	Architecture version 2.05
   381		 * If the cpu-version property in the cpu node contains
   382		 * such a value, we call identify_cpu again with the
   383		 * logical PVR value in order to use the cpu feature
   384		 * bits appropriate for the architecture level.
   385		 *
   386		 * A POWER6 partition in "POWER6 architected" mode
   387		 * uses the 0x0f000002 PVR value; in POWER5+ mode
   388		 * it uses 0x0f000001.
   389		 *
   390		 * If we're using device tree CPU feature discovery then we don't
   391		 * support the cpu-version property, and it's the responsibility of the
   392		 * firmware/hypervisor to provide the correct feature set for the
   393		 * architecture level via the ibm,powerpc-cpu-features binding.
   394		 */
   395		if (!dt_cpu_ftrs_in_use()) {
   396			prop = of_get_flat_dt_prop(node, "cpu-version", NULL);
   397			if (prop && (be32_to_cpup(prop) & 0xff000000) == 0x0f000000)
   398				identify_cpu(0, be32_to_cpup(prop));
   399	
   400			check_cpu_feature_properties(node);
   401			check_cpu_pa_features(node);
   402		}
   403	
   404		identical_pvr_fixup(node);
   405		init_mmu_slb_size(node);
   406	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 9dbed48..358adb4 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -315,6 +315,7 @@  static int __init early_init_dt_scan_cpus(unsigned long node,
 	int len;
 	int found = -1;
 	int found_thread = 0;
+	unsigned int nr_cpus_aligned;
 
 	/* We are scanning "cpu" nodes only */
 	if (type == NULL || strcmp(type, "cpu") != 0)
@@ -361,7 +362,13 @@  static int __init early_init_dt_scan_cpus(unsigned long node,
 	/* Not the boot CPU */
 	if (found < 0)
 		return 0;
-
+	/* to work around p8 subcore mode */
+	nr_cpus_aligned = _ALIGN_UP(nr_cpu_ids, nthreads);
+	if (nr_cpus_aligned != nr_cpu_ids) {
+		pr_info("nr_cpus is forced to align up on threads_per_core,"
+			"from %u to %u\n", nr_cpu_ids, nr_cpus_aligned);
+		nr_cpu_ids = nr_cpus_aligned;
+	}
 	DBG("boot cpu: logical %d physical %d\n", found,
 	    be32_to_cpu(intserv[found_thread]));
 	boot_cpuid = found;