Grab the EFI System Resource Table and check it
PATCH v2 1/1 Grab the EFI System Resource Table and check it
The EFI System Resource Table (ESRT) is necessary for fwupd to identify firmware updates to install. According to the UEFI specification §23.4, the table shall be stored in memory of type EfiBootServicesData. Therefore, Xen must avoid reusing that memory for other purposes, so that Linux can access the ESRT. Additionally, Xen must mark the memory as reserved, so that Linux knows accessing it is safe.
See https://lore.kernel.org/xen-devel/20200818184018.GN1679@mail-itl/T/
for details.
--- xen/arch/arm/efi/efi-boot.h | 9 +++-- xen/arch/x86/efi/efi-boot.h | 5 ++- xen/common/efi/boot.c | 77 +++++++++++++++++++++++++++++++++++-- xen/common/efi/efi.h | 2 +- xen/common/efi/runtime.c | 5 ++- xen/include/efi/efiapi.h | 3 ++ 6 files changed, 89 insertions(+), 12 deletions(-)
xen/arch/arm/efi/efi-boot.h +6 -3
@@ -187,7 +187,8 @@ static bool __init meminfo_add_bank(struct meminfo *mem,static EFI_STATUS __init efi_process_memory_map_bootinfo (EFI_MEMORY_DESCRIPTOR *map,UINTN mmap_size, -UINTN desc_size) +UINTN desc_size, +const EFI_MEMORY_DESCRIPTOR *const esrt_desc) {int Index;EFI_MEMORY_DESCRIPTOR *desc_ptr = map;
@@ -199,6 +200,7 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * desc_ptr->Type == EfiLoaderCode || desc_ptr->Type == EfiLoaderData || (!map_bs && + desc != esrt_desc && (desc_ptr->Type == EfiBootServicesCode || desc_ptr->Type == EfiBootServicesData))) ) {
@@ -404,11 +406,12 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,void *map, UINTN map_size, UINTN desc_size, - UINT32 desc_ver) + UINT32 desc_ver, + const EFI_MEMORY_DESCRIPTOR *const esrt_desc) { EFI_STATUS status; - status =efi_process_memory_map_bootinfo (map, map_size, desc_size); + status =efi_process_memory_map_bootinfo (map, map_size, desc_size, esrt_desc);if (EFI_ERROR (status) )blexit (L"EFI memory map processing failed" );
xen/arch/x86/efi/efi-boot.h +3 -2
@@ -154,7 +154,8 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable,void *map, UINTN map_size, UINTN desc_size, - UINT32 desc_ver) + UINT32 desc_ver, + const EFI_MEMORY_DESCRIPTOR *const esrt_desc) { struct e820entry *e;unsigned int i;
@@ -171,7 +172,7 @@ static void __init efi_arch_process_memory_map(EFI_SYSTEM_TABLE *SystemTable, {case EfiBootServicesCode:case EfiBootServicesData: -if ( map_bs ) +if ( map_bs || desc == esrt_desc ) {default : type =E820_RESERVED ;
xen/common/efi/boot.c +73 -4
130 lines not on this page · raw message
xen/common/efi/efi.h +1 -1
@@ -27,7 +27,7 @@ extern const CHAR16 *efi_fw_vendor;extern const EFI_RUNTIME_SERVICES *efi_rs;extern UINTN efi_memmap_size, efi_mdesc_size; -extern void *efi_memmap; +extern void *efi_memmap, *esrt_desc;#ifdef CONFIG_X86 extern mfn_t efi_l4_mfn;
xen/common/efi/runtime.c +3 -2
@@ -51,6 +51,7 @@ static unsigned int efi_rs_on_cpu = NR_CPUS;UINTN __read_mostly efi_memmap_size;UINTN __read_mostly efi_mdesc_size;void *__read_mostly efi_memmap; +void *__read_mostly esrt_desc;UINT64 __read_mostly efi_boot_max_var_store_size;UINT64 __read_mostly efi_boot_remain_var_store_size;
@@ -251,14 +252,14 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)case XEN_FW_EFI_MEM_INFO :for ( i =0 ; i < efi_memmap_size; i += efi_mdesc_size ) { -EFI_MEMORY_DESCRIPTOR *desc = efi_memmap + i; +const EFI_MEMORY_DESCRIPTOR *desc = efi_memmap + i;u64 len = desc->NumberOfPages <<EFI_PAGE_SHIFT ;if ( info->mem.addr >= desc->PhysicalStart && info->mem.addr < desc->PhysicalStart + len ) { info->mem.type = desc->Type; - info->mem.attr = desc->Attribute; + info->mem.attr = desc == esrt_desc ?EFI_MEMORY_RUNTIME : desc->Attribute;if ( info->mem.addr + info->mem.size < info->mem.addr || info->mem.addr + info->mem.size > desc->PhysicalStart + len )
xen/include/efi/efiapi.h +3 -0
@@ -882,6 +882,9 @@ typedef struct _EFI_BOOT_SERVICES {#define SAL_SYSTEM_TABLE_GUID \ { 0xeb9d2d32, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} } +#define ESRT_GUID \ + { 0xb122a263, 0x3661, 0x4f68, {0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80} } + typedef struct _EFI_CONFIGURATION_TABLE { EFI_GUID VendorGuid;
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
Hi,
Quoted 16 lines
xen/arch/arm/efi/efi-boot.h +2
-1@@ -187,7 +187,8 @@ static bool __init meminfo_add_bank(struct meminfo *mem,static EFI_STATUS __init efi_process_memory_map_bootinfo (EFI_MEMORY_DESCRIPTOR *map,UINTN mmap_size, -UINTN desc_size) +UINTN desc_size, +const EFI_MEMORY_DESCRIPTOR *const esrt_desc) {int Index;EFI_MEMORY_DESCRIPTOR *desc_ptr = map;
xen/arch/arm/efi/efi-boot.h static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * · line 203
Quoted 4 lines
xen/arch/arm/efi/efi-boot.h +1
-0@@ -199,6 +200,7 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * desc_ptr->Type == EfiLoaderCode || desc_ptr->Type == EfiLoaderData || (!map_bs && + desc != esrt_desc &&
I was going to test it but this line is breaking arm build.
xen/arch/arm/efi/efi-boot.h static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * · line 206
Quoted 4 lines
xen/arch/arm/efi/efi-boot.h +0
-0(desc_ptr->Type == EfiBootServicesCode || desc_ptr->Type == EfiBootServicesData))) ) {
I see CC list is pretty small, did you forget to add the maintainers?
Cheers,
Luca
Quoted 9 lines · Luca Fancellu
Hi,
Quoted 7 lines
xen/arch/arm/efi/efi-boot.h +0
-0@@ -187,7 +187,8 @@ static bool __init meminfo_add_bank(struct meminfo *mem,
Quoted 15 lines
xen/arch/arm/efi/efi-boot.h static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * · line 203
Quoted 13 lines
xen/arch/arm/efi/efi-boot.h +3
-1static EFI_STATUS __init efi_process_memory_map_bootinfo (EFI_MEMORY_DESCRIPTOR *map,UINTN mmap_size, -UINTN desc_size) +UINTN desc_size, +const EFI_MEMORY_DESCRIPTOR *const esrt_desc) {int Index;EFI_MEMORY_DESCRIPTOR *desc_ptr = map;@@ -199,6 +200,7 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * desc_ptr->Type == EfiLoaderCode || desc_ptr->Type == EfiLoaderData || (!map_bs && + desc != esrt_desc &&I was going to test it but this line is breaking arm build.
Not too surprising; I don’t think I actually built this for ARM. Can you post the error you get? I’ll send a v3 once that is fixed.
Quoted 6 lines
xen/arch/arm/efi/efi-boot.h static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * · line 206
Quoted 4 lines
xen/arch/arm/efi/efi-boot.h +0
-0(desc_ptr->Type == EfiBootServicesCode || desc_ptr->Type == EfiBootServicesData))) ) {I see CC list is pretty small, did you forget to add the maintainers?
Yeah, I did indeed forget.
Quoted 3 lines
Cheers,
Luca
Signature · 3 lines
Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab
Quoted 30 lines · Demi Marie Obenour
Quoted 9 lines · Luca Fancellu
Hi,
Quoted 7 lines
xen/arch/arm/efi/efi-boot.h +0
-0@@ -187,7 +187,8 @@ static bool __init meminfo_add_bank(struct meminfo *mem,Quoted 15 lines
xen/arch/arm/efi/efi-boot.h static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * · line 203
Quoted 13 lines
xen/arch/arm/efi/efi-boot.h +3
-1static EFI_STATUS __init efi_process_memory_map_bootinfo (EFI_MEMORY_DESCRIPTOR *map,UINTN mmap_size, -UINTN desc_size) +UINTN desc_size, +const EFI_MEMORY_DESCRIPTOR *const esrt_desc) {int Index;EFI_MEMORY_DESCRIPTOR *desc_ptr = map;@@ -199,6 +200,7 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * desc_ptr->Type == EfiLoaderCode || desc_ptr->Type == EfiLoaderData || (!map_bs && + desc != esrt_desc &&I was going to test it but this line is breaking arm build.
Quoted 2 lines
Not too surprising; I don’t think I actually built this for ARM. Can you post the error you get? I’ll send a v3 once that is fixed.
I think I cleaned my logs, but it was an easy one like “desc is not defined”, probably you were looking for “desc_ptr”?