public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Yeoreum Yun <yeoreum.yun@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev,
	kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	will@kernel.org, maz@kernel.org, broonie@kernel.org,
	oliver.upton@linux.dev, miko.lenczewski@arm.com,
	kevin.brodsky@arm.com, ardb@kernel.org, suzuki.poulose@arm.com,
	lpieralisi@kernel.org, scott@os.amperecomputing.com,
	joey.gouly@arm.com, yuzenghui@huawei.com, pbonzini@redhat.com,
	shuah@kernel.org, mark.rutland@arm.com, arnd@arndb.de
Subject: Re: [PATCH v12 6/7] arm64: futex: support futex with FEAT_LSUI
Date: Tue, 10 Feb 2026 16:45:13 +0000	[thread overview]
Message-ID: <aYtgmZZhAKAvtfaK@arm.com> (raw)
In-Reply-To: <20260121190622.2218669-7-yeoreum.yun@arm.com>

I wonder whether we can shorten this function a bit. Not sure it would
be more readable but it would be shorter.

On Wed, Jan 21, 2026 at 07:06:21PM +0000, Yeoreum Yun wrote:
> +static __always_inline int
> +__lsui_cmpxchg32(u32 __user *uaddr, u32 oldval, u32 newval, u32 *oval)
> +{
> +	u64 __user *uaddr64;
> +	bool futex_on_lo;
> +	int ret, i;
> +	u32 other, orig_other;
> +	union {
> +		struct futex_on_lo {
> +			u32 val;
> +			u32 other;
> +		} lo_futex;
> +
> +		struct futex_on_hi {
> +			u32 other;
> +			u32 val;
> +		} hi_futex;
> +
> +		u64 raw;
> +	} oval64, orig64, nval64;

	union {
		u32 futex[2];
		u64 raw;
	}

> +
> +	uaddr64 = (u64 __user *) PTR_ALIGN_DOWN(uaddr, sizeof(u64));
> +	futex_on_lo = IS_ALIGNED((unsigned long)uaddr, sizeof(u64));

	futex_pos = (unsigned long)uaddr & 4 ? 1 : 0;

> +
> +	if (futex_on_lo) {
> +		oval64.lo_futex.val = oldval;
> +		ret = get_user(oval64.lo_futex.other, uaddr + 1);
> +	} else {
> +		oval64.hi_futex.val = oldval;
> +		ret = get_user(oval64.hi_futex.other, uaddr - 1);
> +	}

and here use

	get_user(oval64.raw, uaddr64);
	futex[futex_pos] = oldval;

> +
> +	if (ret)
> +		return -EFAULT;
> +
> +	ret = -EAGAIN;
> +	for (i = 0; i < FUTEX_MAX_LOOPS; i++) {
> +		orig64.raw = nval64.raw = oval64.raw;
> +
> +		if (futex_on_lo)
> +			nval64.lo_futex.val = newval;
> +		else
> +			nval64.hi_futex.val = newval;
> +
> +		if (__lsui_cmpxchg64(uaddr64, &oval64.raw, nval64.raw))
> +			return -EFAULT;
> +
> +		if (futex_on_lo) {
> +			oldval = oval64.lo_futex.val;
> +			other = oval64.lo_futex.other;
> +			orig_other = orig64.lo_futex.other;
> +		} else {
> +			oldval = oval64.hi_futex.val;
> +			other = oval64.hi_futex.other;
> +			orig_other = orig64.hi_futex.other;
> +		}

Something similar here to use futex[futex_pos].

We probably also need to check that the user pointer is 32-bit aligned
and return -EFAULT if not.

-- 
Catalin

  reply	other threads:[~2026-02-10 16:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-21 19:06 [PATCH v12 0/7] support FEAT_LSUI Yeoreum Yun
2026-01-21 19:06 ` [PATCH v12 1/7] arm64: Kconfig: add support for LSUI Yeoreum Yun
2026-02-06 18:36   ` Catalin Marinas
2026-02-10  9:56     ` Yeoreum Yun
2026-01-21 19:06 ` [PATCH v12 2/7] arm64: cpufeature: add FEAT_LSUI Yeoreum Yun
2026-02-06 18:42   ` Catalin Marinas
2026-02-09 18:57     ` Catalin Marinas
2026-02-10  9:54       ` Yeoreum Yun
2026-02-10 16:14         ` Catalin Marinas
2026-02-10 17:01           ` Yeoreum Yun
2026-02-16 18:24             ` Catalin Marinas
2026-02-23 15:54               ` Yeoreum Yun
2026-01-21 19:06 ` [PATCH v12 3/7] KVM: arm64: expose FEAT_LSUI to guest Yeoreum Yun
2026-01-21 19:06 ` [PATCH v12 4/7] KVM: arm64: kselftest: set_id_regs: add test for FEAT_LSUI Yeoreum Yun
2026-01-21 19:06 ` [PATCH v12 5/7] arm64: futex: refactor futex atomic operation Yeoreum Yun
2026-01-21 19:06 ` [PATCH v12 6/7] arm64: futex: support futex with FEAT_LSUI Yeoreum Yun
2026-02-10 16:45   ` Catalin Marinas [this message]
2026-02-10 17:17     ` Yeoreum Yun
2026-02-16 18:04       ` Catalin Marinas
2026-02-17  9:56         ` Yeoreum Yun
2026-01-21 19:06 ` [PATCH v12 7/7] arm64: armv8_deprecated: disable swp emulation when FEAT_LSUI present Yeoreum Yun
2026-02-06  9:04 ` [PATCH v12 0/7] support FEAT_LSUI Yeoreum Yun
2026-02-06 18:35   ` Catalin Marinas
2026-02-12  8:08     ` Yeoreum Yun

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=aYtgmZZhAKAvtfaK@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=joey.gouly@arm.com \
    --cc=kevin.brodsky@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=miko.lenczewski@arm.com \
    --cc=oliver.upton@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=scott@os.amperecomputing.com \
    --cc=shuah@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yeoreum.yun@arm.com \
    --cc=yuzenghui@huawei.com \
    /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