]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0007-bug-introduce-ASSERT_STRUCT_OFFSET.patch
prepare for 6.2 release
[pve-kernel.git] / patches / kernel / 0007-bug-introduce-ASSERT_STRUCT_OFFSET.patch
CommitLineData
83250735
TL
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Maxim Levitsky <mlevitsk@redhat.com>
3Date: Wed, 3 Aug 2022 18:49:59 +0300
4Subject: [PATCH] bug: introduce ASSERT_STRUCT_OFFSET
826eb0ff
FG
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
83250735
TL
8
9ASSERT_STRUCT_OFFSET allows to assert during the build of
10the kernel that a field in a struct have an expected offset.
11
12KVM used to have such macro, but there is almost nothing KVM specific
13in it so move it to build_bug.h, so that it can be used in other
14places in KVM.
15
16Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
17Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
826eb0ff 18Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
83250735
TL
19---
20 arch/x86/kvm/vmx/vmcs12.h | 5 ++---
21 include/linux/build_bug.h | 9 +++++++++
22 2 files changed, 11 insertions(+), 3 deletions(-)
23
24diff --git a/arch/x86/kvm/vmx/vmcs12.h b/arch/x86/kvm/vmx/vmcs12.h
3ae8384f 25index 746129ddd5ae..01936013428b 100644
83250735
TL
26--- a/arch/x86/kvm/vmx/vmcs12.h
27+++ b/arch/x86/kvm/vmx/vmcs12.h
28@@ -208,9 +208,8 @@ struct __packed vmcs12 {
29 /*
30 * For save/restore compatibility, the vmcs12 field offsets must not change.
31 */
32-#define CHECK_OFFSET(field, loc) \
33- BUILD_BUG_ON_MSG(offsetof(struct vmcs12, field) != (loc), \
34- "Offset of " #field " in struct vmcs12 has changed.")
35+#define CHECK_OFFSET(field, loc) \
36+ ASSERT_STRUCT_OFFSET(struct vmcs12, field, loc)
37
38 static inline void vmx_check_vmcs12_offsets(void)
39 {
40diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h
41index e3a0be2c90ad..3aa3640f8c18 100644
42--- a/include/linux/build_bug.h
43+++ b/include/linux/build_bug.h
44@@ -77,4 +77,13 @@
45 #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
46 #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
47
48+
49+/*
50+ * Compile time check that field has an expected offset
51+ */
52+#define ASSERT_STRUCT_OFFSET(type, field, expected_offset) \
53+ BUILD_BUG_ON_MSG(offsetof(type, field) != (expected_offset), \
54+ "Offset of " #field " in " #type " has changed.")
55+
56+
57 #endif /* _LINUX_BUILD_BUG_H */