From: Pavan Kumar Paluri <papaluri@amd.com>
To: <kvm@vger.kernel.org>
Cc: <andrew.jones@linux.dev>, <thomas.lendacky@amd.com>,
<michael.roth@amd.com>, <papaluri@amd.com>, <amit.shah@amd.com>
Subject: [kvm-unit-tests PATCH v2 2/4] x86/efi: Retry call to efi exit boot services
Date: Tue, 26 Mar 2024 12:33:58 -0500 [thread overview]
Message-ID: <20240326173400.773733-2-papaluri@amd.com> (raw)
In-Reply-To: <20240326173400.773733-1-papaluri@amd.com>
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.
Signed-off-by: Pavan Kumar Paluri <papaluri@amd.com>
---
lib/efi.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/lib/efi.c b/lib/efi.c
index 8a74a22834a4..c98bc5c0a022 100644
--- a/lib/efi.c
+++ b/lib/efi.c
@@ -461,16 +461,35 @@ 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);
- if (status != EFI_SUCCESS) {
+ if (status != EFI_SUCCESS && status != EFI_INVALID_PARAMETER) {
printf("Failed to exit boot services\n");
goto efi_main_error;
}
+ /*
+ * There is a possibility that memory map might have changed
+ * between efi_get_memory_map() and efi_exit_boot_services in
+ * which case status is EFI_INVALID_PARAMETER. As per UEFI spec
+ * 2.10, we need to get the updated memory map and keep trying
+ * until status is not EFI_INVALID_PARAMETER.
+ */
+ while (status == EFI_INVALID_PARAMETER) {
+ efi_get_memory_map(&efi_bootinfo.mem_map);
+
+ status = efi_exit_boot_services(handle,
+ &efi_bootinfo.mem_map);
+ if (status != EFI_SUCCESS &&
+ status != EFI_INVALID_PARAMETER) {
+ printf("Failed to exit boot services\n");
+ goto efi_main_error;
+ }
+ }
+
/* Set up arch-specific resources */
status = setup_efi(&efi_bootinfo);
if (status != EFI_SUCCESS) {
--
2.34.1
next prev parent reply other threads:[~2024-03-26 17:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 17:33 [kvm-unit-tests PATCH v2 1/4] x86 EFI: Bypass call to fdt_check_header() Pavan Kumar Paluri
2024-03-26 17:33 ` Pavan Kumar Paluri [this message]
2024-03-27 8:42 ` [kvm-unit-tests PATCH v2 2/4] x86/efi: Retry call to efi exit boot services Andrew Jones
2024-03-26 17:33 ` [kvm-unit-tests PATCH v2 3/4] x86 AMD SEV-ES: Set GHCB page attributes for a new page table Pavan Kumar Paluri
2024-03-26 17:34 ` [kvm-unit-tests PATCH v2 4/4] x86 AMD SEV-ES: Setup a new page table and install level-1 PTEs Pavan Kumar Paluri
2024-03-27 8:08 ` [kvm-unit-tests PATCH v2 1/4] x86 EFI: Bypass call to fdt_check_header() Andrew Jones
2024-03-27 23:24 ` Paluri, PavanKumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240326173400.773733-2-papaluri@amd.com \
--to=papaluri@amd.com \
--cc=amit.shah@amd.com \
--cc=andrew.jones@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox