All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v4 0/2] UEFI Improvements
@ 2024-03-29 13:15 Pavan Kumar Paluri
  2024-03-29 13:15 ` [kvm-unit-tests PATCH v4 1/2] x86 EFI: Bypass call to fdt_check_header() Pavan Kumar Paluri
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pavan Kumar Paluri @ 2024-03-29 13:15 UTC (permalink / raw)
  To: kvm; +Cc: andrew.jones, thomas.lendacky, michael.roth, 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
	 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(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [kvm-unit-tests PATCH v4 1/2] x86 EFI: Bypass call to fdt_check_header()
  2024-03-29 13:15 [kvm-unit-tests PATCH v4 0/2] UEFI Improvements Pavan Kumar Paluri
@ 2024-03-29 13:15 ` Pavan Kumar Paluri
  2024-03-29 13:15 ` [kvm-unit-tests PATCH v4 2/2] x86/efi: Retry call to efi exit boot services Pavan Kumar Paluri
  2024-04-03 11:27 ` [kvm-unit-tests PATCH v4 0/2] UEFI Improvements Andrew Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Pavan Kumar Paluri @ 2024-03-29 13:15 UTC (permalink / raw)
  To: kvm; +Cc: andrew.jones, thomas.lendacky, michael.roth, Pavan Kumar Paluri

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.

Fixes: 9632ce446b8f ("arm64: efi: Improve device tree discovery")
Signed-off-by: Pavan Kumar Paluri <papaluri@amd.com>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
---
 lib/efi.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/efi.c b/lib/efi.c
index 5314eaa81e66..8a74a22834a4 100644
--- a/lib/efi.c
+++ b/lib/efi.c
@@ -204,6 +204,7 @@ static char *efi_convert_cmdline(struct efi_loaded_image_64 *image, int *cmd_lin
 	return (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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [kvm-unit-tests PATCH v4 2/2] x86/efi: Retry call to efi exit boot services
  2024-03-29 13:15 [kvm-unit-tests PATCH v4 0/2] UEFI Improvements Pavan Kumar Paluri
  2024-03-29 13:15 ` [kvm-unit-tests PATCH v4 1/2] x86 EFI: Bypass call to fdt_check_header() Pavan Kumar Paluri
@ 2024-03-29 13:15 ` Pavan Kumar Paluri
  2024-04-03 11:27 ` [kvm-unit-tests PATCH v4 0/2] UEFI Improvements Andrew Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Pavan Kumar Paluri @ 2024-03-29 13:15 UTC (permalink / raw)
  To: kvm; +Cc: andrew.jones, thomas.lendacky, michael.roth, Pavan Kumar Paluri

In 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.

Signed-off-by: Pavan Kumar Paluri <papaluri@amd.com>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
---
 lib/efi.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/lib/efi.c b/lib/efi.c
index 8a74a22834a4..44337837705d 100644
--- a/lib/efi.c
+++ b/lib/efi.c
@@ -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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [kvm-unit-tests PATCH v4 0/2] UEFI Improvements
  2024-03-29 13:15 [kvm-unit-tests PATCH v4 0/2] UEFI Improvements Pavan Kumar Paluri
  2024-03-29 13:15 ` [kvm-unit-tests PATCH v4 1/2] x86 EFI: Bypass call to fdt_check_header() Pavan Kumar Paluri
  2024-03-29 13:15 ` [kvm-unit-tests PATCH v4 2/2] x86/efi: Retry call to efi exit boot services Pavan Kumar Paluri
@ 2024-04-03 11:27 ` Andrew Jones
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2024-04-03 11:27 UTC (permalink / raw)
  To: Pavan Kumar Paluri; +Cc: kvm, thomas.lendacky, michael.roth

On Fri, Mar 29, 2024 at 08:15:20AM -0500, Pavan Kumar Paluri wrote:
> 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(-)
> 
> -- 
> 2.34.1
>

Merged.

Thanks,
drew

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-03 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29 13:15 [kvm-unit-tests PATCH v4 0/2] UEFI Improvements Pavan Kumar Paluri
2024-03-29 13:15 ` [kvm-unit-tests PATCH v4 1/2] x86 EFI: Bypass call to fdt_check_header() Pavan Kumar Paluri
2024-03-29 13:15 ` [kvm-unit-tests PATCH v4 2/2] x86/efi: Retry call to efi exit boot services Pavan Kumar Paluri
2024-04-03 11:27 ` [kvm-unit-tests PATCH v4 0/2] UEFI Improvements Andrew Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.