public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency
@ 2025-01-09 22:55 Kevin Loughlin
  2025-01-09 22:55 ` [PATCH v2 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
                   ` (2 more replies)
  0 siblings, 3 replies; 39+ messages in thread
From: Kevin Loughlin @ 2025-01-09 22:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, bp, dave.hansen, x86, hpa, seanjc, pbonzini,
	kevinloughlin, kirill.shutemov, kai.huang, ubizjak, dave.jiang,
	jgross, kvm, thomas.lendacky, pgonda, sidtelang, mizhang,
	rientjes, szy0127

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 WBNOINVD similar to how WBINVD
is invoked. Second, check for WBNOINVD support and execute WBNOINVD if
possible in lieu of WBINVD to avoid cache invalidations.

Changelog
---
v2: rebase to tip @ dffeaed35cef, drop unnecessary Xen changes, reword.
---
Kevin Loughlin (2):
  x86, lib: Add WBNOINVD helper functions
  KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency

 arch/x86/include/asm/smp.h           |  7 ++++++
 arch/x86/include/asm/special_insns.h |  7 +++++-
 arch/x86/kvm/svm/sev.c               | 35 +++++++++++++++++-----------
 arch/x86/lib/cache-smp.c             | 12 ++++++++++
 4 files changed, 47 insertions(+), 14 deletions(-)

-- 
2.47.1.688.g23fc6f90ad-goog


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

end of thread, other threads:[~2025-02-26 14:22 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-09 22:55 [PATCH v2 0/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-01-09 22:55 ` [PATCH v2 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-01-09 22:55 ` [PATCH v2 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-01-10  8:23   ` Kirill A. Shutemov
2025-01-13 18:47     ` Kevin Loughlin
2025-01-14  7:50       ` Kirill A. Shutemov
2025-01-14 16:12         ` Sean Christopherson
2025-01-17 22:20           ` Kevin Loughlin
2025-01-13 21:46   ` Mingwei Zhang
2025-01-22  0:13 ` [PATCH v3 0/2] " Kevin Loughlin
2025-01-22  0:13   ` [PATCH v3 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-01-22  0:30     ` Dave Hansen
2025-01-22  0:30       ` Dave Hansen
2025-01-22  1:14       ` Kevin Loughlin
2025-01-22  0:13   ` [PATCH v3 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-01-22  1:34   ` [PATCH v4 0/2] " Kevin Loughlin
2025-01-22  1:34     ` [PATCH v4 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-01-22  7:32       ` Kirill A. Shutemov
2025-01-22 19:39         ` Tom Lendacky
2025-01-22 23:16           ` Dave Hansen
2025-01-23  0:06             ` Kevin Loughlin
2025-01-23  0:33               ` Dave Hansen
2025-01-23  0:58                 ` Kevin Loughlin
2025-01-23  1:17                   ` Kevin Loughlin
2025-01-22  1:34     ` [PATCH v4 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-01-23  0:24     ` [PATCH v5 0/2] " Kevin Loughlin
2025-01-23  0:24       ` [PATCH v5 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-01-23  0:36         ` Dave Hansen
2025-01-23  0:55           ` Kevin Loughlin
2025-01-23  0:24       ` [PATCH v5 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-02-26  1:30         ` Sean Christopherson
2025-02-01  0:02       ` [PATCH v6 0/2] " Kevin Loughlin
2025-02-01  0:02         ` [PATCH v6 1/2] x86, lib: Add WBNOINVD helper functions Kevin Loughlin
2025-02-04 16:59           ` Tom Lendacky
2025-02-26  1:26           ` Sean Christopherson
2025-02-26 14:22             ` Borislav Petkov
2025-02-01  0:02         ` [PATCH v6 2/2] KVM: SEV: Prefer WBNOINVD over WBINVD for cache maintenance efficiency Kevin Loughlin
2025-02-04 17:00           ` Tom Lendacky
2025-02-26  1:35       ` [PATCH v5 0/2] " Sean Christopherson

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