diff mbox series

[v2] ARM: decompress: Use /memreserve/ DTS nodes when validating memory

Message ID 20210907145652.63362-1-bert@biot.com (mailing list archive)
State New, archived
Headers show
Series [v2] ARM: decompress: Use /memreserve/ DTS nodes when validating memory | expand

Commit Message

Bert Vermeulen Sept. 7, 2021, 2:56 p.m. UTC
If the bootloader needs the start of memory to be preserved, for example
because it dropped the Trusted Firmware blob there, this chunk of memory
shouldn't be used by the kernel.

To avoid adding yet another SoC-specific text offset to arch/arm/Makefile,
this patch allows for a /memreserve/ entry in the DTS to mark off the
memory chunk instead.

Signed-off-by: Bert Vermeulen <bert@biot.com>
---
 arch/arm/boot/compressed/fdt_check_mem_start.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Geert Uytterhoeven Sept. 7, 2021, 3:09 p.m. UTC | #1
On Tue, Sep 7, 2021 at 4:57 PM Bert Vermeulen <bert@biot.com> wrote:
> If the bootloader needs the start of memory to be preserved, for example
> because it dropped the Trusted Firmware blob there, this chunk of memory
> shouldn't be used by the kernel.
>
> To avoid adding yet another SoC-specific text offset to arch/arm/Makefile,
> this patch allows for a /memreserve/ entry in the DTS to mark off the
> memory chunk instead.
>
> Signed-off-by: Bert Vermeulen <bert@biot.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
Ard Biesheuvel Sept. 9, 2021, 11:29 a.m. UTC | #2
On Tue, 7 Sept 2021 at 16:57, Bert Vermeulen <bert@biot.com> wrote:
>
> If the bootloader needs the start of memory to be preserved, for example
> because it dropped the Trusted Firmware blob there, this chunk of memory
> shouldn't be used by the kernel.
>
> To avoid adding yet another SoC-specific text offset to arch/arm/Makefile,
> this patch allows for a /memreserve/ entry in the DTS to mark off the
> memory chunk instead.
>
> Signed-off-by: Bert Vermeulen <bert@biot.com>

Thanks for working on this - I hope this will allow us to phase out at
least some of the existing text_offset hacks too.

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  arch/arm/boot/compressed/fdt_check_mem_start.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/boot/compressed/fdt_check_mem_start.c b/arch/arm/boot/compressed/fdt_check_mem_start.c
> index 62450d824c3c..1d47de1e860b 100644
> --- a/arch/arm/boot/compressed/fdt_check_mem_start.c
> +++ b/arch/arm/boot/compressed/fdt_check_mem_start.c
> @@ -64,7 +64,7 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
>         uint32_t addr_cells, size_cells, base;
>         uint32_t fdt_mem_start = 0xffffffff;
>         const fdt32_t *reg, *endp;
> -       uint64_t size, end;
> +       uint64_t rsvaddr, size, end;
>         const char *type;
>         int offset, len;
>
> @@ -74,6 +74,19 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
>         if (fdt_magic(fdt) != FDT_MAGIC)
>                 return mem_start;
>
> +       for (offset = fdt_off_mem_rsvmap(fdt); ; offset += 16) {
> +               rsvaddr = get_val(fdt + offset, 2);
> +               size = get_val(fdt + offset + 8, 2);
> +
> +               if (!rsvaddr && !size)
> +                       break;
> +
> +               end = rsvaddr + size;
> +               if (mem_start >= rsvaddr && mem_start <= end)
> +                       /* Relocate past reserved block */
> +                       mem_start = round_up(end, SZ_2M);
> +       }
> +
>         /* There may be multiple cells on LPAE platforms */
>         addr_cells = get_cells(fdt, "#address-cells");
>         size_cells = get_cells(fdt, "#size-cells");
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/arch/arm/boot/compressed/fdt_check_mem_start.c b/arch/arm/boot/compressed/fdt_check_mem_start.c
index 62450d824c3c..1d47de1e860b 100644
--- a/arch/arm/boot/compressed/fdt_check_mem_start.c
+++ b/arch/arm/boot/compressed/fdt_check_mem_start.c
@@ -64,7 +64,7 @@  uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
 	uint32_t addr_cells, size_cells, base;
 	uint32_t fdt_mem_start = 0xffffffff;
 	const fdt32_t *reg, *endp;
-	uint64_t size, end;
+	uint64_t rsvaddr, size, end;
 	const char *type;
 	int offset, len;
 
@@ -74,6 +74,19 @@  uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
 	if (fdt_magic(fdt) != FDT_MAGIC)
 		return mem_start;
 
+	for (offset = fdt_off_mem_rsvmap(fdt); ; offset += 16) {
+		rsvaddr = get_val(fdt + offset, 2);
+		size = get_val(fdt + offset + 8, 2);
+
+		if (!rsvaddr && !size)
+			break;
+
+		end = rsvaddr + size;
+		if (mem_start >= rsvaddr && mem_start <= end)
+			/* Relocate past reserved block */
+			mem_start = round_up(end, SZ_2M);
+	}
+
 	/* There may be multiple cells on LPAE platforms */
 	addr_cells = get_cells(fdt, "#address-cells");
 	size_cells = get_cells(fdt, "#size-cells");