* [PATCH] KVM: x86: Immediately fail the build when possible if required #define is missing
@ 2026-03-02 21:26 Sean Christopherson
2026-03-03 1:27 ` Yao Yuan
2026-04-03 15:13 ` Sean Christopherson
0 siblings, 2 replies; 3+ messages in thread
From: Sean Christopherson @ 2026-03-02 21:26 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Alexey Dobriyan
Guard usage of the must-be-defined macros in KVM's multi-include headers
with the existing #ifdefs that attempt to alert the developer to a missing
macro, and spit out an explicit #error message if a macro is missing, as
referencing the missing macro completely defeats the purpose of the #ifdef
(the compiler spews a ton of error messages and buries the targeted error
message).
Suggested-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm-x86-ops.h | 10 ++++++----
arch/x86/include/asm/kvm-x86-pmu-ops.h | 8 +++++---
arch/x86/kvm/vmx/vmcs_shadow_fields.h | 5 +++--
3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h
index de709fb5bd76..3776cf5382a2 100644
--- a/arch/x86/include/asm/kvm-x86-ops.h
+++ b/arch/x86/include/asm/kvm-x86-ops.h
@@ -1,8 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0 */
-#if !defined(KVM_X86_OP) || !defined(KVM_X86_OP_OPTIONAL)
-BUILD_BUG_ON(1)
-#endif
-
+#if !defined(KVM_X86_OP) || \
+ !defined(KVM_X86_OP_OPTIONAL) || \
+ !defined(KVM_X86_OP_OPTIONAL_RET0)
+#error Missing one or more KVM_X86_OP #defines
+#else
/*
* KVM_X86_OP() and KVM_X86_OP_OPTIONAL() are used to help generate
* both DECLARE/DEFINE_STATIC_CALL() invocations and
@@ -148,6 +149,7 @@ KVM_X86_OP_OPTIONAL(alloc_apic_backing_page)
KVM_X86_OP_OPTIONAL_RET0(gmem_prepare)
KVM_X86_OP_OPTIONAL_RET0(gmem_max_mapping_level)
KVM_X86_OP_OPTIONAL(gmem_invalidate)
+#endif
#undef KVM_X86_OP
#undef KVM_X86_OP_OPTIONAL
diff --git a/arch/x86/include/asm/kvm-x86-pmu-ops.h b/arch/x86/include/asm/kvm-x86-pmu-ops.h
index f0aa6996811f..d5452b3433b7 100644
--- a/arch/x86/include/asm/kvm-x86-pmu-ops.h
+++ b/arch/x86/include/asm/kvm-x86-pmu-ops.h
@@ -1,7 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0 */
-#if !defined(KVM_X86_PMU_OP) || !defined(KVM_X86_PMU_OP_OPTIONAL)
-BUILD_BUG_ON(1)
-#endif
+#if !defined(KVM_X86_PMU_OP) || \
+ !defined(KVM_X86_PMU_OP_OPTIONAL)
+#error Missing one or more KVM_X86_PMU_OP #defines
+#else
/*
* KVM_X86_PMU_OP() and KVM_X86_PMU_OP_OPTIONAL() are used to help generate
@@ -26,6 +27,7 @@ KVM_X86_PMU_OP_OPTIONAL(cleanup)
KVM_X86_PMU_OP_OPTIONAL(write_global_ctrl)
KVM_X86_PMU_OP(mediated_load)
KVM_X86_PMU_OP(mediated_put)
+#endif
#undef KVM_X86_PMU_OP
#undef KVM_X86_PMU_OP_OPTIONAL
diff --git a/arch/x86/kvm/vmx/vmcs_shadow_fields.h b/arch/x86/kvm/vmx/vmcs_shadow_fields.h
index cad128d1657b..67e821c2be6d 100644
--- a/arch/x86/kvm/vmx/vmcs_shadow_fields.h
+++ b/arch/x86/kvm/vmx/vmcs_shadow_fields.h
@@ -1,6 +1,6 @@
#if !defined(SHADOW_FIELD_RO) && !defined(SHADOW_FIELD_RW)
-BUILD_BUG_ON(1)
-#endif
+#error Must #define at least one of SHADOW_FIELD_RO or SHADOW_FIELD_RW
+#else
#ifndef SHADOW_FIELD_RO
#define SHADOW_FIELD_RO(x, y)
@@ -74,6 +74,7 @@ SHADOW_FIELD_RW(HOST_GS_BASE, host_gs_base)
/* 64-bit */
SHADOW_FIELD_RO(GUEST_PHYSICAL_ADDRESS, guest_physical_address)
SHADOW_FIELD_RO(GUEST_PHYSICAL_ADDRESS_HIGH, guest_physical_address)
+#endif
#undef SHADOW_FIELD_RO
#undef SHADOW_FIELD_RW
base-commit: 183bb0ce8c77b0fd1fb25874112bc8751a461e49
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86: Immediately fail the build when possible if required #define is missing
2026-03-02 21:26 [PATCH] KVM: x86: Immediately fail the build when possible if required #define is missing Sean Christopherson
@ 2026-03-03 1:27 ` Yao Yuan
2026-04-03 15:13 ` Sean Christopherson
1 sibling, 0 replies; 3+ messages in thread
From: Yao Yuan @ 2026-03-03 1:27 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel, Alexey Dobriyan
On Mon, Mar 02, 2026 at 01:26:19PM +0800, Sean Christopherson wrote:
> Guard usage of the must-be-defined macros in KVM's multi-include headers
> with the existing #ifdefs that attempt to alert the developer to a missing
> macro, and spit out an explicit #error message if a macro is missing, as
> referencing the missing macro completely defeats the purpose of the #ifdef
> (the compiler spews a ton of error messages and buries the targeted error
> message).
>
> Suggested-by: Alexey Dobriyan <adobriyan@gmail.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/include/asm/kvm-x86-ops.h | 10 ++++++----
> arch/x86/include/asm/kvm-x86-pmu-ops.h | 8 +++++---
> arch/x86/kvm/vmx/vmcs_shadow_fields.h | 5 +++--
> 3 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h
> index de709fb5bd76..3776cf5382a2 100644
> --- a/arch/x86/include/asm/kvm-x86-ops.h
> +++ b/arch/x86/include/asm/kvm-x86-ops.h
> @@ -1,8 +1,9 @@
> /* SPDX-License-Identifier: GPL-2.0 */
> -#if !defined(KVM_X86_OP) || !defined(KVM_X86_OP_OPTIONAL)
> -BUILD_BUG_ON(1)
> -#endif
> -
> +#if !defined(KVM_X86_OP) || \
> + !defined(KVM_X86_OP_OPTIONAL) || \
> + !defined(KVM_X86_OP_OPTIONAL_RET0)
> +#error Missing one or more KVM_X86_OP #defines
More clear than the BUILD_BUG_ON(1) to me.
Reviewed-by: Yuan Yao <yaoyuan@linux.alibaba.com>
> +#else
> /*
> * KVM_X86_OP() and KVM_X86_OP_OPTIONAL() are used to help generate
> * both DECLARE/DEFINE_STATIC_CALL() invocations and
> @@ -148,6 +149,7 @@ KVM_X86_OP_OPTIONAL(alloc_apic_backing_page)
> KVM_X86_OP_OPTIONAL_RET0(gmem_prepare)
> KVM_X86_OP_OPTIONAL_RET0(gmem_max_mapping_level)
> KVM_X86_OP_OPTIONAL(gmem_invalidate)
> +#endif
>
> #undef KVM_X86_OP
> #undef KVM_X86_OP_OPTIONAL
> diff --git a/arch/x86/include/asm/kvm-x86-pmu-ops.h b/arch/x86/include/asm/kvm-x86-pmu-ops.h
> index f0aa6996811f..d5452b3433b7 100644
> --- a/arch/x86/include/asm/kvm-x86-pmu-ops.h
> +++ b/arch/x86/include/asm/kvm-x86-pmu-ops.h
> @@ -1,7 +1,8 @@
> /* SPDX-License-Identifier: GPL-2.0 */
> -#if !defined(KVM_X86_PMU_OP) || !defined(KVM_X86_PMU_OP_OPTIONAL)
> -BUILD_BUG_ON(1)
> -#endif
> +#if !defined(KVM_X86_PMU_OP) || \
> + !defined(KVM_X86_PMU_OP_OPTIONAL)
> +#error Missing one or more KVM_X86_PMU_OP #defines
> +#else
>
> /*
> * KVM_X86_PMU_OP() and KVM_X86_PMU_OP_OPTIONAL() are used to help generate
> @@ -26,6 +27,7 @@ KVM_X86_PMU_OP_OPTIONAL(cleanup)
> KVM_X86_PMU_OP_OPTIONAL(write_global_ctrl)
> KVM_X86_PMU_OP(mediated_load)
> KVM_X86_PMU_OP(mediated_put)
> +#endif
>
> #undef KVM_X86_PMU_OP
> #undef KVM_X86_PMU_OP_OPTIONAL
> diff --git a/arch/x86/kvm/vmx/vmcs_shadow_fields.h b/arch/x86/kvm/vmx/vmcs_shadow_fields.h
> index cad128d1657b..67e821c2be6d 100644
> --- a/arch/x86/kvm/vmx/vmcs_shadow_fields.h
> +++ b/arch/x86/kvm/vmx/vmcs_shadow_fields.h
> @@ -1,6 +1,6 @@
> #if !defined(SHADOW_FIELD_RO) && !defined(SHADOW_FIELD_RW)
> -BUILD_BUG_ON(1)
> -#endif
> +#error Must #define at least one of SHADOW_FIELD_RO or SHADOW_FIELD_RW
> +#else
>
> #ifndef SHADOW_FIELD_RO
> #define SHADOW_FIELD_RO(x, y)
> @@ -74,6 +74,7 @@ SHADOW_FIELD_RW(HOST_GS_BASE, host_gs_base)
> /* 64-bit */
> SHADOW_FIELD_RO(GUEST_PHYSICAL_ADDRESS, guest_physical_address)
> SHADOW_FIELD_RO(GUEST_PHYSICAL_ADDRESS_HIGH, guest_physical_address)
> +#endif
>
> #undef SHADOW_FIELD_RO
> #undef SHADOW_FIELD_RW
>
> base-commit: 183bb0ce8c77b0fd1fb25874112bc8751a461e49
> --
> 2.53.0.473.g4a7958ca14-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86: Immediately fail the build when possible if required #define is missing
2026-03-02 21:26 [PATCH] KVM: x86: Immediately fail the build when possible if required #define is missing Sean Christopherson
2026-03-03 1:27 ` Yao Yuan
@ 2026-04-03 15:13 ` Sean Christopherson
1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2026-04-03 15:13 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Alexey Dobriyan
On Mon, 02 Mar 2026 13:26:19 -0800, Sean Christopherson wrote:
> Guard usage of the must-be-defined macros in KVM's multi-include headers
> with the existing #ifdefs that attempt to alert the developer to a missing
> macro, and spit out an explicit #error message if a macro is missing, as
> referencing the missing macro completely defeats the purpose of the #ifdef
> (the compiler spews a ton of error messages and buries the targeted error
> message).
>
> [...]
Applied to kvm-x86 misc, many weeks ago.
[1/1] KVM: x86: Immediately fail the build when possible if required #define is missing
https://github.com/kvm-x86/linux/commit/55be358e17af
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-03 15:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-02 21:26 [PATCH] KVM: x86: Immediately fail the build when possible if required #define is missing Sean Christopherson
2026-03-03 1:27 ` Yao Yuan
2026-04-03 15:13 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®