Re: [PATCHv2] x86/boot/KASLR: skip the specified crashkernel reserved region
From: Chao Fan
Date: Thu Mar 21 2019 - 02:38:22 EST
On Wed, Mar 13, 2019 at 12:19:31PM +0800, Pingfan Liu wrote:
I tested it in Qemu test with 12G memory, and set crashkernel=6G@6G.
Without this PATCH, it successed to reserve memory just 4 times(total
10 times).
With this PATCH, it successed to reserve memory 15 times(total 15
times).
So I think if you post new version, you can add:
Tested-by: Chao Fan <fanc.fnst@xxxxxxxxxxxxxx>
Thanks,
Chao Fan
>crashkernel=x@y option may fail to reserve the required memory region if
>KASLR puts kernel into the region. To avoid this uncertainty, making KASLR
>skip the required region.
>
>Signed-off-by: Pingfan Liu <kernelfans@xxxxxxxxx>
>Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>Cc: Ingo Molnar <mingo@xxxxxxxxxx>
>Cc: Borislav Petkov <bp@xxxxxxxxx>
>Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
>Cc: Baoquan He <bhe@xxxxxxxxxx>
>Cc: Will Deacon <will.deacon@xxxxxxx>
>Cc: Nicolas Pitre <nico@xxxxxxxxxx>
>Cc: Pingfan Liu <kernelfans@xxxxxxxxx>
>Cc: Chao Fan <fanc.fnst@xxxxxxxxxxxxxx>
>Cc: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
>Cc: Ard Biesheuvel <ard.biesheuvel@xxxxxxxxxx>
>Cc: linux-kernel@xxxxxxxxxxxxxxx
>---
>v1 -> v2: fix some trival format
>
> arch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++--
> 1 file changed, 24 insertions(+), 2 deletions(-)
>
>diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
>index 9ed9709..e185318 100644
>--- a/arch/x86/boot/compressed/kaslr.c
>+++ b/arch/x86/boot/compressed/kaslr.c
>@@ -109,6 +109,7 @@ enum mem_avoid_index {
> MEM_AVOID_BOOTPARAMS,
> MEM_AVOID_MEMMAP_BEGIN,
> MEM_AVOID_MEMMAP_END = MEM_AVOID_MEMMAP_BEGIN + MAX_MEMMAP_REGIONS - 1,
>+ MEM_AVOID_CRASHKERNEL,
> MEM_AVOID_MAX,
> };
>
>@@ -240,6 +241,25 @@ static void parse_gb_huge_pages(char *param, char *val)
> }
> }
>
>+/* parse crashkernel=x@y option */
>+static void mem_avoid_crashkernel_simple(char *option)
>+{
>+ unsigned long long crash_size, crash_base;
>+ char *cur = option;
>+
>+ crash_size = memparse(option, &cur);
>+ if (option == cur)
>+ return;
>+
>+ if (*cur == '@') {
>+ option = cur + 1;
>+ crash_base = memparse(option, &cur);
>+ if (option == cur)
>+ return;
>+ mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
>+ mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
>+ }
>+}
>
> static void handle_mem_options(void)
> {
>@@ -250,7 +270,7 @@ static void handle_mem_options(void)
> u64 mem_size;
>
> if (!strstr(args, "memmap=") && !strstr(args, "mem=") &&
>- !strstr(args, "hugepages"))
>+ !strstr(args, "hugepages") && !strstr(args, "crashkernel="))
> return;
>
> tmp_cmdline = malloc(len + 1);
>@@ -286,6 +306,8 @@ static void handle_mem_options(void)
> goto out;
>
> mem_limit = mem_size;
>+ } else if (strstr(param, "crashkernel")) {
>+ mem_avoid_crashkernel_simple(val);
> }
> }
>
>@@ -414,7 +436,7 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,
>
> /* We don't need to set a mapping for setup_data. */
>
>- /* Mark the memmap regions we need to avoid */
>+ /* Mark the regions we need to avoid */
> handle_mem_options();
>
> #ifdef CONFIG_X86_VERBOSE_BOOTUP
>--
>2.7.4
>
>
>