UEFI Improvements
Subsystems (2)
v4 cover UEFI Improvements
Patch-1: Introduces a fix for x86 arch which is ACPI-based to not get
into the path of fdt.
Patch-2: KUT UEFI-based guest may sometimes fail to exit boot services
due to a possible memory map update that might have taken place between efi_get_memory_map() call and efi_exit_boot_services()
call. As per UEFI specification (2.10), we need to try and keep updating the memory map as long as we get Invalid key failure.
=========
Changelog
=========
v3 -> v4:
* Dropped patches 3 & 4 from the series as they are not relevant to UEFI improvements introduced in this patchset. This would aid in easier review and upstreaming.
* Addressed feedback (Andrew)
* Included R-b tag from Andrew Jones.
v2 -> v3:
* Included R-b tag from Andrew for Patch-1.
* Updated patch-2 to not leak memory map information during re-trials to efi_get_memory_map().
v1 -> v2:
* Incorporated feedback (Andrew, Mike, Tom)
* Updated patch-2 to keep trying to update memory map and calls to exit boot services as long as there is a failure.
* Split Page allocation and GHCB page attributes patch into two patches.
Pavan Kumar Paluri (2):
x86 EFI: Bypass call to fdt_check_header()
x86/efi: Retry call to efi exit boot services
lib/efi.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.1
PATCH v4 1/2 x86 EFI: Bypass call to fdt_check_header()
Issuing a call to fdt_check_header() prevents running any of x86 UEFI enabled tests. Bypass this call for x86 and also calls to efi_load_image(), efi_grow_buffer(), efi_get_var() in order to enable UEFI supported tests for KUT x86 arch.
--- lib/efi.c | 7 +++++++ 1 file changed, 7 insertions(+)
lib/efi.c +7 -0
@@ -204,6 +204,7 @@ static char *efi_convert_cmdline(struct efi_loaded_image_64 *image, int *cmd_linreturn (char *)cmdline_addr; } +#if defined(__aarch64__) || defined(__riscv)/* * Open the file and read it into a buffer. */
@@ -330,6 +331,12 @@ static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)return fdt_check_header (fdt) ==0 ? fdt :NULL ; } +#else +static void *efi_get_fdt (efi_handle_t handle,struct efi_loaded_image_64 *image) +{ +return NULL ; +} +#endif static const struct { struct efi_vendor_dev_path vendor;
Signature · 1 line
2.34.1
PATCH v4 2/2 x86/efi: Retry call to efi exit boot services
In reply to Pavan Kumar PaluriIn some cases, KUT guest might fail to exit boot services due to a possible memory map update that might have taken place between efi_get_memory_map() and efi_exit_boot_services() calls. As per UEFI spec 2.10 (Section 7.4.6 EFI_BOOT_SERVICES.ExitBootServices()), we need to keep trying to update the memory map and calls to exit boot services as long as case status is EFI_INVALID_PARAMETER. Keep freeing the old memory map before obtaining new memory map via efi_get_memory_map() in case of exit boot services failure.
--- lib/efi.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
lib/efi.c +18 -14
@@ -406,8 +406,8 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) efi_system_table = sys_tab;/* Memory map struct values */ -efi_memory_desc_t *map =NULL ; -unsigned long map_size =0 , desc_size =0 , key =0 , buff_size =0 ; +efi_memory_desc_t *map; +unsigned long map_size, desc_size, key, buff_size;u32 desc_ver;/* Helper variables needed to get the cmdline */
@@ -446,13 +446,6 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) efi_bootinfo.mem_map.key_ptr = &key; efi_bootinfo.mem_map.buff_size = &buff_size; -/* Get EFI memory map */ - status =efi_get_memory_map (&efi_bootinfo.mem_map); -if (status !=EFI_SUCCESS ) { -printf ("Failed to get memory map\n" ); - goto efi_main_error; - } -#ifdef __riscv status =efi_get_boot_hartid ();if (status !=EFI_SUCCESS ) {
@@ -461,11 +454,22 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) }#endif -/* -* Exit EFI boot services, let kvm-unit-tests take full control of the -* guest -*/ - status =efi_exit_boot_services (handle, &efi_bootinfo.mem_map); + status =EFI_INVALID_PARAMETER ; +while (status ==EFI_INVALID_PARAMETER ) { + status =efi_get_memory_map (&efi_bootinfo.mem_map); +if (status !=EFI_SUCCESS ) { +printf ("Failed to get memory map\n" ); + goto efi_main_error; + } +/* +* Exit EFI boot services, let kvm-unit-tests take full +* control of the guest. +*/ + status =efi_exit_boot_services (handle, &efi_bootinfo.mem_map); +if (status ==EFI_INVALID_PARAMETER ) +efi_free_pool (*efi_bootinfo.mem_map.map); + } +if (status !=EFI_SUCCESS ) {printf ("Failed to exit boot services\n" ); goto efi_main_error;
Signature · 1 line
2.34.1
Quoted 31 lines · Pavan Kumar Paluri
Patch-1: Introduces a fix for x86 arch which is ACPI-based to not get
into the path of fdt.Patch-2: KUT UEFI-based guest may sometimes fail to exit boot services
due to a possible memory map update that might have taken place betweenefi_get_memory_map()call andefi_exit_boot_services()
call. As per UEFI specification (2.10), we need to try and keep updating the memory map as long as we get Invalid key failure.=========
Changelog
=========
v3 -> v4:
* Dropped patches 3 & 4 from the series as they are not relevant to UEFI improvements introduced in this patchset. This would aid in easier review and upstreaming.
* Addressed feedback (Andrew)
* Included R-b tag from Andrew Jones.v2 -> v3:
* Included R-b tag from Andrew for Patch-1.
* Updated patch-2 to not leak memory map information during re-trials toefi_get_memory_map().v1 -> v2:
* Incorporated feedback (Andrew, Mike, Tom)
* Updated patch-2 to keep trying to update memory map and calls to exit boot services as long as there is a failure.
* Split Page allocation and GHCB page attributes patch into two patches.
Quoted 10 lines
Pavan Kumar Paluri (2):
x86 EFI: Bypass call tofdt_check_header()
x86/efi: Retry call to efi exit boot serviceslib/efi.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-)Signature · 1 line
2.34.1
Merged.
Thanks,
drew