All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Stefano Stabellini <sstabellini@kernel.org>,
	Luca Di Maio <luca@edera.dev>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	xen-devel@lists.xenproject.org, Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Michal Orzel <michal.orzel@amd.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions
Date: Thu, 3 Dec 2026 00:52:10 +0000	[thread overview]
Message-ID: <4dc9d73f-778f-4a76-8eb9-386fb63523d2@citrix.com> (raw)
In-Reply-To: <6d0f1b11-7fe8-58c7-241b-1f891fd66544@kernel.org>

On 03/12/2026 12:38 am, Stefano Stabellini wrote:
>> +#include <asm/alternative.h>
>> +
>> +#define __LSE_PREAMBLE ".arch_extension lse\n"
>> +
>> +/* Patched at boot, like Linux's alternative_has_cap_likely(). */
>> +static always_inline bool system_uses_lse_atomics(void)
>> +{
>> +#ifdef CONFIG_HAS_AS_LSE
>> +    register_t ret;
>> +
>> +    asm_inline volatile ( ALTERNATIVE("mov %0, #0", "mov %0, #1",
>> +                                      ARM64_HAS_LSE_ATOMICS)
>> +                          : "=r" (ret) );
> This costs a mov plus a cbz, and ties up a register, at every atomic
> op. alternative_has_cap_likely() in Linux uses asm goto with
> ALTERNATIVE("b %l[l_no]", "nop", cap), which is a single instruction.
> Not a blocker, but it is cheap to do and these paths are hot.
>
> Separately, ALTERNATIVE() already takes a CONFIG_ argument. That could
> replace the #ifdef CONFIG_HAS_AS_LSE.

This is already a pattern elsewhere in ARM, but yes, it's awful code
generation.

Now with GCC 5.1 as a toolchain baseline, asm goto() can be used
generally.  It's worth cleaning up the current users first, before
adding new ones.

Just be aware; patching of alternatives does not happen instantly at
boot.  It's later.  So, for guarding instruction groups like this, you
must arrange that the path prior to patching is the one that is safe on
all CPUs.

~Andrew


  reply	other threads:[~2026-12-03  0:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:08 [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions Luca Di Maio
2026-12-03  0:38   ` Stefano Stabellini
2026-12-03  0:52     ` Andrew Cooper [this message]
2026-12-01 16:08 ` [PATCH v2 2/5] xen/arm64: use LSE in the atomic_t operations Luca Di Maio
2026-12-03  0:58   ` Stefano Stabellini
2026-12-01 16:08 ` [PATCH v2 3/5] xen/arm64: use LSE in xchg() and cmpxchg() Luca Di Maio
2026-12-03  1:00   ` Stefano Stabellini
2026-12-01 16:08 ` [PATCH v2 4/5] xen/arm64: use LSE in the bitops Luca Di Maio
2026-12-03  1:04   ` Stefano Stabellini
2026-12-01 16:08 ` [PATCH v2 5/5] xen/arm64: use LSE for arch_fetch_and_add() Luca Di Maio
2026-12-03  1:15   ` Stefano Stabellini

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=4dc9d73f-778f-4a76-8eb9-386fb63523d2@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=luca@edera.dev \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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 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.