public inbox for virtualization@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency
@ 2024-12-03  0:59 Kevin Loughlin
  2024-12-03  0:59 ` [RFC PATCH 1/2] x86, lib, xenpv: Add WBNOINVD helper functions Kevin Loughlin
  2024-12-03  0:59 ` [RFC PATCH 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
  0 siblings, 2 replies; 9+ messages in thread
From: Kevin Loughlin @ 2024-12-03  0:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	thomas.lendacky, pgonda, sidtelang, mizhang, virtualization,
	xen-devel, bcm-kernel-feedback-list, Kevin Loughlin

AMD CPUs currently execute WBINVD in the host when unregistering SEV
guest memory or when deactivating SEV guests. Such cache maintenance is
performed to prevent data corruption, wherein the encrypted (C=1)
version of a dirty cache line might otherwise only be written back
after the memory is written in a different context (ex: C=0), yielding
corruption. However, WBINVD is performance-costly, especially because
it invalidates processor caches.

Strictly-speaking, unless the SEV ASID is being recycled (meaning all
existing cache lines with the recycled ASID must be flushed), the
cache invalidation triggered by WBINVD is unnecessary; only the
writeback is needed to prevent data corruption in remaining scenarios.

To improve performance in these scenarios, use WBNOINVD when available
instead of WBINVD. WBNOINVD still writes back all dirty lines
(preventing host data corruption by SEV guests) but does *not*
invalidate processor caches.

First, provide helper functions to use WBINVD similar to how WBINVD is
invoked. Second, check for WBNOINVD support and execute WBNOINVD if
possible in lieu of WBINVD to avoid cache invalidations

Kevin Loughlin (2):
  x86, lib, xenpv: Add WBNOINVD helper functions
  KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency

 arch/x86/include/asm/paravirt.h       |  7 ++++++
 arch/x86/include/asm/paravirt_types.h |  1 +
 arch/x86/include/asm/smp.h            |  7 ++++++
 arch/x86/include/asm/special_insns.h  | 12 ++++++++-
 arch/x86/kernel/paravirt.c            |  6 +++++
 arch/x86/kvm/svm/sev.c                | 35 +++++++++++++++++----------
 arch/x86/lib/cache-smp.c              | 12 +++++++++
 arch/x86/xen/enlighten_pv.c           |  1 +
 8 files changed, 67 insertions(+), 14 deletions(-)

-- 
2.47.0.338.g60cca15819-goog


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

end of thread, other threads:[~2024-12-03 23:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-03  0:59 [RFC PATCH 0/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2024-12-03  0:59 ` [RFC PATCH 1/2] x86, lib, xenpv: Add WBNOINVD helper functions Kevin Loughlin
2024-12-03  1:28   ` Andrew Cooper
2024-12-03  1:44     ` Kevin Loughlin
2024-12-03  4:09       ` Xin Li
2024-12-03  6:47         ` Juergen Gross
2024-12-03  8:10           ` Xin Li
2024-12-03 23:42             ` Kevin Loughlin
2024-12-03  0:59 ` [RFC PATCH 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin

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