Skip to content

KVM: nested virt SMM fixes

Ladi Prosek kvm 5 versions – Applied

Status from this message: Queued, thanks for persisting!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest6 patches 3 repliesApplied
  2. v46 patches 6 repliesSuperseded
  3. v36 patches 4 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v26 patches8 repliesSuperseded
v15 patches3 repliesSuperseded

Changes in v5 from the cover letter

* Removed patch 4 (CR4.VMXE protection in SMM, will be done separately), patch 3 bacame 4 and new patch 3 fixes a bug in load_vmcs12_host_state() which prevented SMM exit to L2 from working without first restoring the state from the SMM state save area.
* Eliminated the first restore from SMM state save area (Paolo)
* Tweaked the HF_SMM_MASK flag manipulation (Paolo)

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/6KVM: x86: introduce ISA specific SMM entry/exit callbacksarch/x86/include/asm/kvm_emulate.h arch/x86/include/asm/kvm_host.h arch/x86/kvm/emulate.c +3 more+58 -10 replies
2/6KVM: x86: introduce ISA specific smi_allowed callbackarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm.c arch/x86/kvm/vmx.c +1 more+14 -10 replies
3/6KVM: nVMX: set IDTR and GDTR limits when loading L1 host statearch/x86/kvm/vmx.c+2 -01 reply
4/6KVM: nVMX: fix SMI injection in guest modearch/x86/kvm/vmx.c+49 -110 replies
5/6KVM: nSVM: refactor nested_svm_vmrunarch/x86/kvm/svm.c+69 -630 replies
6/6KVM: nSVM: fix SMI injection in guest modearch/x86/include/asm/kvm_host.h arch/x86/kvm/svm.c arch/x86/kvm/x86.c+58 -60 replies

Reviews trailers per patch

1 of 6 patches has a Reviewed-by or Acked-by.

PatchJim Mattson
1/6
2/6
3/6R-b
4/6
5/6
6/6

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

Read the v5 thread

Cover letter [PATCH v5 0/6] KVM: nested virt SMM fixes

Windows Server 2016 with Hyper-V enabled fails to boot on OVMF with SMM (OVMF_CODE-need-smm.fd). Turns out that the SMM emulation code in KVM does not handle nested virtualization very well, leading to a whole bunch of issues.

For example, Hyper-V uses descriptor table exiting (SECONDARY_EXEC_DESC) so when the SMM handler tries to switch from real mode a VM exit occurs and is forwarded to a clueless L1.

This series fixes it by switching the vcpu to !guest_mode, i.e. to the L1 state, before entering SMM and then switching back to L2 as part of emulating the RSM instruction.

Patches 1 and 2 are common for both Intel and AMD, patches 3-4 fix Intel, and patches 5-6 AMD.

v1->v2:
* Moved left_smm detection to emulator_set_hflags (couldn't quite get rid of the field despite my original claim) (Paolo)
* Moved the kvm_x86_ops->post_leave_smm() call a few statements down so it really runs after all state has been synced.
* Added the smi_allowed callback (new patch 2) to avoid running into WARN_ON_ONCE(vmx->nested.nested_run_pending) on Intel.

v2->v3:
* Ommitted patch 4 ("KVM: nVMX: save nested EPT information in SMRAM state save map") and replaced it with ("treat CR4.VMXE as reserved in SMM") (Paolo)
* Implemented smi_allowed on AMD to support SMI interception. Turns out Windows needs this when running on >1 vCPU.
* Eliminated internal SMM state on AMD and switched to using the SMM state save area in guest memory instead (Paolo)

v3->v4:
* Changed the order of operations in enter_smm(), now saving the original (and potentially L2) state into the SMM state save area.
* Made em_rsm() reload the SMM state save area if post_leave_smm() entered guest mode. This way, SMM handlers see and may change the actual state of the vCPU at the point where SMI was injected (Radim)
* In patch 4, switched to a different way of avoiding the problem of hitting the very check the patch is adding.

v4->v5:
* Removed patch 4 (CR4.VMXE protection in SMM, will be done separately), patch 3 bacame 4 and new patch 3 fixes a bug in load_vmcs12_host_state() which prevented SMM exit to L2 from working without first restoring the state from the SMM state save area.
* Eliminated the first restore from SMM state save area (Paolo)
* Tweaked the HF_SMM_MASK flag manipulation (Paolo)

Ladi Prosek (6):
KVM: x86: introduce ISA specific SMM entry/exit callbacks
KVM: x86: introduce ISA specific smi_allowed callback
KVM: nVMX: set IDTR and GDTR limits when loading L1 host state
KVM: nVMX: fix SMI injection in guest mode
KVM: nSVM: refactor nested_svm_vmrun
KVM: nSVM: fix SMI injection in guest mode

 arch/x86/include/asm/kvm_emulate.h |   2 +
 arch/x86/include/asm/kvm_host.h    |   7 ++
 arch/x86/kvm/emulate.c             |   9 ++
 arch/x86/kvm/svm.c                 | 205 +++++++++++++++++++++++++------------
 arch/x86/kvm/vmx.c                 |  79 ++++++++++++--
 arch/x86/kvm/x86.c                 |  20 +++-
 6 files changed, 245 insertions(+), 77 deletions(-)