Re: [PATCH v3 2/2] x86/early_printk: Add earlyprintk=tdx to drive the UART with TDVMCALLs
From: Kiryl Shutsemau
Date: Fri Sep 25 2026 - 07:31:09 EST
On Tue, Sep 22, 2026 at 02:20:07PM -0600, Vishal Verma wrote:
> @@ -111,6 +112,23 @@ ANNOTATE_NOENDBR_SYM(io_serial_out);
> DEFINE_STATIC_CALL(serial_in, io_serial_in);
> DEFINE_STATIC_CALL(serial_out, io_serial_out);
>
> +#ifdef CONFIG_INTEL_TDX_GUEST
> +/*
> + * A TDX guest cannot execute port I/O instructions, so ask the VMM to do it.
> + */
> +static __noendbr unsigned int tdx_serial_in(unsigned long addr, int offset)
> +{
> + return tdx_inb(addr + offset);
> +}
> +ANNOTATE_NOENDBR_SYM(tdx_serial_in);
> +
> +static __noendbr void tdx_serial_out(unsigned long addr, int offset, int value)
> +{
> + tdx_outb(value, addr + offset);
> +}
> +ANNOTATE_NOENDBR_SYM(tdx_serial_out);
> +#endif /* CONFIG_INTEL_TDX_GUEST */
> +
> static int early_serial_putc(unsigned char ch)
> {
> unsigned timeout = 0xffff;
> @@ -196,6 +214,22 @@ static __init void early_serial_init(char *s)
> early_serial_hw_init(divisor);
> }
>
> +#ifdef CONFIG_INTEL_TDX_GUEST
> +/*
> + * Use early_serial_base (COM1) and same default baud rate as
> + * "earlyprintk=serial"
> + */
> +static __init void early_serial_tdx_init(void)
> +{
> + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) {
> + static_call_update(serial_in, tdx_serial_in);
> + static_call_update(serial_out, tdx_serial_out);
> + }
> +
> + early_serial_hw_init(115200 / DEFAULT_BAUD);
> +}
> +#endif /* CONFIG_INTEL_TDX_GUEST */
> +
> static __noendbr void mem32_serial_out(unsigned long addr, int offset, int value)
> {
> u32 __iomem *vaddr = (u32 __iomem *)addr;
> @@ -414,6 +448,13 @@ static int __init setup_early_printk(char *buf)
> early_serial_init(buf + 4);
> early_console_register(&early_serial_console, keep);
> }
> +#ifdef CONFIG_INTEL_TDX_GUEST
> + if (!strncmp(buf, "tdx", 3)) {
> + early_serial_tdx_init();
> + early_console_register(&early_serial_console, keep);
> + break;
> + }
> +#endif
All these #ifdefs in early_printk.c can go. X86_FEATURE_TDX_GUEST is a
disabled feature without CONFIG_INTEL_TDX_GUEST, so
cpu_feature_enabled() folds to zero and the compiler drops the
static_call_update() calls and the wrappers with them.
Add stubs for tdx_inb() and tdx_outb() to the #else branch in
<asm/tdx.h> and make the "tdx" case unconditional.
--
Kiryl Shutsemau / Kirill A. Shutemov