All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] arm64: kexec_file: add kdump
@ 2019-11-14  5:15 ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-arm-kernel, linux-kernel, AKASHI Takahiro

This is the last piece of my kexec_file_load implementation for arm64.
It is now ready for being merged as some relevant patch to dtc/libfdt[1]
has finally been integrated in v5.3-rc1.
(Nothing changed since kexec_file v16[2] except adding Patch#1 and #2.)

Patch#1 and #2 are preliminary patches for libfdt component.
Patch#3 is to add kdump support.

Bhepesh's patch[3] will be required for 52-bit VA support.
Once this patch is applied, whether or not CONFIG_ARM64_VA_BITS_52 is
enabled or not, a matching fix on user space side, crash utility,
will also be needed. 

Anyway, I tested my patch, at least, with the following configuration:
1) CONFIG_ARM64_BITS_48=y
2) CONFIG_ARM64_BITS_52=y, but vabits_actual=48

(I don't have any platform to use for
3) CONFIG_ARM64_BITS_52=y, and vabits_actual=52)

[1] commit 9bb9c6a110ea ("scripts/dtc: Update to upstream version
    v1.5.0-23-g87963ee20693"), in particular
	7fcf8208b8a9 libfdt: add fdt_append_addrrange()
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-November/612641.html
[3] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-November/693411.html

Changes in v2 (Nov 14, 2019)
* rebased to v5.4-rc7
* no functional changes

AKASHI Takahiro (3):
  libfdt: define UINT32_MAX in libfdt_env.h
  libfdt: include fdt_addresses.c
  arm64: kexec_file: add crash dump support

 arch/arm64/include/asm/kexec.h         |   4 +
 arch/arm64/kernel/kexec_image.c        |   4 -
 arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
 include/linux/libfdt_env.h             |   3 +
 lib/Makefile                           |   2 +-
 lib/fdt_addresses.c                    |   2 +
 6 files changed, 112 insertions(+), 9 deletions(-)
 create mode 100644 lib/fdt_addresses.c

-- 
2.21.0


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

* [PATCH v2 0/3] arm64: kexec_file: add kdump
@ 2019-11-14  5:15 ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel, AKASHI Takahiro

This is the last piece of my kexec_file_load implementation for arm64.
It is now ready for being merged as some relevant patch to dtc/libfdt[1]
has finally been integrated in v5.3-rc1.
(Nothing changed since kexec_file v16[2] except adding Patch#1 and #2.)

Patch#1 and #2 are preliminary patches for libfdt component.
Patch#3 is to add kdump support.

Bhepesh's patch[3] will be required for 52-bit VA support.
Once this patch is applied, whether or not CONFIG_ARM64_VA_BITS_52 is
enabled or not, a matching fix on user space side, crash utility,
will also be needed. 

Anyway, I tested my patch, at least, with the following configuration:
1) CONFIG_ARM64_BITS_48=y
2) CONFIG_ARM64_BITS_52=y, but vabits_actual=48

(I don't have any platform to use for
3) CONFIG_ARM64_BITS_52=y, and vabits_actual=52)

[1] commit 9bb9c6a110ea ("scripts/dtc: Update to upstream version
    v1.5.0-23-g87963ee20693"), in particular
	7fcf8208b8a9 libfdt: add fdt_append_addrrange()
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-November/612641.html
[3] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-November/693411.html

Changes in v2 (Nov 14, 2019)
* rebased to v5.4-rc7
* no functional changes

AKASHI Takahiro (3):
  libfdt: define UINT32_MAX in libfdt_env.h
  libfdt: include fdt_addresses.c
  arm64: kexec_file: add crash dump support

 arch/arm64/include/asm/kexec.h         |   4 +
 arch/arm64/kernel/kexec_image.c        |   4 -
 arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
 include/linux/libfdt_env.h             |   3 +
 lib/Makefile                           |   2 +-
 lib/fdt_addresses.c                    |   2 +
 6 files changed, 112 insertions(+), 9 deletions(-)
 create mode 100644 lib/fdt_addresses.c

-- 
2.21.0


_______________________________________________
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] 24+ messages in thread

* [PATCH v2 0/3] arm64: kexec_file: add kdump
@ 2019-11-14  5:15 ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel, AKASHI Takahiro

This is the last piece of my kexec_file_load implementation for arm64.
It is now ready for being merged as some relevant patch to dtc/libfdt[1]
has finally been integrated in v5.3-rc1.
(Nothing changed since kexec_file v16[2] except adding Patch#1 and #2.)

Patch#1 and #2 are preliminary patches for libfdt component.
Patch#3 is to add kdump support.

Bhepesh's patch[3] will be required for 52-bit VA support.
Once this patch is applied, whether or not CONFIG_ARM64_VA_BITS_52 is
enabled or not, a matching fix on user space side, crash utility,
will also be needed. 

Anyway, I tested my patch, at least, with the following configuration:
1) CONFIG_ARM64_BITS_48=y
2) CONFIG_ARM64_BITS_52=y, but vabits_actual=48

(I don't have any platform to use for
3) CONFIG_ARM64_BITS_52=y, and vabits_actual=52)

[1] commit 9bb9c6a110ea ("scripts/dtc: Update to upstream version
    v1.5.0-23-g87963ee20693"), in particular
	7fcf8208b8a9 libfdt: add fdt_append_addrrange()
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-November/612641.html
[3] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-November/693411.html

Changes in v2 (Nov 14, 2019)
* rebased to v5.4-rc7
* no functional changes

AKASHI Takahiro (3):
  libfdt: define UINT32_MAX in libfdt_env.h
  libfdt: include fdt_addresses.c
  arm64: kexec_file: add crash dump support

 arch/arm64/include/asm/kexec.h         |   4 +
 arch/arm64/kernel/kexec_image.c        |   4 -
 arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
 include/linux/libfdt_env.h             |   3 +
 lib/Makefile                           |   2 +-
 lib/fdt_addresses.c                    |   2 +
 6 files changed, 112 insertions(+), 9 deletions(-)
 create mode 100644 lib/fdt_addresses.c

-- 
2.21.0


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* [PATCH v2 1/3] libfdt: define UINT32_MAX in libfdt_env.h
  2019-11-14  5:15 ` AKASHI Takahiro
  (?)
@ 2019-11-14  5:15   ` AKASHI Takahiro
  -1 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-arm-kernel, linux-kernel, AKASHI Takahiro

In the implementation of kexec_file_load-based kdump for arm64,
fdt_appendprop_addrrange() will be used, but fdt_addresses.c
will fail to compile due to missing UINT32_MAX.

So just define it in libfdt_env.h.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
---
 include/linux/libfdt_env.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h
index edb0f0c30904..9ca00f11d9b1 100644
--- a/include/linux/libfdt_env.h
+++ b/include/linux/libfdt_env.h
@@ -3,6 +3,7 @@
 #define LIBFDT_ENV_H
 
 #include <linux/kernel.h>	/* For INT_MAX */
+#include <linux/limits.h>	/* For UINT32_MAX */
 #include <linux/string.h>
 
 #include <asm/byteorder.h>
@@ -11,6 +12,8 @@ typedef __be16 fdt16_t;
 typedef __be32 fdt32_t;
 typedef __be64 fdt64_t;
 
+#define UINT32_MAX U32_MAX
+
 #define fdt32_to_cpu(x) be32_to_cpu(x)
 #define cpu_to_fdt32(x) cpu_to_be32(x)
 #define fdt64_to_cpu(x) be64_to_cpu(x)
-- 
2.21.0


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

* [PATCH v2 1/3] libfdt: define UINT32_MAX in libfdt_env.h
@ 2019-11-14  5:15   ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel, AKASHI Takahiro

In the implementation of kexec_file_load-based kdump for arm64,
fdt_appendprop_addrrange() will be used, but fdt_addresses.c
will fail to compile due to missing UINT32_MAX.

So just define it in libfdt_env.h.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
---
 include/linux/libfdt_env.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h
index edb0f0c30904..9ca00f11d9b1 100644
--- a/include/linux/libfdt_env.h
+++ b/include/linux/libfdt_env.h
@@ -3,6 +3,7 @@
 #define LIBFDT_ENV_H
 
 #include <linux/kernel.h>	/* For INT_MAX */
+#include <linux/limits.h>	/* For UINT32_MAX */
 #include <linux/string.h>
 
 #include <asm/byteorder.h>
@@ -11,6 +12,8 @@ typedef __be16 fdt16_t;
 typedef __be32 fdt32_t;
 typedef __be64 fdt64_t;
 
+#define UINT32_MAX U32_MAX
+
 #define fdt32_to_cpu(x) be32_to_cpu(x)
 #define cpu_to_fdt32(x) cpu_to_be32(x)
 #define fdt64_to_cpu(x) be64_to_cpu(x)
-- 
2.21.0


_______________________________________________
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] 24+ messages in thread

* [PATCH v2 1/3] libfdt: define UINT32_MAX in libfdt_env.h
@ 2019-11-14  5:15   ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel, AKASHI Takahiro

In the implementation of kexec_file_load-based kdump for arm64,
fdt_appendprop_addrrange() will be used, but fdt_addresses.c
will fail to compile due to missing UINT32_MAX.

So just define it in libfdt_env.h.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
---
 include/linux/libfdt_env.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h
index edb0f0c30904..9ca00f11d9b1 100644
--- a/include/linux/libfdt_env.h
+++ b/include/linux/libfdt_env.h
@@ -3,6 +3,7 @@
 #define LIBFDT_ENV_H
 
 #include <linux/kernel.h>	/* For INT_MAX */
+#include <linux/limits.h>	/* For UINT32_MAX */
 #include <linux/string.h>
 
 #include <asm/byteorder.h>
@@ -11,6 +12,8 @@ typedef __be16 fdt16_t;
 typedef __be32 fdt32_t;
 typedef __be64 fdt64_t;
 
+#define UINT32_MAX U32_MAX
+
 #define fdt32_to_cpu(x) be32_to_cpu(x)
 #define cpu_to_fdt32(x) cpu_to_be32(x)
 #define fdt64_to_cpu(x) be64_to_cpu(x)
-- 
2.21.0


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* [PATCH v2 2/3] libfdt: include fdt_addresses.c
  2019-11-14  5:15 ` AKASHI Takahiro
  (?)
@ 2019-11-14  5:15   ` AKASHI Takahiro
  -1 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-arm-kernel, linux-kernel, AKASHI Takahiro

In the implementation of kexec_file_loaded-based kdump for arm64,
fdt_appendprop_addrrange() will be needed.

So include fdt_addresses.c in making libfdt.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
---
 lib/Makefile        | 2 +-
 lib/fdt_addresses.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
 create mode 100644 lib/fdt_addresses.c

diff --git a/lib/Makefile b/lib/Makefile
index c5892807e06f..1587a2de99c6 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -220,7 +220,7 @@ KASAN_SANITIZE_stackdepot.o := n
 KCOV_INSTRUMENT_stackdepot.o := n
 
 libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \
-	       fdt_empty_tree.o
+	       fdt_empty_tree.o fdt_addresses.o
 $(foreach file, $(libfdt_files), \
 	$(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))
 lib-$(CONFIG_LIBFDT) += $(libfdt_files)
diff --git a/lib/fdt_addresses.c b/lib/fdt_addresses.c
new file mode 100644
index 000000000000..23610bcf390b
--- /dev/null
+++ b/lib/fdt_addresses.c
@@ -0,0 +1,2 @@
+#include <linux/libfdt_env.h>
+#include "../scripts/dtc/libfdt/fdt_addresses.c"
-- 
2.21.0


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

* [PATCH v2 2/3] libfdt: include fdt_addresses.c
@ 2019-11-14  5:15   ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel, AKASHI Takahiro

In the implementation of kexec_file_loaded-based kdump for arm64,
fdt_appendprop_addrrange() will be needed.

So include fdt_addresses.c in making libfdt.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
---
 lib/Makefile        | 2 +-
 lib/fdt_addresses.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
 create mode 100644 lib/fdt_addresses.c

diff --git a/lib/Makefile b/lib/Makefile
index c5892807e06f..1587a2de99c6 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -220,7 +220,7 @@ KASAN_SANITIZE_stackdepot.o := n
 KCOV_INSTRUMENT_stackdepot.o := n
 
 libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \
-	       fdt_empty_tree.o
+	       fdt_empty_tree.o fdt_addresses.o
 $(foreach file, $(libfdt_files), \
 	$(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))
 lib-$(CONFIG_LIBFDT) += $(libfdt_files)
diff --git a/lib/fdt_addresses.c b/lib/fdt_addresses.c
new file mode 100644
index 000000000000..23610bcf390b
--- /dev/null
+++ b/lib/fdt_addresses.c
@@ -0,0 +1,2 @@
+#include <linux/libfdt_env.h>
+#include "../scripts/dtc/libfdt/fdt_addresses.c"
-- 
2.21.0


_______________________________________________
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] 24+ messages in thread

* [PATCH v2 2/3] libfdt: include fdt_addresses.c
@ 2019-11-14  5:15   ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel, AKASHI Takahiro

In the implementation of kexec_file_loaded-based kdump for arm64,
fdt_appendprop_addrrange() will be needed.

So include fdt_addresses.c in making libfdt.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
---
 lib/Makefile        | 2 +-
 lib/fdt_addresses.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
 create mode 100644 lib/fdt_addresses.c

diff --git a/lib/Makefile b/lib/Makefile
index c5892807e06f..1587a2de99c6 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -220,7 +220,7 @@ KASAN_SANITIZE_stackdepot.o := n
 KCOV_INSTRUMENT_stackdepot.o := n
 
 libfdt_files = fdt.o fdt_ro.o fdt_wip.o fdt_rw.o fdt_sw.o fdt_strerror.o \
-	       fdt_empty_tree.o
+	       fdt_empty_tree.o fdt_addresses.o
 $(foreach file, $(libfdt_files), \
 	$(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))
 lib-$(CONFIG_LIBFDT) += $(libfdt_files)
diff --git a/lib/fdt_addresses.c b/lib/fdt_addresses.c
new file mode 100644
index 000000000000..23610bcf390b
--- /dev/null
+++ b/lib/fdt_addresses.c
@@ -0,0 +1,2 @@
+#include <linux/libfdt_env.h>
+#include "../scripts/dtc/libfdt/fdt_addresses.c"
-- 
2.21.0


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* [PATCH v2 3/3] arm64: kexec_file: add crash dump support
  2019-11-14  5:15 ` AKASHI Takahiro
  (?)
@ 2019-11-14  5:15   ` AKASHI Takahiro
  -1 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-arm-kernel, linux-kernel, AKASHI Takahiro

Enabling crash dump (kdump) includes
* prepare contents of ELF header of a core dump file, /proc/vmcore,
  using crash_prepare_elf64_headers(), and
* add two device tree properties, "linux,usable-memory-range" and
  "linux,elfcorehdr", which represent respectively a memory range
  to be used by crash dump kernel and the header's location

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
---
 arch/arm64/include/asm/kexec.h         |   4 +
 arch/arm64/kernel/kexec_image.c        |   4 -
 arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
 3 files changed, 106 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
index 12a561a54128..d24b527e8c00 100644
--- a/arch/arm64/include/asm/kexec.h
+++ b/arch/arm64/include/asm/kexec.h
@@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
 struct kimage_arch {
 	void *dtb;
 	unsigned long dtb_mem;
+	/* Core ELF header buffer */
+	void *elf_headers;
+	unsigned long elf_headers_mem;
+	unsigned long elf_headers_sz;
 };
 
 extern const struct kexec_file_ops kexec_image_ops;
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index 29a9428486a5..af9987c154ca 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
 	struct kexec_segment *kernel_segment;
 	int ret;
 
-	/* We don't support crash kernels yet. */
-	if (image->type == KEXEC_TYPE_CRASH)
-		return ERR_PTR(-EOPNOTSUPP);
-
 	/*
 	 * We require a kernel with an unambiguous Image header. Per
 	 * Documentation/arm64/booting.rst, this is the case when image_size
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 7b08bf9499b6..f1d1bb895fd2 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -17,12 +17,15 @@
 #include <linux/memblock.h>
 #include <linux/of_fdt.h>
 #include <linux/random.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <asm/byteorder.h>
 
 /* relevant device tree properties */
+#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
+#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
 #define FDT_PROP_INITRD_START	"linux,initrd-start"
 #define FDT_PROP_INITRD_END	"linux,initrd-end"
 #define FDT_PROP_BOOTARGS	"bootargs"
@@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
 	vfree(image->arch.dtb);
 	image->arch.dtb = NULL;
 
+	vfree(image->arch.elf_headers);
+	image->arch.elf_headers = NULL;
+	image->arch.elf_headers_sz = 0;
+
 	return kexec_image_post_load_cleanup_default(image);
 }
 
@@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
 
 	off = ret;
 
+	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
+	if (ret && ret != -FDT_ERR_NOTFOUND)
+		goto out;
+	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
+	if (ret && ret != -FDT_ERR_NOTFOUND)
+		goto out;
+
+	if (image->type == KEXEC_TYPE_CRASH) {
+		/* add linux,elfcorehdr */
+		ret = fdt_appendprop_addrrange(dtb, 0, off,
+				FDT_PROP_KEXEC_ELFHDR,
+				image->arch.elf_headers_mem,
+				image->arch.elf_headers_sz);
+		if (ret)
+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+
+		/* add linux,usable-memory-range */
+		ret = fdt_appendprop_addrrange(dtb, 0, off,
+				FDT_PROP_MEM_RANGE,
+				crashk_res.start,
+				crashk_res.end - crashk_res.start + 1);
+		if (ret)
+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+	}
+
 	/* add bootargs */
 	if (cmdline) {
 		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
@@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs, kaslr-seed, and
- * rng-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed,
+ * rng-seed, userable-memory-range and elfcorehdr.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
@@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
 	}
 }
 
+static int prepare_elf_headers(void **addr, unsigned long *sz)
+{
+	struct crash_mem *cmem;
+	unsigned int nr_ranges;
+	int ret;
+	u64 i;
+	phys_addr_t start, end;
+
+	nr_ranges = 1; /* for exclusion of crashkernel region */
+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
+					MEMBLOCK_NONE, &start, &end, NULL)
+		nr_ranges++;
+
+	cmem = kmalloc(sizeof(struct crash_mem) +
+			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
+	if (!cmem)
+		return -ENOMEM;
+
+	cmem->max_nr_ranges = nr_ranges;
+	cmem->nr_ranges = 0;
+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
+					MEMBLOCK_NONE, &start, &end, NULL) {
+		cmem->ranges[cmem->nr_ranges].start = start;
+		cmem->ranges[cmem->nr_ranges].end = end - 1;
+		cmem->nr_ranges++;
+	}
+
+	/* Exclude crashkernel region */
+	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
+
+	if (!ret)
+		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
+
+	kfree(cmem);
+	return ret;
+}
+
 int load_other_segments(struct kimage *image,
 			unsigned long kernel_load_addr,
 			unsigned long kernel_size,
@@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
 			char *cmdline)
 {
 	struct kexec_buf kbuf;
-	void *dtb = NULL;
-	unsigned long initrd_load_addr = 0, dtb_len;
+	void *headers, *dtb = NULL;
+	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
 	int ret = 0;
 
 	kbuf.image = image;
 	/* not allocate anything below the kernel */
 	kbuf.buf_min = kernel_load_addr + kernel_size;
 
+	/* load elf core header */
+	if (image->type == KEXEC_TYPE_CRASH) {
+		ret = prepare_elf_headers(&headers, &headers_sz);
+		if (ret) {
+			pr_err("Preparing elf core header failed\n");
+			goto out_err;
+		}
+
+		kbuf.buffer = headers;
+		kbuf.bufsz = headers_sz;
+		kbuf.mem = 0;
+		kbuf.memsz = headers_sz;
+		kbuf.buf_align = SZ_64K; /* largest supported page size */
+		kbuf.buf_max = ULONG_MAX;
+		kbuf.top_down = true;
+
+		ret = kexec_add_buffer(&kbuf);
+		if (ret) {
+			vfree(headers);
+			goto out_err;
+		}
+		image->arch.elf_headers = headers;
+		image->arch.elf_headers_mem = kbuf.mem;
+		image->arch.elf_headers_sz = headers_sz;
+
+		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
+			 image->arch.elf_headers_mem, headers_sz, headers_sz);
+	}
+
 	/* load initrd */
 	if (initrd) {
 		kbuf.buffer = initrd;
-- 
2.21.0


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

* [PATCH v2 3/3] arm64: kexec_file: add crash dump support
@ 2019-11-14  5:15   ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel, AKASHI Takahiro

Enabling crash dump (kdump) includes
* prepare contents of ELF header of a core dump file, /proc/vmcore,
  using crash_prepare_elf64_headers(), and
* add two device tree properties, "linux,usable-memory-range" and
  "linux,elfcorehdr", which represent respectively a memory range
  to be used by crash dump kernel and the header's location

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
---
 arch/arm64/include/asm/kexec.h         |   4 +
 arch/arm64/kernel/kexec_image.c        |   4 -
 arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
 3 files changed, 106 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
index 12a561a54128..d24b527e8c00 100644
--- a/arch/arm64/include/asm/kexec.h
+++ b/arch/arm64/include/asm/kexec.h
@@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
 struct kimage_arch {
 	void *dtb;
 	unsigned long dtb_mem;
+	/* Core ELF header buffer */
+	void *elf_headers;
+	unsigned long elf_headers_mem;
+	unsigned long elf_headers_sz;
 };
 
 extern const struct kexec_file_ops kexec_image_ops;
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index 29a9428486a5..af9987c154ca 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
 	struct kexec_segment *kernel_segment;
 	int ret;
 
-	/* We don't support crash kernels yet. */
-	if (image->type == KEXEC_TYPE_CRASH)
-		return ERR_PTR(-EOPNOTSUPP);
-
 	/*
 	 * We require a kernel with an unambiguous Image header. Per
 	 * Documentation/arm64/booting.rst, this is the case when image_size
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 7b08bf9499b6..f1d1bb895fd2 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -17,12 +17,15 @@
 #include <linux/memblock.h>
 #include <linux/of_fdt.h>
 #include <linux/random.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <asm/byteorder.h>
 
 /* relevant device tree properties */
+#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
+#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
 #define FDT_PROP_INITRD_START	"linux,initrd-start"
 #define FDT_PROP_INITRD_END	"linux,initrd-end"
 #define FDT_PROP_BOOTARGS	"bootargs"
@@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
 	vfree(image->arch.dtb);
 	image->arch.dtb = NULL;
 
+	vfree(image->arch.elf_headers);
+	image->arch.elf_headers = NULL;
+	image->arch.elf_headers_sz = 0;
+
 	return kexec_image_post_load_cleanup_default(image);
 }
 
@@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
 
 	off = ret;
 
+	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
+	if (ret && ret != -FDT_ERR_NOTFOUND)
+		goto out;
+	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
+	if (ret && ret != -FDT_ERR_NOTFOUND)
+		goto out;
+
+	if (image->type == KEXEC_TYPE_CRASH) {
+		/* add linux,elfcorehdr */
+		ret = fdt_appendprop_addrrange(dtb, 0, off,
+				FDT_PROP_KEXEC_ELFHDR,
+				image->arch.elf_headers_mem,
+				image->arch.elf_headers_sz);
+		if (ret)
+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+
+		/* add linux,usable-memory-range */
+		ret = fdt_appendprop_addrrange(dtb, 0, off,
+				FDT_PROP_MEM_RANGE,
+				crashk_res.start,
+				crashk_res.end - crashk_res.start + 1);
+		if (ret)
+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+	}
+
 	/* add bootargs */
 	if (cmdline) {
 		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
@@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs, kaslr-seed, and
- * rng-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed,
+ * rng-seed, userable-memory-range and elfcorehdr.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
@@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
 	}
 }
 
+static int prepare_elf_headers(void **addr, unsigned long *sz)
+{
+	struct crash_mem *cmem;
+	unsigned int nr_ranges;
+	int ret;
+	u64 i;
+	phys_addr_t start, end;
+
+	nr_ranges = 1; /* for exclusion of crashkernel region */
+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
+					MEMBLOCK_NONE, &start, &end, NULL)
+		nr_ranges++;
+
+	cmem = kmalloc(sizeof(struct crash_mem) +
+			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
+	if (!cmem)
+		return -ENOMEM;
+
+	cmem->max_nr_ranges = nr_ranges;
+	cmem->nr_ranges = 0;
+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
+					MEMBLOCK_NONE, &start, &end, NULL) {
+		cmem->ranges[cmem->nr_ranges].start = start;
+		cmem->ranges[cmem->nr_ranges].end = end - 1;
+		cmem->nr_ranges++;
+	}
+
+	/* Exclude crashkernel region */
+	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
+
+	if (!ret)
+		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
+
+	kfree(cmem);
+	return ret;
+}
+
 int load_other_segments(struct kimage *image,
 			unsigned long kernel_load_addr,
 			unsigned long kernel_size,
@@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
 			char *cmdline)
 {
 	struct kexec_buf kbuf;
-	void *dtb = NULL;
-	unsigned long initrd_load_addr = 0, dtb_len;
+	void *headers, *dtb = NULL;
+	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
 	int ret = 0;
 
 	kbuf.image = image;
 	/* not allocate anything below the kernel */
 	kbuf.buf_min = kernel_load_addr + kernel_size;
 
+	/* load elf core header */
+	if (image->type == KEXEC_TYPE_CRASH) {
+		ret = prepare_elf_headers(&headers, &headers_sz);
+		if (ret) {
+			pr_err("Preparing elf core header failed\n");
+			goto out_err;
+		}
+
+		kbuf.buffer = headers;
+		kbuf.bufsz = headers_sz;
+		kbuf.mem = 0;
+		kbuf.memsz = headers_sz;
+		kbuf.buf_align = SZ_64K; /* largest supported page size */
+		kbuf.buf_max = ULONG_MAX;
+		kbuf.top_down = true;
+
+		ret = kexec_add_buffer(&kbuf);
+		if (ret) {
+			vfree(headers);
+			goto out_err;
+		}
+		image->arch.elf_headers = headers;
+		image->arch.elf_headers_mem = kbuf.mem;
+		image->arch.elf_headers_sz = headers_sz;
+
+		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
+			 image->arch.elf_headers_mem, headers_sz, headers_sz);
+	}
+
 	/* load initrd */
 	if (initrd) {
 		kbuf.buffer = initrd;
-- 
2.21.0


_______________________________________________
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] 24+ messages in thread

* [PATCH v2 3/3] arm64: kexec_file: add crash dump support
@ 2019-11-14  5:15   ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-11-14  5:15 UTC (permalink / raw)
  To: catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel, AKASHI Takahiro

Enabling crash dump (kdump) includes
* prepare contents of ELF header of a core dump file, /proc/vmcore,
  using crash_prepare_elf64_headers(), and
* add two device tree properties, "linux,usable-memory-range" and
  "linux,elfcorehdr", which represent respectively a memory range
  to be used by crash dump kernel and the header's location

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
---
 arch/arm64/include/asm/kexec.h         |   4 +
 arch/arm64/kernel/kexec_image.c        |   4 -
 arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
 3 files changed, 106 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
index 12a561a54128..d24b527e8c00 100644
--- a/arch/arm64/include/asm/kexec.h
+++ b/arch/arm64/include/asm/kexec.h
@@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
 struct kimage_arch {
 	void *dtb;
 	unsigned long dtb_mem;
+	/* Core ELF header buffer */
+	void *elf_headers;
+	unsigned long elf_headers_mem;
+	unsigned long elf_headers_sz;
 };
 
 extern const struct kexec_file_ops kexec_image_ops;
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index 29a9428486a5..af9987c154ca 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
 	struct kexec_segment *kernel_segment;
 	int ret;
 
-	/* We don't support crash kernels yet. */
-	if (image->type == KEXEC_TYPE_CRASH)
-		return ERR_PTR(-EOPNOTSUPP);
-
 	/*
 	 * We require a kernel with an unambiguous Image header. Per
 	 * Documentation/arm64/booting.rst, this is the case when image_size
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 7b08bf9499b6..f1d1bb895fd2 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -17,12 +17,15 @@
 #include <linux/memblock.h>
 #include <linux/of_fdt.h>
 #include <linux/random.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <asm/byteorder.h>
 
 /* relevant device tree properties */
+#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
+#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
 #define FDT_PROP_INITRD_START	"linux,initrd-start"
 #define FDT_PROP_INITRD_END	"linux,initrd-end"
 #define FDT_PROP_BOOTARGS	"bootargs"
@@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
 	vfree(image->arch.dtb);
 	image->arch.dtb = NULL;
 
+	vfree(image->arch.elf_headers);
+	image->arch.elf_headers = NULL;
+	image->arch.elf_headers_sz = 0;
+
 	return kexec_image_post_load_cleanup_default(image);
 }
 
@@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
 
 	off = ret;
 
+	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
+	if (ret && ret != -FDT_ERR_NOTFOUND)
+		goto out;
+	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
+	if (ret && ret != -FDT_ERR_NOTFOUND)
+		goto out;
+
+	if (image->type == KEXEC_TYPE_CRASH) {
+		/* add linux,elfcorehdr */
+		ret = fdt_appendprop_addrrange(dtb, 0, off,
+				FDT_PROP_KEXEC_ELFHDR,
+				image->arch.elf_headers_mem,
+				image->arch.elf_headers_sz);
+		if (ret)
+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+
+		/* add linux,usable-memory-range */
+		ret = fdt_appendprop_addrrange(dtb, 0, off,
+				FDT_PROP_MEM_RANGE,
+				crashk_res.start,
+				crashk_res.end - crashk_res.start + 1);
+		if (ret)
+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
+	}
+
 	/* add bootargs */
 	if (cmdline) {
 		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
@@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
 }
 
 /*
- * More space needed so that we can add initrd, bootargs, kaslr-seed, and
- * rng-seed.
+ * More space needed so that we can add initrd, bootargs, kaslr-seed,
+ * rng-seed, userable-memory-range and elfcorehdr.
  */
 #define DTB_EXTRA_SPACE 0x1000
 
@@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
 	}
 }
 
+static int prepare_elf_headers(void **addr, unsigned long *sz)
+{
+	struct crash_mem *cmem;
+	unsigned int nr_ranges;
+	int ret;
+	u64 i;
+	phys_addr_t start, end;
+
+	nr_ranges = 1; /* for exclusion of crashkernel region */
+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
+					MEMBLOCK_NONE, &start, &end, NULL)
+		nr_ranges++;
+
+	cmem = kmalloc(sizeof(struct crash_mem) +
+			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
+	if (!cmem)
+		return -ENOMEM;
+
+	cmem->max_nr_ranges = nr_ranges;
+	cmem->nr_ranges = 0;
+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
+					MEMBLOCK_NONE, &start, &end, NULL) {
+		cmem->ranges[cmem->nr_ranges].start = start;
+		cmem->ranges[cmem->nr_ranges].end = end - 1;
+		cmem->nr_ranges++;
+	}
+
+	/* Exclude crashkernel region */
+	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
+
+	if (!ret)
+		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
+
+	kfree(cmem);
+	return ret;
+}
+
 int load_other_segments(struct kimage *image,
 			unsigned long kernel_load_addr,
 			unsigned long kernel_size,
@@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
 			char *cmdline)
 {
 	struct kexec_buf kbuf;
-	void *dtb = NULL;
-	unsigned long initrd_load_addr = 0, dtb_len;
+	void *headers, *dtb = NULL;
+	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
 	int ret = 0;
 
 	kbuf.image = image;
 	/* not allocate anything below the kernel */
 	kbuf.buf_min = kernel_load_addr + kernel_size;
 
+	/* load elf core header */
+	if (image->type == KEXEC_TYPE_CRASH) {
+		ret = prepare_elf_headers(&headers, &headers_sz);
+		if (ret) {
+			pr_err("Preparing elf core header failed\n");
+			goto out_err;
+		}
+
+		kbuf.buffer = headers;
+		kbuf.bufsz = headers_sz;
+		kbuf.mem = 0;
+		kbuf.memsz = headers_sz;
+		kbuf.buf_align = SZ_64K; /* largest supported page size */
+		kbuf.buf_max = ULONG_MAX;
+		kbuf.top_down = true;
+
+		ret = kexec_add_buffer(&kbuf);
+		if (ret) {
+			vfree(headers);
+			goto out_err;
+		}
+		image->arch.elf_headers = headers;
+		image->arch.elf_headers_mem = kbuf.mem;
+		image->arch.elf_headers_sz = headers_sz;
+
+		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
+			 image->arch.elf_headers_mem, headers_sz, headers_sz);
+	}
+
 	/* load initrd */
 	if (initrd) {
 		kbuf.buffer = initrd;
-- 
2.21.0


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 0/3] arm64: kexec_file: add kdump
  2019-11-14  5:15 ` AKASHI Takahiro
  (?)
@ 2019-12-04 20:26   ` Bhupesh Sharma
  -1 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:26 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel

Hi Akashi,

Thanks for the patchset.

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> This is the last piece of my kexec_file_load implementation for arm64.
> It is now ready for being merged as some relevant patch to dtc/libfdt[1]
> has finally been integrated in v5.3-rc1.
> (Nothing changed since kexec_file v16[2] except adding Patch#1 and #2.)
> 
> Patch#1 and #2 are preliminary patches for libfdt component.
> Patch#3 is to add kdump support.
> 
> Bhepesh's patch[3] will be required for 52-bit VA support.
> Once this patch is applied, whether or not CONFIG_ARM64_VA_BITS_52 is
> enabled or not, a matching fix on user space side, crash utility,
> will also be needed.
> 
> Anyway, I tested my patch, at least, with the following configuration:
> 1) CONFIG_ARM64_BITS_48=y
> 2) CONFIG_ARM64_BITS_52=y, but vabits_actual=48
> 
> (I don't have any platform to use for
> 3) CONFIG_ARM64_BITS_52=y, and vabits_actual=52)
> 
> [1] commit 9bb9c6a110ea ("scripts/dtc: Update to upstream version
>      v1.5.0-23-g87963ee20693"), in particular
> 	7fcf8208b8a9 libfdt: add fdt_append_addrrange()
> [2] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-November/612641.html
> [3] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-November/693411.html
> 
> Changes in v2 (Nov 14, 2019)
> * rebased to v5.4-rc7
> * no functional changes

This looks like a step in the right direction. I have some minor 
nitpicks which I have mentioned in the individual patch reviews.

With those addressed (v2?):

Tested-and-Reviewed-by: Bhupesh Sharma <bhsharma@redhat.com>

Thanks,
Bhupesh

> AKASHI Takahiro (3):
>    libfdt: define UINT32_MAX in libfdt_env.h
>    libfdt: include fdt_addresses.c
>    arm64: kexec_file: add crash dump support
> 
>   arch/arm64/include/asm/kexec.h         |   4 +
>   arch/arm64/kernel/kexec_image.c        |   4 -
>   arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
>   include/linux/libfdt_env.h             |   3 +
>   lib/Makefile                           |   2 +-
>   lib/fdt_addresses.c                    |   2 +
>   6 files changed, 112 insertions(+), 9 deletions(-)
>   create mode 100644 lib/fdt_addresses.c
> 


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

* Re: [PATCH v2 0/3] arm64: kexec_file: add kdump
@ 2019-12-04 20:26   ` Bhupesh Sharma
  0 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:26 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-kernel, linux-arm-kernel

Hi Akashi,

Thanks for the patchset.

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> This is the last piece of my kexec_file_load implementation for arm64.
> It is now ready for being merged as some relevant patch to dtc/libfdt[1]
> has finally been integrated in v5.3-rc1.
> (Nothing changed since kexec_file v16[2] except adding Patch#1 and #2.)
> 
> Patch#1 and #2 are preliminary patches for libfdt component.
> Patch#3 is to add kdump support.
> 
> Bhepesh's patch[3] will be required for 52-bit VA support.
> Once this patch is applied, whether or not CONFIG_ARM64_VA_BITS_52 is
> enabled or not, a matching fix on user space side, crash utility,
> will also be needed.
> 
> Anyway, I tested my patch, at least, with the following configuration:
> 1) CONFIG_ARM64_BITS_48=y
> 2) CONFIG_ARM64_BITS_52=y, but vabits_actual=48
> 
> (I don't have any platform to use for
> 3) CONFIG_ARM64_BITS_52=y, and vabits_actual=52)
> 
> [1] commit 9bb9c6a110ea ("scripts/dtc: Update to upstream version
>      v1.5.0-23-g87963ee20693"), in particular
> 	7fcf8208b8a9 libfdt: add fdt_append_addrrange()
> [2] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-November/612641.html
> [3] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-November/693411.html
> 
> Changes in v2 (Nov 14, 2019)
> * rebased to v5.4-rc7
> * no functional changes

This looks like a step in the right direction. I have some minor 
nitpicks which I have mentioned in the individual patch reviews.

With those addressed (v2?):

Tested-and-Reviewed-by: Bhupesh Sharma <bhsharma@redhat.com>

Thanks,
Bhupesh

> AKASHI Takahiro (3):
>    libfdt: define UINT32_MAX in libfdt_env.h
>    libfdt: include fdt_addresses.c
>    arm64: kexec_file: add crash dump support
> 
>   arch/arm64/include/asm/kexec.h         |   4 +
>   arch/arm64/kernel/kexec_image.c        |   4 -
>   arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
>   include/linux/libfdt_env.h             |   3 +
>   lib/Makefile                           |   2 +-
>   lib/fdt_addresses.c                    |   2 +
>   6 files changed, 112 insertions(+), 9 deletions(-)
>   create mode 100644 lib/fdt_addresses.c
> 


_______________________________________________
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] 24+ messages in thread

* Re: [PATCH v2 0/3] arm64: kexec_file: add kdump
@ 2019-12-04 20:26   ` Bhupesh Sharma
  0 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:26 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-kernel, linux-arm-kernel

Hi Akashi,

Thanks for the patchset.

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> This is the last piece of my kexec_file_load implementation for arm64.
> It is now ready for being merged as some relevant patch to dtc/libfdt[1]
> has finally been integrated in v5.3-rc1.
> (Nothing changed since kexec_file v16[2] except adding Patch#1 and #2.)
> 
> Patch#1 and #2 are preliminary patches for libfdt component.
> Patch#3 is to add kdump support.
> 
> Bhepesh's patch[3] will be required for 52-bit VA support.
> Once this patch is applied, whether or not CONFIG_ARM64_VA_BITS_52 is
> enabled or not, a matching fix on user space side, crash utility,
> will also be needed.
> 
> Anyway, I tested my patch, at least, with the following configuration:
> 1) CONFIG_ARM64_BITS_48=y
> 2) CONFIG_ARM64_BITS_52=y, but vabits_actual=48
> 
> (I don't have any platform to use for
> 3) CONFIG_ARM64_BITS_52=y, and vabits_actual=52)
> 
> [1] commit 9bb9c6a110ea ("scripts/dtc: Update to upstream version
>      v1.5.0-23-g87963ee20693"), in particular
> 	7fcf8208b8a9 libfdt: add fdt_append_addrrange()
> [2] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-November/612641.html
> [3] http://lists.infradead.org/pipermail/linux-arm-kernel/2019-November/693411.html
> 
> Changes in v2 (Nov 14, 2019)
> * rebased to v5.4-rc7
> * no functional changes

This looks like a step in the right direction. I have some minor 
nitpicks which I have mentioned in the individual patch reviews.

With those addressed (v2?):

Tested-and-Reviewed-by: Bhupesh Sharma <bhsharma@redhat.com>

Thanks,
Bhupesh

> AKASHI Takahiro (3):
>    libfdt: define UINT32_MAX in libfdt_env.h
>    libfdt: include fdt_addresses.c
>    arm64: kexec_file: add crash dump support
> 
>   arch/arm64/include/asm/kexec.h         |   4 +
>   arch/arm64/kernel/kexec_image.c        |   4 -
>   arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
>   include/linux/libfdt_env.h             |   3 +
>   lib/Makefile                           |   2 +-
>   lib/fdt_addresses.c                    |   2 +
>   6 files changed, 112 insertions(+), 9 deletions(-)
>   create mode 100644 lib/fdt_addresses.c
> 


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 1/3] libfdt: define UINT32_MAX in libfdt_env.h
  2019-11-14  5:15   ` AKASHI Takahiro
  (?)
@ 2019-12-04 20:33     ` Bhupesh Sharma
  -1 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:33 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel

Hi Akashi,

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> In the implementation of kexec_file_load-based kdump for arm64,
> fdt_appendprop_addrrange() will be used, but fdt_addresses.c
> will fail to compile due to missing UINT32_MAX.
> 
> So just define it in libfdt_env.h.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> ---
>   include/linux/libfdt_env.h | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h
> index edb0f0c30904..9ca00f11d9b1 100644
> --- a/include/linux/libfdt_env.h
> +++ b/include/linux/libfdt_env.h
> @@ -3,6 +3,7 @@
>   #define LIBFDT_ENV_H
>   
>   #include <linux/kernel.h>	/* For INT_MAX */
> +#include <linux/limits.h>	/* For UINT32_MAX */
>   #include <linux/string.h>
>   
>   #include <asm/byteorder.h>
> @@ -11,6 +12,8 @@ typedef __be16 fdt16_t;
>   typedef __be32 fdt32_t;
>   typedef __be64 fdt64_t;
>   
> +#define UINT32_MAX U32_MAX
> +
>   #define fdt32_to_cpu(x) be32_to_cpu(x)
>   #define cpu_to_fdt32(x) cpu_to_be32(x)
>   #define fdt64_to_cpu(x) be64_to_cpu(x)
> 

With following upstream patches accepted already in Linus's tree (see 
[0] and [1]), so we can drop this patch from the v3:

[0] 26ed19adbab1 ("libfdt: reduce the number of headers included from 
libfdt_env.h")
[1] a8de1304b7df ("libfdt: define INT32_MAX and UINT32_MAX in libfdt_env.h")

Thanks,
Bhupesh


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

* Re: [PATCH v2 1/3] libfdt: define UINT32_MAX in libfdt_env.h
@ 2019-12-04 20:33     ` Bhupesh Sharma
  0 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:33 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-kernel, linux-arm-kernel

Hi Akashi,

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> In the implementation of kexec_file_load-based kdump for arm64,
> fdt_appendprop_addrrange() will be used, but fdt_addresses.c
> will fail to compile due to missing UINT32_MAX.
> 
> So just define it in libfdt_env.h.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> ---
>   include/linux/libfdt_env.h | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h
> index edb0f0c30904..9ca00f11d9b1 100644
> --- a/include/linux/libfdt_env.h
> +++ b/include/linux/libfdt_env.h
> @@ -3,6 +3,7 @@
>   #define LIBFDT_ENV_H
>   
>   #include <linux/kernel.h>	/* For INT_MAX */
> +#include <linux/limits.h>	/* For UINT32_MAX */
>   #include <linux/string.h>
>   
>   #include <asm/byteorder.h>
> @@ -11,6 +12,8 @@ typedef __be16 fdt16_t;
>   typedef __be32 fdt32_t;
>   typedef __be64 fdt64_t;
>   
> +#define UINT32_MAX U32_MAX
> +
>   #define fdt32_to_cpu(x) be32_to_cpu(x)
>   #define cpu_to_fdt32(x) cpu_to_be32(x)
>   #define fdt64_to_cpu(x) be64_to_cpu(x)
> 

With following upstream patches accepted already in Linus's tree (see 
[0] and [1]), so we can drop this patch from the v3:

[0] 26ed19adbab1 ("libfdt: reduce the number of headers included from 
libfdt_env.h")
[1] a8de1304b7df ("libfdt: define INT32_MAX and UINT32_MAX in libfdt_env.h")

Thanks,
Bhupesh


_______________________________________________
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] 24+ messages in thread

* Re: [PATCH v2 1/3] libfdt: define UINT32_MAX in libfdt_env.h
@ 2019-12-04 20:33     ` Bhupesh Sharma
  0 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:33 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-kernel, linux-arm-kernel

Hi Akashi,

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> In the implementation of kexec_file_load-based kdump for arm64,
> fdt_appendprop_addrrange() will be used, but fdt_addresses.c
> will fail to compile due to missing UINT32_MAX.
> 
> So just define it in libfdt_env.h.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Cc: Rob Herring <robh+dt@kernel.org>
> Cc: Frank Rowand <frowand.list@gmail.com>
> ---
>   include/linux/libfdt_env.h | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h
> index edb0f0c30904..9ca00f11d9b1 100644
> --- a/include/linux/libfdt_env.h
> +++ b/include/linux/libfdt_env.h
> @@ -3,6 +3,7 @@
>   #define LIBFDT_ENV_H
>   
>   #include <linux/kernel.h>	/* For INT_MAX */
> +#include <linux/limits.h>	/* For UINT32_MAX */
>   #include <linux/string.h>
>   
>   #include <asm/byteorder.h>
> @@ -11,6 +12,8 @@ typedef __be16 fdt16_t;
>   typedef __be32 fdt32_t;
>   typedef __be64 fdt64_t;
>   
> +#define UINT32_MAX U32_MAX
> +
>   #define fdt32_to_cpu(x) be32_to_cpu(x)
>   #define cpu_to_fdt32(x) cpu_to_be32(x)
>   #define fdt64_to_cpu(x) be64_to_cpu(x)
> 

With following upstream patches accepted already in Linus's tree (see 
[0] and [1]), so we can drop this patch from the v3:

[0] 26ed19adbab1 ("libfdt: reduce the number of headers included from 
libfdt_env.h")
[1] a8de1304b7df ("libfdt: define INT32_MAX and UINT32_MAX in libfdt_env.h")

Thanks,
Bhupesh


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 3/3] arm64: kexec_file: add crash dump support
  2019-11-14  5:15   ` AKASHI Takahiro
  (?)
@ 2019-12-04 20:44     ` Bhupesh Sharma
  -1 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:44 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: kexec, james.morse, linux-kernel, linux-arm-kernel

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> Enabling crash dump (kdump) includes
> * prepare contents of ELF header of a core dump file, /proc/vmcore,
>    using crash_prepare_elf64_headers(), and
> * add two device tree properties, "linux,usable-memory-range" and
>    "linux,elfcorehdr", which represent respectively a memory range
>    to be used by crash dump kernel and the header's location
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Reviewed-by: James Morse <james.morse@arm.com>
> ---
>   arch/arm64/include/asm/kexec.h         |   4 +
>   arch/arm64/kernel/kexec_image.c        |   4 -
>   arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
>   3 files changed, 106 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
> index 12a561a54128..d24b527e8c00 100644
> --- a/arch/arm64/include/asm/kexec.h
> +++ b/arch/arm64/include/asm/kexec.h
> @@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
>   struct kimage_arch {
>   	void *dtb;
>   	unsigned long dtb_mem;
> +	/* Core ELF header buffer */
> +	void *elf_headers;
> +	unsigned long elf_headers_mem;
> +	unsigned long elf_headers_sz;
>   };
>   
>   extern const struct kexec_file_ops kexec_image_ops;
> diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> index 29a9428486a5..af9987c154ca 100644
> --- a/arch/arm64/kernel/kexec_image.c
> +++ b/arch/arm64/kernel/kexec_image.c
> @@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
>   	struct kexec_segment *kernel_segment;
>   	int ret;
>   
> -	/* We don't support crash kernels yet. */
> -	if (image->type == KEXEC_TYPE_CRASH)
> -		return ERR_PTR(-EOPNOTSUPP);
> -
>   	/*
>   	 * We require a kernel with an unambiguous Image header. Per
>   	 * Documentation/arm64/booting.rst, this is the case when image_size
> diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
> index 7b08bf9499b6..f1d1bb895fd2 100644
> --- a/arch/arm64/kernel/machine_kexec_file.c
> +++ b/arch/arm64/kernel/machine_kexec_file.c
> @@ -17,12 +17,15 @@
>   #include <linux/memblock.h>
>   #include <linux/of_fdt.h>
>   #include <linux/random.h>
> +#include <linux/slab.h>
>   #include <linux/string.h>
>   #include <linux/types.h>
>   #include <linux/vmalloc.h>
>   #include <asm/byteorder.h>
>   
>   /* relevant device tree properties */
> +#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
> +#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
>   #define FDT_PROP_INITRD_START	"linux,initrd-start"
>   #define FDT_PROP_INITRD_END	"linux,initrd-end"
>   #define FDT_PROP_BOOTARGS	"bootargs"
> @@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
>   	vfree(image->arch.dtb);
>   	image->arch.dtb = NULL;
>   
> +	vfree(image->arch.elf_headers);
> +	image->arch.elf_headers = NULL;
> +	image->arch.elf_headers_sz = 0;
> +
>   	return kexec_image_post_load_cleanup_default(image);
>   }
>   
> @@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
>   
>   	off = ret;
>   
> +	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
> +	if (ret && ret != -FDT_ERR_NOTFOUND)
> +		goto out;
> +	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
> +	if (ret && ret != -FDT_ERR_NOTFOUND)
> +		goto out;
> +
> +	if (image->type == KEXEC_TYPE_CRASH) {
> +		/* add linux,elfcorehdr */
> +		ret = fdt_appendprop_addrrange(dtb, 0, off,
> +				FDT_PROP_KEXEC_ELFHDR,
> +				image->arch.elf_headers_mem,
> +				image->arch.elf_headers_sz);
> +		if (ret)
> +			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> +
> +		/* add linux,usable-memory-range */
> +		ret = fdt_appendprop_addrrange(dtb, 0, off,
> +				FDT_PROP_MEM_RANGE,
> +				crashk_res.start,
> +				crashk_res.end - crashk_res.start + 1);
> +		if (ret)
> +			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> +	}
> +
>   	/* add bootargs */
>   	if (cmdline) {
>   		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
> @@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
>   }
>   
>   /*
> - * More space needed so that we can add initrd, bootargs, kaslr-seed, and
> - * rng-seed.
> + * More space needed so that we can add initrd, bootargs, kaslr-seed,
> + * rng-seed, userable-memory-range and elfcorehdr.

nitpick:
s/userable-memory-range/usable-memory-range

>    */
>   #define DTB_EXTRA_SPACE 0x1000
>   
> @@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
>   	}
>   }
>   
> +static int prepare_elf_headers(void **addr, unsigned long *sz)
> +{
> +	struct crash_mem *cmem;
> +	unsigned int nr_ranges;
> +	int ret;
> +	u64 i;
> +	phys_addr_t start, end;
> +
> +	nr_ranges = 1; /* for exclusion of crashkernel region */
> +	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> +					MEMBLOCK_NONE, &start, &end, NULL)
> +		nr_ranges++;
> +
> +	cmem = kmalloc(sizeof(struct crash_mem) +
> +			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
> +	if (!cmem)
> +		return -ENOMEM;
> +
> +	cmem->max_nr_ranges = nr_ranges;
> +	cmem->nr_ranges = 0;
> +	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> +					MEMBLOCK_NONE, &start, &end, NULL) {
> +		cmem->ranges[cmem->nr_ranges].start = start;
> +		cmem->ranges[cmem->nr_ranges].end = end - 1;
> +		cmem->nr_ranges++;
> +	}
> +
> +	/* Exclude crashkernel region */
> +	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
> +
> +	if (!ret)
> +		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
> +
> +	kfree(cmem);
> +	return ret;
> +}
> +
>   int load_other_segments(struct kimage *image,
>   			unsigned long kernel_load_addr,
>   			unsigned long kernel_size,
> @@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
>   			char *cmdline)
>   {
>   	struct kexec_buf kbuf;
> -	void *dtb = NULL;
> -	unsigned long initrd_load_addr = 0, dtb_len;
> +	void *headers, *dtb = NULL;
> +	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
>   	int ret = 0;
>   
>   	kbuf.image = image;
>   	/* not allocate anything below the kernel */
>   	kbuf.buf_min = kernel_load_addr + kernel_size;
>   
> +	/* load elf core header */
> +	if (image->type == KEXEC_TYPE_CRASH) {
> +		ret = prepare_elf_headers(&headers, &headers_sz);
> +		if (ret) {
> +			pr_err("Preparing elf core header failed\n");
> +			goto out_err;
> +		}
> +
> +		kbuf.buffer = headers;
> +		kbuf.bufsz = headers_sz;
> +		kbuf.mem = 0;

With commit c19d050f8088 ("arm64/kexec: Use consistent convention of 
initializing 'kxec_buf.mem' with KEXEC_BUF_MEM_UNKNOWN"), we are trying 
to standardize the way of setting up initial value of 'kbuf.mem'. So we 
can use the following notion (in v3?) instead:
		kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;

> +		kbuf.memsz = headers_sz;
> +		kbuf.buf_align = SZ_64K; /* largest supported page size */
> +		kbuf.buf_max = ULONG_MAX;
> +		kbuf.top_down = true;
> +
> +		ret = kexec_add_buffer(&kbuf);
> +		if (ret) {
> +			vfree(headers);
> +			goto out_err;
> +		}
> +		image->arch.elf_headers = headers;
> +		image->arch.elf_headers_mem = kbuf.mem;
> +		image->arch.elf_headers_sz = headers_sz;
> +
> +		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
> +			 image->arch.elf_headers_mem, headers_sz, headers_sz);
> +	}
> +
>   	/* load initrd */
>   	if (initrd) {
>   		kbuf.buffer = initrd;
> 

Thanks,
Bhupesh


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

* Re: [PATCH v2 3/3] arm64: kexec_file: add crash dump support
@ 2019-12-04 20:44     ` Bhupesh Sharma
  0 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:44 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-kernel, linux-arm-kernel

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> Enabling crash dump (kdump) includes
> * prepare contents of ELF header of a core dump file, /proc/vmcore,
>    using crash_prepare_elf64_headers(), and
> * add two device tree properties, "linux,usable-memory-range" and
>    "linux,elfcorehdr", which represent respectively a memory range
>    to be used by crash dump kernel and the header's location
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Reviewed-by: James Morse <james.morse@arm.com>
> ---
>   arch/arm64/include/asm/kexec.h         |   4 +
>   arch/arm64/kernel/kexec_image.c        |   4 -
>   arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
>   3 files changed, 106 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
> index 12a561a54128..d24b527e8c00 100644
> --- a/arch/arm64/include/asm/kexec.h
> +++ b/arch/arm64/include/asm/kexec.h
> @@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
>   struct kimage_arch {
>   	void *dtb;
>   	unsigned long dtb_mem;
> +	/* Core ELF header buffer */
> +	void *elf_headers;
> +	unsigned long elf_headers_mem;
> +	unsigned long elf_headers_sz;
>   };
>   
>   extern const struct kexec_file_ops kexec_image_ops;
> diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> index 29a9428486a5..af9987c154ca 100644
> --- a/arch/arm64/kernel/kexec_image.c
> +++ b/arch/arm64/kernel/kexec_image.c
> @@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
>   	struct kexec_segment *kernel_segment;
>   	int ret;
>   
> -	/* We don't support crash kernels yet. */
> -	if (image->type == KEXEC_TYPE_CRASH)
> -		return ERR_PTR(-EOPNOTSUPP);
> -
>   	/*
>   	 * We require a kernel with an unambiguous Image header. Per
>   	 * Documentation/arm64/booting.rst, this is the case when image_size
> diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
> index 7b08bf9499b6..f1d1bb895fd2 100644
> --- a/arch/arm64/kernel/machine_kexec_file.c
> +++ b/arch/arm64/kernel/machine_kexec_file.c
> @@ -17,12 +17,15 @@
>   #include <linux/memblock.h>
>   #include <linux/of_fdt.h>
>   #include <linux/random.h>
> +#include <linux/slab.h>
>   #include <linux/string.h>
>   #include <linux/types.h>
>   #include <linux/vmalloc.h>
>   #include <asm/byteorder.h>
>   
>   /* relevant device tree properties */
> +#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
> +#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
>   #define FDT_PROP_INITRD_START	"linux,initrd-start"
>   #define FDT_PROP_INITRD_END	"linux,initrd-end"
>   #define FDT_PROP_BOOTARGS	"bootargs"
> @@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
>   	vfree(image->arch.dtb);
>   	image->arch.dtb = NULL;
>   
> +	vfree(image->arch.elf_headers);
> +	image->arch.elf_headers = NULL;
> +	image->arch.elf_headers_sz = 0;
> +
>   	return kexec_image_post_load_cleanup_default(image);
>   }
>   
> @@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
>   
>   	off = ret;
>   
> +	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
> +	if (ret && ret != -FDT_ERR_NOTFOUND)
> +		goto out;
> +	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
> +	if (ret && ret != -FDT_ERR_NOTFOUND)
> +		goto out;
> +
> +	if (image->type == KEXEC_TYPE_CRASH) {
> +		/* add linux,elfcorehdr */
> +		ret = fdt_appendprop_addrrange(dtb, 0, off,
> +				FDT_PROP_KEXEC_ELFHDR,
> +				image->arch.elf_headers_mem,
> +				image->arch.elf_headers_sz);
> +		if (ret)
> +			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> +
> +		/* add linux,usable-memory-range */
> +		ret = fdt_appendprop_addrrange(dtb, 0, off,
> +				FDT_PROP_MEM_RANGE,
> +				crashk_res.start,
> +				crashk_res.end - crashk_res.start + 1);
> +		if (ret)
> +			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> +	}
> +
>   	/* add bootargs */
>   	if (cmdline) {
>   		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
> @@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
>   }
>   
>   /*
> - * More space needed so that we can add initrd, bootargs, kaslr-seed, and
> - * rng-seed.
> + * More space needed so that we can add initrd, bootargs, kaslr-seed,
> + * rng-seed, userable-memory-range and elfcorehdr.

nitpick:
s/userable-memory-range/usable-memory-range

>    */
>   #define DTB_EXTRA_SPACE 0x1000
>   
> @@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
>   	}
>   }
>   
> +static int prepare_elf_headers(void **addr, unsigned long *sz)
> +{
> +	struct crash_mem *cmem;
> +	unsigned int nr_ranges;
> +	int ret;
> +	u64 i;
> +	phys_addr_t start, end;
> +
> +	nr_ranges = 1; /* for exclusion of crashkernel region */
> +	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> +					MEMBLOCK_NONE, &start, &end, NULL)
> +		nr_ranges++;
> +
> +	cmem = kmalloc(sizeof(struct crash_mem) +
> +			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
> +	if (!cmem)
> +		return -ENOMEM;
> +
> +	cmem->max_nr_ranges = nr_ranges;
> +	cmem->nr_ranges = 0;
> +	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> +					MEMBLOCK_NONE, &start, &end, NULL) {
> +		cmem->ranges[cmem->nr_ranges].start = start;
> +		cmem->ranges[cmem->nr_ranges].end = end - 1;
> +		cmem->nr_ranges++;
> +	}
> +
> +	/* Exclude crashkernel region */
> +	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
> +
> +	if (!ret)
> +		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
> +
> +	kfree(cmem);
> +	return ret;
> +}
> +
>   int load_other_segments(struct kimage *image,
>   			unsigned long kernel_load_addr,
>   			unsigned long kernel_size,
> @@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
>   			char *cmdline)
>   {
>   	struct kexec_buf kbuf;
> -	void *dtb = NULL;
> -	unsigned long initrd_load_addr = 0, dtb_len;
> +	void *headers, *dtb = NULL;
> +	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
>   	int ret = 0;
>   
>   	kbuf.image = image;
>   	/* not allocate anything below the kernel */
>   	kbuf.buf_min = kernel_load_addr + kernel_size;
>   
> +	/* load elf core header */
> +	if (image->type == KEXEC_TYPE_CRASH) {
> +		ret = prepare_elf_headers(&headers, &headers_sz);
> +		if (ret) {
> +			pr_err("Preparing elf core header failed\n");
> +			goto out_err;
> +		}
> +
> +		kbuf.buffer = headers;
> +		kbuf.bufsz = headers_sz;
> +		kbuf.mem = 0;

With commit c19d050f8088 ("arm64/kexec: Use consistent convention of 
initializing 'kxec_buf.mem' with KEXEC_BUF_MEM_UNKNOWN"), we are trying 
to standardize the way of setting up initial value of 'kbuf.mem'. So we 
can use the following notion (in v3?) instead:
		kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;

> +		kbuf.memsz = headers_sz;
> +		kbuf.buf_align = SZ_64K; /* largest supported page size */
> +		kbuf.buf_max = ULONG_MAX;
> +		kbuf.top_down = true;
> +
> +		ret = kexec_add_buffer(&kbuf);
> +		if (ret) {
> +			vfree(headers);
> +			goto out_err;
> +		}
> +		image->arch.elf_headers = headers;
> +		image->arch.elf_headers_mem = kbuf.mem;
> +		image->arch.elf_headers_sz = headers_sz;
> +
> +		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
> +			 image->arch.elf_headers_mem, headers_sz, headers_sz);
> +	}
> +
>   	/* load initrd */
>   	if (initrd) {
>   		kbuf.buffer = initrd;
> 

Thanks,
Bhupesh


_______________________________________________
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] 24+ messages in thread

* Re: [PATCH v2 3/3] arm64: kexec_file: add crash dump support
@ 2019-12-04 20:44     ` Bhupesh Sharma
  0 siblings, 0 replies; 24+ messages in thread
From: Bhupesh Sharma @ 2019-12-04 20:44 UTC (permalink / raw)
  To: AKASHI Takahiro, catalin.marinas, will.deacon, robh+dt, frowand.list
  Cc: james.morse, kexec, linux-kernel, linux-arm-kernel

On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> Enabling crash dump (kdump) includes
> * prepare contents of ELF header of a core dump file, /proc/vmcore,
>    using crash_prepare_elf64_headers(), and
> * add two device tree properties, "linux,usable-memory-range" and
>    "linux,elfcorehdr", which represent respectively a memory range
>    to be used by crash dump kernel and the header's location
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Reviewed-by: James Morse <james.morse@arm.com>
> ---
>   arch/arm64/include/asm/kexec.h         |   4 +
>   arch/arm64/kernel/kexec_image.c        |   4 -
>   arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
>   3 files changed, 106 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
> index 12a561a54128..d24b527e8c00 100644
> --- a/arch/arm64/include/asm/kexec.h
> +++ b/arch/arm64/include/asm/kexec.h
> @@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
>   struct kimage_arch {
>   	void *dtb;
>   	unsigned long dtb_mem;
> +	/* Core ELF header buffer */
> +	void *elf_headers;
> +	unsigned long elf_headers_mem;
> +	unsigned long elf_headers_sz;
>   };
>   
>   extern const struct kexec_file_ops kexec_image_ops;
> diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> index 29a9428486a5..af9987c154ca 100644
> --- a/arch/arm64/kernel/kexec_image.c
> +++ b/arch/arm64/kernel/kexec_image.c
> @@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
>   	struct kexec_segment *kernel_segment;
>   	int ret;
>   
> -	/* We don't support crash kernels yet. */
> -	if (image->type == KEXEC_TYPE_CRASH)
> -		return ERR_PTR(-EOPNOTSUPP);
> -
>   	/*
>   	 * We require a kernel with an unambiguous Image header. Per
>   	 * Documentation/arm64/booting.rst, this is the case when image_size
> diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
> index 7b08bf9499b6..f1d1bb895fd2 100644
> --- a/arch/arm64/kernel/machine_kexec_file.c
> +++ b/arch/arm64/kernel/machine_kexec_file.c
> @@ -17,12 +17,15 @@
>   #include <linux/memblock.h>
>   #include <linux/of_fdt.h>
>   #include <linux/random.h>
> +#include <linux/slab.h>
>   #include <linux/string.h>
>   #include <linux/types.h>
>   #include <linux/vmalloc.h>
>   #include <asm/byteorder.h>
>   
>   /* relevant device tree properties */
> +#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
> +#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
>   #define FDT_PROP_INITRD_START	"linux,initrd-start"
>   #define FDT_PROP_INITRD_END	"linux,initrd-end"
>   #define FDT_PROP_BOOTARGS	"bootargs"
> @@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
>   	vfree(image->arch.dtb);
>   	image->arch.dtb = NULL;
>   
> +	vfree(image->arch.elf_headers);
> +	image->arch.elf_headers = NULL;
> +	image->arch.elf_headers_sz = 0;
> +
>   	return kexec_image_post_load_cleanup_default(image);
>   }
>   
> @@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
>   
>   	off = ret;
>   
> +	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
> +	if (ret && ret != -FDT_ERR_NOTFOUND)
> +		goto out;
> +	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
> +	if (ret && ret != -FDT_ERR_NOTFOUND)
> +		goto out;
> +
> +	if (image->type == KEXEC_TYPE_CRASH) {
> +		/* add linux,elfcorehdr */
> +		ret = fdt_appendprop_addrrange(dtb, 0, off,
> +				FDT_PROP_KEXEC_ELFHDR,
> +				image->arch.elf_headers_mem,
> +				image->arch.elf_headers_sz);
> +		if (ret)
> +			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> +
> +		/* add linux,usable-memory-range */
> +		ret = fdt_appendprop_addrrange(dtb, 0, off,
> +				FDT_PROP_MEM_RANGE,
> +				crashk_res.start,
> +				crashk_res.end - crashk_res.start + 1);
> +		if (ret)
> +			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> +	}
> +
>   	/* add bootargs */
>   	if (cmdline) {
>   		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
> @@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
>   }
>   
>   /*
> - * More space needed so that we can add initrd, bootargs, kaslr-seed, and
> - * rng-seed.
> + * More space needed so that we can add initrd, bootargs, kaslr-seed,
> + * rng-seed, userable-memory-range and elfcorehdr.

nitpick:
s/userable-memory-range/usable-memory-range

>    */
>   #define DTB_EXTRA_SPACE 0x1000
>   
> @@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
>   	}
>   }
>   
> +static int prepare_elf_headers(void **addr, unsigned long *sz)
> +{
> +	struct crash_mem *cmem;
> +	unsigned int nr_ranges;
> +	int ret;
> +	u64 i;
> +	phys_addr_t start, end;
> +
> +	nr_ranges = 1; /* for exclusion of crashkernel region */
> +	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> +					MEMBLOCK_NONE, &start, &end, NULL)
> +		nr_ranges++;
> +
> +	cmem = kmalloc(sizeof(struct crash_mem) +
> +			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
> +	if (!cmem)
> +		return -ENOMEM;
> +
> +	cmem->max_nr_ranges = nr_ranges;
> +	cmem->nr_ranges = 0;
> +	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> +					MEMBLOCK_NONE, &start, &end, NULL) {
> +		cmem->ranges[cmem->nr_ranges].start = start;
> +		cmem->ranges[cmem->nr_ranges].end = end - 1;
> +		cmem->nr_ranges++;
> +	}
> +
> +	/* Exclude crashkernel region */
> +	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
> +
> +	if (!ret)
> +		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
> +
> +	kfree(cmem);
> +	return ret;
> +}
> +
>   int load_other_segments(struct kimage *image,
>   			unsigned long kernel_load_addr,
>   			unsigned long kernel_size,
> @@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
>   			char *cmdline)
>   {
>   	struct kexec_buf kbuf;
> -	void *dtb = NULL;
> -	unsigned long initrd_load_addr = 0, dtb_len;
> +	void *headers, *dtb = NULL;
> +	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
>   	int ret = 0;
>   
>   	kbuf.image = image;
>   	/* not allocate anything below the kernel */
>   	kbuf.buf_min = kernel_load_addr + kernel_size;
>   
> +	/* load elf core header */
> +	if (image->type == KEXEC_TYPE_CRASH) {
> +		ret = prepare_elf_headers(&headers, &headers_sz);
> +		if (ret) {
> +			pr_err("Preparing elf core header failed\n");
> +			goto out_err;
> +		}
> +
> +		kbuf.buffer = headers;
> +		kbuf.bufsz = headers_sz;
> +		kbuf.mem = 0;

With commit c19d050f8088 ("arm64/kexec: Use consistent convention of 
initializing 'kxec_buf.mem' with KEXEC_BUF_MEM_UNKNOWN"), we are trying 
to standardize the way of setting up initial value of 'kbuf.mem'. So we 
can use the following notion (in v3?) instead:
		kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;

> +		kbuf.memsz = headers_sz;
> +		kbuf.buf_align = SZ_64K; /* largest supported page size */
> +		kbuf.buf_max = ULONG_MAX;
> +		kbuf.top_down = true;
> +
> +		ret = kexec_add_buffer(&kbuf);
> +		if (ret) {
> +			vfree(headers);
> +			goto out_err;
> +		}
> +		image->arch.elf_headers = headers;
> +		image->arch.elf_headers_mem = kbuf.mem;
> +		image->arch.elf_headers_sz = headers_sz;
> +
> +		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
> +			 image->arch.elf_headers_mem, headers_sz, headers_sz);
> +	}
> +
>   	/* load initrd */
>   	if (initrd) {
>   		kbuf.buffer = initrd;
> 

Thanks,
Bhupesh


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 3/3] arm64: kexec_file: add crash dump support
  2019-12-04 20:44     ` Bhupesh Sharma
  (?)
@ 2019-12-16  1:43       ` AKASHI Takahiro
  -1 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-12-16  1:43 UTC (permalink / raw)
  To: Bhupesh Sharma
  Cc: catalin.marinas, will.deacon, robh+dt, frowand.list, kexec,
	james.morse, linux-kernel, linux-arm-kernel

I have forgot to address Bhupesh's comment below in my v3.
I'm going to repost my patch.

Thank you, Bhupesh, for your review.

-Takahiro Akashi

On Thu, Dec 05, 2019 at 02:14:14AM +0530, Bhupesh Sharma wrote:
> On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> >Enabling crash dump (kdump) includes
> >* prepare contents of ELF header of a core dump file, /proc/vmcore,
> >   using crash_prepare_elf64_headers(), and
> >* add two device tree properties, "linux,usable-memory-range" and
> >   "linux,elfcorehdr", which represent respectively a memory range
> >   to be used by crash dump kernel and the header's location
> >
> >Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> >Cc: Catalin Marinas <catalin.marinas@arm.com>
> >Cc: Will Deacon <will.deacon@arm.com>
> >Reviewed-by: James Morse <james.morse@arm.com>
> >---
> >  arch/arm64/include/asm/kexec.h         |   4 +
> >  arch/arm64/kernel/kexec_image.c        |   4 -
> >  arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
> >  3 files changed, 106 insertions(+), 8 deletions(-)
> >
> >diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
> >index 12a561a54128..d24b527e8c00 100644
> >--- a/arch/arm64/include/asm/kexec.h
> >+++ b/arch/arm64/include/asm/kexec.h
> >@@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
> >  struct kimage_arch {
> >  	void *dtb;
> >  	unsigned long dtb_mem;
> >+	/* Core ELF header buffer */
> >+	void *elf_headers;
> >+	unsigned long elf_headers_mem;
> >+	unsigned long elf_headers_sz;
> >  };
> >  extern const struct kexec_file_ops kexec_image_ops;
> >diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> >index 29a9428486a5..af9987c154ca 100644
> >--- a/arch/arm64/kernel/kexec_image.c
> >+++ b/arch/arm64/kernel/kexec_image.c
> >@@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
> >  	struct kexec_segment *kernel_segment;
> >  	int ret;
> >-	/* We don't support crash kernels yet. */
> >-	if (image->type == KEXEC_TYPE_CRASH)
> >-		return ERR_PTR(-EOPNOTSUPP);
> >-
> >  	/*
> >  	 * We require a kernel with an unambiguous Image header. Per
> >  	 * Documentation/arm64/booting.rst, this is the case when image_size
> >diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
> >index 7b08bf9499b6..f1d1bb895fd2 100644
> >--- a/arch/arm64/kernel/machine_kexec_file.c
> >+++ b/arch/arm64/kernel/machine_kexec_file.c
> >@@ -17,12 +17,15 @@
> >  #include <linux/memblock.h>
> >  #include <linux/of_fdt.h>
> >  #include <linux/random.h>
> >+#include <linux/slab.h>
> >  #include <linux/string.h>
> >  #include <linux/types.h>
> >  #include <linux/vmalloc.h>
> >  #include <asm/byteorder.h>
> >  /* relevant device tree properties */
> >+#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
> >+#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
> >  #define FDT_PROP_INITRD_START	"linux,initrd-start"
> >  #define FDT_PROP_INITRD_END	"linux,initrd-end"
> >  #define FDT_PROP_BOOTARGS	"bootargs"
> >@@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
> >  	vfree(image->arch.dtb);
> >  	image->arch.dtb = NULL;
> >+	vfree(image->arch.elf_headers);
> >+	image->arch.elf_headers = NULL;
> >+	image->arch.elf_headers_sz = 0;
> >+
> >  	return kexec_image_post_load_cleanup_default(image);
> >  }
> >@@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
> >  	off = ret;
> >+	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
> >+	if (ret && ret != -FDT_ERR_NOTFOUND)
> >+		goto out;
> >+	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
> >+	if (ret && ret != -FDT_ERR_NOTFOUND)
> >+		goto out;
> >+
> >+	if (image->type == KEXEC_TYPE_CRASH) {
> >+		/* add linux,elfcorehdr */
> >+		ret = fdt_appendprop_addrrange(dtb, 0, off,
> >+				FDT_PROP_KEXEC_ELFHDR,
> >+				image->arch.elf_headers_mem,
> >+				image->arch.elf_headers_sz);
> >+		if (ret)
> >+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> >+
> >+		/* add linux,usable-memory-range */
> >+		ret = fdt_appendprop_addrrange(dtb, 0, off,
> >+				FDT_PROP_MEM_RANGE,
> >+				crashk_res.start,
> >+				crashk_res.end - crashk_res.start + 1);
> >+		if (ret)
> >+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> >+	}
> >+
> >  	/* add bootargs */
> >  	if (cmdline) {
> >  		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
> >@@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
> >  }
> >  /*
> >- * More space needed so that we can add initrd, bootargs, kaslr-seed, and
> >- * rng-seed.
> >+ * More space needed so that we can add initrd, bootargs, kaslr-seed,
> >+ * rng-seed, userable-memory-range and elfcorehdr.
> 
> nitpick:
> s/userable-memory-range/usable-memory-range
> 
> >   */
> >  #define DTB_EXTRA_SPACE 0x1000
> >@@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
> >  	}
> >  }
> >+static int prepare_elf_headers(void **addr, unsigned long *sz)
> >+{
> >+	struct crash_mem *cmem;
> >+	unsigned int nr_ranges;
> >+	int ret;
> >+	u64 i;
> >+	phys_addr_t start, end;
> >+
> >+	nr_ranges = 1; /* for exclusion of crashkernel region */
> >+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> >+					MEMBLOCK_NONE, &start, &end, NULL)
> >+		nr_ranges++;
> >+
> >+	cmem = kmalloc(sizeof(struct crash_mem) +
> >+			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
> >+	if (!cmem)
> >+		return -ENOMEM;
> >+
> >+	cmem->max_nr_ranges = nr_ranges;
> >+	cmem->nr_ranges = 0;
> >+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> >+					MEMBLOCK_NONE, &start, &end, NULL) {
> >+		cmem->ranges[cmem->nr_ranges].start = start;
> >+		cmem->ranges[cmem->nr_ranges].end = end - 1;
> >+		cmem->nr_ranges++;
> >+	}
> >+
> >+	/* Exclude crashkernel region */
> >+	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
> >+
> >+	if (!ret)
> >+		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
> >+
> >+	kfree(cmem);
> >+	return ret;
> >+}
> >+
> >  int load_other_segments(struct kimage *image,
> >  			unsigned long kernel_load_addr,
> >  			unsigned long kernel_size,
> >@@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
> >  			char *cmdline)
> >  {
> >  	struct kexec_buf kbuf;
> >-	void *dtb = NULL;
> >-	unsigned long initrd_load_addr = 0, dtb_len;
> >+	void *headers, *dtb = NULL;
> >+	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
> >  	int ret = 0;
> >  	kbuf.image = image;
> >  	/* not allocate anything below the kernel */
> >  	kbuf.buf_min = kernel_load_addr + kernel_size;
> >+	/* load elf core header */
> >+	if (image->type == KEXEC_TYPE_CRASH) {
> >+		ret = prepare_elf_headers(&headers, &headers_sz);
> >+		if (ret) {
> >+			pr_err("Preparing elf core header failed\n");
> >+			goto out_err;
> >+		}
> >+
> >+		kbuf.buffer = headers;
> >+		kbuf.bufsz = headers_sz;
> >+		kbuf.mem = 0;
> 
> With commit c19d050f8088 ("arm64/kexec: Use consistent convention of
> initializing 'kxec_buf.mem' with KEXEC_BUF_MEM_UNKNOWN"), we are trying to
> standardize the way of setting up initial value of 'kbuf.mem'. So we can use
> the following notion (in v3?) instead:
> 		kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
> 
> >+		kbuf.memsz = headers_sz;
> >+		kbuf.buf_align = SZ_64K; /* largest supported page size */
> >+		kbuf.buf_max = ULONG_MAX;
> >+		kbuf.top_down = true;
> >+
> >+		ret = kexec_add_buffer(&kbuf);
> >+		if (ret) {
> >+			vfree(headers);
> >+			goto out_err;
> >+		}
> >+		image->arch.elf_headers = headers;
> >+		image->arch.elf_headers_mem = kbuf.mem;
> >+		image->arch.elf_headers_sz = headers_sz;
> >+
> >+		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
> >+			 image->arch.elf_headers_mem, headers_sz, headers_sz);
> >+	}
> >+
> >  	/* load initrd */
> >  	if (initrd) {
> >  		kbuf.buffer = initrd;
> >
> 
> Thanks,
> Bhupesh
> 

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

* Re: [PATCH v2 3/3] arm64: kexec_file: add crash dump support
@ 2019-12-16  1:43       ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-12-16  1:43 UTC (permalink / raw)
  To: Bhupesh Sharma
  Cc: catalin.marinas, will.deacon, linux-kernel, robh+dt, james.morse,
	frowand.list, kexec, linux-arm-kernel

I have forgot to address Bhupesh's comment below in my v3.
I'm going to repost my patch.

Thank you, Bhupesh, for your review.

-Takahiro Akashi

On Thu, Dec 05, 2019 at 02:14:14AM +0530, Bhupesh Sharma wrote:
> On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> >Enabling crash dump (kdump) includes
> >* prepare contents of ELF header of a core dump file, /proc/vmcore,
> >   using crash_prepare_elf64_headers(), and
> >* add two device tree properties, "linux,usable-memory-range" and
> >   "linux,elfcorehdr", which represent respectively a memory range
> >   to be used by crash dump kernel and the header's location
> >
> >Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> >Cc: Catalin Marinas <catalin.marinas@arm.com>
> >Cc: Will Deacon <will.deacon@arm.com>
> >Reviewed-by: James Morse <james.morse@arm.com>
> >---
> >  arch/arm64/include/asm/kexec.h         |   4 +
> >  arch/arm64/kernel/kexec_image.c        |   4 -
> >  arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
> >  3 files changed, 106 insertions(+), 8 deletions(-)
> >
> >diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
> >index 12a561a54128..d24b527e8c00 100644
> >--- a/arch/arm64/include/asm/kexec.h
> >+++ b/arch/arm64/include/asm/kexec.h
> >@@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
> >  struct kimage_arch {
> >  	void *dtb;
> >  	unsigned long dtb_mem;
> >+	/* Core ELF header buffer */
> >+	void *elf_headers;
> >+	unsigned long elf_headers_mem;
> >+	unsigned long elf_headers_sz;
> >  };
> >  extern const struct kexec_file_ops kexec_image_ops;
> >diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> >index 29a9428486a5..af9987c154ca 100644
> >--- a/arch/arm64/kernel/kexec_image.c
> >+++ b/arch/arm64/kernel/kexec_image.c
> >@@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
> >  	struct kexec_segment *kernel_segment;
> >  	int ret;
> >-	/* We don't support crash kernels yet. */
> >-	if (image->type == KEXEC_TYPE_CRASH)
> >-		return ERR_PTR(-EOPNOTSUPP);
> >-
> >  	/*
> >  	 * We require a kernel with an unambiguous Image header. Per
> >  	 * Documentation/arm64/booting.rst, this is the case when image_size
> >diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
> >index 7b08bf9499b6..f1d1bb895fd2 100644
> >--- a/arch/arm64/kernel/machine_kexec_file.c
> >+++ b/arch/arm64/kernel/machine_kexec_file.c
> >@@ -17,12 +17,15 @@
> >  #include <linux/memblock.h>
> >  #include <linux/of_fdt.h>
> >  #include <linux/random.h>
> >+#include <linux/slab.h>
> >  #include <linux/string.h>
> >  #include <linux/types.h>
> >  #include <linux/vmalloc.h>
> >  #include <asm/byteorder.h>
> >  /* relevant device tree properties */
> >+#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
> >+#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
> >  #define FDT_PROP_INITRD_START	"linux,initrd-start"
> >  #define FDT_PROP_INITRD_END	"linux,initrd-end"
> >  #define FDT_PROP_BOOTARGS	"bootargs"
> >@@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
> >  	vfree(image->arch.dtb);
> >  	image->arch.dtb = NULL;
> >+	vfree(image->arch.elf_headers);
> >+	image->arch.elf_headers = NULL;
> >+	image->arch.elf_headers_sz = 0;
> >+
> >  	return kexec_image_post_load_cleanup_default(image);
> >  }
> >@@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
> >  	off = ret;
> >+	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
> >+	if (ret && ret != -FDT_ERR_NOTFOUND)
> >+		goto out;
> >+	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
> >+	if (ret && ret != -FDT_ERR_NOTFOUND)
> >+		goto out;
> >+
> >+	if (image->type == KEXEC_TYPE_CRASH) {
> >+		/* add linux,elfcorehdr */
> >+		ret = fdt_appendprop_addrrange(dtb, 0, off,
> >+				FDT_PROP_KEXEC_ELFHDR,
> >+				image->arch.elf_headers_mem,
> >+				image->arch.elf_headers_sz);
> >+		if (ret)
> >+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> >+
> >+		/* add linux,usable-memory-range */
> >+		ret = fdt_appendprop_addrrange(dtb, 0, off,
> >+				FDT_PROP_MEM_RANGE,
> >+				crashk_res.start,
> >+				crashk_res.end - crashk_res.start + 1);
> >+		if (ret)
> >+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> >+	}
> >+
> >  	/* add bootargs */
> >  	if (cmdline) {
> >  		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
> >@@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
> >  }
> >  /*
> >- * More space needed so that we can add initrd, bootargs, kaslr-seed, and
> >- * rng-seed.
> >+ * More space needed so that we can add initrd, bootargs, kaslr-seed,
> >+ * rng-seed, userable-memory-range and elfcorehdr.
> 
> nitpick:
> s/userable-memory-range/usable-memory-range
> 
> >   */
> >  #define DTB_EXTRA_SPACE 0x1000
> >@@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
> >  	}
> >  }
> >+static int prepare_elf_headers(void **addr, unsigned long *sz)
> >+{
> >+	struct crash_mem *cmem;
> >+	unsigned int nr_ranges;
> >+	int ret;
> >+	u64 i;
> >+	phys_addr_t start, end;
> >+
> >+	nr_ranges = 1; /* for exclusion of crashkernel region */
> >+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> >+					MEMBLOCK_NONE, &start, &end, NULL)
> >+		nr_ranges++;
> >+
> >+	cmem = kmalloc(sizeof(struct crash_mem) +
> >+			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
> >+	if (!cmem)
> >+		return -ENOMEM;
> >+
> >+	cmem->max_nr_ranges = nr_ranges;
> >+	cmem->nr_ranges = 0;
> >+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> >+					MEMBLOCK_NONE, &start, &end, NULL) {
> >+		cmem->ranges[cmem->nr_ranges].start = start;
> >+		cmem->ranges[cmem->nr_ranges].end = end - 1;
> >+		cmem->nr_ranges++;
> >+	}
> >+
> >+	/* Exclude crashkernel region */
> >+	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
> >+
> >+	if (!ret)
> >+		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
> >+
> >+	kfree(cmem);
> >+	return ret;
> >+}
> >+
> >  int load_other_segments(struct kimage *image,
> >  			unsigned long kernel_load_addr,
> >  			unsigned long kernel_size,
> >@@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
> >  			char *cmdline)
> >  {
> >  	struct kexec_buf kbuf;
> >-	void *dtb = NULL;
> >-	unsigned long initrd_load_addr = 0, dtb_len;
> >+	void *headers, *dtb = NULL;
> >+	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
> >  	int ret = 0;
> >  	kbuf.image = image;
> >  	/* not allocate anything below the kernel */
> >  	kbuf.buf_min = kernel_load_addr + kernel_size;
> >+	/* load elf core header */
> >+	if (image->type == KEXEC_TYPE_CRASH) {
> >+		ret = prepare_elf_headers(&headers, &headers_sz);
> >+		if (ret) {
> >+			pr_err("Preparing elf core header failed\n");
> >+			goto out_err;
> >+		}
> >+
> >+		kbuf.buffer = headers;
> >+		kbuf.bufsz = headers_sz;
> >+		kbuf.mem = 0;
> 
> With commit c19d050f8088 ("arm64/kexec: Use consistent convention of
> initializing 'kxec_buf.mem' with KEXEC_BUF_MEM_UNKNOWN"), we are trying to
> standardize the way of setting up initial value of 'kbuf.mem'. So we can use
> the following notion (in v3?) instead:
> 		kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
> 
> >+		kbuf.memsz = headers_sz;
> >+		kbuf.buf_align = SZ_64K; /* largest supported page size */
> >+		kbuf.buf_max = ULONG_MAX;
> >+		kbuf.top_down = true;
> >+
> >+		ret = kexec_add_buffer(&kbuf);
> >+		if (ret) {
> >+			vfree(headers);
> >+			goto out_err;
> >+		}
> >+		image->arch.elf_headers = headers;
> >+		image->arch.elf_headers_mem = kbuf.mem;
> >+		image->arch.elf_headers_sz = headers_sz;
> >+
> >+		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
> >+			 image->arch.elf_headers_mem, headers_sz, headers_sz);
> >+	}
> >+
> >  	/* load initrd */
> >  	if (initrd) {
> >  		kbuf.buffer = initrd;
> >
> 
> Thanks,
> Bhupesh
> 

_______________________________________________
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] 24+ messages in thread

* Re: [PATCH v2 3/3] arm64: kexec_file: add crash dump support
@ 2019-12-16  1:43       ` AKASHI Takahiro
  0 siblings, 0 replies; 24+ messages in thread
From: AKASHI Takahiro @ 2019-12-16  1:43 UTC (permalink / raw)
  To: Bhupesh Sharma
  Cc: catalin.marinas, will.deacon, linux-kernel, robh+dt, james.morse,
	frowand.list, kexec, linux-arm-kernel

I have forgot to address Bhupesh's comment below in my v3.
I'm going to repost my patch.

Thank you, Bhupesh, for your review.

-Takahiro Akashi

On Thu, Dec 05, 2019 at 02:14:14AM +0530, Bhupesh Sharma wrote:
> On 11/14/2019 10:45 AM, AKASHI Takahiro wrote:
> >Enabling crash dump (kdump) includes
> >* prepare contents of ELF header of a core dump file, /proc/vmcore,
> >   using crash_prepare_elf64_headers(), and
> >* add two device tree properties, "linux,usable-memory-range" and
> >   "linux,elfcorehdr", which represent respectively a memory range
> >   to be used by crash dump kernel and the header's location
> >
> >Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> >Cc: Catalin Marinas <catalin.marinas@arm.com>
> >Cc: Will Deacon <will.deacon@arm.com>
> >Reviewed-by: James Morse <james.morse@arm.com>
> >---
> >  arch/arm64/include/asm/kexec.h         |   4 +
> >  arch/arm64/kernel/kexec_image.c        |   4 -
> >  arch/arm64/kernel/machine_kexec_file.c | 106 ++++++++++++++++++++++++-
> >  3 files changed, 106 insertions(+), 8 deletions(-)
> >
> >diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
> >index 12a561a54128..d24b527e8c00 100644
> >--- a/arch/arm64/include/asm/kexec.h
> >+++ b/arch/arm64/include/asm/kexec.h
> >@@ -96,6 +96,10 @@ static inline void crash_post_resume(void) {}
> >  struct kimage_arch {
> >  	void *dtb;
> >  	unsigned long dtb_mem;
> >+	/* Core ELF header buffer */
> >+	void *elf_headers;
> >+	unsigned long elf_headers_mem;
> >+	unsigned long elf_headers_sz;
> >  };
> >  extern const struct kexec_file_ops kexec_image_ops;
> >diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> >index 29a9428486a5..af9987c154ca 100644
> >--- a/arch/arm64/kernel/kexec_image.c
> >+++ b/arch/arm64/kernel/kexec_image.c
> >@@ -47,10 +47,6 @@ static void *image_load(struct kimage *image,
> >  	struct kexec_segment *kernel_segment;
> >  	int ret;
> >-	/* We don't support crash kernels yet. */
> >-	if (image->type == KEXEC_TYPE_CRASH)
> >-		return ERR_PTR(-EOPNOTSUPP);
> >-
> >  	/*
> >  	 * We require a kernel with an unambiguous Image header. Per
> >  	 * Documentation/arm64/booting.rst, this is the case when image_size
> >diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
> >index 7b08bf9499b6..f1d1bb895fd2 100644
> >--- a/arch/arm64/kernel/machine_kexec_file.c
> >+++ b/arch/arm64/kernel/machine_kexec_file.c
> >@@ -17,12 +17,15 @@
> >  #include <linux/memblock.h>
> >  #include <linux/of_fdt.h>
> >  #include <linux/random.h>
> >+#include <linux/slab.h>
> >  #include <linux/string.h>
> >  #include <linux/types.h>
> >  #include <linux/vmalloc.h>
> >  #include <asm/byteorder.h>
> >  /* relevant device tree properties */
> >+#define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
> >+#define FDT_PROP_MEM_RANGE	"linux,usable-memory-range"
> >  #define FDT_PROP_INITRD_START	"linux,initrd-start"
> >  #define FDT_PROP_INITRD_END	"linux,initrd-end"
> >  #define FDT_PROP_BOOTARGS	"bootargs"
> >@@ -40,6 +43,10 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
> >  	vfree(image->arch.dtb);
> >  	image->arch.dtb = NULL;
> >+	vfree(image->arch.elf_headers);
> >+	image->arch.elf_headers = NULL;
> >+	image->arch.elf_headers_sz = 0;
> >+
> >  	return kexec_image_post_load_cleanup_default(image);
> >  }
> >@@ -55,6 +62,31 @@ static int setup_dtb(struct kimage *image,
> >  	off = ret;
> >+	ret = fdt_delprop(dtb, off, FDT_PROP_KEXEC_ELFHDR);
> >+	if (ret && ret != -FDT_ERR_NOTFOUND)
> >+		goto out;
> >+	ret = fdt_delprop(dtb, off, FDT_PROP_MEM_RANGE);
> >+	if (ret && ret != -FDT_ERR_NOTFOUND)
> >+		goto out;
> >+
> >+	if (image->type == KEXEC_TYPE_CRASH) {
> >+		/* add linux,elfcorehdr */
> >+		ret = fdt_appendprop_addrrange(dtb, 0, off,
> >+				FDT_PROP_KEXEC_ELFHDR,
> >+				image->arch.elf_headers_mem,
> >+				image->arch.elf_headers_sz);
> >+		if (ret)
> >+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> >+
> >+		/* add linux,usable-memory-range */
> >+		ret = fdt_appendprop_addrrange(dtb, 0, off,
> >+				FDT_PROP_MEM_RANGE,
> >+				crashk_res.start,
> >+				crashk_res.end - crashk_res.start + 1);
> >+		if (ret)
> >+			return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL);
> >+	}
> >+
> >  	/* add bootargs */
> >  	if (cmdline) {
> >  		ret = fdt_setprop_string(dtb, off, FDT_PROP_BOOTARGS, cmdline);
> >@@ -125,8 +157,8 @@ static int setup_dtb(struct kimage *image,
> >  }
> >  /*
> >- * More space needed so that we can add initrd, bootargs, kaslr-seed, and
> >- * rng-seed.
> >+ * More space needed so that we can add initrd, bootargs, kaslr-seed,
> >+ * rng-seed, userable-memory-range and elfcorehdr.
> 
> nitpick:
> s/userable-memory-range/usable-memory-range
> 
> >   */
> >  #define DTB_EXTRA_SPACE 0x1000
> >@@ -174,6 +206,43 @@ static int create_dtb(struct kimage *image,
> >  	}
> >  }
> >+static int prepare_elf_headers(void **addr, unsigned long *sz)
> >+{
> >+	struct crash_mem *cmem;
> >+	unsigned int nr_ranges;
> >+	int ret;
> >+	u64 i;
> >+	phys_addr_t start, end;
> >+
> >+	nr_ranges = 1; /* for exclusion of crashkernel region */
> >+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> >+					MEMBLOCK_NONE, &start, &end, NULL)
> >+		nr_ranges++;
> >+
> >+	cmem = kmalloc(sizeof(struct crash_mem) +
> >+			sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
> >+	if (!cmem)
> >+		return -ENOMEM;
> >+
> >+	cmem->max_nr_ranges = nr_ranges;
> >+	cmem->nr_ranges = 0;
> >+	for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE,
> >+					MEMBLOCK_NONE, &start, &end, NULL) {
> >+		cmem->ranges[cmem->nr_ranges].start = start;
> >+		cmem->ranges[cmem->nr_ranges].end = end - 1;
> >+		cmem->nr_ranges++;
> >+	}
> >+
> >+	/* Exclude crashkernel region */
> >+	ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
> >+
> >+	if (!ret)
> >+		ret =  crash_prepare_elf64_headers(cmem, true, addr, sz);
> >+
> >+	kfree(cmem);
> >+	return ret;
> >+}
> >+
> >  int load_other_segments(struct kimage *image,
> >  			unsigned long kernel_load_addr,
> >  			unsigned long kernel_size,
> >@@ -181,14 +250,43 @@ int load_other_segments(struct kimage *image,
> >  			char *cmdline)
> >  {
> >  	struct kexec_buf kbuf;
> >-	void *dtb = NULL;
> >-	unsigned long initrd_load_addr = 0, dtb_len;
> >+	void *headers, *dtb = NULL;
> >+	unsigned long headers_sz, initrd_load_addr = 0, dtb_len;
> >  	int ret = 0;
> >  	kbuf.image = image;
> >  	/* not allocate anything below the kernel */
> >  	kbuf.buf_min = kernel_load_addr + kernel_size;
> >+	/* load elf core header */
> >+	if (image->type == KEXEC_TYPE_CRASH) {
> >+		ret = prepare_elf_headers(&headers, &headers_sz);
> >+		if (ret) {
> >+			pr_err("Preparing elf core header failed\n");
> >+			goto out_err;
> >+		}
> >+
> >+		kbuf.buffer = headers;
> >+		kbuf.bufsz = headers_sz;
> >+		kbuf.mem = 0;
> 
> With commit c19d050f8088 ("arm64/kexec: Use consistent convention of
> initializing 'kxec_buf.mem' with KEXEC_BUF_MEM_UNKNOWN"), we are trying to
> standardize the way of setting up initial value of 'kbuf.mem'. So we can use
> the following notion (in v3?) instead:
> 		kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
> 
> >+		kbuf.memsz = headers_sz;
> >+		kbuf.buf_align = SZ_64K; /* largest supported page size */
> >+		kbuf.buf_max = ULONG_MAX;
> >+		kbuf.top_down = true;
> >+
> >+		ret = kexec_add_buffer(&kbuf);
> >+		if (ret) {
> >+			vfree(headers);
> >+			goto out_err;
> >+		}
> >+		image->arch.elf_headers = headers;
> >+		image->arch.elf_headers_mem = kbuf.mem;
> >+		image->arch.elf_headers_sz = headers_sz;
> >+
> >+		pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
> >+			 image->arch.elf_headers_mem, headers_sz, headers_sz);
> >+	}
> >+
> >  	/* load initrd */
> >  	if (initrd) {
> >  		kbuf.buffer = initrd;
> >
> 
> Thanks,
> Bhupesh
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

end of thread, other threads:[~2019-12-16  1:41 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-14  5:15 [PATCH v2 0/3] arm64: kexec_file: add kdump AKASHI Takahiro
2019-11-14  5:15 ` AKASHI Takahiro
2019-11-14  5:15 ` AKASHI Takahiro
2019-11-14  5:15 ` [PATCH v2 1/3] libfdt: define UINT32_MAX in libfdt_env.h AKASHI Takahiro
2019-11-14  5:15   ` AKASHI Takahiro
2019-11-14  5:15   ` AKASHI Takahiro
2019-12-04 20:33   ` Bhupesh Sharma
2019-12-04 20:33     ` Bhupesh Sharma
2019-12-04 20:33     ` Bhupesh Sharma
2019-11-14  5:15 ` [PATCH v2 2/3] libfdt: include fdt_addresses.c AKASHI Takahiro
2019-11-14  5:15   ` AKASHI Takahiro
2019-11-14  5:15   ` AKASHI Takahiro
2019-11-14  5:15 ` [PATCH v2 3/3] arm64: kexec_file: add crash dump support AKASHI Takahiro
2019-11-14  5:15   ` AKASHI Takahiro
2019-11-14  5:15   ` AKASHI Takahiro
2019-12-04 20:44   ` Bhupesh Sharma
2019-12-04 20:44     ` Bhupesh Sharma
2019-12-04 20:44     ` Bhupesh Sharma
2019-12-16  1:43     ` AKASHI Takahiro
2019-12-16  1:43       ` AKASHI Takahiro
2019-12-16  1:43       ` AKASHI Takahiro
2019-12-04 20:26 ` [PATCH v2 0/3] arm64: kexec_file: add kdump Bhupesh Sharma
2019-12-04 20:26   ` Bhupesh Sharma
2019-12-04 20:26   ` Bhupesh Sharma

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.