[PATCH v4 0/2] x86/tdx: Use TDVMCALLs directly for earlyprintk

From: Vishal Verma

Date: Mon Oct 05 2026 - 18:51:22 EST


Background
==========

TDX guests have early_printk support, but it is through a roundabout way
using a #VE exception as a functional mechanism. The exception handler
has to use TDG.VP.VEINFO.GET to find out what faulted, and then issue
the TDVMCALL. Simplify this by using a TDVMCALL from the guest which can
directly perform the port I/O.

Patch details
=============

Patch 1 is a cleanup that moves the port I/O direction constants to
arch/x86/include/asm/shared/tdx.h.

Patch 2: Add a new earlyprintk=tdx option, which calls the new
tdx_serial_in() / tdx_serial_out() helpers to perform the port I/O
directly using TDVMCALLs.

The serial earlyprintk path is left as is - TD guests using this will
still take a #VE exception, and the exception handler will perform the
I/O.

Testing
=======

Added a counter for the number of COM1 port I/O #VEs handled:

no earlyprintk - ~63000
earlyprintk=ttyS0 - ~61000
earlyprintk=tdx - ~35000

The new tdx option nearly halves the number of #VEs handled.

Additionally, ran the usual suite of CI testing, which covers KVM self
tests, KVM unit tests, and Avocado KVM tests without any regressions.

Signed-off-by: Vishal Verma <vishal.l.verma@xxxxxxxxx>
---
Changes in v4:
- Rename the tdx_inb()/tdx_outb() helpers directly to the serial
accessors with __noendbr annotations, and remove the config ifdefs
from early_printk.c. (Kiryl)
- Rebase to v7.3-rc6
- Link to v3: https://patch.msgid.link/20260922-b4-tdx_earlyprintk_tdcalls-v3-0-6ebaa599df10@xxxxxxxxx

Changes in v3:
- Drop the ttySN and baudrate option parsing for earlyprintk=tdx (Dave Hansen)
- Link to v2: https://patch.msgid.link/20260921-b4-tdx_earlyprintk_tdcalls-v2-0-ad1fde3f25fd@xxxxxxxxx

Changes in v2:
- Rebase to v7.3-rc4
- Move the TDX hypercall helpers into coco/tdx/tdx.c (Kiryl)
- Add a new earlyprintk=tdx option that implements the direct TDVMCALL
path (Dave Hansen)
- Link to v1: https://patch.msgid.link/20260910-b4-tdx_earlyprintk_tdcalls-v1-0-4b2b1bf9001b@xxxxxxxxx

---
Vishal Verma (2):
x86/tdx: Move port I/O definitions to a shared header
x86/early_printk: Add earlyprintk=tdx to drive the UART with TDVMCALLs

Documentation/admin-guide/kernel-parameters.txt | 8 ++++++
arch/x86/include/asm/shared/tdx.h | 6 ++++
arch/x86/include/asm/tdx.h | 4 +++
arch/x86/boot/compressed/tdx.c | 4 +--
arch/x86/coco/tdx/tdx.c | 37 +++++++++++++++++++++----
arch/x86/kernel/early_printk.c | 20 +++++++++++++
6 files changed, 71 insertions(+), 8 deletions(-)
---
base-commit: a90ee4305c4a5df72c11b31dacfdc76e00fcf78a
change-id: 20260903-b4-tdx_earlyprintk_tdcalls-40d1b21a8ba2

Best regards,
--
Vishal Verma <vishal.l.verma@xxxxxxxxx>