Thread (36 messages) 36 messages, 4 authors, 2020-10-06

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

From: Florian Fainelli <f.fainelli@gmail.com>
Date: 2020-10-01 16:46:57


On 10/1/2020 8:22 AM, Linus Walleij wrote:
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.

Signed-off-by: Linus Walleij <redacted>
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
-- 
Florian

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help