Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1461199

[RFC 1/4] Creating one or two CMA area at Boot time

From Ronit Halder <ronit.crj@gmail.com>
Newsgroups linux.kernel
Subject [RFC 1/4] Creating one or two CMA area at Boot time
Date 2016-08-12 16:30 +0200
Message-ID <s5lDb-2Nj-19@gated-at.bofh.it> (permalink)
References <s5ltv-2Ka-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This patch create CMA area(s) at boot time. In case of x86_32
only one CMA area will be created. In case of x86_64 if the
user wants to reserve high memory for crash kernel, then there
must be at least 256MB (needed for swiotlb and DMA buffers)
low memory. In that case two CMA areas (one in low memory and
one in high memory) will be created.

Signed-off-by: Ronit Halder <ronit.crj@gmail.com>

---
 arch/x86/kernel/setup.c | 44 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d2bbe34..87c16c7 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -69,6 +69,7 @@
 #include <linux/crash_dump.h>
 #include <linux/tboot.h>
 #include <linux/jiffies.h>
+#include <linux/cma.h>
 
 #include <video/edid.h>
 
@@ -123,6 +124,10 @@
 unsigned long max_low_pfn_mapped;
 unsigned long max_pfn_mapped;
 
+#ifdef CONFIG_KEXEC_CMA
+struct cma *crashk_cma;
+struct cma *crashk_cma_low;
+#endif
 #ifdef CONFIG_DMI
 RESERVE_BRK(dmi_alloc, 65536);
 #endif
@@ -532,6 +537,18 @@ static int __init reserve_crashkernel_low(void)
 		return -ENOMEM;
 	}
 
+#ifdef CONFIG_KEXEC_CMA
+	ret =  cma_declare_contiguous(low_base, low_size, 0, CRASH_ALIGN, 0, 1, &crashk_cma_low);
+	if (ret) {
+		pr_err("%s: Error reserving CMA area for crashkernel low.\n", __func__);
+		return ret;
+	}
+
+	pr_info("Reserving %ldMB of low memory at %ldMB for CMA area for crashkernel low(System low RAM: %ldMB)\n",
+		(unsigned long)(low_size >> 20),
+		(unsigned long)(low_base >> 20),
+		(unsigned long)(total_low_mem >> 20));
+#else
 	ret = memblock_reserve(low_base, low_size);
 	if (ret) {
 		pr_err("%s: Error reserving crashkernel low memblock.\n", __func__);
@@ -547,6 +564,7 @@ static int __init reserve_crashkernel_low(void)
 	crashk_low_res.end   = low_base + low_size - 1;
 	insert_resource(&iomem_resource, &crashk_low_res);
 #endif
+#endif
 	return 0;
 }
 
@@ -578,8 +596,10 @@ static void __init reserve_crashkernel(void)
 						    high ? CRASH_ADDR_HIGH_MAX
 							 : CRASH_ADDR_LOW_MAX,
 						    crash_size, CRASH_ALIGN);
+		pr_info("Crash_base %llu crash_size %llu\n", crash_base, crash_size);
+
 		if (!crash_base) {
-			pr_info("crashkernel reservation failed - No suitable area found.\n");
+			pr_info("Crashkernel reservation failed - No suitable area found.\n");
 			return;
 		}
 
@@ -589,11 +609,28 @@ static void __init reserve_crashkernel(void)
 		start = memblock_find_in_range(crash_base,
 					       crash_base + crash_size,
 					       crash_size, 1 << 20);
+		pr_info("Base_mentioned crash_base %llu crash_size %llu\n", crash_base, crash_size);
 		if (start != crash_base) {
 			pr_info("crashkernel reservation failed - memory is in use.\n");
 			return;
 		}
 	}
+#ifdef CONFIG_KEXEC_CMA
+	crashk_cma = NULL;
+	crashk_cma_low = NULL;
+	if (crash_base >= (1ULL << 32) && reserve_crashkernel_low())
+		return;
+	ret =  cma_declare_contiguous(crash_base, crash_size, 0, CRASH_ALIGN, 0, 1, &crashk_cma);
+	if (ret) {
+		pr_err("%s: Error reserving CMA area for crashkernel.\n", __func__);
+		return;
+	}
+
+	pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n",
+		(unsigned long)(crash_size >> 20),
+		(unsigned long)(crash_base >> 20),
+		(unsigned long)(total_mem >> 20));
+#else
 	ret = memblock_reserve(crash_base, crash_size);
 	if (ret) {
 		pr_err("%s: Error reserving crashkernel memblock.\n", __func__);
@@ -613,6 +650,7 @@ 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);
+#endif
 }
 #else
 static void __init reserve_crashkernel(void)
@@ -720,7 +758,7 @@ static void __init trim_snb_memory(void)
 	 * already been reserved.
 	 */
 	memblock_reserve(0, 1<<20);
-	
+
 	for (i = 0; i < ARRAY_SIZE(bad_pages); i++) {
 		if (memblock_reserve(bad_pages[i], PAGE_SIZE))
 			printk(KERN_WARNING "failed to reserve 0x%08lx\n",
@@ -812,7 +850,7 @@ static void __init trim_low_memory_range(void)
 {
 	memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE));
 }
-	
+
 /*
  * Dump out kernel offset information on panic.
  */
-- 
2.9.0.GIT

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC 0/4] Kexec: Enable run time memory resrvation of crash kernel Ronit Halder <ronit.crj@gmail.com> - 2016-08-12 16:20 +0200
  [RFC 2/4] Functions for memory reservation and release Ronit Halder <ronit.crj@gmail.com> - 2016-08-12 16:30 +0200
  [RFC 1/4] Creating one or two CMA area at Boot time Ronit Halder <ronit.crj@gmail.com> - 2016-08-12 16:30 +0200
  [RFC 4/4] Enable memory allocation through sysfs interface Ronit Halder <ronit.crj@gmail.com> - 2016-08-12 16:30 +0200
  [RFC 3/4] Adding a new kernel configuration to enable the feature Ronit Halder <ronit.crj@gmail.com> - 2016-08-12 16:30 +0200
  Re: [RFC 0/4] Kexec: Enable run time memory resrvation of crash  kernel Pratyush Anand <panand@redhat.com> - 2016-08-22 13:00 +0200
    Re: [RFC 0/4] Kexec: Enable run time memory resrvation of crash  kernel Xunlei Pang <xpang@redhat.com> - 2016-08-23 09:20 +0200

csiph-web