Skip to contentSkip to conversation

x86/efi: Drop support for fake EFI memory maps

RFC PATCH In review Ard Biesheuvel 5 participants 7 messages Jun 20, 2024 – Jul 1, 2024

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

RFC PATCH 1/1 x86/efi: Drop support for fake EFI memory maps

From: Ard Biesheuvel <[email protected]>

Between kexec and confidential VM support, handling the EFI memory maps correctly on x86 is already proving to be rather difficult (as opposed to other EFI architectures which manage to never modify the EFI memory map to begin with)

EFI fake memory map support is essentially a development hack (for testing new support for the 'special purpose' and 'more reliable' EFI memory attributes) that leaked into production code. The regions marked in this manner are not actually recognized as such by the firmware itself or the EFI stub (and never have), and marking memory as 'more reliable' seems rather futile if the underlying memory is just ordinary RAM.

Marking memory as 'special purpose' in this way is also dubious, but may be in use in production code nonetheless. However, the same should be achievable by using the memmap= command line option with the ! operator.

EFI fake memmap support is not enabled by any of the major distros (Debian, Fedora, SUSE, Ubuntu) and does not exist on other architectures, so let's drop support for it.

Cc Taku Izumi <[email protected]>
Cc Dan Williams <[email protected]>
---
 Documentation/admin-guide/kernel-parameters.txt |  21 ---
 arch/x86/Kconfig                                |  20 --
 arch/x86/boot/compressed/kaslr.c                |  43 +----
 arch/x86/include/asm/efi.h                      |  15 --
 arch/x86/kernel/setup.c                         |   1 -
 arch/x86/platform/efi/efi.c                     |   2 -
 arch/x86/platform/efi/fake_mem.c                | 197 --------------------
 arch/x86/platform/efi/memmap.c                  |   1 +
 drivers/firmware/efi/libstub/x86-stub.c         |   2 +-
 9 files changed, 11 insertions(+), 291 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -21
index 11e57ba2985c..90c64525e7e1 100644
@@ -1450,27 +1450,6 @@
 			you are really sure that your UEFI does sane gc and
 			fulfills the spec otherwise your board may brick.
 
-	efi_fake_mem=	nn[KMG]@ss[KMG]:aa[,nn[KMG]@ss[KMG]:aa,..] [EFI,X86,EARLY]
-			Add arbitrary attribute to specific memory range by
-			updating original EFI memory map.
-			Region of memory which aa attribute is added to is
-			from ss to ss+nn.
-
-			If efi_fake_mem=2G@4G:0x10000,2G@0x10a0000000:0x10000
-			is specified, EFI_MEMORY_MORE_RELIABLE(0x10000)
-			attribute is added to range 0x100000000-0x180000000 and
-			0x10a0000000-0x1120000000.
-
-			If efi_fake_mem=8G@9G:0x40000 is specified, the
-			EFI_MEMORY_SP(0x40000) attribute is added to
-			range 0x240000000-0x43fffffff.
-
-			Using this parameter you can do debugging of EFI memmap
-			related features. For example, you can do debugging of
-			Address Range Mirroring feature even if your box
-			doesn't support it, or mark specific memory as
-			"soft reserved".
-
 	efivar_ssdt=	[EFI; X86] Name of an EFI variable that contains an SSDT
 			that is to be dynamically loaded by Linux. If there are
 			multiple variables with the same name but with different
arch/x86/Kconfig +0 -20
index 1d7122a1883e..0c31f65aeb1d 100644
@@ -2038,26 +2038,6 @@ config EFI_MIXED
 
 	  If unsure, say N.
 
-config EFI_FAKE_MEMMAP
-	bool "Enable EFI fake memory map"
-	depends on EFI
-	help
-	  Saying Y here will enable "efi_fake_mem" boot option.  By specifying
-	  this parameter, you can add arbitrary attribute to specific memory
-	  range by updating original (firmware provided) EFI memmap.  This is
-	  useful for debugging of EFI memmap related feature, e.g., Address
-	  Range Mirroring feature.
-
-config EFI_MAX_FAKE_MEM
-	int "maximum allowable number of ranges in efi_fake_mem boot option"
-	depends on EFI_FAKE_MEMMAP
-	range 1 128
-	default 8
-	help
-	  Maximum allowable number of ranges in efi_fake_mem boot option.
-	  Ranges can be set up to this value using comma-separated list.
-	  The default value is 8.
-
 config EFI_RUNTIME_MAP
 	bool "Export EFI runtime maps to sysfs" if EXPERT
 	depends on EFI
arch/x86/boot/compressed/kaslr.c +9 -34

80 lines not on this page · raw message

arch/x86/include/asm/efi.h +0 -15
index 481096177500..b3e4d999b913 100644
@@ -384,23 +384,8 @@ static inline void efi_reserve_boot_services(void)
 }
 #endif /* CONFIG_EFI */
 
-#ifdef CONFIG_EFI_FAKE_MEMMAP
-extern void __init efi_fake_memmap_early(void);
-extern void __init efi_fake_memmap(void);
-#else
-static inline void efi_fake_memmap_early(void)
-{
-}
-
-static inline void efi_fake_memmap(void)
-{
-}
-#endif
-
 extern int __init efi_memmap_alloc(unsigned int num_entries,
 				   struct efi_memory_map_data *data);
-extern void __efi_memmap_free(u64 phys, unsigned long size,
-			      unsigned long flags);
 
 extern int __init efi_memmap_install(struct efi_memory_map_data *data);
 extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
arch/x86/kernel/setup.c +0 -1
index 05c5aa951da7..282e8577ac7b 100644
@@ -995,7 +995,6 @@ void __init setup_arch(char **cmdline_p)
 	mem_encrypt_setup_arch();
 	cc_random_init();
 
-	efi_fake_memmap();
 	efi_find_mirror();
 	efi_esrt_init();
 	efi_mokvar_table_init();
arch/x86/platform/efi/efi.c +0 -2
index f090ec972d7b..88a96816de9a 100644
@@ -226,8 +226,6 @@ int __init efi_memblock_x86_reserve_range(void)
 	if (add_efi_memmap || do_efi_soft_reserve())
 		do_add_efi_memmap();
 
-	efi_fake_memmap_early();
-
 	WARN(efi.memmap.desc_version != 1,
 	     "Unexpected EFI_MEMORY_DESCRIPTOR version %ld",
 	     efi.memmap.desc_version);
arch/x86/platform/efi/fake_mem.c deleted +0 -197

197 lines not on this page · raw message

arch/x86/platform/efi/memmap.c +1 -0
index 6ed1935504b9..061b8ecc71a1 100644
@@ -30,6 +30,7 @@ static phys_addr_t __init __efi_memmap_alloc_late(unsigned long size)
 	return PFN_PHYS(page_to_pfn(p));
 }
 
+static
 void __init __efi_memmap_free(u64 phys, unsigned long size, unsigned long flags)
 {
 	if (flags & EFI_MEMMAP_MEMBLOCK) {
drivers/firmware/efi/libstub/x86-stub.c +1 -1
index 1983fd3bf392..68df27bd71c9 100644
@@ -781,7 +781,7 @@ static const char *cmdline_memmap_override;
 static efi_status_t parse_options(const char *cmdline)
 {
 	static const char opts[][14] = {
-		"mem=", "memmap=", "efi_fake_mem=", "hugepages="
+		"mem=", "memmap=", "hugepages="
 	};
 
 	for (int i = 0; i < ARRAY_SIZE(opts); i++) {
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 26 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Between kexec and confidential VM support, handling the EFI memory maps correctly on x86 is already proving to be rather difficult (as opposed to other EFI architectures which manage to never modify the EFI memory map to begin with)

EFI fake memory map support is essentially a development hack (for testing new support for the 'special purpose' and 'more reliable' EFI memory attributes) that leaked into production code. The regions marked in this manner are not actually recognized as such by the firmware itself or the EFI stub (and never have), and marking memory as 'more reliable' seems rather futile if the underlying memory is just ordinary RAM.

Marking memory as 'special purpose' in this way is also dubious, but may be in use in production code nonetheless. However, the same should be achievable by using the memmap= command line option with the ! operator.

EFI fake memmap support is not enabled by any of the major distros (Debian, Fedora, SUSE, Ubuntu) and does not exist on other architectures, so let's drop support for it.

Cc Taku Izumi <[email protected]>
Cc Dan Williams <[email protected]>
Quoted 11 lines
---
 Documentation/admin-guide/kernel-parameters.txt |  21 ---
 arch/x86/Kconfig                                |  20 --
 arch/x86/boot/compressed/kaslr.c                |  43 +----
 arch/x86/include/asm/efi.h                      |  15 --
 arch/x86/kernel/setup.c                         |   1 -
 arch/x86/platform/efi/efi.c                     |   2 -
 arch/x86/platform/efi/fake_mem.c                | 197 --------------------
 arch/x86/platform/efi/memmap.c                  |   1 +
 drivers/firmware/efi/libstub/x86-stub.c         |   2 +-
 9 files changed, 11 insertions(+), 291 deletions(-)

I obviously like this:

I don't see the author or anyone else objecting, I guess queue it?

Or if you feel like you wanna give folks a full cycle, you could queue it for the next MW...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#2 lore raw
Quoted 40 lines · Borislav Petkov
Quoted 26 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Between kexec and confidential VM support, handling the EFI memory maps correctly on x86 is already proving to be rather difficult (as opposed to other EFI architectures which manage to never modify the EFI memory map to begin with)

EFI fake memory map support is essentially a development hack (for testing new support for the 'special purpose' and 'more reliable' EFI memory attributes) that leaked into production code. The regions marked in this manner are not actually recognized as such by the firmware itself or the EFI stub (and never have), and marking memory as 'more reliable' seems rather futile if the underlying memory is just ordinary RAM.

Marking memory as 'special purpose' in this way is also dubious, but may be in use in production code nonetheless. However, the same should be achievable by using the memmap= command line option with the ! operator.

EFI fake memmap support is not enabled by any of the major distros (Debian, Fedora, SUSE, Ubuntu) and does not exist on other architectures, so let's drop support for it.

Cc Taku Izumi <[email protected]>
Cc Dan Williams <[email protected]>
Quoted 11 lines
---
 Documentation/admin-guide/kernel-parameters.txt |  21 ---
 arch/x86/Kconfig                                |  20 --
 arch/x86/boot/compressed/kaslr.c                |  43 +----
 arch/x86/include/asm/efi.h                      |  15 --
 arch/x86/kernel/setup.c                         |   1 -
 arch/x86/platform/efi/efi.c                     |   2 -
 arch/x86/platform/efi/fake_mem.c                | 197 --------------------
 arch/x86/platform/efi/memmap.c                  |   1 +
 drivers/firmware/efi/libstub/x86-stub.c         |   2 +-
 9 files changed, 11 insertions(+), 291 deletions(-)
Quoted 6 lines

I obviously like this:

I don't see the author or anyone else objecting, I guess queue it?

Thanks.

Quoted 3 lines

Or if you feel like you wanna give folks a full cycle, you could queue it for the next MW...

It's been in -next for ~10 days so I might just send it for the next cycle. We can always revert it if something gets broken.

#3 lore raw
In reply to Ard Biesheuvel

[ add Tony who may care about the more-reliable removal ]

Quoted 15 lines · Ard Biesheuvel

From: Ard Biesheuvel <[email protected]>

Between kexec and confidential VM support, handling the EFI memory maps correctly on x86 is already proving to be rather difficult (as opposed to other EFI architectures which manage to never modify the EFI memory map to begin with)

EFI fake memory map support is essentially a development hack (for testing new support for the 'special purpose' and 'more reliable' EFI memory attributes) that leaked into production code. The regions marked in this manner are not actually recognized as such by the firmware itself or the EFI stub (and never have), and marking memory as 'more reliable' seems rather futile if the underlying memory is just ordinary RAM.

Quoted 3 lines

Marking memory as 'special purpose' in this way is also dubious, but may be in use in production code nonetheless. However, the same should be achievable by using the memmap= command line option with the ! operator.

Ugh, sorry I missed this earlier. I only now just saw this bubble up in my inbox from the reply from Boris, but I have concerns with this removal.

The problem is that what is and is not "special purpose" is a platform *and* use case policy. BIOS can only make a rough guess at platform manufacturing time, and certainly does not have use case information.

One of the main reasons to prefer efi_fake_mem over memmap= is all of the end user hand holding needed to correct broken usage of memmap=

https://nvdimm.wiki.kernel.org/how_to_choose_the_correct_memmap_kernel_parameter_for_pmem_on_your_system

...if anything I have been wanting to rip out memmap= more than efi_fake_mem just to cut down on the PEBKAC reports from memmap= users from the PMEM days. Those reports only died down because Optane died, but CXL is here now to revive that "fun".

However, that said, maybe the safety properties of efi_fake_mem=nn@ss:0x40000 can be brought over to memmap=. The main property that protects end users is that the attribute only applies to existing EFI Conventional Memory ranges. So unlike memmap= that blindly replaces the memory map whether it makes sense or not, efi_fake_mem= would fail gracefully if the attribute was applied to nonsense ranges.

Quoted 3 lines

EFI fake memmap support is not enabled by any of the major distros (Debian, Fedora, SUSE, Ubuntu) and does not exist on other architectures, so let's drop support for it.

I think part of the problem here is that platform with differentiated memory, (PMEM, HBM, CXL, etc...) have remained somewhat boutique since the introduction of this facility. As they become more ubiquitous, as trends seem to indicate, I think the frustration with BIOS policy may become more widespread.

So we can remove it and see who screams, but we may want to put a work-alike safe option in memmap= first just to keep our own sanity.

#4 lore raw
Quoted 1 line · Dan Williams

[ add Tony who may care about the more-reliable removal ]

I don't think I care about removal the fake options. I have had systems that support real "more-reliable" memory for many years.

-Tony

Acked-by
#5 lore raw
Quoted 5 lines · Tony Luck
Quoted 1 line · Dan Williams

[ add Tony who may care about the more-reliable removal ]

I don't think I care about removal the fake options. I have had systems that support real "more-reliable" memory for many years.

Ok, lets remove it and see what happens. I recall now that the major policy knob that users may care about is efi=nosoftreserve, and the ability to specify efi_fake_mem for testing purposes can move to memmap= on the assumption that kernel-devs are much less likely to specify broken settings, or at least can pick up the pieces.

Ard, you can add:

maintainer
#6 lore raw
Quoted 14 lines · Dan Williams
Quoted 5 lines · Tony Luck
Quoted 1 line · Dan Williams

[ add Tony who may care about the more-reliable removal ]

I don't think I care about removal the fake options. I have had systems that support real "more-reliable" memory for many years.

Ok, lets remove it and see what happens. I recall now that the major policy knob that users may care about is efi=nosoftreserve, and the ability to specify efi_fake_mem for testing purposes can move to memmap= on the assumption that kernel-devs are much less likely to specify broken settings, or at least can pick up the pieces.

Quoted 4 lines

Ard, you can add:

Thanks all.