KASAN debug kernel fails to boot at early stage when CONFIG_SMP=y is set (kernel 6.5-rc5, PowerMac G4 3,6)

Christophe Leroy christophe.leroy at csgroup.eu
Tue Sep 12 17:47:50 AEST 2023



Le 12/09/2023 à 02:11, Erhard Furtner a écrit :
> On Mon, 4 Sep 2023 14:55:17 +0000
> Christophe Leroy <christophe.leroy at csgroup.eu> wrote:
> 
>> Another thing that could be interesting to test is to remove (or comment
>> out) the following line in arch/powerpc/mm/kasan/Makefile :
>>
>>     obj-$(CONFIG_PPC_BOOK3S_32)	+= book3s_32.o
>>
>> That way, the weak version of kasan_init_region() will be used instead
>> of the one in book3s_32.c
> 
> Tinkered around with older kernels and .config options meanwhile. I found out it's not a new issue, also happens on kernel v6.0. Have not tried older kernels yet.
> 
> Also on v6.0 the issue disappears when I comment out "obj-$(CONFIG_PPC_BOOK3S_32) += book3s_32.o" in arch/powerpc/mm/kasan/Makefile.
> 
> Even more interesting is the issue disappears too when I deselect INIT_STACK_ALL_PATTERN in my kernel .config. The kernel boots just fine with KASAN when INIT_STACK_NONE=y is set! True for kernel v6.0 and v6.6-rc1.
> 
> Current v6.6-rc1 kernel .config and dmesg attached.
> 

I suspect something wrong when we set the BATs.

Can you try with the following additional traces:

diff --git a/arch/powerpc/mm/kasan/book3s_32.c 
b/arch/powerpc/mm/kasan/book3s_32.c
index 450a67ef0bbe..9954b7a3b7ae 100644
--- a/arch/powerpc/mm/kasan/book3s_32.c
+++ b/arch/powerpc/mm/kasan/book3s_32.c
@@ -15,6 +15,7 @@ int __init kasan_init_region(void *start, size_t size)
  	phys_addr_t phys;
  	int ret;

+	pr_err("%s: %px %x %lx %lx\n", __func__, start, size, k_start, k_end);
  	while (k_nobat < k_end) {
  		unsigned int k_size = bat_block_size(k_nobat, k_end);
  		int idx = find_free_bat();
@@ -28,6 +29,7 @@ int __init kasan_init_region(void *start, size_t size)
  		if (!phys)
  			break;

+		pr_err("%s: setbat %d %lx %x %x\n", __func__, idx, k_nobat, phys, 
k_size);
  		setbat(idx, k_nobat, phys, k_size, PAGE_KERNEL);
  		k_nobat += k_size;
  	}
@@ -47,6 +49,7 @@ int __init kasan_init_region(void *start, size_t size)

  	kasan_update_early_region(k_start, k_nobat, __pte(0));

+	pr_err("%s: loop %lx %lx\n", __func__, k_nobat, k_end);
  	for (k_cur = k_nobat; k_cur < k_end; k_cur += PAGE_SIZE) {
  		pmd_t *pmd = pmd_off_k(k_cur);
  		pte_t pte = pfn_pte(PHYS_PFN(phys + k_cur - k_nobat), PAGE_KERNEL);


You'd then get something like:

Total memory = 2048MB; using 4096kB for hash table
Activating Kernel Userspace Access Protection
Activating Kernel Userspace Execution Prevention
Linux version 6.6.0-rc1+ (chleroy at PO20335.IDSI0.si.c-s.fr) 
(powerpc64-linux-gcc (GCC) 12.2.0, GNU ld (GNU Binutils) 2.39) #461 Tue 
Sep 12 09:37:11 CEST 2023
kasan_init_region: c0000000 30000000 f8000000 fe000000
kasan_init_region: setbat 3 f8000000 7c000000 4000000
kasan_init_region: loop fc000000 fe000000
KASAN init done


Thanks
Christophe


More information about the Linuxppc-dev mailing list