Hi All,

I compiled the latest Git kernel ([url=http://www.xenosoft.de/linux-image-5.16-alpha4-X1000_X5000.tar.gz][b]alpha4[/b][/url]) with the new PowerPC updates [url=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5c0b0c676ac2d84f69568715af91e45b610fe17a][b]5.16-1[/b][/url] today. Unfortunately this kernel doesn't boot on the X5000. The X1000 and the virtual e5500 QEMU KVM-HV machine boots with this kernel.

I was able to revert the new PowerPC updates [url=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5c0b0c676ac2d84f69568715af91e45b610fe17a][b]5.16-1[/b][/url] with the following command.


[code]git revert 5c0b0c676ac2d84f69568715af91e45b610fe17a -m 1[/code]

After a new compiling, the kernel boots without any problems on my X5000.

I bisected today.

About bisecting:

[quote]
Git bisect is like a little wizard that walks you through recent commits, asks you if they are good or bad, and narrows down the broken commit.
Git bisect starts with the midpoint commit. The midpoint commit is between the initial “good” commit and the initial “bad” commit.
If the midpoint commit was good, you know the commit that introduced the change is between your midpoint and the initial “bad” commit.
If the midpoint commit was bad, you know the commit that introduced the change is between your midpoint and the initial “good” commit.
After that git bisect selects a new midpoint in the area where the commit was bad. And this is repeated over and over again till the bad commit has been found.
[/quote]

[list=1]
[*] [code]git bisect start[/code]
[*] [code]git bisect good 8bb7eca972ad531c9b149c0a51ab43a417385813[/code] (Good: [url=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.15&id=8bb7eca972ad531c9b149c0a51ab43a417385813][b]Linux 5.15[/b][/url])
[*] [code]git bisect bad c80be257a4cd0f72c083e6056ff0ce2da871e9dc[/code] (Bad: [b][url=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c80be257a4cd0f72c083e6056ff0ce2da871e9dc]i2c: xgene-slimpro: Fix wrong pointer passed to PTR_ERR()[/url][/b] -- 2021-11-06 22:09:37 +0100)
Output:
[code][464fddbba1dfbc219f1e9145127a482d2159dee5] Merge tag 'pnp-5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm[/code]
[*] [b]git bisect good[/b]
Output:
[code][2219b0ceefe835b92a8a74a73fe964aa052742a2] Merge tag 'soc-5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc[/code]
[*] [b]git bisect good[/b]
Output:
[code][048ff8629e117d8411a787559417c781bcd78d7e] Merge tag 'usb-5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb[/code]
[*] [b]git bisect good[/b]
Output:
[code][5c904c66ed4e86c31ac7c033b64274cebed04e0e] Merge tag 'char-misc-5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc[/code]
[*] [b]git bisect good[/b]
Output:
[code][a51e4a1acb5fa4ce0b0f0bd3606463a09e6fa1b0] Merge tag 'microblaze-v5.16' of git://git.monstr.eu/linux-2.6-microblaze[[/code]
[*] [b]git bisect bad[/b]
Output:
[code][abfecb39092029c42c79bacac3d1c96a133ff231] Merge tag 'tty-5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty[[/code]
[*] [b]git bisect good[/b]
Output:
[code][a3f36773802d44d1e50e7c4c09b3e17018581d11] Merge tag 'mips_5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux[/code]
[*] [b]git bisect good[/b]
Output:
[code][e9efabc6e4c31517394be13c2f0c5abadd33f328] powerpc/5200: dts: add missing pci ranges[/code]
[*] [b]git bisect bad[/b]
Output:
[code][02b182e67482d9167a13a0ff19b55037b70b21ad] powerpc/perf: Refactor the code definition of perf reg extended mask[/code]
[*] [b]git bisect good[/b]
Output:
[code][7453f501d443c7febf48809ee1c530b64d625c59] powerpc/kexec_file: Add of_node_put() before goto[/code]
[*] [b]git bisect good[/b]
Output:
[code][52bda69ae8b5102fe08c9db10f4a1514478e07d3] powerpc/fsl_booke: Tell map_mem_in_cams() if init is done[/code]
[*] [b]git bisect bad[/b]
Output:
[code][3a75fd709c89cb45b8b1044b8ef0d15027a69f9b] powerpc/fsl_booke: Rename fsl_booke.c to fsl_book3e.c[/code]
[*] [b]git bisect good[/b]
Output:
[code][a97dd9e2f760c6996a8f1385ddab0bfef325b364] powerpc/fsl_booke: Enable reloading of TLBCAM without switching to AS1[/code]
[*] [b]git bisect good[/b]
Output:
[code]52bda69ae8b5102fe08c9db10f4a1514478e07d3 is the first bad commit
commit 52bda69ae8b5102fe08c9db10f4a1514478e07d3
Author: Christophe Leroy <christophe.leroy@csgroup.eu>
Date:   Fri Oct 15 12:02:46 2021 +0200

    powerpc/fsl_booke: Tell map_mem_in_cams() if init is done
    
    In order to be able to call map_mem_in_cams() once more
    after init for STRICT_KERNEL_RWX, add an argument.
    
    For now, map_mem_in_cams() is always called only during init.
    
    Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/3b69a7e0b393b16984ade882a5eae5d727717459.1634292136.git.christophe.leroy@csgroup.eu

:040000 040000 69b8a7cae22a3a39041496805966209b80fee142 bc4d2d8fa43e7495d1373e5fd792f529cd42265f M	arch[/code]
[/list]

Result: [url=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=52bda69ae8b5102fe08c9db10f4a1514478e07d3][b]52bda69ae8b5102fe08c9db10f4a1514478e07d3[/b][/url] is the first bad commit.

I was able to revert the first bad commit.

[code]git revert 52bda69ae8b5102fe08c9db10f4a1514478e07d3[/code]

Output:

[code]
[master c86db5684d55] Revert "powerpc/fsl_booke: Tell map_mem_in_cams() if init is done"
 4 files changed, 10 insertions(+), 10 deletions(-)
[/code]

Unfortunately it didn't compile.

Error messages:

[code]
arch/powerpc/mm/nohash/fsl_book3e.c: In function ‘map_mem_in_cams_addr’:
arch/powerpc/mm/nohash/fsl_book3e.c:185:19: error: ‘init’ undeclared (first use in this function); did you mean ‘int’?
   pgprot_t prot = init ? PAGE_KERNEL_X : PAGE_KERNEL_ROX;
                   ^~~~
                   int
[/code]

I had to revert the commit [url=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d5970045cf9e266d9a43941ac0866865fd22a36a][b]d5970045cf9e266d9a43941ac0866865fd22a36a[/b][/url] additionally. I found this commit in the [url=https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/log/?h=next]PowerPC Git tree[/url].

[code]git revert d5970045cf9e266d9a43941ac0866865fd22a36a[/code]

Output:

[code]
[master 053a1c6288f5] Revert "powerpc/fsl_booke: Update of TLBCAMs after init"
 2 files changed, 5 insertions(+), 29 deletions(-)
[/code]

After a new compiling, the kernel boots without any problems.

I created a patch for reverting the bad commit.

[code]diff -rupN a b > fsl_booke.patch[/code]


[b]fsl_booke.patch[/b]:

[code]
diff -rupN a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h
--- a/arch/powerpc/mm/mmu_decl.h	2021-11-08 14:46:04.841131156 +0100
+++ b/arch/powerpc/mm/mmu_decl.h	2021-11-08 14:45:12.441244455 +0100
@@ -126,7 +126,7 @@ unsigned long mmu_mapin_ram(unsigned lon
 
 #ifdef CONFIG_PPC_FSL_BOOK3E
 extern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx,
-				     bool dryrun, bool init);
+				     bool dryrun);
 extern unsigned long calc_cam_sz(unsigned long ram, unsigned long virt,
 				 phys_addr_t phys);
 #ifdef CONFIG_PPC32
@@ -168,7 +168,7 @@ static inline phys_addr_t v_block_mapped
 static inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; }
 #endif
 
-#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) || defined(CONFIG_PPC_FSL_BOOK3E)
+#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx)
 void mmu_mark_initmem_nx(void);
 void mmu_mark_rodata_ro(void);
 #else
diff -rupN a/arch/powerpc/mm/nohash/fsl_book3e.c b/arch/powerpc/mm/nohash/fsl_book3e.c
--- a/arch/powerpc/mm/nohash/fsl_book3e.c	2021-11-08 14:46:04.841131156 +0100
+++ b/arch/powerpc/mm/nohash/fsl_book3e.c	2021-11-08 14:45:12.441244455 +0100
@@ -168,7 +168,7 @@ unsigned long calc_cam_sz(unsigned long
 
 static unsigned long map_mem_in_cams_addr(phys_addr_t phys, unsigned long virt,
 					unsigned long ram, int max_cam_idx,
-					bool dryrun, bool init)
+					bool dryrun)
 {
 	int i;
 	unsigned long amount_mapped = 0;
@@ -182,7 +182,7 @@ static unsigned long map_mem_in_cams_add
 	/* Calculate CAM values */
 	for (i = 0; boundary && i < max_cam_idx; i++) {
 		unsigned long cam_sz;
-		pgprot_t prot = init ? PAGE_KERNEL_X : PAGE_KERNEL_ROX;
+		pgprot_t prot = PAGE_KERNEL_X;
 
 		cam_sz = calc_cam_sz(boundary, virt, phys);
 		if (!dryrun)
@@ -195,7 +195,7 @@ static unsigned long map_mem_in_cams_add
 	}
 	for (ram -= amount_mapped; ram && i < max_cam_idx; i++) {
 		unsigned long cam_sz;
-		pgprot_t prot = init ? PAGE_KERNEL_X : PAGE_KERNEL;
+		pgprot_t prot = PAGE_KERNEL_X;
 
 		cam_sz = calc_cam_sz(ram, virt, phys);
 		if (!dryrun)
@@ -210,13 +210,8 @@ static unsigned long map_mem_in_cams_add
 	if (dryrun)
 		return amount_mapped;
 
-	if (init) {
-		loadcam_multi(0, i, max_cam_idx);
-		tlbcam_index = i;
-	} else {
-		loadcam_multi(0, i, 0);
-		WARN_ON(i > tlbcam_index);
-	}
+	loadcam_multi(0, i, max_cam_idx);
+	tlbcam_index = i;
 
 #ifdef CONFIG_PPC64
 	get_paca()->tcd.esel_next = i;
@@ -227,12 +222,12 @@ static unsigned long map_mem_in_cams_add
 	return amount_mapped;
 }
 
-unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx, bool dryrun, bool init)
+unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx, bool dryrun)
 {
 	unsigned long virt = PAGE_OFFSET;
 	phys_addr_t phys = memstart_addr;
 
-	return map_mem_in_cams_addr(phys, virt, ram, max_cam_idx, dryrun, init);
+	return map_mem_in_cams_addr(phys, virt, ram, max_cam_idx, dryrun);
 }
 
 #ifdef CONFIG_PPC32
@@ -273,7 +268,7 @@ void __init adjust_total_lowmem(void)
 	ram = min((phys_addr_t)__max_low_memory, (phys_addr_t)total_lowmem);
 
 	i = switch_to_as1();
-	__max_low_memory = map_mem_in_cams(ram, CONFIG_LOWMEM_CAM_NUM, false, true);
+	__max_low_memory = map_mem_in_cams(ram, CONFIG_LOWMEM_CAM_NUM, false);
 	restore_to_as0(i, 0, 0, 1);
 
 	pr_info("Memory CAM mapping: ");
@@ -285,25 +280,6 @@ void __init adjust_total_lowmem(void)
 	memblock_set_current_limit(memstart_addr + __max_low_memory);
 }
 
-#ifdef CONFIG_STRICT_KERNEL_RWX
-void mmu_mark_rodata_ro(void)
-{
-	/* Everything is done in mmu_mark_initmem_nx() */
-}
-#endif
-
-void mmu_mark_initmem_nx(void)
-{
-	unsigned long remapped;
-
-	if (!strict_kernel_rwx_enabled())
-		return;
-
-	remapped = map_mem_in_cams(__max_low_memory, CONFIG_LOWMEM_CAM_NUM, false, false);
-
-	WARN_ON(__max_low_memory != remapped);
-}
-
 void setup_initial_memory_limit(phys_addr_t first_memblock_base,
 				phys_addr_t first_memblock_size)
 {
@@ -363,11 +339,11 @@ notrace void __init relocate_init(u64 dt
 		/* map a 64M area for the second relocation */
 		if (memstart_addr > start)
 			map_mem_in_cams(0x4000000, CONFIG_LOWMEM_CAM_NUM,
-					false, true);
+					false);
 		else
 			map_mem_in_cams_addr(start, PAGE_OFFSET + offset,
 					0x4000000, CONFIG_LOWMEM_CAM_NUM,
-					false, true);
+					false);
 		restore_to_as0(n, offset, __va(dt_ptr), 1);
 		/* We should never reach here */
 		panic("Relocation error");
diff -rupN a/arch/powerpc/mm/nohash/kaslr_booke.c b/arch/powerpc/mm/nohash/kaslr_booke.c
--- a/arch/powerpc/mm/nohash/kaslr_booke.c	2021-11-08 14:46:04.841131156 +0100
+++ b/arch/powerpc/mm/nohash/kaslr_booke.c	2021-11-08 14:44:41.801312036 +0100
@@ -314,7 +314,7 @@ static unsigned long __init kaslr_choose
 		pr_warn("KASLR: No safe seed for randomizing the kernel base.\n");
 
 	ram = min_t(phys_addr_t, __max_low_memory, size);
-	ram = map_mem_in_cams(ram, CONFIG_LOWMEM_CAM_NUM, true, false);
+	ram = map_mem_in_cams(ram, CONFIG_LOWMEM_CAM_NUM, true);
 	linear_sz = min_t(unsigned long, ram, SZ_512M);
 
 	/* If the linear size is smaller than 64M, do not randmize */
diff -rupN a/arch/powerpc/mm/nohash/tlb.c b/arch/powerpc/mm/nohash/tlb.c
--- a/arch/powerpc/mm/nohash/tlb.c	2021-11-08 14:46:04.841131156 +0100
+++ b/arch/powerpc/mm/nohash/tlb.c	2021-11-08 14:44:42.149311263 +0100
@@ -645,7 +645,7 @@ static void early_init_this_mmu(void)
 
 		if (map)
 			linear_map_top = map_mem_in_cams(linear_map_top,
-							 num_cams, true, true);
+							 num_cams, false);
 	}
 #endif
 
@@ -766,7 +766,7 @@ void setup_initial_memory_limit(phys_add
 		num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4;
 
 		linear_sz = map_mem_in_cams(first_memblock_size, num_cams,
-					    false, true);
+					    true);
 
 		ppc64_rma_size = min_t(u64, linear_sz, 0x40000000);
 	} else
[/code]

I compiled the kernel with this patch. After that it boots without any problems.

I reported this issue to the Linuxppc-dev mailing list today.

Link: [url=https://lists.ozlabs.org/pipermail/linuxppc-dev/2021-November/236461.html][FSL P50x0] Cyrus+ board doesn't boot with the PowerPC updates 5.16-1[/url]

Cheers,
Christian
