Re: [PATCH v2 2/2] x86/tdx: Fix zero-extension for 32-bit port I/O
From: Kiryl Shutsemau
Date: Fri May 22 2026 - 12:29:38 EST
On Tue, May 12, 2026 at 06:14:13PM -0700, Dave Hansen wrote:
> On 4/28/26 05:56, Kiryl Shutsemau (Meta) wrote:
> > + if (size == 4)
> > + regs->ax = 0;
> > + else
> > + regs->ax &= ~mask;
>
> I haven't thought about this _that_ much, but this feels wrong. Why is
> is 4 so special cased?
>
> Also, what _are_ the limits on the registers that 'in' can be used on?
>
> RAX - n/a, no 64-bit I/O
> EAX - size=4
> AX - size=2
> AH - n/a no encoding for inb
> AL - size=1
>
> I'd find this much easier to grasp if there was a nice table of what the
> registers, sizes, and masks ended up being usable. As usual, x86 is
> "fun" here.
How about this for the comment:
/*
* IN writes the result into a sub-register of RAX. Only the
* 32-bit form zero-extends; the smaller forms leave the upper
* bits untouched:
*
* insn dest size bits written bits preserved
* inb AL 1 RAX[ 7: 0] RAX[63: 8]
* inw AX 2 RAX[15: 0] RAX[63:16]
* inl EAX 4 RAX[63: 0] (none, zero-extended)
*
* 'mask' only covers the low 'size' bytes, which is exactly
* the range affected for size 1 and 2. For size 4 the write
* also clears RAX[63:32], so widen the clear-mask.
*/
--
Kiryl Shutsemau / Kirill A. Shutemov