Skip to content

KVM: x86: Cleanup #MC and XCR0/XSS/PKRU handling

Sean Christopherson kvm linux-coco lkml 2 versions – Applied

Status from this message: Applied to kvm-x86 misc, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 4 repliesApplied
  2. v14 patches 14 repliesApplied

Changes in v2 from the cover letter

- Collect reviews. [Jon, Rick]
- Fix TDX (suprisingly, not servicing host IRQs is problematic, /s). [Tony]

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/4KVM: SVM: Handle #MCs in guest outside of fastpatharch/x86/kvm/svm/svm.c+9 -90 replies
2/4KVM: VMX: Handle #MCs on VM-Enter/TD-Enter outside of the fastpatharch/x86/kvm/vmx/tdx.c arch/x86/kvm/vmx/vmx.c+11 -83 replies
3/4KVM: x86: Load guest/host XCR0 and XSS outside of the fastpath run looparch/x86/kvm/x86.c+26 -130 replies
4/4KVM: x86: Load guest/host PKRU outside of the fastpath run looparch/x86/kvm/svm/svm.c arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c +1 more+10 -120 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchRick EdgecombeJon KohlerTony LindgrenBinbin Wu
1/4R-b R-b
2/4R-b R-b
3/4R-b R-b
4/4R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v2 thread

Cover letter [PATCH v2 0/4] KVM: x86: Cleanup #MC and XCR0/XSS/PKRU handling

Optimize XCR0/XSS loads that are currently done on every VM-Enter and VM-Exit, by handling them outside of KVM's fastpath inner loop.

Context switching at entry/exit is unnecessary behavior inherited from a hack-a-fix that papered over an egregious #MC handling bug where the kernel #MC handler would call schedule() from atomic contexts. The resulting #GP due to trying to swap FPU state with a guest XCR0/XSS was "fixed" by loading the host values before handling #MCs from the guest.

Thankfully, the #MC mess has long since been cleaned up, so it's once again safe to swap XCR0/XSS outside of the fastpath (but with IRQs still disabled!).

Note, Binbin's kvm_load_xfeatures() still applies cleanly on top, so I deliberately didn't include it here (but am still planning on applying it).

v2:
- Collect reviews. [Jon, Rick]
- Fix TDX (suprisingly, not servicing host IRQs is problematic, /s). [Tony]

v1: https://lore.kernel.org/all/[email protected]

Sean Christopherson (4):
KVM: SVM: Handle #MCs in guest outside of fastpath
KVM: VMX: Handle #MCs on VM-Enter/TD-Enter outside of the fastpath
KVM: x86: Load guest/host XCR0 and XSS outside of the fastpath run
loop
KVM: x86: Load guest/host PKRU outside of the fastpath run loop

 arch/x86/kvm/svm/svm.c | 20 ++++++++---------
 arch/x86/kvm/vmx/tdx.c |  3 ---
 arch/x86/kvm/vmx/vmx.c | 20 +++++++++--------
 arch/x86/kvm/x86.c     | 51 +++++++++++++++++++++++++++++-------------
 arch/x86/kvm/x86.h     |  2 --
 5 files changed, 55 insertions(+), 41 deletions(-)

base-commit: 4531ff85d9251ff429a633bdb55209d3360f39f2

Signature · 1 line
2.52.0.rc1.455.g30608eb744-goog