Skip to content

Commit ef61f8a

Browse files
schnhrrIngo Molnar
authored andcommitted
x86/boot/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. Signed-off-by: Jan H. Schönherr <jschoenh@amazon.de> Cc: Andy Lutomirski <luto@kernel.org> Cc: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20180202231020.15608-1-jschoenh@amazon.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 672c0ae commit ef61f8a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,15 @@
22372237
The memory region may be marked as e820 type 12 (0xc)
22382238
and is NVDIMM or ADR memory.
22392239

2240+
memmap=<size>%<offset>-<oldtype>+<newtype>
2241+
[KNL,ACPI] Convert memory within the specified region
2242+
from <oldtype> to <newtype>. If "-<oldtype>" is left
2243+
out, the whole region will be marked as <newtype>,
2244+
even if previously unavailable. If "+<newtype>" is left
2245+
out, matching memory will be removed. Types are
2246+
specified as e820 types, e.g., 1 = RAM, 2 = reserved,
2247+
3 = ACPI, 12 = PRAM.
2248+
22402249
memory_corruption_check=0/1 [X86]
22412250
Some BIOSes seem to corrupt the first 64k of
22422251
memory when doing things like suspend/resume.

arch/x86/kernel/e820.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,24 @@ static int __init parse_memmap_one(char *p)
924924
} else if (*p == '!') {
925925
start_at = memparse(p+1, &p);
926926
e820__range_add(start_at, mem_size, E820_TYPE_PRAM);
927+
} else if (*p == '%') {
928+
enum e820_type from = 0, to = 0;
929+
930+
start_at = memparse(p + 1, &p);
931+
if (*p == '-')
932+
from = simple_strtoull(p + 1, &p, 0);
933+
if (*p == '+')
934+
to = simple_strtoull(p + 1, &p, 0);
935+
if (*p != '\0')
936+
return -EINVAL;
937+
if (from && to)
938+
e820__range_update(start_at, mem_size, from, to);
939+
else if (to)
940+
e820__range_add(start_at, mem_size, to);
941+
else if (from)
942+
e820__range_remove(start_at, mem_size, from, 1);
943+
else
944+
e820__range_remove(start_at, mem_size, 0, 0);
927945
} else {
928946
e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
929947
}

0 commit comments

Comments
 (0)