Re: [RFC PATCH] powerpc/book3e: KASAN Full support for 64bit
Christophe Leroy writes: > On 06/03/2019 11:50 PM, Daniel Axtens wrote: >> Christophe Leroy writes: >> >>> Hi, >>> >>> Ok, can you share your .config ? >> >> Sure! This one is with kasan off as the last build I did was testing to >> see if the code reorgisation was the cause of the issues. (it was not) >> >> >> >> >> This was the kasan-enabled config that failed to boot: >> >> > > Same issue with your .config under QEMU: > > A go with gdb shows: > > Breakpoint 3, 0xc0027b6c in exc_0x700_common () > => 0xc0027b6c : f8 01 00 70 std > r0,112(r1) > (gdb) bt > #0 0xc0027b6c in exc_0x700_common () > #1 0xc136f80c in .udbg_init_memcons () > Thanks for debugging this! > Without CONFIG_PPC_EARLY_DEBUG, it boots fine for me. Can you check on > your side ? Yes, that works on my side. > Deactivating KASAN for arch/powerpc/kernel/udbg.o and > arch/powerpc/sysdev/udbg_memcons.o is not enough, we hit a call to > strstr() in register_early_udbg_console(), and once we get rid of it (in > the same way as in prom_init.c) the next issue is register_console() and > I don't know what to do about that one. Disabling early debug seems like a reasonable restriction to add. I'll have a look at modules across this and book3s next. Regards, Daniel > > Christophe > >> >> >> Regards, >> Daniel >> >>> >>> Christophe >>> >>> Le 31/05/2019 à 03:29, Daniel Axtens a écrit : Hi Christophe, I tried this on the t4240rdb and it fails to boot if KASAN is enabled. It does boot with the patch applied but KASAN disabled, so that narrows it down a little bit. I need to focus on 3s first so I'll just drop 3e from my patch set for now. Regards, Daniel > The KASAN shadow area is mapped into vmemmap space: > 0x8000 0400 to 0x8000 0600 . > For this vmemmap has to be disabled. > > Cc: Daniel Axtens > Signed-off-by: Christophe Leroy > --- >arch/powerpc/Kconfig | 1 + >arch/powerpc/Kconfig.debug| 3 +- >arch/powerpc/include/asm/kasan.h | 11 +++ >arch/powerpc/kernel/Makefile | 2 + >arch/powerpc/kernel/head_64.S | 3 + >arch/powerpc/kernel/setup_64.c| 20 +++--- >arch/powerpc/mm/kasan/Makefile| 1 + >arch/powerpc/mm/kasan/kasan_init_64.c | 129 > ++ >8 files changed, 159 insertions(+), 11 deletions(-) >create mode 100644 arch/powerpc/mm/kasan/kasan_init_64.c > > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig > index 1a2fb50126b2..e0b7c45e4dc7 100644 > --- a/arch/powerpc/Kconfig > +++ b/arch/powerpc/Kconfig > @@ -174,6 +174,7 @@ config PPC > select HAVE_ARCH_AUDITSYSCALL > select HAVE_ARCH_JUMP_LABEL > select HAVE_ARCH_KASAN if PPC32 > + select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && > !SPARSEMEM_VMEMMAP > select HAVE_ARCH_KGDB > select HAVE_ARCH_MMAP_RND_BITS > select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT > diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug > index 61febbbdd02b..b4140dd6b4e4 100644 > --- a/arch/powerpc/Kconfig.debug > +++ b/arch/powerpc/Kconfig.debug > @@ -370,4 +370,5 @@ config PPC_FAST_ENDIAN_SWITCH >config KASAN_SHADOW_OFFSET > hex > depends on KASAN > - default 0xe000 > + default 0xe000 if PPC32 > + default 0x68000400 if PPC64 > diff --git a/arch/powerpc/include/asm/kasan.h > b/arch/powerpc/include/asm/kasan.h > index 296e51c2f066..756b3d58f921 100644 > --- a/arch/powerpc/include/asm/kasan.h > +++ b/arch/powerpc/include/asm/kasan.h > @@ -23,10 +23,21 @@ > >#define KASAN_SHADOW_OFFSETASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) > > +#ifdef CONFIG_PPC32 >#define KASAN_SHADOW_END 0UL > >#define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) > > +#else > + > +#include > + > +#define KASAN_SHADOW_SIZE(KERN_VIRT_SIZE >> > KASAN_SHADOW_SCALE_SHIFT) > + > +#define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) > + > +#endif /* CONFIG_PPC32 */ > + >#ifdef CONFIG_KASAN >void kasan_early_init(void); >void kasan_mmu_init(void); > diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile > index 0ea6c4aa3a20..7f232c06f11d 100644 > --- a/arch/powerpc/kernel/Makefile > +++ b/arch/powerpc/kernel/Makefile > @@ -35,6 +35,8 @@ KASAN_SANITIZE_early_32.o := n >KASAN_SANITIZE_cputable.o := n >KASAN_SANITIZE_prom_init.o := n >KASAN_SANITIZE_btext.o := n > +KASAN_SANITIZE_paca.o := n
Re: [RFC PATCH] powerpc/book3e: KASAN Full support for 64bit
On 06/03/2019 11:50 PM, Daniel Axtens wrote: Christophe Leroy writes: Hi, Ok, can you share your .config ? Sure! This one is with kasan off as the last build I did was testing to see if the code reorgisation was the cause of the issues. (it was not) This was the kasan-enabled config that failed to boot: Same issue with your .config under QEMU: A go with gdb shows: Breakpoint 3, 0xc0027b6c in exc_0x700_common () => 0xc0027b6c :f8 01 00 70 std r0,112(r1) (gdb) bt #0 0xc0027b6c in exc_0x700_common () #1 0xc136f80c in .udbg_init_memcons () Without CONFIG_PPC_EARLY_DEBUG, it boots fine for me. Can you check on your side ? Deactivating KASAN for arch/powerpc/kernel/udbg.o and arch/powerpc/sysdev/udbg_memcons.o is not enough, we hit a call to strstr() in register_early_udbg_console(), and once we get rid of it (in the same way as in prom_init.c) the next issue is register_console() and I don't know what to do about that one. Christophe Regards, Daniel Christophe Le 31/05/2019 à 03:29, Daniel Axtens a écrit : Hi Christophe, I tried this on the t4240rdb and it fails to boot if KASAN is enabled. It does boot with the patch applied but KASAN disabled, so that narrows it down a little bit. I need to focus on 3s first so I'll just drop 3e from my patch set for now. Regards, Daniel The KASAN shadow area is mapped into vmemmap space: 0x8000 0400 to 0x8000 0600 . For this vmemmap has to be disabled. Cc: Daniel Axtens Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + arch/powerpc/Kconfig.debug| 3 +- arch/powerpc/include/asm/kasan.h | 11 +++ arch/powerpc/kernel/Makefile | 2 + arch/powerpc/kernel/head_64.S | 3 + arch/powerpc/kernel/setup_64.c| 20 +++--- arch/powerpc/mm/kasan/Makefile| 1 + arch/powerpc/mm/kasan/kasan_init_64.c | 129 ++ 8 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 arch/powerpc/mm/kasan/kasan_init_64.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 1a2fb50126b2..e0b7c45e4dc7 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -174,6 +174,7 @@ config PPC select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_KASAN if PPC32 + select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && !SPARSEMEM_VMEMMAP select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug index 61febbbdd02b..b4140dd6b4e4 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -370,4 +370,5 @@ config PPC_FAST_ENDIAN_SWITCH config KASAN_SHADOW_OFFSET hex depends on KASAN - default 0xe000 + default 0xe000 if PPC32 + default 0x68000400 if PPC64 diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 296e51c2f066..756b3d58f921 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -23,10 +23,21 @@ #define KASAN_SHADOW_OFFSET ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) +#ifdef CONFIG_PPC32 #define KASAN_SHADOW_END 0UL #define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) +#else + +#include + +#define KASAN_SHADOW_SIZE (KERN_VIRT_SIZE >> KASAN_SHADOW_SCALE_SHIFT) + +#define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) + +#endif /* CONFIG_PPC32 */ + #ifdef CONFIG_KASAN void kasan_early_init(void); void kasan_mmu_init(void); diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 0ea6c4aa3a20..7f232c06f11d 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -35,6 +35,8 @@ KASAN_SANITIZE_early_32.o := n KASAN_SANITIZE_cputable.o := n KASAN_SANITIZE_prom_init.o := n KASAN_SANITIZE_btext.o := n +KASAN_SANITIZE_paca.o := n +KASAN_SANITIZE_setup_64.o := n ifdef CONFIG_KASAN CFLAGS_early_32.o += -DDISABLE_BRANCH_PROFILING diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S index 3fad8d499767..80fbd8024fb2 100644 --- a/arch/powerpc/kernel/head_64.S +++ b/arch/powerpc/kernel/head_64.S @@ -966,6 +966,9 @@ start_here_multiplatform: * and SLB setup before we turn on relocation. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif /* Restore parameters passed from prom_init/kexec */ mr r3,r31 bl early_setup /* also sets r13 and SPRG_PACA */ diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index ba404dd9ce1d..d2bf860dd966 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -311,6 +311,16 @@ void __init
Re: [RFC PATCH] powerpc/book3e: KASAN Full support for 64bit
Hi, Ok, can you share your .config ? Christophe Le 31/05/2019 à 03:29, Daniel Axtens a écrit : Hi Christophe, I tried this on the t4240rdb and it fails to boot if KASAN is enabled. It does boot with the patch applied but KASAN disabled, so that narrows it down a little bit. I need to focus on 3s first so I'll just drop 3e from my patch set for now. Regards, Daniel The KASAN shadow area is mapped into vmemmap space: 0x8000 0400 to 0x8000 0600 . For this vmemmap has to be disabled. Cc: Daniel Axtens Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + arch/powerpc/Kconfig.debug| 3 +- arch/powerpc/include/asm/kasan.h | 11 +++ arch/powerpc/kernel/Makefile | 2 + arch/powerpc/kernel/head_64.S | 3 + arch/powerpc/kernel/setup_64.c| 20 +++--- arch/powerpc/mm/kasan/Makefile| 1 + arch/powerpc/mm/kasan/kasan_init_64.c | 129 ++ 8 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 arch/powerpc/mm/kasan/kasan_init_64.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 1a2fb50126b2..e0b7c45e4dc7 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -174,6 +174,7 @@ config PPC select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_KASAN if PPC32 + select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && !SPARSEMEM_VMEMMAP select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug index 61febbbdd02b..b4140dd6b4e4 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -370,4 +370,5 @@ config PPC_FAST_ENDIAN_SWITCH config KASAN_SHADOW_OFFSET hex depends on KASAN - default 0xe000 + default 0xe000 if PPC32 + default 0x68000400 if PPC64 diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 296e51c2f066..756b3d58f921 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -23,10 +23,21 @@ #define KASAN_SHADOW_OFFSET ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) +#ifdef CONFIG_PPC32 #define KASAN_SHADOW_END 0UL #define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) +#else + +#include + +#define KASAN_SHADOW_SIZE (KERN_VIRT_SIZE >> KASAN_SHADOW_SCALE_SHIFT) + +#define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) + +#endif /* CONFIG_PPC32 */ + #ifdef CONFIG_KASAN void kasan_early_init(void); void kasan_mmu_init(void); diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 0ea6c4aa3a20..7f232c06f11d 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -35,6 +35,8 @@ KASAN_SANITIZE_early_32.o := n KASAN_SANITIZE_cputable.o := n KASAN_SANITIZE_prom_init.o := n KASAN_SANITIZE_btext.o := n +KASAN_SANITIZE_paca.o := n +KASAN_SANITIZE_setup_64.o := n ifdef CONFIG_KASAN CFLAGS_early_32.o += -DDISABLE_BRANCH_PROFILING diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S index 3fad8d499767..80fbd8024fb2 100644 --- a/arch/powerpc/kernel/head_64.S +++ b/arch/powerpc/kernel/head_64.S @@ -966,6 +966,9 @@ start_here_multiplatform: * and SLB setup before we turn on relocation. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif /* Restore parameters passed from prom_init/kexec */ mr r3,r31 bl early_setup /* also sets r13 and SPRG_PACA */ diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index ba404dd9ce1d..d2bf860dd966 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -311,6 +311,16 @@ void __init early_setup(unsigned long dt_ptr) DBG(" -> early_setup(), dt_ptr: 0x%lx\n", dt_ptr); /* +* Configure exception handlers. This include setting up trampolines +* if needed, setting exception endian mode, etc... +*/ + configure_exceptions(); + + /* Apply all the dynamic patching */ + apply_feature_fixups(); + setup_feature_keys(); + + /* * Do early initialization using the flattened device * tree, such as retrieving the physical memory map or * calculating/retrieving the hash table size. @@ -325,16 +335,6 @@ void __init early_setup(unsigned long dt_ptr) setup_paca(paca_ptrs[boot_cpuid]); fixup_boot_paca(); - /* -* Configure exception handlers. This include setting up trampolines -* if needed, setting exception endian mode, etc... -*/ - configure_exceptions(); - - /* Apply all the dynamic patching */ - apply_feature_fixups(); - setup_feature_keys(); - /*
Re: [RFC PATCH] powerpc/book3e: KASAN Full support for 64bit
Hi Christophe, I tried this on the t4240rdb and it fails to boot if KASAN is enabled. It does boot with the patch applied but KASAN disabled, so that narrows it down a little bit. I need to focus on 3s first so I'll just drop 3e from my patch set for now. Regards, Daniel > The KASAN shadow area is mapped into vmemmap space: > 0x8000 0400 to 0x8000 0600 . > For this vmemmap has to be disabled. > > Cc: Daniel Axtens > Signed-off-by: Christophe Leroy > --- > arch/powerpc/Kconfig | 1 + > arch/powerpc/Kconfig.debug| 3 +- > arch/powerpc/include/asm/kasan.h | 11 +++ > arch/powerpc/kernel/Makefile | 2 + > arch/powerpc/kernel/head_64.S | 3 + > arch/powerpc/kernel/setup_64.c| 20 +++--- > arch/powerpc/mm/kasan/Makefile| 1 + > arch/powerpc/mm/kasan/kasan_init_64.c | 129 > ++ > 8 files changed, 159 insertions(+), 11 deletions(-) > create mode 100644 arch/powerpc/mm/kasan/kasan_init_64.c > > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig > index 1a2fb50126b2..e0b7c45e4dc7 100644 > --- a/arch/powerpc/Kconfig > +++ b/arch/powerpc/Kconfig > @@ -174,6 +174,7 @@ config PPC > select HAVE_ARCH_AUDITSYSCALL > select HAVE_ARCH_JUMP_LABEL > select HAVE_ARCH_KASAN if PPC32 > + select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && > !SPARSEMEM_VMEMMAP > select HAVE_ARCH_KGDB > select HAVE_ARCH_MMAP_RND_BITS > select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT > diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug > index 61febbbdd02b..b4140dd6b4e4 100644 > --- a/arch/powerpc/Kconfig.debug > +++ b/arch/powerpc/Kconfig.debug > @@ -370,4 +370,5 @@ config PPC_FAST_ENDIAN_SWITCH > config KASAN_SHADOW_OFFSET > hex > depends on KASAN > - default 0xe000 > + default 0xe000 if PPC32 > + default 0x68000400 if PPC64 > diff --git a/arch/powerpc/include/asm/kasan.h > b/arch/powerpc/include/asm/kasan.h > index 296e51c2f066..756b3d58f921 100644 > --- a/arch/powerpc/include/asm/kasan.h > +++ b/arch/powerpc/include/asm/kasan.h > @@ -23,10 +23,21 @@ > > #define KASAN_SHADOW_OFFSET ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) > > +#ifdef CONFIG_PPC32 > #define KASAN_SHADOW_END 0UL > > #define KASAN_SHADOW_SIZE(KASAN_SHADOW_END - KASAN_SHADOW_START) > > +#else > + > +#include > + > +#define KASAN_SHADOW_SIZE(KERN_VIRT_SIZE >> KASAN_SHADOW_SCALE_SHIFT) > + > +#define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) > + > +#endif /* CONFIG_PPC32 */ > + > #ifdef CONFIG_KASAN > void kasan_early_init(void); > void kasan_mmu_init(void); > diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile > index 0ea6c4aa3a20..7f232c06f11d 100644 > --- a/arch/powerpc/kernel/Makefile > +++ b/arch/powerpc/kernel/Makefile > @@ -35,6 +35,8 @@ KASAN_SANITIZE_early_32.o := n > KASAN_SANITIZE_cputable.o := n > KASAN_SANITIZE_prom_init.o := n > KASAN_SANITIZE_btext.o := n > +KASAN_SANITIZE_paca.o := n > +KASAN_SANITIZE_setup_64.o := n > > ifdef CONFIG_KASAN > CFLAGS_early_32.o += -DDISABLE_BRANCH_PROFILING > diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S > index 3fad8d499767..80fbd8024fb2 100644 > --- a/arch/powerpc/kernel/head_64.S > +++ b/arch/powerpc/kernel/head_64.S > @@ -966,6 +966,9 @@ start_here_multiplatform: >* and SLB setup before we turn on relocation. >*/ > > +#ifdef CONFIG_KASAN > + bl kasan_early_init > +#endif > /* Restore parameters passed from prom_init/kexec */ > mr r3,r31 > bl early_setup /* also sets r13 and SPRG_PACA */ > diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c > index ba404dd9ce1d..d2bf860dd966 100644 > --- a/arch/powerpc/kernel/setup_64.c > +++ b/arch/powerpc/kernel/setup_64.c > @@ -311,6 +311,16 @@ void __init early_setup(unsigned long dt_ptr) > DBG(" -> early_setup(), dt_ptr: 0x%lx\n", dt_ptr); > > /* > + * Configure exception handlers. This include setting up trampolines > + * if needed, setting exception endian mode, etc... > + */ > + configure_exceptions(); > + > + /* Apply all the dynamic patching */ > + apply_feature_fixups(); > + setup_feature_keys(); > + > + /* >* Do early initialization using the flattened device >* tree, such as retrieving the physical memory map or >* calculating/retrieving the hash table size. > @@ -325,16 +335,6 @@ void __init early_setup(unsigned long dt_ptr) > setup_paca(paca_ptrs[boot_cpuid]); > fixup_boot_paca(); > > - /* > - * Configure exception handlers. This include setting up trampolines > - * if needed, setting exception endian mode, etc... > - */ > - configure_exceptions(); > - > - /* Apply all the dynamic patching */ > -
Re: [RFC PATCH] powerpc/book3e: KASAN Full support for 64bit
Hi Christophe, > Daniel, > > This patch applies on top of my series. > > With this patch, I've managed to enable KASAN without the changes you > proposed on the KASAN core. This allows a full support of KASAN, ie not > limited to KASAN_MINIMAL. > > There is still some details to address, but it boots OK on qemu-e500. > > Can you have a try and tell me if it works on your side too ? > > It will likely fail for modules at the time being as I did nothing about it. > > Tell me if you continue working on it. I don't plan to spend more time > on it for the time being. Thanks!! I will have a look - I've been trying to do something on 3s Radix and was hoping to apply lessons learned from that to the 3e case. So it may take a little while but I will eventually get back to this. Regards, Daniel > > Like I did on PPC32, it would be good to create an early_64.c file and > move into it the few functions from setup_64.c and paca.c that are > called before feature_fixups are done, in order to not disable KASAN on > the entire paca.c and setup_64.c > > I guess we could reduce a bit the size of the IOREMAP_AREA and put KASAN > on top of it instead of using VMEMMAP space, allthough I don't have a > clean view of how it would cooperate with VMEMMMAP if we keep it enabled. > > I've not been able to identify what is the largest size of the linear > mapping (ie the 0xc000 region). > > Christophe > > Le 28/03/2019 à 15:21, Christophe Leroy a écrit : >> The KASAN shadow area is mapped into vmemmap space: >> 0x8000 0400 to 0x8000 0600 . >> For this vmemmap has to be disabled. >> >> Cc: Daniel Axtens >> Signed-off-by: Christophe Leroy >> --- >> arch/powerpc/Kconfig | 1 + >> arch/powerpc/Kconfig.debug| 3 +- >> arch/powerpc/include/asm/kasan.h | 11 +++ >> arch/powerpc/kernel/Makefile | 2 + >> arch/powerpc/kernel/head_64.S | 3 + >> arch/powerpc/kernel/setup_64.c| 20 +++--- >> arch/powerpc/mm/kasan/Makefile| 1 + >> arch/powerpc/mm/kasan/kasan_init_64.c | 129 >> ++ >> 8 files changed, 159 insertions(+), 11 deletions(-) >> create mode 100644 arch/powerpc/mm/kasan/kasan_init_64.c >> >> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig >> index 1a2fb50126b2..e0b7c45e4dc7 100644 >> --- a/arch/powerpc/Kconfig >> +++ b/arch/powerpc/Kconfig >> @@ -174,6 +174,7 @@ config PPC >> select HAVE_ARCH_AUDITSYSCALL >> select HAVE_ARCH_JUMP_LABEL >> select HAVE_ARCH_KASAN if PPC32 >> +select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && >> !SPARSEMEM_VMEMMAP >> select HAVE_ARCH_KGDB >> select HAVE_ARCH_MMAP_RND_BITS >> select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT >> diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug >> index 61febbbdd02b..b4140dd6b4e4 100644 >> --- a/arch/powerpc/Kconfig.debug >> +++ b/arch/powerpc/Kconfig.debug >> @@ -370,4 +370,5 @@ config PPC_FAST_ENDIAN_SWITCH >> config KASAN_SHADOW_OFFSET >> hex >> depends on KASAN >> -default 0xe000 >> +default 0xe000 if PPC32 >> +default 0x68000400 if PPC64 >> diff --git a/arch/powerpc/include/asm/kasan.h >> b/arch/powerpc/include/asm/kasan.h >> index 296e51c2f066..756b3d58f921 100644 >> --- a/arch/powerpc/include/asm/kasan.h >> +++ b/arch/powerpc/include/asm/kasan.h >> @@ -23,10 +23,21 @@ >> >> #define KASAN_SHADOW_OFFSETASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) >> >> +#ifdef CONFIG_PPC32 >> #define KASAN_SHADOW_END 0UL >> >> #define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) >> >> +#else >> + >> +#include >> + >> +#define KASAN_SHADOW_SIZE (KERN_VIRT_SIZE >> KASAN_SHADOW_SCALE_SHIFT) >> + >> +#define KASAN_SHADOW_END(KASAN_SHADOW_START + KASAN_SHADOW_SIZE) >> + >> +#endif /* CONFIG_PPC32 */ >> + >> #ifdef CONFIG_KASAN >> void kasan_early_init(void); >> void kasan_mmu_init(void); >> diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile >> index 0ea6c4aa3a20..7f232c06f11d 100644 >> --- a/arch/powerpc/kernel/Makefile >> +++ b/arch/powerpc/kernel/Makefile >> @@ -35,6 +35,8 @@ KASAN_SANITIZE_early_32.o := n >> KASAN_SANITIZE_cputable.o := n >> KASAN_SANITIZE_prom_init.o := n >> KASAN_SANITIZE_btext.o := n >> +KASAN_SANITIZE_paca.o := n >> +KASAN_SANITIZE_setup_64.o := n >> >> ifdef CONFIG_KASAN >> CFLAGS_early_32.o += -DDISABLE_BRANCH_PROFILING >> diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S >> index 3fad8d499767..80fbd8024fb2 100644 >> --- a/arch/powerpc/kernel/head_64.S >> +++ b/arch/powerpc/kernel/head_64.S >> @@ -966,6 +966,9 @@ start_here_multiplatform: >> * and SLB setup before we turn on relocation. >> */ >> >> +#ifdef CONFIG_KASAN >> +bl kasan_early_init >> +#endif >> /* Restore parameters passed from prom_init/kexec */ >> mr r3,r31 >>
Re: [RFC PATCH] powerpc/book3e: KASAN Full support for 64bit
Daniel, This patch applies on top of my series. With this patch, I've managed to enable KASAN without the changes you proposed on the KASAN core. This allows a full support of KASAN, ie not limited to KASAN_MINIMAL. There is still some details to address, but it boots OK on qemu-e500. Can you have a try and tell me if it works on your side too ? It will likely fail for modules at the time being as I did nothing about it. Tell me if you continue working on it. I don't plan to spend more time on it for the time being. Like I did on PPC32, it would be good to create an early_64.c file and move into it the few functions from setup_64.c and paca.c that are called before feature_fixups are done, in order to not disable KASAN on the entire paca.c and setup_64.c I guess we could reduce a bit the size of the IOREMAP_AREA and put KASAN on top of it instead of using VMEMMAP space, allthough I don't have a clean view of how it would cooperate with VMEMMMAP if we keep it enabled. I've not been able to identify what is the largest size of the linear mapping (ie the 0xc000 region). Christophe Le 28/03/2019 à 15:21, Christophe Leroy a écrit : The KASAN shadow area is mapped into vmemmap space: 0x8000 0400 to 0x8000 0600 . For this vmemmap has to be disabled. Cc: Daniel Axtens Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + arch/powerpc/Kconfig.debug| 3 +- arch/powerpc/include/asm/kasan.h | 11 +++ arch/powerpc/kernel/Makefile | 2 + arch/powerpc/kernel/head_64.S | 3 + arch/powerpc/kernel/setup_64.c| 20 +++--- arch/powerpc/mm/kasan/Makefile| 1 + arch/powerpc/mm/kasan/kasan_init_64.c | 129 ++ 8 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 arch/powerpc/mm/kasan/kasan_init_64.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 1a2fb50126b2..e0b7c45e4dc7 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -174,6 +174,7 @@ config PPC select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_KASAN if PPC32 + select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && !SPARSEMEM_VMEMMAP select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug index 61febbbdd02b..b4140dd6b4e4 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -370,4 +370,5 @@ config PPC_FAST_ENDIAN_SWITCH config KASAN_SHADOW_OFFSET hex depends on KASAN - default 0xe000 + default 0xe000 if PPC32 + default 0x68000400 if PPC64 diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 296e51c2f066..756b3d58f921 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -23,10 +23,21 @@ #define KASAN_SHADOW_OFFSET ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) +#ifdef CONFIG_PPC32 #define KASAN_SHADOW_END 0UL #define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) +#else + +#include + +#define KASAN_SHADOW_SIZE (KERN_VIRT_SIZE >> KASAN_SHADOW_SCALE_SHIFT) + +#define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) + +#endif /* CONFIG_PPC32 */ + #ifdef CONFIG_KASAN void kasan_early_init(void); void kasan_mmu_init(void); diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 0ea6c4aa3a20..7f232c06f11d 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -35,6 +35,8 @@ KASAN_SANITIZE_early_32.o := n KASAN_SANITIZE_cputable.o := n KASAN_SANITIZE_prom_init.o := n KASAN_SANITIZE_btext.o := n +KASAN_SANITIZE_paca.o := n +KASAN_SANITIZE_setup_64.o := n ifdef CONFIG_KASAN CFLAGS_early_32.o += -DDISABLE_BRANCH_PROFILING diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S index 3fad8d499767..80fbd8024fb2 100644 --- a/arch/powerpc/kernel/head_64.S +++ b/arch/powerpc/kernel/head_64.S @@ -966,6 +966,9 @@ start_here_multiplatform: * and SLB setup before we turn on relocation. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif /* Restore parameters passed from prom_init/kexec */ mr r3,r31 bl early_setup /* also sets r13 and SPRG_PACA */ diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index ba404dd9ce1d..d2bf860dd966 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -311,6 +311,16 @@ void __init early_setup(unsigned long dt_ptr) DBG(" -> early_setup(), dt_ptr: 0x%lx\n", dt_ptr); /* +* Configure exception handlers. This include setting up trampolines +* if needed, setting exception endian