[PATCH 00/10] KVM: emulate: enable AVX moves

Paolo Bonzini posted 10 patches 2 months, 3 weeks ago
arch/x86/kvm/emulate.c     | 320 ++++++++++++++++++++++++++-----------
arch/x86/kvm/fpu.h         |  62 +++++++
arch/x86/kvm/kvm_emulate.h |  20 ++-
arch/x86/kvm/x86.c         |   9 ++
4 files changed, 311 insertions(+), 100 deletions(-)
[PATCH 00/10] KVM: emulate: enable AVX moves
Posted by Paolo Bonzini 2 months, 3 weeks ago
Over a year ago, Keith Busch posted an RFC patch to enable VMOVDQA
and VMOVDQU instructions in the KVM emulator.  The reason to do so
is that people are using QEMU to emulate fancy devices whose drivers
use those instructions with BARs that, on real hardware, would
presumably support write combining.  These same people obviously
would appreciate being able to use KVM instead of emulation, hence
the request.

The original patch was not bad at all, but missed a few details:

- checking in XCR0 if AVX is enabled (which also protects against
  *hosts* with AVX disabled)

- 32-bit support

- clearing the high bytes of AVX registers if VEX.L=0

- checking some invalid prefix combinations

The ugly parts are in patch 7, which has to juggle the fact that the
same instruction can decode to SSE and AVX, and we only know which are
valid after all the groups are handled.

While at it I also included a small refactoring taken out of the
APX series, by Chang S. Bae, some cleanups, and an extra MOVNTDQ
instruction.

Paolo

Chang S. Bae (1):
  KVM: x86: Refactor REX prefix handling in instruction emulation

Paolo Bonzini (9):
  KVM: emulate: add MOVNTDQA
  KVM: emulate: move Src2Shift up one bit
  KVM: emulate: improve formatting of flags table
  KVM: emulate: move op_prefix to struct x86_emulate_ctxt
  KVM: emulate: share common register decoding code
  KVM: emulate: add get_xcr callback
  KVM: emulate: add AVX support to register fetch and writeback
  KVM: emulate: decode VEX prefix
  KVM: emulate: enable AVX moves

 arch/x86/kvm/emulate.c     | 320 ++++++++++++++++++++++++++-----------
 arch/x86/kvm/fpu.h         |  62 +++++++
 arch/x86/kvm/kvm_emulate.h |  20 ++-
 arch/x86/kvm/x86.c         |   9 ++
 4 files changed, 311 insertions(+), 100 deletions(-)

-- 
2.43.5
Re: [PATCH 00/10] KVM: emulate: enable AVX moves
Posted by Sean Christopherson 2 months, 2 weeks ago
On Thu, 13 Nov 2025 19:36:23 -0500, Paolo Bonzini wrote:
> Over a year ago, Keith Busch posted an RFC patch to enable VMOVDQA
> and VMOVDQU instructions in the KVM emulator.  The reason to do so
> is that people are using QEMU to emulate fancy devices whose drivers
> use those instructions with BARs that, on real hardware, would
> presumably support write combining.  These same people obviously
> would appreciate being able to use KVM instead of emulation, hence
> the request.
> 
> [...]

Applied to kvm-x86 misc, with massaged shortlogs to make it obvious these are
x86 changes.

[1/10] KVM: x86: Add support for emulating MOVNTDQA
       https://github.com/kvm-x86/linux/commit/c57d9bafbd0b
[2/10] KVM: x86: Move Src2Shift up one bit (use bits 36:32 for Src2 in the emulator)
       https://github.com/kvm-x86/linux/commit/3f3fc58df502
[3/10] KVM: x86: Improve formatting of the emulator's flags table
       https://github.com/kvm-x86/linux/commit/3d8834a0d1c9
[4/10] KVM: x86: Move op_prefix to struct x86_emulate_ctxt (from x86_decode_insn())
       https://github.com/kvm-x86/linux/commit/1a84b07acaa4
[5/10] KVM: x86: Share emulator's common register decoding code
       https://github.com/kvm-x86/linux/commit/7e11eec989c8
[6/10] KVM: x86: Add x86_emulate_ops.get_xcr() callback
       https://github.com/kvm-x86/linux/commit/f106797f81d6
[7/10] KVM: x86: Add AVX support to the emulator's register fetch and writeback
       https://github.com/kvm-x86/linux/commit/4cb21be4c3b0
[8/10] KVM: x86: Refactor REX prefix handling in instruction emulation
       https://github.com/kvm-x86/linux/commit/825f0aece084
[9/10] KVM: x86: Add emulator support for decoding VEX prefixes
       https://github.com/kvm-x86/linux/commit/f0585a714a75
[10/10] KVM: x86: Enable support for emulating AVX MOV instructions
       https://github.com/kvm-x86/linux/commit/ebec25438f3d

--
https://github.com/kvm-x86/linux/tree/next
Re: [PATCH 00/10] KVM: emulate: enable AVX moves
Posted by Chang S. Bae 2 months, 3 weeks ago
On 11/13/2025 4:36 PM, Paolo Bonzini wrote:
> 
> While at it I also included a small refactoring taken out of the
> APX series, by Chang S. Bae, some cleanups, and an extra MOVNTDQ
> instruction.

As I'm preparing REX2 support, appreciate this effort! I’ve added my 
review tag for the obvious and nice cleanups.

I can also look further at the VEX pieces and other related bits, and
would like to follow up with test tags unless anything else comes up.

Thanks,
Chang
Re: [PATCH 00/10] KVM: emulate: enable AVX moves
Posted by Keith Busch 2 months, 3 weeks ago
On Thu, Nov 13, 2025 at 07:36:23PM -0500, Paolo Bonzini wrote:
> Over a year ago, Keith Busch posted an RFC patch to enable VMOVDQA
> and VMOVDQU instructions in the KVM emulator.  The reason to do so
> is that people are using QEMU to emulate fancy devices whose drivers
> use those instructions with BARs that, on real hardware, would
> presumably support write combining.  These same people obviously
> would appreciate being able to use KVM instead of emulation, hence
> the request.

Thanks so much! We do still use this, so I'm happy to see this moving. I
know it's been some time in the making, but I can appreciate this is
pretty gnarly and the details are important. I will be happy to give
this a run through the emulation devices, though it may be another week
or so before I can give it a spin.