Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sairaj Kodilkar <sarunkod@amd.com>
To: "H. Peter Anvin" <hpa@zytor.com>, Borislav Petkov <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	Ingo Molnar <mingo@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	Sairaj Kodilkar <sarunkod@amd.com>,
	"Sean Christopherson" <seanjc@google.com>,
	Thomas Gleixner <tglx@kernel.org>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <x86@kernel.org>
Cc: <Vasant.Hegde@amd.com>, <Suravee.Suthikulpanit@amd.com>
Subject: [PATCH v5 0/2] Add support for cmpxchg16b emulation
Date: Thu, 26 Nov 2026 11:35:13 +0530	[thread overview]
Message-ID: <20261126060515.2198-1-sarunkod@amd.com> (raw)

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/20260706062153.346-1-sarunkod@amd.com/T/#u

==================

Changes since v4:
https://lore.kernel.org/all/20260908074739.10748-1-sarunkod@amd.com/
Patch 2: Check if guest has cmpxchg(8/16)b capability present before emulating
	 it [sashiko].

Changes since v3:
https://lore.kernel.org/all/20260826070004.8100-1-sarunkod@amd.com/
Patch 1: 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/20260706063035.1139-1-sarunkod@amd.com/
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 | 63 +++++++++++++++++++++++++++++++++-
 arch/x86/kvm/emulate.c         | 52 ++++++++++++++++++++--------
 arch/x86/kvm/kvm_emulate.h     |  8 +++++
 arch/x86/kvm/x86.c             | 19 +++++++++-
 4 files changed, 126 insertions(+), 16 deletions(-)

-- 
2.34.1


             reply	other threads:[~2026-11-26  6:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  6:05 Sairaj Kodilkar [this message]
2026-11-26  6:05 ` [PATCH v5 1/2] x86/uaccess: Extend CMPXCHG user helpers to 128-bit operands Sairaj Kodilkar
2026-11-26  6:22   ` sashiko-bot
2026-11-26  6:05 ` [PATCH v5 2/2] KVM: x86: Add support for cmpxchg16b emulation Sairaj Kodilkar
2026-11-26  6:28   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126060515.2198-1-sarunkod@amd.com \
    --to=sarunkod@amd.com \
    --cc=Suravee.Suthikulpanit@amd.com \
    --cc=Vasant.Hegde@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox