lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190910151341.14986-2-kasong@redhat.com>
Date:   Tue, 10 Sep 2019 23:13:40 +0800
From:   Kairui Song <kasong@...hat.com>
To:     linux-kernel@...r.kernel.org
Cc:     Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Thomas Lendacky <Thomas.Lendacky@....com>,
        Baoquan He <bhe@...hat.com>, Lianbo Jiang <lijiang@...hat.com>,
        Dave Young <dyoung@...hat.com>, x86@...nel.org,
        "kexec@...ts.infradead.org" <kexec@...ts.infradead.org>,
        Kairui Song <kasong@...hat.com>
Subject: [PATCH v3 1/2] x86/kdump: Split some code out of reserve_crashkernel

Split out the code related to finding suitable region for kdump out of
reserve_crashkernel, clean up and refactor for further change, no feature
change.

Signed-off-by: Kairui Song <kasong@...hat.com>
---
 arch/x86/kernel/setup.c | 92 +++++++++++++++++++++++++++--------------
 1 file changed, 60 insertions(+), 32 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index bbe35bf879f5..71f20bb18cb0 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -526,6 +526,63 @@ static int __init reserve_crashkernel_low(void)
 	return 0;
 }
 
+static int __init crashkernel_find_region(unsigned long long *crash_base,
+					  unsigned long long *crash_size,
+					  bool high)
+{
+	unsigned long long base, size;
+
+	base = *crash_base;
+	size = *crash_size;
+
+	/*
+	 * base == 0 means: find the address automatically, else just
+	 * verify the region is useable
+	 */
+	if (base) {
+		unsigned long long start;
+
+		start = memblock_find_in_range(base, base + size,
+					       size, 1 << 20);
+		if (start != base) {
+			pr_info("crashkernel reservation failed - memory is in use.\n");
+			return -1;
+		}
+		return 0;
+	}
+
+	/*
+	 * crashkernel=x,high reserves memory over 4G, also allocates
+	 * 256M extra low memory for DMA buffers and swiotlb.
+	 * But the extra memory is not required for all machines.
+	 * So try low memory first and fall back to high memory
+	 * unless "crashkernel=size[KMG],high" is specified.
+	 */
+	if (high)
+		goto high_reserve;
+
+	base = memblock_find_in_range(CRASH_ALIGN,
+				      CRASH_ADDR_LOW_MAX, size,
+				      CRASH_ALIGN);
+	if (base)
+		goto found;
+
+high_reserve:
+	/* Try high reserve */
+	base = memblock_find_in_range(CRASH_ALIGN,
+				      CRASH_ADDR_HIGH_MAX, size,
+				      CRASH_ALIGN);
+	if (base)
+		goto found;
+
+	pr_info("crashkernel reservation failed - No suitable area found.\n");
+	return -1;
+found:
+	*crash_base = base;
+	*crash_size = size;
+	return 0;
+}
+
 static void __init reserve_crashkernel(void)
 {
 	unsigned long long crash_size, crash_base, total_mem;
@@ -550,39 +607,10 @@ static void __init reserve_crashkernel(void)
 		return;
 	}
 
-	/* 0 means: find the address automatically */
-	if (!crash_base) {
-		/*
-		 * Set CRASH_ADDR_LOW_MAX upper bound for crash memory,
-		 * crashkernel=x,high reserves memory over 4G, also allocates
-		 * 256M extra low memory for DMA buffers and swiotlb.
-		 * But the extra memory is not required for all machines.
-		 * So try low memory first and fall back to high memory
-		 * unless "crashkernel=size[KMG],high" is specified.
-		 */
-		if (!high)
-			crash_base = memblock_find_in_range(CRASH_ALIGN,
-						CRASH_ADDR_LOW_MAX,
-						crash_size, CRASH_ALIGN);
-		if (!crash_base)
-			crash_base = memblock_find_in_range(CRASH_ALIGN,
-						CRASH_ADDR_HIGH_MAX,
-						crash_size, CRASH_ALIGN);
-		if (!crash_base) {
-			pr_info("crashkernel reservation failed - No suitable area found.\n");
-			return;
-		}
-	} else {
-		unsigned long long start;
+	ret = crashkernel_find_region(&crash_base, &crash_size, high);
+	if (ret)
+		return;
 
-		start = memblock_find_in_range(crash_base,
-					       crash_base + crash_size,
-					       crash_size, 1 << 20);
-		if (start != crash_base) {
-			pr_info("crashkernel reservation failed - memory is in use.\n");
-			return;
-		}
-	}
 	ret = memblock_reserve(crash_base, crash_size);
 	if (ret) {
 		pr_err("%s: Error reserving crashkernel memblock.\n", __func__);
-- 
2.21.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ