[PATCH 6/9] KVM: x86: Add static asserts to document connection b/w TSS structs and macros

From: Sean Christopherson

Date: Thu Jun 25 2026 - 18:06:00 EST


Add static asserts to sanity check the I/O permission map and TSS size
macros against tss_segment_32. Alternatively, the macros could simply use
offsetof() and sizeof(), but having literal numbers makes it easier to
understand the bigger picture, and provides a good excuse for the sanity
checks.

Opportunistically add the necessary includes to make tss.h self sufficient.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/tss.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/arch/x86/kvm/tss.h b/arch/x86/kvm/tss.h
index 117bf8bec07d..55ced8975840 100644
--- a/arch/x86/kvm/tss.h
+++ b/arch/x86/kvm/tss.h
@@ -2,6 +2,10 @@
#ifndef __TSS_SEGMENT_H
#define __TSS_SEGMENT_H

+#include <linux/build_bug.h>
+#include <linux/stddef.h>
+#include <linux/types.h>
+
struct tss_segment_32 {
u32 prev_task_link;
u32 esp0;
@@ -64,4 +68,7 @@ struct tss_segment_16 {
#define RMODE_TSS_SIZE \
(TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)

+static_assert(offsetof(struct tss_segment_32, io_map) == TSS_IOPB_BASE_OFFSET);
+static_assert(sizeof(struct tss_segment_32) == TSS_BASE_SIZE);
+
#endif
--
2.55.0.rc0.799.gd6f94ed593-goog