From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: use inlines instead of macros for is_sev_*guest
Date: Mon, 13 Apr 2026 14:41:43 -0700 [thread overview]
Message-ID: <ad1jFw5IPY78nDDw@google.com> (raw)
In-Reply-To: <20260413170009.380778-1-pbonzini@redhat.com>
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
> but also will catch mistakes more easily for others.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/svm/svm.h | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
> index fd0652b32c81..a10668d17a16 100644
> --- a/arch/x86/kvm/svm/svm.h
> +++ b/arch/x86/kvm/svm/svm.h
> @@ -422,9 +422,19 @@ static __always_inline bool is_sev_snp_guest(struct kvm_vcpu *vcpu)
> return ____sev_snp_guest(vcpu->kvm);
> }
> #else
> -#define is_sev_guest(vcpu) false
> -#define is_sev_es_guest(vcpu) false
> -#define is_sev_snp_guest(vcpu) false
> +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;
> +}
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.
Alternatively, e.g. if a "bad code generation" issue pops up again, we could use
BUILD_BUG_ON_INVALID() to validate the input.
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 5440486a3d32..3f572f30f28c 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -425,19 +425,9 @@ static __always_inline bool is_sev_snp_guest(struct kvm_vcpu *vcpu)
return ____sev_snp_guest(vcpu->kvm);
}
#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; })
#endif
static inline bool ghcb_gpa_is_registered(struct vcpu_svm *svm, u64 val)
next prev parent reply other threads:[~2026-04-13 21:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 17:00 [PATCH] KVM: x86: use inlines instead of macros for is_sev_*guest Paolo Bonzini
2026-04-13 21:41 ` Sean Christopherson [this message]
2026-04-14 15:33 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ad1jFw5IPY78nDDw@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.