Skip to content

Add support for cmpxchg16b emulation

Sairaj Kodilkar kvm lkml sashiko-reviews 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 1 replyIn review
  2. v32 patches 7 repliesSuperseded
  3. v22 patches 5 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v11 patch5 repliesSuperseded

Changes in v4 from the cover letter

https://lore.kernel.org/all/[email protected]/
Patch1: Split the old value across RAX and RDX using "+a" and "+b" instead of

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2x86/uaccess: Extend CMPXCHG user helpers to 128-bit operandsarch/x86/include/asm/uaccess.h+63 -11 reply
2/2KVM: x86: Add support for cmpxchg16b emulationarch/x86/include/asm/uaccess.h arch/x86/kvm/emulate.c arch/x86/kvm/kvm_emulate.h +1 more+47 -180 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/2] Add support for cmpxchg16b emulation

This series adds 128-bit compare-exchange support needed for KVM to emulate guest cmpxchg16b instructions.

The AMD IOMMU driver updates 256-bit device table entries with two 128-bit cmpxchg operations. For hardware-accelerated vIOMMU, QEMU traps those DTE accesses to install nested page tables [1]. KVM must emulate guest cmpxchg16b on the trapped MMIO regions; without that, DTE access emulation fails.

Patch 1: extends the x86 user CMPXCHG helpers with __try_cmpxchg128_user_asm() (cmpxchg16b on x86-64), wired into unsafe_try_cmpxchg_user().

Patch 2: extends KVM CMPXCHG8B emulation to 16-byte operands (REX.W=1) and uses the new helper for atomic 16-byte compare-exchange on guest RAM via emulator_cmpxchg_emulated().

You can find the KUT to test this series at [2].

[1] https://github.com/AMDESE/qemu-iommu/blob/wip/for_iommufd_hw_queue-v8_amd_viommu_20260106/hw/i386/amd_viommu.c#L517
[2] https://lore.kernel.org/kvm/[email protected]/T/#u

Changes since v3:
https://lore.kernel.org/all/[email protected]/
Patch1: Split the old value across RAX and RDX using "+a" and "+b" instead of

	using "+A" [Dave]

Patch 2: Use __c instead of ctx in cmpxchg macro [Sashiko]

Changes since v2:
https://lore.kernel.org/all/[email protected]/
Patch 1: Trigger build failure if __try_cmpxchg128_user_asm is called on 32 bit
machines [Sean]

Sairaj Kodilkar (2):
x86/uaccess: Extend CMPXCHG user helpers to 128-bit operands
KVM: x86: Add support for cmpxchg16b emulation

 arch/x86/include/asm/uaccess.h | 64 +++++++++++++++++++++++++++++++++-
 arch/x86/kvm/emulate.c         | 50 +++++++++++++++++---------
 arch/x86/kvm/kvm_emulate.h     |  6 ++++
 arch/x86/kvm/x86.c             |  9 ++++-
 4 files changed, 111 insertions(+), 18 deletions(-)

base-commit: 45c13f3f9e3bb15fd89ff2864c6f627a3b4b4229

Signature · 1 line
2.34.1