Skip to contentSkip to conversation

Do not reserve crashkernel high memory if crashkernel low memory reserving failed

PATCH In review Baoquan He 3 participants 4 messages Sep 24, 2015 – Oct 14, 2015 x86

lore
Share & tools
lore

Baoquan He

author
#0 lore raw

PATCH 1/1 Do not reserve crashkernel high memory if crashkernel low memory reserving failed

People reported that when allocating crashkernel memory using ",high" and ",low" syntax, there were cases where the reservation of the "high" portion succeeds, but the reservation of the "low" portion fails. Then kexec can load kdump kernel successfully, but the boot of kdump kernel fails as there's no low memory. This is because allocation of low memory for kdump kernel can fail on large systems for reasons. E.g it could be manually specified crashkernel low memory is too large to find in memblock region.

In this patch add return value for reserve_crashkernel_low. Then try to reserve crashkernel low memory after crashkernel high memory has been allocated. If crashkernel low memory reservation failed free crashkernel high memory and return. User can take measures when they found kdump kernel cann't be loaded successfully.

---
v1->v2:
Boris commented that error value EINVAL is negative, should use "return -EINVAL".

v2->v3:
Yinghai pointed out that during memblock_reserve, we could double the memblock reserve array. New memblock reserve could be overlapped with range for crashkernel high. So we have to reserve crashkernel high firstly, then free it if crashkernel low memory allocation failed.

v3->v4:
Dave suggested using "return -ENOMEM" when low memory reservation failed and printing failure message anyway.

v4->v5:
Andrew suggested changing the content of failure message and taking higher severity KERN_ERR.

 arch/x86/kernel/setup.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
arch/x86/kernel/setup.c +11 -9
index fdb7f2a..e510e61 100644
@@ -493,7 +493,7 @@ static void __init memblock_x86_reserve_range_setup_data(void)
 # define CRASH_KERNEL_ADDR_HIGH_MAX	MAXMEM
 #endif
 
-static void __init reserve_crashkernel_low(void)
+static int __init reserve_crashkernel_low(void)
 {
 #ifdef CONFIG_X86_64
 	const unsigned long long alignment = 16<<20;	/* 16M */
@@ -522,17 +522,16 @@ static void __init reserve_crashkernel_low(void)
 	} else {
 		/* passed with crashkernel=0,low ? */
 		if (!low_size)
-			return;
+			return 0;
 	}
 
 	low_base = memblock_find_in_range(low_size, (1ULL<<32),
 					low_size, alignment);
 
 	if (!low_base) {
-		if (!auto_set)
-			pr_info("crashkernel low reservation failed - No suitable area found.\n");
-
-		return;
+		pr_err("Failed to reserve %ldMB of low memory for crashkernel, please try smaller size.\n",
+				(unsigned long)(low_size >> 20));
+		return -ENOMEM;
 	}
 
 	memblock_reserve(low_base, low_size);
@@ -544,6 +543,7 @@ static void __init reserve_crashkernel_low(void)
 	crashk_low_res.end   = low_base + low_size - 1;
 	insert_resource(&iomem_resource, &crashk_low_res);
 #endif
+	return 0;
 }
 
 static void __init reserve_crashkernel(void)
@@ -595,6 +595,11 @@ static void __init reserve_crashkernel(void)
 	}
 	memblock_reserve(crash_base, crash_size);
 
+	if (crash_base >= (1ULL<<32) && reserve_crashkernel_low()) {
+		memblock_free(crash_base, crash_size);
+		return;
+	}
+
 	printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
 			"for crashkernel (System RAM: %ldMB)\n",
 			(unsigned long)(crash_size >> 20),
@@ -604,9 +609,6 @@ static void __init reserve_crashkernel(void)
 	crashk_res.start = crash_base;
 	crashk_res.end   = crash_base + crash_size - 1;
 	insert_resource(&iomem_resource, &crashk_res);
-
-	if (crash_base >= (1ULL<<32))
-		reserve_crashkernel_low();
 }
 #else
 static void __init reserve_crashkernel(void)
Signature · 1 line
2.4.0
author
#1 lore raw

Hi all,

Ping.

Any other suggestion for this fix?

Quoted 107 lines · Baoquan He

People reported that when allocating crashkernel memory using ",high" and ",low" syntax, there were cases where the reservation of the "high" portion succeeds, but the reservation of the "low" portion fails. Then kexec can load kdump kernel successfully, but the boot of kdump kernel fails as there's no low memory. This is because allocation of low memory for kdump kernel can fail on large systems for reasons. E.g it could be manually specified crashkernel low memory is too large to find in memblock region.

In this patch add return value for reserve_crashkernel_low. Then try to reserve crashkernel low memory after crashkernel high memory has been allocated. If crashkernel low memory reservation failed free crashkernel high memory and return. User can take measures when they found kdump kernel cann't be loaded successfully.

---
v1->v2:
Boris commented that error value EINVAL is negative, should use "return -EINVAL".

v2->v3:
Yinghai pointed out that during memblock_reserve, we could double the memblock reserve array. New memblock reserve could be overlapped with range for crashkernel high. So we have to reserve crashkernel high firstly, then free it if crashkernel low memory allocation failed.

v3->v4:
Dave suggested using "return -ENOMEM" when low memory reservation failed and printing failure message anyway.

v4->v5:
Andrew suggested changing the content of failure message and taking higher severity KERN_ERR.

 arch/x86/kernel/setup.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
arch/x86/kernel/setup.c +11 -9
index fdb7f2a..e510e61 100644
@@ -493,7 +493,7 @@ static void __init memblock_x86_reserve_range_setup_data(void)
 # define CRASH_KERNEL_ADDR_HIGH_MAX	MAXMEM
 #endif
 
-static void __init reserve_crashkernel_low(void)
+static int __init reserve_crashkernel_low(void)
 {
 #ifdef CONFIG_X86_64
 	const unsigned long long alignment = 16<<20;	/* 16M */
@@ -522,17 +522,16 @@ static void __init reserve_crashkernel_low(void)
 	} else {
 		/* passed with crashkernel=0,low ? */
 		if (!low_size)
-			return;
+			return 0;
 	}
 
 	low_base = memblock_find_in_range(low_size, (1ULL<<32),
 					low_size, alignment);
 
 	if (!low_base) {
-		if (!auto_set)
-			pr_info("crashkernel low reservation failed - No suitable area found.\n");
-
-		return;
+		pr_err("Failed to reserve %ldMB of low memory for crashkernel, please try smaller size.\n",
+				(unsigned long)(low_size >> 20));
+		return -ENOMEM;
 	}
 
 	memblock_reserve(low_base, low_size);
@@ -544,6 +543,7 @@ static void __init reserve_crashkernel_low(void)
 	crashk_low_res.end   = low_base + low_size - 1;
 	insert_resource(&iomem_resource, &crashk_low_res);
 #endif
+	return 0;
 }
 
 static void __init reserve_crashkernel(void)
@@ -595,6 +595,11 @@ static void __init reserve_crashkernel(void)
 	}
 	memblock_reserve(crash_base, crash_size);
 
+	if (crash_base >= (1ULL<<32) && reserve_crashkernel_low()) {
+		memblock_free(crash_base, crash_size);
+		return;
+	}
+
 	printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
 			"for crashkernel (System RAM: %ldMB)\n",
 			(unsigned long)(crash_size >> 20),
@@ -604,9 +609,6 @@ static void __init reserve_crashkernel(void)
 	crashk_res.start = crash_base;
 	crashk_res.end   = crash_base + crash_size - 1;
 	insert_resource(&iomem_resource, &crashk_res);
-
-	if (crash_base >= (1ULL<<32))
-		reserve_crashkernel_low();
 }
 #else
 static void __init reserve_crashkernel(void)
Signature · 1 line
2.4.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Baoquan He
Quoted 32 lines · Baoquan He

People reported that when allocating crashkernel memory using ",high" and ",low" syntax, there were cases where the reservation of the "high" portion succeeds, but the reservation of the "low" portion fails. Then kexec can load kdump kernel successfully, but the boot of kdump kernel fails as there's no low memory. This is because allocation of low memory for kdump kernel can fail on large systems for reasons. E.g it could be manually specified crashkernel low memory is too large to find in memblock region.

In this patch add return value for reserve_crashkernel_low. Then try to reserve crashkernel low memory after crashkernel high memory has been allocated. If crashkernel low memory reservation failed free crashkernel high memory and return. User can take measures when they found kdump kernel cann't be loaded successfully.

---
v1->v2:
Boris commented that error value EINVAL is negative, should use "return -EINVAL".

v2->v3:
Yinghai pointed out that during memblock_reserve, we could double the memblock reserve array. New memblock reserve could be overlapped with range for crashkernel high. So we have to reserve crashkernel high firstly, then free it if crashkernel low memory allocation failed.

v3->v4:
Dave suggested using "return -ENOMEM" when low memory reservation failed and printing failure message anyway.

Quoted 6 lines

v4->v5:
Andrew suggested changing the content of failure message and taking higher severity KERN_ERR.

 arch/x86/kernel/setup.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

The patch is also in SLES for some time now and was successfully tested there.

Joerg

Reviewed-by Joerg Roedel Tested-by Joerg Roedel
#3 lore raw
Quoted 4 lines · Joerg Roedel

The patch is also in SLES for some time now and was successfully tested there.

Thanks, I massaged it a bit and ended up applying this:

---
From: Baoquan He <[email protected]>
Date: Thu, 24 Sep 2015 11:24:51 +0800
Subject: [PATCH] x86/setup: Do not reserve crashkernel high memory if low
reservation failed

People reported that when allocating crashkernel memory using the ",high" and ",low" syntax, there were cases where the reservation of the high portion succeeds but the reservation of the low portion fails.

Then kexec can load the kdump kernel successfully, but booting the kdump kernel fails as there's no low memory.

The low memory allocation for the kdump kernel can fail on large systems for a couple of reasons. For example, the manually specified crashkernel low memory can be too large and thus no adequate memblock region would be found.

Therefore, we try to reserve low memory for the crash kernel *after* the high memory portion has been allocated. If that fails, we free crashkernel high memory too and return. The user can then take measures accordingly.

Cc Andrew Morton <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Dave Young <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Kosina <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Mark Salter <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc WANG Chao <[email protected]>
Cc x86-ml <[email protected]>
[ Massage text. ]

Signed-off-by:

---
 arch/x86/kernel/setup.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
arch/x86/kernel/setup.c +11 -9
index fdb7f2a2d328..1b36839e41eb 100644
@@ -493,7 +493,7 @@ static void __init memblock_x86_reserve_range_setup_data(void)
 # define CRASH_KERNEL_ADDR_HIGH_MAX	MAXMEM
 #endif
 
-static void __init reserve_crashkernel_low(void)
+static int __init reserve_crashkernel_low(void)
 {
 #ifdef CONFIG_X86_64
 	const unsigned long long alignment = 16<<20;	/* 16M */
@@ -522,17 +522,16 @@ static void __init reserve_crashkernel_low(void)
 	} else {
 		/* passed with crashkernel=0,low ? */
 		if (!low_size)
-			return;
+			return 0;
 	}
 
 	low_base = memblock_find_in_range(low_size, (1ULL<<32),
 					low_size, alignment);
 
 	if (!low_base) {
-		if (!auto_set)
-			pr_info("crashkernel low reservation failed - No suitable area found.\n");
-
-		return;
+		pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n",
+		       (unsigned long)(low_size >> 20));
+		return -ENOMEM;
 	}
 
 	memblock_reserve(low_base, low_size);
@@ -544,6 +543,7 @@ static void __init reserve_crashkernel_low(void)
 	crashk_low_res.end   = low_base + low_size - 1;
 	insert_resource(&iomem_resource, &crashk_low_res);
 #endif
+	return 0;
 }
 
 static void __init reserve_crashkernel(void)
@@ -595,6 +595,11 @@ static void __init reserve_crashkernel(void)
 	}
 	memblock_reserve(crash_base, crash_size);
 
+	if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) {
+		memblock_free(crash_base, crash_size);
+		return;
+	}
+
 	printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
 			"for crashkernel (System RAM: %ldMB)\n",
 			(unsigned long)(crash_size >> 20),
@@ -604,9 +609,6 @@ static void __init reserve_crashkernel(void)
 	crashk_res.start = crash_base;
 	crashk_res.end   = crash_base + crash_size - 1;
 	insert_resource(&iomem_resource, &crashk_res);
-
-	if (crash_base >= (1ULL<<32))
-		reserve_crashkernel_low();
 }
 #else
 static void __init reserve_crashkernel(void)
Signature · 4 lines
2.3.5

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--