[PATCH v2 11/36] KVM: nVMX: Add alignment check for struct vmcs12
From: isaku . yamahata
Date: Thu Mar 05 2026 - 12:51:38 EST
From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
As struct vmcs12 has __packed attributes and it has manual alignment,
it's easy to add unaligned member without any warnings. Add alignment
check to avoid accidental misalignment.
Signed-off-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
---
arch/x86/kvm/vmx/vmcs12.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/vmcs12.h b/arch/x86/kvm/vmx/vmcs12.h
index 21cd1b75e4fd..8c9d4c22b960 100644
--- a/arch/x86/kvm/vmx/vmcs12.h
+++ b/arch/x86/kvm/vmx/vmcs12.h
@@ -217,7 +217,8 @@ struct __packed vmcs12 {
* although appending fields and/or filling gaps is obviously allowed.
*/
#define CHECK_OFFSET(field, loc) \
- ASSERT_STRUCT_OFFSET(struct vmcs12, field, loc)
+ ASSERT_STRUCT_OFFSET(struct vmcs12, field, loc); \
+ static_assert(loc % __alignof(((struct vmcs12 *)0)->field) == 0)
static inline void vmx_check_vmcs12_offsets(void)
{
--
2.45.2