[PATCH 10/21] KVM: SEV: Move standard VM-scoped helpers to detect SEV+ guests to sev.c

Sean Christopherson posted 21 patches 4 weeks ago
[PATCH 10/21] KVM: SEV: Move standard VM-scoped helpers to detect SEV+ guests to sev.c
Posted by Sean Christopherson 4 weeks ago
Now that all external usage of the VM-scoped APIs to detect SEV+ guests is
gone, drop the stubs provided for CONFIG_KVM_AMD_SEV=n builds and bury the
"standard" APIs in sev.c.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/svm/sev.c | 14 ++++++++++++++
 arch/x86/kvm/svm/svm.h | 17 -----------------
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 35033dc79390..0c5b47272335 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -107,6 +107,20 @@ static unsigned int nr_asids;
 static unsigned long *sev_asid_bitmap;
 static unsigned long *sev_reclaim_asid_bitmap;
 
+static bool sev_guest(struct kvm *kvm)
+{
+	return ____sev_guest(kvm);
+}
+static bool sev_es_guest(struct kvm *kvm)
+{
+	return ____sev_es_guest(kvm);
+}
+
+static bool sev_snp_guest(struct kvm *kvm)
+{
+	return ____sev_snp_guest(kvm);
+}
+
 static int snp_decommission_context(struct kvm *kvm);
 
 struct enc_region {
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 5f8977eec874..1b27d20f3022 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -389,20 +389,6 @@ static __always_inline bool ____sev_snp_guest(struct kvm *kvm)
 	       !WARN_ON_ONCE(!____sev_es_guest(kvm));
 }
 
-static __always_inline bool sev_guest(struct kvm *kvm)
-{
-	return ____sev_guest(kvm);
-}
-static __always_inline bool sev_es_guest(struct kvm *kvm)
-{
-	return ____sev_es_guest(kvm);
-}
-
-static __always_inline bool sev_snp_guest(struct kvm *kvm)
-{
-	return ____sev_snp_guest(kvm);
-}
-
 static __always_inline bool is_sev_guest(struct kvm_vcpu *vcpu)
 {
 	return ____sev_guest(vcpu->kvm);
@@ -417,9 +403,6 @@ static __always_inline bool is_sev_snp_guest(struct kvm_vcpu *vcpu)
 	return ____sev_snp_guest(vcpu->kvm);
 }
 #else
-#define sev_guest(kvm) false
-#define sev_es_guest(kvm) false
-#define sev_snp_guest(kvm) false
 #define is_sev_guest(vcpu) false
 #define is_sev_es_guest(vcpu) false
 #define is_sev_snp_guest(vcpu) false
-- 
2.53.0.473.g4a7958ca14-goog
Re: [PATCH 10/21] KVM: SEV: Move standard VM-scoped helpers to detect SEV+ guests to sev.c
Posted by Alexander Potapenko 3 weeks ago
> -static __always_inline bool sev_guest(struct kvm *kvm)
> -{
> -       return ____sev_guest(kvm);
> -}
> -static __always_inline bool sev_es_guest(struct kvm *kvm)
> -{
> -       return ____sev_es_guest(kvm);
> -}

arch/x86/kvm/svm/avic.c is still using sev_es_guest(), isn't it?
Re: [PATCH 10/21] KVM: SEV: Move standard VM-scoped helpers to detect SEV+ guests to sev.c
Posted by Sean Christopherson 1 week ago
On Tue, Mar 17, 2026, Alexander Potapenko wrote:
> > -static __always_inline bool sev_guest(struct kvm *kvm)
> > -{
> > -       return ____sev_guest(kvm);
> > -}
> > -static __always_inline bool sev_es_guest(struct kvm *kvm)
> > -{
> > -       return ____sev_es_guest(kvm);
> > -}
> 
> arch/x86/kvm/svm/avic.c is still using sev_es_guest(), isn't it?

When applied against kvm/master, yes.  I posted this against v7.0-rc2, which
didn't have commit 87d0f901a9bd ("KVM: SVM: Set/clear CR8 write interception when
AVIC is (de)activated").

If that's the only flaw, I'll fixup "KVM: SEV: Provide vCPU-scoped accessors for
detecting SEV+ guests" when applying (instead of sending a v2).