mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-17 16:36:45 -04:00
KVM: x86: Immediately fail the build when possible if required #define is missing
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> Reviewed-by: Yuan Yao <yaoyuan@linux.alibaba.com> Link: https://patch.msgid.link/20260302212619.710873-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user