public inbox for linux-coco@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v2 0/4] KVM: x86: Cleanup #MC and XCR0/XSS/PKRU handling
@ 2025-11-18 22:23 Sean Christopherson
  2025-11-18 22:23 ` [PATCH v2 1/4] KVM: SVM: Handle #MCs in guest outside of fastpath Sean Christopherson
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Sean Christopherson @ 2025-11-18 22:23 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Kirill A. Shutemov
  Cc: kvm, x86, linux-coco, linux-kernel, Rick Edgecombe, Jon Kohler,
	Tony Lindgren

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/20251030224246.3456492-1-seanjc@google.com

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
-- 
2.52.0.rc1.455.g30608eb744-goog


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-11-21 18:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-18 22:23 [PATCH v2 0/4] KVM: x86: Cleanup #MC and XCR0/XSS/PKRU handling Sean Christopherson
2025-11-18 22:23 ` [PATCH v2 1/4] KVM: SVM: Handle #MCs in guest outside of fastpath Sean Christopherson
2025-11-18 22:23 ` [PATCH v2 2/4] KVM: VMX: Handle #MCs on VM-Enter/TD-Enter outside of the fastpath Sean Christopherson
2025-11-19  6:11   ` Tony Lindgren
2025-11-21  6:09   ` Binbin Wu
2025-11-21 18:58     ` Sean Christopherson
2025-11-18 22:23 ` [PATCH v2 3/4] KVM: x86: Load guest/host XCR0 and XSS outside of the fastpath run loop Sean Christopherson
2025-11-18 22:23 ` [PATCH v2 4/4] KVM: x86: Load guest/host PKRU " Sean Christopherson
2025-11-21 18:55 ` [PATCH v2 0/4] KVM: x86: Cleanup #MC and XCR0/XSS/PKRU handling Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox