Skip to content

Add #VC exception handling for AMD SEV-ES

Varad Gautam kvm 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest11 patches 14 repliesIn review
  2. v2 posting 2/210 patches 14 repliesSuperseded
  3. v2 posting 1/21 patch 3 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v113 patches13 repliesSuperseded

Changes in v3 from the cover letter

- Reduce the diff between insn decoder code imported into kvm-unit-tests and the original code in Linux; cleanup #VC handling.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11x86: AMD SEV-ES: Setup #VC exception handler for AMD SEV-ESMakefile configure lib/x86/amd_sev.c +6 more+69 -80 replies
2/11x86: Move svm.h to lib/x86/lib/x86/svm.h x86/svm.c x86/svm_tests.c+2 -20 replies
3/11lib: Define unlikely()/likely() macros in libcflat.hlib/libcflat.h x86/kvmclock.c+3 -40 replies
4/11lib: x86: Import insn decoder from Linux.gitignore lib/x86/insn/README lib/x86/insn/gen-insn-attr-x86.awk +8 more+2984 -26 replies
5/11x86: AMD SEV-ES: Pull related GHCB definitions and helpers from Linuxlib/x86/amd_sev.h lib/x86/msr.h lib/x86/processor.h +2 more+145 -10 replies
6/11x86: AMD SEV-ES: Prepare for #VC processinglib/x86/amd_sev_vc.c+89 -10 replies
7/11lib/x86: Move xsave helpers to lib/lib/x86/xsave.c lib/x86/xsave.h x86/Makefile.common +1 more+55 -420 replies
8/11x86: AMD SEV-ES: Handle CPUID #VClib/x86/amd_sev_vc.c+91 -00 replies
9/11x86: AMD SEV-ES: Handle MSR #VClib/x86/amd_sev_vc.c+28 -00 replies
10/11x86: AMD SEV-ES: Handle IOIO #VClib/x86/amd_sev_vc.c lib/x86/processor.h+176 -00 replies
11/11x86: AMD SEV-ES: Handle string IO for IOIO #VClib/x86/amd_sev_vc.c+106 -28 replies

Reviews trailers per patch

6 of 11 patches have a Reviewed-by or Acked-by.

PatchMarc Orr
1/11R-b
2/11R-b
3/11
4/11
5/11
6/11
7/11R-b
8/11
9/11R-b
10/11R-b
11/11R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [kvm-unit-tests PATCH v3 00/11] Add #VC exception handling for AMD SEV-ES

For AMD SEV-ES, kvm-unit-tests currently rely on UEFI to set up a #VC exception handler. This leads to the following problems:

1) The test's page table needs to map the firmware and the shared GHCB used by the firmware.
2) The firmware needs to keep its #VC handler in the current IDT so that kvm-unit-tests can copy the #VC entry into its own IDT.
3) The firmware #VC handler might use state which is not available anymore after ExitBootServices.
4) After ExitBootServices, the firmware needs to get the GHCB address from the GHCB MSR if it needs to use the kvm-unit-test GHCB. This requires keeping an identity mapping, and the GHCB address must be in the MSR at all times where a #VC could happen.

Problems 1) and 2) were temporarily mitigated via commits b114aa57ab ("x86 AMD SEV-ES: Set up GHCB page") and 706ede1833 ("x86 AMD SEV-ES:
Copy UEFI #VC IDT entry") respectively.

However, to make kvm-unit-tests reliable against 3) and 4), the tests must supply their own #VC handler [1][2].

This series adds #VC exception processing from Linux into kvm-unit-tests, and makes it the default way of handling #VC exceptions.

If --amdsev-efi-vc is passed during ./configure, the tests will continue using the UEFI #VC handler.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/YSA%[email protected]/

Git branch: https://github.com/varadgautam/kvm-unit-tests/commits/vc-handler-v3

v3:
- Reduce the diff between insn decoder code imported into kvm-unit-tests and the original code in Linux; cleanup #VC handling.

v2:
- Drop #VC processing code for RDTSC/RDTSCP and WBINVD (seanjc). KVM does not trap RDTSC/RDTSCP, and the tests do not produce a WBINVD exit to be handled.
- Clarify the rationale for tests needing their own #VC handler (marcorr).

Varad Gautam (11):
x86: AMD SEV-ES: Setup #VC exception handler for AMD SEV-ES
x86: Move svm.h to lib/x86/
lib: Define unlikely()/likely() macros in libcflat.h
lib: x86: Import insn decoder from Linux
x86: AMD SEV-ES: Pull related GHCB definitions and helpers from Linux
x86: AMD SEV-ES: Prepare for #VC processing
lib/x86: Move xsave helpers to lib/
x86: AMD SEV-ES: Handle CPUID #VC
x86: AMD SEV-ES: Handle MSR #VC
x86: AMD SEV-ES: Handle IOIO #VC
x86: AMD SEV-ES: Handle string IO for IOIO #VC

 .gitignore                         |    2 +
 Makefile                           |    3 +
 configure                          |   21 +
 lib/libcflat.h                     |    3 +
 lib/x86/amd_sev.c                  |   13 +-
 lib/x86/amd_sev.h                  |   96 +++
 lib/x86/amd_sev_vc.c               |  494 +++++++++++++
 lib/x86/desc.c                     |   15 +
 lib/x86/desc.h                     |    1 +
 lib/x86/insn/README                |   23 +
 lib/x86/insn/gen-insn-attr-x86.awk |  444 +++++++++++
 lib/x86/insn/inat.c                |   86 +++
 lib/x86/insn/inat.h                |  233 ++++++
 lib/x86/insn/inat_types.h          |   18 +
 lib/x86/insn/insn.c                |  749 +++++++++++++++++++
 lib/x86/insn/insn.h                |  279 +++++++
 lib/x86/insn/insn_glue.h           |   32 +
 lib/x86/insn/x86-opcode-map.txt    | 1106 ++++++++++++++++++++++++++++
 lib/x86/msr.h                      |    1 +
 lib/x86/processor.h                |   16 +
 lib/x86/setup.c                    |    8 +
 {x86 => lib/x86}/svm.h             |   40 +-
 lib/x86/xsave.c                    |   37 +
 lib/x86/xsave.h                    |   16 +
 x86/Makefile.common                |   16 +-
 x86/Makefile.x86_64                |    1 +
 x86/kvmclock.c                     |    4 -
 x86/svm.c                          |    2 +-
 x86/svm_tests.c                    |    2 +-
 x86/xsave.c                        |   43 +-
 30 files changed, 3745 insertions(+), 59 deletions(-)
 create mode 100644 lib/x86/amd_sev_vc.c
 create mode 100644 lib/x86/insn/README
 create mode 100644 lib/x86/insn/gen-insn-attr-x86.awk
 create mode 100644 lib/x86/insn/inat.c
 create mode 100644 lib/x86/insn/inat.h
 create mode 100644 lib/x86/insn/inat_types.h
 create mode 100644 lib/x86/insn/insn.c
 create mode 100644 lib/x86/insn/insn.h
 create mode 100644 lib/x86/insn/insn_glue.h
 create mode 100644 lib/x86/insn/x86-opcode-map.txt
 rename {x86 => lib/x86}/svm.h (93%)
 create mode 100644 lib/x86/xsave.c
 create mode 100644 lib/x86/xsave.h
Signature · 1 line
2.32.0