Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sairaj Kodilkar" <sarunkod@amd.com>, kvm@vger.kernel.org
Subject: Re: [PATCH v5 2/2] KVM: x86: Add support for cmpxchg16b emulation
Date: Thu, 26 Nov 2026 06:28:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-234852@kernel.org> (raw)
In-Reply-To: <20261126060515.2198-3-sarunkod@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] KVM: x86: em_cmpxchg8b() returns X86EMUL_UNHANDLEABLE instead
  of #UD
- [Medium] KVM: x86: em_cmpxchg8b() checks CPUID after destination
  memory read
--

commit 98ac1f736784d209fed9239b44c3756356d76e28
Author: Sairaj Kodilkar <sarunkod@amd.com>

KVM: x86: Add support for cmpxchg16b emulation

This commit adds 128-bit CMPXCHG16B emulation support to em_cmpxchg8b()
and emulator_cmpxchg_emulated(), and checks guest CPUID for
X86_FEATURE_CX8 and X86_FEATURE_CX16 before emulating CMPXCHG8B and
CMPXCHG16B.

[Severity: High]
In arch/x86/kvm/emulate.c, em_cmpxchg8b() returns X86EMUL_UNHANDLEABLE
when ctxt->ops->guest_has_cmpxchg8b(ctxt) or
ctxt->ops->guest_has_cmpxchg16b(ctxt) returns false. Should this call
emulate_ud(ctxt) instead, like em_rdpid() and em_movbe() do?

Returning X86EMUL_UNHANDLEABLE translates to EMULATION_FAILED without
queuing UD_VECTOR. Because group9 marks em_cmpxchg8b with PageTable, a
write to a shadow-protected page table calls
kvm_unprotect_and_retry_on_failure(), unprotecting the GFN and re-entering
the guest to execute the withheld instruction natively on the host CPU.
For non-page-table accesses such as MMIO, handle_emulation_failure() exits
to userspace with KVM_EXIT_INTERNAL_ERROR when running at L1 CPL 0 or when
exit_on_emulation_error is enabled, rather than injecting #UD into the
guest.

[Severity: Medium]
Also in arch/x86/kvm/emulate.c, does checking guest_has_cmpxchg8b() and
guest_has_cmpxchg16b() inside em_cmpxchg8b() perform the CPUID check too
late?

In x86_emulate_insn(), because ctxt->dst.type is OP_MEM and Mov is not
set, segmented_read() linearizes, validates, and reads the 8-byte or
16-byte destination operand before calling ctxt->execute(ctxt). If CX8 or
CX16 is withheld in guest CPUID, executing CMPXCHG8B or CMPXCHG16B on an
MMIO address exits to userspace with KVM_EXIT_MMIO to perform the read
before checking CPUID, and an unaligned 16-byte address or unmapped page
injects #GP(0) or #PF instead of #UD. Checking the feature in a
check_perm callback (with CheckPerm) would ensure #UD is raised before
any destination memory access.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126060515.2198-2-sarunkod@amd.com?part=2

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  6:05 [PATCH v5 0/2] Add support for cmpxchg16b emulation Sairaj Kodilkar
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 [this message]

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=sashiko-outbox-234852@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sarunkod@amd.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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