Skip to contentSkip to conversation

crashdump: Add print_crashkernel_region_size() function

PATCH In review Eric DeVolder 4 participants 22 messages Feb 6, 2017 – Feb 8, 2017

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH v2 1/12 crashdump/x86: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Crash kernel region size is available via sysfs on Linux running on bare metal. However, this does not work when Linux runs as Xen dom0. In this case Xen crash kernel region size should be established using __HYPERVISOR_kexec_op hypercall (Linux kernel kexec functionality does not make a lot of sense in Xen dom0). Sadly hypercalls are not easily accessible using shell scripts or something like that. Potentially we can check "xl dmesg" output for crashkernel option but this is not nice. So, let's add this functionality, for Linux running on bare metal and as Xen dom0, to kexec-tools. This way kdump scripts may establish crash kernel region size in one way regardless of platform. All burden of platform detection lies on kexec-tools.

Figure (and unit) displayed by this new kexec-tools functionality is the same as one taken from /sys/kernel/kexec_crash_size.

This patch just adds print_crashkernel_region_size() function, which prints crash kernel region size, for x86 arch. Next patches will add same named function for other archs supported by kexec-tools. Last patch of this series will export this functionality to the userspace via separate kexec utility option.

---
v0: Interal version.
v1: Posted to kexec-tools mailing list
v2: Incorporated feedback:
- utilize the is_crashkernel_mem_reserved() function common in all archs
- for ppc and ppc64, utilize device-tree values to print size
- for unsupported architectures, print appropriate message

---
 kexec/arch/i386/crashdump-x86.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
kexec/arch/i386/crashdump-x86.c +12 -0
index 88aeee3..ae46dcf 100644
@@ -1094,3 +1094,15 @@ int is_crashkernel_mem_reserved(void)
 
 	return !!crash_reserved_mem_nr;
 }
+
+void print_crashkernel_region_size(void)
+{
+	uint64_t start = 0, end = 0;
+
+	if (is_crashkernel_mem_reserved()) {
+		get_crash_kernel_load_range(&start, &end);
+		printf("%lu\n", end - start + 1);
+	} else
+		printf("0\n");
+}
+
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#7 lore raw

PATCH v2 5/12 crashdump/m68k: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Provide just print_crashkernel_region_size() stub. This way we can properly build kexec utility on m68k arch even if the functionality is not available on it.

---
 kexec/arch/m68k/kexec-m68k.c | 5 +++++
 1 file changed, 5 insertions(+)
kexec/arch/m68k/kexec-m68k.c +5 -0
index 372aa37..0cbf18e 100644
@@ -89,6 +89,11 @@ int is_crashkernel_mem_reserved(void)
 	return 0;
 }
 
+void print_crashkernel_region_size(void)
+{
+	printf("Crashkernel functionality is not available.\n");
+}
+
 unsigned long virt_to_phys(unsigned long addr)
 {
 	return addr + m68k_memoffset;
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#12 lore raw

PATCH v2 8/12 crashdump/ppc64: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

note

---
 kexec/arch/ppc64/crashdump-ppc64.c | 33 +++++++++++++++++++++++++++------
 kexec/arch/ppc64/kexec-ppc64.c     | 23 +++++++++++++++++++++++
 kexec/arch/ppc64/kexec-ppc64.h     |  2 ++
 3 files changed, 52 insertions(+), 6 deletions(-)
kexec/arch/ppc64/crashdump-ppc64.c +27 -6
index f62b159..0f4fd77 100644
@@ -526,15 +526,36 @@ void add_usable_mem_rgns(unsigned long long base, unsigned long long size)
 		usablemem_rgns.size, base, size);
 }
 
+int get_crash_kernel_load_range(uint64_t *start, uint64_t *end)
+{
+	unsigned long long value;
+	if (get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-base", &value)) {
+		*start = value;
+	}
+	else
+		*start = 0;
+	if (get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-size", &value)) {
+		*end = *start + value - 1;
+	}
+	else
+		*end = 0;
+	return 0;
+}
+
 int is_crashkernel_mem_reserved(void)
 {
-	int fd;
+	return get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-base", NULL);
+}
 
-	fd = open("/proc/device-tree/chosen/linux,crashkernel-base", O_RDONLY);
-	if (fd < 0)
-		return 0;
-	close(fd);
-	return 1;
+void print_crashkernel_region_size(void)
+{
+        uint64_t start = 0, end = 0;
+
+        if (is_crashkernel_mem_reserved()) {
+                get_crash_kernel_load_range(&start, &end);
+                printf("%llu\n", end - start + 1);
+        } else
+                printf("0\n");
 }
 
 #if 0
kexec/arch/ppc64/kexec-ppc64.c +23 -0
index 09ee025..dd0fc67 100644
@@ -356,6 +356,29 @@ void scan_reserved_ranges(unsigned long kexec_flags, int *range_index)
 	*range_index = i;
 }
 
+int get_devtree_value (const char *fname, unsigned long long *pvalue)
+{
+	/* Return 1 if fname/value valid, 0 otherwise */
+	FILE *file;
+	char buf[MAXBYTES];
+	int rcode = 1, n = -1;
+	unsigned long long value = 0;
+	if ((file = fopen(fname, "r"))) {
+		n = fread(buf, 1, MAXBYTES, file);
+		fclose(file);
+	}
+	if (n == sizeof(uint32_t)) {
+		value = ((uint32_t *)buf)[0];
+	} else if (n == sizeof(uint64_t)) {
+		value = ((uint64_t *)buf)[0];
+	} else {
+		fprintf(stderr, "%s node has invalid size: %d\n", fname, n);
+		rcode = 0;
+	}
+	if (pvalue) *pvalue = value;
+	return rcode;
+}
+
 /* Get devtree details and create exclude_range array
  * Also create usablemem_ranges for KEXEC_ON_CRASH
  */
kexec/arch/ppc64/kexec-ppc64.h +2 -0
index 89ee942..3d20419 100644
@@ -14,6 +14,8 @@
 #define HAVE_DYNAMIC_MEMORY
 #define NEED_RESERVE_DTB
 
+extern int get_devtree_value (const char *fname, unsigned long long *pvalue);
+
 int setup_memory_ranges(unsigned long kexec_flags);
 
 int elf_ppc64_probe(const char *buf, off_t len);
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#15 lore raw

PATCH v2 9/12 crashdump/s390: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

---
 kexec/arch/s390/kexec-s390.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
kexec/arch/s390/kexec-s390.c +10 -0
index 074575e..212a64f 100644
@@ -262,3 +262,13 @@ int is_crashkernel_mem_reserved(void)
 	return parse_iomem_single("Crash kernel\n", &start, &end) == 0 ?
 		(start != end) : 0;
 }
+
+void print_crashkernel_region_size(void)
+{
+	uint64_t start, end;
+
+	if (!parse_iomem_single("Crash kernel\n", &start, &end) && start != end)
+		printf("%lu\n", end - start + 1);
+	else
+		printf("0\n");
+}
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#16 lore raw

PATCH v2 10/12 crashdump/sh: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

---
 kexec/arch/sh/crashdump-sh.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
kexec/arch/sh/crashdump-sh.c +10 -0
index 9e6af6b..6556eb1 100644
@@ -178,3 +178,13 @@ int is_crashkernel_mem_reserved(void)
 	return parse_iomem_single("Crash kernel\n", &start, &end) == 0 ?
 	  (start != end) : 0;
 }
+
+void print_crashkernel_region_size(void)
+{
+	uint64_t start, end;
+
+	if (!parse_iomem_single("Crash kernel\n", &start, &end) && start != end)
+		printf("%lu\n", end - start + 1);
+	else
+		printf("0\n");
+}
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#18 lore raw

PATCH v2 12/12 kexec: Add option to get crash kernel region size

In reply to Eric DeVolder

Here print_crashkernel_region_size() function is available on all archs (even if the functionality is not implemented on some). So, we can safely use it in arch independent code and export the functionality to the user space.

---
 kexec/kexec.8 | 3 +++
 kexec/kexec.c | 4 ++++
 2 files changed, 7 insertions(+)
kexec/kexec.8 +3 -0
index f4b39a6..e0131b4 100644
@@ -179,6 +179,9 @@ Load a helper image to jump back to original kernel.
 .TP
 .BI \-\-reuseinitrd
 Reuse initrd from first boot.
+.TP
+.BI \-\-print-ckr-size
+Print crash kernel region size, if available.
 
 
 .SH SUPPORTED KERNEL FILE TYPES AND OPTIONS
kexec/kexec.c +4 -0
index a2ba79d..482b6a7 100644
@@ -995,6 +995,7 @@ void usage(void)
 	       "     --mem-max=<addr> Specify the highest memory address to\n"
 	       "                      load code into.\n"
 	       "     --reuseinitrd    Reuse initrd from first boot.\n"
+	       "     --print-ckr-size Print crash kernel region size.\n"
 	       "     --load-preserve-context Load the new kernel and preserve\n"
 	       "                      context of current kernel during kexec.\n"
 	       "     --load-jump-back-helper Load a helper image to jump back\n"
@@ -1375,6 +1376,9 @@ int main(int argc, char *argv[])
 		case OPT_STATUS:
 			do_status = 1;
 			break;
+		case OPT_PRINT_CKR_SIZE:
+			print_crashkernel_region_size();
+			return 0;
 		default:
 			break;
 		}
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#17 lore raw

PATCH v2 11/12 kexec: Add option to get crash kernel region size

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Here print_crashkernel_region_size() function is available on all archs (even if the functionality is not implemented on some). So, we can safely use it in arch independent code and export the functionality to the user space.

---
 kexec/kexec.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kexec/kexec.h +4 -1
index 2b06f59..3ac81f5 100644
@@ -226,7 +226,8 @@ extern int file_types;
 #define OPT_LOAD_PRESERVE_CONTEXT 259
 #define OPT_LOAD_JUMP_BACK_HELPER 260
 #define OPT_ENTRY		261
-#define OPT_MAX			262
+#define OPT_PRINT_CKR_SIZE	262
+#define OPT_MAX			263
 #define KEXEC_OPTIONS \
 	{ "help",		0, 0, OPT_HELP }, \
 	{ "version",		0, 0, OPT_VERSION }, \
@@ -247,6 +248,7 @@ extern int file_types;
 	{ "kexec-file-syscall",	0, 0, OPT_KEXEC_FILE_SYSCALL }, \
 	{ "debug",		0, 0, OPT_DEBUG }, \
 	{ "status",		0, 0, OPT_STATUS }, \
+	{ "print-ckr-size",     0, 0, OPT_PRINT_CKR_SIZE }, \
 
 #define KEXEC_OPT_STR "h?vdfxyluet:psS"
 
@@ -293,6 +295,7 @@ int arch_compat_trampoline(struct kexec_info *info);
 void arch_update_purgatory(struct kexec_info *info);
 int is_crashkernel_mem_reserved(void);
 int get_crash_kernel_load_range(uint64_t *start, uint64_t *end);
+void print_crashkernel_region_size(void);
 char *get_command_line(void);
 
 int kexec_iomem_for_each_line(char *match,
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#3 lore raw

PATCH v2 2/12 crashdump/arm: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

---
 kexec/arch/arm/crashdump-arm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
kexec/arch/arm/crashdump-arm.c +10 -0
index 4a89b5e..cd66520 100644
@@ -413,3 +413,13 @@ int is_crashkernel_mem_reserved(void)
 
 	return crash_kernel_mem.start != crash_kernel_mem.end;
 }
+
+void print_crashkernel_region_size(void)
+{
+	uint64_t start, end;
+
+	if (!parse_iomem_single("Crash kernel\n", &start, &end) && start != end)
+		printf("%lu\n", end - start + 1);
+	else
+		printf("0\n");
+}
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#9 lore raw

PATCH v2 6/12 crashdump/mips: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

---
 kexec/arch/mips/crashdump-mips.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kexec/arch/mips/crashdump-mips.c +9 -0
index d6cff5a..594e1b9 100644
@@ -385,3 +385,12 @@ int is_crashkernel_mem_reserved(void)
 		(start != end) : 0;
 }
 
+void print_crashkernel_region_size(void)
+{
+	uint64_t start, end;
+
+	if (!parse_iomem_single("Crash kernel\n", &start, &end) && start != end)
+		printf("%lu\n", end - start + 1);
+	else
+		printf("0\n");
+}
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#10 lore raw

PATCH v2 7/12 crashdump/ppc: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

---
 kexec/arch/ppc/crashdump-powerpc.c | 34 +++++++++++++++++++++++++++-------
 kexec/arch/ppc/kexec-ppc.c         | 23 +++++++++++++++++++++++
 kexec/arch/ppc/kexec-ppc.h         |  1 +
 3 files changed, 51 insertions(+), 7 deletions(-)
kexec/arch/ppc/crashdump-powerpc.c +27 -7
index 3dc35eb..4c12452 100644
@@ -397,14 +397,34 @@ void add_usable_mem_rgns(unsigned long long base, unsigned long long size)
 		usablemem_rgns.size, base, size);
 }
 
+int get_crash_kernel_load_range(uint64_t *start, uint64_t *end)
+{
+	unsigned long long value;
+	if (get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-base", &value)) {
+		*start = value;
+	}
+	else
+		*start = 0;
+	if (get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-size", &value)) {
+		*end = *start + value - 1;
+	}
+	else
+		*end = 0;
+	return 0;
+}
+
 int is_crashkernel_mem_reserved(void)
 {
-	int fd;
-
-	fd = open("/proc/device-tree/chosen/linux,crashkernel-base", O_RDONLY);
-	if (fd < 0)
-		return 0;
-	close(fd);
-	return 1;
+	return get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-base", NULL);
 }
 
+void print_crashkernel_region_size(void)
+{
+        uint64_t start = 0, end = 0;
+
+        if (is_crashkernel_mem_reserved()) {
+                get_crash_kernel_load_range(&start, &end);
+                printf("%llu\n", end - start + 1);
+        } else
+                printf("0\n");
+}
kexec/arch/ppc/kexec-ppc.c +23 -0
index d046110..78e8fb8 100644
@@ -423,6 +423,29 @@ err_out:
 	return -1;
 }
 
+int get_devtree_value (const char *fname, unsigned long long *pvalue)
+{
+	/* Return 1 if fname/value valid, 0 otherwise */
+	FILE *file;
+	char buf[MAXBYTES];
+	int rcode = 1, n = -1;
+	unsigned long long value = 0;
+	if ((file = fopen(fname, "r"))) {
+		n = fread(buf, 1, MAXBYTES, file);
+		fclose(file);
+	}
+	if (n == sizeof(uint32_t)) {
+		value = ((uint32_t *)buf)[0];
+	} else if (n == sizeof(uint64_t)) {
+		value = ((uint64_t *)buf)[0];
+	} else {
+		fprintf(stderr, "%s node has invalid size: %d\n", fname, n);
+		rcode = 0;
+	}
+	if (pvalue) *pvalue = value;
+	return rcode;
+}
+
 /* Get devtree details and create exclude_range array
  * Also create usablemem_ranges for KEXEC_ON_CRASH
  */
kexec/arch/ppc/kexec-ppc.h +1 -0
index 904cf48..69189f0 100644
@@ -71,6 +71,7 @@ extern unsigned char reuse_initrd;
 extern const char *ramdisk;
 
 /* Method to parse the memory/reg nodes in device-tree */
+extern int get_devtree_value (const char *fname, unsigned long long *pvalue);
 extern unsigned long dt_address_cells, dt_size_cells;
 extern int init_memory_region_info(void);
 extern int read_memory_region_limits(int fd, unsigned long long *start,
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#6 lore raw

PATCH v2 4/12 crashdump/ia64: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

---
 kexec/arch/ia64/crashdump-ia64.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
kexec/arch/ia64/crashdump-ia64.c +10 -0
index 726c9f4..07de42a 100644
@@ -286,3 +286,13 @@ int is_crashkernel_mem_reserved(void)
 	return parse_iomem_single("Crash kernel\n", &start,
 				  &end) == 0 ?  (start != end) : 0;
 }
+
+void print_crashkernel_region_size(void)
+{
+	uint64_t start, end;
+
+	if (!parse_iomem_single("Crash kernel\n", &start, &end) && start != end)
+		printf("%lu\n", end - start + 1);
+	else
+		printf("0\n");
+}
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#4 lore raw

PATCH v2 3/12 crashdump/cris: Add print_crashkernel_region_size() function

In reply to Eric DeVolder

From: Daniel Kiper <[email protected]>

Provide just print_crashkernel_region_size() stub. This way we can properly build kexec utility on cris arch even if the functionality is not available on it.

---
 kexec/arch/cris/kexec-cris.c | 5 +++++
 1 file changed, 5 insertions(+)
kexec/arch/cris/kexec-cris.c +5 -0
index 4ac2f89..5601d8e 100644
@@ -77,6 +77,11 @@ int is_crashkernel_mem_reserved(void)
 	return 0;
 }
 
+void print_crashkernel_region_size(void)
+{
+	printf("Crashkernel functionality is not available.\n");
+}
+
 unsigned long virt_to_phys(unsigned long addr)
 {
 	return (addr) & 0x7fffffff;
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#0 lore raw

v2 cover crashdump: Add print_crashkernel_region_size() function

Crash kernel region size is available via sysfs on Linux running on bare metal. However, this does not work when Linux runs as Xen dom0. In this case Xen crash kernel region size should be established using __HYPERVISOR_kexec_op hypercall (Linux kernel kexec functionality does not make a lot of sense in Xen dom0). Sadly hypercalls are not easily accessible using shell scripts or something like that. Potentially we can check "xl dmesg" output for crashkernel option but this is not nice. So, let's add this functionality, for Linux running on bare metal and as Xen dom0, to kexec-tools. This way kdump scripts may establish crash kernel region size in one way regardless of platform. All burden of platform detection lies on kexec-tools.

Figure (and unit) displayed by this new kexec-tools functionality is the same as one taken from /sys/kernel/kexec_crash_size.

This patch just adds print_crashkernel_region_size() function, which prints crash kernel region size, for x86 arch. Next patches will add same named function for other archs supported by kexec-tools. Last patch of this series will export this functionality to the userspace via separate kexec utility option.

---
v0: Interal version.
v1: Posted to kexec-tools mailing list
v2: Incorporated feedback:
- utilize the is_crashkernel_mem_reserved() function common in all archs
- for ppc and ppc64, utilize device-tree values to print size
- for unsupported architectures, print appropriate message

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#13 lore raw

Re: [PATCH v2 08/12] crashdump/ppc64: Add print_crashkernel_region_size() function

In reply to Eric DeVolder
Quoted 3 lines · Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

You may actually spell out the name of the x86 patch, like:

'Follow similar x86 pach titled: XYZ".

Quoted 6 lines

note

^^^^ ?

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#20 lore raw
In reply to Eric DeVolder
Quoted 15 lines · Eric DeVolder

Crash kernel region size is available via sysfs on Linux running on bare metal. However, this does not work when Linux runs as Xen dom0. In this case Xen crash kernel region size should be established using __HYPERVISOR_kexec_op hypercall (Linux kernel kexec functionality does not make a lot of sense in Xen dom0). Sadly hypercalls are not easily accessible using shell scripts or something like that. Potentially we can check "xl dmesg" output for crashkernel option but this is not nice. So, let's add this functionality, for Linux running on bare metal and as Xen dom0, to kexec-tools. This way kdump scripts may establish crash kernel region size in one way regardless of platform. All burden of platform detection lies on kexec-tools.

Figure (and unit) displayed by this new kexec-tools functionality is the same as one taken from /sys/kernel/kexec_crash_size.

Quoted 8 lines

This patch just adds print_crashkernel_region_size() function, which prints crash kernel region size, for x86 arch. Next patches will add same named function for other archs supported by kexec-tools. Last patch of this series will export this functionality to the userspace via separate kexec utility option.

This does not need to have SOB.

Quoted 7 lines

---
v0: Interal version.
v1: Posted to kexec-tools mailing list
v2: Incorporated feedback:
- utilize the is_crashkernel_mem_reserved() function common in all archs
- for ppc and ppc64, utilize device-tree values to print size
- for unsupported architectures, print appropriate message

Next time please provide a list of patches (numbers are OK) changed in comparison to earlier version. Results of "git diff --stat master.." and "git shortlog master.." (I assume that you based patches on master) are also nice to have at the bottom of patch #00.

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw

Re: [PATCH v2 01/12] crashdump/x86: Add print_crashkernel_region_size() function

In reply to Eric DeVolder
Quoted 25 lines · Eric DeVolder

From: Daniel Kiper <[email protected]>

Crash kernel region size is available via sysfs on Linux running on bare metal. However, this does not work when Linux runs as Xen dom0. In this case Xen crash kernel region size should be established using __HYPERVISOR_kexec_op hypercall (Linux kernel kexec functionality does not make a lot of sense in Xen dom0). Sadly hypercalls are not easily accessible using shell scripts or something like that. Potentially we can check "xl dmesg" output for crashkernel option but this is not nice. So, let's add this functionality, for Linux running on bare metal and as Xen dom0, to kexec-tools. This way kdump scripts may establish crash kernel region size in one way regardless of platform. All burden of platform detection lies on kexec-tools.

Figure (and unit) displayed by this new kexec-tools functionality is the same as one taken from /sys/kernel/kexec_crash_size.

This patch just adds print_crashkernel_region_size() function, which prints crash kernel region size, for x86 arch. Next patches will add same named function for other archs supported by kexec-tools. Last patch of this series will export this functionality to the userspace via separate kexec utility option.

Quoted 7 lines

---
v0: Interal version.
v1: Posted to kexec-tools mailing list
v2: Incorporated feedback:
- utilize the is_crashkernel_mem_reserved() function common in all archs
- for ppc and ppc64, utilize device-tree values to print size
- for unsupported architectures, print appropriate message

Please do not blindly copy description of changes from patch #00. I think it makes more sense if you tell us what really has been changed in this patch.

Otherwise LGTM.

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw

Re: [PATCH v2 03/12] crashdump/cris: Add print_crashkernel_region_size() function

In reply to Eric DeVolder
Quoted 17 lines · Eric DeVolder

From: Daniel Kiper <[email protected]>

Provide just print_crashkernel_region_size() stub. This way we can properly build kexec utility on cris arch even if the functionality is not available on it.

---
 kexec/arch/cris/kexec-cris.c | 5 +++++
 1 file changed, 5 insertions(+)
kexec/arch/cris/kexec-cris.c +0 -0
index 4ac2f89..5601d8e 100644

kexec/arch/cris/kexec-cris.c int is_crashkernel_mem_reserved(void) · line 82

Quoted 6 lines
kexec/arch/cris/kexec-cris.c +3 -0
@@ -77,6 +77,11 @@ int is_crashkernel_mem_reserved(void)
 	return 0;
 }
 
+void print_crashkernel_region_size(void)
+{
+	printf("Crashkernel functionality is not available.\n");

Error message is a bit confusing. What about "Crash kernel region size cannot be printed because this info is not exposed by the system."?

Or simpler: Crash kernel region size is not exposed by the system.

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#8 lore raw

Re: [PATCH v2 05/12] crashdump/m68k: Add print_crashkernel_region_size() function

In reply to Eric DeVolder
Quoted 17 lines · Eric DeVolder

From: Daniel Kiper <[email protected]>

Provide just print_crashkernel_region_size() stub. This way we can properly build kexec utility on m68k arch even if the functionality is not available on it.

---
 kexec/arch/m68k/kexec-m68k.c | 5 +++++
 1 file changed, 5 insertions(+)
kexec/arch/m68k/kexec-m68k.c +0 -0
index 372aa37..0cbf18e 100644

kexec/arch/m68k/kexec-m68k.c int is_crashkernel_mem_reserved(void) · line 94

Quoted 6 lines
kexec/arch/m68k/kexec-m68k.c +3 -0
@@ -89,6 +89,11 @@ int is_crashkernel_mem_reserved(void)
 	return 0;
 }
 
+void print_crashkernel_region_size(void)
+{
+	printf("Crashkernel functionality is not available.\n");

Ditto.

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#11 lore raw

Re: [PATCH v2 07/12] crashdump/ppc: Add print_crashkernel_region_size() function

In reply to Eric DeVolder
Quoted 17 lines · Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

---
 kexec/arch/ppc/crashdump-powerpc.c | 34 +++++++++++++++++++++++++++-------
 kexec/arch/ppc/kexec-ppc.c         | 23 +++++++++++++++++++++++
 kexec/arch/ppc/kexec-ppc.h         |  1 +
 3 files changed, 51 insertions(+), 7 deletions(-)
kexec/arch/ppc/crashdump-powerpc.c +0 -0
index 3dc35eb..4c12452 100644

kexec/arch/ppc/crashdump-powerpc.c void add_usable_mem_rgns(unsigned long long base, unsigned long long size) · line 405

Quoted 9 lines
kexec/arch/ppc/crashdump-powerpc.c +6 -0
@@ -397,14 +397,34 @@ void add_usable_mem_rgns(unsigned long long base, unsigned long long size)
 		usablemem_rgns.size, base, size);
 }
 
+int get_crash_kernel_load_range(uint64_t *start, uint64_t *end)
+{
+	unsigned long long value;
+	if (get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-base", &value)) {
+		*start = value;
+	}

Curly brackets are not needed here.

kexec/arch/ppc/crashdump-powerpc.c void add_usable_mem_rgns(unsigned long long base, unsigned long long size) · line 410

Quoted 5 lines
kexec/arch/ppc/crashdump-powerpc.c +5 -0
+	else
+		*start = 0;
+	if (get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-size", &value)) {
+		*end = *start + value - 1;
+	}

Ditto.

kexec/arch/ppc/crashdump-powerpc.c void add_usable_mem_rgns(unsigned long long base, unsigned long long size) · line 412

Quoted 2 lines
kexec/arch/ppc/crashdump-powerpc.c +2 -0
+	else
+		*end = 0;

I think that you should return -1 if get_devtree_value() returned error here and there.

kexec/arch/ppc/crashdump-powerpc.c void add_usable_mem_rgns(unsigned long long base, unsigned long long size) · line 418

Quoted 13 lines
kexec/arch/ppc/crashdump-powerpc.c +4 -7
+	return 0;
+}
+
 int is_crashkernel_mem_reserved(void)
 {
-	int fd;
-
-	fd = open("/proc/device-tree/chosen/linux,crashkernel-base", O_RDONLY);
-	if (fd < 0)
-		return 0;
-	close(fd);
-	return 1;
+	return get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-base", NULL);

is_crashkernel_mem_reserved() change begs separate patch.

kexec/arch/ppc/crashdump-powerpc.c void add_usable_mem_rgns(unsigned long long base, unsigned long long size) · line 426

Quoted 8 lines
kexec/arch/ppc/crashdump-powerpc.c +6 -0
 }
 
+void print_crashkernel_region_size(void)
+{
+        uint64_t start = 0, end = 0;
+
+        if (is_crashkernel_mem_reserved()) {
+                get_crash_kernel_load_range(&start, &end);

Please check value returned by get_crash_kernel_load_range() here.

kexec/arch/ppc/kexec-ppc.c err_out: · line 426

Quoted 13 lines
kexec/arch/ppc/crashdump-powerpc.c +4 -0
+                printf("%llu\n", end - start + 1);
+        } else
+                printf("0\n");
+}
kexec/arch/ppc/kexec-ppc.c +1 -0
index d046110..78e8fb8 100644
@@ -423,6 +423,29 @@ err_out:
 	return -1;
 }
 
+int get_devtree_value (const char *fname, unsigned long long *pvalue)

Redundant space between function name and bracket.

kexec/arch/ppc/kexec-ppc.c err_out: · line 431

Quoted 5 lines
kexec/arch/ppc/kexec-ppc.c +5 -0
+{
+	/* Return 1 if fname/value valid, 0 otherwise */
+	FILE *file;
+	char buf[MAXBYTES];
+	int rcode = 1, n = -1;

s/rcode/ret/ And please follow convention and return -1 in case of error.

kexec/arch/ppc/kexec-ppc.c err_out: · line 432

Quoted 1 line
kexec/arch/ppc/kexec-ppc.c +1 -0
+	unsigned long long value = 0;

Lack of empty line here.

kexec/arch/ppc/kexec-ppc.c err_out: · line 438

Quoted 6 lines
kexec/arch/ppc/kexec-ppc.c +6 -0
+	if ((file = fopen(fname, "r"))) {
+		n = fread(buf, 1, MAXBYTES, file);
+		fclose(file);
+	}
+	if (n == sizeof(uint32_t)) {
+		value = ((uint32_t *)buf)[0];

Curly brackets are not needed here.

kexec/arch/ppc/kexec-ppc.c err_out: · line 440

Quoted 2 lines
kexec/arch/ppc/kexec-ppc.c +2 -0
+	} else if (n == sizeof(uint64_t)) {
+		value = ((uint64_t *)buf)[0];

Ditto.

kexec/arch/ppc/kexec-ppc.c err_out: · line 445

Quoted 5 lines
kexec/arch/ppc/kexec-ppc.c +5 -0
+	} else {
+		fprintf(stderr, "%s node has invalid size: %d\n", fname, n);
+		rcode = 0;
+	}
+	if (pvalue) *pvalue = value;

"*pvalue = value;" should be in line below "if".

kexec/arch/ppc/kexec-ppc.c err_out: · line 446

Quoted 1 line
kexec/arch/ppc/kexec-ppc.c +1 -0
+	return rcode;

Please do not glue all lines into one giant block here and there. It is unreadable.

Quoted 10 lines
kexec/arch/ppc/kexec-ppc.c +2 -0
+}
+
 /* Get devtree details and create exclude_range array
  * Also create usablemem_ranges for KEXEC_ON_CRASH
  */
kexec/arch/ppc/kexec-ppc.h +0 -0
index 904cf48..69189f0 100644

kexec/arch/ppc/kexec-ppc.h extern unsigned char reuse_initrd; · line 74

Quoted 4 lines
kexec/arch/ppc/kexec-ppc.h +1 -0
@@ -71,6 +71,7 @@ extern unsigned char reuse_initrd;
 extern const char *ramdisk;
 
 /* Method to parse the memory/reg nodes in device-tree */
+extern int get_devtree_value (const char *fname, unsigned long long *pvalue);

Put get_devtree_value() under read_memory_region_limits().

kexec/arch/ppc/kexec-ppc.h extern unsigned char reuse_initrd; · line 77

Quoted 3 lines
kexec/arch/ppc/kexec-ppc.h +0 -0
 extern unsigned long dt_address_cells, dt_size_cells;
 extern int init_memory_region_info(void);
 extern int read_memory_region_limits(int fd, unsigned long long *start,

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#14 lore raw

Re: [PATCH v2 08/12] crashdump/ppc64: Add print_crashkernel_region_size() function

In reply to Eric DeVolder
Quoted 8 lines · Eric DeVolder

From: Daniel Kiper <[email protected]>

Follow similar x86 patch.

note

???

And please look at my comments for "crashdump/ppc: Add print_crashkernel_region_size() function". This patch requires similar fixes and cleanups like PPC one.

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#19 lore raw

Re: [PATCH v2 12/12] kexec: Add option to get crash kernel region size

In reply to Eric DeVolder
Quoted 6 lines · Eric DeVolder

Here print_crashkernel_region_size() function is available on all archs (even if the functionality is not implemented on some). So, we can safely use it in arch independent code and export the functionality to the user space.

I think that patch #11 and #12 should be merged into one thing like it was in my original series.

Daniel

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#21 lore raw
In reply to Eric DeVolder
Quoted 12 lines · Eric DeVolder

Crash kernel region size is available via sysfs on Linux running on bare metal. However, this does not work when Linux runs as Xen dom0. In this case Xen crash kernel region size should be established using __HYPERVISOR_kexec_op hypercall (Linux kernel kexec functionality does not make a lot of sense in Xen dom0). Sadly hypercalls are not easily accessible using shell scripts or something like that. Potentially we can check "xl dmesg" output for crashkernel option but this is not nice. So, let's add this functionality, for Linux running on bare metal and as Xen dom0, to kexec-tools. This way kdump scripts may establish crash kernel region size in one way regardless of platform. All burden of platform detection lies on kexec-tools.

Quoted 8 lines

Figure (and unit) displayed by this new kexec-tools functionality is the same as one taken from /sys/kernel/kexec_crash_size.

This patch just adds print_crashkernel_region_size() function, which prints crash kernel region size, for x86 arch. Next patches will add same named function for other archs supported by kexec-tools. Last patch of this series will export this functionality to the userspace via separate kexec utility option.

IMHO, overall code would have been more cleaner if we introduce get_crash_kernel_load_range() for each arch. Then a single function to get_crash_kernel_size() in kexec/kexec.c.

~Pratyush

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec