x86/boot/KASLR: skip the specified crashkernel reserved region
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.
---
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
@@ -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
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.
Signed-off-by Pingfan Liu <[email protected]>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 formatarch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)arch/x86/boot/compressed/kaslr.c +1
-0@@ -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
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.
Signed-off-by Pingfan Liu <[email protected]>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 formatarch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)arch/x86/boot/compressed/kaslr.c +1
-0@@ -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
BaoquanQuoted 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
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-EINVALon failure. */
static int__initparse_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,
PingfanQuoted 53 lines
Thanks
BaoquanQuoted 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
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-EINVALon failure. */
static int__initparse_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,
PingfanQuoted 53 lines
Thanks
BaoquanQuoted 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
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 kaslrThanks
BaoquanQuoted 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-EINVALon failure. */
static int__initparse_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,
PingfanQuoted 53 lines
Thanks
BaoquanQuoted 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
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
[...]
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()orprocess_efi_entries()should be called twice. One beforehandle_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 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()orprocess_efi_entries()should be called twice. One beforehandle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about theYou mean calling
process_e820_entriesto 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 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()orprocess_efi_entries()should be called twice. One beforehandle_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_entriesto 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 bye820__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?
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()orprocess_efi_entries()should be called twice. One beforehandle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about theYou mean calling
process_e820_entriesto 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 bye820__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
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()orprocess_efi_entries()should be called twice. One beforehandle_mem_options(), so crashkernel can evaluate the reserved size. It is doable, and what is your opinion about theYou mean calling
process_e820_entriesto 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 bye820__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 callprocess_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
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.
Signed-off-by Pingfan Liu <[email protected]>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@@ -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
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.
Signed-off-by Pingfan Liu <[email protected]>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@@ -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
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:
Tested-by Chao Fan <[email protected]>
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 FanQuoted 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.
Signed-off-by Pingfan Liu <[email protected]>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@@ -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