linux/drivers/firmware/efi/libstub
Ard Biesheuvel ba69e0750b efi: Avoid cold plugged memory for placing the kernel
UEFI 2.11 introduced EFI_MEMORY_HOT_PLUGGABLE to annotate system memory
regions that are 'cold plugged' at boot, i.e., hot pluggable memory that
is available from early boot, and described as system RAM by the
firmware.

Existing loaders and EFI applications running in the boot context will
happily use this memory for allocating data structures that cannot be
freed or moved at runtime, and this prevents the memory from being
unplugged. Going forward, the new EFI_MEMORY_HOT_PLUGGABLE attribute
should be tested, and memory annotated as such should be avoided for
such allocations.

In the EFI stub, there are a couple of occurrences where, instead of the
high-level AllocatePages() UEFI boot service, a low-level code sequence
is used that traverses the EFI memory map and carves out the requested
number of pages from a free region. This is needed, e.g., for allocating
as low as possible, or for allocating pages at random.

While AllocatePages() should presumably avoid special purpose memory and
cold plugged regions, this manual approach needs to incorporate this
logic itself, in order to prevent the kernel itself from ending up in a
hot unpluggable region, preventing it from being unplugged.

So add the EFI_MEMORY_HOTPLUGGABLE macro definition, and check for it
where appropriate.

Cc: stable@vger.kernel.org
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-02-04 14:08:22 +01:00
..
alignedmem.c efi/libstub: Add one kernel-doc comment 2024-01-30 21:44:21 +01:00
arm32-stub.c
arm64-stub.c arm64/efistub: Clean up KASLR logic 2024-07-10 12:22:46 +02:00
arm64.c efistub/smbios: Simplify SMBIOS enumeration API 2024-07-02 00:42:04 +02:00
bitmap.c
efi-stub-entry.c efi: move screen_info into efi init code 2023-10-17 16:33:39 +02:00
efi-stub-helper.c efi/libstub: Use __free() helper for pool deallocations 2025-01-14 08:35:27 +01:00
efi-stub.c efi/libstub: Use __free() helper for pool deallocations 2025-01-14 08:35:27 +01:00
efistub.h efi/libstub: Simplify GOP handling code 2025-01-14 08:35:08 +01:00
fdt.c efi: libstub: only free priv.runtime_map when allocated 2024-04-29 17:47:32 +02:00
file.c efi/libstub: Take command line overrides into account for loaded files 2024-11-17 08:54:01 +01:00
find.c
gop.c efi/libstub: Refactor and clean up GOP resolution picker code 2025-01-14 08:35:27 +01:00
intrinsics.c
kaslr.c efi/libstub: Use cleanup helpers for freeing copies of the memory map 2025-01-14 08:35:27 +01:00
loongarch-stub.c efi/loongarch: Directly position the loaded image file 2023-12-19 11:16:37 +01:00
loongarch-stub.h efi/loongarch: Directly position the loaded image file 2023-12-19 11:16:37 +01:00
loongarch.c LoongArch: Add writecombine support for DMW-based ioremap() 2024-07-20 22:40:59 +08:00
Makefile efi: libstub: Use '-std=gnu11' to fix build with GCC 15 2025-01-22 12:57:45 +01:00
Makefile.zboot efi/zboot: Limit compression options to GZIP and ZSTD 2024-12-06 16:59:56 +01:00
mem.c efi/libstub: Use cleanup helpers for freeing copies of the memory map 2025-01-14 08:35:27 +01:00
pci.c efi/libstub: Simplify PCI I/O handle buffer traversal 2025-01-14 08:35:27 +01:00
printk.c
random.c
randomalloc.c efi: Avoid cold plugged memory for placing the kernel 2025-02-04 14:08:22 +01:00
relocate.c efi: Avoid cold plugged memory for placing the kernel 2025-02-04 14:08:22 +01:00
riscv-stub.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
riscv.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
screen_info.c efi/libstub: Zero initialize heap allocated struct screen_info 2024-07-17 22:51:20 +02:00
secureboot.c
skip_spaces.c
smbios.c x86/efistub: Enable SMBIOS protocol handling for x86 2024-07-08 10:17:44 +02:00
string.c
systable.c
tpm.c libstub,tpm: do not ignore failure case when reading final event log 2024-10-15 20:27:30 +02:00
unaccepted_memory.c mm: rework accept memory helpers 2024-09-01 20:26:07 -07:00
vsprintf.c
x86-5lvl.c x86/asm: Always set A (accessed) flag in GDT descriptors 2023-12-20 10:57:51 +01:00
x86-stub.c efi/libstub: Use __free() helper for pool deallocations 2025-01-14 08:35:27 +01:00
x86-stub.h x86/efistub: Give up if memory attribute protocol returns an error 2024-01-26 16:58:19 +01:00
zboot-header.S
zboot.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
zboot.lds efi/libstub: zboot.lds: Discard .discard sections 2024-05-23 09:02:39 +02:00