Discussion:
[PATCH v2 01/12] crashdump/x86: Add print_crashkernel_region_size() function
Eric DeVolder
2017-02-06 19:42:13 UTC
Permalink
From: 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 <***@oracle.com>
Signed-off-by: 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
Eric DeVolder
2017-02-06 19:42:17 UTC
Permalink
From: 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 <***@oracle.com>
Signed-off-by: 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
Daniel Kiper
2017-02-07 15:09:24 UTC
Permalink
Post by Eric DeVolder
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(+)
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
Eric DeVolder
2017-02-06 19:42:22 UTC
Permalink
From: Daniel Kiper <***@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <***@oracle.com>
Signed-off-by: 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
Eric DeVolder
2017-02-06 19:42:21 UTC
Permalink
From: Daniel Kiper <***@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <***@oracle.com>
Signed-off-by: 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
Eric DeVolder
2017-02-06 19:42:24 UTC
Permalink
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 <***@oracle.com>
Signed-off-by: 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
Daniel Kiper
2017-02-07 16:14:08 UTC
Permalink
Post by 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
Eric DeVolder
2017-02-06 19:42:20 UTC
Permalink
From: Daniel Kiper <***@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <***@oracle.com>
Signed-off-by: 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
Konrad Rzeszutek Wilk
2017-02-06 19:50:31 UTC
Permalink
Post by Eric DeVolder
Follow similar x86 patch.
You may actually spell out the name of the x86 patch, like:

'Follow similar x86 pach titled: XYZ".
Post by Eric DeVolder
note
^^^^ ?
Daniel Kiper
2017-02-07 16:09:12 UTC
Permalink
Post by Eric DeVolder
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
Eric DeVolder
2017-02-06 19:42:23 UTC
Permalink
From: 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 <***@oracle.com>
Signed-off-by: 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
Eric DeVolder
2017-02-06 19:42:18 UTC
Permalink
From: Daniel Kiper <***@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <***@oracle.com>
Signed-off-by: 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
Eric DeVolder
2017-02-06 19:42:14 UTC
Permalink
From: Daniel Kiper <***@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <***@oracle.com>
Signed-off-by: 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
Eric DeVolder
2017-02-06 19:42:19 UTC
Permalink
From: Daniel Kiper <***@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <***@oracle.com>
Signed-off-by: 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
Daniel Kiper
2017-02-07 16:06:09 UTC
Permalink
Post by Eric DeVolder
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(-)
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.
Post by Eric DeVolder
+ else
+ *start = 0;
+ if (get_devtree_value("/proc/device-tree/chosen/linux,crashkernel-size", &value)) {
+ *end = *start + value - 1;
+ }
Ditto.
Post by Eric DeVolder
+ else
+ *end = 0;
I think that you should return -1 if get_devtree_value() returned error
here and there.
Post by Eric DeVolder
+ 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.
Post by Eric DeVolder
}
+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.
Post by Eric DeVolder
+ 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
return -1;
}
+int get_devtree_value (const char *fname, unsigned long long *pvalue)
Redundant space between function name and bracket.
Post by Eric DeVolder
+{
+ /* 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.
Post by Eric DeVolder
+ unsigned long long value = 0;
Lack of empty line here.
Post by Eric DeVolder
+ 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.
Post by Eric DeVolder
+ } else if (n == sizeof(uint64_t)) {
+ value = ((uint64_t *)buf)[0];
Ditto.
Post by Eric DeVolder
+ } 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".
Post by Eric DeVolder
+ return rcode;
Please do not glue all lines into one giant block here and there. It is unreadable.
Post by Eric DeVolder
+}
+
/* 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().
Post by Eric DeVolder
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
Eric DeVolder
2017-02-06 19:42:16 UTC
Permalink
From: Daniel Kiper <***@oracle.com>

Follow similar x86 patch.

Signed-off-by: Daniel Kiper <***@oracle.com>
Signed-off-by: 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
Eric DeVolder
2017-02-06 19:42:15 UTC
Permalink
From: 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 <***@oracle.com>
Signed-off-by: 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
Daniel Kiper
2017-02-07 15:07:49 UTC
Permalink
Post by Eric DeVolder
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(+)
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
Daniel Kiper
2017-02-07 14:42:06 UTC
Permalink
Post by 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.
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.
Post by Eric DeVolder
---
v0: Interal version.
v1: Posted to kexec-tools mailing list
- 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
Daniel Kiper
2017-02-07 14:55:38 UTC
Permalink
Post by 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.
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
- 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
Pratyush Anand
2017-02-08 08:37:57 UTC
Permalink
Post by 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.
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

Loading...