[PATCH] x86/efistub: Don't try to print after ExitBootService()

From: Nikolay Borisov
Date: Wed Oct 11 2023 - 15:25:39 EST


setup_e820() is executed after UEFI's ExitBootService has been called.
This causes the firmware to throw an exception because Console IO
protocol handler is supposed to work only during boot service
environment. As per UEFI 2.9, section 12.1:

"This protocol isused to handle input and output of text-based
information intended for the system user during the operation of code
in the boot services environment."

Running a TDX guest with TDVF with unaccepted memory disabled results in
the following output:

!!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!!
RIP - 0000000000603D51, CS - 0000000000000038, RFLAGS - 0000000000010046
RAX - 0000000000000000, RCX - 0000000000000000, RDX - 000000007EC27530
RBX - 0000000001C227A1, RSP - 000000007EC274D8, RBP - 000000007EC27530
RSI - 000000000000000A, RDI - 000000007EC27530
R8 - 00000000AC1C4720, R9 - 000000007D2C5F18, R10 - 0000000000400000
R11 - 0000000000000000, R12 - 0000000001C22B0E, R13 - 0000000000000000
R14 - 0000000000000032, R15 - 000000007C6022D0
DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030
GS - 0000000000000030, SS - 0000000000000030
CR0 - 0000000080010031, CR2 - 0000000000000000, CR3 - 000000007EA01000
CR4 - 0000000000000268, CR8 - 0000000000000000
DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
GDTR - 000000007E7E6000 0000000000000047, LDTR - 0000000000000000
IDTR - 000000007D2BD018 0000000000000FFF, TR - 0000000000000000
FXSAVE_STATE - 000000007EC27130
!!!! Can't find image information. !!!!

Signed-off-by: Nikolay Borisov <nik.borisov@xxxxxxxx>
---
drivers/firmware/efi/libstub/x86-stub.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 2fee52ed335d..3b8bccd7c216 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -605,11 +605,8 @@ setup_e820(struct boot_params *params, struct setup_data *e820ext, u32 e820ext_s
break;

case EFI_UNACCEPTED_MEMORY:
- if (!IS_ENABLED(CONFIG_UNACCEPTED_MEMORY)) {
- efi_warn_once(
-"The system has unaccepted memory, but kernel does not support it\nConsider enabling CONFIG_UNACCEPTED_MEMORY\n");
+ if (!IS_ENABLED(CONFIG_UNACCEPTED_MEMORY))
continue;
- }
e820_type = E820_TYPE_RAM;
process_unaccepted_memory(d->phys_addr,
d->phys_addr + PAGE_SIZE * d->num_pages);
--
2.34.1