Skip to contentSkip to conversation

KASan for Arm

PATCH Superseded Linus Walleij 4 participants 36 messages Oct 1, 2020 – Oct 6, 2020

Subsystems (4)

v14 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v14 cover KASan for Arm

This is the 14th iteration of KASan for ARM/Aarch32.

I have added one patch in the beginning of the series to fix the issue when the DTB (often attached DTB) ends up in lowmem. It also amends ARM to copy the device tree instead of just unflattening it and using it from where it is.

This fixes my particular issue on the Qualcomm APQ8060 and I hope it may also solve Florian's issue and what Ard has been seeing. If you inspect patch 1/6 you can see what has been going on for me. My hypothesis about what was going on was mostly right.

You are encouraged to test this patch set to find memory out of bounds bugs with ARM32 platforms and drivers.

There is a git branch you can pull in:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=kasan

Abbott Liu (1):
ARM: Define the virtual space of KASan's shadow region

Andrey Ryabinin (3):
ARM: Disable KASan instrumentation for some code
ARM: Replace string mem* functions for KASan
ARM: Enable KASan for ARM

Linus Walleij (2):
ARM: Handle a device tree in lowmem
ARM: Initialize the mapping of KASan shadow memory

 Documentation/arm/memory.rst                  |   5 +
 Documentation/dev-tools/kasan.rst             |   4 +-
 .../features/debug/KASAN/arch-support.txt     |   2 +-
 arch/arm/Kconfig                              |  10 +
 arch/arm/boot/compressed/Makefile             |   1 +
 arch/arm/boot/compressed/string.c             |  19 ++
 arch/arm/include/asm/kasan.h                  |  32 ++
 arch/arm/include/asm/kasan_def.h              |  81 +++++
 arch/arm/include/asm/memory.h                 |   5 +
 arch/arm/include/asm/pgalloc.h                |   8 +-
 arch/arm/include/asm/prom.h                   |   5 +
 arch/arm/include/asm/string.h                 |  21 ++
 arch/arm/include/asm/thread_info.h            |   8 +
 arch/arm/include/asm/uaccess-asm.h            |   2 +-
 arch/arm/kernel/devtree.c                     |  14 +-
 arch/arm/kernel/entry-armv.S                  |   3 +-
 arch/arm/kernel/entry-common.S                |   9 +-
 arch/arm/kernel/head-common.S                 |   7 +-
 arch/arm/kernel/setup.c                       |  10 +-
 arch/arm/kernel/unwind.c                      |   6 +-
 arch/arm/lib/memcpy.S                         |   3 +
 arch/arm/lib/memmove.S                        |   5 +-
 arch/arm/lib/memset.S                         |   3 +
 arch/arm/mm/Makefile                          |   5 +
 arch/arm/mm/kasan_init.c                      | 286 ++++++++++++++++++
 arch/arm/mm/mmu.c                             |  55 +++-
 arch/arm/mm/pgd.c                             |  16 +-
 arch/arm/vdso/Makefile                        |   2 +
 28 files changed, 608 insertions(+), 19 deletions(-)
 create mode 100644 arch/arm/include/asm/kasan.h
 create mode 100644 arch/arm/include/asm/kasan_def.h
 create mode 100644 arch/arm/mm/kasan_init.c
Signature · 7 lines
2.26.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

PATCH v14 1/6 ARM: Handle a device tree in lowmem

If the kernel grows big, it can happen that the kernel does not fit in the first memory block. This is normally out-of-spec but it turns out that the boot usually survives this.

What it does not survive is that the prepare_page_table() code wipes all PMDs (page table pointers for the virtual memory) over lowmem, including the PMD where the attached DTB is stored. (The variable is named atags but this only really happens for DTBs.)

Let's deal with this.

First, this makes the code jump over two PMDs where the DTB is stored if it ends up in lowmem: it could happen that the DTB crosses a PMD_SIZE boundary so to be on the safe side we need to skip over the one we know it starts in and also the next.

Next we make ARM use unflatten_and_copy_device_tree() instead of just unflattening it where it is. Currently we just assume that the device tree will be in some kind of "safe" memory and as proven by KASan it will sometimes end up in the kernel lowmem which will create crashes as the kernel will clear all lowmem PMDs while initializing the memory manager.

Finally, we add a new call to the MMU code to go in and clear out the PMDs in lowmem if the device tree was there.

Example boot log on an affected system:

ATAGs/DTB found in lowmem, skip clearing PMD @0xc3000000 ATAGs/DTB found in lowmem, skip clearing PMD @0xc3200000 (...)
DTB @430af0e0 (physical) copied to @cc394d80 (virtual) Clear ATAGs/DTB PMD @0xc3000000
Clear ATAGs/DTB PMD @0xc3200000

This fixes the problem where the Qualcomm APQ8060 would not boot while using KASan.

---
ChangeLog v13->v14:
- New patch fixing the regression when using KASan on at least one of the affected platforms.

---
 arch/arm/include/asm/prom.h |  5 +++++
 arch/arm/kernel/devtree.c   | 14 +++++++++++++-
 arch/arm/kernel/setup.c     |  8 ++++++--
 arch/arm/mm/mmu.c           | 37 +++++++++++++++++++++++++++++++++++--
 4 files changed, 59 insertions(+), 5 deletions(-)
arch/arm/include/asm/prom.h +5 -0
index 1e36c40533c1..41e189a2631c 100644
@@ -11,6 +11,7 @@
 
 extern const struct machine_desc *setup_machine_fdt(unsigned int dt_phys);
 extern void __init arm_dt_init_cpu_maps(void);
+void __init setup_machine_copy_fdt(unsigned int dt_phys);
 
 #else /* CONFIG_OF */
 
@@ -21,5 +22,9 @@ static inline const struct machine_desc *setup_machine_fdt(unsigned int dt_phys)
 
 static inline void arm_dt_init_cpu_maps(void) { }
 
+static inline void setup_machine_copy_fdt(unsigned int dt_phys)
+{
+}
+
 #endif /* CONFIG_OF */
 #endif /* ASMARM_PROM_H */
arch/arm/kernel/devtree.c +13 -1
index 39c978698406..267011e133a7 100644
@@ -23,7 +23,7 @@
 #include <asm/smp_plat.h>
 #include <asm/mach/arch.h>
 #include <asm/mach-types.h>
-
+#include <asm/mach/map.h>
 
 #ifdef CONFIG_SMP
 extern struct of_cpu_method __cpu_method_of_table[];
@@ -257,3 +257,15 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
 
 	return mdesc;
 }
+
+extern void arm_mm_clear_atag_pages(void);
+
+void __init setup_machine_copy_fdt(unsigned int dt_phys)
+{
+	/* This will point the DT parser to the new location */
+	unflatten_and_copy_device_tree();
+	pr_info("DTB @%08x (physical) copied to @%px (virtual)\n",
+		dt_phys, initial_boot_params);
+	/* Clear out any mappings over the device tree */
+	arm_mm_clear_atag_pages();
+}
arch/arm/kernel/setup.c +6 -2
index d8e18cdd96d3..d0562cdc919e 100644
@@ -1076,11 +1076,14 @@ void __init hyp_mode_check(void)
 void __init setup_arch(char **cmdline_p)
 {
 	const struct machine_desc *mdesc;
+	bool using_dt = false;
 
 	setup_processor();
 	mdesc = setup_machine_fdt(__atags_pointer);
 	if (!mdesc)
 		mdesc = setup_machine_tags(__atags_pointer, __machine_arch_type);
+	else
+		using_dt = true;
 	if (!mdesc) {
 		early_print("\nError: invalid dtb and unrecognized/unsupported machine ID\n");
 		early_print("  r1=0x%08x, r2=0x%08x\n", __machine_arch_type,
@@ -1109,7 +1112,6 @@ void __init setup_arch(char **cmdline_p)
 
 	early_fixmap_init();
 	early_ioremap_init();
-
 	parse_early_param();
 
 #ifdef CONFIG_MMU
@@ -1135,7 +1137,9 @@ void __init setup_arch(char **cmdline_p)
 	if (mdesc->restart)
 		arm_pm_restart = mdesc->restart;
 
-	unflatten_device_tree();
+	/* Remap and copy the device tree */
+	if (using_dt)
+		setup_machine_copy_fdt(__atags_pointer);
 
 	arm_dt_init_cpu_maps();
 	psci_dt_init();
arch/arm/mm/mmu.c +35 -2
index c36f977b2ccb..732c856c357d 100644
@@ -68,6 +68,8 @@ pgprot_t pgprot_kernel;
 EXPORT_SYMBOL(pgprot_user);
 EXPORT_SYMBOL(pgprot_kernel);
 
+extern unsigned long __atags_pointer;
+
 struct cachepolicy {
 	const char	policy[16];
 	unsigned int	cr_mask;
@@ -1258,6 +1260,7 @@ void __init adjust_lowmem_bounds(void)
 static inline void prepare_page_table(void)
 {
 	unsigned long addr;
+	unsigned long atags;
 	phys_addr_t end;
 
 	/*
@@ -1284,9 +1287,40 @@ static inline void prepare_page_table(void)
 	 * Clear out all the kernel space mappings, except for the first
 	 * memory bank, up to the vmalloc region.
 	 */
+	atags = __phys_to_virt(__atags_pointer);
+	atags &= PMD_MASK;
 	for (addr = __phys_to_virt(end);
-	     addr < VMALLOC_START; addr += PMD_SIZE)
+	     addr < VMALLOC_START; addr += PMD_SIZE) {
+		if (addr >= atags && addr < (atags + 2 * PMD_SIZE)) {
+			pr_info("ATAGs/DTB found in lowmem, skip clearing PMD @0x%08lx\n", addr);
+			continue;
+		}
 		pmd_clear(pmd_off_k(addr));
+	}
+}
+
+void __init arm_mm_clear_atag_pages(void)
+{
+	unsigned long addr;
+	unsigned long atags;
+	phys_addr_t end;
+
+	/*
+	 * Clear out the kernel space mappings used by the attached DTB if
+	 * it happens to end up in lowmem.
+	 */
+	end = memblock.memory.regions[0].base + memblock.memory.regions[0].size;
+	if (end >= arm_lowmem_limit)
+		end = arm_lowmem_limit;
+	atags = __phys_to_virt(__atags_pointer);
+	atags &= PMD_MASK;
+	for (addr = __phys_to_virt(end);
+	     addr < VMALLOC_START; addr += PMD_SIZE) {
+		if (addr >= atags && addr < (atags + 2 * PMD_SIZE)) {
+			pr_info("Clear ATAGs/DTB PMD @0x%08lx\n", addr);
+			pmd_clear(pmd_off_k(addr));
+		}
+	}
 }
 
 #ifdef CONFIG_ARM_LPAE
@@ -1503,7 +1537,6 @@ static void __init map_lowmem(void)
 }
 
 #ifdef CONFIG_ARM_PV_FIXUP
-extern unsigned long __atags_pointer;
 typedef void pgtables_remap(long long offset, unsigned long pgd, void *bdata);
 pgtables_remap lpae_pgtables_remap_asm;
 
Signature · 7 lines
2.26.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 37 lines · Linus Walleij

If the kernel grows big, it can happen that the kernel does not fit in the first memory block. This is normally out-of-spec but it turns out that the boot usually survives this.

What it does not survive is that the prepare_page_table() code wipes all PMDs (page table pointers for the virtual memory) over lowmem, including the PMD where the attached DTB is stored. (The variable is named atags but this only really happens for DTBs.)

Let's deal with this.

First, this makes the code jump over two PMDs where the DTB is stored if it ends up in lowmem: it could happen that the DTB crosses a PMD_SIZE boundary so to be on the safe side we need to skip over the one we know it starts in and also the next.

Next we make ARM use unflatten_and_copy_device_tree() instead of just unflattening it where it is. Currently we just assume that the device tree will be in some kind of "safe" memory and as proven by KASan it will sometimes end up in the kernel lowmem which will create crashes as the kernel will clear all lowmem PMDs while initializing the memory manager.

Finally, we add a new call to the MMU code to go in and clear out the PMDs in lowmem if the device tree was there.

Example boot log on an affected system:

ATAGs/DTB found in lowmem, skip clearing PMD @0xc3000000 ATAGs/DTB found in lowmem, skip clearing PMD @0xc3200000 (...)
DTB @430af0e0 (physical) copied to @cc394d80 (virtual) Clear ATAGs/DTB PMD @0xc3000000
Clear ATAGs/DTB PMD @0xc3200000

Quoted 4 lines

This fixes the problem where the Qualcomm APQ8060 would not boot while using KASan.

This is a much cleaner version than what we had been carrying in our STB Linux distribution which was:

https://github.com/Broadcom/stblinux-4.9/blob/master/linux/arch/arm/kernel/head.S#L251

https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/of/fdt.c#L688

Signature · 6 lines
Florian

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#3 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 5 lines · Florian Fainelli

This is a much cleaner version than what we had been carrying in our STB Linux distribution which was:

https://github.com/Broadcom/stblinux-4.9/blob/master/linux/arch/arm/kernel/head.S#L251
https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/of/fdt.c#L688

Oh I was surprised that it didn't happen more often. It turns out it does :D
Do you also get the prints on affected platforms? Reviewed-by?

Let's see what others say about this approach and then put it in Russell's patch tracker.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#4 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

In reply to Linus Walleij
Quoted 38 lines · Linus Walleij

If the kernel grows big, it can happen that the kernel does not fit in the first memory block. This is normally out-of-spec but it turns out that the boot usually survives this.

What it does not survive is that the prepare_page_table() code wipes all PMDs (page table pointers for the virtual memory) over lowmem, including the PMD where the attached DTB is stored. (The variable is named atags but this only really happens for DTBs.)

Let's deal with this.

First, this makes the code jump over two PMDs where the DTB is stored if it ends up in lowmem: it could happen that the DTB crosses a PMD_SIZE boundary so to be on the safe side we need to skip over the one we know it starts in and also the next.

Next we make ARM use unflatten_and_copy_device_tree() instead of just unflattening it where it is. Currently we just assume that the device tree will be in some kind of "safe" memory and as proven by KASan it will sometimes end up in the kernel lowmem which will create crashes as the kernel will clear all lowmem PMDs while initializing the memory manager.

Finally, we add a new call to the MMU code to go in and clear out the PMDs in lowmem if the device tree was there.

Example boot log on an affected system:

ATAGs/DTB found in lowmem, skip clearing PMD @0xc3000000 ATAGs/DTB found in lowmem, skip clearing PMD @0xc3200000 (...)
DTB @430af0e0 (physical) copied to @cc394d80 (virtual) Clear ATAGs/DTB PMD @0xc3000000
Clear ATAGs/DTB PMD @0xc3200000

Quoted 4 lines

This fixes the problem where the Qualcomm APQ8060 would not boot while using KASan.

OK, so if I am understanding this correctly, the root problem is that the kernel unmaps the memory that the attached DTB resides in, right? So how is it possible that the kernel does not fit in the first memblock? Doesn't that mean that we are using memory that is not available to begin with?

Do you have a dump of the memory layout on the platform in question? How do 0xc3000000/0xc3200000 map onto physical addresses, and how are those described?

If that memory is not actually available to begin with, this fix papers over the problem, and we should be fixing this in the decompressor instead.

Quoted 172 lines

---
ChangeLog v13->v14:
- New patch fixing the regression when using KASan on at least one of the affected platforms.

---
 arch/arm/include/asm/prom.h |  5 +++++
 arch/arm/kernel/devtree.c   | 14 +++++++++++++-
 arch/arm/kernel/setup.c     |  8 ++++++--
 arch/arm/mm/mmu.c           | 37 +++++++++++++++++++++++++++++++++++--
 4 files changed, 59 insertions(+), 5 deletions(-)
arch/arm/include/asm/prom.h +5 -0
index 1e36c40533c1..41e189a2631c 100644
@@ -11,6 +11,7 @@
 
 extern const struct machine_desc *setup_machine_fdt(unsigned int dt_phys);
 extern void __init arm_dt_init_cpu_maps(void);
+void __init setup_machine_copy_fdt(unsigned int dt_phys);
 
 #else /* CONFIG_OF */
 
@@ -21,5 +22,9 @@ static inline const struct machine_desc *setup_machine_fdt(unsigned int dt_phys)
 
 static inline void arm_dt_init_cpu_maps(void) { }
 
+static inline void setup_machine_copy_fdt(unsigned int dt_phys)
+{
+}
+
 #endif /* CONFIG_OF */
 #endif /* ASMARM_PROM_H */
arch/arm/kernel/devtree.c +13 -1
index 39c978698406..267011e133a7 100644
@@ -23,7 +23,7 @@
 #include <asm/smp_plat.h>
 #include <asm/mach/arch.h>
 #include <asm/mach-types.h>
-
+#include <asm/mach/map.h>
 
 #ifdef CONFIG_SMP
 extern struct of_cpu_method __cpu_method_of_table[];
@@ -257,3 +257,15 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys)
 
        return mdesc;
 }
+
+extern void arm_mm_clear_atag_pages(void);
+
+void __init setup_machine_copy_fdt(unsigned int dt_phys)
+{
+       /* This will point the DT parser to the new location */
+       unflatten_and_copy_device_tree();
+       pr_info("DTB @%08x (physical) copied to @%px (virtual)\n",
+               dt_phys, initial_boot_params);
+       /* Clear out any mappings over the device tree */
+       arm_mm_clear_atag_pages();
+}
arch/arm/kernel/setup.c +6 -2
index d8e18cdd96d3..d0562cdc919e 100644
@@ -1076,11 +1076,14 @@ void __init hyp_mode_check(void)
 void __init setup_arch(char **cmdline_p)
 {
        const struct machine_desc *mdesc;
+       bool using_dt = false;
 
        setup_processor();
        mdesc = setup_machine_fdt(__atags_pointer);
        if (!mdesc)
                mdesc = setup_machine_tags(__atags_pointer, __machine_arch_type);
+       else
+               using_dt = true;
        if (!mdesc) {
                early_print("\nError: invalid dtb and unrecognized/unsupported machine ID\n");
                early_print("  r1=0x%08x, r2=0x%08x\n", __machine_arch_type,
@@ -1109,7 +1112,6 @@ void __init setup_arch(char **cmdline_p)
 
        early_fixmap_init();
        early_ioremap_init();
-
        parse_early_param();
 
 #ifdef CONFIG_MMU
@@ -1135,7 +1137,9 @@ void __init setup_arch(char **cmdline_p)
        if (mdesc->restart)
                arm_pm_restart = mdesc->restart;
 
-       unflatten_device_tree();
+       /* Remap and copy the device tree */
+       if (using_dt)
+               setup_machine_copy_fdt(__atags_pointer);
 
        arm_dt_init_cpu_maps();
        psci_dt_init();
arch/arm/mm/mmu.c +35 -3
index c36f977b2ccb..732c856c357d 100644
@@ -68,6 +68,8 @@ pgprot_t pgprot_kernel;
 EXPORT_SYMBOL(pgprot_user);
 EXPORT_SYMBOL(pgprot_kernel);
 
+extern unsigned long __atags_pointer;
+
 struct cachepolicy {
        const char      policy[16];
        unsigned int    cr_mask;
@@ -1258,6 +1260,7 @@ void __init adjust_lowmem_bounds(void)
 static inline void prepare_page_table(void)
 {
        unsigned long addr;
+       unsigned long atags;
        phys_addr_t end;
 
        /*
@@ -1284,9 +1287,40 @@ static inline void prepare_page_table(void)
         * Clear out all the kernel space mappings, except for the first
         * memory bank, up to the vmalloc region.
         */
+       atags = __phys_to_virt(__atags_pointer);
+       atags &= PMD_MASK;
        for (addr = __phys_to_virt(end);
-            addr < VMALLOC_START; addr += PMD_SIZE)
+            addr < VMALLOC_START; addr += PMD_SIZE) {
+               if (addr >= atags && addr < (atags + 2 * PMD_SIZE)) {
+                       pr_info("ATAGs/DTB found in lowmem, skip clearing PMD @0x%08lx\n", addr);
+                       continue;
+               }
                pmd_clear(pmd_off_k(addr));
+       }
+}
+
+void __init arm_mm_clear_atag_pages(void)
+{
+       unsigned long addr;
+       unsigned long atags;
+       phys_addr_t end;
+
+       /*
+        * Clear out the kernel space mappings used by the attached DTB if
+        * it happens to end up in lowmem.
+        */
+       end = memblock.memory.regions[0].base + memblock.memory.regions[0].size;
+       if (end >= arm_lowmem_limit)
+               end = arm_lowmem_limit;
+       atags = __phys_to_virt(__atags_pointer);
+       atags &= PMD_MASK;
+       for (addr = __phys_to_virt(end);
+            addr < VMALLOC_START; addr += PMD_SIZE) {
+               if (addr >= atags && addr < (atags + 2 * PMD_SIZE)) {
+                       pr_info("Clear ATAGs/DTB PMD @0x%08lx\n", addr);
+                       pmd_clear(pmd_off_k(addr));
+               }
+       }
 }
 
 #ifdef CONFIG_ARM_LPAE
@@ -1503,7 +1537,6 @@ static void __init map_lowmem(void)
 }
 
 #ifdef CONFIG_ARM_PV_FIXUP
-extern unsigned long __atags_pointer;
 typedef void pgtables_remap(long long offset, unsigned long pgd, void *bdata);
 pgtables_remap lpae_pgtables_remap_asm;
 
--
Quoted 2 lines

2.26.2

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 4 lines · Ard Biesheuvel

On Thu, 1 Oct 2020 at 17:22, Linus Walleij <[email protected]> wrote:

OK, so if I am understanding this correctly, the root problem is that the kernel unmaps the memory that the attached DTB resides in, right?

Yups, or, well in some places the kernel knows that the DT is there so it sets up two 1MB sections over it, and then it assumes "no-one is ever gonna touch those two section mappings, OK".

It's this code from head.S:

/*
* Then map boot params address in r2 if specified.
* We map 2 sections in case the ATAGs/DTB crosses a section boundary. */
mov r0, r2, lsr #SECTION_SHIFT
movs r0, r0, lsl #SECTION_SHIFT
subne r3, r0, r8
addne r3, r3, #PAGE_OFFSET
addne r3, r4, r3, lsr #(SECTION_SHIFT - PMD_ORDER)
orrne r6, r7, r0
strne r6, [r3], #1 << PMD_ORDER
addne r6, r6, #1 << SECTION_SHIFT
strne r6, [r3]

Then these two blocks end up in lowmem, and as the kernel clears the PMD:s in prepare_page_table(), in mm/mmu.c is clears the two PMDs covering the device tree under some circumstances.

[Ard]

Quoted 8 lines

So how is it possible that the kernel does not fit in the first memblock? Doesn't that mean that we are using memory that is not available to begin with?

Do you have a dump of the memory layout on the platform in question?

How do 0xc3000000/0xc3200000 map onto physical addresses, and how are those described?

The kernel per se actually fits inside the first memblock, but not the attached DTB which ends up above the *uncompressed* kernel, so there is always a gap between the end of the kernel text and the DTB. See this illustration:
https://dflund.se/~triad/images/decompress-5.jpg

This is how it looks with all my funky debug code (that I am in the process of merging by the way, so it is easier to debug things like this):

This platform boots using fastboot:

# fastboot --base 40200000 --cmdline "console=ttyMSM0,115200,n8" boot zImage
So we load the zImage at 0x40200000
which is where the physical memory starts on this
platform because the modem is using 0x0-0x41ffffff.

Then I get these debug prints:

DTB:0x410A09C0 (0x000051B5)
C:0x402080C0-0x410A5C20->0x42217100-0x430B4C60
DTB:0x430AFA00 (0x00005242)

This means the DTB is first found in physical memory at 0x410A09C0 then we relocate the kernel from 0x402080C0 to 0x42217100 to make space for the uncompressed kernel above it
and after that the DTB is found located at 0x430AFA00.

This is using attached device tree so that is why the DTB is right after the compressed kernel in memory.

Uncompressing Linux... done, booting the kernel.
MMU enable: 0x40300000->0x40300000
Kernel RAM: 0x40000000->0xc0000000
Kernel RAM: 0x40100000->0xc0100000
Kernel RAM: 0x40200000->0xc0200000
(...)
Kernel RAM: 0x42500000->0xc2500000
Kernel RAM: 0x42600000->0xc2600000
ATAG/DTB : 0x43000000->0xc3000000
ATAG/DTB : 0x43100000->0xc3100000

First is the 1:1 mapping for the MMU enable code, then all the kernel text segment mappings. Then the DTB is mapped in using the linear kernel map and as you can see that ends up to be at 0xc30AFA00 so we map the 2 MB
at 0x43000000 and 0x43100000.

That is close to the kernel... so indeed:

Clear PMDs from 0x00000000 to 0xb6e00000
Clear PMDs from 0xbf000000 to 0xbf000000
Clear PMDs from 0xbf000000 to 0xc0000000 Memblock[0].base: 0x40200000 size: 0x02c00000, end: 0x42e00000 Clear PMDs from 0xc2e00000 to 0xe0800000 (lowmem) ATAGs/DTB found in lowmem, skip clearing PMD @0xc3000000 ATAGs/DTB found in lowmem, skip clearing PMD @0xc3200000

Ooops.

(The last two messages comes from this patch, the rest is debug prints I added.)

The first memblock is 44 MB and the linear map ends at 0xc2e00000 which will cover the whole uncompressed kernel, but then we come to this code in prepare_page_table():

/*
* Clear out all the kernel space mappings, except for the first
* memory bank, up to the vmalloc region.
*/
for (addr = __phys_to_virt(end); addr < VMALLOC_START; addr += PMD_SIZE)

     pmd_clear(pmd_off_k(addr));

This clears out all mappings from the end of the first memblock to VMALLOC_START. Including the PMD used by the DTB.

Ooops.

Quoted 3 lines

If that memory is not actually available to begin with, this fix papers over the problem, and we should be fixing this in the decompressor instead.

The kernel actually fits in the first memblock, but then it clears the lowmem right below itself and by that point the MMU has figured out that there is another memblock below it that it will happily use for lowmem and just goes ahead and wipes that. The code has no awareness
that there might be a DTB there.

The decompressor seems to have always been blissfully ignorant about what happens with the attached DTB after it just pushed it a bit upwards in memory (if relocating) it just passes the location in r2 in accordance with the boot specification, to me it seems more like something the kernel proper should handle.

I don't think that loading the DTB separately to some high address as advocated by many peope is much better. It can create the same problem if loaded in the wrong place and possibly be placed in other dangerous areas like inside the VMALLOC area where it can get its mappings destroyed at any instance. (We don't check for that either.)

To me it seems like it was always like this and people have just been trial-and-erroring by putting the DTB at address until it works.

The way attached DTB works is that the entire compressed kernel and the attached DTB usually ends up
inside the first memblock as well so the initialization of the kernel lowmem will not wipe its two PMDs.

The problem with that approach is that if your kernel suddenly gets bigger - like when enabling KASan - then this can occur, especially with attached device trees.

I can mitigate the problem for example by just loading the kernel at 0x50000000 instead:

DTB:0x50EA09C0 (0x000051B5) C:0x500080C0-0x50EA5C20->0x52217100-0x530B4C60 DTB:0x530AFA00 (0x00005242)
Uncompressing Linux... done, booting the kernel.
MMU enable: 0x50300000->0x50300000
Kernel RAM: 0x50000000->0xc0000000
Kernel RAM: 0x50100000->0xc0100000
Kernel RAM: 0x50200000->0xc0200000
(...)
Kernel RAM: 0x52500000->0xc2500000
Kernel RAM: 0x52600000->0xc2600000
ATAG/DTB : 0x53000000->0xc3000000
ATAG/DTB : 0x53100000->0xc3100000
(...)
Clear PMDs from 0x00000000 to 0xb6e00000
Clear PMDs from 0xbf000000 to 0xbf000000
Clear PMDs from 0xbf000000 to 0xc0000000
Memblock end is above arm_lowmem_limit (0x60000000) Memblock[0].base: 0x50000000 size: 0x10000000, end: 0x60000000 Clear PMDs from 0xd0000000 to 0xd0800000 (lowmem)

The DTB is at physical 0x530AFA00 which is virtual 0xC30AFA00 and since the first memblock now is bigger, the kernel and the DTB fits inside it and the DTB mapping is between the kernel and the lowmem mappings, so the PMDs will not be cleared.

I think "most" cases work for people because their first memblock is big like this (256 MB) and their kernel is relatively small compared to that so the uncompressed and compressed kernel, and the attached DTB all fit inside it. In my case the first memblock was "just" 44 MB and that was just small enough to trigger this.

So to summarize:

- The kernel decompressor just moves the kernel and the attached DTB upward in memory so it will not be overwritten by the decompressor.

- This will sometimes make part of the compressed kernel and DTB end up above the first memblock.

- This works because there is more memory above
the first memblock, in an adjacent memblock.
(The decompressor has always assumed so much)

- The kernel then puts the lowmem mappings from
the end of the first memblock to VMALLOC_START
and clear the PMDs

- If the DTB has been pushed up to lowmem, the two PMDs over the DTB will be cleared, resulting in a crash.

Maybe I should just put all of this into the commit message so people can see the mess :D

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Hi Linus,

Thanks for the elaborate explanation.

Quoted 11 lines · Linus Walleij
Quoted 4 lines · Ard Biesheuvel

On Thu, 1 Oct 2020 at 17:22, Linus Walleij <[email protected]> wrote:

OK, so if I am understanding this correctly, the root problem is that the kernel unmaps the memory that the attached DTB resides in, right?

Yups, or, well in some places the kernel knows that the DT is there so it sets up two 1MB sections over it, and then it assumes "no-one is ever gonna touch those two section mappings, OK".

OK, so from your explanation, I gathered that:
- the 'appended DTB' is not appended anymore when the core kernel boots, and the problem is caused by the fact that the decompressor blindly chooses a location for it, whereas the firmware makes a more informed decision when it places the DT in memory
- the memory holding the DT may be unmapped inadvertently
- the memory holding the DT may be wiped inadvertently.

...

Quoted 7 lines

The kernel actually fits in the first memblock, but then it clears the lowmem right below itself and by that point the MMU has figured out that there is another memblock below it that it will happily use for lowmem and just goes ahead and wipes that. The code has no awareness
that there might be a DTB there.

Where in the code does this happen? It seems to me that at this point, the DT memory should have been memblock_reserve()d, and the code in question should disregard it from wiping.

Quoted 6 lines

The decompressor seems to have always been blissfully ignorant about what happens with the attached DTB after it just pushed it a bit upwards in memory (if relocating) it just passes the location in r2 in accordance with the boot specification, to me it seems more like something the kernel proper should handle.

Quoted 8 lines

I don't think that loading the DTB separately to some high address as advocated by many peope is much better. It can create the same problem if loaded in the wrong place and possibly be placed in other dangerous areas like inside the VMALLOC area where it can get its mappings destroyed at any instance. (We don't check for that either.)

I think putting the mapping of the DT outside of the linear region is reasonable, tbh, and this is what we do on arm64. That way, the firmware does not have to care at all about the MM configuration of the kernel, and it could simply put it in high memory as well.

One option would be to create a virtual mapping for the DT at the base of the modules region. This takes up 1 MB in the typical (non-LPAE) case, and 4 MB in the worst case, making it more likely that you will run out of module space, but we already have infrastructure to deal with that.

...

Quoted 17 lines

So to summarize:

- The kernel decompressor just moves the kernel and the attached DTB upward in memory so it will not be overwritten by the decompressor.

- This will sometimes make part of the compressed kernel and DTB end up above the first memblock.

- This works because there is more memory above
the first memblock, in an adjacent memblock.
(The decompressor has always assumed so much)

- The kernel then puts the lowmem mappings from
the end of the first memblock to VMALLOC_START
and clear the PMDs

Quoted 6 lines

- If the DTB has been pushed up to lowmem, the two PMDs over the DTB will be cleared, resulting in a crash.

Maybe I should just put all of this into the commit message so people can see the mess :D

I'd prefer to fix this in a more structural way, tbh.

Let me see if I can code up a PoC

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#7 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 87 lines · Ard Biesheuvel

Hi Linus,

Thanks for the elaborate explanation.

Quoted 11 lines · Linus Walleij
Quoted 4 lines · Ard Biesheuvel

On Thu, 1 Oct 2020 at 17:22, Linus Walleij <[email protected]> wrote:

OK, so if I am understanding this correctly, the root problem is that the kernel unmaps the memory that the attached DTB resides in, right?

Yups, or, well in some places the kernel knows that the DT is there so it sets up two 1MB sections over it, and then it assumes "no-one is ever gonna touch those two section mappings, OK".

OK, so from your explanation, I gathered that:
- the 'appended DTB' is not appended anymore when the core kernel boots, and the problem is caused by the fact that the decompressor blindly chooses a location for it, whereas the firmware makes a more informed decision when it places the DT in memory
- the memory holding the DT may be unmapped inadvertently
- the memory holding the DT may be wiped inadvertently.

...

Quoted 7 lines

The kernel actually fits in the first memblock, but then it clears the lowmem right below itself and by that point the MMU has figured out that there is another memblock below it that it will happily use for lowmem and just goes ahead and wipes that. The code has no awareness
that there might be a DTB there.

Where in the code does this happen? It seems to me that at this point, the DT memory should have been memblock_reserve()d, and the code in question should disregard it from wiping.

Quoted 6 lines

The decompressor seems to have always been blissfully ignorant about what happens with the attached DTB after it just pushed it a bit upwards in memory (if relocating) it just passes the location in r2 in accordance with the boot specification, to me it seems more like something the kernel proper should handle.

Quoted 8 lines

I don't think that loading the DTB separately to some high address as advocated by many peope is much better. It can create the same problem if loaded in the wrong place and possibly be placed in other dangerous areas like inside the VMALLOC area where it can get its mappings destroyed at any instance. (We don't check for that either.)

I think putting the mapping of the DT outside of the linear region is reasonable, tbh, and this is what we do on arm64. That way, the firmware does not have to care at all about the MM configuration of the kernel, and it could simply put it in high memory as well.

One option would be to create a virtual mapping for the DT at the base of the modules region. This takes up 1 MB in the typical (non-LPAE) case, and 4 MB in the worst case, making it more likely that you will run out of module space, but we already have infrastructure to deal with that.

...

Quoted 20 lines

So to summarize:

- The kernel decompressor just moves the kernel and the attached DTB upward in memory so it will not be overwritten by the decompressor.

- This will sometimes make part of the compressed kernel and DTB end up above the first memblock.

- This works because there is more memory above
the first memblock, in an adjacent memblock.
(The decompressor has always assumed so much)

- The kernel then puts the lowmem mappings from
the end of the first memblock to VMALLOC_START
and clear the PMDs

- If the DTB has been pushed up to lowmem, the two PMDs over the DTB will be cleared, resulting in a crash.

Quoted 7 lines
Quoted 3 lines

Maybe I should just put all of this into the commit message so people can see the mess :D

I'd prefer to fix this in a more structural way, tbh.

Let me see if I can code up a PoC

I pushed a branch to

https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=arm-dt-mapping

that moves the DT mapping to a read-only region at the top of the kernel VA space: there happened to be a 4 MB hole there (between VMALLOC_END and FIXADDR_START) that we can use, even if the purpose of that hole was as a guard region, as a read-only mapping still catches stray writes.

What I don't get is why the DT *contents* get clobbered - arm_memblock_init() memblock_reserve's the DT contents, and wiping reserved memblocks is something we really shouldn't be doing.

Signature · 6 lines
Ard.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#8 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 6 lines · Ard Biesheuvel
Quoted 1 line · Ard Biesheuvel

Let me see if I can code up a PoC

I pushed a branch to

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=arm-dt-mapping

that moves the DT mapping to a read-only region at the top of the kernel VA space: there happened to be a 4 MB hole there (between VMALLOC_END and FIXADDR_START) that we can use, even if the purpose of that hole was as a guard region, as a read-only mapping still catches stray writes.

I will test it when I'm back at the hardware.
I tried to do this thing as well but couldn't figure out a good place to map it, putting it between VMALLOC_END
and FIXADDR_START seems like a good idea!

But this is going to be a problem:

+ map.type = MT_ROM;

Because the current code calls unflatten_device_tree() which will unflatten the device tree right where it is. So then the memory needs to be RW.

This is why in my patch I change that to
unflatten_and_copy_device_tree() so I can treat
it as a ROM, unflatten and copy that and then
ditch the memory where the device tree is so the
kernel does not need to work around that.

(unflatten_and_copy_device_tree()
will not delete the memblock around the device tree, so that would need to be fixed in my patch.)

With your patch, if we call unflatten_and_copy_device_tree() we can use MT_ROM but then we would want to get rid of the remapped memory and memblock
for the device tree after copying and unflattening it, but since there is no delete_mapping() counterpart to create_mapping() I guess that is going to be hard?

Quoted 3 lines

What I don't get is why the DT *contents* get clobbered - arm_memblock_init() memblock_reserve's the DT contents, and wiping reserved memblocks is something we really shouldn't be doing.

The contents are fine on my system, just the two section mappings get wiped.

I hope my previous mail explains that, the code in prepare_page_table() simply just wipes the lowmem PMDs without any regard for any reserved memblocks being in that range.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#9 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 7 lines · Linus Walleij

The contents are fine on my system, just the two section mappings get wiped.

I hope my previous mail explains that, the code in prepare_page_table() simply just wipes the lowmem PMDs without any regard for any reserved memblocks being in that range.

Would it be a viable approach to make a patch to make prepare_page_table() respect any reserved memblocks?

That would fix this bug.

Then I could make a separate patch to copy the device tree and delete the memblock used by it as a separate optimization. (Not that I know if memblock actually allows for disposal of memblocks...)

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#10 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

In reply to Linus Walleij
Quoted 21 lines · Linus Walleij
Quoted 6 lines · Ard Biesheuvel
Quoted 1 line · Ard Biesheuvel

Let me see if I can code up a PoC

I pushed a branch to

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=arm-dt-mapping

that moves the DT mapping to a read-only region at the top of the kernel VA space: there happened to be a 4 MB hole there (between VMALLOC_END and FIXADDR_START) that we can use, even if the purpose of that hole was as a guard region, as a read-only mapping still catches stray writes.

I will test it when I'm back at the hardware.
I tried to do this thing as well but couldn't figure out a good place to map it, putting it between VMALLOC_END
and FIXADDR_START seems like a good idea!

Quoted 8 lines

But this is going to be a problem:

+ map.type = MT_ROM;

Because the current code calls unflatten_device_tree() which will unflatten the device tree right where it is. So then the memory needs to be RW.

I don't think this is the case. Note that arm64 has been using r/o mappings for the device tree for a long time, and it calls unflatten_device_tree() without any problems.

Quoted 19 lines

This is why in my patch I change that to
unflatten_and_copy_device_tree() so I can treat
it as a ROM, unflatten and copy that and then
ditch the memory where the device tree is so the
kernel does not need to work around that.

(unflatten_and_copy_device_tree()
will not delete the memblock around the device tree, so that would need to be fixed in my patch.)

With your patch, if we call unflatten_and_copy_device_tree() we can use MT_ROM but then we would want to get rid of the remapped memory and memblock
for the device tree after copying and unflattening it, but since there is no delete_mapping() counterpart to create_mapping() I guess that is going to be hard?

Quoted 7 lines
Quoted 3 lines

What I don't get is why the DT *contents* get clobbered - arm_memblock_init() memblock_reserve's the DT contents, and wiping reserved memblocks is something we really shouldn't be doing.

The contents are fine on my system, just the two section mappings get wiped.

Ah ok.

Quoted 5 lines

I hope my previous mail explains that, the code in prepare_page_table() simply just wipes the lowmem PMDs without any regard for any reserved memblocks being in that range.

In that case, mapping the DT outside of the linear region should solve this entirely.

Note that this code boots fine for me. The only question I have is whether the ATAGS based systems require the ability to make changes to the data structure at runtime.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#11 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 27 lines · Ard Biesheuvel
Quoted 25 lines · Linus Walleij
Quoted 6 lines · Ard Biesheuvel
Quoted 1 line · Ard Biesheuvel

Let me see if I can code up a PoC

I pushed a branch to

Quoted 7 lines

https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=arm-dt-mapping

that moves the DT mapping to a read-only region at the top of the kernel VA space: there happened to be a 4 MB hole there (between VMALLOC_END and FIXADDR_START) that we can use, even if the purpose of that hole was as a guard region, as a read-only mapping still catches stray writes.

I will test it when I'm back at the hardware.
I tried to do this thing as well but couldn't figure out a good place to map it, putting it between VMALLOC_END
and FIXADDR_START seems like a good idea!

But this is going to be a problem:

+ map.type = MT_ROM;

Quoted 9 lines
Quoted 4 lines

Because the current code calls unflatten_device_tree() which will unflatten the device tree right where it is. So then the memory needs to be RW.

I don't think this is the case. Note that arm64 has been using r/o mappings for the device tree for a long time, and it calls unflatten_device_tree() without any problems.

I think the problem here may be that early_init_fdt_reserve_self() uses the wrong translation for obtaining the PA of the device tree blob. This is also the reason we no longer use it on arm64 IIRC.

When I add the following on top, everything works as expected with MT_ROM, including the ability to dump the firmware provided DT from /sys/firmware/fdt

arch/arm/kernel/setup.c +4 -1
index 40fe688a7b76..1dbc8a46cf5f 100644
@@ -18,6 +18,7 @@
 #include <linux/of_platform.h>
 #include <linux/init.h>
 #include <linux/kexec.h>
+#include <linux/libfdt.h>
 #include <linux/of_fdt.h>
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
@@ -1082,8 +1083,11 @@ void __init setup_arch(char **cmdline_p)
                atags_vaddr = FDT_VIRT_ADDR(__atags_pointer);
 
        setup_processor();
-       if (atags_vaddr)
+       if (atags_vaddr) {
                mdesc = setup_machine_fdt(atags_vaddr);
+               if (mdesc)
+                       memblock_reserve(__atags_pointer,

fdt_totalsize(atags_vaddr));
+ }

        if (!mdesc)
                mdesc = setup_machine_tags(atags_vaddr, __machine_arch_type);
        if (!mdesc) {
arch/arm/mm/init.c +0 -0
index 000c1b48e973..652a87bd065c 100644
@@ -223,7 +223,6 @@ void __init arm_memblock_init(const struct

machine_desc *mdesc)

        if (mdesc->reserve)
                mdesc->reserve();
-       early_init_fdt_reserve_self();
        early_init_fdt_scan_reserved_mem();

        /* reserve memory for DMA contiguous allocations */

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#12 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 7 lines · Ard Biesheuvel

I think the problem here may be that early_init_fdt_reserve_self() uses the wrong translation for obtaining the PA of the device tree blob. This is also the reason we no longer use it on arm64 IIRC.

When I add the following on top, everything works as expected with MT_ROM, including the ability to dump the firmware provided DT from /sys/firmware/fdt

(...)

Quoted 6 lines
arch/arm/kernel/setup.c +3 -1
-       if (atags_vaddr)
+       if (atags_vaddr) {
                mdesc = setup_machine_fdt(atags_vaddr);
+               if (mdesc)
+                       memblock_reserve(__atags_pointer,

fdt_totalsize(atags_vaddr));

I tested with this too and it works fine, and makes perfect sense, it should protect the physical memory used by the DT even if that happens to be in lowmem.

Please fold this into the patch! (Reviewed/Tested-by).

If we go for copying and unflattening the devicetree instead of just unflattning it the memblock should be removed, which is nice and clean to my OCD because then we don't have this random "hole" in the memory, but I suspect then we should also drop the virtual mapping and that seems like it could be hard.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#13 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 18 lines · Linus Walleij
Quoted 7 lines · Ard Biesheuvel

I think the problem here may be that early_init_fdt_reserve_self() uses the wrong translation for obtaining the PA of the device tree blob. This is also the reason we no longer use it on arm64 IIRC.

When I add the following on top, everything works as expected with MT_ROM, including the ability to dump the firmware provided DT from /sys/firmware/fdt

(...)

Quoted 6 lines
arch/arm/kernel/setup.c +3 -1
-       if (atags_vaddr)
+       if (atags_vaddr) {
                mdesc = setup_machine_fdt(atags_vaddr);
+               if (mdesc)
+                       memblock_reserve(__atags_pointer,

fdt_totalsize(atags_vaddr));

Quoted 6 lines

I tested with this too and it works fine, and makes perfect sense, it should protect the physical memory used by the DT even if that happens to be in lowmem.

Please fold this into the patch! (Reviewed/Tested-by).

OK, thanks. The patches will look slightly different, though, so you may have to take another look, and give these in reply.

Quoted 7 lines

If we go for copying and unflattening the devicetree instead of just unflattning it the memblock should be removed, which is nice and clean to my OCD because then we don't have this random "hole" in the memory, but I suspect then we should also drop the virtual mapping and that seems like it could be hard.

We don't actually unmap the DT from the linear region, we just alias it elsewhere in the VA space, so that we don't have to reason about whether the DT is in the first memblock or below/above/whatever.

So the DT is just one of the many memblock_reservations, and this actually doesn't change - the DT is still there, it is reserved, we just access it via another route.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#14 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 7 lines · Ard Biesheuvel

We don't actually unmap the DT from the linear region, we just alias it elsewhere in the VA space, so that we don't have to reason about whether the DT is in the first memblock or below/above/whatever.

So the DT is just one of the many memblock_reservations, and this actually doesn't change - the DT is still there, it is reserved, we just access it via another route.

Yeah I see.

I had a conversation with Rob Herring where he said it would be nice if ARM used unflatten_and_copy_device_tree() like most other architectures, but I don't know what it would bring us? (Paging Rob.)

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#15 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

In reply to Ard Biesheuvel
Quoted 5 lines · Ard Biesheuvel
Quoted 1 line

Let me see if I can code up a PoC

I pushed a branch to

https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=arm-dt-mapping

I tested these two on the APQ8060 today and it works like a charm :D Tested-by/Reviewed-by: Linus Walleij <[email protected]>

I think we can just put these into Russell's patch tracker already, they just make everything so much cleaner.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#16 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

Quoted 7 lines · Linus Walleij
Quoted 4 lines · Ard Biesheuvel
Quoted 1 line

Let me see if I can code up a PoC

I pushed a branch to

Quoted 8 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=arm-dt-mapping

I tested these two on the APQ8060 today and it works like a charm :D Tested-by/Reviewed-by: Linus Walleij <[email protected]>

I think we can just put these into Russell's patch tracker already, they just make everything so much cleaner.

Thanks.

I will send them to the list today.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#17 lore raw

Re: [PATCH 1/6 v14] ARM: Handle a device tree in lowmem

In reply to Ard Biesheuvel

Hi Ard,

thanks for helping out, finally we're getting somewhere with this!

Quoted 9 lines · Ard Biesheuvel

On Sun, 4 Oct 2020 at 22:50, Linus Walleij <[email protected]> wrote:

OK, so from your explanation, I gathered that:
- the 'appended DTB' is not appended anymore when the core kernel boots, and the problem is caused by the fact that the decompressor blindly chooses a location for it, whereas the firmware makes a more informed decision when it places the DT in memory
- the memory holding the DT may be unmapped inadvertently
- the memory holding the DT may be wiped inadvertently.

Correct.

Quoted 8 lines
Quoted 6 lines

The kernel actually fits in the first memblock, but then it clears the lowmem right below itself and by that point the MMU has figured out that there is another memblock below it that it will happily use for lowmem and just goes ahead and wipes that. The code has no awareness
that there might be a DTB there.

Where in the code does this happen?

This happens in mm/mmu.c, prepare_page_table(), line1283:

/*
* Clear out all the kernel space mappings, except for the first
* memory bank, up to the vmalloc region.
*/
for (addr = __phys_to_virt(end); addr < VMALLOC_START; addr += PMD_SIZE)

        pmd_clear(pmd_off_k(addr));

Here end is augmented roofed at arm_lowmem_limit which seems common but that incidentally does not happen on my platform because of the small size of the first memblock.

Quoted 3 lines

It seems to me that at this point,
the DT memory should have been memblock_reserve()d, and the code in question should disregard it from wiping.

This code seems pretty ignorant about anything like that, This happens as the first call in paging_init() after arm_memblock_init() but before we
have called memblock_set_current_limit().

We need to keep these mappings alive until we have called unflatten_and_copy_device_tree() which transfers the device tree into memory the kernel controls. Then we should free/unmap that memory so that the kernel can use it. What happens to the memory where the DTB is stored right now is kind of "undefined" which doesn't feel good to me at all.

Quoted 2 lines

I think putting the mapping of the DT outside of the linear region is reasonable, tbh, and this is what we do on arm64.

Yes that is much better. Arm64 also relies on the bootloader to do the decompression and some other simplifications I really like.

Quoted 5 lines

One option would be to create a virtual mapping for the DT at the base of the modules region. This takes up 1 MB in the typical (non-LPAE) case, and 4 MB in the worst case, making it more likely that you will run out of module space, but we already have infrastructure to deal with that.

2MB (two section mappings) is what head.S always maps and that would be 4MB on LPAE indeed.

I tried to use the earlymaps for this but I couldn't get it to work, besides it only supports some 16 pages so not good approach since the early boot maps a whopping 2MB.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#18 lore raw

PATCH v14 2/6 ARM: Disable KASan instrumentation for some code

In reply to Linus Walleij

From: Andrey Ryabinin <[email protected]>

Disable instrumentation for arch/arm/boot/compressed/* since that code is executed before the kernel has even set up its mappings and definately out of scope for KASan.

Disable instrumentation of arch/arm/vdso/* because that code is not linked with the kernel image, so the KASan management code would fail to link.

Disable instrumentation of arch/arm/mm/physaddr.c. See commit ec6d06efb0ba ("arm64: Add support for CONFIG_DEBUG_VIRTUAL") for more details.

Disable kasan check in the function unwind_pop_register because it does not matter that kasan checks failed when unwind_pop_register() reads the stack memory of a task.

---
ChangeLog v13->v14:
- Resend with the other patches
ChangeLog v12->v13:
- Rebase on kernel v5.9-rc1
ChangeLog v11->v12:
- Resend with the other changes.
ChangeLog v10->v11:
- Resend with the other changes.
ChangeLog v9->v10:
- Rebase on v5.8-rc1
ChangeLog v8->v9:
- Collect Ard's tags.
ChangeLog v7->v8:
- Do not sanitize arch/arm/mm/mmu.c.
Apart from being intuitively correct, it turns out that KASan will insert a __asan_load4() into the set_pte_at() function in mmu.c and this is something that KASan calls in the early initialization, to set up the shadow memory. Naturally, __asan_load4() cannot be called before the shadow memory is set up so we need to exclude mmu.c from sanitization.
ChangeLog v6->v7:
- Removed the KVM instrumentaton disablement since KVM on ARM32 is gone.

---
 arch/arm/boot/compressed/Makefile | 1 +
 arch/arm/kernel/unwind.c          | 6 +++++-
 arch/arm/mm/Makefile              | 2 ++
 arch/arm/vdso/Makefile            | 2 ++
 4 files changed, 10 insertions(+), 1 deletion(-)
arch/arm/boot/compressed/Makefile +1 -0
index b1147b7f2c8d..362e17e37398 100644
@@ -24,6 +24,7 @@ OBJS		+= hyp-stub.o
 endif
 
 GCOV_PROFILE		:= n
+KASAN_SANITIZE		:= n
 
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
 KCOV_INSTRUMENT		:= n
arch/arm/kernel/unwind.c +5 -1
index d2bd0df2318d..f35eb584a18a 100644
@@ -236,7 +236,11 @@ static int unwind_pop_register(struct unwind_ctrl_block *ctrl,
 		if (*vsp >= (unsigned long *)ctrl->sp_high)
 			return -URC_FAILURE;
 
-	ctrl->vrs[reg] = *(*vsp)++;
+	/* Use READ_ONCE_NOCHECK here to avoid this memory access
+	 * from being tracked by KASAN.
+	 */
+	ctrl->vrs[reg] = READ_ONCE_NOCHECK(*(*vsp));
+	(*vsp)++;
 	return URC_OK;
 }
 
arch/arm/mm/Makefile +2 -0
index 7cb1699fbfc4..99699c32d8a5 100644
@@ -7,6 +7,7 @@ obj-y				:= extable.o fault.o init.o iomap.o
 obj-y				+= dma-mapping$(MMUEXT).o
 obj-$(CONFIG_MMU)		+= fault-armv.o flush.o idmap.o ioremap.o \
 				   mmap.o pgd.o mmu.o pageattr.o
+KASAN_SANITIZE_mmu.o		:= n
 
 ifneq ($(CONFIG_MMU),y)
 obj-y				+= nommu.o
@@ -16,6 +17,7 @@ endif
 obj-$(CONFIG_ARM_PTDUMP_CORE)	+= dump.o
 obj-$(CONFIG_ARM_PTDUMP_DEBUGFS)	+= ptdump_debugfs.o
 obj-$(CONFIG_MODULES)		+= proc-syms.o
+KASAN_SANITIZE_physaddr.o	:= n
 obj-$(CONFIG_DEBUG_VIRTUAL)	+= physaddr.o
 
 obj-$(CONFIG_ALIGNMENT_TRAP)	+= alignment.o
arch/arm/vdso/Makefile +2 -0
index a54f70731d9f..171c3dcb5242 100644
@@ -42,6 +42,8 @@ GCOV_PROFILE := n
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
 KCOV_INSTRUMENT := n
 
+KASAN_SANITIZE := n
+
 # Force dependency
 $(obj)/vdso.o : $(obj)/vdso.so
 
Signature · 7 lines
2.26.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#19 lore raw

PATCH v14 3/6 ARM: Replace string mem* functions for KASan

In reply to Linus Walleij

From: Andrey Ryabinin <[email protected]>

Functions like memset()/memmove()/memcpy() do a lot of memory accesses.

If a bad pointer is passed to one of these functions it is important to catch this. Compiler instrumentation cannot do this since these functions are written in assembly.

KASan replaces these memory functions with instrumented variants.

The original functions are declared as weak symbols so that the strong definitions in mm/kasan/kasan.c can replace them.

The original functions have aliases with a '__' prefix in their name, so we can call the non-instrumented variant if needed.

We must use __memcpy()/__memset() in place of memcpy()/memset() when we copy .data to RAM and when we clear .bss, because kasan_early_init cannot be called before the initialization of .data and .bss.

For the kernel compression and EFI libstub's custom string libraries we need a special quirk: even if these are built without KASan enabled, they rely on the global headers for their custom string libraries, which means that e.g. memcpy() will be defined to __memcpy() and we get link failures. Since these implementations are written i C rather than assembly we use e.g. __alias(memcpy) to redirected any users back to the local implementation.

---
ChangeLog v13->v14:
- Resend with the other patches
ChangeLog v12->v13:
- Rebase on kernel v5.9-rc1
ChangeLog v11->v12:
- Resend with the other changes.
ChangeLog v10->v11:
- Resend with the other changes.
ChangeLog v9->v10:
- Rebase on v5.8-rc1
ChangeLog v8->v9:
- Collect Ard's tags.
ChangeLog v7->v8:
- Use the less invasive version of handling the global redefines of the string functions in the decompressor: __alias() the functions locally in the library.
- Put in some more comments so readers of the code knows what is going on.
ChangeLog v6->v7:
- Move the hacks around __SANITIZE_ADDRESS__ into this file
- Edit the commit message
- Rebase on the other v2 patches

---
 arch/arm/boot/compressed/string.c | 19 +++++++++++++++++++
 arch/arm/include/asm/string.h     | 21 +++++++++++++++++++++
 arch/arm/kernel/head-common.S     |  4 ++--
 arch/arm/lib/memcpy.S             |  3 +++
 arch/arm/lib/memmove.S            |  5 ++++-
 arch/arm/lib/memset.S             |  3 +++
 6 files changed, 52 insertions(+), 3 deletions(-)
arch/arm/boot/compressed/string.c +19 -0
index ade5079bebbf..8c0fa276d994 100644
@@ -7,6 +7,25 @@
 
 #include <linux/string.h>
 
+/*
+ * The decompressor is built without KASan but uses the same redirects as the
+ * rest of the kernel when CONFIG_KASAN is enabled, defining e.g. memcpy()
+ * to __memcpy() but since we are not linking with the main kernel string
+ * library in the decompressor, that will lead to link failures.
+ *
+ * Undefine KASan's versions, define the wrapped functions and alias them to
+ * the right names so that when e.g. __memcpy() appear in the code, it will
+ * still be linked to this local version of memcpy().
+ */
+#ifdef CONFIG_KASAN
+#undef memcpy
+#undef memmove
+#undef memset
+void *__memcpy(void *__dest, __const void *__src, size_t __n) __alias(memcpy);
+void *__memmove(void *__dest, __const void *__src, size_t count) __alias(memmove);
+void *__memset(void *s, int c, size_t count) __alias(memset);
+#endif
+
 void *memcpy(void *__dest, __const void *__src, size_t __n)
 {
 	int i = 0;
arch/arm/include/asm/string.h +21 -0
index 111a1d8a41dd..947f93037d87 100644
@@ -5,6 +5,9 @@
 /*
  * We don't do inline string functions, since the
  * optimised inline asm versions are not small.
+ *
+ * The __underscore versions of some functions are for KASan to be able
+ * to replace them with instrumented versions.
  */
 
 #define __HAVE_ARCH_STRRCHR
@@ -15,15 +18,18 @@ extern char * strchr(const char * s, int c);
 
 #define __HAVE_ARCH_MEMCPY
 extern void * memcpy(void *, const void *, __kernel_size_t);
+extern void *__memcpy(void *dest, const void *src, __kernel_size_t n);
 
 #define __HAVE_ARCH_MEMMOVE
 extern void * memmove(void *, const void *, __kernel_size_t);
+extern void *__memmove(void *dest, const void *src, __kernel_size_t n);
 
 #define __HAVE_ARCH_MEMCHR
 extern void * memchr(const void *, int, __kernel_size_t);
 
 #define __HAVE_ARCH_MEMSET
 extern void * memset(void *, int, __kernel_size_t);
+extern void *__memset(void *s, int c, __kernel_size_t n);
 
 #define __HAVE_ARCH_MEMSET32
 extern void *__memset32(uint32_t *, uint32_t v, __kernel_size_t);
@@ -39,4 +45,19 @@ static inline void *memset64(uint64_t *p, uint64_t v, __kernel_size_t n)
 	return __memset64(p, v, n * 8, v >> 32);
 }
 
+/*
+ * For files that are not instrumented (e.g. mm/slub.c) we
+ * must use non-instrumented versions of the mem*
+ * functions named __memcpy() etc. All such kernel code has
+ * been tagged with KASAN_SANITIZE_file.o = n, which means
+ * that the address sanitization argument isn't passed to the
+ * compiler, and __SANITIZE_ADDRESS__ is not set. As a result
+ * these defines kick in.
+ */
+#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
+#define memcpy(dst, src, len) __memcpy(dst, src, len)
+#define memmove(dst, src, len) __memmove(dst, src, len)
+#define memset(s, c, n) __memset(s, c, n)
+#endif
+
 #endif
arch/arm/kernel/head-common.S +2 -2
index 4a3982812a40..6840c7c60a85 100644
@@ -95,7 +95,7 @@ __mmap_switched:
  THUMB(	ldmia	r4!, {r0, r1, r2, r3} )
  THUMB(	mov	sp, r3 )
 	sub	r2, r2, r1
-	bl	memcpy				@ copy .data to RAM
+	bl	__memcpy			@ copy .data to RAM
 #endif
 
    ARM(	ldmia	r4!, {r0, r1, sp} )
@@ -103,7 +103,7 @@ __mmap_switched:
  THUMB(	mov	sp, r3 )
 	sub	r2, r1, r0
 	mov	r1, #0
-	bl	memset				@ clear .bss
+	bl	__memset			@ clear .bss
 
 	ldmia	r4, {r0, r1, r2, r3}
 	str	r9, [r0]			@ Save processor ID
arch/arm/lib/memcpy.S +3 -0
index 09a333153dc6..ad4625d16e11 100644
@@ -58,6 +58,8 @@
 
 /* Prototype: void *memcpy(void *dest, const void *src, size_t n); */
 
+.weak memcpy
+ENTRY(__memcpy)
 ENTRY(mmiocpy)
 ENTRY(memcpy)
 
@@ -65,3 +67,4 @@ ENTRY(memcpy)
 
 ENDPROC(memcpy)
 ENDPROC(mmiocpy)
+ENDPROC(__memcpy)
arch/arm/lib/memmove.S +4 -1
index b50e5770fb44..fd123ea5a5a4 100644
@@ -24,12 +24,14 @@
  * occurring in the opposite direction.
  */
 
+.weak memmove
+ENTRY(__memmove)
 ENTRY(memmove)
 	UNWIND(	.fnstart			)
 
 		subs	ip, r0, r1
 		cmphi	r2, ip
-		bls	memcpy
+		bls	__memcpy
 
 		stmfd	sp!, {r0, r4, lr}
 	UNWIND(	.fnend				)
@@ -222,3 +224,4 @@ ENTRY(memmove)
 18:		backward_copy_shift	push=24	pull=8
 
 ENDPROC(memmove)
+ENDPROC(__memmove)
arch/arm/lib/memset.S +3 -0
index 6ca4535c47fb..0e7ff0423f50 100644
@@ -13,6 +13,8 @@
 	.text
 	.align	5
 
+.weak memset
+ENTRY(__memset)
 ENTRY(mmioset)
 ENTRY(memset)
 UNWIND( .fnstart         )
@@ -132,6 +134,7 @@ UNWIND( .fnstart            )
 UNWIND( .fnend   )
 ENDPROC(memset)
 ENDPROC(mmioset)
+ENDPROC(__memset)
 
 ENTRY(__memset32)
 UNWIND( .fnstart         )
Signature · 7 lines
2.26.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#20 lore raw

PATCH v14 4/6 ARM: Define the virtual space of KASan's shadow region

In reply to Linus Walleij

From: Abbott Liu <[email protected]>

Define KASAN_SHADOW_OFFSET,KASAN_SHADOW_START and KASAN_SHADOW_END for the Arm kernel address sanitizer. We are "stealing" lowmem (the 4GB addressable by a 32bit architecture) out of the virtual address space to use as shadow memory for KASan as follows:

 +----+ 0xffffffff
 |    |\
 |    | |-> Static kernel image (vmlinux) BSS and page table
 |    |/
 +----+ PAGE_OFFSET
 |    |\
 |    | |->  Loadable kernel modules virtual address space area
 |    |/
 +----+ MODULES_VADDR = KASAN_SHADOW_END
 |    |\
 |    | |-> The shadow area of kernel virtual address.
 |    |/
 +----+->  TASK_SIZE (start of kernel space) = KASAN_SHADOW_START the
 |    |\   shadow address of MODULES_VADDR
 |    | |
 |    | |
 |    | |-> The user space area in lowmem. The kernel address
 |    | |   sanitizer do not use this space, nor does it map it.
 |    | |
 |    | |
 |    | |
 |    | |
 |    |/

------ 0

0 .. TASK_SIZE is the memory that can be used by shared userspace/kernelspace. It us used for userspace processes and for passing parameters and memory buffers in system calls etc. We do not need to shadow this area.

KASAN_SHADOW_START:
This value begins with the MODULE_VADDR's shadow address. It is the start of kernel virtual space. Since we have modules to load, we need to cover also that area with shadow memory so we can find memory bugs in modules.

KASAN_SHADOW_END
This value is the 0x100000000's shadow address: the mapping that would be after the end of the kernel memory at 0xffffffff. It is the end of kernel address sanitizer shadow area. It is also the start of the module area.

KASAN_SHADOW_OFFSET:
This value is used to map an address to the corresponding shadow address by the following formula:

   shadow_addr = (address >> 3) + KASAN_SHADOW_OFFSET;

As you would expect, >> 3 is equal to dividing by 8, meaning each byte in the shadow memory covers 8 bytes of kernel memory, so one bit shadow memory per byte of kernel memory is used.

The KASAN_SHADOW_OFFSET is provided in a Kconfig option depending on the VMSPLIT layout of the system: the kernel and userspace can split up lowmem in different ways according to needs, so we calculate the shadow offset depending on this.

When kasan is enabled, the definition of TASK_SIZE is not an 8-bit rotated constant, so we need to modify the TASK_SIZE access code in the *.s file.

The kernel and modules may use different amounts of memory, according to the VMSPLIT configuration, which in turn determines the PAGE_OFFSET.

We use the following KASAN_SHADOW_OFFSETs depending on how the virtual memory is split up:

- 0x1f000000 if we have 1G userspace / 3G kernelspace split:
- The kernel address space is 3G (0xc0000000)
- PAGE_OFFSET is then set to 0x40000000 so the kernel static

    image (vmlinux) uses addresses 0x40000000 .. 0xffffffff
  - On top of that we have the MODULES_VADDR which under
    the worst case (using ARM instructions) is
    PAGE_OFFSET - 16M (0x01000000) = 0x3f000000
    so the modules use addresses 0x3f000000 .. 0x3fffffff
  - So the addresses 0x3f000000 .. 0xffffffff need to be
    covered with shadow memory. That is 0xc1000000 bytes
    of memory.
  - 1/8 of that is needed for its shadow memory, so
    0x18200000 bytes of shadow memory is needed. We
    "steal" that from the remaining lowmem.
  - The KASAN_SHADOW_START becomes 0x26e00000, to
    KASAN_SHADOW_END at 0x3effffff.
  - Now we can calculate the KASAN_SHADOW_OFFSET for any
    kernel address as 0x3f000000 needs to map to the first
    byte of shadow memory and 0xffffffff needs to map to
    the last byte of shadow memory. Since:
    SHADOW_ADDR = (address >> 3) + KASAN_SHADOW_OFFSET
    0x26e00000 = (0x3f000000 >> 3) + KASAN_SHADOW_OFFSET
    KASAN_SHADOW_OFFSET = 0x26e00000 - (0x3f000000 >> 3)
    KASAN_SHADOW_OFFSET = 0x26e00000 - 0x07e00000
    KASAN_SHADOW_OFFSET = 0x1f000000

- 0x5f000000 if we have 2G userspace / 2G kernelspace split:
- The kernel space is 2G (0x80000000)
- PAGE_OFFSET is set to 0x80000000 so the kernel static

    image uses 0x80000000 .. 0xffffffff.
  - On top of that we have the MODULES_VADDR which under
    the worst case (using ARM instructions) is
    PAGE_OFFSET - 16M (0x01000000) = 0x7f000000
    so the modules use addresses 0x7f000000 .. 0x7fffffff
  - So the addresses 0x7f000000 .. 0xffffffff need to be
    covered with shadow memory. That is 0x81000000 bytes
    of memory.
  - 1/8 of that is needed for its shadow memory, so
    0x10200000 bytes of shadow memory is needed. We
    "steal" that from the remaining lowmem.
  - The KASAN_SHADOW_START becomes 0x6ee00000, to
    KASAN_SHADOW_END at 0x7effffff.
  - Now we can calculate the KASAN_SHADOW_OFFSET for any
    kernel address as 0x7f000000 needs to map to the first
    byte of shadow memory and 0xffffffff needs to map to
    the last byte of shadow memory. Since:
    SHADOW_ADDR = (address >> 3) + KASAN_SHADOW_OFFSET
    0x6ee00000 = (0x7f000000 >> 3) + KASAN_SHADOW_OFFSET
    KASAN_SHADOW_OFFSET = 0x6ee00000 - (0x7f000000 >> 3)
    KASAN_SHADOW_OFFSET = 0x6ee00000 - 0x0fe00000
    KASAN_SHADOW_OFFSET = 0x5f000000

- 0x9f000000 if we have 3G userspace / 1G kernelspace split, and this is the default split for ARM:
- The kernel address space is 1GB (0x40000000)
- PAGE_OFFSET is set to 0xc0000000 so the kernel static

    image uses 0xc0000000 .. 0xffffffff.
  - On top of that we have the MODULES_VADDR which under
    the worst case (using ARM instructions) is
    PAGE_OFFSET - 16M (0x01000000) = 0xbf000000
    so the modules use addresses 0xbf000000 .. 0xbfffffff
  - So the addresses 0xbf000000 .. 0xffffffff need to be
    covered with shadow memory. That is 0x41000000 bytes
    of memory.
  - 1/8 of that is needed for its shadow memory, so
    0x08200000 bytes of shadow memory is needed. We
    "steal" that from the remaining lowmem.
  - The KASAN_SHADOW_START becomes 0xb6e00000, to
    KASAN_SHADOW_END at 0xbfffffff.
  - Now we can calculate the KASAN_SHADOW_OFFSET for any
    kernel address as 0xbf000000 needs to map to the first
    byte of shadow memory and 0xffffffff needs to map to
    the last byte of shadow memory. Since:
    SHADOW_ADDR = (address >> 3) + KASAN_SHADOW_OFFSET
    0xb6e00000 = (0xbf000000 >> 3) + KASAN_SHADOW_OFFSET
    KASAN_SHADOW_OFFSET = 0xb6e00000 - (0xbf000000 >> 3)
    KASAN_SHADOW_OFFSET = 0xb6e00000 - 0x17e00000
    KASAN_SHADOW_OFFSET = 0x9f000000

- 0x8f000000 if we have 3G userspace / 1G kernelspace with full 1 GB low memory (VMSPLIT_3G_OPT):
- The kernel address space is 1GB (0x40000000)
- PAGE_OFFSET is set to 0xb0000000 so the kernel static

    image uses 0xb0000000 .. 0xffffffff.
  - On top of that we have the MODULES_VADDR which under
    the worst case (using ARM instructions) is
    PAGE_OFFSET - 16M (0x01000000) = 0xaf000000
    so the modules use addresses 0xaf000000 .. 0xaffffff
  - So the addresses 0xaf000000 .. 0xffffffff need to be
    covered with shadow memory. That is 0x51000000 bytes
    of memory.
  - 1/8 of that is needed for its shadow memory, so
    0x0a200000 bytes of shadow memory is needed. We
    "steal" that from the remaining lowmem.
  - The KASAN_SHADOW_START becomes 0xa4e00000, to
    KASAN_SHADOW_END at 0xaeffffff.
  - Now we can calculate the KASAN_SHADOW_OFFSET for any
    kernel address as 0xaf000000 needs to map to the first
    byte of shadow memory and 0xffffffff needs to map to
    the last byte of shadow memory. Since:
    SHADOW_ADDR = (address >> 3) + KASAN_SHADOW_OFFSET
    0xa4e00000 = (0xaf000000 >> 3) + KASAN_SHADOW_OFFSET
    KASAN_SHADOW_OFFSET = 0xa4e00000 - (0xaf000000 >> 3)
    KASAN_SHADOW_OFFSET = 0xa4e00000 - 0x15e00000
    KASAN_SHADOW_OFFSET = 0x8f000000

- The default value of 0xffffffff for KASAN_SHADOW_OFFSET is an error value. We should always match one of the above shadow offsets.

When we do this, TASK_SIZE will sometimes get a bit odd values that will not fit into immediate mov assembly instructions. To account for this, we need to rewrite some assembly using TASK_SIZE like this:

-       mov     r1, #TASK_SIZE
+       ldr     r1, =TASK_SIZE

or

-       cmp     r4, #TASK_SIZE
+       ldr     r0, =TASK_SIZE
+       cmp     r4, r0

this is done to avoid the immediate #TASK_SIZE that need to fit into a limited number of bits.

---
ChangeLog v13->v14:
- Resend with the other patches
ChangeLog v12->v13:
- Rebase on kernel v5.9-rc1
ChangeLog v11->v12:
- Resend with the other changes.
ChangeLog v10->v11:
- Resend with the other changes.
ChangeLog v9->v10:
- Rebase on v5.8-rc1
ChangeLog v8->v9:
- Collect Ard's tags.
ChangeLog v7->v8:
- Rewrote the PMD clearing code to take into account that KASan may not always be adjacent to MODULES_VADDR: if we compile for thumb, then there will be an 8 MB hole between the shadow memory and MODULES_VADDR. Make this explicit and use the KASAN defines with an explicit ifdef so it is clear what is going on in the prepare_page_table().
- Patch memory.rst to reflect the location of KASan shadow memory.
ChangeLog v6->v7:
- Use the SPDX license identifier.
- Rewrote the commit message and updates the illustration.
- Move KASAN_OFFSET Kconfig set-up into this patch and put it right after PAGE_OFFSET so it is clear how this works, and we have all defines in one patch.
- Added KASAN_SHADOW_OFFSET of 0x8f000000 for 3G_OPT. See the calculation in the commit message.
- Updated the commit message with detailed information on how KASAN_SHADOW_OFFSET is obtained for the different VMSPLIT/PAGE_OFFSET options.

---
 Documentation/arm/memory.rst       |  5 ++
 arch/arm/Kconfig                   |  9 ++++
 arch/arm/include/asm/kasan_def.h   | 81 ++++++++++++++++++++++++++++++
 arch/arm/include/asm/memory.h      |  5 ++
 arch/arm/include/asm/uaccess-asm.h |  2 +-
 arch/arm/kernel/entry-armv.S       |  3 +-
 arch/arm/kernel/entry-common.S     |  9 ++--
 arch/arm/mm/mmu.c                  | 18 +++++++
 8 files changed, 127 insertions(+), 5 deletions(-)
 create mode 100644 arch/arm/include/asm/kasan_def.h
Documentation/arm/memory.rst +5 -0
index 0521b4ce5c96..36bae90cfb1e 100644
@@ -72,6 +72,11 @@ MODULES_VADDR	MODULES_END-1	Kernel module space
 				Kernel modules inserted via insmod are
 				placed here using dynamic mappings.
 
+TASK_SIZE	MODULES_VADDR-1	KASAn shadow memory when KASan is in use.
+				The range from MODULES_VADDR to the top
+				of the memory is shadowed here with 1 bit
+				per byte of memory.
+
 00001000	TASK_SIZE-1	User space mappings
 				Per-thread mappings are placed here via
 				the mmap() system call.
arch/arm/Kconfig +9 -0
index e00d94b16658..0489b8d07172 100644
@@ -1324,6 +1324,15 @@ config PAGE_OFFSET
 	default 0xB0000000 if VMSPLIT_3G_OPT
 	default 0xC0000000
 
+config KASAN_SHADOW_OFFSET
+	hex
+	depends on KASAN
+	default 0x1f000000 if PAGE_OFFSET=0x40000000
+	default 0x5f000000 if PAGE_OFFSET=0x80000000
+	default 0x9f000000 if PAGE_OFFSET=0xC0000000
+	default 0x8f000000 if PAGE_OFFSET=0xB0000000
+	default 0xffffffff
+
 config NR_CPUS
 	int "Maximum number of CPUs (2-32)"
 	range 2 32
arch/arm/include/asm/kasan_def.h new file +81 -0

81 lines not on this page · raw message

arch/arm/include/asm/memory.h +5 -0
index 99035b5891ef..5cfa9e5dc733 100644
@@ -18,6 +18,7 @@
 #ifdef CONFIG_NEED_MACH_MEMORY_H
 #include <mach/memory.h>
 #endif
+#include <asm/kasan_def.h>
 
 /* PAGE_OFFSET - the virtual address of the start of the kernel image */
 #define PAGE_OFFSET		UL(CONFIG_PAGE_OFFSET)
@@ -28,7 +29,11 @@
  * TASK_SIZE - the maximum size of a user space task.
  * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
  */
+#ifndef CONFIG_KASAN
 #define TASK_SIZE		(UL(CONFIG_PAGE_OFFSET) - UL(SZ_16M))
+#else
+#define TASK_SIZE		(KASAN_SHADOW_START)
+#endif
 #define TASK_UNMAPPED_BASE	ALIGN(TASK_SIZE / 3, SZ_16M)
 
 /*
arch/arm/include/asm/uaccess-asm.h +1 -1
index 907571fd05c6..e6eb7a2aaf1e 100644
@@ -85,7 +85,7 @@
 	 */
 	.macro	uaccess_entry, tsk, tmp0, tmp1, tmp2, disable
 	ldr	\tmp1, [\tsk, #TI_ADDR_LIMIT]
-	mov	\tmp2, #TASK_SIZE
+	ldr	\tmp2, =TASK_SIZE
 	str	\tmp2, [\tsk, #TI_ADDR_LIMIT]
  DACR(	mrc	p15, 0, \tmp0, c3, c0, 0)
  DACR(	str	\tmp0, [sp, #SVC_DACR])
arch/arm/kernel/entry-armv.S +2 -1
index 55a47df04773..c4220f51fcf3 100644
@@ -427,7 +427,8 @@ ENDPROC(__fiq_abt)
 	@ if it was interrupted in a critical region.  Here we
 	@ perform a quick test inline since it should be false
 	@ 99.9999% of the time.  The rest is done out of line.
-	cmp	r4, #TASK_SIZE
+	ldr	r0, =TASK_SIZE
+	cmp	r4, r0
 	blhs	kuser_cmpxchg64_fixup
 #endif
 #endif
arch/arm/kernel/entry-common.S +6 -3
index 271cb8a1eba1..fee279e28a72 100644
@@ -50,7 +50,8 @@ __ret_fast_syscall:
  UNWIND(.cantunwind	)
 	disable_irq_notrace			@ disable interrupts
 	ldr	r2, [tsk, #TI_ADDR_LIMIT]
-	cmp	r2, #TASK_SIZE
+	ldr	r1, =TASK_SIZE
+	cmp	r2, r1
 	blne	addr_limit_check_failed
 	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
 	tst	r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
@@ -87,7 +88,8 @@ __ret_fast_syscall:
 #endif
 	disable_irq_notrace			@ disable interrupts
 	ldr	r2, [tsk, #TI_ADDR_LIMIT]
-	cmp	r2, #TASK_SIZE
+	ldr     r1, =TASK_SIZE
+	cmp     r2, r1
 	blne	addr_limit_check_failed
 	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
 	tst	r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
@@ -128,7 +130,8 @@ ret_slow_syscall:
 	disable_irq_notrace			@ disable interrupts
 ENTRY(ret_to_user_from_irq)
 	ldr	r2, [tsk, #TI_ADDR_LIMIT]
-	cmp	r2, #TASK_SIZE
+	ldr     r1, =TASK_SIZE
+	cmp	r2, r1
 	blne	addr_limit_check_failed
 	ldr	r1, [tsk, #TI_FLAGS]
 	tst	r1, #_TIF_WORK_MASK
arch/arm/mm/mmu.c +18 -0
index 732c856c357d..89728232a99a 100644
@@ -30,6 +30,7 @@
 #include <asm/procinfo.h>
 #include <asm/memory.h>
 #include <asm/pgalloc.h>
+#include <asm/kasan_def.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
@@ -1266,8 +1267,25 @@ static inline void prepare_page_table(void)
 	/*
 	 * Clear out all the mappings below the kernel image.
 	 */
+#ifdef CONFIG_KASAN
+	/*
+	 * KASan's shadow memory inserts itself between the TASK_SIZE
+	 * and MODULES_VADDR. Do not clear the KASan shadow memory mappings.
+	 */
+	for (addr = 0; addr < KASAN_SHADOW_START; addr += PMD_SIZE)
+		pmd_clear(pmd_off_k(addr));
+	/*
+	 * Skip over the KASan shadow area. KASAN_SHADOW_END is sometimes
+	 * equal to MODULES_VADDR and then we exit the pmd clearing. If we
+	 * are using a thumb-compiled kernel, there there will be 8MB more
+	 * to clear as KASan always offset to 16 MB below MODULES_VADDR.
+	 */
+	for (addr = KASAN_SHADOW_END; addr < MODULES_VADDR; addr += PMD_SIZE)
+		pmd_clear(pmd_off_k(addr));
+#else
 	for (addr = 0; addr < MODULES_VADDR; addr += PMD_SIZE)
 		pmd_clear(pmd_off_k(addr));
+#endif
 
 #ifdef CONFIG_XIP_KERNEL
 	/* The XIP kernel is mapped in the module area -- skip over it */
Signature · 7 lines
2.26.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#21 lore raw

PATCH v14 5/6 ARM: Initialize the mapping of KASan shadow memory

In reply to Linus Walleij

This patch initializes KASan shadow region's page table and memory. There are two stage for KASan initializing:

1. At early boot stage the whole shadow region is mapped to just one physical page (kasan_zero_page). It is finished by the function kasan_early_init which is called by __mmap_switched(arch/arm/kernel/ head-common.S)

2. After the calling of paging_init, we use kasan_zero_page as zero shadow for some memory that KASan does not need to track, and we allocate a new shadow space for the other memory that KASan need to track. These issues are finished by the function kasan_init which is call by setup_arch.

When using KASan we also need to increase the THREAD_SIZE_ORDER from 1 to 2 as the extra calls for shadow memory uses quite a bit of stack.

As we need to make a temporary copy of the PGD when setting up shadow memory we create a helpful PGD_SIZE definition for both LPAE and non-LPAE setups.

The KASan core code unconditionally calls pud_populate() so this needs to be changed from BUG() to do {} while (0) when building with KASan enabled.

After the initial development by Andre Ryabinin several modifications have been made to this code:

Abbott Liu <[email protected]>
- Add support ARM LPAE: If LPAE is enabled, KASan shadow region's mapping table need be copied in the pgd_alloc() function.
- Change kasan_pte_populate,kasan_pmd_populate,kasan_pud_populate, kasan_pgd_populate from .meminit.text section to .init.text section. Reported by Florian Fainelli <[email protected]>

Linus Walleij <[email protected]>:
- Drop the custom mainpulation of TTBR0 and just use cpu_switch_mm() to switch the pgd table.
- Adopt to handle 4th level page tabel folding.
- Rewrite the entire page directory and page entry initialization sequence to be recursive based on ARM64:s kasan_init.c.

---
ChangeLog v13->v14:
- Provide more elaborate prints of how virtual kernel memory is mapped to the allocated lowmem pages.
- Make sure to also map the memory around the __atags_pointer:
this memory is used for the device tree blob (DTB) and will be accessed by the device tree parser. We were just lucky that this was mostly in some acceptable memory location until now.
ChangeLog v12->v13:
- Rebase on kernel v5.9-rc1
ChangeLog v11->v12:
- Do not try to shadow highmem memory blocks. (Ard)
- Provoke a build bug if the entire shadow memory doesn't fit inside a single pgd_index() (Ard)
- Move the pointer to (unsigned long) casts into the create_mapping() function. (Ard)
- After setting up the shadow memory make sure to issue local_flush_tlb_all() so that we refresh all the global mappings. (Ard)
- Simplify pte_populate() (Ard)
- Skip over pud population as well as p4d. (Ard)
- Drop the stop condition pmd_none(*pmdp) in the pmd population loop. (Ard)
- Stop passing around the node (NUMA) parameter in the init code, we are not expecting any NUMA architectures to be introduced into ARM32 so just hardcode NUMA_NO_NODE when calling memblock_alloc_try_nid().
ChangeLog v10->v11:
- Fix compilation on LPAE systems.
- Move the check for valid pgdp, pudp and pmdp into the loop for each level moving over the directory pointers: we were just lucky that we just needed one directory for each level so this fixes the pmdp issue with LPAE and KASan now works like a charm on LPAE as well.
- Fold fourth level page directory (p4d) into the global page directory pgd and just skip into the page upper directory (pud) directly. We do not anticipate that ARM32 will every use 5-level page tables.
- Simplify the ifdeffery around the temporary pgd.
- Insert a comment about pud_populate() that is unconditionally called by the KASan core code.
ChangeLog v9->v10:
- Rebase onto v5.8-rc1
- add support for folded p4d page tables, use the primitives necessary for the 4th level folding, add (empty) walks of p4d level.
- Use the <linux/pgtable.h> header file that has now appeared as part of the VM consolidation series.
- Use a recursive method to walk pgd/p4d/pud/pmd/pte instead of the separate early/main calls and the flat call structure used in the old code. This was inspired by the ARM64 KASan init code.
- Assume authorship of this code, I have now written the majority of it so the blame is on me and noone else.
ChangeLog v8->v9:
- Drop the custom CP15 manipulation and cache flushing for swapping TTBR0 and instead just use cpu_switch_mm().
- Collect Ard's tags.
ChangeLog v7->v8:
- Rebased.
ChangeLog v6->v7:
- Use SPDX identifer for the license.
- Move the TTBR0 accessor calls into this patch.

---
 arch/arm/include/asm/kasan.h       |  32 ++++
 arch/arm/include/asm/pgalloc.h     |   8 +-
 arch/arm/include/asm/thread_info.h |   8 +
 arch/arm/kernel/head-common.S      |   3 +
 arch/arm/kernel/setup.c            |   2 +
 arch/arm/mm/Makefile               |   3 +
 arch/arm/mm/kasan_init.c           | 286 +++++++++++++++++++++++++++++
 arch/arm/mm/pgd.c                  |  16 +-
 8 files changed, 356 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/include/asm/kasan.h
 create mode 100644 arch/arm/mm/kasan_init.c
arch/arm/include/asm/kasan.h new file +32 -0
new file mode 100644
index 000000000000..56b954db160e
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * arch/arm/include/asm/kasan.h
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Author: Andrey Ryabinin <[email protected]>
+ *
+ */
+
+#ifndef __ASM_KASAN_H
+#define __ASM_KASAN_H
+
+#ifdef CONFIG_KASAN
+
+#include <asm/kasan_def.h>
+
+#define KASAN_SHADOW_SCALE_SHIFT 3
+
+/*
+ * The compiler uses a shadow offset assuming that addresses start
+ * from 0. Kernel addresses don't start from 0, so shadow
+ * for kernel really starts from 'compiler's shadow offset' +
+ * ('kernel address space start' >> KASAN_SHADOW_SCALE_SHIFT)
+ */
+
+extern void kasan_init(void);
+
+#else
+static inline void kasan_init(void) { }
+#endif
+
+#endif
arch/arm/include/asm/pgalloc.h +7 -1
index 15f4674715f8..fdee1f04f4f3 100644
@@ -21,6 +21,7 @@
 #define _PAGE_KERNEL_TABLE	(PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
 
 #ifdef CONFIG_ARM_LPAE
+#define PGD_SIZE		(PTRS_PER_PGD * sizeof(pgd_t))
 
 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
 {
@@ -28,14 +29,19 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
 }
 
 #else	/* !CONFIG_ARM_LPAE */
+#define PGD_SIZE		(PAGE_SIZE << 2)
 
 /*
  * Since we have only two-level page tables, these are trivial
  */
 #define pmd_alloc_one(mm,addr)		({ BUG(); ((pmd_t *)2); })
 #define pmd_free(mm, pmd)		do { } while (0)
+#ifdef CONFIG_KASAN
+/* The KASan core unconditionally calls pud_populate() on all architectures */
+#define pud_populate(mm,pmd,pte)	do { } while (0)
+#else
 #define pud_populate(mm,pmd,pte)	BUG()
-
+#endif
 #endif	/* CONFIG_ARM_LPAE */
 
 extern pgd_t *pgd_alloc(struct mm_struct *mm);
arch/arm/include/asm/thread_info.h +8 -0
index 536b6b979f63..56fae7861fd3 100644
@@ -13,7 +13,15 @@
 #include <asm/fpstate.h>
 #include <asm/page.h>
 
+#ifdef CONFIG_KASAN
+/*
+ * KASan uses a lot of extra stack space so the thread size order needs to
+ * be increased.
+ */
+#define THREAD_SIZE_ORDER	2
+#else
 #define THREAD_SIZE_ORDER	1
+#endif
 #define THREAD_SIZE		(PAGE_SIZE << THREAD_SIZE_ORDER)
 #define THREAD_START_SP		(THREAD_SIZE - 8)
 
arch/arm/kernel/head-common.S +3 -0
index 6840c7c60a85..89c80154b9ef 100644
@@ -111,6 +111,9 @@ __mmap_switched:
 	str	r8, [r2]			@ Save atags pointer
 	cmp	r3, #0
 	strne	r10, [r3]			@ Save control register values
+#ifdef CONFIG_KASAN
+	bl	kasan_early_init
+#endif
 	mov	lr, #0
 	b	start_kernel
 ENDPROC(__mmap_switched)
arch/arm/kernel/setup.c +2 -0
index d0562cdc919e..8b28eca23326 100644
@@ -58,6 +58,7 @@
 #include <asm/unwind.h>
 #include <asm/memblock.h>
 #include <asm/virt.h>
+#include <asm/kasan.h>
 
 #include "atags.h"
 
@@ -1132,6 +1133,7 @@ void __init setup_arch(char **cmdline_p)
 	early_ioremap_reset();
 
 	paging_init(mdesc);
+	kasan_init();
 	request_standard_resources(mdesc);
 
 	if (mdesc->restart)
arch/arm/mm/Makefile +3 -0
index 99699c32d8a5..4536159bc8fa 100644
@@ -113,3 +113,6 @@ obj-$(CONFIG_CACHE_L2X0_PMU)	+= cache-l2x0-pmu.o
 obj-$(CONFIG_CACHE_XSC3L2)	+= cache-xsc3l2.o
 obj-$(CONFIG_CACHE_TAUROS2)	+= cache-tauros2.o
 obj-$(CONFIG_CACHE_UNIPHIER)	+= cache-uniphier.o
+
+KASAN_SANITIZE_kasan_init.o	:= n
+obj-$(CONFIG_KASAN)		+= kasan_init.o
arch/arm/mm/kasan_init.c new file +286 -0

286 lines not on this page · raw message

arch/arm/mm/pgd.c +15 -1
index c5e1b27046a8..f8e9bc58a84f 100644
@@ -66,7 +66,21 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
 	new_pmd = pmd_alloc(mm, new_pud, 0);
 	if (!new_pmd)
 		goto no_pmd;
-#endif
+#ifdef CONFIG_KASAN
+	/*
+	 * Copy PMD table for KASAN shadow mappings.
+	 */
+	init_pgd = pgd_offset_k(TASK_SIZE);
+	init_p4d = p4d_offset(init_pgd, TASK_SIZE);
+	init_pud = pud_offset(init_p4d, TASK_SIZE);
+	init_pmd = pmd_offset(init_pud, TASK_SIZE);
+	new_pmd = pmd_offset(new_pud, TASK_SIZE);
+	memcpy(new_pmd, init_pmd,
+	       (pmd_index(MODULES_VADDR) - pmd_index(TASK_SIZE))
+	       * sizeof(pmd_t));
+	clean_dcache_area(new_pmd, PTRS_PER_PMD * sizeof(pmd_t));
+#endif /* CONFIG_KASAN */
+#endif /* CONFIG_LPAE */
 
 	if (!vectors_high()) {
 		/*
Signature · 7 lines
2.26.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#22 lore raw

PATCH v14 6/6 ARM: Enable KASan for ARM

In reply to Linus Walleij

From: Andrey Ryabinin <[email protected]>

This patch enables the kernel address sanitizer for ARM. XIP_KERNEL has not been tested and is therefore not allowed for now.

---
ChangeLog v13->v14:
- Resend with the other patches.
ChangeLog v12->v13:
- Rebase on kernel v5.9-rc1
ChangeLog v11->v12:
- Resend with the other changes.
ChangeLog v10->v11:
- Resend with the other changes.
ChangeLog v9->v10:
- Rebase on v5.8-rc1
ChangeLog v8->v9:
- Fix the arch feature matrix for Arm to include KASan.
- Collect Ard's tags.
ChangeLog v7->v8:
- Moved the hacks to __ADDRESS_SANITIZE__ to the patch replacing the memory access functions.
- Moved the definition of KASAN_OFFSET out of this patch and to the patch that defines the virtual memory used by KASan.

---
 Documentation/dev-tools/kasan.rst                   | 4 ++--
 Documentation/features/debug/KASAN/arch-support.txt | 2 +-
 arch/arm/Kconfig                                    | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)
Documentation/dev-tools/kasan.rst +2 -2
index 38fd5681fade..050dcd346144 100644
@@ -18,8 +18,8 @@ out-of-bounds accesses for global variables is only supported since Clang 11.
 
 Tag-based KASAN is only supported in Clang and requires version 7.0.0 or later.
 
-Currently generic KASAN is supported for the x86_64, arm64, xtensa, s390 and
-riscv architectures, and tag-based KASAN is supported only for arm64.
+Currently generic KASAN is supported for the x86_64, arm, arm64, xtensa, s390
+and riscv architectures, and tag-based KASAN is supported only for arm64.
 
 Usage
 -----
Documentation/features/debug/KASAN/arch-support.txt +1 -1
index c3fe9b266e7b..b2288dc14b72 100644
@@ -8,7 +8,7 @@
     -----------------------
     |       alpha: | TODO |
     |         arc: | TODO |
-    |         arm: | TODO |
+    |         arm: |  ok  |
     |       arm64: |  ok  |
     |         c6x: | TODO |
     |        csky: | TODO |
arch/arm/Kconfig +1 -0
index 0489b8d07172..873bd26f5d43 100644
@@ -66,6 +66,7 @@ config ARM
 	select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6
 	select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU
 	select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU
+	select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL
 	select HAVE_ARCH_MMAP_RND_BITS if MMU
 	select HAVE_ARCH_SECCOMP_FILTER if AEABI && !OABI_COMPAT
 	select HAVE_ARCH_THREAD_STRUCT_WHITELIST
Signature · 7 lines
2.26.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#23 lore raw
In reply to Linus Walleij
Quoted 14 lines · Linus Walleij

This is the 14th iteration of KASan for ARM/Aarch32.

I have added one patch in the beginning of the series to fix the issue when the DTB (often attached DTB) ends up in lowmem. It also amends ARM to copy the device tree instead of just unflattening it and using it from where it is.

This fixes my particular issue on the Qualcomm APQ8060 and I hope it may also solve Florian's issue and what Ard has been seeing. If you inspect patch 1/6 you can see what has been going on for me. My hypothesis about what was going on was mostly right.

Quoted 5 lines

You are encouraged to test this patch set to find memory out of bounds bugs with ARM32 platforms and drivers.

There is a git branch you can pull in:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=kasan

It does appear to be slight better, although all platforms that I have where memory starts at physical address 0 cannot boot, attached logs which are all more or less the same.

The physical memory map looks like this:

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

Do any of the platforms you use for testing have a similar memory map? Could you try to contrive a QEMU machine to have something similar in case that helps reproducing these failures?

Thanks

Quoted 46 lines

Abbott Liu (1):
ARM: Define the virtual space of KASan's shadow region

Andrey Ryabinin (3):
ARM: Disable KASan instrumentation for some code
ARM: Replace string mem* functions for KASan
ARM: Enable KASan for ARM

Linus Walleij (2):
ARM: Handle a device tree in lowmem
ARM: Initialize the mapping of KASan shadow memory

  Documentation/arm/memory.rst                  |   5 +
  Documentation/dev-tools/kasan.rst             |   4 +-
  .../features/debug/KASAN/arch-support.txt     |   2 +-
  arch/arm/Kconfig                              |  10 +
  arch/arm/boot/compressed/Makefile             |   1 +
  arch/arm/boot/compressed/string.c             |  19 ++
  arch/arm/include/asm/kasan.h                  |  32 ++
  arch/arm/include/asm/kasan_def.h              |  81 +++++
  arch/arm/include/asm/memory.h                 |   5 +
  arch/arm/include/asm/pgalloc.h                |   8 +-
  arch/arm/include/asm/prom.h                   |   5 +
  arch/arm/include/asm/string.h                 |  21 ++
  arch/arm/include/asm/thread_info.h            |   8 +
  arch/arm/include/asm/uaccess-asm.h            |   2 +-
  arch/arm/kernel/devtree.c                     |  14 +-
  arch/arm/kernel/entry-armv.S                  |   3 +-
  arch/arm/kernel/entry-common.S                |   9 +-
  arch/arm/kernel/head-common.S                 |   7 +-
  arch/arm/kernel/setup.c                       |  10 +-
  arch/arm/kernel/unwind.c                      |   6 +-
  arch/arm/lib/memcpy.S                         |   3 +
  arch/arm/lib/memmove.S                        |   5 +-
  arch/arm/lib/memset.S                         |   3 +
  arch/arm/mm/Makefile                          |   5 +
  arch/arm/mm/kasan_init.c                      | 286 ++++++++++++++++++
  arch/arm/mm/mmu.c                             |  55 +++-
  arch/arm/mm/pgd.c                             |  16 +-
  arch/arm/vdso/Makefile                        |   2 +
  28 files changed, 608 insertions(+), 19 deletions(-)

create mode 100644 arch/arm/include/asm/kasan.h create mode 100644 arch/arm/include/asm/kasan_def.h create mode 100644 arch/arm/mm/kasan_init.c

Signature · 1 line
Florian
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.9.0-rc7-g79c212fcfb1d (fainelli@fainelli-desktop) (arm-linux-gcc (GCC) 8.3.0, GNU ld (GNU Binutils) 2.32) #6 SMP Thu Oct 1 12:09:58 PDT 2020
[    0.000000] CPU: ARMv7 Processor [420f00f3] revision 3 (ARMv7), cr=30c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: BCM97250SV
[    0.000000] printk: bootconsole [earlycon0] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 16 MiB at 0x000000003cc00000
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000002fffffff]
[    0.000000]   Normal   empty
[    0.000000]   HighMem  [mem 0x0000000030000000-0x000000003dffefff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000003dffefff]
[    0.000000] Zeroed struct page in unavailable ranges: 1 pages
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000003dffefff]
[    0.000000] kasan: Truncate memory block c0000000-fdfff000
[    0.000000]  to c0000000-f0000000
[    0.000000] kasan: Mapping kernel virtual memory block: c0000000-f0000000 at shadow: b7000000-bd000000
[    0.000000] 8<--- cut here ---
[    0.000000] Unable to handle kernel paging request at virtual address bcdffe00
[    0.000000] pgd = (ptrval)
[    0.000000] [bcdffe00] *pgd=80000000006003, *pmd=00000000
[    0.000000] Internal error: Oops: 206 [#1] SMP ARM
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.9.0-rc7-g79c212fcfb1d #6
[    0.000000] Hardware name: Broadcom STB (Flattened Device Tree)
[    0.000000] PC is at check_memory_region+0x54/0x1c8
[    0.000000] LR is at 0x40
[    0.000000] pc : [<c0455080>]    lr : [<00000040>]    psr: 600000d3
[    0.000000] sp : c2803c18  ip : bcdffe00  fp : c2803c44
[    0.000000] r10: 00000000  r9 : 00001000  r8 : bce00000
[    0.000000] r7 : bcdfffff  r6 : eeffffff  r5 : eefff000  r4 : 00000000
[    0.000000] r3 : c181d3fc  r2 : 00000001  r1 : 00001000  r0 : eefff000
[    0.000000] Flags: nZCv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment user
[    0.000000] Control: 30c5387d  Table: 01877100  DAC: fffffffd
[    0.000000] Process swapper (pid: 0, stack limit = 0x(ptrval))
[    0.000000] Stack: (0xc2803c18 to 0xc2804000)
[    0.000000] 3c00:                                                       c181d3fc 00001000
[    0.000000] 3c20: eefff000 00000000 00000000 c2806d48 00001000 00000000 c2803c64 c2803c48
[    0.000000] 3c40: c0452e84 c0455038 b7500794 00000000 eefff000 00000000 c2803d6c c2803c68
[    0.000000] 3c60: c181d3fc c0452e68 3fffffff 00000000 00000001 00000000 ffffffff 00000000
[    0.000000] 3c80: 0000006a c2800010 c2b7ca60 c2b7ca60 c2806df0 600000d3 c2b7cc60 0000005a
[    0.000000] 3ca0: 41b58ab3 c1681824 c181d2c4 c2803cb8 c02b4320 c02b239c c166b130 c2803dec
[    0.000000] 3cc0: 3fffffff 00000000 c2803d24 00000001 00000018 00000000 c166b1a4 c2690420
[    0.000000] 3ce0: 00000000 c166b130 c2803dec 00000000 00000000 c166b1d8 c2803d1c c2803d08
[    0.000000] 3d00: 00000001 00000000 c166b130 c2803dec c2803d4c c2803d20 c02b5a3c c02b43d8
[    0.000000] 3d20: c02b43fc c02b4144 c166b1a4 b75007ac c2806d48 c28a29e0 c2ba0ac0 00000000
[    0.000000] 3d40: c2803de4 00000001 00000000 b7600000 ef474fa0 c0006dd8 c16e2060 b75f4000
[    0.000000] 3d60: c2803d9c c2803d70 c180b930 c181d2d0 3fffffff 00000000 00000001 00000000
[    0.000000] 3d80: ffffffff c166bb78 2f00071f c2b784d8 c2803df4 c2803da0 c180babc c180b8b8
[    0.000000] 3da0: 2f00071f 00c00000 c2803dd4 bd000000 c28a2780 00002b76 c280a484 c0003010
[    0.000000] 3dc0: 00000000 bd000000 c2803e14 bd000000 b7000000 c28a29e0 c2ba0ac0 3dfff000
[    0.000000] 3de0: 00000000 c166b1d8 c2803e14 c2803df8 c180bbf8 c180b944 bd000000 c2803e18
[    0.000000] 3e00: c0000000 00000000 c2803e6c c2803e18 c180beb0 c180bbac f0000000 00000000
[    0.000000] 3e20: 00000000 c166b1a4 c16e2060 c166b17c c16e2000 c18750d8 3dfff000 00000000
[    0.000000] 3e40: c2803e6c c28a2780 c2fdcfa0 c1873a40 c0008000 e12fff1e c0226668 c18613a0
[    0.000000] 3e60: c2803fa4 c2803e70 c1805684 c180bc78 0000006c 30c5387d 00000003 00000001
[    0.000000] 3e80: 00000001 00000000 c16e2060 c2690420 185007d8 00000001 c2803f9c 00000000
[    0.000000] 3ea0: 420f00f3 c2806d40 c2803ecc c2803eb8 c2803fbc c2803f60 c1200980 c2803f9c
[    0.000000] 3ec0: 41b58ab3 c16696b0 c1804e3c c02b43d8 c02b4fd0 c02b59b0 00000000 b75007e4
[    0.000000] 3ee0: c2806d48 30c0387d ffffffff 0781a000 c2803f94 c2803f00 c02b4fd0 c02b59b0
[    0.000000] 3f00: c2803f74 00000000 c2803f34 c2803f18 c2803f34 c2803f20 c0298af8 c0454b8c
[    0.000000] 3f20: 41b58ab3 c166bb78 c02b4f40 c2803f38 c0320aac c0454b8c 00000000 c2865538
[    0.000000] 3f40: c2803f9c c28653e0 c1877270 c28655ac c28653f0 0781a000 c2b9b5c0 00000005
[    0.000000] 3f60: 00000000 ffffffff c2803f84 c2803f78 c0454bec 00000000 c2803fa4 00007000
[    0.000000] 3f80: c2806d48 30c0387d ffffffff 0781a000 420f00f3 c2806d40 c2803ff4 c2803fa8
[    0.000000] 3fa0: c1801010 c1804e48 c280a484 c0003010 00000001 bf000000 00000000 c1873a40
[    0.000000] 3fc0: 00000000 00000000 ffffffff c1800334 00000000 30c0387d ffffffff 0781a000
[    0.000000] 3fe0: 420f00f3 30c5387d 00000000 c2803ff8 00000000 c1800f94 00000000 00000000
[    0.000000] Backtrace: 
[    0.000000] [<c045502c>] (check_memory_region) from [<c0452e84>] (memset+0x28/0x44)
[    0.000000]  r10:00000000 r9:00001000 r8:c2806d48 r7:00000000 r6:00000000 r5:eefff000
[    0.000000]  r4:00001000 r3:c181d3fc
[    0.000000] [<c0452e5c>] (memset) from [<c181d3fc>] (memblock_alloc_try_nid+0x138/0x170)
[    0.000000]  r7:00000000 r6:eefff000 r5:00000000 r4:b7500794
[    0.000000] [<c181d2c4>] (memblock_alloc_try_nid) from [<c180b930>] (kasan_alloc_block.constprop.1+0x84/0x8c)
[    0.000000]  r10:b75f4000 r9:c16e2060 r8:c0006dd8 r7:ef474fa0 r6:b7600000 r5:00000000
[    0.000000]  r4:00000001
[    0.000000] [<c180b8ac>] (kasan_alloc_block.constprop.1) from [<c180babc>] (kasan_pgd_populate+0x184/0x268)
[    0.000000]  r5:c2b784d8 r4:2f00071f
[    0.000000] [<c180b938>] (kasan_pgd_populate) from [<c180bbf8>] (create_mapping+0x58/0x64)
[    0.000000]  r10:c166b1d8 r9:00000000 r8:3dfff000 r7:c2ba0ac0 r6:c28a29e0 r5:b7000000
[    0.000000]  r4:bd000000
[    0.000000] [<c180bba0>] (create_mapping) from [<c180beb0>] (kasan_init+0x244/0x394)
[    0.000000]  r5:00000000 r4:c0000000
[    0.000000] [<c180bc6c>] (kasan_init) from [<c1805684>] (setup_arch+0x848/0x1048)
[    0.000000]  r10:c18613a0 r9:c0226668 r8:e12fff1e r7:c0008000 r6:c1873a40 r5:c2fdcfa0
[    0.000000]  r4:c28a2780
[    0.000000] [<c1804e3c>] (setup_arch) from [<c1801010>] (start_kernel+0x88/0x3e4)
[    0.000000]  r10:c2806d40 r9:420f00f3 r8:0781a000 r7:ffffffff r6:30c0387d r5:c2806d48
[    0.000000]  r4:00007000
[    0.000000] [<c1800f88>] (start_kernel) from [<00000000>] (0x0)
[    0.000000]  r10:30c5387d r9:420f00f3 r8:0781a000 r7:ffffffff r6:30c0387d r5:00000000
[    0.000000]  r4:c1800334
[    0.000000] Code: da00001a e21c4007 1a000028 e1a0e1ce (e1cc40d0) 
[    0.000000] random: get_random_bytes called from print_oops_end_marker+0x30/0x5c with crng_init=0
[    0.000000] ---[ end trace fc1cf4c40c8932da ]---
[    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.9.0-rc7-g79c212fcfb1d (fainelli@fainelli-desktop) (arm-linux-gcc (GCC) 8.3.0, GNU ld (GNU Binutils) 2.32) #6 SMP Thu Oct 1 12:09:58 PDT 2020
[    0.000000] CPU: ARMv7 Processor [420f00f3] revision 3 (ARMv7), cr=30c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: BCM97364SV
[    0.000000] printk: bootconsole [earlycon0] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 16 MiB at 0x000000003cc00000
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000002fffffff]
[    0.000000]   Normal   empty
[    0.000000]   HighMem  [mem 0x0000000030000000-0x000000003dffefff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000003dffefff]
[    0.000000] Zeroed struct page in unavailable ranges: 1 pages
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000003dffefff]
[    0.000000] kasan: Truncate memory block c0000000-fdfff000
[    0.000000]  to c0000000-f0000000
[    0.000000] kasan: Mapping kernel virtual memory block: c0000000-f0000000 at shadow: b7000000-bd000000
[    0.000000] 8<--- cut here ---
[    0.000000] Unable to handle kernel paging request at virtual address bcdffe00
[    0.000000] pgd = (ptrval)
[    0.000000] [bcdffe00] *pgd=80000000006003, *pmd=00000000
[    0.000000] Internal error: Oops: 206 [#1] SMP ARM
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.9.0-rc7-g79c212fcfb1d #6
[    0.000000] Hardware name: Broadcom STB (Flattened Device Tree)
[    0.000000] PC is at check_memory_region+0x54/0x1c8
[    0.000000] LR is at 0x40
[    0.000000] pc : [<c0455080>]    lr : [<00000040>]    psr: 600000d3
[    0.000000] sp : c2803c18  ip : bcdffe00  fp : c2803c44
[    0.000000] r10: 00000000  r9 : 00001000  r8 : bce00000
[    0.000000] r7 : bcdfffff  r6 : eeffffff  r5 : eefff000  r4 : 00000000
[    0.000000] r3 : c181d3fc  r2 : 00000001  r1 : 00001000  r0 : eefff000
[    0.000000] Flags: nZCv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment user
[    0.000000] Control: 30c5387d  Table: 01877100  DAC: fffffffd
[    0.000000] Process swapper (pid: 0, stack limit = 0x(ptrval))
[    0.000000] Stack: (0xc2803c18 to 0xc2804000)
[    0.000000] 3c00:                                                       c181d3fc 00001000
[    0.000000] 3c20: eefff000 00000000 00000000 c2806d48 00001000 00000000 c2803c64 c2803c48
[    0.000000] 3c40: c0452e84 c0455038 b7500794 00000000 eefff000 00000000 c2803d6c c2803c68
[    0.000000] 3c60: c181d3fc c0452e68 3fffffff 00000000 00000001 00000000 ffffffff 00000000
[    0.000000] 3c80: 0000006a c2800010 c2b7ca60 c2b7ca60 c2806df0 600000d3 c2b7cc60 0000005a
[    0.000000] 3ca0: 41b58ab3 c1681824 c181d2c4 c2803cb8 c02b4320 c02b239c c166b130 c2803dec
[    0.000000] 3cc0: 3fffffff 00000000 c2803d24 00000001 00000018 00000000 c166b1a4 c2690420
[    0.000000] 3ce0: 00000000 c166b130 c2803dec 00000000 00000000 c166b1d8 c2803d1c c2803d08
[    0.000000] 3d00: 00000001 00000000 c166b130 c2803dec c2803d4c c2803d20 c02b5a3c c02b43d8
[    0.000000] 3d20: c02b43fc c02b4144 c166b1a4 b75007ac c2806d48 c28a29e0 c2ba0ac0 00000000
[    0.000000] 3d40: c2803de4 00000001 00000000 b7600000 ef474fa0 c0006dd8 c16e2060 b75f4000
[    0.000000] 3d60: c2803d9c c2803d70 c180b930 c181d2d0 3fffffff 00000000 00000001 00000000
[    0.000000] 3d80: ffffffff c166bb78 2f00071f c2b784d8 c2803df4 c2803da0 c180babc c180b8b8
[    0.000000] 3da0: 2f00071f 00c00000 c2803dd4 bd000000 c28a2780 00002b76 c280a484 c0003010
[    0.000000] 3dc0: 00000000 bd000000 c2803e14 bd000000 b7000000 c28a29e0 c2ba0ac0 3dfff000
[    0.000000] 3de0: 00000000 c166b1d8 c2803e14 c2803df8 c180bbf8 c180b944 bd000000 c2803e18
[    0.000000] 3e00: c0000000 00000000 c2803e6c c2803e18 c180beb0 c180bbac f0000000 00000000
[    0.000000] 3e20: 00000000 c166b1a4 c16e2060 c166b17c c16e2000 c18750d8 3dfff000 00000000
[    0.000000] 3e40: c2803e6c c28a2780 c2fdcfa0 c1873a40 c0008000 e12fff1e c0226668 c18613a0
[    0.000000] 3e60: c2803fa4 c2803e70 c1805684 c180bc78 0000006c 30c5387d 00000003 00000001
[    0.000000] 3e80: 00000001 00000000 c16e2060 c2690420 185007d8 00000001 c2803f9c 00000000
[    0.000000] 3ea0: 420f00f3 c2806d40 c2803ecc c2803eb8 c2803fbc c2803f60 c1200980 c2803f9c
[    0.000000] 3ec0: 41b58ab3 c16696b0 c1804e3c c02b43d8 c02b4fd0 c02b59b0 00000000 b75007e4
[    0.000000] 3ee0: c2806d48 30c0387d ffffffff 07819000 c2803f94 c2803f00 c02b4fd0 c02b59b0
[    0.000000] 3f00: c2803f74 00000000 c2803f34 c2803f18 c2803f34 c2803f20 c0298af8 c0454b8c
[    0.000000] 3f20: 41b58ab3 c166bb78 c02b4f40 c2803f38 c0320aac c0454b8c 00000000 c2865538
[    0.000000] 3f40: c2803f9c c28653e0 c1877270 c28655ac c28653f0 07819000 c2b9b5c0 00000005
[    0.000000] 3f60: 00000000 ffffffff c2803f84 c2803f78 c0454bec 00000000 c2803fa4 00007000
[    0.000000] 3f80: c2806d48 30c0387d ffffffff 07819000 420f00f3 c2806d40 c2803ff4 c2803fa8
[    0.000000] 3fa0: c1801010 c1804e48 c280a484 c0003010 00000001 bf000000 00000000 c1873a40
[    0.000000] 3fc0: 00000000 00000000 ffffffff c1800334 00000000 30c0387d ffffffff 07819000
[    0.000000] 3fe0: 420f00f3 30c5387d 00000000 c2803ff8 00000000 c1800f94 00000000 00000000
[    0.000000] Backtrace: 
[    0.000000] [<c045502c>] (check_memory_region) from [<c0452e84>] (memset+0x28/0x44)
[    0.000000]  r10:00000000 r9:00001000 r8:c2806d48 r7:00000000 r6:00000000 r5:eefff000
[    0.000000]  r4:00001000 r3:c181d3fc
[    0.000000] [<c0452e5c>] (memset) from [<c181d3fc>] (memblock_alloc_try_nid+0x138/0x170)
[    0.000000]  r7:00000000 r6:eefff000 r5:00000000 r4:b7500794
[    0.000000] [<c181d2c4>] (memblock_alloc_try_nid) from [<c180b930>] (kasan_alloc_block.constprop.1+0x84/0x8c)
[    0.000000]  r10:b75f4000 r9:c16e2060 r8:c0006dd8 r7:ef474fa0 r6:b7600000 r5:00000000
[    0.000000]  r4:00000001
[    0.000000] [<c180b8ac>] (kasan_alloc_block.constprop.1) from [<c180babc>] (kasan_pgd_populate+0x184/0x268)
[    0.000000]  r5:c2b784d8 r4:2f00071f
[    0.000000] [<c180b938>] (kasan_pgd_populate) from [<c180bbf8>] (create_mapping+0x58/0x64)
[    0.000000]  r10:c166b1d8 r9:00000000 r8:3dfff000 r7:c2ba0ac0 r6:c28a29e0 r5:b7000000
[    0.000000]  r4:bd000000
[    0.000000] [<c180bba0>] (create_mapping) from [<c180beb0>] (kasan_init+0x244/0x394)
[    0.000000]  r5:00000000 r4:c0000000
[    0.000000] [<c180bc6c>] (kasan_init) from [<c1805684>] (setup_arch+0x848/0x1048)
[    0.000000]  r10:c18613a0 r9:c0226668 r8:e12fff1e r7:c0008000 r6:c1873a40 r5:c2fdcfa0
[    0.000000]  r4:c28a2780
[    0.000000] [<c1804e3c>] (setup_arch) from [<c1801010>] (start_kernel+0x88/0x3e4)
[    0.000000]  r10:c2806d40 r9:420f00f3 r8:07819000 r7:ffffffff r6:30c0387d r5:c2806d48
[    0.000000]  r4:00007000
[    0.000000] [<c1800f88>] (start_kernel) from [<00000000>] (0x0)
[    0.000000]  r10:30c5387d r9:420f00f3 r8:07819000 r7:ffffffff r6:30c0387d r5:00000000
[    0.000000]  r4:c1800334
[    0.000000] Code: da00001a e21c4007 1a000028 e1a0e1ce (e1cc40d0) 
[    0.000000] random: get_random_bytes called from print_oops_end_marker+0x30/0x5c with crng_init=0
[    0.000000] ---[ end trace 3c426ea188f7e274 ]---
[    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.9.0-rc7-g79c212fcfb1d (fainelli@fainelli-desktop) (arm-linux-gcc (GCC) 8.3.0, GNU ld (GNU Binutils) 2.32) #6 SMP Thu Oct 1 12:09:58 PDT 2020
[    0.000000] CPU: ARMv7 Processor [420f00f3] revision 3 (ARMv7), cr=30c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: BCM97366SV_V20_NO_PKT2
[    0.000000] printk: bootconsole [earlycon0] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 16 MiB at 0x00000000bec00000
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000002fffffff]
[    0.000000]   Normal   empty
[    0.000000]   HighMem  [mem 0x0000000030000000-0x00000000bfffefff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000003dffffff]
[    0.000000]   node   0: [mem 0x0000000080000000-0x00000000bfffefff]
[    0.000000] Zeroed struct page in unavailable ranges: 1 pages
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x00000000bfffefff]
[    0.000000] kasan: Truncate memory block c0000000-fe000000
[    0.000000]  to c0000000-f0000000
[    0.000000] kasan: Mapping kernel virtual memory block: c0000000-f0000000 at shadow: b7000000-bd000000
[    0.000000] 8<--- cut here ---
[    0.000000] Unable to handle kernel paging request at virtual address bcbffe00
[    0.000000] pgd = (ptrval)
[    0.000000] [bcbffe00] *pgd=80000000006003, *pmd=00000000
[    0.000000] Internal error: Oops: 206 [#1] SMP ARM
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.9.0-rc7-g79c212fcfb1d #6
[    0.000000] Hardware name: Broadcom STB (Flattened Device Tree)
[    0.000000] PC is at check_memory_region+0x54/0x1c8
[    0.000000] LR is at 0x40
[    0.000000] pc : [<c0455080>]    lr : [<00000040>]    psr: 600000d3
[    0.000000] sp : c2803c18  ip : bcbffe00  fp : c2803c44
[    0.000000] r10: 00000000  r9 : 00001000  r8 : bcc00000
[    0.000000] r7 : bcbfffff  r6 : edffffff  r5 : edfff000  r4 : 00000000
[    0.000000] r3 : c181d3fc  r2 : 00000001  r1 : 00001000  r0 : edfff000
[    0.000000] Flags: nZCv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment user
[    0.000000] Control: 30c5387d  Table: 01877100  DAC: fffffffd
[    0.000000] Process swapper (pid: 0, stack limit = 0x(ptrval))
[    0.000000] Stack: (0xc2803c18 to 0xc2804000)
[    0.000000] 3c00:                                                       c181d3fc 00001000
[    0.000000] 3c20: edfff000 00000000 00000000 c2806d48 00001000 00000000 c2803c64 c2803c48
[    0.000000] 3c40: c0452e84 c0455038 b7500794 00000000 edfff000 00000000 c2803d6c c2803c68
[    0.000000] 3c60: c181d3fc c0452e68 3fffffff 00000000 00000001 00000000 ffffffff 00000000
[    0.000000] 3c80: 0000006a c2800010 c2b7ca60 c2b7ca60 c2806df0 600000d3 c2b7cc60 0000005a
[    0.000000] 3ca0: 41b58ab3 c1681824 c181d2c4 c2803cb8 c02b4320 c02b239c c166b130 c2803dec
[    0.000000] 3cc0: 3fffffff 00000000 c2803d24 00000001 00000019 00000000 c166b1a4 c2690420
[    0.000000] 3ce0: 00000000 c166b130 c2803dec 00000000 00000000 c166b1d8 c2803d1c c2803d08
[    0.000000] 3d00: 00000001 00000000 c166b130 c2803dec c2803d4c c2803d20 c02b5a3c c02b43d8
[    0.000000] 3d20: c02b43fc c02b4144 c166b1a4 b75007ac c2806d48 c28a29e0 c2ba0ac0 00000000
[    0.000000] 3d40: c2803de4 00000001 00000000 b7c00000 ee1f1f88 c0006df0 c16e2060 b7bf1000
[    0.000000] 3d60: c2803d9c c2803d70 c180b930 c181d2d0 3fffffff 00000000 00000001 00000000
[    0.000000] 3d80: ffffffff c166bb78 2e00071f c2b784d8 c2803df4 c2803da0 c180babc c180b8b8
[    0.000000] 3da0: 2e00071f 00c00000 c2803dd4 bd000000 c28a2780 00002b76 c280a484 c0003010
[    0.000000] 3dc0: 00000000 bd000000 c2803e14 bd000000 b7000000 c28a29e0 c2ba0ac0 3e000000
[    0.000000] 3de0: 00000000 c166b1d8 c2803e14 c2803df8 c180bbf8 c180b944 bd000000 c2803e18
[    0.000000] 3e00: c0000000 00000000 c2803e6c c2803e18 c180beb0 c180bbac f0000000 00000000
[    0.000000] 3e20: 80000000 c166b1a4 c16e2060 c166b17c c16e2000 c18750d8 3e000000 00000000
[    0.000000] 3e40: c2803e6c c28a2780 c2fdcfa0 c1873a40 c0008000 e12fff1e c0226668 c18613a0
[    0.000000] 3e60: c2803fa4 c2803e70 c1805684 c180bc78 0000006c 30c5387d 00000003 00000001
[    0.000000] 3e80: 00000001 00000000 c16e2060 c2690420 185007d8 00000001 c2803f9c 00000000
[    0.000000] 3ea0: 420f00f3 c2806d40 c2803ecc c2803eb8 c2803fbc c2803f60 c1200980 c2803f9c
[    0.000000] 3ec0: 41b58ab3 c16696b0 c1804e3c c02b43d8 c02b4fd0 c02b59b0 00000000 b75007e4
[    0.000000] 3ee0: c2806d48 30c0387d ffffffff 0780e000 c2803f94 c2803f00 c02b4fd0 c02b59b0
[    0.000000] 3f00: c2803f74 00000000 c2803f34 c2803f18 c2803f34 c2803f20 c0298af8 c0454b8c
[    0.000000] 3f20: 41b58ab3 c166bb78 c02b4f40 c2803f38 c0320aac c0454b8c 00000000 c2865538
[    0.000000] 3f40: c2803f9c c28653e0 c1877270 c28655ac c28653f0 0780e000 c2b9b5c0 00000005
[    0.000000] 3f60: 00000000 ffffffff c2803f84 c2803f78 c0454bec 00000000 c2803fa4 00007000
[    0.000000] 3f80: c2806d48 30c0387d ffffffff 0780e000 420f00f3 c2806d40 c2803ff4 c2803fa8
[    0.000000] 3fa0: c1801010 c1804e48 c280a484 c0003010 00000001 bf000000 00000000 c1873a40
[    0.000000] 3fc0: 00000000 00000000 ffffffff c1800334 00000000 30c0387d ffffffff 0780e000
[    0.000000] 3fe0: 420f00f3 30c5387d 00000000 c2803ff8 00000000 c1800f94 00000000 00000000
[    0.000000] Backtrace: 
[    0.000000] [<c045502c>] (check_memory_region) from [<c0452e84>] (memset+0x28/0x44)
[    0.000000]  r10:00000000 r9:00001000 r8:c2806d48 r7:00000000 r6:00000000 r5:edfff000
[    0.000000]  r4:00001000 r3:c181d3fc
[    0.000000] [<c0452e5c>] (memset) from [<c181d3fc>] (memblock_alloc_try_nid+0x138/0x170)
[    0.000000]  r7:00000000 r6:edfff000 r5:00000000 r4:b7500794
[    0.000000] [<c181d2c4>] (memblock_alloc_try_nid) from [<c180b930>] (kasan_alloc_block.constprop.1+0x84/0x8c)
[    0.000000]  r10:b7bf1000 r9:c16e2060 r8:c0006df0 r7:ee1f1f88 r6:b7c00000 r5:00000000
[    0.000000]  r4:00000001
[    0.000000] [<c180b8ac>] (kasan_alloc_block.constprop.1) from [<c180babc>] (kasan_pgd_populate+0x184/0x268)
[    0.000000]  r5:c2b784d8 r4:2e00071f
[    0.000000] [<c180b938>] (kasan_pgd_populate) from [<c180bbf8>] (create_mapping+0x58/0x64)
[    0.000000]  r10:c166b1d8 r9:00000000 r8:3e000000 r7:c2ba0ac0 r6:c28a29e0 r5:b7000000
[    0.000000]  r4:bd000000
[    0.000000] [<c180bba0>] (create_mapping) from [<c180beb0>] (kasan_init+0x244/0x394)
[    0.000000]  r5:00000000 r4:c0000000
[    0.000000] [<c180bc6c>] (kasan_init) from [<c1805684>] (setup_arch+0x848/0x1048)
[    0.000000]  r10:c18613a0 r9:c0226668 r8:e12fff1e r7:c0008000 r6:c1873a40 r5:c2fdcfa0
[    0.000000]  r4:c28a2780
[    0.000000] [<c1804e3c>] (setup_arch) from [<c1801010>] (start_kernel+0x88/0x3e4)
[    0.000000]  r10:c2806d40 r9:420f00f3 r8:0780e000 r7:ffffffff r6:30c0387d r5:c2806d48
[    0.000000]  r4:00007000
[    0.000000] [<c1800f88>] (start_kernel) from [<00000000>] (0x0)
[    0.000000]  r10:30c5387d r9:420f00f3 r8:0780e000 r7:ffffffff r6:30c0387d r5:00000000
[    0.000000]  r4:c1800334
[    0.000000] Code: da00001a e21c4007 1a000028 e1a0e1ce (e1cc40d0) 
[    0.000000] random: get_random_bytes called from print_oops_end_marker+0x30/0x5c with crng_init=0
[    0.000000] ---[ end trace 692b945dc0693f87 ]---
[    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.9.0-rc7-g79c212fcfb1d (fainelli@fainelli-desktop) (arm-linux-gcc (GCC) 8.3.0, GNU ld (GNU Binutils) 2.32) #6 SMP Thu Oct 1 12:09:58 PDT 2020
[    0.000000] CPU: ARMv7 Processor [420f00f3] revision 3 (ARMv7), cr=30c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: BCM97445VMS
[    0.000000] printk: bootconsole [earlycon0] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 16 MiB at 0x00000000bec00000
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000002fffffff]
[    0.000000]   Normal   empty
[    0.000000]   HighMem  [mem 0x0000000030000000-0x00000000bfffefff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000003dffffff]
[    0.000000]   node   0: [mem 0x0000000040000000-0x00000000bfffefff]
[    0.000000] Zeroed struct page in unavailable ranges: 1 pages
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x00000000bfffefff]
[    0.000000] kasan: Truncate memory block c0000000-fe000000
[    0.000000]  to c0000000-f0000000
[    0.000000] kasan: Mapping kernel virtual memory block: c0000000-f0000000 at shadow: b7000000-bd000000
[    0.000000] 8<--- cut here ---
[    0.000000] Unable to handle kernel paging request at virtual address bc9ffe00
[    0.000000] pgd = (ptrval)
[    0.000000] [bc9ffe00] *pgd=80000000006003, *pmd=00000000
[    0.000000] Internal error: Oops: 206 [#1] SMP ARM
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.9.0-rc7-g79c212fcfb1d #6
[    0.000000] Hardware name: Broadcom STB (Flattened Device Tree)
[    0.000000] PC is at check_memory_region+0x54/0x1c8
[    0.000000] LR is at 0x40
[    0.000000] pc : [<c0455080>]    lr : [<00000040>]    psr: 600000d3
[    0.000000] sp : c2803c18  ip : bc9ffe00  fp : c2803c44
[    0.000000] r10: 00000000  r9 : 00001000  r8 : bca00000
[    0.000000] r7 : bc9fffff  r6 : ecffffff  r5 : ecfff000  r4 : 00000000
[    0.000000] r3 : c181d3fc  r2 : 00000001  r1 : 00001000  r0 : ecfff000
[    0.000000] Flags: nZCv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment user
[    0.000000] Control: 30c5387d  Table: 01877100  DAC: fffffffd
[    0.000000] Process swapper (pid: 0, stack limit = 0x(ptrval))
[    0.000000] Stack: (0xc2803c18 to 0xc2804000)
[    0.000000] 3c00:                                                       c181d3fc 00001000
[    0.000000] 3c20: ecfff000 00000000 00000000 c2806d48 00001000 00000000 c2803c64 c2803c48
[    0.000000] 3c40: c0452e84 c0455038 b7500794 00000000 ecfff000 00000000 c2803d6c c2803c68
[    0.000000] 3c60: c181d3fc c0452e68 3fffffff 00000000 00000001 00000000 ffffffff 00000000
[    0.000000] 3c80: 0000006a c2800010 c2b7ca60 c2b7ca60 c2806df0 600000d3 c2b7cc60 0000005a
[    0.000000] 3ca0: 41b58ab3 c1681824 c181d2c4 c2803cb8 c02b4320 c02b239c c166b130 c2803dec
[    0.000000] 3cc0: 3fffffff 00000000 c2803d24 00000001 00000019 00000000 c166b1a4 c2690420
[    0.000000] 3ce0: 00000000 c166b130 c2803dec 00000000 00000000 c166b1d8 c2803d1c c2803d08
[    0.000000] 3d00: 00000001 00000000 c166b130 c2803dec c2803d4c c2803d20 c02b5a3c c02b43d8
[    0.000000] 3d20: c02b43fc c02b4144 c166b1a4 b75007ac c2806d48 c28a29e0 c2ba0ac0 00000000
[    0.000000] 3d40: c2803de4 00000001 00000000 b8200000 ed1eef70 c0006e08 c16e2060 b81ee000
[    0.000000] 3d60: c2803d9c c2803d70 c180b930 c181d2d0 3fffffff 00000000 00000001 00000000
[    0.000000] 3d80: ffffffff c166bb78 2d00071f c2b784d8 c2803df4 c2803da0 c180babc c180b8b8
[    0.000000] 3da0: 2d00071f 00c00000 c2803dd4 bd000000 c28a2780 00002b76 c280a484 c0003010
[    0.000000] 3dc0: 00000000 bd000000 c2803e14 bd000000 b7000000 c28a29e0 c2ba0ac0 3e000000
[    0.000000] 3de0: 00000000 c166b1d8 c2803e14 c2803df8 c180bbf8 c180b944 bd000000 c2803e18
[    0.000000] 3e00: c0000000 00000000 c2803e6c c2803e18 c180beb0 c180bbac f0000000 00000000
[    0.000000] 3e20: 40000000 c166b1a4 c16e2060 c166b17c c16e2000 c18750d8 3e000000 00000000
[    0.000000] 3e40: c2803e6c c28a2780 c2fdcfa0 c1873a40 c0008000 e12fff1e c0226668 c18613a0
[    0.000000] 3e60: c2803fa4 c2803e70 c1805684 c180bc78 0000006c 30c5387d 00000003 00000001
[    0.000000] 3e80: 00000001 00000000 c16e2060 c2690420 185007d8 00000001 c2803f9c 00000000
[    0.000000] 3ea0: 420f00f3 c2806d40 c2803ecc c2803eb8 c2803fbc c2803f60 c1200980 c2803f9c
[    0.000000] 3ec0: 41b58ab3 c16696b0 c1804e3c c02b43d8 c02b4fd0 c02b59b0 00000000 b75007e4
[    0.000000] 3ee0: c2806d48 30c0387d ffffffff 07723000 c2803f94 c2803f00 c02b4fd0 c02b59b0
[    0.000000] 3f00: c2803f74 00000000 c2803f34 c2803f18 c2803f34 c2803f20 c0298af8 c0454b8c
[    0.000000] 3f20: 41b58ab3 c166bb78 c02b4f40 c2803f38 c0320aac c0454b8c 00000000 c2865538
[    0.000000] 3f40: c2803f9c c28653e0 c1877270 c28655ac c28653f0 07723000 c2b9b5c0 00000005
[    0.000000] 3f60: 00000000 ffffffff c2803f84 c2803f78 c0454bec 00000000 c2803fa4 00007000
[    0.000000] 3f80: c2806d48 30c0387d ffffffff 07723000 420f00f3 c2806d40 c2803ff4 c2803fa8
[    0.000000] 3fa0: c1801010 c1804e48 c280a484 c0003010 00000001 bf000000 00000000 c1873a40
[    0.000000] 3fc0: 00000000 00000000 ffffffff c1800334 00000000 30c0387d ffffffff 07723000
[    0.000000] 3fe0: 420f00f3 30c5387d 00000000 c2803ff8 00000000 c1800f94 00000000 00000000
[    0.000000] Backtrace: 
[    0.000000] [<c045502c>] (check_memory_region) from [<c0452e84>] (memset+0x28/0x44)
[    0.000000]  r10:00000000 r9:00001000 r8:c2806d48 r7:00000000 r6:00000000 r5:ecfff000
[    0.000000]  r4:00001000 r3:c181d3fc
[    0.000000] [<c0452e5c>] (memset) from [<c181d3fc>] (memblock_alloc_try_nid+0x138/0x170)
[    0.000000]  r7:00000000 r6:ecfff000 r5:00000000 r4:b7500794
[    0.000000] [<c181d2c4>] (memblock_alloc_try_nid) from [<c180b930>] (kasan_alloc_block.constprop.1+0x84/0x8c)
[    0.000000]  r10:b81ee000 r9:c16e2060 r8:c0006e08 r7:ed1eef70 r6:b8200000 r5:00000000
[    0.000000]  r4:00000001
[    0.000000] [<c180b8ac>] (kasan_alloc_block.constprop.1) from [<c180babc>] (kasan_pgd_populate+0x184/0x268)
[    0.000000]  r5:c2b784d8 r4:2d00071f
[    0.000000] [<c180b938>] (kasan_pgd_populate) from [<c180bbf8>] (create_mapping+0x58/0x64)
[    0.000000]  r10:c166b1d8 r9:00000000 r8:3e000000 r7:c2ba0ac0 r6:c28a29e0 r5:b7000000
[    0.000000]  r4:bd000000
[    0.000000] [<c180bba0>] (create_mapping) from [<c180beb0>] (kasan_init+0x244/0x394)
[    0.000000]  r5:00000000 r4:c0000000
[    0.000000] [<c180bc6c>] (kasan_init) from [<c1805684>] (setup_arch+0x848/0x1048)
[    0.000000]  r10:c18613a0 r9:c0226668 r8:e12fff1e r7:c0008000 r6:c1873a40 r5:c2fdcfa0
[    0.000000]  r4:c28a2780
[    0.000000] [<c1804e3c>] (setup_arch) from [<c1801010>] (start_kernel+0x88/0x3e4)
[    0.000000]  r10:c2806d40 r9:420f00f3 r8:07723000 r7:ffffffff r6:30c0387d r5:c2806d48
[    0.000000]  r4:00007000
[    0.000000] [<c1800f88>] (start_kernel) from [<00000000>] (0x0)
[    0.000000]  r10:30c5387d r9:420f00f3 r8:07723000 r7:ffffffff r6:30c0387d r5:00000000
[    0.000000]  r4:c1800334
[    0.000000] Code: da00001a e21c4007 1a000028 e1a0e1ce (e1cc40d0) 
[    0.000000] random: get_random_bytes called from print_oops_end_marker+0x30/0x5c with crng_init=0
[    0.000000] ---[ end trace 8c76059b8bd5784b ]---
[    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.9.0-rc7-g79c212fcfb1d (fainelli@fainelli-desktop) (arm-linux-gcc (GCC) 8.3.0, GNU ld (GNU Binutils) 2.32) #6 SMP Thu Oct 1 12:09:58 PDT 2020
[    0.000000] CPU: ARMv7 Processor [420f00f2] revision 2 (ARMv7), cr=30c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: BCM974371SV
[    0.000000] printk: bootconsole [earlycon0] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 16 MiB at 0x000000003ec00000
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000002fffffff]
[    0.000000]   Normal   empty
[    0.000000]   HighMem  [mem 0x0000000030000000-0x000000003fffefff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000003fffefff]
[    0.000000] Zeroed struct page in unavailable ranges: 1 pages
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000003fffefff]
[    0.000000] kasan: Truncate memory block c0000000-fffff000
[    0.000000]  to c0000000-f0000000
[    0.000000] kasan: Mapping kernel virtual memory block: c0000000-f0000000 at shadow: b7000000-bd000000
[    0.000000] 8<--- cut here ---
[    0.000000] Unable to handle kernel paging request at virtual address bcdffe00
[    0.000000] pgd = (ptrval)
[    0.000000] [bcdffe00] *pgd=80000000006003, *pmd=00000000
[    0.000000] Internal error: Oops: 206 [#1] SMP ARM
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.9.0-rc7-g79c212fcfb1d #6
[    0.000000] Hardware name: Broadcom STB (Flattened Device Tree)
[    0.000000] PC is at check_memory_region+0x54/0x1c8
[    0.000000] LR is at 0x40
[    0.000000] pc : [<c0455080>]    lr : [<00000040>]    psr: 600000d3
[    0.000000] sp : c2803c18  ip : bcdffe00  fp : c2803c44
[    0.000000] r10: 00000000  r9 : 00001000  r8 : bce00000
[    0.000000] r7 : bcdfffff  r6 : eeffffff  r5 : eefff000  r4 : 00000000
[    0.000000] r3 : c181d3fc  r2 : 00000001  r1 : 00001000  r0 : eefff000
[    0.000000] Flags: nZCv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment user
[    0.000000] Control: 30c5387d  Table: 01877100  DAC: fffffffd
[    0.000000] Process swapper (pid: 0, stack limit = 0x(ptrval))
[    0.000000] Stack: (0xc2803c18 to 0xc2804000)
[    0.000000] 3c00:                                                       c181d3fc 00001000
[    0.000000] 3c20: eefff000 00000000 00000000 c2806d48 00001000 00000000 c2803c64 c2803c48
[    0.000000] 3c40: c0452e84 c0455038 b7500794 00000000 eefff000 00000000 c2803d6c c2803c68
[    0.000000] 3c60: c181d3fc c0452e68 3fffffff 00000000 00000001 00000000 ffffffff 00000000
[    0.000000] 3c80: 0000006a c2800010 c2b7ca60 c2b7ca60 c2806df0 600000d3 c2b7cc60 0000005a
[    0.000000] 3ca0: 41b58ab3 c1681824 c181d2c4 c2803cb8 c02b4320 c02b239c c166b130 c2803dec
[    0.000000] 3cc0: 3fffffff 00000000 c2803d24 00000001 00000018 00000000 c166b1a4 c2690420
[    0.000000] 3ce0: 00000000 c166b130 c2803dec 00000000 00000000 c166b1d8 c2803d1c c2803d08
[    0.000000] 3d00: 00000001 00000000 c166b130 c2803dec c2803d4c c2803d20 c02b5a3c c02b43d8
[    0.000000] 3d20: c02b43fc c02b4144 c166b1a4 b75007ac c2806d48 c28a29e0 c2ba0ac0 00000000
[    0.000000] 3d40: c2803de4 00000001 00000000 b7600000 ef474fa0 c0006dd8 c16e2060 b75f4000
[    0.000000] 3d60: c2803d9c c2803d70 c180b930 c181d2d0 3fffffff 00000000 00000001 00000000
[    0.000000] 3d80: ffffffff c166bb78 2f00071f c2b784d8 c2803df4 c2803da0 c180babc c180b8b8
[    0.000000] 3da0: 2f00071f 00c00000 c2803dd4 bd000000 c28a2780 00002b76 c280a484 c0003010
[    0.000000] 3dc0: 00000000 bd000000 c2803e14 bd000000 b7000000 c28a29e0 c2ba0ac0 3ffff000
[    0.000000] 3de0: 00000000 c166b1d8 c2803e14 c2803df8 c180bbf8 c180b944 bd000000 c2803e18
[    0.000000] 3e00: c0000000 00000000 c2803e6c c2803e18 c180beb0 c180bbac f0000000 00000000
[    0.000000] 3e20: 00000000 c166b1a4 c16e2060 c166b17c c16e2000 c18750d8 3ffff000 00000000
[    0.000000] 3e40: c2803e6c c28a2780 c2fdcfa0 c1873a40 c0008000 e12fff1e c0226668 c18613a0
[    0.000000] 3e60: c2803fa4 c2803e70 c1805684 c180bc78 0000006c 30c5387d 00000003 00000001
[    0.000000] 3e80: 00000001 00000000 c16e2060 c2690420 185007d8 00000001 c2803f9c 00000000
[    0.000000] 3ea0: 420f00f2 c2806d40 c2803ecc c2803eb8 c2803fbc c2803f60 c1200980 c2803f9c
[    0.000000] 3ec0: 41b58ab3 c16696b0 c1804e3c c02b43d8 c02b4fd0 c02b59b0 00000000 b75007e4
[    0.000000] 3ee0: c2806d48 30c0387d ffffffff 07819000 c2803f94 c2803f00 c02b4fd0 c02b59b0
[    0.000000] 3f00: c2803f74 00000000 c2803f34 c2803f18 c2803f34 c2803f20 c0298af8 c0454b8c
[    0.000000] 3f20: 41b58ab3 c166bb78 c02b4f40 c2803f38 c0320aac c0454b8c 00000000 c2865538
[    0.000000] 3f40: c2803f9c c28653e0 c1877270 c28655ac c28653f0 07819000 c2b9b5c0 00000005
[    0.000000] 3f60: 00000000 ffffffff c2803f84 c2803f78 c0454bec 00000000 c2803fa4 00007000
[    0.000000] 3f80: c2806d48 30c0387d ffffffff 07819000 420f00f2 c2806d40 c2803ff4 c2803fa8
[    0.000000] 3fa0: c1801010 c1804e48 c280a484 c0003010 00000001 bf000000 00000000 c1873a40
[    0.000000] 3fc0: 00000000 00000000 ffffffff c1800334 00000000 30c0387d ffffffff 07819000
[    0.000000] 3fe0: 420f00f2 30c5387d 00000000 c2803ff8 00000000 c1800f94 00000000 00000000
[    0.000000] Backtrace: 
[    0.000000] [<c045502c>] (check_memory_region) from [<c0452e84>] (memset+0x28/0x44)
[    0.000000]  r10:00000000 r9:00001000 r8:c2806d48 r7:00000000 r6:00000000 r5:eefff000
[    0.000000]  r4:00001000 r3:c181d3fc
[    0.000000] [<c0452e5c>] (memset) from [<c181d3fc>] (memblock_alloc_try_nid+0x138/0x170)
[    0.000000]  r7:00000000 r6:eefff000 r5:00000000 r4:b7500794
[    0.000000] [<c181d2c4>] (memblock_alloc_try_nid) from [<c180b930>] (kasan_alloc_block.constprop.1+0x84/0x8c)
[    0.000000]  r10:b75f4000 r9:c16e2060 r8:c0006dd8 r7:ef474fa0 r6:b7600000 r5:00000000
[    0.000000]  r4:00000001
[    0.000000] [<c180b8ac>] (kasan_alloc_block.constprop.1) from [<c180babc>] (kasan_pgd_populate+0x184/0x268)
[    0.000000]  r5:c2b784d8 r4:2f00071f
[    0.000000] [<c180b938>] (kasan_pgd_populate) from [<c180bbf8>] (create_mapping+0x58/0x64)
[    0.000000]  r10:c166b1d8 r9:00000000 r8:3ffff000 r7:c2ba0ac0 r6:c28a29e0 r5:b7000000
[    0.000000]  r4:bd000000
[    0.000000] [<c180bba0>] (create_mapping) from [<c180beb0>] (kasan_init+0x244/0x394)
[    0.000000]  r5:00000000 r4:c0000000
[    0.000000] [<c180bc6c>] (kasan_init) from [<c1805684>] (setup_arch+0x848/0x1048)
[    0.000000]  r10:c18613a0 r9:c0226668 r8:e12fff1e r7:c0008000 r6:c1873a40 r5:c2fdcfa0
[    0.000000]  r4:c28a2780
[    0.000000] [<c1804e3c>] (setup_arch) from [<c1801010>] (start_kernel+0x88/0x3e4)
[    0.000000]  r10:c2806d40 r9:420f00f2 r8:07819000 r7:ffffffff r6:30c0387d r5:c2806d48
[    0.000000]  r4:00007000
[    0.000000] [<c1800f88>] (start_kernel) from [<00000000>] (0x0)
[    0.000000]  r10:30c5387d r9:420f00f2 r8:07819000 r7:ffffffff r6:30c0387d r5:00000000
[    0.000000]  r4:c1800334
[    0.000000] Code: da00001a e21c4007 1a000028 e1a0e1ce (e1cc40d0) 
[    0.000000] random: get_random_bytes called from print_oops_end_marker+0x30/0x5c with crng_init=0
[    0.000000] ---[ end trace 0000000000000000 ]---
[    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.9.0-rc7-g79c212fcfb1d (fainelli@fainelli-desktop) (arm-linux-gcc (GCC) 8.3.0, GNU ld (GNU Binutils) 2.32) #6 SMP Thu Oct 1 12:09:58 PDT 2020
[    0.000000] CPU: ARMv7 Processor [420f00f3] revision 3 (ARMv7), cr=30c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: BCM97449SSV_4GB
[    0.000000] printk: bootconsole [earlycon0] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 16 MiB at 0x00000000bec00000
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000002fffffff]
[    0.000000]   Normal   empty
[    0.000000]   HighMem  [mem 0x0000000030000000-0x000000033fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000007dffffff]
[    0.000000]   node   0: [mem 0x0000000080000000-0x00000000bfffefff]
[    0.000000]   node   0: [mem 0x0000000300000000-0x000000033fffffff]
[    0.000000] Zeroed struct page in unavailable ranges: 1 pages
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000033fffffff]
[    0.000000] kasan: Truncate memory block c0000000-3e000000
[    0.000000]  to c0000000-f0000000
[    0.000000] kasan: Mapping kernel virtual memory block: c0000000-f0000000 at shadow: b7000000-bd000000
[    0.000000] 8<--- cut here ---
[    0.000000] Unable to handle kernel paging request at virtual address bc9ffe00
[    0.000000] pgd = (ptrval)
[    0.000000] [bc9ffe00] *pgd=80000000006003, *pmd=00000000
[    0.000000] Internal error: Oops: 206 [#1] SMP ARM
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.9.0-rc7-g79c212fcfb1d #6
[    0.000000] Hardware name: Broadcom STB (Flattened Device Tree)
[    0.000000] PC is at check_memory_region+0x54/0x1c8
[    0.000000] LR is at 0x40
[    0.000000] pc : [<c0455080>]    lr : [<00000040>]    psr: 600000d3
[    0.000000] sp : c2803c18  ip : bc9ffe00  fp : c2803c44
[    0.000000] r10: 00000000  r9 : 00001000  r8 : bca00000
[    0.000000] r7 : bc9fffff  r6 : ecffffff  r5 : ecfff000  r4 : 00000000
[    0.000000] r3 : c181d3fc  r2 : 00000001  r1 : 00001000  r0 : ecfff000
[    0.000000] Flags: nZCv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment user
[    0.000000] Control: 30c5387d  Table: 01877100  DAC: fffffffd
[    0.000000] Process swapper (pid: 0, stack limit = 0x(ptrval))
[    0.000000] Stack: (0xc2803c18 to 0xc2804000)
[    0.000000] 3c00:                                                       c181d3fc 00001000
[    0.000000] 3c20: ecfff000 00000000 00000000 c2806d48 00001000 00000000 c2803c64 c2803c48
[    0.000000] 3c40: c0452e84 c0455038 b7500794 00000000 ecfff000 00000000 c2803d6c c2803c68
[    0.000000] 3c60: c181d3fc c0452e68 3fffffff 00000000 00000001 00000000 ffffffff 00000000
[    0.000000] 3c80: 0000006a c2800010 c2b7ca60 c2b7ca60 c2806df0 600000d3 c2b7cc60 0000005a
[    0.000000] 3ca0: 41b58ab3 c1681824 c181d2c4 c2803cb8 c02b4320 c02b239c c166b130 c2803dec
[    0.000000] 3cc0: 3fffffff 00000000 c2803d24 00000001 0000001a 00000000 c166b1a4 c2690420
[    0.000000] 3ce0: 00000000 c166b130 c2803dec 00000000 00000000 c166b1d8 c2803d1c c2803d08
[    0.000000] 3d00: 00000001 00000000 c166b130 c2803dec c2803d4c c2803d20 c02b5a3c c02b43d8
[    0.000000] 3d20: c02b43fc c02b4144 c166b1a4 b75007ac c2806d48 c28a29e0 c2ba0ac0 00000000
[    0.000000] 3d40: c2803de4 00000001 00000000 b7800000 ed1f3f98 c0006de0 c16e2060 b77f3000
[    0.000000] 3d60: c2803d9c c2803d70 c180b930 c181d2d0 3fffffff 00000000 00000001 00000000
[    0.000000] 3d80: ffffffff c166bb78 2d00071f c2b784d8 c2803df4 c2803da0 c180babc c180b8b8
[    0.000000] 3da0: 2d00071f 00c00000 c2803dd4 bd000000 c28a2780 00002b76 c280a484 c0003010
[    0.000000] 3dc0: 00000000 bd000000 c2803e14 bd000000 b7000000 c28a29e0 c2ba0ac0 7e000000
[    0.000000] 3de0: 00000000 c166b1d8 c2803e14 c2803df8 c180bbf8 c180b944 bd000000 c2803e18
[    0.000000] 3e00: c0000000 00000000 c2803e6c c2803e18 c180beb0 c180bbac f0000000 00000000
[    0.000000] 3e20: 80000000 c166b1a4 c16e2060 c166b17c c16e2000 c18750d8 7e000000 00000000
[    0.000000] 3e40: c2803e6c c28a2780 c2fdcfa0 c1873a40 c0008000 e12fff1e c0226668 c18613a0
[    0.000000] 3e60: c2803fa4 c2803e70 c1805684 c180bc78 0000006c 30c5387d 00000003 00000001
[    0.000000] 3e80: 00000001 00000000 c16e2060 c2690420 185007d8 00000001 c2803f9c 00000000
[    0.000000] 3ea0: 420f00f3 c2806d40 c2803ecc c2803eb8 c2803fbc c2803f60 c1200980 c2803f9c
[    0.000000] 3ec0: 41b58ab3 c16696b0 c1804e3c c02b43d8 c02b4fd0 c02b59b0 00000000 b75007e4
[    0.000000] 3ee0: c2806d48 30c0387d ffffffff 07822000 c2803f94 c2803f00 c02b4fd0 c02b59b0
[    0.000000] 3f00: c2803f74 00000000 c2803f34 c2803f18 c2803f34 c2803f20 c0298af8 c0454b8c
[    0.000000] 3f20: 41b58ab3 c166bb78 c02b4f40 c2803f38 c0320aac c0454b8c 00000000 c2865538
[    0.000000] 3f40: c2803f9c c28653e0 c1877270 c28655ac c28653f0 07822000 c2b9b5c0 00000005
[    0.000000] 3f60: 00000000 ffffffff c2803f84 c2803f78 c0454bec 00000000 c2803fa4 00007000
[    0.000000] 3f80: c2806d48 30c0387d ffffffff 07822000 420f00f3 c2806d40 c2803ff4 c2803fa8
[    0.000000] 3fa0: c1801010 c1804e48 c280a484 c0003010 00000001 bf000000 00000000 c1873a40
[    0.000000] 3fc0: 00000000 00000000 ffffffff c1800334 00000000 30c0387d ffffffff 07822000
[    0.000000] 3fe0: 420f00f3 30c5387d 00000000 c2803ff8 00000000 c1800f94 00000000 00000000
[    0.000000] Backtrace: 
[    0.000000] [<c045502c>] (check_memory_region) from [<c0452e84>] (memset+0x28/0x44)
[    0.000000]  r10:00000000 r9:00001000 r8:c2806d48 r7:00000000 r6:00000000 r5:ecfff000
[    0.000000]  r4:00001000 r3:c181d3fc
[    0.000000] [<c0452e5c>] (memset) from [<c181d3fc>] (memblock_alloc_try_nid+0x138/0x170)
[    0.000000]  r7:00000000 r6:ecfff000 r5:00000000 r4:b7500794
[    0.000000] [<c181d2c4>] (memblock_alloc_try_nid) from [<c180b930>] (kasan_alloc_block.constprop.1+0x84/0x8c)
[    0.000000]  r10:b77f3000 r9:c16e2060 r8:c0006de0 r7:ed1f3f98 r6:b7800000 r5:00000000
[    0.000000]  r4:00000001
[    0.000000] [<c180b8ac>] (kasan_alloc_block.constprop.1) from [<c180babc>] (kasan_pgd_populate+0x184/0x268)
[    0.000000]  r5:c2b784d8 r4:2d00071f
[    0.000000] [<c180b938>] (kasan_pgd_populate) from [<c180bbf8>] (create_mapping+0x58/0x64)
[    0.000000]  r10:c166b1d8 r9:00000000 r8:7e000000 r7:c2ba0ac0 r6:c28a29e0 r5:b7000000
[    0.000000]  r4:bd000000
[    0.000000] [<c180bba0>] (create_mapping) from [<c180beb0>] (kasan_init+0x244/0x394)
[    0.000000]  r5:00000000 r4:c0000000
[    0.000000] [<c180bc6c>] (kasan_init) from [<c1805684>] (setup_arch+0x848/0x1048)
[    0.000000]  r10:c18613a0 r9:c0226668 r8:e12fff1e r7:c0008000 r6:c1873a40 r5:c2fdcfa0
[    0.000000]  r4:c28a2780
[    0.000000] [<c1804e3c>] (setup_arch) from [<c1801010>] (start_kernel+0x88/0x3e4)
[    0.000000]  r10:c2806d40 r9:420f00f3 r8:07822000 r7:ffffffff r6:30c0387d r5:c2806d48
[    0.000000]  r4:00007000
[    0.000000] [<c1800f88>] (start_kernel) from [<00000000>] (0x0)
[    0.000000]  r10:30c5387d r9:420f00f3 r8:07822000 r7:ffffffff r6:30c0387d r5:00000000
[    0.000000]  r4:c1800334
[    0.000000] Code: da00001a e21c4007 1a000028 e1a0e1ce (e1cc40d0) 
[    0.000000] random: get_random_bytes called from print_oops_end_marker+0x30/0x5c with crng_init=0
[    0.000000] ---[ end trace 53c87bc3ccbdcda0 ]---
[    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#24 lore raw
Quoted 8 lines · Florian Fainelli

The physical memory map looks like this:

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

Do any of the platforms you use for testing have a similar memory map? Could you try to contrive a QEMU machine to have something similar in

Nothing with the DRAM extension, no. I do test on a bunch of platforms that have the RAM at starting at 0x0.

Quoted 1 line

case that helps reproducing these failures?

Are these Broadcom chips hard to get for me? If it is a reference design I can certainly afford to just buy one. If there is a hackable product I can buy and pry apart and play with just point me at it and I'll get it.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#25 lore raw
Quoted 11 lines · Linus Walleij
Quoted 8 lines · Florian Fainelli

The physical memory map looks like this:

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

Do any of the platforms you use for testing have a similar memory map? Could you try to contrive a QEMU machine to have something similar in

Quoted 6 lines

Nothing with the DRAM extension, no. I do test on a bunch of platforms that have the RAM at starting at 0x0.

Quoted 1 line

case that helps reproducing these failures?

Are these Broadcom chips hard to get for me?

Yes they are hard for you to get.

Quoted 4 lines

If it is a reference
design I can certainly afford to just buy one. If there is a hackable product I can buy and pry apart and play with just point me at it and I'll get it.

Testing anything or asking me to sprinkle debug would probably be easier. Have you got your hands on a Raspberry Pi 4? That one would be quite similar to one of our Broadcom STB chips (7211) and I would be curious to know if it even works there.

Signature · 6 lines
Florian

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#26 lore raw
In reply to Florian Fainelli
Quoted 5 lines · Florian Fainelli

The physical memory map looks like this:

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

So plenty of highmem, and then with LPAE you have theoretically 12 GB of RAM. In an ARM32 system?

I think Arnd is gonna love this system for our highmem experiments if that is something that is going to happen often... Is that DRAM extension often mounted and used?

Quoted 3 lines
Quoted 1 line

Are these Broadcom chips hard to get for me?

Yes they are hard for you to get.

Isn't one of them this beast:
https://www.ebay.com/c/502488121

Or do you mean that this device is locked down like a fortress and not really hackable? There seems to be a UART on the back and all.

Quoted 3 lines

Have you got your hands on a Raspberry Pi 4? That one would be quite similar to one of our Broadcom STB chips (7211) and I would be curious to know if it even works there.

Pi 3 and 4 are 64bit Cortex A53 and A72 CPUs IIUC, so they are in arch/arm64 and does not have this problem.

Your systems are curiously interesting, there is copious highmem etc.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#27 lore raw
Quoted 9 lines · Linus Walleij
Quoted 3 lines · Florian Fainelli

Have you got your hands on a Raspberry Pi 4? That one would be quite similar to one of our Broadcom STB chips (7211) and I would be curious to know if it even works there.

Pi 3 and 4 are 64bit Cortex A53 and A72 CPUs IIUC, so they are in arch/arm64 and does not have this problem.

They should be good enough for testing though -- Raspberry Pi 4 can run both 32-bit or 64-bit kernels.

Arnd

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#28 lore raw
In reply to Linus Walleij
Quoted 16 lines · Linus Walleij
Quoted 5 lines · Florian Fainelli

The physical memory map looks like this:

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

So plenty of highmem, and then with LPAE you have theoretically 12 GB of RAM. In an ARM32 system?

I think Arnd is gonna love this system for our highmem experiments if that is something that is going to happen often... Is that DRAM extension often mounted and used?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Are these Broadcom chips hard to get for me?

Yes they are hard for you to get.

Isn't one of them this beast:
https://www.ebay.com/c/502488121

What the heck... someone must have been dumpster diving or been given a gift :) This one is a BCM97425 which is MIPS-based.

Quoted 4 lines

Or do you mean that this device is locked down like a fortress and not really hackable? There seems to be a UART on the back and all.

The devices are locked down and we don't send devices unless you are a customer. Since our business unit never signed up for Linaro we do not have an exchange program and every attempt in the past to send devices has been met with rejection. I did manage to get Kevin Hilman a couple of devices that we could consider using.

Quoted 10 lines
Quoted 4 lines

Have you got your hands on a Raspberry Pi 4? That one would be quite similar to one of our Broadcom STB chips (7211) and I would be curious to know if it even works there.

Pi 3 and 4 are 64bit Cortex A53 and A72 CPUs IIUC, so they are in arch/arm64 and does not have this problem.

Your systems are curiously interesting, there is copious highmem etc.

Yes, yes they are curious beasts :)

Signature · 6 lines
Florian

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#29 lore raw
In reply to Florian Fainelli
Quoted 30 lines · Florian Fainelli
Quoted 14 lines · Linus Walleij

This is the 14th iteration of KASan for ARM/Aarch32.

I have added one patch in the beginning of the series to fix the issue when the DTB (often attached DTB) ends up in lowmem. It also amends ARM to copy the device tree instead of just unflattening it and using it from where it is.

This fixes my particular issue on the Qualcomm APQ8060 and I hope it may also solve Florian's issue and what Ard has been seeing. If you inspect patch 1/6 you can see what has been going on for me. My hypothesis about what was going on was mostly right.

Quoted 5 lines

You are encouraged to test this patch set to find memory out of bounds bugs with ARM32 platforms and drivers.

There is a git branch you can pull in:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=kasan

It does appear to be slight better, although all platforms that I have where memory starts at physical address 0 cannot boot, attached logs which are all more or less the same.

The physical memory map looks like this:

Quoted 8 lines

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

Do any of the platforms you use for testing have a similar memory map? Could you try to contrive a QEMU machine to have something similar in case that helps reproducing these failures?

I am getting very similar failures on a Raspberry Pi4 booting in 32-bit mode from U-boot+EFI

Full log attached.

I will try to dig a bit deeper.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#30 lore raw
Quoted 41 lines · Ard Biesheuvel
Quoted 30 lines · Florian Fainelli
Quoted 14 lines · Linus Walleij

This is the 14th iteration of KASan for ARM/Aarch32.

I have added one patch in the beginning of the series to fix the issue when the DTB (often attached DTB) ends up in lowmem. It also amends ARM to copy the device tree instead of just unflattening it and using it from where it is.

This fixes my particular issue on the Qualcomm APQ8060 and I hope it may also solve Florian's issue and what Ard has been seeing. If you inspect patch 1/6 you can see what has been going on for me. My hypothesis about what was going on was mostly right.

Quoted 5 lines

You are encouraged to test this patch set to find memory out of bounds bugs with ARM32 platforms and drivers.

There is a git branch you can pull in:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=kasan

It does appear to be slight better, although all platforms that I have where memory starts at physical address 0 cannot boot, attached logs which are all more or less the same.

The physical memory map looks like this:

Quoted 8 lines

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

Do any of the platforms you use for testing have a similar memory map? Could you try to contrive a QEMU machine to have something similar in case that helps reproducing these failures?

Quoted 6 lines

I am getting very similar failures on a Raspberry Pi4 booting in 32-bit mode from U-boot+EFI

Full log attached.

I will try to dig a bit deeper.

OK, one obvious issue with the code as-is is that the following routine

static __init void *kasan_alloc_block(size_t size)
{
return memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS),

                                MEMBLOCK_ALLOC_KASAN, NUMA_NO_NODE);
}

is called after the early shadow is unmapped, but before the permanent shadow is in place. memblock_alloc_try_nid() clears the newly allocated memory using memset(), which checks the associated shadow, which is unmapped -> BOOM.

With the following implementation, I can avoid the crash similar to the one Florian is reporting:

static __init void *kasan_alloc_block(size_t size) {
void *p = memblock_alloc_try_nid_raw(size, size,

    __pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_KASAN,
    NUMA_NO_NODE);

if (p)

    __memset(p, 0, size);

return p;
}

However, I still get a hang a bit later, and I haven't tracked that down yet.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#31 lore raw
Quoted 72 lines · Ard Biesheuvel
Quoted 41 lines · Ard Biesheuvel
Quoted 30 lines · Florian Fainelli
Quoted 14 lines · Linus Walleij

This is the 14th iteration of KASan for ARM/Aarch32.

I have added one patch in the beginning of the series to fix the issue when the DTB (often attached DTB) ends up in lowmem. It also amends ARM to copy the device tree instead of just unflattening it and using it from where it is.

This fixes my particular issue on the Qualcomm APQ8060 and I hope it may also solve Florian's issue and what Ard has been seeing. If you inspect patch 1/6 you can see what has been going on for me. My hypothesis about what was going on was mostly right.

Quoted 5 lines

You are encouraged to test this patch set to find memory out of bounds bugs with ARM32 platforms and drivers.

There is a git branch you can pull in:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=kasan

It does appear to be slight better, although all platforms that I have where memory starts at physical address 0 cannot boot, attached logs which are all more or less the same.

The physical memory map looks like this:

Quoted 8 lines

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

Do any of the platforms you use for testing have a similar memory map? Could you try to contrive a QEMU machine to have something similar in case that helps reproducing these failures?

Quoted 6 lines

I am getting very similar failures on a Raspberry Pi4 booting in 32-bit mode from U-boot+EFI

Full log attached.

I will try to dig a bit deeper.

OK, one obvious issue with the code as-is is that the following routine

static __init void *kasan_alloc_block(size_t size)
{
return memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS),

                                MEMBLOCK_ALLOC_KASAN, NUMA_NO_NODE);
}

is called after the early shadow is unmapped, but before the permanent shadow is in place. memblock_alloc_try_nid() clears the newly allocated memory using memset(), which checks the associated shadow, which is unmapped -> BOOM.

With the following implementation, I can avoid the crash similar to the one Florian is reporting:

static __init void *kasan_alloc_block(size_t size) {
void *p = memblock_alloc_try_nid_raw(size, size,

    __pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_KASAN,
    NUMA_NO_NODE);
Quoted 6 lines

if (p)

    __memset(p, 0, size);

return p;
}

However, I still get a hang a bit later, and I haven't tracked that down yet.

The above issue appears to be related to TLB maintenance. So keeping kasan_alloc_block() as is, and doing

arch/arm/mm/kasan_init.c +2 -0
@@ -223,6 +223,8 @@ void __init kasan_init(void)
                __pgd(__pa(tmp_pmd_table) | PMD_TYPE_TABLE | L_PGD_SWAPPER));
 #endif
        cpu_switch_mm(tmp_pgd_table, &init_mm);
+       local_flush_tlb_all();
+
        clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);
 
        kasan_populate_early_shadow(kasan_mem_to_shadow((void *)VMALLOC_START),

instead fixes the crash as well.

Still have the hang right after though ..

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#32 lore raw
Quoted 96 lines · Ard Biesheuvel
Quoted 72 lines · Ard Biesheuvel
Quoted 41 lines · Ard Biesheuvel
Quoted 30 lines · Florian Fainelli
Quoted 14 lines · Linus Walleij

This is the 14th iteration of KASan for ARM/Aarch32.

I have added one patch in the beginning of the series to fix the issue when the DTB (often attached DTB) ends up in lowmem. It also amends ARM to copy the device tree instead of just unflattening it and using it from where it is.

This fixes my particular issue on the Qualcomm APQ8060 and I hope it may also solve Florian's issue and what Ard has been seeing. If you inspect patch 1/6 you can see what has been going on for me. My hypothesis about what was going on was mostly right.

Quoted 5 lines

You are encouraged to test this patch set to find memory out of bounds bugs with ARM32 platforms and drivers.

There is a git branch you can pull in:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=kasan

It does appear to be slight better, although all platforms that I have where memory starts at physical address 0 cannot boot, attached logs which are all more or less the same.

The physical memory map looks like this:

Quoted 8 lines

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

Do any of the platforms you use for testing have a similar memory map? Could you try to contrive a QEMU machine to have something similar in case that helps reproducing these failures?

Quoted 6 lines

I am getting very similar failures on a Raspberry Pi4 booting in 32-bit mode from U-boot+EFI

Full log attached.

I will try to dig a bit deeper.

OK, one obvious issue with the code as-is is that the following routine

static __init void *kasan_alloc_block(size_t size)
{
return memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS),

                                MEMBLOCK_ALLOC_KASAN, NUMA_NO_NODE);
}

is called after the early shadow is unmapped, but before the permanent shadow is in place. memblock_alloc_try_nid() clears the newly allocated memory using memset(), which checks the associated shadow, which is unmapped -> BOOM.

With the following implementation, I can avoid the crash similar to the one Florian is reporting:

static __init void *kasan_alloc_block(size_t size) {
void *p = memblock_alloc_try_nid_raw(size, size,

    __pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_KASAN,
    NUMA_NO_NODE);
Quoted 6 lines

if (p)

    __memset(p, 0, size);

return p;
}

However, I still get a hang a bit later, and I haven't tracked that down yet.

The above issue appears to be related to TLB maintenance. So keeping kasan_alloc_block() as is, and doing

arch/arm/mm/kasan_init.c +2 -0
@@ -223,6 +223,8 @@ void __init kasan_init(void)
                __pgd(__pa(tmp_pmd_table) | PMD_TYPE_TABLE | L_PGD_SWAPPER));
 #endif
        cpu_switch_mm(tmp_pgd_table, &init_mm);
+       local_flush_tlb_all();
+
        clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);
 
        kasan_populate_early_shadow(kasan_mem_to_shadow((void *)VMALLOC_START),
Quoted 3 lines

instead fixes the crash as well.

Still have the hang right after though ..

OK, booting now - turns out the switch back to swapper_pg_dir needs a proper TLB flush as well.

Full patch below - with that applied, I can boot the RPi4 to the point where it wants to mount the rootfs (but I don't have a 32-bit rootfs at hand)

The first change avoids reallocating KASAN blocks when a range gets mapped twice - this occurs when mapping the DTB space explicitly (although I am not sure that that is still needed now that you move the DTB)

arch/arm/mm/kasan_init.c +5 -1
index 6fd9bc70970f..6877212a370d 100644
@@ -45,11 +45,15 @@
 
        do {
                pte_t entry;
+               void *p;
 
                next = addr + PAGE_SIZE;
 
                if (!early) {
-                       void *p = kasan_alloc_block(PAGE_SIZE);
+                       if (!pte_none(READ_ONCE(*ptep)))
+                               continue;
+
+                       p = kasan_alloc_block(PAGE_SIZE);
                        if (!p) {
                                panic("%s failed to alloc pte for

address 0x%lx\n",

                                      __func__, addr);
@@ -223,11 +227,15 @@
                __pgd(__pa(tmp_pmd_table) | PMD_TYPE_TABLE | L_PGD_SWAPPER));
 #endif
        cpu_switch_mm(tmp_pgd_table, &init_mm);
+       local_flush_tlb_all();
+
        clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);

        kasan_populate_early_shadow(kasan_mem_to_shadow((void *)VMALLOC_START),
                                    kasan_mem_to_shadow((void *)-1UL) + 1);

+ __memblock_dump_all();
+

        for_each_memblock(memory, reg) {
                void *start = __va(reg->base);
                void *end = __va(reg->base + reg->size);
@@ -277,10 +285,11 @@
                           pfn_pte(virt_to_pfn(kasan_early_shadow_page),
                                __pgprot(pgprot_val(PAGE_KERNEL)
                                         | L_PTE_RDONLY)));
+
+       cpu_switch_mm(swapper_pg_dir, &init_mm);
        local_flush_tlb_all();

        memset(kasan_early_shadow_page, 0, PAGE_SIZE);
-       cpu_switch_mm(swapper_pg_dir, &init_mm);
        pr_info("Kernel address sanitizer initialized\n");
        init_task.kasan_depth = 0;

}

Full boot log attached.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#33 lore raw
Quoted 109 lines · Ard Biesheuvel
Quoted 96 lines · Ard Biesheuvel
Quoted 77 lines · Ard Biesheuvel
Quoted 41 lines · Ard Biesheuvel
Quoted 30 lines · Florian Fainelli
Quoted 14 lines · Linus Walleij

This is the 14th iteration of KASan for ARM/Aarch32.

I have added one patch in the beginning of the series to fix the issue when the DTB (often attached DTB) ends up in lowmem. It also amends ARM to copy the device tree instead of just unflattening it and using it from where it is.

This fixes my particular issue on the Qualcomm APQ8060 and I hope it may also solve Florian's issue and what Ard has been seeing. If you inspect patch 1/6 you can see what has been going on for me. My hypothesis about what was going on was mostly right.

Quoted 5 lines

You are encouraged to test this patch set to find memory out of bounds bugs with ARM32 platforms and drivers.

There is a git branch you can pull in:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=kasan

It does appear to be slight better, although all platforms that I have where memory starts at physical address 0 cannot boot, attached logs which are all more or less the same.

The physical memory map looks like this:

Quoted 8 lines

0..3GB -> DRAM
3GB..4GB -> Registers, Boot ROM, Boot SRAM
4GB..12GB -> DRAM extension

Do any of the platforms you use for testing have a similar memory map? Could you try to contrive a QEMU machine to have something similar in case that helps reproducing these failures?

Quoted 6 lines

I am getting very similar failures on a Raspberry Pi4 booting in 32-bit mode from U-boot+EFI

Full log attached.

I will try to dig a bit deeper.

OK, one obvious issue with the code as-is is that the following routine

static __init void *kasan_alloc_block(size_t size)
{
return memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS),

                                 MEMBLOCK_ALLOC_KASAN, NUMA_NO_NODE);
}

is called after the early shadow is unmapped, but before the permanent shadow is in place. memblock_alloc_try_nid() clears the newly allocated memory using memset(), which checks the associated shadow, which is unmapped -> BOOM.

With the following implementation, I can avoid the crash similar to the one Florian is reporting:

static __init void *kasan_alloc_block(size_t size)

{
   void *p = memblock_alloc_try_nid_raw(size, size,
     __pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_KASAN,
     NUMA_NO_NODE);

   if (p)
     __memset(p, 0, size);
   return p;
}
Quoted 1 line

However, I still get a hang a bit later, and I haven't tracked that down yet.

The above issue appears to be related to TLB maintenance. So keeping kasan_alloc_block() as is, and doing

arch/arm/mm/kasan_init.c +2 -0
@@ -223,6 +223,8 @@ void __init kasan_init(void)
                 __pgd(__pa(tmp_pmd_table) | PMD_TYPE_TABLE | L_PGD_SWAPPER));
  #endif
         cpu_switch_mm(tmp_pgd_table, &init_mm);
+       local_flush_tlb_all();
+
         clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);
 
         kasan_populate_early_shadow(kasan_mem_to_shadow((void *)VMALLOC_START),
Quoted 3 lines

instead fixes the crash as well.

Still have the hang right after though ..

OK, booting now - turns out the switch back to swapper_pg_dir needs a proper TLB flush as well.

Full patch below - with that applied, I can boot the RPi4 to the point where it wants to mount the rootfs (but I don't have a 32-bit rootfs at hand)

Quoted 4 lines

The first change avoids reallocating KASAN blocks when a range gets mapped twice - this occurs when mapping the DTB space explicitly (although I am not sure that that is still needed now that you move the DTB)

We are almost there it seems. There are only 3 boards that do not boot (they are all similar in configuration, amounts of memory and placement of reserved regions), see the attached log. Every other platform now boots correctly so this is definitively a big improvement!

Signature · 1 line
Florian
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 5.9.0-rc7-g6e04af38fd04 (fainelli@fainelli-desktop) (arm-linux-gcc (GCC) 8.3.0, GNU ld (GNU Binutils) 2.32) #12 SMP Sun Oct 4 13:06:11 PDT 2020
[    0.000000] CPU: ARMv7 Processor [410fd083] revision 3 (ARMv7), cr=30c5383d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[    0.000000] OF: fdt: Machine model: BCM972112SV
[    0.000000] earlycon: pl11 at MMIO 0x000000047e201000 (options '115200')
[    0.000000] printk: bootconsole [pl11] enabled
[    0.000000] Memory policy: Data cache writealloc
[    0.000000] cma: Reserved 16 MiB at 0x000000007f000000
[    0.000000] ATAGs/DTB found in lowmem, skip clearing PMD @0xce5fe000
[    0.000000] ATAGs/DTB found in lowmem, skip clearing PMD @0xce7fe000
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000002fffffff]
[    0.000000]   Normal   empty
[    0.000000]   HighMem  [mem 0x0000000030000000-0x000000007fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x00000000063fdfff]
[    0.000000]   node   0: [mem 0x0000000006400000-0x000000000fffffff]
[    0.000000]   node   0: [mem 0x0000000010400000-0x000000007fffffff]
[    0.000000] Zeroed struct page in unavailable ranges: 2 pages
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000007fffffff]
[    0.000000] MEMBLOCK configuration:
[    0.000000]  memory size = 0x000000007fbfe000 reserved size = 0x00000000053ef6e0
[    0.000000]  memory.cnt  = 0x3
[    0.000000]  memory[0x0]	[0x0000000000000000-0x00000000063fdfff], 0x00000000063fe000 bytes flags: 0x0
[    0.000000]  memory[0x1]	[0x0000000006400000-0x000000000fffffff], 0x0000000009c00000 bytes flags: 0x0
[    0.000000]  memory[0x2]	[0x0000000010400000-0x000000007fffffff], 0x000000006fc00000 bytes flags: 0x0
[    0.000000]  reserved.cnt  = 0xb
[    0.000000]  reserved[0x0]	[0x0000000000000000-0x0000000000000fff], 0x0000000000001000 bytes flags: 0x0
[    0.000000]  reserved[0x1]	[0x0000000000003000-0x0000000000007fff], 0x0000000000005000 bytes flags: 0x0
[    0.000000]  reserved[0x2]	[0x0000000000200000-0x0000000002fdcf9f], 0x0000000002ddcfa0 bytes flags: 0x0
[    0.000000]  reserved[0x3]	[0x00000000061ff000-0x00000000061fffff], 0x0000000000001000 bytes flags: 0x0
[    0.000000]  reserved[0x4]	[0x0000000006400000-0x00000000065fffff], 0x0000000000200000 bytes flags: 0x0
[    0.000000]  reserved[0x5]	[0x000000000e415000-0x000000000e41960f], 0x0000000000004610 bytes flags: 0x0
[    0.000000]  reserved[0x6]	[0x000000002e980000-0x000000002fd7ffff], 0x0000000001400000 bytes flags: 0x0
[    0.000000]  reserved[0x7]	[0x000000002fff8000-0x000000002fffdfff], 0x0000000000006000 bytes flags: 0x0
[    0.000000]  reserved[0x8]	[0x000000002fffeec0-0x000000002fffefbf], 0x0000000000000100 bytes flags: 0x0
[    0.000000]  reserved[0x9]	[0x000000002fffefd0-0x000000002fffffff], 0x0000000000001030 bytes flags: 0x0
[    0.000000]  reserved[0xa]	[0x000000007f000000-0x000000007fffffff], 0x0000000001000000 bytes flags: 0x0
[    0.000000] kasan: Mapping kernel virtual memory block: c0000000-c63fe000 at shadow: b7000000-b7c7fc00
[    0.000000] Kernel panic - not syncing: kasan_pte_populate failed to alloc pte for address 0xe2806000
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.9.0-rc7-g6e04af38fd04 #12
[    0.000000] Hardware name: Broadcom STB (Flattened Device Tree)
[    0.000000] Backtrace: 
[    0.000000] [<c02120b4>] (dump_backtrace) from [<c02123d8>] (show_stack+0x20/0x24)
[    0.000000]  r9:ffffffff r8:00000080 r7:c298e900 r6:600000d3 r5:00000000 r4:c298e900
[    0.000000] [<c02123b8>] (show_stack) from [<c08869e0>] (dump_stack+0xbc/0xe0)
[    0.000000] [<c0886924>] (dump_stack) from [<c022fc6c>] (panic+0x19c/0x3e4)
[    0.000000]  r10:e2806000 r9:c2b790e0 r8:c166b5bc r7:c2803d60 r6:00000000 r5:c2b7df00
[    0.000000]  r4:c2b78e20 r3:00000001
[    0.000000] [<c022fad0>] (panic) from [<c180bae4>] (kasan_pgd_populate+0x1ac/0x26c)
[    0.000000]  r3:00000000 r2:e2806000 r1:c1212734 r0:c166b5bc
[    0.000000]  r7:b7c7fc00
[    0.000000] [<c180b938>] (kasan_pgd_populate) from [<c180bbfc>] (create_mapping+0x58/0x64)
[    0.000000]  r10:c166b690 r9:00000000 r8:063fe000 r7:c2ba0ac0 r6:c28a29e0 r5:b7000000
[    0.000000]  r4:b7c7fc00
[    0.000000] [<c180bba4>] (create_mapping) from [<c180bee0>] (kasan_init+0x270/0x3c0)
[    0.000000]  r5:00000000 r4:c0000000
[    0.000000] [<c180bc70>] (kasan_init) from [<c1805684>] (setup_arch+0x848/0x1048)
[    0.000000]  r10:c1861450 r9:c0226668 r8:e12fff1e r7:c0008000 r6:c1873a40 r5:c2fdcfa0
[    0.000000]  r4:c28a2780
[    0.000000] [<c1804e3c>] (setup_arch) from [<c1801010>] (start_kernel+0x88/0x3e4)
[    0.000000]  r10:c2806d40 r9:410fd083 r8:0e415000 r7:ffffffff r6:30c0387d r5:c2806d48
[    0.000000]  r4:00007000
[    0.000000] [<c1800f88>] (start_kernel) from [<00000000>] (0x0)
[    0.000000]  r10:30c5387d r9:410fd083 r8:0e415000 r7:ffffffff r6:30c0387d r5:00000000
[    0.000000]  r4:c1800334
[    0.000000] ---[ end Kernel panic - not syncing: kasan_pte_populate failed to alloc pte for address 0xe2806000 ]---

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#34 lore raw
In reply to Ard Biesheuvel
Quoted 2 lines · Ard Biesheuvel

OK, booting now - turns out the switch back to swapper_pg_dir needs a proper TLB flush as well.

Wow this is so nice, thanks a ton Ard!!

I folded this into my kasan init patch.

Quoted 4 lines

The first change avoids reallocating KASAN blocks when a range gets mapped twice - this occurs when mapping the DTB space explicitly (although I am not sure that that is still needed now that you move the DTB)

Sooner or later someone is going to make this happen anyway so better be safe than sorry.

Thanks!!
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#35 lore raw
In reply to Linus Walleij
Quoted 2 lines · Linus Walleij

There is a git branch you can pull in:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator.git/log/?h=kasan

I have updated this branch with a version with Ard's patches for relocating the DTB to fixed mapping underneath, and the patches there have Ard's fixes folded in as well.

Will resend tomorrow or so.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel