Skip to contentSkip to conversation

x86/efi: Handle EFI_UNACCEPTED_MEMORY in do_add_efi_memmap()

PATCH New Kiryl Shutsemau (Meta) 1 participant 1 message Nov 25

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

PATCH 1/1 x86/efi: Handle EFI_UNACCEPTED_MEMORY in do_add_efi_memmap()

The EFI stub reports unaccepted memory to the kernel as E820 RAM. do_add_efi_memmap() has no case for EFI_UNACCEPTED_MEMORY and adds the same range again as E820_TYPE_RESERVED. e820__update_table() resolves the overlap in favour of the reserved type, so the kernel never uses the range.

do_add_efi_memmap() runs when soft reservation is enabled and the firmware marks any conventional memory EFI_MEMORY_SP; that takes no command-line option. It also runs with the add_efi_memmap boot parameter. A TDX or SEV-SNP guest booted either way loses the memory the firmware left unaccepted, and it does not show up in MemTotal.

Add unaccepted memory as RAM, as the stub does. Without CONFIG_UNACCEPTED_MEMORY the kernel cannot accept it, so keep it reserved there.

Fixes 745e3ed85f71 ("efi/libstub: Implement support for unaccepted memory")

---
Build-tested only, with and without CONFIG_UNACCEPTED_MEMORY.

 arch/x86/platform/efi/efi.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/x86/platform/efi/efi.c +6 -0
index 5eb96c17883e..f03d5e984f2f 100644
@@ -150,6 +150,12 @@ static void __init do_add_efi_memmap(void)
 		case EFI_PERSISTENT_MEMORY:
 			e820_type = E820_TYPE_PMEM;
 			break;
+		case EFI_UNACCEPTED_MEMORY:
+			if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY))
+				e820_type = E820_TYPE_RAM;
+			else
+				e820_type = E820_TYPE_RESERVED;
+			break;
 		default:
 			/*
 			 * EFI_RESERVED_TYPE EFI_RUNTIME_SERVICES_CODE

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.54.0