]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: SVM: Macrofy SEV=n versions of sev_xxx_guest()
authorSean Christopherson <seanjc@google.com>
Wed, 27 Nov 2024 23:46:59 +0000 (15:46 -0800)
committerSean Christopherson <seanjc@google.com>
Tue, 17 Dec 2024 00:15:27 +0000 (16:15 -0800)
Define sev_{,es_,snp_}guest() as "false" when SEV is disabled via Kconfig,
i.e. when CONFIG_KVM_AMD_SEV=n.  Despite the helpers being __always_inline,
gcc-12 is somehow incapable of realizing that the return value is a
compile-time constant and generates sub-optimal code.

Opportunistically clump the paths together to reduce the amount of
ifdeffery.

No functional change intended.

Link: https://lore.kernel.org/r/20241127234659.4046347-1-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/svm.h

index 43fa6a16eb1917821945ca8fdebf1caff1ddcb54..2f5d8b105eb01db157cff6bb32c0c5336cb435a1 100644 (file)
@@ -358,39 +358,32 @@ static __always_inline struct kvm_sev_info *to_kvm_sev_info(struct kvm *kvm)
        return &to_kvm_svm(kvm)->sev_info;
 }
 
+#ifdef CONFIG_KVM_AMD_SEV
 static __always_inline bool sev_guest(struct kvm *kvm)
 {
-#ifdef CONFIG_KVM_AMD_SEV
        struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
 
        return sev->active;
-#else
-       return false;
-#endif
 }
-
 static __always_inline bool sev_es_guest(struct kvm *kvm)
 {
-#ifdef CONFIG_KVM_AMD_SEV
        struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
 
        return sev->es_active && !WARN_ON_ONCE(!sev->active);
-#else
-       return false;
-#endif
 }
 
 static __always_inline bool sev_snp_guest(struct kvm *kvm)
 {
-#ifdef CONFIG_KVM_AMD_SEV
        struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
 
        return (sev->vmsa_features & SVM_SEV_FEAT_SNP_ACTIVE) &&
               !WARN_ON_ONCE(!sev_es_guest(kvm));
+}
 #else
-       return false;
+#define sev_guest(kvm) false
+#define sev_es_guest(kvm) false
+#define sev_snp_guest(kvm) false
 #endif
-}
 
 static inline bool ghcb_gpa_is_registered(struct vcpu_svm *svm, u64 val)
 {