[PATCH 08/21] KVM: SEV: Add quad-underscore version of VM-scoped APIs to detect SEV+ guests

From: Sean Christopherson

Date: Tue Mar 10 2026 - 19:53:02 EST


Add "unsafe" quad-underscore versions of the SEV+ guest detectors in
anticipation of hardening the APIs via lockdep assertions. This will allow
adding exceptions for usage that is known to be safe in advance of the
lockdep assertions.

Use a pile of underscores to try and communicate that use of the "unsafe"
shouldn't be done lightly.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/svm/svm.h | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 121138901fd6..5f8977eec874 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -370,37 +370,51 @@ static __always_inline struct kvm_sev_info *to_kvm_sev_info(struct kvm *kvm)
}

#ifdef CONFIG_KVM_AMD_SEV
-static __always_inline bool sev_guest(struct kvm *kvm)
+static __always_inline bool ____sev_guest(struct kvm *kvm)
{
return to_kvm_sev_info(kvm)->active;
}
-static __always_inline bool sev_es_guest(struct kvm *kvm)
+static __always_inline bool ____sev_es_guest(struct kvm *kvm)
{
struct kvm_sev_info *sev = to_kvm_sev_info(kvm);

return sev->es_active && !WARN_ON_ONCE(!sev->active);
}

-static __always_inline bool sev_snp_guest(struct kvm *kvm)
+static __always_inline bool ____sev_snp_guest(struct kvm *kvm)
{
struct kvm_sev_info *sev = to_kvm_sev_info(kvm);

return (sev->vmsa_features & SVM_SEV_FEAT_SNP_ACTIVE) &&
- !WARN_ON_ONCE(!sev_es_guest(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);
+ return ____sev_guest(vcpu->kvm);
}
static __always_inline bool is_sev_es_guest(struct kvm_vcpu *vcpu)
{
- return sev_es_guest(vcpu->kvm);
+ return ____sev_es_guest(vcpu->kvm);
}

static __always_inline bool is_sev_snp_guest(struct kvm_vcpu *vcpu)
{
- return sev_snp_guest(vcpu->kvm);
+ return ____sev_snp_guest(vcpu->kvm);
}
#else
#define sev_guest(kvm) false
--
2.53.0.473.g4a7958ca14-goog