Re: [PATCH] KVM: x86: use inlines instead of macros for is_sev_*guest

From: Paolo Bonzini

Date: Tue Apr 14 2026 - 11:34:06 EST


On 4/13/26 23:41, Sean Christopherson wrote:
On Mon, Apr 13, 2026, Paolo Bonzini wrote:
This helps avoiding more embarrassment to this maintainer,

Not building SEV support before pushing to kvm/queue is certainly a choice :-D

Fortunately, the part where I actually do more than a build smoke test and push to kvm/next has some automation... but the bots are too fast these days.

As called out in commit 45d522d3ee9c ("KVM: SVM: Macrofy SEV=n versions of
sev_xxx_guest()"), use of macros is intentional as gcc-12 at least generates
suboptimal code if there's a proper function.

That said, gcc-11 (I don't think I have gcc-12 laying around anywhere) generates
identical code for all of kvm-amd.ko with and without macros, so maybe whatever I
saw a transient issue? I don't have a strong motivation for caring about any
version of gcc, so I'm a-ok using __always_inline functions.

Yeah, it seems strange for the compiler to have this problem except at -O0.

#else
-static __always_inline bool is_sev_guest(struct kvm_vcpu *vcpu)
-{
- return false;
-}
-static __always_inline bool is_sev_es_guest(struct kvm_vcpu *vcpu)
-{
- return false;
-}
-
-static __always_inline bool is_sev_snp_guest(struct kvm_vcpu *vcpu)
-{
- return false;
-}
+#define is_sev_guest(vcpu) ({ BUILD_BUG_ON_INVALID((vcpu)->kvm); false; })
+#define is_sev_es_guest(vcpu) ({ BUILD_BUG_ON_INVALID((vcpu)->kvm); false; })
+#define is_sev_snp_guest(vcpu) ({ BUILD_BUG_ON_INVALID((vcpu)->kvm); false; })

BUILD_BUG_ON_INVALID isn't great because it doesn't have type checking.

Paolo