2021-08-11 08:53:58

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v5 0/9] Add generic support for kdump DT properties

Hi all,

This patch series adds generic support for parsing DT properties related
to crash dump kernels ("linux,elfcorehdr" and "linux,elfcorehdr" under
the "/chosen" node), makes use of it on arm32, and performs a few
cleanups. It is an evolution of the combination of [1] and [2].

The series consists of 6 parts:
1. Patch 1 prepares architecture-specific code (needed for MIPS only)
to avoid duplicating elf core header reservation later.
2. Patch 2 prepares the visibility of variables used to hold
information retrieved from the DT properties.
3. Patches 3-5 add support to the FDT core for handling the
properties.
This can co-exist safely with architecture-specific handling, until
the latter has been removed.
4. Patch 6 removes the non-standard handling of "linux,elfcorehdr" on
riscv.
5. Patches 7-8 convert arm64 to use the generic handling instead of
its own implementation.
6. Patch 9 adds support for kdump properties to arm32.
The corresponding patch for kexec-tools is "[PATCH] arm: kdump: Add
DT properties to crash dump kernel's DTB"[3], which is still valid.

Changes compared to v4[4]:
- New patch "[PATCH v5 1/9] MIPS: Avoid future duplicate elf core
header reservation",
- Drop "memblock: Add variables for usable memory limitation", as this
is now handled in FDT core code,
- Make ELFCORE_ADDR_{MAX,ERR} visible, too,
- Handle the actual elf core header reservation and memory capping in
FDT core code,
- Add Reviewed-by, Acked-by,
- Remove all architecture-specific handling on arm64,
- Drop "arm64: kdump: Use IS_ENABLED(CONFIG_CRASH_DUMP) instead of
#ifdef", as the affected code is gone,
- Remove the addition of "linux,elfcorehdr" and
"linux,usable-memory-range" handling to arch/arm/mm/init.c.

Changes compared to older versions:
- Make elfcorehdr_{addr,size} always visible,
- Add variables for usable memory limitation,
- Use IS_ENABLED() instead of #ifdef (incl. initrd and arm64),
- Clarify what architecture-specific code is still responsible for,
- Add generic support for parsing linux,usable-memory-range,
- Remove custom linux,usable-memory-range parsing on arm64,
- Use generic handling on ARM.

This has been tested with kexec/kdump on arm32 and arm64, and
boot-tested on riscv64 and DT-less MIPS.

Thanks!

[1] "[PATCH v3] ARM: Parse kdump DT properties"
https://lore.kernel.org/r/[email protected]/
[2] "[PATCH 0/3] Add generic-support for linux,elfcorehdr and fix riscv"
https://lore.kernel.org/r/[email protected]/
[3] "[PATCH] arm: kdump: Add DT properties to crash dump kernel's DTB"
https://lore.kernel.org/r/[email protected]/
[4] "[PATCH v4 00/10] Add generic support for kdump DT properties"
https://lore.kernel.org/r/[email protected]

Geert Uytterhoeven (9):
MIPS: Avoid future duplicate elf core header reservation
crash_dump: Make elfcorehdr address/size symbols always visible
of: fdt: Add generic support for handling elf core headers property
of: fdt: Add generic support for handling usable memory range property
of: fdt: Use IS_ENABLED(CONFIG_BLK_DEV_INITRD) instead of #ifdef
riscv: Remove non-standard linux,elfcorehdr handling
arm64: kdump: Remove custom linux,elfcorehdr handling
arm64: kdump: Remove custom linux,usable-memory-range handling
ARM: uncompress: Parse "linux,usable-memory-range" DT property

Documentation/devicetree/bindings/chosen.txt | 12 +--
.../arm/boot/compressed/fdt_check_mem_start.c | 48 ++++++++--
arch/arm64/mm/init.c | 88 -----------------
arch/mips/kernel/setup.c | 3 +-
arch/riscv/mm/init.c | 20 ----
drivers/of/fdt.c | 94 +++++++++++++++++--
include/linux/crash_dump.h | 3 +-
7 files changed, 139 insertions(+), 129 deletions(-)

--
2.25.1

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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


2021-08-11 08:54:11

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v5 1/9] MIPS: Avoid future duplicate elf core header reservation

Prepare for early_init_fdt_scan_reserved_mem() reserving the memory
occupied by an elf core header described in the device tree.
As arch_mem_init() calls early_init_fdt_scan_reserved_mem() before
mips_reserve_vmcore(), the latter needs to check if the memory has
already been reserved before.

Note that mips_reserve_vmcore() cannot just be removed, as not all MIPS
systems use DT.

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
v5:
- New.
---
arch/mips/kernel/setup.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 23a140327a0bac1b..4693add05743d78b 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -429,7 +429,8 @@ static void __init mips_reserve_vmcore(void)
pr_info("Reserving %ldKB of memory at %ldKB for kdump\n",
(unsigned long)elfcorehdr_size >> 10, (unsigned long)elfcorehdr_addr >> 10);

- memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
+ if (!memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)
+ memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
#endif
}

--
2.25.1

2021-08-11 08:56:37

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v5 9/9] ARM: uncompress: Parse "linux,usable-memory-range" DT property

Add support for parsing the "linux,usable-memory-range" DT property.
This property is used to describe the usable memory reserved for the
crash dump kernel, and thus makes the memory reservation explicit.
If present, Linux no longer needs to mask the program counter, and rely
on the "mem=" kernel parameter to obtain the start and size of usable
memory.

For backwards compatibility, the traditional method to derive the start
of memory is still used if "linux,usable-memory-range" is absent.

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
The corresponding patch for kexec-tools is "[PATCH] arm: kdump: Add DT
properties to crash dump kernel's DTB", which is still valid:
https://lore.kernel.org/linux-arm-kernel/[email protected]/

v5:
- Remove the addition of "linux,elfcorehdr" and
"linux,usable-memory-range" handling to arch/arm/mm/init.c,

v4:
- Remove references to architectures in chosen.txt, to avoid having to
change this again when more architectures copy kdump support,
- Remove the architecture-specific code for parsing
"linux,usable-memory-range" and "linux,elfcorehdr", as the FDT core
code now takes care of this,
- Move chosen.txt change to patch changing the FDT core,
- Use IS_ENABLED(CONFIG_CRASH_DUMP) instead of #ifdef,

v3:
- Rebase on top of accepted solution for DTB memory information
handling, which is part of v5.12-rc1,

v2:
- Rebase on top of reworked DTB memory information handling.
---
.../arm/boot/compressed/fdt_check_mem_start.c | 48 ++++++++++++++++---
1 file changed, 42 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boot/compressed/fdt_check_mem_start.c b/arch/arm/boot/compressed/fdt_check_mem_start.c
index 62450d824c3ca180..9291a2661bdfe57f 100644
--- a/arch/arm/boot/compressed/fdt_check_mem_start.c
+++ b/arch/arm/boot/compressed/fdt_check_mem_start.c
@@ -55,16 +55,17 @@ static uint64_t get_val(const fdt32_t *cells, uint32_t ncells)
* DTB, and, if out-of-range, replace it by the real start address.
* To preserve backwards compatibility (systems reserving a block of memory
* at the start of physical memory, kdump, ...), the traditional method is
- * always used if it yields a valid address.
+ * used if it yields a valid address, unless the "linux,usable-memory-range"
+ * property is present.
*
* Return value: start address of physical memory to use
*/
uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
{
- uint32_t addr_cells, size_cells, base;
+ uint32_t addr_cells, size_cells, usable_base, base;
uint32_t fdt_mem_start = 0xffffffff;
- const fdt32_t *reg, *endp;
- uint64_t size, end;
+ const fdt32_t *usable, *reg, *endp;
+ uint64_t size, usable_end, end;
const char *type;
int offset, len;

@@ -80,6 +81,27 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
if (addr_cells > 2 || size_cells > 2)
return mem_start;

+ /*
+ * Usable memory in case of a crash dump kernel
+ * This property describes a limitation: memory within this range is
+ * only valid when also described through another mechanism
+ */
+ usable = get_prop(fdt, "/chosen", "linux,usable-memory-range",
+ (addr_cells + size_cells) * sizeof(fdt32_t));
+ if (usable) {
+ size = get_val(usable + addr_cells, size_cells);
+ if (!size)
+ return mem_start;
+
+ if (addr_cells > 1 && fdt32_ld(usable)) {
+ /* Outside 32-bit address space */
+ return mem_start;
+ }
+
+ usable_base = fdt32_ld(usable + addr_cells - 1);
+ usable_end = usable_base + size;
+ }
+
/* Walk all memory nodes and regions */
for (offset = fdt_next_node(fdt, -1, NULL); offset >= 0;
offset = fdt_next_node(fdt, offset, NULL)) {
@@ -107,7 +129,20 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)

base = fdt32_ld(reg + addr_cells - 1);
end = base + size;
- if (mem_start >= base && mem_start < end) {
+ if (usable) {
+ /*
+ * Clip to usable range, which takes precedence
+ * over mem_start
+ */
+ if (base < usable_base)
+ base = usable_base;
+
+ if (end > usable_end)
+ end = usable_end;
+
+ if (end <= base)
+ continue;
+ } else if (mem_start >= base && mem_start < end) {
/* Calculated address is valid, use it */
return mem_start;
}
@@ -123,7 +158,8 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
}

/*
- * The calculated address is not usable.
+ * The calculated address is not usable, or was overridden by the
+ * "linux,usable-memory-range" property.
* Use the lowest usable physical memory address from the DTB instead,
* and make sure this is a multiple of 2 MiB for phys/virt patching.
*/
--
2.25.1

2021-08-11 08:56:58

by Geert Uytterhoeven

[permalink] [raw]
Subject: [PATCH v5 8/9] arm64: kdump: Remove custom linux,usable-memory-range handling

Remove the architecture-specific code for handling the
"linux,usable-memory-range" property under the "/chosen" node in DT, as
the platform-agnostic FDT core code already takes care of this.

Signed-off-by: Geert Uytterhoeven <[email protected]>
---
v5:
- Remove all handling, not just parsing,

v4:
- New.
---
arch/arm64/mm/init.c | 35 -----------------------------------
1 file changed, 35 deletions(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index bac4f06bb7d900a2..4e90a1d170587376 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -197,45 +197,10 @@ static int __init early_mem(char *p)
}
early_param("mem", early_mem);

-static int __init early_init_dt_scan_usablemem(unsigned long node,
- const char *uname, int depth, void *data)
-{
- struct memblock_region *usablemem = data;
- const __be32 *reg;
- int len;
-
- if (depth != 1 || strcmp(uname, "chosen") != 0)
- return 0;
-
- reg = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len);
- if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells)))
- return 1;
-
- usablemem->base = dt_mem_next_cell(dt_root_addr_cells, &reg);
- usablemem->size = dt_mem_next_cell(dt_root_size_cells, &reg);
-
- return 1;
-}
-
-static void __init fdt_enforce_memory_region(void)
-{
- struct memblock_region reg = {
- .size = 0,
- };
-
- of_scan_flat_dt(early_init_dt_scan_usablemem, &reg);
-
- if (reg.size)
- memblock_cap_memory_range(reg.base, reg.size);
-}
-
void __init arm64_memblock_init(void)
{
const s64 linear_region_size = PAGE_END - _PAGE_OFFSET(vabits_actual);

- /* Handle linux,usable-memory-range property */
- fdt_enforce_memory_region();
-
/* Remove memory above our supported physical address size */
memblock_remove(1ULL << PHYS_MASK_SHIFT, ULLONG_MAX);

--
2.25.1

2021-08-11 15:37:58

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] MIPS: Avoid future duplicate elf core header reservation

On Wed, Aug 11, 2021 at 10:51 AM Geert Uytterhoeven
<[email protected]> wrote:
> Prepare for early_init_fdt_scan_reserved_mem() reserving the memory
> occupied by an elf core header described in the device tree.
> As arch_mem_init() calls early_init_fdt_scan_reserved_mem() before
> mips_reserve_vmcore(), the latter needs to check if the memory has
> already been reserved before.
>
> Note that mips_reserve_vmcore() cannot just be removed, as not all MIPS
> systems use DT.
>
> Signed-off-by: Geert Uytterhoeven <[email protected]>
> ---
> v5:
> - New.
> ---
> arch/mips/kernel/setup.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 23a140327a0bac1b..4693add05743d78b 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -429,7 +429,8 @@ static void __init mips_reserve_vmcore(void)
> pr_info("Reserving %ldKB of memory at %ldKB for kdump\n",
> (unsigned long)elfcorehdr_size >> 10, (unsigned long)elfcorehdr_addr >> 10);
>
> - memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
> + if (!memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)

As pointed out by lkp, there's a closing parenthesis missing.

/me hides back under his rock.

> + memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
> #endif

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

2021-08-15 15:27:37

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v5 0/9] Add generic support for kdump DT properties

On Wed, Aug 11, 2021 at 10:50:58AM +0200, Geert Uytterhoeven wrote:
> Hi all,
>
> This patch series adds generic support for parsing DT properties related
> to crash dump kernels ("linux,elfcorehdr" and "linux,elfcorehdr" under
> the "/chosen" node), makes use of it on arm32, and performs a few
> cleanups. It is an evolution of the combination of [1] and [2].

The DT bits look fine to me. How do you expect this to be merged? I'm
happy to take it if arch maintainers can ack it.

>
> The series consists of 6 parts:
> 1. Patch 1 prepares architecture-specific code (needed for MIPS only)
> to avoid duplicating elf core header reservation later.
> 2. Patch 2 prepares the visibility of variables used to hold
> information retrieved from the DT properties.
> 3. Patches 3-5 add support to the FDT core for handling the
> properties.
> This can co-exist safely with architecture-specific handling, until
> the latter has been removed.

Looks like patch 5 doesn't have any dependencies with the series?

> 4. Patch 6 removes the non-standard handling of "linux,elfcorehdr" on
> riscv.

I thought this should be applied for 5.14?

> 5. Patches 7-8 convert arm64 to use the generic handling instead of
> its own implementation.
> 6. Patch 9 adds support for kdump properties to arm32.
> The corresponding patch for kexec-tools is "[PATCH] arm: kdump: Add
> DT properties to crash dump kernel's DTB"[3], which is still valid.

This one can be applied on its own, right?

Rob

2021-08-16 05:57:28

by Mike Rapoport

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] MIPS: Avoid future duplicate elf core header reservation

Hi Geert,

On Wed, Aug 11, 2021 at 10:50:59AM +0200, Geert Uytterhoeven wrote:
> Prepare for early_init_fdt_scan_reserved_mem() reserving the memory
> occupied by an elf core header described in the device tree.
> As arch_mem_init() calls early_init_fdt_scan_reserved_mem() before
> mips_reserve_vmcore(), the latter needs to check if the memory has
> already been reserved before.

Doing memblock_reserve() for the same region is usually fine, did you
encounter any issues without this patch?

> Note that mips_reserve_vmcore() cannot just be removed, as not all MIPS
> systems use DT.
>
> Signed-off-by: Geert Uytterhoeven <[email protected]>
> ---
> v5:
> - New.
> ---
> arch/mips/kernel/setup.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 23a140327a0bac1b..4693add05743d78b 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -429,7 +429,8 @@ static void __init mips_reserve_vmcore(void)
> pr_info("Reserving %ldKB of memory at %ldKB for kdump\n",
> (unsigned long)elfcorehdr_size >> 10, (unsigned long)elfcorehdr_addr >> 10);
>
> - memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
> + if (!memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)
> + memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
> #endif
> }
>
> --
> 2.25.1
>

--
Sincerely yours,
Mike.

2021-08-23 10:15:34

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v5 0/9] Add generic support for kdump DT properties

Hi Rob,

On Sun, Aug 15, 2021 at 5:25 PM Rob Herring <[email protected]> wrote:
> On Wed, Aug 11, 2021 at 10:50:58AM +0200, Geert Uytterhoeven wrote:
> > This patch series adds generic support for parsing DT properties related
> > to crash dump kernels ("linux,elfcorehdr" and "linux,elfcorehdr" under
> > the "/chosen" node), makes use of it on arm32, and performs a few
> > cleanups. It is an evolution of the combination of [1] and [2].
>
> The DT bits look fine to me. How do you expect this to be merged? I'm
> happy to take it if arch maintainers can ack it.

I had hoped you could take the series...

> > The series consists of 6 parts:
> > 1. Patch 1 prepares architecture-specific code (needed for MIPS only)
> > to avoid duplicating elf core header reservation later.
> > 2. Patch 2 prepares the visibility of variables used to hold
> > information retrieved from the DT properties.
> > 3. Patches 3-5 add support to the FDT core for handling the
> > properties.
> > This can co-exist safely with architecture-specific handling, until
> > the latter has been removed.
>
> Looks like patch 5 doesn't have any dependencies with the series?

Indeed. So you can take it independently.

> > 4. Patch 6 removes the non-standard handling of "linux,elfcorehdr" on
> > riscv.
>
> I thought this should be applied for 5.14?

Me too, but unfortunately that hasn't happened yet...

> > 5. Patches 7-8 convert arm64 to use the generic handling instead of
> > its own implementation.
> > 6. Patch 9 adds support for kdump properties to arm32.
> > The corresponding patch for kexec-tools is "[PATCH] arm: kdump: Add
> > DT properties to crash dump kernel's DTB"[3], which is still valid.
>
> This one can be applied on its own, right?

While that wouldn't break anything (i.e. no regression), it still
wouldn't work if the DT properties are present, and the now-legacy
"mem=" kernel command line parameter is not.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

2021-08-23 10:21:46

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] MIPS: Avoid future duplicate elf core header reservation

Hi Mike,

On Mon, Aug 16, 2021 at 7:52 AM Mike Rapoport <[email protected]> wrote:
> On Wed, Aug 11, 2021 at 10:50:59AM +0200, Geert Uytterhoeven wrote:
> > Prepare for early_init_fdt_scan_reserved_mem() reserving the memory
> > occupied by an elf core header described in the device tree.
> > As arch_mem_init() calls early_init_fdt_scan_reserved_mem() before
> > mips_reserve_vmcore(), the latter needs to check if the memory has
> > already been reserved before.
>
> Doing memblock_reserve() for the same region is usually fine, did you
> encounter any issues without this patch?

Does it also work if the same region is part of an earlier larger
reservation? I am no memblock expert, so I don't know.
I didn't run into any issues, as my MIPS platform is non-DT, but I
assume arch/arm64/mm/init.c:reserve_elfcorehdr() had the check for
a reason.

Thanks!

>
> > Note that mips_reserve_vmcore() cannot just be removed, as not all MIPS
> > systems use DT.
> >
> > Signed-off-by: Geert Uytterhoeven <[email protected]>
> > ---
> > v5:
> > - New.
> > ---
> > arch/mips/kernel/setup.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> > index 23a140327a0bac1b..4693add05743d78b 100644
> > --- a/arch/mips/kernel/setup.c
> > +++ b/arch/mips/kernel/setup.c
> > @@ -429,7 +429,8 @@ static void __init mips_reserve_vmcore(void)
> > pr_info("Reserving %ldKB of memory at %ldKB for kdump\n",
> > (unsigned long)elfcorehdr_size >> 10, (unsigned long)elfcorehdr_addr >> 10);
> >
> > - memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
> > + if (!memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)
> > + memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
> > #endif
> > }

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

2021-08-23 12:57:00

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH v5 8/9] arm64: kdump: Remove custom linux,usable-memory-range handling

On Wed, Aug 11, 2021 at 10:51:06AM +0200, Geert Uytterhoeven wrote:
> Remove the architecture-specific code for handling the
> "linux,usable-memory-range" property under the "/chosen" node in DT, as
> the platform-agnostic FDT core code already takes care of this.
>
> Signed-off-by: Geert Uytterhoeven <[email protected]>

Acked-by: Catalin Marinas <[email protected]>

2021-08-23 13:14:55

by Mike Rapoport

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] MIPS: Avoid future duplicate elf core header reservation

On Mon, Aug 23, 2021 at 12:17:50PM +0200, Geert Uytterhoeven wrote:
> Hi Mike,
>
> On Mon, Aug 16, 2021 at 7:52 AM Mike Rapoport <[email protected]> wrote:
> > On Wed, Aug 11, 2021 at 10:50:59AM +0200, Geert Uytterhoeven wrote:
> > > Prepare for early_init_fdt_scan_reserved_mem() reserving the memory
> > > occupied by an elf core header described in the device tree.
> > > As arch_mem_init() calls early_init_fdt_scan_reserved_mem() before
> > > mips_reserve_vmcore(), the latter needs to check if the memory has
> > > already been reserved before.
> >
> > Doing memblock_reserve() for the same region is usually fine, did you
> > encounter any issues without this patch?
>
> Does it also work if the same region is part of an earlier larger
> reservation? I am no memblock expert, so I don't know.
> I didn't run into any issues, as my MIPS platform is non-DT, but I
> assume arch/arm64/mm/init.c:reserve_elfcorehdr() had the check for
> a reason.

The memory will be reserved regardless of the earlier reservation, the
issue may appear when the reservations are made for different purpose. E.g.
if there was crash kernel allocation before the reservation of elfcorehdr.

The check in such case will prevent the second reservation, but, at least
in arch/arm64/mm/init.c:reserve_elfcorehdr() it does not seem to prevent
different users of the overlapping regions to step on each others toes.

Moreover, arm64::reserve_elfcorehdr() seems buggy to me, because of there
is only a partial overlap of the elfcorehdr with the previous reservation,
the non-overlapping part of elfcorehdr won't get reserved at all.

> Thanks!
>
> >
> > > Note that mips_reserve_vmcore() cannot just be removed, as not all MIPS
> > > systems use DT.
> > >
> > > Signed-off-by: Geert Uytterhoeven <[email protected]>
> > > ---
> > > v5:
> > > - New.
> > > ---
> > > arch/mips/kernel/setup.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> > > index 23a140327a0bac1b..4693add05743d78b 100644
> > > --- a/arch/mips/kernel/setup.c
> > > +++ b/arch/mips/kernel/setup.c
> > > @@ -429,7 +429,8 @@ static void __init mips_reserve_vmcore(void)
> > > pr_info("Reserving %ldKB of memory at %ldKB for kdump\n",
> > > (unsigned long)elfcorehdr_size >> 10, (unsigned long)elfcorehdr_addr >> 10);
> > >
> > > - memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
> > > + if (!memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)
> > > + memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
> > > #endif
> > > }
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
>
> 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

--
Sincerely yours,
Mike.

2021-08-23 14:47:10

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] MIPS: Avoid future duplicate elf core header reservation

On Mon, Aug 23, 2021 at 8:10 AM Mike Rapoport <[email protected]> wrote:
>
> On Mon, Aug 23, 2021 at 12:17:50PM +0200, Geert Uytterhoeven wrote:
> > Hi Mike,
> >
> > On Mon, Aug 16, 2021 at 7:52 AM Mike Rapoport <[email protected]> wrote:
> > > On Wed, Aug 11, 2021 at 10:50:59AM +0200, Geert Uytterhoeven wrote:
> > > > Prepare for early_init_fdt_scan_reserved_mem() reserving the memory
> > > > occupied by an elf core header described in the device tree.
> > > > As arch_mem_init() calls early_init_fdt_scan_reserved_mem() before
> > > > mips_reserve_vmcore(), the latter needs to check if the memory has
> > > > already been reserved before.
> > >
> > > Doing memblock_reserve() for the same region is usually fine, did you
> > > encounter any issues without this patch?
> >
> > Does it also work if the same region is part of an earlier larger
> > reservation? I am no memblock expert, so I don't know.
> > I didn't run into any issues, as my MIPS platform is non-DT, but I
> > assume arch/arm64/mm/init.c:reserve_elfcorehdr() had the check for
> > a reason.
>
> The memory will be reserved regardless of the earlier reservation, the
> issue may appear when the reservations are made for different purpose. E.g.
> if there was crash kernel allocation before the reservation of elfcorehdr.
>
> The check in such case will prevent the second reservation, but, at least
> in arch/arm64/mm/init.c:reserve_elfcorehdr() it does not seem to prevent
> different users of the overlapping regions to step on each others toes.

If the kernel has been passed in overlapping regions, is there
anything you can do other than hope to get a message out?

> Moreover, arm64::reserve_elfcorehdr() seems buggy to me, because of there
> is only a partial overlap of the elfcorehdr with the previous reservation,
> the non-overlapping part of elfcorehdr won't get reserved at all.

What do you suggest as the arm64 version is not the common version?

Rob

2021-08-23 14:54:28

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v5 0/9] Add generic support for kdump DT properties

On Mon, Aug 23, 2021 at 5:13 AM Geert Uytterhoeven <[email protected]> wrote:
>
> Hi Rob,
>
> On Sun, Aug 15, 2021 at 5:25 PM Rob Herring <[email protected]> wrote:
> > On Wed, Aug 11, 2021 at 10:50:58AM +0200, Geert Uytterhoeven wrote:
> > > This patch series adds generic support for parsing DT properties related
> > > to crash dump kernels ("linux,elfcorehdr" and "linux,elfcorehdr" under
> > > the "/chosen" node), makes use of it on arm32, and performs a few
> > > cleanups. It is an evolution of the combination of [1] and [2].
> >
> > The DT bits look fine to me. How do you expect this to be merged? I'm
> > happy to take it if arch maintainers can ack it.
>
> I had hoped you could take the series...

My current thought is I'll take 2-5, 7 and 8 given that's what I have
acks for and the others can be applied independently.

> > > The series consists of 6 parts:
> > > 1. Patch 1 prepares architecture-specific code (needed for MIPS only)
> > > to avoid duplicating elf core header reservation later.
> > > 2. Patch 2 prepares the visibility of variables used to hold
> > > information retrieved from the DT properties.
> > > 3. Patches 3-5 add support to the FDT core for handling the
> > > properties.
> > > This can co-exist safely with architecture-specific handling, until
> > > the latter has been removed.
> >
> > Looks like patch 5 doesn't have any dependencies with the series?
>
> Indeed. So you can take it independently.
>
> > > 4. Patch 6 removes the non-standard handling of "linux,elfcorehdr" on
> > > riscv.
> >
> > I thought this should be applied for 5.14?
>
> Me too, but unfortunately that hasn't happened yet...

Buried in the middle of this series is not going to encourage it to be
picked up as a fix.

Rob

2021-08-23 15:21:42

by Mike Rapoport

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] MIPS: Avoid future duplicate elf core header reservation

On Mon, Aug 23, 2021 at 09:44:55AM -0500, Rob Herring wrote:
> On Mon, Aug 23, 2021 at 8:10 AM Mike Rapoport <[email protected]> wrote:
> >
> > On Mon, Aug 23, 2021 at 12:17:50PM +0200, Geert Uytterhoeven wrote:
> > > Hi Mike,
> > >
> > > On Mon, Aug 16, 2021 at 7:52 AM Mike Rapoport <[email protected]> wrote:
> > > > On Wed, Aug 11, 2021 at 10:50:59AM +0200, Geert Uytterhoeven wrote:
> > > > > Prepare for early_init_fdt_scan_reserved_mem() reserving the memory
> > > > > occupied by an elf core header described in the device tree.
> > > > > As arch_mem_init() calls early_init_fdt_scan_reserved_mem() before
> > > > > mips_reserve_vmcore(), the latter needs to check if the memory has
> > > > > already been reserved before.
> > > >
> > > > Doing memblock_reserve() for the same region is usually fine, did you
> > > > encounter any issues without this patch?
> > >
> > > Does it also work if the same region is part of an earlier larger
> > > reservation? I am no memblock expert, so I don't know.
> > > I didn't run into any issues, as my MIPS platform is non-DT, but I
> > > assume arch/arm64/mm/init.c:reserve_elfcorehdr() had the check for
> > > a reason.
> >
> > The memory will be reserved regardless of the earlier reservation, the
> > issue may appear when the reservations are made for different purpose. E.g.
> > if there was crash kernel allocation before the reservation of elfcorehdr.
> >
> > The check in such case will prevent the second reservation, but, at least
> > in arch/arm64/mm/init.c:reserve_elfcorehdr() it does not seem to prevent
> > different users of the overlapping regions to step on each others toes.
>
> If the kernel has been passed in overlapping regions, is there
> anything you can do other than hope to get a message out?

Nothing really. I've been thinking about adding flags to memblock.reserved
to at least distinguish firmware regions from the kernel allocations, but I
never got to that.

> > Moreover, arm64::reserve_elfcorehdr() seems buggy to me, because of there
> > is only a partial overlap of the elfcorehdr with the previous reservation,
> > the non-overlapping part of elfcorehdr won't get reserved at all.
>
> What do you suggest as the arm64 version is not the common version?

I'm not really familiar with crash dump internals, so I don't know if
resetting elfcorehdr_addr to ELFCORE_ADDR_ERR is a good idea. I think at
least arm64::reserve_elfcorehdr() should reserve the entire elfcorehdr area
regardless of the overlap. Otherwise it might get overwritten by a random
memblock_alloc().

> Rob

--
Sincerely yours,
Mike.

2021-08-24 11:57:27

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v5 0/9] Add generic support for kdump DT properties

On Mon, Aug 23, 2021 at 4:52 PM Rob Herring <[email protected]> wrote:
> On Mon, Aug 23, 2021 at 5:13 AM Geert Uytterhoeven <[email protected]> wrote:
> > On Sun, Aug 15, 2021 at 5:25 PM Rob Herring <[email protected]> wrote:
> > > On Wed, Aug 11, 2021 at 10:50:58AM +0200, Geert Uytterhoeven wrote:
> > > > This patch series adds generic support for parsing DT properties related
> > > > to crash dump kernels ("linux,elfcorehdr" and "linux,elfcorehdr" under
> > > > the "/chosen" node), makes use of it on arm32, and performs a few
> > > > cleanups. It is an evolution of the combination of [1] and [2].
> > >
> > > The DT bits look fine to me. How do you expect this to be merged? I'm
> > > happy to take it if arch maintainers can ack it.
> >
> > I had hoped you could take the series...
>
> My current thought is I'll take 2-5, 7 and 8 given that's what I have
> acks for and the others can be applied independently.

Note that Palmer did ack patch 6, so you can include it.

Russell: any thoughts about patch 9?

Thanks!

> > > > The series consists of 6 parts:
> > > > 1. Patch 1 prepares architecture-specific code (needed for MIPS only)
> > > > to avoid duplicating elf core header reservation later.
> > > > 2. Patch 2 prepares the visibility of variables used to hold
> > > > information retrieved from the DT properties.
> > > > 3. Patches 3-5 add support to the FDT core for handling the
> > > > properties.
> > > > This can co-exist safely with architecture-specific handling, until
> > > > the latter has been removed.
> > >
> > > Looks like patch 5 doesn't have any dependencies with the series?
> >
> > Indeed. So you can take it independently.
> >
> > > > 4. Patch 6 removes the non-standard handling of "linux,elfcorehdr" on
> > > > riscv.
> > >
> > > I thought this should be applied for 5.14?
> >
> > Me too, but unfortunately that hasn't happened yet...
>
> Buried in the middle of this series is not going to encourage it to be
> picked up as a fix.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

2021-08-24 22:45:55

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v5 0/9] Add generic support for kdump DT properties

On Tue, Aug 24, 2021 at 6:55 AM Geert Uytterhoeven <[email protected]> wrote:
>
> On Mon, Aug 23, 2021 at 4:52 PM Rob Herring <[email protected]> wrote:
> > On Mon, Aug 23, 2021 at 5:13 AM Geert Uytterhoeven <[email protected]> wrote:
> > > On Sun, Aug 15, 2021 at 5:25 PM Rob Herring <[email protected]> wrote:
> > > > On Wed, Aug 11, 2021 at 10:50:58AM +0200, Geert Uytterhoeven wrote:
> > > > > This patch series adds generic support for parsing DT properties related
> > > > > to crash dump kernels ("linux,elfcorehdr" and "linux,elfcorehdr" under
> > > > > the "/chosen" node), makes use of it on arm32, and performs a few
> > > > > cleanups. It is an evolution of the combination of [1] and [2].
> > > >
> > > > The DT bits look fine to me. How do you expect this to be merged? I'm
> > > > happy to take it if arch maintainers can ack it.
> > >
> > > I had hoped you could take the series...
> >
> > My current thought is I'll take 2-5, 7 and 8 given that's what I have
> > acks for and the others can be applied independently.
>
> Note that Palmer did ack patch 6, so you can include it.

Right, but Palmer should have taken it if it's for 5.14.

Anyways, I've now applied patches 2-8. If we want to improve the
handling over what arm64 code did as discussed, I think that's a
separate patch anyways.

Rob