android_kernel_sony_sdm845/drivers/of
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nicolas Boichat 666ae7c255 of/fdt: Make sure no-map does not remove already reserved regions
[ Upstream commit 8a5a75e5e9e55de1cef5d83ca3589cb4899193ef ]

If the device tree is incorrectly configured, and attempts to
define a "no-map" reserved memory that overlaps with the kernel
data/code, the kernel would crash quickly after boot, with no
obvious clue about the nature of the issue.

For example, this would happen if we have the kernel mapped at
these addresses (from /proc/iomem):
40000000-41ffffff : System RAM
  40080000-40dfffff : Kernel code
  40e00000-411fffff : reserved
  41200000-413e0fff : Kernel data

And we declare a no-map shared-dma-pool region at a fixed address
within that range:
mem_reserved: mem_region {
	compatible = "shared-dma-pool";
	reg = <0 0x40000000 0 0x01A00000>;
	no-map;
};

To fix this, when removing memory regions at early boot (which is
what "no-map" regions do), we need to make sure that the memory
is not already reserved. If we do, __reserved_mem_reserve_reg
will throw an error:
[    0.000000] OF: fdt: Reserved memory: failed to reserve memory
   for node 'mem_region': base 0x0000000040000000, size 26 MiB
and the code that will try to use the region should also fail,
later on.

We do not do anything for non-"no-map" regions, as memblock
explicitly allows reserved regions to overlap, and the commit
that this fixes removed the check for that precise reason.

[ qperret: fixed conflicts caused by the usage of memblock_mark_nomap ]

Fixes: 094cb98179 ("of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap")
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Quentin Perret <qperret@google.com>
Link: https://lore.kernel.org/r/20210115114544.1830068-3-qperret@google.com
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-03-03 17:44:37 +01:00
..
unittest-data
address.c of/address: Fix of_node memory leak in of_dma_is_coherent 2020-11-18 18:26:27 +01:00
base.c of: fix missing kobject init for !SYSFS && OF_DYNAMIC config 2020-04-24 07:59:10 +02:00
device.c of: fix of_device_get_modalias returned length when truncating buffers 2018-03-22 09:17:41 +01:00
dynamic.c
fdt.c of/fdt: Make sure no-map does not remove already reserved regions 2021-03-03 17:44:37 +01:00
fdt_address.c
irq.c
Kconfig of: Add OF_DMA_DEFAULT_COHERENT & select it on powerpc 2020-02-14 16:31:01 -05:00
Makefile
of_mdio.c of: mdio: Fix a signedness bug in of_phy_get_and_connect() 2020-01-29 10:24:32 +01:00
of_net.c
of_numa.c of, numa: Validate some distance map rules 2018-11-21 09:26:00 +01:00
of_pci.c
of_pci_irq.c
of_private.h
of_reserved_mem.c of: Fix reserved-memory overlap detection 2020-11-10 10:24:03 +01:00
overlay.c
pdt.c
platform.c
resolver.c
unittest.c of: unittest: kmemleak in of_unittest_platform_populate() 2020-04-24 07:59:10 +02:00