]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: SEV: Add quad-underscore version of VM-scoped APIs to detect SEV+ guests
authorSean Christopherson <seanjc@google.com>
Tue, 10 Mar 2026 23:48:16 +0000 (16:48 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 8 Apr 2026 23:04:25 +0000 (16:04 -0700)
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.

Link: https://patch.msgid.link/20260310234829.2608037-9-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/svm.h

index 79f00184a2ec9d14da3c1be08a79a9c7ee488e72..f14e2fe551cd3602dcde70d2e9d2b37d2777c995 100644 (file)
@@ -371,37 +371,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