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 1/2] x86/uaccess: Extend CMPXCHG user helpers to 128-bit operands
Date: Thu, 26 Nov 2026 06:22:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-234836@kernel.org> (raw)
In-Reply-To: <20261126060515.2198-2-sarunkod@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] x86/uaccess: wrong fallback when CX16 is absent in
  unsafe_try_cmpxchg_user()
--

commit 41f10bc42b22924b13230c70050428ef6b8cacb9
Author: Sairaj Kodilkar <sarunkod@amd.com>

x86/uaccess: Extend CMPXCHG user helpers to 128-bit operands

This commit adds 128-bit operand support to the user-space cmpxchg helpers
on x86-64 using cmpxchg16b, and stubs the 128-bit helper on 32-bit kernels
with BUILD_BUG_ON().

> diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
> index 3a0dd3c2b233e..15425af59de92 100644
> --- a/arch/x86/include/asm/uaccess.h
> +++ b/arch/x86/include/asm/uaccess.h

[ ... ]

> @@ -580,6 +633,14 @@ extern void __try_cmpxchg_user_wrong_size(void);
>  	case 8:	__ret = __try_cmpxchg64_user_asm((__force u64 *)(_ptr), (_oldp),\
>  						 (_nval), _label);		\
>  		break;								\
> +	case 16:								\
> +		if (boot_cpu_has(X86_FEATURE_CX16))				\
> +			__ret = __try_cmpxchg128_user_asm(			\
> +					(__force u128 *)(_ptr),			\
> +					(_oldp), (_nval), _label);		\
> +		else								\
> +			__ret = 0;						\
> +		break;								\

[Severity: Medium]
Should the !boot_cpu_has(X86_FEATURE_CX16) fallback jump to _label instead
of setting __ret = 0?

unsafe_try_cmpxchg_user() returns false (0) on a compare-and-exchange value
mismatch after updating *_oldp, and jumps to _label when the access faults:

arch/x86/include/asm/uaccess.h:__try_cmpxchg_user() {
	int __ret = -EFAULT;						\
	__uaccess_begin_nospec();					\
	__ret = !unsafe_try_cmpxchg_user(_ptr, _oldp, _nval, _label);	\
_label:									\
	__uaccess_end();						\
	__ret;								\
}

Setting __ret = 0 leaves *_oldp unmodified and causes __try_cmpxchg_user()
to return 1 (value mismatch) instead of -EFAULT, so callers retrying on
mismatch can loop forever.

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

  reply	other threads:[~2026-11-26  6:22 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 [this message]
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=sashiko-outbox-234836@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