Re: [PATCH v4 3/3] x86/tdx: Fix zero-extension for 32-bit port I/O

From: Kiryl Shutsemau

Date: Fri Jun 05 2026 - 07:58:14 EST


On Fri, Jun 05, 2026 at 03:10:39PM +0800, Binbin Wu wrote:
>
>
> On 6/4/2026 10:47 PM, Kiryl Shutsemau (Meta) wrote:
> > According to x86 architecture rules, 32-bit operations zero-extend the
> > result to 64 bits. The current implementation of handle_in() only masks
> > the lower 32 bits, which preserves the upper 32 bits of RAX when a
> > 32-bit port IN instruction is emulated.
> >
> > Use insn_assign_reg() to write the result back into RAX with proper
> > partial-register-write semantics: 1- and 2-byte forms leave the upper
> > bits untouched, the 4-byte form zero-extends to the full register.
> >
> > Fixes: 03149948832a ("x86/tdx: Port I/O: Add runtime hypercalls")
> > Reported-by: Borys Tsyrulnikov <tsyrulnikov.borys@xxxxxxxxx>
> > Link: https://lore.kernel.org/all/CAKw_Dz96rfSQc6Rn+9QBcUFHhmkK+9zu+P=bxowfZwxrATCBRg@xxxxxxxxxxxxxx/
> > Signed-off-by: Kiryl Shutsemau <kas@xxxxxxxxxx>
> > Cc: stable@xxxxxxxxxxxxxxx
>
> I think the concern sashiko commented in patch 2 is valid.

Yeah. I guess I'll just use the KVM implementation verbatim.

Dave, any objections?

--
Kiryl Shutsemau / Kirill A. Shutemov