* [PATCH 0/7] x86/efi: Prepwork for memory map cleanup
@ 2026-04-10 7:59 Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 1/7] x86/efi: Omit redundant kernel image overlap check Ard Biesheuvel
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-04-10 7:59 UTC (permalink / raw)
To: linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel
From: Ard Biesheuvel <ardb@kernel.org>
This is a follow-up to [0], which had some fundamental issues, as
spotted by Sashiko [1]. Disentangling the EFI memory map mess on x86
needs a rethink, but some of the prepwork is still worthwhile, and so it
is presented here separately.
The end goal is still the same, i.e., to remove the need for the x86
boot code to modify the EFI memory map, or reallocate/copy/remap it
numerous times.
[0] https://lore.kernel.org/all/20260319090529.1091660-21-ardb+git@google.com/
[1] https://sashiko.dev/#/patchset/20260319090529.1091660-21-ardb%2Bgit%40google.com
Ard Biesheuvel (7):
x86/efi: Omit redundant kernel image overlap check
x86/efi: Drop redundant EFI_PARAVIRT check
x86/efi: Only merge EFI memory map entries on 32-bit systems
x86/efi: Defer sub-1M check from unmap to free stage
x86/efi: Simplify real mode trampoline allocation quirk
x86/efi: Unmap kernel-reserved boot regions from EFI page tables
x86/efi: Drop EFI_MEMORY_RUNTIME check from __ioremap_check_other()
arch/x86/include/asm/efi.h | 6 ++
arch/x86/mm/ioremap.c | 7 +-
arch/x86/platform/efi/efi.c | 39 +---------
arch/x86/platform/efi/efi_32.c | 31 ++++++++
arch/x86/platform/efi/quirks.c | 78 +++++++-------------
5 files changed, 69 insertions(+), 92 deletions(-)
base-commit: 259e3e6f9382b6a9fe570313d97c59a233f7d72f
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/7] x86/efi: Omit redundant kernel image overlap check
2026-04-10 7:59 [PATCH 0/7] x86/efi: Prepwork for memory map cleanup Ard Biesheuvel
@ 2026-04-10 7:59 ` Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 2/7] x86/efi: Drop redundant EFI_PARAVIRT check Ard Biesheuvel
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-04-10 7:59 UTC (permalink / raw)
To: linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel
From: Ard Biesheuvel <ardb@kernel.org>
The physical region covering the kernel's executable image is
memblock_reserve()'d in early_mem_reserve(), and so it is guaranteed not
to intersect with the regions passed to can_free_region(). So remove the
pointless overlap check.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/platform/efi/quirks.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 35caa5746115..05ef1b06c25d 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -305,16 +305,11 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size)
* can free regions in efi_free_boot_services().
*
* Use this function to ensure we do not free regions owned by somebody
- * else. We must only reserve (and then free) regions:
- *
- * - Not within any part of the kernel
- * - Not the BIOS reserved area (E820_TYPE_RESERVED, E820_TYPE_NVS, etc)
+ * else. We must only reserve (and then free) regions that do not intersect
+ * with the BIOS reserved area (E820_TYPE_RESERVED, E820_TYPE_NVS, etc)
*/
static __init bool can_free_region(u64 start, u64 size)
{
- if (start + size > __pa_symbol(_text) && start <= __pa_symbol(_end))
- return false;
-
if (!e820__mapped_all(start, start+size, E820_TYPE_RAM))
return false;
@@ -343,10 +338,8 @@ void __init efi_reserve_boot_services(void)
* Because the following memblock_reserve() is paired
* with free_reserved_area() for this region in
* efi_free_boot_services(), we must be extremely
- * careful not to reserve, and subsequently free,
- * critical regions of memory (like the kernel image) or
- * those regions that somebody else has already
- * reserved.
+ * careful not to reserve, and subsequently free, critical
+ * regions of memory that somebody else has already reserved.
*
* A good example of a critical region that must not be
* freed is page zero (first 4Kb of memory), which may
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/7] x86/efi: Drop redundant EFI_PARAVIRT check
2026-04-10 7:59 [PATCH 0/7] x86/efi: Prepwork for memory map cleanup Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 1/7] x86/efi: Omit redundant kernel image overlap check Ard Biesheuvel
@ 2026-04-10 7:59 ` Ard Biesheuvel
2026-04-10 11:36 ` Thomas Huth
2026-04-10 7:59 ` [PATCH 3/7] x86/efi: Only merge EFI memory map entries on 32-bit systems Ard Biesheuvel
` (4 subsequent siblings)
6 siblings, 1 reply; 9+ messages in thread
From: Ard Biesheuvel @ 2026-04-10 7:59 UTC (permalink / raw)
To: linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel
From: Ard Biesheuvel <ardb@kernel.org>
efi_memblock_x86_reserve_range() exits early if EFI_PARAVIRT is set, so
there is no point in checking it a second time further down.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/platform/efi/efi.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index d84c6020dda1..b60f8454a1ec 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -211,11 +211,9 @@ int __init efi_memblock_x86_reserve_range(void)
data.desc_size = e->efi_memdesc_size;
data.desc_version = e->efi_memdesc_version;
- if (!efi_enabled(EFI_PARAVIRT)) {
- rv = efi_memmap_init_early(&data);
- if (rv)
- return rv;
- }
+ rv = efi_memmap_init_early(&data);
+ if (rv)
+ return rv;
if (add_efi_memmap || do_efi_soft_reserve())
do_add_efi_memmap();
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/7] x86/efi: Only merge EFI memory map entries on 32-bit systems
2026-04-10 7:59 [PATCH 0/7] x86/efi: Prepwork for memory map cleanup Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 1/7] x86/efi: Omit redundant kernel image overlap check Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 2/7] x86/efi: Drop redundant EFI_PARAVIRT check Ard Biesheuvel
@ 2026-04-10 7:59 ` Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 4/7] x86/efi: Defer sub-1M check from unmap to free stage Ard Biesheuvel
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-04-10 7:59 UTC (permalink / raw)
To: linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel
From: Ard Biesheuvel <ardb@kernel.org>
Commit
202f9d0a4180 ("x86, efi: Merge contiguous memory regions of the same type and attribute")
introduced a pass over the EFI memory map, ensuring that contiguous
regions of the same type and attribute are coalesced into a single
entry. This was needed because relative references may exist between
those regions, and so the virtual remapping needs to preserve the
relative placement of these regions. This virtual remapping was based on
ioremap() at the time, which does not guarantee that adjacent physical
addresses are mapped adjacently in the virtual space.
Commit
d2f7cbe7b26a ("x86/efi: Runtime services virtual mapping")
introduced a new strategy for virtually remapping the EFI runtime
services, which is now the only remaining one, and commit
a5caa209ba9c ("x86/efi: Fix boot crash by mapping EFI memmap entries bottom-up at runtime, instead of top-down")
tweaked the logic to ensure that the relative offset of adjacent regions
of any type is preserved on 64-bit systems, by reversing the order in
which the EFI memory map is traversed when choosing the virtual
placement.
This means that merging regions is no longer needed on 64-bit, given
that the relative placement of adjacent regions is guaranteed to be
preserved in the virtual space. So make this hack 32-bit only.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/include/asm/efi.h | 6 ++++
arch/x86/platform/efi/efi.c | 31 --------------------
arch/x86/platform/efi/efi_32.c | 31 ++++++++++++++++++++
3 files changed, 37 insertions(+), 31 deletions(-)
diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 51b4cdbea061..e397ea61c9f8 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -143,6 +143,12 @@ extern void efi_unmap_boot_services(void);
void arch_efi_call_virt_setup(void);
void arch_efi_call_virt_teardown(void);
+#ifdef CONFIG_X86_32
+void efi_merge_regions(void);
+#else
+static inline void efi_merge_regions(void) {}
+#endif
+
extern u64 efi_setup;
#ifdef CONFIG_EFI
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index b60f8454a1ec..2330d028a889 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -502,37 +502,6 @@ void __init efi_init(void)
efi_print_memmap();
}
-/* Merge contiguous regions of the same type and attribute */
-static void __init efi_merge_regions(void)
-{
- efi_memory_desc_t *md, *prev_md = NULL;
-
- for_each_efi_memory_desc(md) {
- u64 prev_size;
-
- if (!prev_md) {
- prev_md = md;
- continue;
- }
-
- if (prev_md->type != md->type ||
- prev_md->attribute != md->attribute) {
- prev_md = md;
- continue;
- }
-
- prev_size = prev_md->num_pages << EFI_PAGE_SHIFT;
-
- if (md->phys_addr == (prev_md->phys_addr + prev_size)) {
- prev_md->num_pages += md->num_pages;
- md->type = EFI_RESERVED_TYPE;
- md->attribute = 0;
- continue;
- }
- prev_md = md;
- }
-}
-
static void *realloc_pages(void *old_memmap, int old_shift)
{
void *ret;
diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
index b2cc7b4552a1..886ede4117b5 100644
--- a/arch/x86/platform/efi/efi_32.c
+++ b/arch/x86/platform/efi/efi_32.c
@@ -152,3 +152,34 @@ void arch_efi_call_virt_teardown(void)
firmware_restrict_branch_speculation_end();
efi_fpu_end();
}
+
+/* Merge contiguous regions of the same type and attribute */
+void __init efi_merge_regions(void)
+{
+ efi_memory_desc_t *md, *prev_md = NULL;
+
+ for_each_efi_memory_desc(md) {
+ u64 prev_size;
+
+ if (!prev_md) {
+ prev_md = md;
+ continue;
+ }
+
+ if (prev_md->type != md->type ||
+ prev_md->attribute != md->attribute) {
+ prev_md = md;
+ continue;
+ }
+
+ prev_size = prev_md->num_pages << EFI_PAGE_SHIFT;
+
+ if (md->phys_addr == (prev_md->phys_addr + prev_size)) {
+ prev_md->num_pages += md->num_pages;
+ md->type = EFI_RESERVED_TYPE;
+ md->attribute = 0;
+ continue;
+ }
+ prev_md = md;
+ }
+}
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/7] x86/efi: Defer sub-1M check from unmap to free stage
2026-04-10 7:59 [PATCH 0/7] x86/efi: Prepwork for memory map cleanup Ard Biesheuvel
` (2 preceding siblings ...)
2026-04-10 7:59 ` [PATCH 3/7] x86/efi: Only merge EFI memory map entries on 32-bit systems Ard Biesheuvel
@ 2026-04-10 7:59 ` Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 5/7] x86/efi: Simplify real mode trampoline allocation quirk Ard Biesheuvel
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-04-10 7:59 UTC (permalink / raw)
To: linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel
From: Ard Biesheuvel <ardb@kernel.org>
As a first step towards moving the free logic to a later stage
altogether, and only keeping the unmap and the realmode trampoline hack
during the early stage of freeing the boot service code and data
regions, move the logic that avoids freeing memory below 1M to the later
stage.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/platform/efi/quirks.c | 28 +++++++++-----------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 05ef1b06c25d..999c9277c49c 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -468,18 +468,6 @@ void __init efi_unmap_boot_services(void)
size -= rm_size;
}
- /*
- * Don't free memory under 1M for two reasons:
- * - BIOS might clobber it
- * - Crash kernel needs it to be reserved
- */
- if (start + size < SZ_1M)
- continue;
- if (start < SZ_1M) {
- size -= (SZ_1M - start);
- start = SZ_1M;
- }
-
/*
* With CONFIG_DEFERRED_STRUCT_PAGE_INIT parts of the memory
* map are still not initialized and we can't reliably free
@@ -537,12 +525,20 @@ static int __init efi_free_boot_services(void)
if (!ranges_to_free)
return 0;
- while (range->start) {
- void *start = phys_to_virt(range->start);
+ while (range->start || range->end) {
+ /*
+ * Don't free memory under 1M for two reasons:
+ * - BIOS might clobber it
+ * - Crash kernel needs it to be reserved
+ */
+ unsigned long s = max(range->start, SZ_1M);
+ void *start = phys_to_virt(s);
void *end = phys_to_virt(range->end);
- free_reserved_area(start, end, -1, NULL);
- freed += (end - start);
+ if (start < end) {
+ free_reserved_area(start, end, -1, NULL);
+ freed += (end - start);
+ }
range++;
}
kfree(ranges_to_free);
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/7] x86/efi: Simplify real mode trampoline allocation quirk
2026-04-10 7:59 [PATCH 0/7] x86/efi: Prepwork for memory map cleanup Ard Biesheuvel
` (3 preceding siblings ...)
2026-04-10 7:59 ` [PATCH 4/7] x86/efi: Defer sub-1M check from unmap to free stage Ard Biesheuvel
@ 2026-04-10 7:59 ` Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 6/7] x86/efi: Unmap kernel-reserved boot regions from EFI page tables Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 7/7] x86/efi: Drop EFI_MEMORY_RUNTIME check from __ioremap_check_other() Ard Biesheuvel
6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-04-10 7:59 UTC (permalink / raw)
To: linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel
From: Ard Biesheuvel <ardb@kernel.org>
To work around a common bug in EFI firmware for x86 systems, Linux
reserves all EFI boot services code and data regions until after it has
invoked the SetVirtualAddressMap() EFI runtime service. This is needed
because those regions may still be accessed by the firmware during that
call, even though the EFI spec says that they shouldn't.
This includes any boot services data regions below 1M, which might mean
that by the time the real mode trampoline is being allocated, all memory
below 1M is already exhausted.
Commit
5bc653b73182 ("x86/efi: Allocate a trampoline if needed in efi_free_boot_services()")
added a quirk to detect this condition, and to make another attempt at
allocating the real mode trampoline when freeing those boot services
regions again. This is a rather crude hack, which gets in the way of
cleanup work on the EFI/x86 memory map handling code.
Given that
- the real mode trampoline is normally allocated soon after all EFI boot
services regions are reserved temporarily,
- this allocation logic marks all memory below 1M as reserved,
- the trampoline memory is not actually populated until an early
initcall,
there is actually no need to reserve any boot services regions below 1M,
even if they are mapped into the EFI page tables during the call to
SetVirtualAddressMap(). So cap the lower bound of the reserved regions
to 1M, and fix up the size accordingly when making the reservation. This
allows the additional quirk to be dropped entirely.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/platform/efi/quirks.c | 29 ++++----------------
1 file changed, 6 insertions(+), 23 deletions(-)
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index 999c9277c49c..ee906c0c46c1 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -324,10 +324,14 @@ void __init efi_reserve_boot_services(void)
return;
for_each_efi_memory_desc(md) {
- u64 start = md->phys_addr;
- u64 size = md->num_pages << EFI_PAGE_SHIFT;
+ u64 start = max(md->phys_addr, SZ_1M);
+ u64 end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
+ u64 size = end - start;
bool already_reserved;
+ if (end <= start)
+ continue;
+
if (md->type != EFI_BOOT_SERVICES_CODE &&
md->type != EFI_BOOT_SERVICES_DATA)
continue;
@@ -427,7 +431,6 @@ void __init efi_unmap_boot_services(void)
for_each_efi_memory_desc(md) {
unsigned long long start = md->phys_addr;
unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
- size_t rm_size;
if (md->type != EFI_BOOT_SERVICES_CODE &&
md->type != EFI_BOOT_SERVICES_DATA) {
@@ -448,26 +451,6 @@ void __init efi_unmap_boot_services(void)
*/
efi_unmap_pages(md);
- /*
- * Nasty quirk: if all sub-1MB memory is used for boot
- * services, we can get here without having allocated the
- * real mode trampoline. It's too late to hand boot services
- * memory back to the memblock allocator, so instead
- * try to manually allocate the trampoline if needed.
- *
- * I've seen this on a Dell XPS 13 9350 with firmware
- * 1.4.4 with SGX enabled booting Linux via Fedora 24's
- * grub2-efi on a hard disk. (And no, I don't know why
- * this happened, but Linux should still try to boot rather
- * panicking early.)
- */
- rm_size = real_mode_size_needed();
- if (rm_size && (start + rm_size) < (1<<20) && size >= rm_size) {
- set_real_mode_mem(start);
- start += rm_size;
- size -= rm_size;
- }
-
/*
* With CONFIG_DEFERRED_STRUCT_PAGE_INIT parts of the memory
* map are still not initialized and we can't reliably free
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/7] x86/efi: Unmap kernel-reserved boot regions from EFI page tables
2026-04-10 7:59 [PATCH 0/7] x86/efi: Prepwork for memory map cleanup Ard Biesheuvel
` (4 preceding siblings ...)
2026-04-10 7:59 ` [PATCH 5/7] x86/efi: Simplify real mode trampoline allocation quirk Ard Biesheuvel
@ 2026-04-10 7:59 ` Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 7/7] x86/efi: Drop EFI_MEMORY_RUNTIME check from __ioremap_check_other() Ard Biesheuvel
6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-04-10 7:59 UTC (permalink / raw)
To: linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel
From: Ard Biesheuvel <ardb@kernel.org>
Currently, the logic that unmaps boot services code and data regions
that were mapped temporarily to work around firmware bugs disregards
regions that have been marked as EFI_MEMORY_RUNTIME. However, such
regions only have significance to the OS, and there is no reason to
retain the mapping in the EFI page tables, given that the runtime
firmware must never touch those regions.
So pull the unmap forward.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/platform/efi/quirks.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index ee906c0c46c1..929ee71a140c 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -438,12 +438,6 @@ void __init efi_unmap_boot_services(void)
continue;
}
- /* Do not free, someone else owns it: */
- if (md->attribute & EFI_MEMORY_RUNTIME) {
- num_entries++;
- continue;
- }
-
/*
* Before calling set_virtual_address_map(), EFI boot services
* code/data regions were mapped as a quirk for buggy firmware.
@@ -451,6 +445,12 @@ void __init efi_unmap_boot_services(void)
*/
efi_unmap_pages(md);
+ /* Do not free, someone else owns it: */
+ if (md->attribute & EFI_MEMORY_RUNTIME) {
+ num_entries++;
+ continue;
+ }
+
/*
* With CONFIG_DEFERRED_STRUCT_PAGE_INIT parts of the memory
* map are still not initialized and we can't reliably free
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/7] x86/efi: Drop EFI_MEMORY_RUNTIME check from __ioremap_check_other()
2026-04-10 7:59 [PATCH 0/7] x86/efi: Prepwork for memory map cleanup Ard Biesheuvel
` (5 preceding siblings ...)
2026-04-10 7:59 ` [PATCH 6/7] x86/efi: Unmap kernel-reserved boot regions from EFI page tables Ard Biesheuvel
@ 2026-04-10 7:59 ` Ard Biesheuvel
6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-04-10 7:59 UTC (permalink / raw)
To: linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel, Tom Lendacky
From: Ard Biesheuvel <ardb@kernel.org>
__ioremap_check_other() is called when memremap() is used on memory that
turns out to be reserved. This may be the case for ESRT or MOK tables
that are reserved via efi_mem_reserve(), in which case they will be
covered by EfiBootServicesData entries in the EFI memory map.
Such entries are created with the EFI_MEMORY_RUNTIME attribute set, to
distinguish them from EfiBootServicesData entries that were reserved
only temporarily, in order to work around firmware bugs.
However, given that
a) __ioremap_check_other() is only called for memory that could not be
mapped using try_ram_remap(),
b) on x86, the EFI memory map only retains EfiBootServicesData entries that
cover a permanent reservation,
the EFI_MEMORY_RUNTIME check is redundant, and can be dropped.
This removes the need to set this attribute in the first place, which is
desirable as it results in considerable complexity in managing the EFI
memory map on x86. This will be addressed in follow-up work.
While at it, use switch() rather than if() to avoid multiple calls to
efi_mem_type(), which is backed by a hypervisor call in some cases.
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/mm/ioremap.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 12c8180ca1ba..5be11e031b8e 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -124,10 +124,11 @@ static void __ioremap_check_other(resource_size_t addr, struct ioremap_desc *des
if (!IS_ENABLED(CONFIG_EFI))
return;
- if (efi_mem_type(addr) == EFI_RUNTIME_SERVICES_DATA ||
- (efi_mem_type(addr) == EFI_BOOT_SERVICES_DATA &&
- efi_mem_attributes(addr) & EFI_MEMORY_RUNTIME))
+ switch (efi_mem_type(addr)) {
+ case EFI_RUNTIME_SERVICES_DATA:
+ case EFI_BOOT_SERVICES_DATA:
desc->flags |= IORES_MAP_ENCRYPTED;
+ }
}
static int __ioremap_collect_map_flags(struct resource *res, void *arg)
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/7] x86/efi: Drop redundant EFI_PARAVIRT check
2026-04-10 7:59 ` [PATCH 2/7] x86/efi: Drop redundant EFI_PARAVIRT check Ard Biesheuvel
@ 2026-04-10 11:36 ` Thomas Huth
0 siblings, 0 replies; 9+ messages in thread
From: Thomas Huth @ 2026-04-10 11:36 UTC (permalink / raw)
To: Ard Biesheuvel, linux-efi; +Cc: linux-kernel, x86, Ard Biesheuvel
On 10/04/2026 09.59, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
>
> efi_memblock_x86_reserve_range() exits early if EFI_PARAVIRT is set, so
> there is no point in checking it a second time further down.
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> arch/x86/platform/efi/efi.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
> index d84c6020dda1..b60f8454a1ec 100644
> --- a/arch/x86/platform/efi/efi.c
> +++ b/arch/x86/platform/efi/efi.c
> @@ -211,11 +211,9 @@ int __init efi_memblock_x86_reserve_range(void)
> data.desc_size = e->efi_memdesc_size;
> data.desc_version = e->efi_memdesc_version;
>
> - if (!efi_enabled(EFI_PARAVIRT)) {
> - rv = efi_memmap_init_early(&data);
> - if (rv)
> - return rv;
> - }
> + rv = efi_memmap_init_early(&data);
> + if (rv)
> + return rv;
Maybe add:
Fixes: d85e3e3494078 ("efi: xen: Set EFI_PARAVIRT for Xen dom0 boot on all
architectures")
?
Anyway,
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-04-10 11:36 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-10 7:59 [PATCH 0/7] x86/efi: Prepwork for memory map cleanup Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 1/7] x86/efi: Omit redundant kernel image overlap check Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 2/7] x86/efi: Drop redundant EFI_PARAVIRT check Ard Biesheuvel
2026-04-10 11:36 ` Thomas Huth
2026-04-10 7:59 ` [PATCH 3/7] x86/efi: Only merge EFI memory map entries on 32-bit systems Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 4/7] x86/efi: Defer sub-1M check from unmap to free stage Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 5/7] x86/efi: Simplify real mode trampoline allocation quirk Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 6/7] x86/efi: Unmap kernel-reserved boot regions from EFI page tables Ard Biesheuvel
2026-04-10 7:59 ` [PATCH 7/7] x86/efi: Drop EFI_MEMORY_RUNTIME check from __ioremap_check_other() Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox