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

From: H. Peter Anvin

Date: Tue May 12 2026 - 22:33:36 EST


On May 12, 2026 6:14:13 PM PDT, Dave Hansen <dave.hansen@xxxxxxxxx> 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.

Because zero extension only applies to dwords.

x86-64 has three subregisters per GPR:

Bits 7-0
Bits 15-8
Bits 63-16