All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: decompress: Use /memreserve/ DTS nodes when validating memory
@ 2021-09-06  9:59 ` Bert Vermeulen
  0 siblings, 0 replies; 4+ messages in thread
From: Bert Vermeulen @ 2021-09-06  9:59 UTC (permalink / raw)
  To: Russell King, Geert Uytterhoeven, Ard Biesheuvel, Nicolas Pitre,
	Bert Vermeulen, linux-arm-kernel, linux-kernel
  Cc: John Crispin

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(-)

diff --git a/arch/arm/boot/compressed/fdt_check_mem_start.c b/arch/arm/boot/compressed/fdt_check_mem_start.c
index 62450d824c3c..15a20c60155e 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, 8);
+		size = get_val(fdt + offset + 8, 8);
+
+		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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] ARM: decompress: Use /memreserve/ DTS nodes when validating memory
@ 2021-09-06  9:59 ` Bert Vermeulen
  0 siblings, 0 replies; 4+ messages in thread
From: Bert Vermeulen @ 2021-09-06  9:59 UTC (permalink / raw)
  To: Russell King, Geert Uytterhoeven, Ard Biesheuvel, Nicolas Pitre,
	Bert Vermeulen, linux-arm-kernel, linux-kernel
  Cc: John Crispin

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(-)

diff --git a/arch/arm/boot/compressed/fdt_check_mem_start.c b/arch/arm/boot/compressed/fdt_check_mem_start.c
index 62450d824c3c..15a20c60155e 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, 8);
+		size = get_val(fdt + offset + 8, 8);
+
+		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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ARM: decompress: Use /memreserve/ DTS nodes when validating memory
  2021-09-06  9:59 ` Bert Vermeulen
@ 2021-09-07  8:16   ` Geert Uytterhoeven
  -1 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2021-09-07  8:16 UTC (permalink / raw)
  To: Bert Vermeulen
  Cc: Russell King, Ard Biesheuvel, Nicolas Pitre, Linux ARM,
	Linux Kernel Mailing List, John Crispin

Hoi Bert,

On Mon, Sep 6, 2021 at 12:00 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>

Thanks for your patch!

> --- 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, 8);
> +               size = get_val(fdt + offset + 8, 8);

The last parameter of get_val() is the number of cells, not the number
of bytes. Hence it should be 2 for the 64-bit values in the memory
reservation block.

The rest looks good to me.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ARM: decompress: Use /memreserve/ DTS nodes when validating memory
@ 2021-09-07  8:16   ` Geert Uytterhoeven
  0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2021-09-07  8:16 UTC (permalink / raw)
  To: Bert Vermeulen
  Cc: Russell King, Ard Biesheuvel, Nicolas Pitre, Linux ARM,
	Linux Kernel Mailing List, John Crispin

Hoi Bert,

On Mon, Sep 6, 2021 at 12:00 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>

Thanks for your patch!

> --- 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, 8);
> +               size = get_val(fdt + offset + 8, 8);

The last parameter of get_val() is the number of cells, not the number
of bytes. Hence it should be 2 for the 64-bit values in the memory
reservation block.

The rest looks good to me.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-07  8:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06  9:59 [PATCH] ARM: decompress: Use /memreserve/ DTS nodes when validating memory Bert Vermeulen
2021-09-06  9:59 ` Bert Vermeulen
2021-09-07  8:16 ` Geert Uytterhoeven
2021-09-07  8:16   ` Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.