From: Kairui Song <kasong@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Thomas Lendacky <Thomas.Lendacky@amd.com>,
Baoquan He <bhe@redhat.com>, Lianbo Jiang <lijiang@redhat.com>,
Dave Young <dyoung@redhat.com>,
x86@kernel.org,
"kexec@lists.infradead.org" <kexec@lists.infradead.org>,
Kairui Song <kasong@redhat.com>
Subject: [PATCH v3 1/2] x86/kdump: Split some code out of reserve_crashkernel
Date: Tue, 10 Sep 2019 23:13:40 +0800 [thread overview]
Message-ID: <20190910151341.14986-2-kasong@redhat.com> (raw)
In-Reply-To: <20190910151341.14986-1-kasong@redhat.com>
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@redhat.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
next prev parent reply other threads:[~2019-09-10 15:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-10 15:13 [PATCH v3 0/2] x86/kdump: Reserve extra memory when SME or SEV is active Kairui Song
2019-09-10 15:13 ` Kairui Song [this message]
2019-09-10 15:13 ` [PATCH v3 2/2] " Kairui Song
2019-09-11 5:56 ` Ingo Molnar
[not found] ` <CACPcB9cEE5eYWixkUvMeLVdRC5qhrru9PbjbLLxP3k1jsbRanQ@mail.gmail.com>
2019-09-18 7:55 ` [PATCH v3 0/2] " Dave Young
2019-09-18 10:17 ` Kairui Song
2019-09-25 10:36 ` [PATCH v3 2/2] " Kairui Song
2019-09-27 5:42 ` Dave Young
2019-09-27 7:52 ` Kairui Song
2019-10-12 9:24 ` Kairui Song
2019-10-14 11:05 ` Dave Young
2019-10-14 11:11 ` Dave Young
2019-10-15 2:18 ` Dave Young
2019-10-15 17:18 ` Kairui Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190910151341.14986-2-kasong@redhat.com \
--to=kasong@redhat.com \
--cc=Thomas.Lendacky@amd.com \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=dyoung@redhat.com \
--cc=kexec@lists.infradead.org \
--cc=lijiang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).