mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests
@ 2026-11-24 13:32 Pankaj Gupta
  2026-11-24 13:32 ` [PATCH RFC 1/3] x86/e820: Ignore memmap= " Pankaj Gupta
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Pankaj Gupta @ 2026-11-24 13:32 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: H . Peter Anvin, Tom Lendacky, Ard Biesheuvel, Kiryl Shutsemau,
	Ilias Apalodimas, linux-kernel, Mike Rapoport, linux-mm,
	linux-efi, Pankaj.gupta.linux, 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_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/20261102113127.161823-1-pankaj.gupta@amd.com/
[2] https://lore.kernel.org/all/20261113105554.199912-1-pankaj.gupta@amd.com/

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(+)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH RFC 1/3] x86/e820: Ignore memmap= in confidential guests
  2026-11-24 13:32 [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests Pankaj Gupta
@ 2026-11-24 13:32 ` Pankaj Gupta
  2026-11-24 13:32 ` [PATCH RFC 2/3] x86/e820: Allow memmap= in a kdump kernel " Pankaj Gupta
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Pankaj Gupta @ 2026-11-24 13:32 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: H . Peter Anvin, Tom Lendacky, Ard Biesheuvel, Kiryl Shutsemau,
	Ilias Apalodimas, linux-kernel, Mike Rapoport, linux-mm,
	linux-efi, Pankaj.gupta.linux, Pankaj Gupta

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/deb5ea81-70bd-463d-8d98-ed51c316cf75@app.fastmail.com/
[2] https://lore.kernel.org/all/20261113105554.199912-1-pankaj.gupta@amd.com/

Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Pankaj Gupta <pankaj.gupta@amd.com>
---
 arch/x86/kernel/e820.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 0967b485f38b..142657be690d 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -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, ',');
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH RFC 2/3] x86/e820: Allow memmap= in a kdump kernel in confidential guests
  2026-11-24 13:32 [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests Pankaj Gupta
  2026-11-24 13:32 ` [PATCH RFC 1/3] x86/e820: Ignore memmap= " Pankaj Gupta
@ 2026-11-24 13:32 ` Pankaj Gupta
  2026-11-24 13:32 ` [PATCH RFC 3/3] x86/e820: Ignore mem= " Pankaj Gupta
  2026-11-24 15:09 ` [PATCH RFC 0/3] x86/e820: Ignore memmap= and " Dave Hansen
  3 siblings, 0 replies; 9+ messages in thread
From: Pankaj Gupta @ 2026-11-24 13:32 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: H . Peter Anvin, Tom Lendacky, Ard Biesheuvel, Kiryl Shutsemau,
	Ilias Apalodimas, linux-kernel, Mike Rapoport, linux-mm,
	linux-efi, Pankaj.gupta.linux, Pankaj Gupta

A 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.

Signed-off-by: Pankaj Gupta <pankaj.gupta@amd.com>
---
 arch/x86/kernel/e820.c | 7 +++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 142657be690d..9c206ad4369c 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -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;
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH RFC 3/3] x86/e820: Ignore mem= in confidential guests
  2026-11-24 13:32 [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests Pankaj Gupta
  2026-11-24 13:32 ` [PATCH RFC 1/3] x86/e820: Ignore memmap= " Pankaj Gupta
  2026-11-24 13:32 ` [PATCH RFC 2/3] x86/e820: Allow memmap= in a kdump kernel " Pankaj Gupta
@ 2026-11-24 13:32 ` Pankaj Gupta
  2026-11-24 15:09 ` [PATCH RFC 0/3] x86/e820: Ignore memmap= and " Dave Hansen
  3 siblings, 0 replies; 9+ messages in thread
From: Pankaj Gupta @ 2026-11-24 13:32 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: H . Peter Anvin, Tom Lendacky, Ard Biesheuvel, Kiryl Shutsemau,
	Ilias Apalodimas, linux-kernel, Mike Rapoport, linux-mm,
	linux-efi, Pankaj.gupta.linux, Pankaj Gupta

mem= 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=.

Signed-off-by: Pankaj Gupta <pankaj.gupta@amd.com>
---
 arch/x86/kernel/e820.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 9c206ad4369c..c7b86267a480 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -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);
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests
  2026-11-24 13:32 [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests Pankaj Gupta
                   ` (2 preceding siblings ...)
  2026-11-24 13:32 ` [PATCH RFC 3/3] x86/e820: Ignore mem= " Pankaj Gupta
@ 2026-11-24 15:09 ` Dave Hansen
  2026-11-24 15:56   ` Mike Rapoport
  3 siblings, 1 reply; 9+ messages in thread
From: Dave Hansen @ 2026-11-24 15:09 UTC (permalink / raw)
  To: Pankaj Gupta, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86
  Cc: H . Peter Anvin, Tom Lendacky, Ard Biesheuvel, Kiryl Shutsemau,
	Ilias Apalodimas, linux-kernel, Mike Rapoport, linux-mm,
	linux-efi, Pankaj.gupta.linux

On 11/24/26 05:32, Pankaj Gupta wrote:
> 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.

memmap= and mem= are debugging tools, right? If you use them, you get to
keep the pieces. Why add complexity for this?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests
  2026-11-24 15:09 ` [PATCH RFC 0/3] x86/e820: Ignore memmap= and " Dave Hansen
@ 2026-11-24 15:56   ` Mike Rapoport
  2026-11-24 15:58     ` Dave Hansen
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Rapoport @ 2026-11-24 15:56 UTC (permalink / raw)
  To: Dave Hansen
  Cc: Pankaj Gupta, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H . Peter Anvin, Tom Lendacky, Ard Biesheuvel,
	Kiryl Shutsemau, Ilias Apalodimas, linux-kernel, linux-mm,
	linux-efi, Pankaj.gupta.linux

On Tue, Nov 24, 2026 at 07:09:42AM -0800, Dave Hansen wrote:
> On 11/24/26 05:32, Pankaj Gupta wrote:
> > 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.
> 
> memmap= and mem= are debugging tools, right? 

I wish they were :)
But AFAIU they are used to carve out "pmem" or PFN-mapped memory.

> If you use them, you get to keep the pieces. Why add complexity for this?

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests
  2026-11-24 15:56   ` Mike Rapoport
@ 2026-11-24 15:58     ` Dave Hansen
  2026-11-24 16:14       ` Mike Rapoport
  0 siblings, 1 reply; 9+ messages in thread
From: Dave Hansen @ 2026-11-24 15:58 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Pankaj Gupta, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H . Peter Anvin, Tom Lendacky, Ard Biesheuvel,
	Kiryl Shutsemau, Ilias Apalodimas, linux-kernel, linux-mm,
	linux-efi, Pankaj.gupta.linux

On 11/24/26 07:56, Mike Rapoport wrote:
> On Tue, Nov 24, 2026 at 07:09:42AM -0800, Dave Hansen wrote:
>> On 11/24/26 05:32, Pankaj Gupta wrote:
>>> 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.
>> 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?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests
  2026-11-24 15:58     ` Dave Hansen
@ 2026-11-24 16:14       ` Mike Rapoport
  2026-11-24 16:26         ` Ard Biesheuvel
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Rapoport @ 2026-11-24 16:14 UTC (permalink / raw)
  To: Dave Hansen
  Cc: Pankaj Gupta, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H . Peter Anvin, Tom Lendacky, Ard Biesheuvel,
	Kiryl Shutsemau, Ilias Apalodimas, linux-kernel, linux-mm,
	linux-efi, Pankaj.gupta.linux

On Tue, Nov 24, 2026 at 07:58:31AM -0800, Dave Hansen wrote:
> On 11/24/26 07:56, Mike Rapoport wrote:
> > On Tue, Nov 24, 2026 at 07:09:42AM -0800, Dave Hansen wrote:
> >> On 11/24/26 05:32, Pankaj Gupta wrote:
> >>> 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.
> >> 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 :)

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests
  2026-11-24 16:14       ` Mike Rapoport
@ 2026-11-24 16:26         ` Ard Biesheuvel
  0 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-11-24 16:26 UTC (permalink / raw)
  To: Mike Rapoport, Dave Hansen
  Cc: Pankaj Gupta, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H . Peter Anvin, Tom Lendacky,
	Kiryl Shutsemau (Meta),
	Ilias Apalodimas, linux-kernel, linux-mm, linux-efi,
	Pankaj.gupta.linux


On Tue, 24 Nov 2026, at 17:14, Mike Rapoport wrote:
> On Tue, Nov 24, 2026 at 07:58:31AM -0800, Dave Hansen wrote:
>> On 11/24/26 07:56, Mike Rapoport wrote:
>> > On Tue, Nov 24, 2026 at 07:09:42AM -0800, Dave Hansen wrote:
>> >> On 11/24/26 05:32, Pankaj Gupta wrote:
>> >>> 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.
>> >> 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 :)
>

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-24 16:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 13:32 [PATCH RFC 0/3] x86/e820: Ignore memmap= and mem= in confidential guests Pankaj Gupta
2026-11-24 13:32 ` [PATCH RFC 1/3] x86/e820: Ignore memmap= " Pankaj Gupta
2026-11-24 13:32 ` [PATCH RFC 2/3] x86/e820: Allow memmap= in a kdump kernel " Pankaj Gupta
2026-11-24 13:32 ` [PATCH RFC 3/3] x86/e820: Ignore mem= " Pankaj Gupta
2026-11-24 15:09 ` [PATCH RFC 0/3] x86/e820: Ignore memmap= and " Dave Hansen
2026-11-24 15:56   ` Mike Rapoport
2026-11-24 15:58     ` Dave Hansen
2026-11-24 16:14       ` Mike Rapoport
2026-11-24 16:26         ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®