Skip to contentSkip to conversation

x86/boot/KASLR: skip the specified crashkernel reserved region

PATCH Superseded Pingfan Liu 3 participants 15 messages Mar 13, 2019 – Mar 29, 2019 x86

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/boot/KASLR: skip the specified crashkernel reserved region

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.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Baoquan He <[email protected]>
Cc Will Deacon <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Pingfan Liu <[email protected]>
Cc Chao Fan <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
v1 -> v2: fix some trival format

 arch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +24 -2
index 9ed9709..e185318 100644
@@ -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
Signature · 1 line
2.7.4
#1 lore raw

Please change subject as:

"x86/boot/KASLR: skip the specified crashkernel region"

Don't see why reserved is needed here.

Quoted 36 lines · Pingfan Liu

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.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Baoquan He <[email protected]>
Cc Will Deacon <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Pingfan Liu <[email protected]>
Cc Chao Fan <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
v1 -> v2: fix some trival format

 arch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +1 -0
index 9ed9709..e185318 100644
@@ -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,
 };
 

arch/x86/boot/compressed/kaslr.c static void parse_gb_huge_pages(char *param, char *val) · line 245

Quoted 5 lines
arch/x86/boot/compressed/kaslr.c +2 -0
@@ -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)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Except of these, patch looks good to me. It's a nice catch, and only need a simple fix based on the current code.

Thanks
Baoquan

Quoted 50 lines
arch/x86/boot/compressed/kaslr.c +21 -2
+{
+	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
Signature · 1 line
2.7.4
#2 lore raw
Quoted 5 lines · Baoquan He

Please change subject as:

"x86/boot/KASLR: skip the specified crashkernel region"

OK.

Quoted 42 lines

Don't see why reserved is needed here.

Quoted 39 lines · Pingfan Liu

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.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Baoquan He <[email protected]>
Cc Will Deacon <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Pingfan Liu <[email protected]>
Cc Chao Fan <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
v1 -> v2: fix some trival format

 arch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +1 -0
index 9ed9709..e185318 100644
@@ -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)
      }
 }
 
Quoted 6 lines

arch/x86/boot/compressed/kaslr.c static void parse_gb_huge_pages(char *param, char *val) · line 245

Quoted 2 lines
arch/x86/boot/compressed/kaslr.c +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above the definition
/*
* That function parses "simple" (old) crashkernel command lines like *
* crashkernel=size[@offset]
*
* It returns 0 on success and -EINVAL on failure.
*/
static int __init parse_crashkernel_simple(char *cmdline,

Do you have alternative suggestion?

Quoted 3 lines

Except of these, patch looks good to me. It's a nice catch, and only need a simple fix based on the current code.

Thank you for the kindly review.

Regards,
Pingfan

Quoted 53 lines

Thanks
Baoquan

Quoted 50 lines
arch/x86/boot/compressed/kaslr.c +21 -3
+{
+     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

#3 lore raw
Quoted 8 lines · Pingfan Liu
Quoted 6 lines

arch/x86/boot/compressed/kaslr.c static void parse_gb_huge_pages(char *param, char *val) · line 245

Quoted 2 lines
arch/x86/boot/compressed/kaslr.c +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

Quoted 5 lines

the definition
/*
* That function parses "simple" (old) crashkernel command lines like *
* crashkernel=size[@offset]

Hmm, should only crashkernel=size@offset be cared? crashkernel=size will auto finding a place to reserve, and that is after KASLR.

Quoted 68 lines

*
* It returns 0 on success and -EINVAL on failure. */
static int __init parse_crashkernel_simple(char *cmdline,

Do you have alternative suggestion?

Quoted 3 lines

Except of these, patch looks good to me. It's a nice catch, and only need a simple fix based on the current code.

Thank you for the kindly review.

Regards,
Pingfan

Quoted 53 lines

Thanks
Baoquan

Quoted 50 lines
arch/x86/boot/compressed/kaslr.c +21 -3
+{
+     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

#4 lore raw
Quoted 7 lines · Baoquan He
Quoted 6 lines · Pingfan Liu
Quoted 6 lines

arch/x86/boot/compressed/kaslr.c static void parse_gb_huge_pages(char *param, char *val) · line 245

Quoted 2 lines
arch/x86/boot/compressed/kaslr.c +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Quoted 5 lines
Quoted 2 lines

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

OK, I misunderstood it. We do have parse_crashkernel_simple() to handle crashkernel=size[@offset] case, to differente with other complicated cases, like crashkernel=size,[high|low],

Then I am fine with this naming. Soryy about the noise.

By the way, do you think if we should take care of this case:
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]

It can also specify @offset. Not sure if it's too complicated, you may have a investigation.

These two cases have dependency on your crashkernel=X bug fix patch. The current code only allow crashkernel= to reserve under 896MB. I noticed Boris has agreed on the solution. Maybe you can repost a new version based on the discussion.

http://lkml.kernel.org/r/[email protected]
[PATCHv7] x86/kdump: bugfix, make the behavior of crashkernel=X consistent with kaslr

Thanks
Baoquan

Quoted 78 lines
Quoted 6 lines

the definition
/*
* That function parses "simple" (old) crashkernel command lines like *
* crashkernel=size[@offset]

Hmm, should only crashkernel=size@offset be cared? crashkernel=size will auto finding a place to reserve, and that is after KASLR.

Quoted 68 lines

*
* It returns 0 on success and -EINVAL on failure. */
static int __init parse_crashkernel_simple(char *cmdline,

Do you have alternative suggestion?

Quoted 3 lines

Except of these, patch looks good to me. It's a nice catch, and only need a simple fix based on the current code.

Thank you for the kindly review.

Regards,
Pingfan

Quoted 53 lines

Thanks
Baoquan

Quoted 50 lines
arch/x86/boot/compressed/kaslr.c +21 -3
+{
+     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

#5 lore raw
Quoted 19 lines · Baoquan He
Quoted 7 lines · Baoquan He
Quoted 6 lines · Pingfan Liu
Quoted 6 lines

arch/x86/boot/compressed/kaslr.c static void parse_gb_huge_pages(char *param, char *val) · line 245

Quoted 2 lines
arch/x86/boot/compressed/kaslr.c +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Quoted 5 lines
Quoted 2 lines

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

OK, I misunderstood it. We do have parse_crashkernel_simple() to handle crashkernel=size[@offset] case, to differente with other complicated cases, like crashkernel=size,[high|low],

Quoted 8 lines

Then I am fine with this naming. Soryy about the noise.

By the way, do you think if we should take care of this case:
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]

It can also specify @offset. Not sure if it's too complicated, you may have a investigation.

OK, I will try it.

Quoted 1 line

These two cases have dependency on your crashkernel=X bug fix patch.

No, crashkernel=x@y should have no dependcy on crashkernel=X, the later one relies on memblock searching.

Quoted 3 lines

The current code only allow crashkernel= to reserve under 896MB. I noticed Boris has agreed on the solution. Maybe you can repost a new version based on the discussion.

I will sync with Dave to see whether he will post the new version.

Thank you for kindly review.

Regards,
Pingfan

Quoted 85 lines

http://lkml.kernel.org/r/[email protected]
[PATCHv7] x86/kdump: bugfix, make the behavior of crashkernel=X consistent with kaslr

Thanks
Baoquan

Quoted 78 lines
Quoted 6 lines

the definition
/*
* That function parses "simple" (old) crashkernel command lines like *
* crashkernel=size[@offset]

Hmm, should only crashkernel=size@offset be cared? crashkernel=size will auto finding a place to reserve, and that is after KASLR.

Quoted 68 lines

*
* It returns 0 on success and -EINVAL on failure. */
static int __init parse_crashkernel_simple(char *cmdline,

Do you have alternative suggestion?

Quoted 3 lines

Except of these, patch looks good to me. It's a nice catch, and only need a simple fix based on the current code.

Thank you for the kindly review.

Regards,
Pingfan

Quoted 53 lines

Thanks
Baoquan

Quoted 50 lines
arch/x86/boot/compressed/kaslr.c +21 -3
+{
+     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

#6 lore raw
In reply to Baoquan He
Quoted 19 lines · Baoquan He
Quoted 7 lines · Baoquan He
Quoted 6 lines · Pingfan Liu
Quoted 6 lines

arch/x86/boot/compressed/kaslr.c static void parse_gb_huge_pages(char *param, char *val) · line 245

Quoted 2 lines
arch/x86/boot/compressed/kaslr.c +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Quoted 5 lines
Quoted 2 lines

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

OK, I misunderstood it. We do have parse_crashkernel_simple() to handle crashkernel=size[@offset] case, to differente with other complicated cases, like crashkernel=size,[high|low],

Quoted 8 lines

Then I am fine with this naming. Soryy about the noise.

By the way, do you think if we should take care of this case:
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]

It can also specify @offset. Not sure if it's too complicated, you may have a investigation.

In this case, kernel should get the total memory size info. So process_e820_entries() or process_efi_entries() should be called twice. One before handle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about the extra complicate?

Thanks,
Pingfan
[...]

#7 lore raw
Quoted 25 lines · Pingfan Liu
Quoted 24 lines · Baoquan He
Quoted 7 lines · Baoquan He
Quoted 6 lines · Pingfan Liu
Quoted 6 lines

arch/x86/boot/compressed/kaslr.c static void parse_gb_huge_pages(char *param, char *val) · line 245

Quoted 2 lines
arch/x86/boot/compressed/kaslr.c +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Quoted 5 lines
Quoted 2 lines

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

OK, I misunderstood it. We do have parse_crashkernel_simple() to handle crashkernel=size[@offset] case, to differente with other complicated cases, like crashkernel=size,[high|low],

Then I am fine with this naming. Soryy about the noise.

By the way, do you think if we should take care of this case:
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]

Quoted 7 lines
Quoted 3 lines

It can also specify @offset. Not sure if it's too complicated, you may have a investigation.

In this case, kernel should get the total memory size info. So process_e820_entries() or process_efi_entries() should be called twice. One before handle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about the

You mean calling process_e820_entries to calculate the RAM size in system? I may not do like that, please check what __find_max_addr() is doing. Did I get it?

#8 lore raw
Quoted 30 lines · Baoquan He
Quoted 28 lines · Pingfan Liu
Quoted 27 lines · Baoquan He
Quoted 7 lines · Baoquan He
Quoted 6 lines · Pingfan Liu
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Quoted 5 lines
Quoted 2 lines

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

OK, I misunderstood it. We do have parse_crashkernel_simple() to handle crashkernel=size[@offset] case, to differente with other complicated cases, like crashkernel=size,[high|low],

Then I am fine with this naming. Soryy about the noise.

By the way, do you think if we should take care of this case:
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]

It can also specify @offset. Not sure if it's too complicated, you may have a investigation.

Quoted 8 lines
Quoted 4 lines

In this case, kernel should get the total memory size info. So process_e820_entries() or process_efi_entries() should be called twice. One before handle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about the

You mean calling process_e820_entries to calculate the RAM size in system? I may not do like that, please check what __find_max_addr() is doing. Did I get it?

Yes, you got my meaning. But __find_max_addr() relies on the info, fed by e820__memblock_setup(). It also involves the iteration of all e820 entries to get the max address. No essential difference, right?

#9 lore raw
Quoted 36 lines · Pingfan Liu
Quoted 35 lines · Baoquan He
Quoted 32 lines · Pingfan Liu
Quoted 19 lines · Baoquan He
Quoted 7 lines · Baoquan He
Quoted 6 lines · Pingfan Liu
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Quoted 5 lines
Quoted 2 lines

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

OK, I misunderstood it. We do have parse_crashkernel_simple() to handle crashkernel=size[@offset] case, to differente with other complicated cases, like crashkernel=size,[high|low],

Quoted 8 lines

Then I am fine with this naming. Soryy about the noise.

By the way, do you think if we should take care of this case:
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]

It can also specify @offset. Not sure if it's too complicated, you may have a investigation.

In this case, kernel should get the total memory size info. So process_e820_entries() or process_efi_entries() should be called twice. One before handle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about the

Quoted 7 lines
Quoted 3 lines

You mean calling process_e820_entries to calculate the RAM size in system? I may not do like that, please check what __find_max_addr() is doing. Did I get it?

Yes, you got my meaning. But __find_max_addr() relies on the info, fed by e820__memblock_setup(). It also involves the iteration of all e820 entries to get the max address. No essential difference, right?

Hmm, I would say iterating e820 or efi entries to get the mas addr should be different with calling process_e820_entries(). The 1st is much simpler, right?

#10 lore raw
Quoted 42 lines · Baoquan He
Quoted 40 lines · Pingfan Liu
Quoted 38 lines · Baoquan He
Quoted 25 lines · Pingfan Liu
Quoted 24 lines · Baoquan He
Quoted 7 lines · Baoquan He
Quoted 6 lines · Pingfan Liu
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Quoted 5 lines
Quoted 2 lines

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

OK, I misunderstood it. We do have parse_crashkernel_simple() to handle crashkernel=size[@offset] case, to differente with other complicated cases, like crashkernel=size,[high|low],

Then I am fine with this naming. Soryy about the noise.

By the way, do you think if we should take care of this case:
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]

Quoted 7 lines
Quoted 3 lines

It can also specify @offset. Not sure if it's too complicated, you may have a investigation.

In this case, kernel should get the total memory size info. So process_e820_entries() or process_efi_entries() should be called twice. One before handle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about the

You mean calling process_e820_entries to calculate the RAM size in system? I may not do like that, please check what __find_max_addr() is doing. Did I get it?

Quoted 8 lines
Quoted 3 lines

Yes, you got my meaning. But __find_max_addr() relies on the info, fed by e820__memblock_setup(). It also involves the iteration of all e820 entries to get the max address. No essential difference, right?

Hmm, I would say iterating e820 or efi entries to get the mas addr should be different with calling process_e820_entries(). The 1st is much simpler, right?

Yes. My original meaning is to reuse process_e820_entries(), but does not call process_mem_region() at the first time.

Thanks,
Pingfan

#11 lore raw
Quoted 47 lines · Pingfan Liu
Quoted 46 lines · Baoquan He
Quoted 43 lines · Pingfan Liu
Quoted 30 lines · Baoquan He
Quoted 28 lines · Pingfan Liu
Quoted 27 lines · Baoquan He
Quoted 7 lines · Baoquan He
Quoted 6 lines · Pingfan Liu
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+/* parse crashkernel=x@y option */
+static void mem_avoid_crashkernel_simple(char *option)

Chao ever mentioned this, I want to ask again, why does it has to be xxx_simple()?

Quoted 5 lines
Quoted 2 lines

Seems that I had replied Chao's question in another email. The naming follows the function parse_crashkernel_simple(), as the notes above

                       ~~~~~~~~~~~~~~~~~~~~~~~~

Sorry, I don't get. typo?

OK, I misunderstood it. We do have parse_crashkernel_simple() to handle crashkernel=size[@offset] case, to differente with other complicated cases, like crashkernel=size,[high|low],

Then I am fine with this naming. Soryy about the noise.

By the way, do you think if we should take care of this case:
crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]

It can also specify @offset. Not sure if it's too complicated, you may have a investigation.

Quoted 8 lines
Quoted 4 lines

In this case, kernel should get the total memory size info. So process_e820_entries() or process_efi_entries() should be called twice. One before handle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about the

You mean calling process_e820_entries to calculate the RAM size in system? I may not do like that, please check what __find_max_addr() is doing. Did I get it?

Yes, you got my meaning. But __find_max_addr() relies on the info, fed by e820__memblock_setup(). It also involves the iteration of all e820 entries to get the max address. No essential difference, right?

Quoted 6 lines
Quoted 4 lines

Hmm, I would say iterating e820 or efi entries to get the mas addr should be different with calling process_e820_entries(). The 1st is much simpler, right?

Yes. My original meaning is to reuse process_e820_entries(), but does not call process_mem_region() at the first time.

Got it. That would be nice, but it will bring hackery which Thomas and Boris have clearly expressed disliking. Adding a new function to find the max addr, it truly doesn't reuse code, while it makes the code paths and logic are pretty clear. These avoiding cases are bloating code, however they usually don't happen in a same system. We make a simply and clear logic to make code strightforward with good code comments and printing message, it will be easier to debug issue if happened.

So, I think a draft patch is welcomed, we can have a look at the logic, then polish it later to make a formal patch. Makes sense?

Thanks
Baoquan

#12 lore raw
In reply to Pingfan Liu

On Wed, Mar 13, 2019 at 12:19:31PM +0800, Pingfan Liu wrote:

Hi Pingfan,

I wonder your test method and test case.
Do you test it in the Qemu guest or real machine.

Thanks,
Chao Fan

Quoted 93 lines

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.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Baoquan He <[email protected]>
Cc Will Deacon <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Pingfan Liu <[email protected]>
Cc Chao Fan <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
v1 -> v2: fix some trival format

arch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++--

1 file changed, 24 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +24 -2
index 9ed9709..e185318 100644
@@ -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
Signature · 1 line
2.7.4
Tested-by on v2 1/1
#13 lore raw
In reply to Pingfan Liu

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:

Thanks,
Chao Fan

Quoted 93 lines

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.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Baoquan He <[email protected]>
Cc Will Deacon <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Pingfan Liu <[email protected]>
Cc Chao Fan <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
v1 -> v2: fix some trival format

arch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++--

1 file changed, 24 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +24 -2
index 9ed9709..e185318 100644
@@ -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
Signature · 1 line
2.7.4
#14 lore raw
Quoted 9 lines · Chao Fan

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).

Quoted 4 lines

So I think if you post new version, you can add:

Appreciate for your testing. I had done some test on a real machine with a private patch to narrow down the KASLR range. I think your test method is more simple and I will add the tested-by you.

Regards,
Pingfan

Quoted 98 lines

Thanks,
Chao Fan

Quoted 93 lines

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.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Baoquan He <[email protected]>
Cc Will Deacon <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Pingfan Liu <[email protected]>
Cc Chao Fan <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Ard Biesheuvel <[email protected]>

---
v1 -> v2: fix some trival format

arch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++--

1 file changed, 24 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +24 -3
index 9ed9709..e185318 100644
@@ -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