All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function
@ 2017-02-06 19:42 Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 01/12] crashdump/x86: " Eric DeVolder
                   ` (13 more replies)
  0 siblings, 14 replies; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

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.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
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
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* [PATCH v2 01/12] crashdump/x86: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-07 14:55   ` Daniel Kiper
  2017-02-06 19:42 ` [PATCH v2 02/12] crashdump/arm: " Eric DeVolder
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

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.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
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(+)

diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 88aeee3..ae46dcf 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -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");
+}
+
-- 
2.7.4


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

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

* [PATCH v2 02/12] crashdump/arm: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 01/12] crashdump/x86: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 03/12] crashdump/cris: " Eric DeVolder
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/arch/arm/crashdump-arm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kexec/arch/arm/crashdump-arm.c b/kexec/arch/arm/crashdump-arm.c
index 4a89b5e..cd66520 100644
--- a/kexec/arch/arm/crashdump-arm.c
+++ b/kexec/arch/arm/crashdump-arm.c
@@ -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");
+}
-- 
2.7.4


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

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

* [PATCH v2 03/12] crashdump/cris: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 01/12] crashdump/x86: " Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 02/12] crashdump/arm: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-07 15:07   ` Daniel Kiper
  2017-02-06 19:42 ` [PATCH v2 04/12] crashdump/ia64: " Eric DeVolder
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

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.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/arch/cris/kexec-cris.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kexec/arch/cris/kexec-cris.c b/kexec/arch/cris/kexec-cris.c
index 4ac2f89..5601d8e 100644
--- a/kexec/arch/cris/kexec-cris.c
+++ b/kexec/arch/cris/kexec-cris.c
@@ -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;
-- 
2.7.4


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

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

* [PATCH v2 04/12] crashdump/ia64: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (2 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 03/12] crashdump/cris: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 05/12] crashdump/m68k: " Eric DeVolder
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/arch/ia64/crashdump-ia64.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kexec/arch/ia64/crashdump-ia64.c b/kexec/arch/ia64/crashdump-ia64.c
index 726c9f4..07de42a 100644
--- a/kexec/arch/ia64/crashdump-ia64.c
+++ b/kexec/arch/ia64/crashdump-ia64.c
@@ -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");
+}
-- 
2.7.4


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

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

* [PATCH v2 05/12] crashdump/m68k: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (3 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 04/12] crashdump/ia64: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-07 15:09   ` Daniel Kiper
  2017-02-06 19:42 ` [PATCH v2 06/12] crashdump/mips: " Eric DeVolder
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

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.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/arch/m68k/kexec-m68k.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kexec/arch/m68k/kexec-m68k.c b/kexec/arch/m68k/kexec-m68k.c
index 372aa37..0cbf18e 100644
--- a/kexec/arch/m68k/kexec-m68k.c
+++ b/kexec/arch/m68k/kexec-m68k.c
@@ -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;
-- 
2.7.4


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

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

* [PATCH v2 06/12] crashdump/mips: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (4 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 05/12] crashdump/m68k: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 07/12] crashdump/ppc: " Eric DeVolder
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/arch/mips/crashdump-mips.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kexec/arch/mips/crashdump-mips.c b/kexec/arch/mips/crashdump-mips.c
index d6cff5a..594e1b9 100644
--- a/kexec/arch/mips/crashdump-mips.c
+++ b/kexec/arch/mips/crashdump-mips.c
@@ -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");
+}
-- 
2.7.4


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

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

* [PATCH v2 07/12] crashdump/ppc: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (5 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 06/12] crashdump/mips: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-07 16:06   ` Daniel Kiper
  2017-02-06 19:42 ` [PATCH v2 08/12] crashdump/ppc64: " Eric DeVolder
                   ` (6 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 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(-)

diff --git a/kexec/arch/ppc/crashdump-powerpc.c b/kexec/arch/ppc/crashdump-powerpc.c
index 3dc35eb..4c12452 100644
--- a/kexec/arch/ppc/crashdump-powerpc.c
+++ b/kexec/arch/ppc/crashdump-powerpc.c
@@ -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");
+}
diff --git a/kexec/arch/ppc/kexec-ppc.c b/kexec/arch/ppc/kexec-ppc.c
index d046110..78e8fb8 100644
--- a/kexec/arch/ppc/kexec-ppc.c
+++ b/kexec/arch/ppc/kexec-ppc.c
@@ -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
  */
diff --git a/kexec/arch/ppc/kexec-ppc.h b/kexec/arch/ppc/kexec-ppc.h
index 904cf48..69189f0 100644
--- a/kexec/arch/ppc/kexec-ppc.h
+++ b/kexec/arch/ppc/kexec-ppc.h
@@ -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,
-- 
2.7.4


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

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

* [PATCH v2 08/12] crashdump/ppc64: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (6 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 07/12] crashdump/ppc: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-06 19:50   ` Konrad Rzeszutek Wilk
  2017-02-07 16:09   ` Daniel Kiper
  2017-02-06 19:42 ` [PATCH v2 09/12] crashdump/s390: " Eric DeVolder
                   ` (5 subsequent siblings)
  13 siblings, 2 replies; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>

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

diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c
index f62b159..0f4fd77 100644
--- a/kexec/arch/ppc64/crashdump-ppc64.c
+++ b/kexec/arch/ppc64/crashdump-ppc64.c
@@ -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
diff --git a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c
index 09ee025..dd0fc67 100644
--- a/kexec/arch/ppc64/kexec-ppc64.c
+++ b/kexec/arch/ppc64/kexec-ppc64.c
@@ -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
  */
diff --git a/kexec/arch/ppc64/kexec-ppc64.h b/kexec/arch/ppc64/kexec-ppc64.h
index 89ee942..3d20419 100644
--- a/kexec/arch/ppc64/kexec-ppc64.h
+++ b/kexec/arch/ppc64/kexec-ppc64.h
@@ -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);
-- 
2.7.4


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

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

* [PATCH v2 09/12] crashdump/s390: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (7 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 08/12] crashdump/ppc64: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 10/12] crashdump/sh: " Eric DeVolder
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/arch/s390/kexec-s390.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kexec/arch/s390/kexec-s390.c b/kexec/arch/s390/kexec-s390.c
index 074575e..212a64f 100644
--- a/kexec/arch/s390/kexec-s390.c
+++ b/kexec/arch/s390/kexec-s390.c
@@ -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");
+}
-- 
2.7.4


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

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

* [PATCH v2 10/12] crashdump/sh: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (8 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 09/12] crashdump/s390: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 11/12] kexec: Add option to get crash kernel region size Eric DeVolder
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/arch/sh/crashdump-sh.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kexec/arch/sh/crashdump-sh.c b/kexec/arch/sh/crashdump-sh.c
index 9e6af6b..6556eb1 100644
--- a/kexec/arch/sh/crashdump-sh.c
+++ b/kexec/arch/sh/crashdump-sh.c
@@ -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");
+}
-- 
2.7.4


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

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

* [PATCH v2 11/12] kexec: Add option to get crash kernel region size
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (9 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 10/12] crashdump/sh: " Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-06 19:42 ` [PATCH v2 12/12] " Eric DeVolder
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

From: Daniel Kiper <daniel.kiper@oracle.com>

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.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/kexec.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kexec/kexec.h b/kexec/kexec.h
index 2b06f59..3ac81f5 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -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,
-- 
2.7.4


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

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

* [PATCH v2 12/12] kexec: Add option to get crash kernel region size
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (10 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 11/12] kexec: Add option to get crash kernel region size Eric DeVolder
@ 2017-02-06 19:42 ` Eric DeVolder
  2017-02-07 16:14   ` Daniel Kiper
  2017-02-07 14:42 ` [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Daniel Kiper
  2017-02-08  8:37 ` Pratyush Anand
  13 siblings, 1 reply; 22+ messages in thread
From: Eric DeVolder @ 2017-02-06 19:42 UTC (permalink / raw)
  To: horms, kexec, andrew.cooper3, dyoung; +Cc: daniel.kiper, konrad.wilk

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.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
---
 kexec/kexec.8 | 3 +++
 kexec/kexec.c | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/kexec/kexec.8 b/kexec/kexec.8
index f4b39a6..e0131b4 100644
--- a/kexec/kexec.8
+++ b/kexec/kexec.8
@@ -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
diff --git a/kexec/kexec.c b/kexec/kexec.c
index a2ba79d..482b6a7 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -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;
 		}
-- 
2.7.4


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

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

* Re: [PATCH v2 08/12] crashdump/ppc64: Add print_crashkernel_region_size() function
  2017-02-06 19:42 ` [PATCH v2 08/12] crashdump/ppc64: " Eric DeVolder
@ 2017-02-06 19:50   ` Konrad Rzeszutek Wilk
  2017-02-07 16:09   ` Daniel Kiper
  1 sibling, 0 replies; 22+ messages in thread
From: Konrad Rzeszutek Wilk @ 2017-02-06 19:50 UTC (permalink / raw)
  To: Eric DeVolder; +Cc: andrew.cooper3, dyoung, horms, kexec, daniel.kiper

On Mon, Feb 06, 2017 at 01:42:20PM -0600, Eric DeVolder wrote:
> From: Daniel Kiper <daniel.kiper@oracle.com>
> 
> Follow similar x86 patch.

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

'Follow similar x86 pach titled: XYZ".

> 
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
> 

> note
  ^^^^ ?


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

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

* Re: [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (11 preceding siblings ...)
  2017-02-06 19:42 ` [PATCH v2 12/12] " Eric DeVolder
@ 2017-02-07 14:42 ` Daniel Kiper
  2017-02-08  8:37 ` Pratyush Anand
  13 siblings, 0 replies; 22+ messages in thread
From: Daniel Kiper @ 2017-02-07 14:42 UTC (permalink / raw)
  To: Eric DeVolder; +Cc: andrew.cooper3, dyoung, horms, kexec, konrad.wilk

On Mon, Feb 06, 2017 at 01:42:12PM -0600, Eric DeVolder wrote:
> 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.
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>

This does not need to have SOB.

> ---
> 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
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 01/12] crashdump/x86: Add print_crashkernel_region_size() function
  2017-02-06 19:42 ` [PATCH v2 01/12] crashdump/x86: " Eric DeVolder
@ 2017-02-07 14:55   ` Daniel Kiper
  0 siblings, 0 replies; 22+ messages in thread
From: Daniel Kiper @ 2017-02-07 14:55 UTC (permalink / raw)
  To: Eric DeVolder; +Cc: andrew.cooper3, dyoung, horms, kexec, konrad.wilk

On Mon, Feb 06, 2017 at 01:42:13PM -0600, Eric DeVolder wrote:
> From: Daniel Kiper <daniel.kiper@oracle.com>
>
> 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.
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
> ---
> 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
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 03/12] crashdump/cris: Add print_crashkernel_region_size() function
  2017-02-06 19:42 ` [PATCH v2 03/12] crashdump/cris: " Eric DeVolder
@ 2017-02-07 15:07   ` Daniel Kiper
  0 siblings, 0 replies; 22+ messages in thread
From: Daniel Kiper @ 2017-02-07 15:07 UTC (permalink / raw)
  To: Eric DeVolder; +Cc: andrew.cooper3, dyoung, horms, kexec, konrad.wilk

On Mon, Feb 06, 2017 at 01:42:15PM -0600, Eric DeVolder wrote:
> From: Daniel Kiper <daniel.kiper@oracle.com>
>
> 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.
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
> ---
>  kexec/arch/cris/kexec-cris.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/kexec/arch/cris/kexec-cris.c b/kexec/arch/cris/kexec-cris.c
> index 4ac2f89..5601d8e 100644
> --- a/kexec/arch/cris/kexec-cris.c
> +++ b/kexec/arch/cris/kexec-cris.c
> @@ -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
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 05/12] crashdump/m68k: Add print_crashkernel_region_size() function
  2017-02-06 19:42 ` [PATCH v2 05/12] crashdump/m68k: " Eric DeVolder
@ 2017-02-07 15:09   ` Daniel Kiper
  0 siblings, 0 replies; 22+ messages in thread
From: Daniel Kiper @ 2017-02-07 15:09 UTC (permalink / raw)
  To: Eric DeVolder; +Cc: andrew.cooper3, dyoung, horms, kexec, konrad.wilk

On Mon, Feb 06, 2017 at 01:42:17PM -0600, Eric DeVolder wrote:
> From: Daniel Kiper <daniel.kiper@oracle.com>
>
> 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.
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
> ---
>  kexec/arch/m68k/kexec-m68k.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/kexec/arch/m68k/kexec-m68k.c b/kexec/arch/m68k/kexec-m68k.c
> index 372aa37..0cbf18e 100644
> --- a/kexec/arch/m68k/kexec-m68k.c
> +++ b/kexec/arch/m68k/kexec-m68k.c
> @@ -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
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 07/12] crashdump/ppc: Add print_crashkernel_region_size() function
  2017-02-06 19:42 ` [PATCH v2 07/12] crashdump/ppc: " Eric DeVolder
@ 2017-02-07 16:06   ` Daniel Kiper
  0 siblings, 0 replies; 22+ messages in thread
From: Daniel Kiper @ 2017-02-07 16:06 UTC (permalink / raw)
  To: Eric DeVolder; +Cc: andrew.cooper3, dyoung, horms, kexec, konrad.wilk

On Mon, Feb 06, 2017 at 01:42:19PM -0600, Eric DeVolder wrote:
> From: Daniel Kiper <daniel.kiper@oracle.com>
>
> Follow similar x86 patch.
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
> ---
>  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(-)
>
> diff --git a/kexec/arch/ppc/crashdump-powerpc.c b/kexec/arch/ppc/crashdump-powerpc.c
> index 3dc35eb..4c12452 100644
> --- a/kexec/arch/ppc/crashdump-powerpc.c
> +++ b/kexec/arch/ppc/crashdump-powerpc.c
> @@ -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.

> +	else
> +		*start = 0;
> +	if (get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-size", &value)) {
> +		*end = *start + value - 1;
> +	}

Ditto.

> +	else
> +		*end = 0;

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

> +	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.

>  }
>
> +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.

> +                printf("%llu\n", end - start + 1);
> +        } else
> +                printf("0\n");
> +}
> diff --git a/kexec/arch/ppc/kexec-ppc.c b/kexec/arch/ppc/kexec-ppc.c
> index d046110..78e8fb8 100644
> --- a/kexec/arch/ppc/kexec-ppc.c
> +++ b/kexec/arch/ppc/kexec-ppc.c
> @@ -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.

> +{
> +	/* 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.

> +	unsigned long long value = 0;

Lack of empty line here.

> +	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.

> +	} else if (n == sizeof(uint64_t)) {
> +		value = ((uint64_t *)buf)[0];

Ditto.

> +	} 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".

> +	return rcode;

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

> +}
> +
>  /* Get devtree details and create exclude_range array
>   * Also create usablemem_ranges for KEXEC_ON_CRASH
>   */
> diff --git a/kexec/arch/ppc/kexec-ppc.h b/kexec/arch/ppc/kexec-ppc.h
> index 904cf48..69189f0 100644
> --- a/kexec/arch/ppc/kexec-ppc.h
> +++ b/kexec/arch/ppc/kexec-ppc.h
> @@ -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().

>  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
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 08/12] crashdump/ppc64: Add print_crashkernel_region_size() function
  2017-02-06 19:42 ` [PATCH v2 08/12] crashdump/ppc64: " Eric DeVolder
  2017-02-06 19:50   ` Konrad Rzeszutek Wilk
@ 2017-02-07 16:09   ` Daniel Kiper
  1 sibling, 0 replies; 22+ messages in thread
From: Daniel Kiper @ 2017-02-07 16:09 UTC (permalink / raw)
  To: Eric DeVolder; +Cc: andrew.cooper3, dyoung, horms, kexec, konrad.wilk

On Mon, Feb 06, 2017 at 01:42:20PM -0600, Eric DeVolder wrote:
> From: Daniel Kiper <daniel.kiper@oracle.com>
>
> Follow similar x86 patch.
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>
>
> 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
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH v2 12/12] kexec: Add option to get crash kernel region size
  2017-02-06 19:42 ` [PATCH v2 12/12] " Eric DeVolder
@ 2017-02-07 16:14   ` Daniel Kiper
  0 siblings, 0 replies; 22+ messages in thread
From: Daniel Kiper @ 2017-02-07 16:14 UTC (permalink / raw)
  To: Eric DeVolder; +Cc: andrew.cooper3, dyoung, horms, kexec, konrad.wilk

On Mon, Feb 06, 2017 at 01:42:24PM -0600, Eric DeVolder wrote:
> 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.
>
> Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
> Signed-off-by: Eric DeVolder <eric.devolder@oracle.com>

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

Daniel

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

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

* Re: [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function
  2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
                   ` (12 preceding siblings ...)
  2017-02-07 14:42 ` [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Daniel Kiper
@ 2017-02-08  8:37 ` Pratyush Anand
  13 siblings, 0 replies; 22+ messages in thread
From: Pratyush Anand @ 2017-02-08  8:37 UTC (permalink / raw)
  To: Eric DeVolder, horms, kexec, andrew.cooper3, dyoung
  Cc: daniel.kiper, konrad.wilk



On Tuesday 07 February 2017 01:12 AM, Eric DeVolder wrote:
> 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.

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
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

end of thread, other threads:[~2017-02-08  8:38 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-06 19:42 [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Eric DeVolder
2017-02-06 19:42 ` [PATCH v2 01/12] crashdump/x86: " Eric DeVolder
2017-02-07 14:55   ` Daniel Kiper
2017-02-06 19:42 ` [PATCH v2 02/12] crashdump/arm: " Eric DeVolder
2017-02-06 19:42 ` [PATCH v2 03/12] crashdump/cris: " Eric DeVolder
2017-02-07 15:07   ` Daniel Kiper
2017-02-06 19:42 ` [PATCH v2 04/12] crashdump/ia64: " Eric DeVolder
2017-02-06 19:42 ` [PATCH v2 05/12] crashdump/m68k: " Eric DeVolder
2017-02-07 15:09   ` Daniel Kiper
2017-02-06 19:42 ` [PATCH v2 06/12] crashdump/mips: " Eric DeVolder
2017-02-06 19:42 ` [PATCH v2 07/12] crashdump/ppc: " Eric DeVolder
2017-02-07 16:06   ` Daniel Kiper
2017-02-06 19:42 ` [PATCH v2 08/12] crashdump/ppc64: " Eric DeVolder
2017-02-06 19:50   ` Konrad Rzeszutek Wilk
2017-02-07 16:09   ` Daniel Kiper
2017-02-06 19:42 ` [PATCH v2 09/12] crashdump/s390: " Eric DeVolder
2017-02-06 19:42 ` [PATCH v2 10/12] crashdump/sh: " Eric DeVolder
2017-02-06 19:42 ` [PATCH v2 11/12] kexec: Add option to get crash kernel region size Eric DeVolder
2017-02-06 19:42 ` [PATCH v2 12/12] " Eric DeVolder
2017-02-07 16:14   ` Daniel Kiper
2017-02-07 14:42 ` [PATCH v2 00/12] crashdump: Add print_crashkernel_region_size() function Daniel Kiper
2017-02-08  8:37 ` Pratyush Anand

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.