Skip to contentSkip to conversation

Load crash kernel high on x86

PATCH Superseded Petr Tesarik 3 participants 5 messages Sep 23, 2015 – Sep 24, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Load crash kernel high on x86

There may be more than one crash kernel regions on x86. Currently, kexec-tools picks the largest one. If high reservation is smaller than low, it will try to load panic kernel low. However, the kexec syscall checks that target address is within crashk_res boundaries, so attempts to load crash kernel low result in -EADDRNOTAVAIL, and kexec prints out this error message:

kexec_load failed: Cannot assign requested address

Looking at the logic in arch/x86/kernel/setup.c, there are only two possible layouts:

1. crashk_res is below 4G, and there is only one region,
2. crashk_res is above 4G, and crashk_low_res is below 4G

In either case, kexec-tools must pick the highest region.

---
 kexec/arch/i386/crashdump-x86.c    | 21 +++++++--------------
 kexec/arch/i386/kexec-x86-common.c |  4 ++--
 kexec/kexec.h                      |  2 +-
 3 files changed, 10 insertions(+), 17 deletions(-)
kexec/arch/i386/crashdump-x86.c +7 -14
index 63959b7..9d866cc 100644
@@ -1026,24 +1026,17 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 	return 0;
 }
 
-int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end)
+/* On x86, the kernel may make a low reservation in addition to the
+ * normal reservation. However, the kernel refuses to load the panic
+ * kernel to low memory, so always choose the highest range.
+ */
+int get_crash_kernel_range(uint64_t *start, uint64_t *end)
 {
-	int i, idx = -1;
-	unsigned long sz_max = 0, sz;
-
 	if (!crash_reserved_mem_nr)
 		return -1;
 
-	for (i = crash_reserved_mem_nr - 1; i >= 0; i--) {
-		sz = crash_reserved_mem[i].end - crash_reserved_mem[i].start +1;
-		if (sz <= sz_max)
-			continue;
-		sz_max = sz;
-		idx = i;
-	}
-
-	*start = crash_reserved_mem[idx].start;
-	*end = crash_reserved_mem[idx].end;
+	*start = crash_reserved_mem[crash_reserved_mem_nr - 1].start;
+	*end = crash_reserved_mem[crash_reserved_mem_nr - 1].end;
 
 	return 0;
 }
kexec/arch/i386/kexec-x86-common.c +2 -2
index 041c8ec..620c02d 100644
@@ -371,9 +371,9 @@ int get_memory_ranges(struct memory_range **range, int *ranges,
 	    !(kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
 		uint64_t start, end;
 
-		ret = get_max_crash_kernel_limit(&start, &end);
+		ret = get_crash_kernel_range(&start, &end);
 		if (ret != 0) {
-			fprintf(stderr, "get_max_crash_kernel_limit failed.\n");
+			fprintf(stderr, "get_crash_kernel_range failed.\n");
 			return -1;
 		}
 
kexec/kexec.h +1 -1
index 0fa977f..5577d84 100644
@@ -288,7 +288,7 @@ int arch_process_options(int argc, char **argv);
 int arch_compat_trampoline(struct kexec_info *info);
 void arch_update_purgatory(struct kexec_info *info);
 int is_crashkernel_mem_reserved(void);
-int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end);
+int get_crash_kernel_range(uint64_t *start, uint64_t *end);
 char *get_command_line(void);
 
 int kexec_iomem_for_each_line(char *match,
Signature · 6 lines
2.1.4

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Petr Tesarik

There may be more than one crash kernel regions on x86. Currently, kexec-tools picks the largest one. If high reservation is smaller than low, it will try to load panic kernel low. However, the kexec syscall checks that target address is within crashk_res boundaries, so attempts to load crash kernel low result in -EADDRNOTAVAIL, and kexec prints out this error message:

kexec_load failed: Cannot assign requested address

Quoted 7 lines

Looking at the logic in arch/x86/kernel/setup.c, there are only two possible layouts:

1. crashk_res is below 4G, and there is only one region,
2. crashk_res is above 4G, and crashk_low_res is below 4G

In either case, kexec-tools must pick the highest region.

Quoted 82 lines
---
 kexec/arch/i386/crashdump-x86.c    | 21 +++++++--------------
 kexec/arch/i386/kexec-x86-common.c |  4 ++--
 kexec/kexec.h                      |  2 +-
 3 files changed, 10 insertions(+), 17 deletions(-)
kexec/arch/i386/crashdump-x86.c +7 -14
index 63959b7..9d866cc 100644
@@ -1026,24 +1026,17 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 	return 0;
 }
 
-int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end)
+/* On x86, the kernel may make a low reservation in addition to the
+ * normal reservation. However, the kernel refuses to load the panic
+ * kernel to low memory, so always choose the highest range.
+ */
+int get_crash_kernel_range(uint64_t *start, uint64_t *end)
 {
-	int i, idx = -1;
-	unsigned long sz_max = 0, sz;
-
 	if (!crash_reserved_mem_nr)
 		return -1;
 
-	for (i = crash_reserved_mem_nr - 1; i >= 0; i--) {
-		sz = crash_reserved_mem[i].end - crash_reserved_mem[i].start +1;
-		if (sz <= sz_max)
-			continue;
-		sz_max = sz;
-		idx = i;
-	}
-
-	*start = crash_reserved_mem[idx].start;
-	*end = crash_reserved_mem[idx].end;
+	*start = crash_reserved_mem[crash_reserved_mem_nr - 1].start;
+	*end = crash_reserved_mem[crash_reserved_mem_nr - 1].end;
 
 	return 0;
 }
kexec/arch/i386/kexec-x86-common.c +2 -2
index 041c8ec..620c02d 100644
@@ -371,9 +371,9 @@ int get_memory_ranges(struct memory_range **range, int *ranges,
 	    !(kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
 		uint64_t start, end;
 
-		ret = get_max_crash_kernel_limit(&start, &end);
+		ret = get_crash_kernel_range(&start, &end);
 		if (ret != 0) {
-			fprintf(stderr, "get_max_crash_kernel_limit failed.\n");
+			fprintf(stderr, "get_crash_kernel_range failed.\n");
 			return -1;
 		}
 
kexec/kexec.h +1 -1
index 0fa977f..5577d84 100644
@@ -288,7 +288,7 @@ int arch_process_options(int argc, char **argv);
 int arch_compat_trampoline(struct kexec_info *info);
 void arch_update_purgatory(struct kexec_info *info);
 int is_crashkernel_mem_reserved(void);
-int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end);
+int get_crash_kernel_range(uint64_t *start, uint64_t *end);
 char *get_command_line(void);
 
 int kexec_iomem_for_each_line(char *match,
Signature · 6 lines
2.1.4

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

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

#2 lore raw
In reply to Petr Tesarik
Quoted 10 lines · Petr Tesarik
 kexec/arch/i386/crashdump-x86.c    | 21 +++++++--------------
 kexec/arch/i386/kexec-x86-common.c |  4 ++--
 kexec/kexec.h                      |  2 +-
 3 files changed, 10 insertions(+), 17 deletions(-)
kexec/arch/i386/crashdump-x86.c +0 -0
index 63959b7..9d866cc 100644

kexec/arch/i386/crashdump-x86.c int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline, · line 1033

Quoted 9 lines
kexec/arch/i386/crashdump-x86.c +5 -1
@@ -1026,24 +1026,17 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 	return 0;
 }
 
-int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end)
+/* On x86, the kernel may make a low reservation in addition to the
+ * normal reservation. However, the kernel refuses to load the panic
+ * kernel to low memory, so always choose the highest range.
+ */
+int get_crash_kernel_range(uint64_t *start, uint64_t *end)

How about get_crash_kernel_load_range? In kernel crashk_res and crashk_low_res are all named as "Crash kernel", but only crashk_res is used to load kernel/initrd stuffs.

Quoted 58 lines
kexec/arch/i386/crashdump-x86.c +2 -13
 {
-	int i, idx = -1;
-	unsigned long sz_max = 0, sz;
-
 	if (!crash_reserved_mem_nr)
 		return -1;
 
-	for (i = crash_reserved_mem_nr - 1; i >= 0; i--) {
-		sz = crash_reserved_mem[i].end - crash_reserved_mem[i].start +1;
-		if (sz <= sz_max)
-			continue;
-		sz_max = sz;
-		idx = i;
-	}
-
-	*start = crash_reserved_mem[idx].start;
-	*end = crash_reserved_mem[idx].end;
+	*start = crash_reserved_mem[crash_reserved_mem_nr - 1].start;
+	*end = crash_reserved_mem[crash_reserved_mem_nr - 1].end;
 
 	return 0;
 }
kexec/arch/i386/kexec-x86-common.c +2 -2
index 041c8ec..620c02d 100644
@@ -371,9 +371,9 @@ int get_memory_ranges(struct memory_range **range, int *ranges,
 	    !(kexec_flags & KEXEC_PRESERVE_CONTEXT)) {
 		uint64_t start, end;
 
-		ret = get_max_crash_kernel_limit(&start, &end);
+		ret = get_crash_kernel_range(&start, &end);
 		if (ret != 0) {
-			fprintf(stderr, "get_max_crash_kernel_limit failed.\n");
+			fprintf(stderr, "get_crash_kernel_range failed.\n");
 			return -1;
 		}
 
kexec/kexec.h +1 -1
index 0fa977f..5577d84 100644
@@ -288,7 +288,7 @@ int arch_process_options(int argc, char **argv);
 int arch_compat_trampoline(struct kexec_info *info);
 void arch_update_purgatory(struct kexec_info *info);
 int is_crashkernel_mem_reserved(void);
-int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end);
+int get_crash_kernel_range(uint64_t *start, uint64_t *end);
 char *get_command_line(void);
 
 int kexec_iomem_for_each_line(char *match,
Signature · 6 lines
2.1.4

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

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

#3 lore raw
Quoted 14 lines · On Thu, 24 Sep 2015 11:29:42 +0800 Baoquan He <[email protected]> wrote:
Quoted 13 lines · Petr Tesarik
 kexec/arch/i386/crashdump-x86.c    | 21 +++++++--------------
 kexec/arch/i386/kexec-x86-common.c |  4 ++--
 kexec/kexec.h                      |  2 +-
 3 files changed, 10 insertions(+), 17 deletions(-)
kexec/arch/i386/crashdump-x86.c +0 -0
index 63959b7..9d866cc 100644
@@ -1026,24 +1026,17 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 	return 0;
 }
 
Quoted 10 lines

kexec/arch/i386/crashdump-x86.c int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline, · line 1033

Quoted 6 lines
kexec/arch/i386/crashdump-x86.c +5 -1
-int get_max_crash_kernel_limit(uint64_t *start, uint64_t *end)
+/* On x86, the kernel may make a low reservation in addition to the
+ * normal reservation. However, the kernel refuses to load the panic
+ * kernel to low memory, so always choose the highest range.
+ */
+int get_crash_kernel_range(uint64_t *start, uint64_t *end)

How about get_crash_kernel_load_range? In kernel crashk_res and crashk_low_res are all named as "Crash kernel", but only crashk_res is used to load kernel/initrd stuffs.

I'm glad this patch is getting a bikeshedding kind of discussion. ;-)
I don't mind calling the function whatever you like. So let's make it get_crash_kernel_load_range. Wait for v3. ;-)

Petr Tesarik

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

#4 lore raw
Quoted 10 lines · Petr Tesarik
Quoted 3 lines · On Thu, 24 Sep 2015 11:29:42 +0800 Baoquan He <[email protected]> wrote:

How about get_crash_kernel_load_range? In kernel crashk_res and crashk_low_res are all named as "Crash kernel", but only crashk_res is used to load kernel/initrd stuffs.

I'm glad this patch is getting a bikeshedding kind of discussion. ;-)
I don't mind calling the function whatever you like. So let's make it get_crash_kernel_load_range. Wait for v3. ;-)

Hi Petr,

I think it's a reasonable fix when I saw your v1 and offer my ack. Then people think the function name should be adjusted. If you think like that, I will take back my last comment, then you don't need to bother to fix it.

Baoquan

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