From: Sean Christopherson Date: Tue, 10 Mar 2026 23:48:16 +0000 (-0700) Subject: KVM: SEV: Add quad-underscore version of VM-scoped APIs to detect SEV+ guests X-Git-Tag: v7.1-rc1~118^2~2^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=138e5f6a3e1172fee8665bc8b1bbe695ba6b2adf;p=thirdparty%2Fkernel%2Flinux.git KVM: SEV: Add quad-underscore version of VM-scoped APIs to detect SEV+ guests 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 --- diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 79f00184a2ec9..f14e2fe551cd3 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -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