Re: [PATCH v14 20/22] KVM: selftests: Implement MMIO WRITE for the TDX VM

From: Peter Fang

Date: Thu Aug 27 2026 - 05:22:41 EST


On Wed, Jul 22, 2026 at 11:13:25PM +0000, Lisa Wang wrote:
> From: Erdem Aktas <erdemaktas@xxxxxxxxxx>
>
> Implement the tdx_mmio_write() to allow TDX VMs to request MMIO
> emulation.
>
> Follow the Intel Guest-Hypervisor Communication Interface (GHCI) spec
> to the minimum extent that a spec-abiding TDX module will pass the
> request to KVM. Skip implementing the #VE handler as described in the
> GHCI spec to reduce selftests dependency.
>
> To perform emulated I/O, VMs use the TDG.VP.VMCALL instruction to
> request MMIO.
>

[ ... ]

> diff --git a/tools/testing/selftests/kvm/include/x86/tdx/tdx.h b/tools/testing/selftests/kvm/include/x86/tdx/tdx.h
> new file mode 100644
> index 000000000000..6355a30bb47f
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/include/x86/tdx/tdx.h
> @@ -0,0 +1,17 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef SELFTEST_KVM_TDX_TDX_H
> +#define SELFTEST_KVM_TDX_TDX_H
> +
> +#include <linux/types.h>
> +
> +#define TDG_VP_VMCALL_VE_REQUEST_MMIO 48
> +#define TDVMCALL_MMIO_WRITE 1

The indentation in these two lines is off.

> +
> +u64 __tdcall(u64 leaf, u64 r12, u64 r13, u64 r14, u64 r15);

As Xiaoyao already pointed out, this function name is misleading. This
is a TDG.VP.VMCALL (or a TDVMCALL), and r11 is a subfunction (the guest
kernel simply calls it "fn").

> +
> +.globl __tdcall
> +/*
> + * u64 __tdcall(u64 leaf, u64 r12, u64 r13, u64 r14, u64 r15)
> + */
> +__tdcall:
> + push %r12
> + push %r13
> + push %r14
> + push %r15
> +
> + /* Map C ABI fast arguments to TDX GHCI payload registers */
> + /* RDI=leaf, RSI=r12, RDX=r13, RCX=r14, R8=r15 */

[ ... ]

> +
> + pop %r15
> + pop %r14
> + pop %r13
> + pop %r12
> + ret

This is probably more of a nit... td_boot.S has:

.section .note.GNU-stack,"",%progbits

...to disable executable stack.

>
> --
> 2.55.0.229.g6434b31f56-goog
>
>