x86/e820: Ignore memmap= and mem= in confidential guests
Subsystems (3)
cover x86/e820: Ignore memmap= and mem= in confidential guests
In a confidential guest (SEV-SNP, TDX) the EFI stub builds the unaccepted memory bitmap before the command line is parsed. memmap= and mem= edit e820_table only afterwards.
accept_memory() accepts whole 2 MiB units. A memmap= hole that is not unit-aligned is touched when its unit is accepted. On SEV-SNP this faults early in boot and crashes the guest (e.g. memmap=1M$0x1ffe00000), because PVALIDATE needs the page mapped and the hole is not. TDX works on physical addresses, so the hole is accepted and the options work there today. The same option therefore behaves differently per vendor.
This replaces my earlier fix [1][2], following review feedback from Ard Biesheuvel and Kiryl Shutsemau: the firmware's view of memory must match the OS, and a bitmap unit cannot be half accepted. Instead of making the bitmap follow memmap= and mem=, ignore them in confidential guests.
Patch 1 warns and ignores memmap= in confidential guests. Patch 2 keeps memmap= in a kdump kernel (elfcorehdr= on the command
line), as ignoring it would let the kdump kernel use the memory of the crashed kernel.
Patch 3 does the same for mem=.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Pankaj Gupta (3):
x86/e820: Ignore memmap= in confidential guests x86/e820: Allow memmap= in a kdump kernel in confidential guests x86/e820: Ignore mem= in confidential guests
arch/x86/kernel/e820.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
Signature · 1 line
2.34.1
RFC PATCH 1/3 x86/e820: Ignore memmap= in confidential guests
In a confidential guest the memory layout, including the EFI unaccepted memory bitmap, is set up by the firmware and the EFI stub before the command line is parsed. memmap= only edits the E820 table afterwards, so the two no longer match.
The bitmap has one bit per unit and a unit cannot be partly accepted. A memmap= hole that does not start and end on unit boundaries splits a unit. Accepting that unit touches the hole, which faults early in boot on SEV-SNP. A kexec kernel gets an E820 table in which the hole is still RAM.
Ard suggested to avoid such command line hacks in confidential VMs, as the firmware's view of memory should be in sync with the OS [1]. The discussion of the unaccepted memory fix [2] showed that the bitmap cannot represent this case.
Warn and ignore memmap= in confidential guests.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
--- arch/x86/kernel/e820.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/x86/kernel/e820.c +13 -0
@@ -15,6 +15,7 @@#include <linux/firmware-map.h> #include <linux/sort.h> #include <linux/kvm_types.h> +#include <linux/cc_platform.h> #include <asm/e820/api.h> #include <asm/setup.h>
@@ -905,6 +906,15 @@ __init unsigned long e820__end_of_low_ram_pfn(void)__initdata static int userdef; +__init static bool cc_ignore_cmdline_mem (const char *opt) +{ +if (!cc_platform_has (CC_ATTR_GUEST_MEM_ENCRYPT )) +return false; + +pr_warn ("%s= is not supported in confidential guests, ignoring\n" , opt); +return true; +} +/* The "mem=nopentium" boot option disables 4MB page tables on 32-bit kernels: */ __init static int parse_memopt (char *p) {
@@ -997,6 +1007,9 @@ __init static int parse_memmap_one(char *p)__init static int parse_memmap_opt (char *str) { +if (cc_ignore_cmdline_mem ("memmap" )) +return 0 ; +while (str) {char *k =strchr (str,',' );
Signature · 1 line
2.34.1
RFC PATCH 2/3 x86/e820: Allow memmap= in a kdump kernel in confidential guests
In reply to Pankaj GuptaA kdump kernel can get memmap= on its command line, e.g. from kexec_load, to restrict the memory it may use to its reserved region. Ignoring it would let the kdump kernel use the memory of the crashed kernel.
Do not ignore memmap= when elfcorehdr= is on the command line, which marks a kdump kernel.
--- arch/x86/kernel/e820.c | 7 +++++++ 1 file changed, 6 insertions(+)
arch/x86/kernel/e820.c +6 -0
@@ -17,6 +17,7 @@#include <linux/kvm_types.h> #include <linux/cc_platform.h> +#include <asm/cmdline.h> #include <asm/e820/api.h> #include <asm/setup.h>
@@ -908,9 +909,14 @@ __initdata static int userdef;__init static bool cc_ignore_cmdline_mem (const char *opt) { +char buf[32 ]; +if (!cc_platform_has (CC_ATTR_GUEST_MEM_ENCRYPT ))return false; +if (cmdline_find_option (boot_command_line,"elfcorehdr" , buf,sizeof (buf)) >=0 ) +return false; +pr_warn ("%s= is not supported in confidential guests, ignoring\n" , opt);return true; }
Signature · 1 line
2.34.1
RFC PATCH 3/3 x86/e820: Ignore mem= in confidential guests
In reply to Pankaj Guptamem= also only edits the E820 table, after the firmware and the EFI stub have set up the unaccepted memory bitmap. It removes the RAM above the given limit, but the bitmap bits for it stay set.
accept_memory() accepts whole units, and one more unit when the range ends on a unit boundary. Memory below the limit can therefore pull in a unit that is no longer in the E820 table. On SEV-SNP that memory is not mapped and PVALIDATE faults.
Warn and ignore mem= in confidential guests, for the same reason as memmap=.
--- arch/x86/kernel/e820.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kernel/e820.c +3 -0
@@ -940,6 +940,9 @@ __init static int parse_memopt(char *p)#endif } +if (cc_ignore_cmdline_mem ("mem" )) +return 0 ; + userdef =1 ; mem_size =memparse (p, &p);
Signature · 1 line
2.34.1
Quoted 3 lines · Pankaj Gupta
In a confidential guest (SEV-SNP, TDX) the EFI stub builds the unaccepted memory bitmap before the command line is parsed. memmap= and mem= edit
e820_tableonly afterwards.
memmap= and mem= are debugging tools, right? If you use them, you get to keep the pieces. Why add complexity for this?
Quoted 6 lines · Dave Hansen
Quoted 3 lines · Pankaj Gupta
In a confidential guest (SEV-SNP, TDX) the EFI stub builds the unaccepted memory bitmap before the command line is parsed. memmap= and mem= edit
e820_tableonly afterwards.memmap= and mem= are debugging tools, right?
I wish they were :)
But AFAIU they are used to carve out "pmem" or PFN-mapped memory.
Quoted 1 line
If you use them, you get to keep the pieces. Why add complexity for this?
Signature · 2 lines
Sincerely yours, Mike.
Quoted 8 lines · Mike Rapoport
Quoted 5 lines · Dave Hansen
Quoted 3 lines · Pankaj Gupta
In a confidential guest (SEV-SNP, TDX) the EFI stub builds the unaccepted memory bitmap before the command line is parsed. memmap= and mem= edit
e820_tableonly afterwards.memmap= and mem= are debugging tools, right?
I wish they were 🙂
But AFAIU they are used to carve out "pmem" or PFN-mapped memory.
I've used them that way for development, but production pmem systems always had persistent memory in their BIOS-provided memory maps.
How are folks depending on these in production in confidential guests?
Quoted 6 lines · Dave Hansen
Quoted 5 lines · Mike Rapoport
Quoted 4 lines · Dave Hansen
Quoted 3 lines · Pankaj Gupta
In a confidential guest (SEV-SNP, TDX) the EFI stub builds the unaccepted memory bitmap before the command line is parsed. memmap= and mem= edit
e820_tableonly afterwards.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
memmap= and mem= are debugging tools, right?
I wish they were 🙂
But AFAIU they are used to carve out "pmem" or PFN-mapped memory.I've used them that way for development, but production pmem systems always had persistent memory in their BIOS-provided memory maps.
How are folks depending on these in production in confidential guests?
They shouldn't but you can't guarantee that.
But I don't mind letting them crash if they do :)
Signature · 2 lines
Sincerely yours, Mike.
Ard Biesheuvel
maintainerQuoted 11 lines · Mike Rapoport
Quoted 10 lines · Dave Hansen
Quoted 8 lines · Mike Rapoport
Quoted 5 lines · Dave Hansen
Quoted 3 lines · Pankaj Gupta
In a confidential guest (SEV-SNP, TDX) the EFI stub builds the unaccepted memory bitmap before the command line is parsed. memmap= and mem= edit
e820_tableonly afterwards.memmap= and mem= are debugging tools, right?
I wish they were 🙂
But AFAIU they are used to carve out "pmem" or PFN-mapped memory.
Quoted 9 lines
Quoted 4 lines
I've used them that way for development, but production pmem systems always had persistent memory in their BIOS-provided memory maps.
How are folks depending on these in production in confidential guests?
They shouldn't but you can't guarantee that.
But I don't mind letting them crash if they do :)
I'm fine with either approach (i.e. disallowing it or doing nothing at all), as long as we don't pretend that this is something that is expected to work.
Quoted 7 lines · Ard Biesheuvel
Quoted 4 lines
They shouldn't but you can't guarantee that.
But I don't mind letting them crash if they do 🙂
I'm fine with either approach (i.e. disallowing it or doing nothing at all), as long as we don't pretend that this is something that is expected to work.
Yeah, it's not supposed to work. I'd rather document "don't poke the sharp stick in your eye" versus trying to make the stick less sharp.
Hi Dave,
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
They shouldn't but you can't guarantee that.
But I don't mind letting them crash if they do 🙂
I'm fine with either approach (i.e. disallowing it or doing nothing at all), as long as we don't pretend that this is something that is expected to work.
Yeah, it's not supposed to work. I'd rather document "don't poke the sharp stick in your eye" versus trying to make the stick less sharp.
I understand your point. Ideally I would prefer that the guest does not crash, so this makes me a bit uncomfortable.
However, fixing it would add complexity for something that is not expected to be used in production. I will send a patch to document this behavior.
Thanks,
Pankaj
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
In a confidential guest (SEV-SNP, TDX) the EFI stub builds the unaccepted memory bitmap before the command line is parsed. memmap= and mem= edit
e820_tableonly afterwards.memmap= and mem= are debugging tools, right?
I wish they were 🙂
But AFAIU they are used to carve out "pmem" or PFN-mapped memory.I've used them that way for development, but production pmem systems always had persistent memory in their BIOS-provided memory maps.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
How are folks depending on these in production in confidential guests?
They shouldn't but you can't guarantee that.
But I don't mind letting them crash if they do :)
I'm fine with either approach (i.e. disallowing it or doing nothing at all), as long as we don't pretend that this is something that is expected to work.
Yes, it is confusing for a user who expects it to work. I hit this myself and spent time finding the cause: a memmap= hole consistently crashes a confidential guest (SEV-SNP) early in boot.
I tried to fix it [1], but a bitmap unit cannot be half accepted when the hole is not 2 MiB aligned. Also, a TDX guest does accept such holes.
So we are left with the following options:
- disallow the memmap= options with a clear warning, as this series does,
- add similar handling for TDX, so that holes are not accepted there either, as done for SEV-SNP in [1]; memmap= holes that are not 2 MiB aligned would still be unhandled, or
- only print a warning and leave the options applied, in which case memmap= holes still crash SEV-SNP guests.
Which of these do you prefer, or is there a better way to handle it?
[1] https://lore.kernel.org/all/[email protected]/
Thanks,
Pankaj