Skip to contentSkip to conversation

x86: e820: Implement a range manipulation operator

PATCH Superseded Jan H. Schönherr 2 participants 4 messages Feb 1, 2018 – Feb 2, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: e820: Implement a range manipulation operator

Add a more versatile memmap= operator, which -- in addition to all the things that were possible before -- allows you to:
- redeclare existing ranges -- before, you were limited to adding ranges;
- drop any range -- like a mem= for any location;
- use any e820 memory type -- not just some predefined ones.

The syntax is:

memmap=<size>%<offset>-<oldtype>+<newtype>

Size and offset work as usual. The "-<oldtype>" and "+<newtype>" are optional and their existence determine the behavior: The command works on the specified range of memory limited to type <oldtype> (if specified). This memory is then configured to show up as <newtype>. If <newtype> is not specified, the memory is removed from the e820 map.

---
 Documentation/admin-guide/kernel-parameters.txt |  9 +++++++++
 arch/x86/kernel/e820.c                          | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +9 -0
index 46b26bfee27b..94609eaff2a9 100644
@@ -2221,6 +2221,15 @@
 			The memory region may be marked as e820 type 12 (0xc)
 			and is NVDIMM or ADR memory.
 
+	memmap=<size>%<offset>-<oldtype>+<newtype>
+			[KNL,ACPI] Convert memory within the specified region
+			from <oldtype> to <newtype>. If "-<oldtype>" is left
+			out, the whole region will be marked as <newtype>,
+			even if previously unavailable. If "+<newtype>" is left
+			out, matching memory will be removed. Types are
+			specified as e820 types, eg, 1==RAM, 2==reserved,
+			3==ACPI, 12==PRAM.
+
 	memory_corruption_check=0/1 [X86]
 			Some BIOSes seem to corrupt the first 64k of
 			memory when doing things like suspend/resume.
arch/x86/kernel/e820.c +18 -0
index 71c11ad5643e..cd22c6a07632 100644
@@ -924,6 +924,24 @@ static int __init parse_memmap_one(char *p)
 	} else if (*p == '!') {
 		start_at = memparse(p+1, &p);
 		e820__range_add(start_at, mem_size, E820_TYPE_PRAM);
+	} else if (*p == '%') {
+		enum e820_type from = 0, to = 0;
+
+		start_at = memparse(p + 1, &p);
+		if (*p == '-')
+			from = simple_strtoull(p + 1, &p, 0);
+		if (*p == '+')
+			to = simple_strtoull(p + 1, &p, 0);
+		if (*p != 0)
+			return -EINVAL;
+		if (from && to)
+			e820__range_update(start_at, mem_size, from, to);
+		else if (to)
+			e820__range_add(start_at, mem_size, to);
+		else if (from)
+			e820__range_remove(start_at, mem_size, from, 1);
+		else
+			e820__range_remove(start_at, mem_size, 0, 0);
 	} else {
 		e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
 	}
Signature · 1 line
2.9.3.1.gcba166c.dirty
#1 lore raw

Documentation/admin-guide/kernel-parameters.txt line 2231

Quoted 7 lines · Jan H. Schönherr
Documentation/admin-guide/kernel-parameters.txt +7 -0
+                       [KNL,ACPI] Convert memory within the specified region
+                       from <oldtype> to <newtype>. If "-<oldtype>" is left
+                       out, the whole region will be marked as <newtype>,
+                       even if previously unavailable. If "+<newtype>" is left
+                       out, matching memory will be removed. Types are
+                       specified as e820 types, eg, 1==RAM, 2==reserved,
+                       3==ACPI, 12==PRAM.

s/==/ = /g

arch/x86/kernel/e820.c static int __init parse_memmap_one(char *p) · line 935

Quoted 9 lines
arch/x86/kernel/e820.c +9 -0
+       } else if (*p == '%') {
+               enum e820_type from = 0, to = 0;
+
+               start_at = memparse(p + 1, &p);
+               if (*p == '-')
+                       from = simple_strtoull(p + 1, &p, 0);
+               if (*p == '+')
+                       to = simple_strtoull(p + 1, &p, 0);
+               if (*p != 0)

if (*p)

or

if (*p != '\0')

?

Quoted 9 lines
arch/x86/kernel/e820.c +9 -0
+                       return -EINVAL;
+               if (from && to)
+                       e820__range_update(start_at, mem_size, from, to);
+               else if (to)
+                       e820__range_add(start_at, mem_size, to);
+               else if (from)
+                       e820__range_remove(start_at, mem_size, from, 1);
+               else
+                       e820__range_remove(start_at, mem_size, 0, 0);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 11 lines · Andy Shevchenko

Documentation/admin-guide/kernel-parameters.txt line 2231

Quoted 7 lines · Jan H. Schönherr
Documentation/admin-guide/kernel-parameters.txt +7 -0
+                       [KNL,ACPI] Convert memory within the specified region
+                       from <oldtype> to <newtype>. If "-<oldtype>" is left
+                       out, the whole region will be marked as <newtype>,
+                       even if previously unavailable. If "+<newtype>" is left
+                       out, matching memory will be removed. Types are
+                       specified as e820 types, eg, 1==RAM, 2==reserved,
+                       3==ACPI, 12==PRAM.

s/==/ = /g

Sure. I've also properly abbreviated that "e.g.".

Quoted 10 lines

arch/x86/kernel/e820.c static int __init parse_memmap_one(char *p) · line 935

Quoted 9 lines
arch/x86/kernel/e820.c +9 -0
+       } else if (*p == '%') {
+               enum e820_type from = 0, to = 0;
+
+               start_at = memparse(p + 1, &p);
+               if (*p == '-')
+                       from = simple_strtoull(p + 1, &p, 0);
+               if (*p == '+')
+                       to = simple_strtoull(p + 1, &p, 0);
+               if (*p != 0)
Quoted 7 lines

if (*p)

or

if (*p != '\0')

?

Something similar to the latter is used in the function already. The latter it is.

Regards
Jan

#3 lore raw

PATCH v2 1/1 x86: e820: Implement a range manipulation operator

Add a more versatile memmap= operator, which -- in addition to all the things that were possible before -- allows you to:
- redeclare existing ranges -- before, you were limited to adding ranges;
- drop any range -- like a mem= for any location;
- use any e820 memory type -- not just some predefined ones.

The syntax is:

memmap=<size>%<offset>-<oldtype>+<newtype>

Size and offset work as usual. The "-<oldtype>" and "+<newtype>" are optional and their existence determine the behavior: The command works on the specified range of memory limited to type <oldtype> (if specified). This memory is then configured to show up as <newtype>. If <newtype> is not specified, the memory is removed from the e820 map.

---
v2: Small coding style and typography adjustments

 Documentation/admin-guide/kernel-parameters.txt |  9 +++++++++
 arch/x86/kernel/e820.c                          | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +9 -0
index 46b26bfee27b..60926ae3ec06 100644
@@ -2221,6 +2221,15 @@
 			The memory region may be marked as e820 type 12 (0xc)
 			and is NVDIMM or ADR memory.
 
+	memmap=<size>%<offset>-<oldtype>+<newtype>
+			[KNL,ACPI] Convert memory within the specified region
+			from <oldtype> to <newtype>. If "-<oldtype>" is left
+			out, the whole region will be marked as <newtype>,
+			even if previously unavailable. If "+<newtype>" is left
+			out, matching memory will be removed. Types are
+			specified as e820 types, e.g., 1 = RAM, 2 = reserved,
+			3 = ACPI, 12 = PRAM.
+
 	memory_corruption_check=0/1 [X86]
 			Some BIOSes seem to corrupt the first 64k of
 			memory when doing things like suspend/resume.
arch/x86/kernel/e820.c +18 -0
index 71c11ad5643e..6a2cb1442e05 100644
@@ -924,6 +924,24 @@ static int __init parse_memmap_one(char *p)
 	} else if (*p == '!') {
 		start_at = memparse(p+1, &p);
 		e820__range_add(start_at, mem_size, E820_TYPE_PRAM);
+	} else if (*p == '%') {
+		enum e820_type from = 0, to = 0;
+
+		start_at = memparse(p + 1, &p);
+		if (*p == '-')
+			from = simple_strtoull(p + 1, &p, 0);
+		if (*p == '+')
+			to = simple_strtoull(p + 1, &p, 0);
+		if (*p != '\0')
+			return -EINVAL;
+		if (from && to)
+			e820__range_update(start_at, mem_size, from, to);
+		else if (to)
+			e820__range_add(start_at, mem_size, to);
+		else if (from)
+			e820__range_remove(start_at, mem_size, from, 1);
+		else
+			e820__range_remove(start_at, mem_size, 0, 0);
 	} else {
 		e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
 	}
Signature · 1 line
2.9.3.1.gcba166c.dirty