From: Pavan Kumar Paluri <papaluri@amd.com>
To: <kvm@vger.kernel.org>
Cc: <pbonzini@redhat.com>, <andrew.jones@linux.dev>,
<nikos.nikoleris@arm.com>, <thomas.lendacky@amd.com>,
<michael.roth@amd.com>, <amit.shah@amd.com>,
Pavan Kumar Paluri <papaluri@amd.com>
Subject: [kvm-unit-tests RFC PATCH 2/3] x86/efi: Retry call to efi exit boot services
Date: Mon, 25 Mar 2024 16:36:22 -0500 [thread overview]
Message-ID: <20240325213623.747590-2-papaluri@amd.com> (raw)
In-Reply-To: <20240325213623.747590-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 update the memory map and retry call to exit boot
services.
Signed-off-by: Pavan Kumar Paluri <papaluri@amd.com>
---
lib/efi.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/lib/efi.c b/lib/efi.c
index 124e77685230..9d066bfad0b6 100644
--- a/lib/efi.c
+++ b/lib/efi.c
@@ -458,14 +458,27 @@ 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
+ * guest.
*/
status = efi_exit_boot_services(handle, &efi_bootinfo.mem_map);
- if (status != EFI_SUCCESS) {
- 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 try again.
+ */
+ if (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) {
+ printf("Failed to exit boot services\n");
+ goto efi_main_error;
+ }
}
/* Set up arch-specific resources */
--
2.34.1
next prev parent reply other threads:[~2024-03-25 21:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-25 21:36 [kvm-unit-tests RFC PATCH 1/3] x86 EFI: Bypass call to fdt_check_header() Pavan Kumar Paluri
2024-03-25 21:36 ` Pavan Kumar Paluri [this message]
2024-03-26 8:57 ` [kvm-unit-tests RFC PATCH 2/3] x86/efi: Retry call to efi exit boot services Andrew Jones
2024-03-26 13:29 ` Paluri, PavanKumar
2024-03-26 13:38 ` Michael Roth
2024-03-26 13:45 ` Paluri, PavanKumar
2024-03-26 13:58 ` Michael Roth
2024-03-25 21:36 ` [kvm-unit-tests RFC PATCH 3/3] x86 AMD SEV-ES: Setup a new page table and install level 1 PTEs Pavan Kumar Paluri
2024-03-26 14:01 ` Tom Lendacky
2024-03-26 15:35 ` Paluri, PavanKumar
2024-03-26 8:51 ` [kvm-unit-tests RFC PATCH 1/3] x86 EFI: Bypass call to fdt_check_header() Andrew Jones
2024-03-26 13:28 ` Paluri, PavanKumar
2024-03-26 15:30 ` 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=20240325213623.747590-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=nikos.nikoleris@arm.com \
--cc=pbonzini@redhat.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