From: Catalin Marinas <catalin.marinas@arm.com>
To: Yeoreum Yun <yeoreum.yun@arm.com>
Cc: will@kernel.org, broonie@kernel.org, maz@kernel.org,
oliver.upton@linux.dev, shameerali.kolothum.thodi@huawei.com,
joey.gouly@arm.com, james.morse@arm.com, ardb@kernel.org,
scott@os.amperecomputing.com, suzuki.poulose@arm.com,
yuzenghui@huawei.com, mark.rutland@arm.com,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 4/5] arm64: futex: refactor futex atomic operation
Date: Fri, 15 Aug 2025 17:38:55 +0100 [thread overview]
Message-ID: <aJ9in0fUI01J3a4S@arm.com> (raw)
In-Reply-To: <20250811163635.1562145-5-yeoreum.yun@arm.com>
On Mon, Aug 11, 2025 at 05:36:34PM +0100, Yeoreum Yun wrote:
> Refactor futex atomic operations using ll/sc method with
> clearing PSTATE.PAN to prepare to apply FEAT_LSUI on them.
>
> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
> ---
> arch/arm64/include/asm/futex.h | 183 ++++++++++++++++++++++-----------
> 1 file changed, 124 insertions(+), 59 deletions(-)
>
> diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h
> index bc06691d2062..fdec4f3f2b15 100644
> --- a/arch/arm64/include/asm/futex.h
> +++ b/arch/arm64/include/asm/futex.h
> @@ -7,73 +7,164 @@
>
> #include <linux/futex.h>
> #include <linux/uaccess.h>
> +#include <linux/stringify.h>
>
> #include <asm/errno.h>
>
> -#define FUTEX_MAX_LOOPS 128 /* What's the largest number you can think of? */
> +#define LLSC_MAX_LOOPS 128 /* What's the largest number you can think of? */
>
> -#define __futex_atomic_op(insn, ret, oldval, uaddr, tmp, oparg) \
> -do { \
> - unsigned int loops = FUTEX_MAX_LOOPS; \
> +#define LLSC_FUTEX_ATOMIC_OP(op, asm_op) \
> +static __always_inline int \
> +__llsc_futex_atomic_##op(int oparg, u32 __user *uaddr, int *oval) \
> +{ \
> + unsigned int loops = LLSC_MAX_LOOPS; \
> + int ret, val, tmp; \
> \
> uaccess_enable_privileged(); \
> - asm volatile( \
> -" prfm pstl1strm, %2\n" \
> -"1: ldxr %w1, %2\n" \
> - insn "\n" \
> -"2: stlxr %w0, %w3, %2\n" \
> -" cbz %w0, 3f\n" \
> -" sub %w4, %w4, %w0\n" \
> -" cbnz %w4, 1b\n" \
> -" mov %w0, %w6\n" \
> -"3:\n" \
> -" dmb ish\n" \
> + asm volatile("// __llsc_futex_atomic_" #op "\n" \
> + " prfm pstl1strm, %2\n" \
> + "1: ldxr %w1, %2\n" \
> + " " #asm_op " %w3, %w1, %w5\n" \
> + "2: stlxr %w0, %w3, %2\n" \
> + " cbz %w0, 3f\n" \
> + " sub %w4, %w4, %w0\n" \
> + " cbnz %w4, 1b\n" \
> + " mov %w0, %w6\n" \
> + "3:\n" \
> + " dmb ish\n" \
Don't change indentation and code in the same patch, it makes it harder
to follow what you actually changed. I guess the only difference is
asm_op instead of insn.
> _ASM_EXTABLE_UACCESS_ERR(1b, 3b, %w0) \
> _ASM_EXTABLE_UACCESS_ERR(2b, 3b, %w0) \
> - : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp), \
> + : "=&r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp), \
And here you changed oldval to val (was this necessary?)
> "+r" (loops) \
> : "r" (oparg), "Ir" (-EAGAIN) \
> : "memory"); \
> uaccess_disable_privileged(); \
> -} while (0)
> + \
> + if (!ret) \
> + *oval = val; \
> + \
> + return ret; \
> +}
> +
> +LLSC_FUTEX_ATOMIC_OP(add, add)
> +LLSC_FUTEX_ATOMIC_OP(or, orr)
> +LLSC_FUTEX_ATOMIC_OP(and, and)
> +LLSC_FUTEX_ATOMIC_OP(eor, eor)
> +
> +static __always_inline int
> +__llsc_futex_atomic_set(int oparg, u32 __user *uaddr, int *oval)
> +{
> + unsigned int loops = LLSC_MAX_LOOPS;
> + int ret, val;
> +
> + uaccess_enable_privileged();
> + asm volatile("//__llsc_futex_xchg\n"
> + " prfm pstl1strm, %2\n"
> + "1: ldxr %w1, %2\n"
> + "2: stlxr %w0, %w4, %2\n"
> + " cbz %w3, 3f\n"
> + " sub %w3, %w3, %w0\n"
> + " cbnz %w3, 1b\n"
> + " mov %w0, %w5\n"
> + "3:\n"
> + " dmb ish\n"
> + _ASM_EXTABLE_UACCESS_ERR(1b, 3b, %w0)
> + _ASM_EXTABLE_UACCESS_ERR(2b, 3b, %w0)
> + : "=&r" (ret), "=&r" (val), "+Q" (*uaddr), "+r" (loops)
> + : "r" (oparg), "Ir" (-EAGAIN)
> + : "memory");
> + uaccess_disable_privileged();
Was this separate function just to avoid the "mov" instruction for the
"set" case? The patch description states that the reworking is necessary
for the FEAT_LSUI use but it looks to me like it does more. Please split
it in separate patches, though I'd leave any potential optimisation for
a separate series and keep the current code as close as possible to the
original one.
--
Catalin
next prev parent reply other threads:[~2025-08-15 16:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 16:36 [PATCH v6 0/5] support FEAT_LSUI and apply it on futex atomic ops Yeoreum Yun
2025-08-11 16:36 ` [PATCH v6 1/5] arm64: cpufeature: add FEAT_LSUI Yeoreum Yun
2025-08-15 17:33 ` Catalin Marinas
2025-08-16 11:04 ` Yeoreum Yun
2025-08-11 16:36 ` [PATCH v6 2/5] KVM: arm64: expose FEAT_LSUI to guest Yeoreum Yun
2025-08-11 16:36 ` [PATCH v6 3/5] arm64: Kconfig: add LSUI Kconfig Yeoreum Yun
2025-08-11 16:36 ` [PATCH v6 4/5] arm64: futex: refactor futex atomic operation Yeoreum Yun
2025-08-15 16:38 ` Catalin Marinas [this message]
2025-08-16 13:03 ` Yeoreum Yun
2025-08-11 16:36 ` [PATCH v6 5/5] arm64: futex: support futex with FEAT_LSUI Yeoreum Yun
2025-08-15 17:02 ` Catalin Marinas
2025-08-16 12:30 ` Yeoreum Yun
2025-08-16 14:57 ` Yeoreum Yun
2025-08-18 18:35 ` Catalin Marinas
2025-08-18 19:53 ` Yeoreum Yun
2025-08-19 8:38 ` Catalin Marinas
2025-08-19 9:11 ` Yeoreum Yun
2025-08-19 14:29 ` Catalin Marinas
2025-08-19 15:15 ` 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=aJ9in0fUI01J3a4S@arm.com \
--to=catalin.marinas@arm.com \
--cc=ardb@kernel.org \
--cc=broonie@kernel.org \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=scott@os.amperecomputing.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.