Re: [PATCH v4 2/2] x86/early_printk: Add earlyprintk=tdx to drive the UART with TDVMCALLs

From: Edgecombe, Rick P

Date: Fri Oct 09 2026 - 16:21:20 EST


On Mon, 2026-10-05 at 16:50 -0600, Vishal Verma wrote:
> A TDX guest cannot execute port I/O instructions directly, but
> earlyprintk's serial console still issues plain inb()/outb() and lets
> each one fault into the #VE handler to be emulated as a TDVMCALL.
>
> While that works, it is a roundabout way to get a character out.
> early_serial_putc() polls the LSR, and then writes a byte, but since the
> TDX guest can't directly do port I/O, a #VE exception is raised. The #VE
> handler must call TDG.VP.VEINFO.GET to find out what faulted, and then
> it can issue the TDVMCALL that does the actual work.
>
> This makes #VE a functional mechanism for doing I/O, which is not
> desirable, is unnecessarily complicated and fragile, and results in
> twice the number of calls into the TDX module.
>
> Instead, add an earlyprintk=tdx option, which can issue the TDVMCALLs
> directly. Add a pair of tdx_serial_in() and tdx_serial_out() accessors
> and set them up in this case.
>
> Note that the output does not appear any earlier - "earlyprintk=" is an
> early_param(), so the console is still registered from
> parse_early_param(). This only changes how the bytes leave the guest
> once it is up.
>
> LLMs were used under supervision to create this patch, to help
> understand the scope and mechanisms, create testing instrumentation
> (throwaway) to count #VEs in the serial vs tdx earlyprintk setups,
> and to drive lab machines to do this testing.
>
> Signed-off-by: Vishal Verma <vishal.l.verma@xxxxxxxxx>

Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>