Hello, This patch series updates the x86_64 KVM-Unit-Tests to run under UEFI and culminates in enabling AMD SEV/SEV-ES. We are sending it out for early review as it provides basic support to run test cases in UEFI, and also enables AMD SEV and SEV-ES features. The patches are organized as two parts. The first part (patches 1-9) enables the x86_64 test cases to run under UEFI. In particular, these patches allow the x86_64 test cases to be built as EFI applications. The efi_main() function sets up the KVM-Unit-Tests framework to run under UEFI and then launches the test cases' main() function. To date, we have 38/43 test cases running with UEFI using this approach. The second part of the series (patches 10-16) focuses on SEV. In particular, these patches introduce SEV/SEV-ES set up code into the EFI set up process, including checking if SEV is supported, setting c-bits for page table entries, and (notably) reusing the UEFI #VC handler so that the set up process does not need to re-implement it (a test case can always implement a new #VC handler and load it after set up is finished). Using this approach, we are able to launch the x86_64 test cases under SEV-ES and exercise KVM's VMGEXIT handler. See the Part 1 and Part 2 summaries, below, for a high-level breakdown of how the patches are organized. Part 1 Summary: Commits 1-3 introduce support to build test cases as EFI applications (with the GNU-EFI library). Commits 4-8 set up KVM-Unit-Tests to run under UEFI. In doing so, these patches incrementally enable most existing x86_64 test cases to run under UEFI. Commit 9 fixes several test cases that fail to compile with GNU-EFI due to UEFI's position independent code (PIC) requirement. Part 2 Summary: Commits 10-11 introduce support for SEV by adding new configuration flags and set up code to set the SEV c-bit in page table entries. SEV-related code is currently injected by configuration flags and C macros, it is also possible to remove these flags and macros and implement runtime SEV check and set up functions. Commits 12-15 introduce support for SEV-ES by reusing the UEFI #VC handler in KVM-Unit-Tests. They also fix GDT and IDT issues that occur when reusing UEFI functions in KVM-Unit-Tests. Commit 16 adds additional test cases for SEV-ES. Regards, Zixuan Wang Zixuan Wang (16): x86 UEFI: Copy code from GNU-EFI x86 UEFI: Boot from UEFI x86 UEFI: Move setjmp.h out of desc.h x86 UEFI: Load KVM-Unit-Tests IDT after UEFI boot up x86 UEFI: Load GDT and TSS after UEFI boot up x86 UEFI: Set up memory allocator x86 UEFI: Set up RSDP after UEFI boot up x86 UEFI: Set up page tables x86 UEFI: Convert x86 test cases to PIC x86 AMD SEV: Initial support x86 AMD SEV: Page table with c-bit x86 AMD SEV-ES: Check SEV-ES status x86 AMD SEV-ES: Load GDT with UEFI segments x86 AMD SEV-ES: Copy UEFI #VC IDT entry x86 AMD SEV-ES: Set up GHCB page x86 AMD SEV-ES: Add test cases .gitignore | 3 + Makefile | 47 ++++++- README.md | 6 + configure | 29 +++++ lib/efi.c | 60 +++++++++ lib/string.c | 3 + lib/x86/acpi.c | 38 +++++- lib/x86/acpi.h | 4 + lib/x86/amd_sev.c | 147 +++++++++++++++++++++ lib/x86/amd_sev.h | 59 +++++++++ lib/x86/asm/page.h | 14 +- lib/x86/asm/setup.h | 37 ++++++ lib/x86/desc.c | 4 + lib/x86/desc.h | 5 - lib/x86/setup.c | 259 +++++++++++++++++++++++++++++++++++++ lib/x86/usermode.c | 3 +- lib/x86/vm.c | 18 ++- x86/Makefile.common | 75 ++++++++--- x86/Makefile.i386 | 5 +- x86/Makefile.x86_64 | 58 ++++++--- x86/access.c | 6 +- x86/amd_sev.c | 97 ++++++++++++++ x86/cet.c | 8 +- x86/efi/README.md | 72 +++++++++++ x86/efi/efistart64.S | 141 ++++++++++++++++++++ x86/efi/elf_x86_64_efi.lds | 81 ++++++++++++ x86/efi/run | 63 +++++++++ x86/emulator.c | 5 +- x86/eventinj.c | 6 +- x86/run | 16 ++- x86/smap.c | 8 +- x86/umip.c | 10 +- x86/vmx.c | 1 + 33 files changed, 1311 insertions(+), 77 deletions(-) create mode 100644 lib/efi.c create mode 100644 lib/x86/amd_sev.c create mode 100644 lib/x86/amd_sev.h create mode 100644 lib/x86/asm/setup.h create mode 100644 x86/amd_sev.c create mode 100644 x86/efi/README.md create mode 100644 x86/efi/efistart64.S create mode 100644 x86/efi/elf_x86_64_efi.lds create mode 100755 x86/efi/run -- 2.33.0.rc1.237.g0d66db33f3-goog