Re: [PATCH 2/3] KVM: VMX: Disallowing using to_vmx() in common VT code

From: Binbin Wu

Date: Mon Aug 17 2026 - 02:15:31 EST


On 8/15/2026 12:11 AM, Sean Christopherson wrote:
> Poison to_vmx() in main.c and posted_intr.c so that attempting to interpret
> the vCPU as a VMX vCPU will fail at compile time, as opposed to failing at
> runtime, or worse corrupting state without outright failing.
>
> Note, to_tdx() is buried in tdx.c, i.e. isn't broadly reachable, and so
> doesn't need the same treatment as to_vmx().
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>

Nit:
About the short log, use "Disallow using" instead of "Disallowing using"?

Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>> ---
> arch/x86/kvm/vmx/main.c | 2 ++
> arch/x86/kvm/vmx/posted_intr.c | 2 ++
> 2 files changed, 4 insertions(+)
>
> diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c
> index aa5b44bb212b..95d89d809c19 100644
> --- a/arch/x86/kvm/vmx/main.c
> +++ b/arch/x86/kvm/vmx/main.c
> @@ -11,6 +11,8 @@
> #include "tdx.h"
> #include "tdx_arch.h"
>
> +#pragma GCC poison to_vmx
> +
> #ifdef CONFIG_KVM_INTEL_TDX
> static_assert(offsetof(struct vcpu_vmx, vt) == offsetof(struct vcpu_tdx, vt));
>
> diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
> index 4a6d9a17da23..24221ba553be 100644
> --- a/arch/x86/kvm/vmx/posted_intr.c
> +++ b/arch/x86/kvm/vmx/posted_intr.c
> @@ -14,6 +14,8 @@
> #include "vmx.h"
> #include "tdx.h"
>
> +#pragma GCC poison to_vmx
> +
> /*
> * Maintain a per-CPU list of vCPUs that need to be awakened by wakeup_handler()
> * when a WAKEUP_VECTOR interrupted is posted. vCPUs are added to the list when