Re: [PATCH v4 2/3] x86/insn-eval: Add insn_assign_reg() helper
From: Edgecombe, Rick P
Date: Tue Jun 30 2026 - 20:07:04 EST
On Thu, 2026-06-04 at 15:47 +0100, Kiryl Shutsemau (Meta) wrote:
> KVM's instruction emulator has a small helper, assign_register(), that
> writes a value into a sub-register with x86 partial-register-write
> semantics: 1- and 2-byte writes leave the upper bits of the destination
> untouched, 4-byte writes zero-extend to 64 bits, 8-byte writes overwrite
> the full register.
>
> The TDX guest #VE handler needs the same logic for port I/O emulation
> to get 32-bit zero-extension right. Rather than copy-pasting the helper,
> lift it to <asm/insn-eval.h> as insn_assign_reg() so both can use it.
>
> Rewrite the body using arithmetic instead of pointer punning so the
> helper does not depend on -fno-strict-aliasing or little-endian byte
> order, and add <asm/insn.h> to the header's includes so it builds
> standalone in callers that have not pulled it in transitively.
>
> No functional change.
>
> Signed-off-by: Kiryl Shutsemau <kas@xxxxxxxxxx>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
We should probably ping Sean/Paolo to ack this if we want Dave to take it. Is it
the plan?