[PATCH v2 6/8] KVM: VMX: Use dummy pseudo-overlay struct for to_vt() and vt_to_vcpu()

From: Sean Christopherson

Date: Wed Aug 26 2026 - 13:29:49 EST


Define a combined vcpu_vmx_tdx structure to represent the common layout of
vcpu_vmx and vcpu_tdx, instead of having vcpu_tdx piggyback vcpu_vmx. I.e.
require VMX and TDX to match the common definition, not for TDX to match
VMX. This will allow moving to_vt() and vt_to_vcpu() to common.h where
they belong.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/vmx/main.c | 4 +++-
arch/x86/kvm/vmx/vmx.h | 9 +++++++--
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c
index 8ac6ea58b481..0151baa56598 100644
--- a/arch/x86/kvm/vmx/main.c
+++ b/arch/x86/kvm/vmx/main.c
@@ -13,8 +13,10 @@

#pragma GCC poison to_vmx

+static_assert(offsetof(struct vcpu_vmx_tdx, vt) == offsetof(struct vcpu_vmx, vt));
+
#ifdef CONFIG_KVM_INTEL_TDX
-static_assert(offsetof(struct vcpu_vmx, vt) == offsetof(struct vcpu_tdx, vt));
+static_assert(offsetof(struct vcpu_vmx_tdx, vt) == offsetof(struct vcpu_tdx, vt));

static void vt_disable_virtualization_cpu(void)
{
diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
index dc8517f15bc4..0415d328e1a5 100644
--- a/arch/x86/kvm/vmx/vmx.h
+++ b/arch/x86/kvm/vmx/vmx.h
@@ -304,14 +304,19 @@ struct kvm_vmx {
u64 *pid_table;
};

+struct vcpu_vmx_tdx {
+ struct kvm_vcpu vcpu;
+ struct vcpu_vt vt;
+};
+
static __always_inline struct vcpu_vt *to_vt(struct kvm_vcpu *vcpu)
{
- return &(container_of(vcpu, struct vcpu_vmx, vcpu)->vt);
+ return &(container_of(vcpu, struct vcpu_vmx_tdx, vcpu)->vt);
}

static __always_inline struct kvm_vcpu *vt_to_vcpu(struct vcpu_vt *vt)
{
- return &(container_of(vt, struct vcpu_vmx, vt)->vcpu);
+ return &(container_of(vt, struct vcpu_vmx_tdx, vt)->vcpu);
}

static __always_inline union vmx_exit_reason vmx_get_exit_reason(struct kvm_vcpu *vcpu)
--
2.55.0.887.g758fc8c411-goog