In order to permit the ESRT to be used when doing pseudo-EFI boot without a EFI memory map, e.g., when booting inside a Xen dom0 on x86, make the sanity checks optional based on whether the memory map is available. If additional validation is needed, it is up to the Xen EFI glue code to implement this in its xen_efi_config_table_is_valid() helper, or provide a EFI memory map like it does on other architectures. Co-developed-by: Demi Marie Obenour <demi@xxxxxxxxxxxxxxxxxxxxxx> Signed-off-by: Demi Marie Obenour <demi@xxxxxxxxxxxxxxxxxxxxxx> Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx> --- arch/x86/platform/efi/quirks.c | 3 + drivers/firmware/efi/esrt.c | 61 +++++++++++--------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index b0b848d6933a..9307be2f4afa 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -250,6 +250,9 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size) int num_entries; void *new; + if (!efi_enabled(EFI_MEMMAP)) + return; + if (efi_mem_desc_lookup(addr, &md) || md.type != EFI_BOOT_SERVICES_DATA) { pr_err("Failed to lookup EFI memory descriptor for %pa\n", &addr); diff --git a/drivers/firmware/efi/esrt.c b/drivers/firmware/efi/esrt.c index 2a2f52b017e7..adb31fba45ae 100644 --- a/drivers/firmware/efi/esrt.c +++ b/drivers/firmware/efi/esrt.c @@ -243,40 +243,45 @@ void __init efi_esrt_init(void) void *va; struct efi_system_resource_table tmpesrt; size_t size, max, entry_size, entries_size; - efi_memory_desc_t md; - int rc; + bool reserve_esrt; phys_addr_t end; - if (!efi_enabled(EFI_MEMMAP)) - return; - pr_debug("esrt-init: loading.\n"); if (!esrt_table_exists()) return; - rc = efi_mem_desc_lookup(efi.esrt, &md); - if (rc < 0 || - (!(md.attribute & EFI_MEMORY_RUNTIME) && - md.type != EFI_BOOT_SERVICES_DATA && - md.type != EFI_RUNTIME_SERVICES_DATA)) { - pr_warn("ESRT header is not in the memory map.\n"); - return; - } + size = sizeof(*esrt); + if (efi_enabled(EFI_MEMMAP)) { + efi_memory_desc_t md; + int rc; + + rc = efi_mem_desc_lookup(efi.esrt, &md); + if (rc < 0 || + (!(md.attribute & EFI_MEMORY_RUNTIME) && + md.type != EFI_BOOT_SERVICES_DATA && + md.type != EFI_RUNTIME_SERVICES_DATA)) { + pr_warn("ESRT header is not in the memory map.\n"); + return; + } - max = efi_mem_desc_end(&md); - if (max < efi.esrt) { - pr_err("EFI memory descriptor is invalid. (esrt: %p max: %p)\n", - (void *)efi.esrt, (void *)max); - return; - } + reserve_esrt = (md.type == EFI_BOOT_SERVICES_DATA); + max = efi_mem_desc_end(&md); + if (max < efi.esrt) { + pr_err("EFI memory descriptor is invalid. (esrt: %p max: %p)\n", + (void *)efi.esrt, (void *)max); + return; + } - size = sizeof(*esrt); - max -= efi.esrt; + max -= efi.esrt; - if (max < size) { - pr_err("ESRT header doesn't fit on single memory map entry. (size: %zu max: %zu)\n", - size, max); - return; + if (max < size) { + pr_err("ESRT header doesn't fit on single memory map entry. (size: %zu max: %zu)\n", + size, max); + return; + } + } else { + reserve_esrt = true; + max = SIZE_MAX; } va = early_memremap(efi.esrt, size); @@ -332,9 +337,11 @@ void __init efi_esrt_init(void) esrt_data_size = size; end = esrt_data + size; - pr_info("Reserving ESRT space from %pa to %pa.\n", &esrt_data, &end); - if (md.type == EFI_BOOT_SERVICES_DATA) + if (reserve_esrt) { + pr_info("Reserving ESRT space from %pa to %pa.\n", &esrt_data, + &end); efi_mem_reserve(esrt_data, esrt_data_size); + } pr_debug("esrt-init: loaded.\n"); } -- 2.35.1