Skip to contentSkip to conversation

x86/boot/KASLR: skip the specified crashkernel region

PATCH Superseded Pingfan Liu 3 participants 11 messages Apr 2, 2019 – Apr 4, 2019 x86

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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

crashkernel=x@y or or =range1:size1[,range2:size2,...]@offset option may fail to reserve the required memory region if KASLR puts kernel into the region. To avoid this uncertainty, asking KASLR to 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]>

---
v2 -> v3: adding parsing of crashkernel=range1:size1[,range2:size2,...]@offset

 arch/x86/boot/compressed/kaslr.c | 116 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 114 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +114 -2
index 2e53c05..7f698f4 100644
@@ -107,6 +107,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,
 };
 
@@ -238,6 +239,115 @@ static void parse_gb_huge_pages(char *param, char *val)
 	}
 }
 
+/* code heavily copied from parse_crashkernel_mem() */
+static void handle_crashkernel_mem(char *cmdline,
+					unsigned long long system_ram,
+					unsigned long long *crash_size,
+					unsigned long long *crash_base)
+{
+	char *tmp, *cur = cmdline;
+
+	/* for each entry of the comma-separated list */
+	do {
+		unsigned long long start, end = ULLONG_MAX, size;
+
+		/* get the start of the range */
+		start = memparse(cur, &tmp);
+		/* no value given */
+		if (cur == tmp)
+			return;
+		cur = tmp;
+		if (*cur != '-')
+			return;
+		cur++;
+
+		/* if no ':' is here, than we read the end */
+		if (*cur != ':') {
+			end = memparse(cur, &tmp);
+			/* no value given */
+			if (cur == tmp)
+				return;
+			cur = tmp;
+			/* invalid if crashkernel end <= start */
+			if (end <= start)
+				return;
+		}
+		/* expect ":" after range */
+		if (*cur != ':')
+			return;
+		cur++;
+
+		size = memparse(cur, &tmp);
+		/* no size value given */
+		if (cur == tmp)
+			return;
+		cur = tmp;
+		if (size >= system_ram)
+			return;
+
+		/* match ? */
+		if (system_ram >= start && system_ram < end) {
+			*crash_size = size;
+			break;
+		}
+	} while (*cur++ == ',');
+
+	if (*crash_size > 0) {
+		while (*cur && *cur != ' ' && *cur != '@')
+			cur++;
+		if (*cur == '@') {
+			cur++;
+			*crash_base = memparse(cur, &tmp);
+		}
+	}
+}
+
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+	unsigned long long crash_size, crash_base = 0;
+	char	*first_colon, *first_space, *cur = option;
+
+	first_colon = strchr(option, ':');
+	first_space = strchr(option, ' ');
+	/* if contain ":" */
+	if (first_colon && (!first_space || first_colon < first_space)) {
+		int i;
+		u64 total_sz = 0;
+		struct boot_e820_entry *entry;
+
+		for (i = 0; i < boot_params->e820_entries; i++) {
+			entry = &boot_params->e820_table[i];
+			/* Skip non-RAM entries. */
+			if (entry->type != E820_TYPE_RAM)
+				continue;
+			total_sz += entry->size;
+		}
+		handle_crashkernel_mem(option, total_sz, &crash_size,
+			&crash_base);
+	} else {
+		crash_size = memparse(option, &cur);
+		if (option == cur)
+			return;
+		while (*cur && *cur != ' ' && *cur != '@')
+			cur++;
+		if (*cur == '@') {
+			option = cur + 1;
+			crash_base = memparse(option, &cur);
+		}
+	}
+	if (crash_base) {
+		mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+		mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+	} else {
+		/*
+ 		 * Clearing mem_avoid if no offset is given. This is consistent
+ 		 * with kernel, which uses the last crashkernel= option.
+		 */
+		mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+		mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+	}
+}
 
 static void handle_mem_options(void)
 {
@@ -248,7 +358,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);
@@ -284,6 +394,8 @@ static void handle_mem_options(void)
 				goto out;
 
 			mem_limit = mem_size;
+		} else if (strstr(param, "crashkernel")) {
+			mem_avoid_specified_crashkernel_region(val);
 		}
 	}
 
@@ -412,7 +524,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();
 
 	/* Enumerate the immovable memory regions */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 1 line · Pingfan Liu

crashkernel=x@y or or =range1:size1[,range2:size2,...]@offset option may

or or?

Quoted 18 lines

fail to reserve the required memory region if KASLR puts kernel into the region. To avoid this uncertainty, asking KASLR to 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]>

---

[...]

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */

Before review, I want to say more about the background. It's very hard to review the code for someone who is not so familiar with kdump, so could you please explain more ahout
the uasge of crashkernel=range1:size1[,range2:size2,...]@offset. And also there are so many jobs who are parsing string. So I really need your help to understand the PATCH.

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

Quoted 4 lines
arch/x86/boot/compressed/kaslr.c +4 -0
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+	unsigned long long crash_size, crash_base = 0;
+	char	*first_colon, *first_space, *cur = option;

Is there a tab after char?

Quoted 5 lines
arch/x86/boot/compressed/kaslr.c +5 -0
+
+	first_colon = strchr(option, ':');
+	first_space = strchr(option, ' ');
+	/* if contain ":" */
+	if (first_colon && (!first_space || first_colon < first_space)) {

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

Quoted 10 lines
arch/x86/boot/compressed/kaslr.c +10 -0
+		int i;
+		u64 total_sz = 0;
+		struct boot_e820_entry *entry;
+
+		for (i = 0; i < boot_params->e820_entries; i++) {
+			entry = &boot_params->e820_table[i];
+			/* Skip non-RAM entries. */
+			if (entry->type != E820_TYPE_RAM)
+				continue;
+			total_sz += entry->size;

I wonder whether it's needed to consider the memory ranges here. I think it's OK to only record the regions should to be avoid. I remeber I ever talked with Baoquan about the similiar problems. @Baoquan, I am not sure if I misunderstand something.

Thanks,
Chao Fan

Quoted 61 lines
arch/x86/boot/compressed/kaslr.c +26 -0
+		}
+		handle_crashkernel_mem(option, total_sz, &crash_size,
+			&crash_base);
+	} else {
+		crash_size = memparse(option, &cur);
+		if (option == cur)
+			return;
+		while (*cur && *cur != ' ' && *cur != '@')
+			cur++;
+		if (*cur == '@') {
+			option = cur + 1;
+			crash_base = memparse(option, &cur);
+		}
+	}
+	if (crash_base) {
+		mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+		mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+	} else {
+		/*
+ 		 * Clearing mem_avoid if no offset is given. This is consistent
+ 		 * with kernel, which uses the last crashkernel= option.
+		 */
+		mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+		mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+	}
+}

static void handle_mem_options(void)
{

arch/x86/boot/compressed/kaslr.c +4 -2
@@ -248,7 +358,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);
@@ -284,6 +394,8 @@ static void handle_mem_options(void)
 				goto out;
 
 			mem_limit = mem_size;
+		} else if (strstr(param, "crashkernel")) {
+			mem_avoid_specified_crashkernel_region(val);
 		}
 	}
 
@@ -412,7 +524,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();
 
 	/* Enumerate the immovable memory regions */
Signature · 1 line
2.7.4
#2 lore raw
Quoted 22 lines · Chao Fan
Quoted 1 line · Pingfan Liu

crashkernel=x@y or or =range1:size1[,range2:size2,...]@offset option may

or or?

Quoted 18 lines

fail to reserve the required memory region if KASLR puts kernel into the region. To avoid this uncertainty, asking KASLR to 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]>

---

[...]

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */

Before review, I want to say more about the background. It's very hard to review the code for someone who is not so familiar with kdump, so could you please explain more ahout
the uasge of crashkernel=range1:size1[,range2:size2,...]@offset. And also there are so many jobs who are parsing string. So I really need your help to understand the PATCH.

The hard part may be handle_crashkernel_mem() itself. However, it's almost copied from parse_crashkernel_mem() completely. If we can reuse that function, thing's gonna be perfect.

Quoted 17 lines

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

Quoted 5 lines
arch/x86/boot/compressed/kaslr.c +4 -0
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+	unsigned long long crash_size, crash_base = 0;
+	char	*first_colon, *first_space, *cur = option;

Is there a tab after char?

Quoted 11 lines
arch/x86/boot/compressed/kaslr.c +11 -0
+
+	first_colon = strchr(option, ':');
+	first_space = strchr(option, ' ');
+	/* if contain ":" */
+	if (first_colon && (!first_space || first_colon < first_space)) {
+		int i;
+		u64 total_sz = 0;
+		struct boot_e820_entry *entry;
+
+		for (i = 0; i < boot_params->e820_entries; i++) {
+			entry = &boot_params->e820_table[i];
Quoted 8 lines

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

Quoted 4 lines
arch/x86/boot/compressed/kaslr.c +4 -0
+			/* Skip non-RAM entries. */
+			if (entry->type != E820_TYPE_RAM)
+				continue;
+			total_sz += entry->size;

I wonder whether it's needed to consider the memory ranges here. I think it's OK to only record the regions should to be avoid. I remeber I ever talked with Baoquan about the similiar problems. @Baoquan, I am not sure if I misunderstand something.

Not sure if I get you. Could you be more specific?

#3 lore raw
In reply to Chao Fan
Quoted 47 lines · Chao Fan
Quoted 1 line · Pingfan Liu

crashkernel=x@y or or =range1:size1[,range2:size2,...]@offset option may

or or?

Quoted 18 lines

fail to reserve the required memory region if KASLR puts kernel into the region. To avoid this uncertainty, asking KASLR to 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]>

---

[...]

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */

Before review, I want to say more about the background. It's very hard to review the code for someone who is not so familiar with kdump, so could you please explain more ahout
the uasge of crashkernel=range1:size1[,range2:size2,...]@offset. And also there are so many jobs who are parsing string. So I really need your help to understand the PATCH.

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

Quoted 4 lines
arch/x86/boot/compressed/kaslr.c +4 -0
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+      unsigned long long crash_size, crash_base = 0;
+      char    *first_colon, *first_space, *cur = option;

Is there a tab after char?

Quoted 9 lines
arch/x86/boot/compressed/kaslr.c +9 -0
+
+      first_colon = strchr(option, ':');
+      first_space = strchr(option, ' ');
+      /* if contain ":" */
+      if (first_colon && (!first_space || first_colon < first_space)) {
+              int i;
+              u64 total_sz = 0;
+              struct boot_e820_entry *entry;
+
Quoted 8 lines

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

Quoted 6 lines
arch/x86/boot/compressed/kaslr.c +6 -0
+              for (i = 0; i < boot_params->e820_entries; i++) {
+                      entry = &boot_params->e820_table[i];
+                      /* Skip non-RAM entries. */
+                      if (entry->type != E820_TYPE_RAM)
+                              continue;
+                      total_sz += entry->size;

I wonder whether it's needed to consider the memory ranges here. I think it's OK to only record the regions should to be avoid.

Maybe not catch you exactly. In the case of crashkernel=range1:size1[,range2:size2,...]@offset, the size of avoid region depends on the size of total system ram.

Quoted 68 lines

I remeber I ever talked with Baoquan about the similiar problems. @Baoquan, I am not sure if I misunderstand something.

Thanks,
Chao Fan

Quoted 61 lines
arch/x86/boot/compressed/kaslr.c +26 -0
+              }
+              handle_crashkernel_mem(option, total_sz, &crash_size,
+                      &crash_base);
+      } else {
+              crash_size = memparse(option, &cur);
+              if (option == cur)
+                      return;
+              while (*cur && *cur != ' ' && *cur != '@')
+                      cur++;
+              if (*cur == '@') {
+                      option = cur + 1;
+                      crash_base = memparse(option, &cur);
+              }
+      }
+      if (crash_base) {
+              mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+              mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+      } else {
+              /*
+               * Clearing mem_avoid if no offset is given. This is consistent
+               * with kernel, which uses the last crashkernel= option.
+               */
+              mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+              mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+      }
+}

static void handle_mem_options(void)
{

arch/x86/boot/compressed/kaslr.c +4 -3
@@ -248,7 +358,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);
@@ -284,6 +394,8 @@ static void handle_mem_options(void)
                              goto out;
 
                      mem_limit = mem_size;
+              } else if (strstr(param, "crashkernel")) {
+                      mem_avoid_specified_crashkernel_region(val);
              }
      }
 
@@ -412,7 +524,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();
 
      /* Enumerate the immovable memory regions */
--

2.7.4

#4 lore raw
Quoted 56 lines · Pingfan Liu
Quoted 47 lines · Chao Fan
Quoted 1 line · Pingfan Liu

crashkernel=x@y or or =range1:size1[,range2:size2,...]@offset option may

or or?

Quoted 18 lines

fail to reserve the required memory region if KASLR puts kernel into the region. To avoid this uncertainty, asking KASLR to 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]>

---

[...]

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */

Before review, I want to say more about the background. It's very hard to review the code for someone who is not so familiar with kdump, so could you please explain more ahout
the uasge of crashkernel=range1:size1[,range2:size2,...]@offset. And also there are so many jobs who are parsing string. So I really need your help to understand the PATCH.

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

Quoted 4 lines
arch/x86/boot/compressed/kaslr.c +4 -0
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+      unsigned long long crash_size, crash_base = 0;
+      char    *first_colon, *first_space, *cur = option;

Is there a tab after char?

Quoted 9 lines
arch/x86/boot/compressed/kaslr.c +9 -0
+
+      first_colon = strchr(option, ':');
+      first_space = strchr(option, ' ');
+      /* if contain ":" */
+      if (first_colon && (!first_space || first_colon < first_space)) {
+              int i;
+              u64 total_sz = 0;
+              struct boot_e820_entry *entry;
+
Quoted 8 lines

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

Quoted 6 lines
arch/x86/boot/compressed/kaslr.c +6 -0
+              for (i = 0; i < boot_params->e820_entries; i++) {
+                      entry = &boot_params->e820_table[i];
+                      /* Skip non-RAM entries. */
+                      if (entry->type != E820_TYPE_RAM)
+                              continue;
+                      total_sz += entry->size;

I wonder whether it's needed to consider the memory ranges here. I think it's OK to only record the regions should to be avoid.

Quoted 3 lines

Maybe not catch you exactly. In the case of crashkernel=range1:size1[,range2:size2,...]@offset, the size of avoid region depends on the size of total system ram.

Got it, I midunderstand it.

Thanks,
Chao Fan

Quoted 70 lines
Quoted 68 lines

I remeber I ever talked with Baoquan about the similiar problems. @Baoquan, I am not sure if I misunderstand something.

Thanks,
Chao Fan

Quoted 61 lines
arch/x86/boot/compressed/kaslr.c +26 -0
+              }
+              handle_crashkernel_mem(option, total_sz, &crash_size,
+                      &crash_base);
+      } else {
+              crash_size = memparse(option, &cur);
+              if (option == cur)
+                      return;
+              while (*cur && *cur != ' ' && *cur != '@')
+                      cur++;
+              if (*cur == '@') {
+                      option = cur + 1;
+                      crash_base = memparse(option, &cur);
+              }
+      }
+      if (crash_base) {
+              mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+              mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+      } else {
+              /*
+               * Clearing mem_avoid if no offset is given. This is consistent
+               * with kernel, which uses the last crashkernel= option.
+               */
+              mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+              mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+      }
+}

static void handle_mem_options(void)
{

arch/x86/boot/compressed/kaslr.c +4 -3
@@ -248,7 +358,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);
@@ -284,6 +394,8 @@ static void handle_mem_options(void)
                              goto out;
 
                      mem_limit = mem_size;
+              } else if (strstr(param, "crashkernel")) {
+                      mem_avoid_specified_crashkernel_region(val);
              }
      }
 
@@ -412,7 +524,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();
 
      /* Enumerate the immovable memory regions */
--

2.7.4

#5 lore raw
In reply to Pingfan Liu
Quoted 37 lines · Pingfan Liu

crashkernel=x@y or or =range1:size1[,range2:size2,...]@offset option may fail to reserve the required memory region if KASLR puts kernel into the region. To avoid this uncertainty, asking KASLR to 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]>

---
v2 -> v3: adding parsing of crashkernel=range1:size1[,range2:size2,...]@offset

 arch/x86/boot/compressed/kaslr.c | 116 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 114 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +1 -0
index 2e53c05..7f698f4 100644
@@ -107,6 +107,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 246

Quoted 8 lines
arch/x86/boot/compressed/kaslr.c +5 -0
@@ -238,6 +239,115 @@ static void parse_gb_huge_pages(char *param, char *val)
 	}
 }
 
+/* code heavily copied from parse_crashkernel_mem() */
+static void handle_crashkernel_mem(char *cmdline,
+					unsigned long long system_ram,
+					unsigned long long *crash_size,
+					unsigned long long *crash_base)

This version looks better and the logic is simple. It will be much better if we can share code with parse_crashkernel_mem() since both of them look almost the same.

Quoted 50 lines
arch/x86/boot/compressed/kaslr.c +50 -0
+{
+	char *tmp, *cur = cmdline;
+
+	/* for each entry of the comma-separated list */
+	do {
+		unsigned long long start, end = ULLONG_MAX, size;
+
+		/* get the start of the range */
+		start = memparse(cur, &tmp);
+		/* no value given */
+		if (cur == tmp)
+			return;
+		cur = tmp;
+		if (*cur != '-')
+			return;
+		cur++;
+
+		/* if no ':' is here, than we read the end */
+		if (*cur != ':') {
+			end = memparse(cur, &tmp);
+			/* no value given */
+			if (cur == tmp)
+				return;
+			cur = tmp;
+			/* invalid if crashkernel end <= start */
+			if (end <= start)
+				return;
+		}
+		/* expect ":" after range */
+		if (*cur != ':')
+			return;
+		cur++;
+
+		size = memparse(cur, &tmp);
+		/* no size value given */
+		if (cur == tmp)
+			return;
+		cur = tmp;
+		if (size >= system_ram)
+			return;
+
+		/* match ? */
+		if (system_ram >= start && system_ram < end) {
+			*crash_size = size;
+			break;
+		}
+	} while (*cur++ == ',');
+
+	if (*crash_size > 0) {
+		while (*cur && *cur != ' ' && *cur != '@')

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

Quoted 10 lines
arch/x86/boot/compressed/kaslr.c +10 -0
+			cur++;
+		if (*cur == '@') {
+			cur++;
+			*crash_base = memparse(cur, &tmp);
+		}
+	}
+}
+
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
+static void mem_avoid_specified_crashkernel_region(char *option)

Maybe just add more words to explain the specified crashkernel region cases, but remove the 'speecified' word in function name?

Quoted 8 lines
arch/x86/boot/compressed/kaslr.c +8 -0
+{
+	unsigned long long crash_size, crash_base = 0;
+	char	*first_colon, *first_space, *cur = option;
+
+	first_colon = strchr(option, ':');
+	first_space = strchr(option, ' ');
+	/* if contain ":" */
+	if (first_colon && (!first_space || first_colon < first_space)) {

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

Quoted 10 lines
arch/x86/boot/compressed/kaslr.c +10 -0
+		int i;
+		u64 total_sz = 0;
+		struct boot_e820_entry *entry;
+
+		for (i = 0; i < boot_params->e820_entries; i++) {
+			entry = &boot_params->e820_table[i];
+			/* Skip non-RAM entries. */
+			if (entry->type != E820_TYPE_RAM)
+				continue;
+			total_sz += entry->size;

Wrap this for loop into a static function to calculate the system RAM size?

Other than these, I think this adding looks good. It won't impact the current handling, and very easy to recognize what it's doing. Thanks for the effort.

Thanks
Baoquan

Quoted 59 lines
arch/x86/boot/compressed/kaslr.c +30 -2
+		}
+		handle_crashkernel_mem(option, total_sz, &crash_size,
+			&crash_base);
+	} else {
+		crash_size = memparse(option, &cur);
+		if (option == cur)
+			return;
+		while (*cur && *cur != ' ' && *cur != '@')
+			cur++;
+		if (*cur == '@') {
+			option = cur + 1;
+			crash_base = memparse(option, &cur);
+		}
+	}
+	if (crash_base) {
+		mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+		mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+	} else {
+		/*
+ 		 * Clearing mem_avoid if no offset is given. This is consistent
+ 		 * with kernel, which uses the last crashkernel= option.
+		 */
+		mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+		mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+	}
+}
 
 static void handle_mem_options(void)
 {
@@ -248,7 +358,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);
@@ -284,6 +394,8 @@ static void handle_mem_options(void)
 				goto out;
 
 			mem_limit = mem_size;
+		} else if (strstr(param, "crashkernel")) {
+			mem_avoid_specified_crashkernel_region(val);
 		}
 	}
 
@@ -412,7 +524,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();
 
 	/* Enumerate the immovable memory regions */
Signature · 1 line
2.7.4
#6 lore raw
Quoted 42 lines · Baoquan He
Quoted 40 lines · Pingfan Liu

crashkernel=x@y or or =range1:size1[,range2:size2,...]@offset option may fail to reserve the required memory region if KASLR puts kernel into the region. To avoid this uncertainty, asking KASLR to 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]>

---
v2 -> v3: adding parsing of crashkernel=range1:size1[,range2:size2,...]@offset

 arch/x86/boot/compressed/kaslr.c | 116 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 114 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/kaslr.c +1 -0
index 2e53c05..7f698f4 100644
@@ -107,6 +107,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,
 };
 
@@ -238,6 +239,115 @@ static void parse_gb_huge_pages(char *param, char *val)
      }
 }
 
Quoted 10 lines

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

Quoted 5 lines
arch/x86/boot/compressed/kaslr.c +5 -0
+/* code heavily copied from parse_crashkernel_mem() */
+static void handle_crashkernel_mem(char *cmdline,
+                                     unsigned long long system_ram,
+                                     unsigned long long *crash_size,
+                                     unsigned long long *crash_base)

This version looks better and the logic is simple. It will be much better if we can share code with parse_crashkernel_mem() since both of them look almost the same.

A little hard, but I will have a try.

Quoted 55 lines
Quoted 55 lines
arch/x86/boot/compressed/kaslr.c +55 -0
+{
+     char *tmp, *cur = cmdline;
+
+     /* for each entry of the comma-separated list */
+     do {
+             unsigned long long start, end = ULLONG_MAX, size;
+
+             /* get the start of the range */
+             start = memparse(cur, &tmp);
+             /* no value given */
+             if (cur == tmp)
+                     return;
+             cur = tmp;
+             if (*cur != '-')
+                     return;
+             cur++;
+
+             /* if no ':' is here, than we read the end */
+             if (*cur != ':') {
+                     end = memparse(cur, &tmp);
+                     /* no value given */
+                     if (cur == tmp)
+                             return;
+                     cur = tmp;
+                     /* invalid if crashkernel end <= start */
+                     if (end <= start)
+                             return;
+             }
+             /* expect ":" after range */
+             if (*cur != ':')
+                     return;
+             cur++;
+
+             size = memparse(cur, &tmp);
+             /* no size value given */
+             if (cur == tmp)
+                     return;
+             cur = tmp;
+             if (size >= system_ram)
+                     return;
+
+             /* match ? */
+             if (system_ram >= start && system_ram < end) {
+                     *crash_size = size;
+                     break;
+             }
+     } while (*cur++ == ',');
+
+     if (*crash_size > 0) {
+             while (*cur && *cur != ' ' && *cur != '@')
+                     cur++;
+             if (*cur == '@') {
+                     cur++;
+                     *crash_base = memparse(cur, &tmp);
+             }
Quoted 9 lines

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

Quoted 5 lines
arch/x86/boot/compressed/kaslr.c +5 -0
+     }
+}
+
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
+static void mem_avoid_specified_crashkernel_region(char *option)

Maybe just add more words to explain the specified crashkernel region cases, but remove the 'speecified' word in function name?

OK.

Quoted 13 lines
Quoted 13 lines
arch/x86/boot/compressed/kaslr.c +13 -0
+{
+     unsigned long long crash_size, crash_base = 0;
+     char    *first_colon, *first_space, *cur = option;
+
+     first_colon = strchr(option, ':');
+     first_space = strchr(option, ' ');
+     /* if contain ":" */
+     if (first_colon && (!first_space || first_colon < first_space)) {
+             int i;
+             u64 total_sz = 0;
+             struct boot_e820_entry *entry;
+
+             for (i = 0; i < boot_params->e820_entries; i++) {
Quoted 9 lines

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

Quoted 5 lines
arch/x86/boot/compressed/kaslr.c +5 -0
+                     entry = &boot_params->e820_table[i];
+                     /* Skip non-RAM entries. */
+                     if (entry->type != E820_TYPE_RAM)
+                             continue;
+                     total_sz += entry->size;

Wrap this for loop into a static function to calculate the system RAM size?

OK.

Thanks for your review.

Regards,
Pingfan

Quoted 65 lines

Other than these, I think this adding looks good. It won't impact the current handling, and very easy to recognize what it's doing. Thanks for the effort.

Thanks
Baoquan

Quoted 59 lines
arch/x86/boot/compressed/kaslr.c +30 -3
+             }
+             handle_crashkernel_mem(option, total_sz, &crash_size,
+                     &crash_base);
+     } else {
+             crash_size = memparse(option, &cur);
+             if (option == cur)
+                     return;
+             while (*cur && *cur != ' ' && *cur != '@')
+                     cur++;
+             if (*cur == '@') {
+                     option = cur + 1;
+                     crash_base = memparse(option, &cur);
+             }
+     }
+     if (crash_base) {
+             mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+             mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+     } else {
+             /*
+              * Clearing mem_avoid if no offset is given. This is consistent
+              * with kernel, which uses the last crashkernel= option.
+              */
+             mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+             mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+     }
+}
 
 static void handle_mem_options(void)
 {
@@ -248,7 +358,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);
@@ -284,6 +394,8 @@ static void handle_mem_options(void)
                              goto out;
 
                      mem_limit = mem_size;
+             } else if (strstr(param, "crashkernel")) {
+                     mem_avoid_specified_crashkernel_region(val);
              }
      }
 
@@ -412,7 +524,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();
 
      /* Enumerate the immovable memory regions */
--

2.7.4

#7 lore raw
In reply to Pingfan Liu

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

Quoted 6 lines
arch/x86/boot/compressed/kaslr.c +6 -0
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+	unsigned long long crash_size, crash_base = 0;
+	char	*first_colon, *first_space, *cur = option;
+

Another thing which need be noticed is that you may only need to handle when '@' is found. Otherwise just let it go. Right?

Quoted 40 lines
arch/x86/boot/compressed/kaslr.c +40 -0
+	first_colon = strchr(option, ':');
+	first_space = strchr(option, ' ');
+	/* if contain ":" */
+	if (first_colon && (!first_space || first_colon < first_space)) {
+		int i;
+		u64 total_sz = 0;
+		struct boot_e820_entry *entry;
+
+		for (i = 0; i < boot_params->e820_entries; i++) {
+			entry = &boot_params->e820_table[i];
+			/* Skip non-RAM entries. */
+			if (entry->type != E820_TYPE_RAM)
+				continue;
+			total_sz += entry->size;
+		}
+		handle_crashkernel_mem(option, total_sz, &crash_size,
+			&crash_base);
+	} else {
+		crash_size = memparse(option, &cur);
+		if (option == cur)
+			return;
+		while (*cur && *cur != ' ' && *cur != '@')
+			cur++;
+		if (*cur == '@') {
+			option = cur + 1;
+			crash_base = memparse(option, &cur);
+		}
+	}
+	if (crash_base) {
+		mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+		mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+	} else {
+		/*
+ 		 * Clearing mem_avoid if no offset is given. This is consistent
+ 		 * with kernel, which uses the last crashkernel= option.
+		 */
+		mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+		mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+	}
+}
#8 lore raw
Quoted 11 lines · Baoquan He

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

Quoted 7 lines
arch/x86/boot/compressed/kaslr.c +6 -0
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+     unsigned long long crash_size, crash_base = 0;
+     char    *first_colon, *first_space, *cur = option;
+

Another thing which need be noticed is that you may only need to handle when '@' is found. Otherwise just let it go. Right?

According to kernel's behavior, only the last "crashkernel=" option takes effect. Hence if no '@', then clearing mem_avoid

Quoted 40 lines
Quoted 40 lines
arch/x86/boot/compressed/kaslr.c +40 -0
+     first_colon = strchr(option, ':');
+     first_space = strchr(option, ' ');
+     /* if contain ":" */
+     if (first_colon && (!first_space || first_colon < first_space)) {
+             int i;
+             u64 total_sz = 0;
+             struct boot_e820_entry *entry;
+
+             for (i = 0; i < boot_params->e820_entries; i++) {
+                     entry = &boot_params->e820_table[i];
+                     /* Skip non-RAM entries. */
+                     if (entry->type != E820_TYPE_RAM)
+                             continue;
+                     total_sz += entry->size;
+             }
+             handle_crashkernel_mem(option, total_sz, &crash_size,
+                     &crash_base);
+     } else {
+             crash_size = memparse(option, &cur);
+             if (option == cur)
+                     return;
+             while (*cur && *cur != ' ' && *cur != '@')
+                     cur++;
+             if (*cur == '@') {
+                     option = cur + 1;
+                     crash_base = memparse(option, &cur);
+             }
+     }
+     if (crash_base) {
+             mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+             mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+     } else {
+             /*
+              * Clearing mem_avoid if no offset is given. This is consistent
+              * with kernel, which uses the last crashkernel= option.
+              */
+             mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+             mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+     }
+}
#9 lore raw
Quoted 12 lines · Pingfan Liu
Quoted 11 lines · Baoquan He

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

Quoted 7 lines
arch/x86/boot/compressed/kaslr.c +6 -0
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+     unsigned long long crash_size, crash_base = 0;
+     char    *first_colon, *first_space, *cur = option;
+

Another thing which need be noticed is that you may only need to handle when '@' is found. Otherwise just let it go. Right?

Quoted 2 lines

According to kernel's behavior, only the last "crashkernel=" option takes effect. Hence if no '@', then clearing mem_avoid

Here I mean that you can search '@' at the beginning if crashkernel is found. Maybe no need to clear mem_avoid since it's global data, has been initialized to 0 during loading. It's in BSS, right?

You don't have to search first colon or first space, then parse size of crashkernel, and finally find out that it's only crashkernel=512M-2G:64M,2G-:128M style, no '@' specified. What do you think?

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
arch/x86/boot/compressed/kaslr.c +40 -0
+     first_colon = strchr(option, ':');
+     first_space = strchr(option, ' ');
+     /* if contain ":" */
+     if (first_colon && (!first_space || first_colon < first_space)) {
+             int i;
+             u64 total_sz = 0;
+             struct boot_e820_entry *entry;
+
+             for (i = 0; i < boot_params->e820_entries; i++) {
+                     entry = &boot_params->e820_table[i];
+                     /* Skip non-RAM entries. */
+                     if (entry->type != E820_TYPE_RAM)
+                             continue;
+                     total_sz += entry->size;
+             }
+             handle_crashkernel_mem(option, total_sz, &crash_size,
+                     &crash_base);
+     } else {
+             crash_size = memparse(option, &cur);
+             if (option == cur)
+                     return;
+             while (*cur && *cur != ' ' && *cur != '@')
+                     cur++;
+             if (*cur == '@') {
+                     option = cur + 1;
+                     crash_base = memparse(option, &cur);
+             }
+     }
+     if (crash_base) {
+             mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+             mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+     } else {
+             /*
+              * Clearing mem_avoid if no offset is given. This is consistent
+              * with kernel, which uses the last crashkernel= option.
+              */
+             mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+             mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+     }
+}
#10 lore raw
Quoted 14 lines · Baoquan He
Quoted 12 lines · Pingfan Liu
Quoted 11 lines · Baoquan He

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

Quoted 7 lines
arch/x86/boot/compressed/kaslr.c +6 -0
+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
+static void mem_avoid_specified_crashkernel_region(char *option)
+{
+     unsigned long long crash_size, crash_base = 0;
+     char    *first_colon, *first_space, *cur = option;
+

Another thing which need be noticed is that you may only need to handle when '@' is found. Otherwise just let it go. Right?

Quoted 7 lines
Quoted 2 lines

According to kernel's behavior, only the last "crashkernel=" option takes effect. Hence if no '@', then clearing mem_avoid

Here I mean that you can search '@' at the beginning if crashkernel is found. Maybe no need to clear mem_avoid since it's global data, has been initialized to 0 during loading. It's in BSS, right?

Consider the following cmdline crashkernel=256M@1G crashkernel=512M. These two options are handled independently by handle_mem_options(), and the later one should overwrite the previous one. This is the behavior of current kernel's code, referring to get_last_crashkernel().

Quoted 4 lines

You don't have to search first colon or first space, then parse size of crashkernel, and finally find out that it's only crashkernel=512M-2G:64M,2G-:128M style, no '@' specified. What do you think?

Yes, that will be better. But I plan to reuse parse_crashkernel_mem/simple().

Thanks,
Pingfan

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
arch/x86/boot/compressed/kaslr.c +40 -0
+     first_colon = strchr(option, ':');
+     first_space = strchr(option, ' ');
+     /* if contain ":" */
+     if (first_colon && (!first_space || first_colon < first_space)) {
+             int i;
+             u64 total_sz = 0;
+             struct boot_e820_entry *entry;
+
+             for (i = 0; i < boot_params->e820_entries; i++) {
+                     entry = &boot_params->e820_table[i];
+                     /* Skip non-RAM entries. */
+                     if (entry->type != E820_TYPE_RAM)
+                             continue;
+                     total_sz += entry->size;
+             }
+             handle_crashkernel_mem(option, total_sz, &crash_size,
+                     &crash_base);
+     } else {
+             crash_size = memparse(option, &cur);
+             if (option == cur)
+                     return;
+             while (*cur && *cur != ' ' && *cur != '@')
+                     cur++;
+             if (*cur == '@') {
+                     option = cur + 1;
+                     crash_base = memparse(option, &cur);
+             }
+     }
+     if (crash_base) {
+             mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
+             mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
+     } else {
+             /*
+              * Clearing mem_avoid if no offset is given. This is consistent
+              * with kernel, which uses the last crashkernel= option.
+              */
+             mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
+             mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
+     }
+}