From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2239606A322 for ; Thu, 3 Dec 2026 01:00:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=VPeYYFid Received: from list by lists.xenproject.org with outflank-mailman.1511366.1703807 (Exim 4.92) (envelope-from ) id 1xYvBP-0003g6-3s; Thu, 03 Dec 2026 01:00:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1511366.1703807; Thu, 03 Dec 2026 01:00:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYvBP-0003fz-0B; Thu, 03 Dec 2026 01:00:23 +0000 Received: by outflank-mailman (input) for mailman id 1511366; Thu, 03 Dec 2026 01:00:21 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYvBN-0003CV-OH for xen-devel@lists.xenproject.org; Thu, 03 Dec 2026 01:00:21 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xYvBN-00EHIr-4m for xen-devel@lists.xenproject.org; Thu, 03 Dec 2026 02:00:21 +0100 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b10bf18-8faa-0a2a0a5109dd-0a2a45078bf0-30 for ; Thu, 03 Dec 2026 02:00:21 +0100 Received: from [172.105.4.254] (helo=tor.source.kernel.org) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b10bf23-b4ea-0a2a45070019-ac6904fea2cc-3 for ; Thu, 03 Dec 2026 02:00:20 +0100 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 14E3460145; Thu, 3 Dec 2026 01:00:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0FAC1F000C1; Thu, 3 Dec 2026 01:00:17 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=k20260515 header.d=kernel.org header.i="@kernel.org" header.h="Date:From:To:cc:Subject:In-Reply-To:References" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796259618; bh=jh57tDHi27vp9oHWNbsuqUJwps7fJ1syhROsTKZog5A=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=VPeYYFiduB2Cc2qfmzAOB9dwS3NQ3nC6w2FpzWwhccm0xpvw5Iy9shTK2Nssf3D8y y5zpsJpA55ugt1rPMJwWIS4woenlajvWF8O/QPGNN7pWI98yaM6ULDmzm1179exqjm k4kxlFINP73AkLQZIGH1N4p3Q7EPAk3D98j0g9vs6RoXLnQcRQV0lgIZETl6aT4u8m 1vT4yqvCq8RQJt1p6FQ1D/91pvSl9OciCGiczfF6PrVk/agqOnlGsQIlttkcQXQsfL DteHbrA61vEVWJZNstBYNf/ImDXghAskms4O0D3Le1En/IM6VwT3ab3Lfq9jRJcetw zSCbIDtHOZJvg== Date: Wed, 2 Dec 2026 17:00:16 -0800 (PST) From: Stefano Stabellini To: Luca Di Maio cc: xen-devel@lists.xenproject.org, Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: Re: [PATCH v2 3/5] xen/arm64: use LSE in xchg() and cmpxchg() In-Reply-To: <20261201160817.466800-4-luca@edera.dev> Message-ID: <93508802-4769-aee1-43e1-5d5708cbc036@kernel.org> References: <20261201160817.466800-1-luca@edera.dev> <20261201160817.466800-4-luca@edera.dev> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-purgate-ID: tlsNG-ef75cf/1796259621-A5EC6AE4-FABEFC95/0/0 X-purgate-type: clean X-purgate-size: 3334 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Tue, 1 Dec 2026, Luca Di Maio wrote: > As for the atomic_t operations, use SWPAL and CAS when the CPU has LSE, > with the same barriers. A CAS cannot fail spuriously, so the _timeout > variants used by guest atomics succeed on their first try. > > Assisted-by: Claude:claude-opus-5-5 > Signed-off-by: Luca Di Maio Reviewed-by: Stefano Stabellini > --- > xen/arch/arm/include/asm/arm64/cmpxchg.h | 41 ++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > > diff --git a/xen/arch/arm/include/asm/arm64/cmpxchg.h b/xen/arch/arm/include/asm/arm64/cmpxchg.h > index f160e8e7bc..442b6e1698 100644 > --- a/xen/arch/arm/include/asm/arm64/cmpxchg.h > +++ b/xen/arch/arm/include/asm/arm64/cmpxchg.h > @@ -2,6 +2,7 @@ > #define __ASM_ARM64_CMPXCHG_H > > #include > +#include > > extern void __bad_xchg(volatile void *ptr, int size); > > @@ -11,6 +12,14 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size > > switch (size) { > case 1: > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > + " swpalb %w2, %w0, %1" > + : "=&r" (ret), "+Q" (*(volatile u8 *)ptr) > + : "r" (x) > + : "memory"); > + break; > + } > asm volatile("// __xchg1\n" > "1: ldxrb %w0, %2\n" > " stlxrb %w1, %w3, %2\n" > @@ -20,6 +29,14 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size > : "memory"); > break; > case 2: > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > + " swpalh %w2, %w0, %1" > + : "=&r" (ret), "+Q" (*(volatile u16 *)ptr) > + : "r" (x) > + : "memory"); > + break; > + } > asm volatile("// __xchg2\n" > "1: ldxrh %w0, %2\n" > " stlxrh %w1, %w3, %2\n" > @@ -29,6 +46,14 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size > : "memory"); > break; > case 4: > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > + " swpal %w2, %w0, %1" > + : "=&r" (ret), "+Q" (*(volatile u32 *)ptr) > + : "r" (x) > + : "memory"); > + break; > + } > asm volatile("// __xchg4\n" > "1: ldxr %w0, %2\n" > " stlxr %w1, %w3, %2\n" > @@ -38,6 +63,14 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size > : "memory"); > break; > case 8: > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > + " swpal %2, %0, %1" > + : "=&r" (ret), "+Q" (*(volatile u64 *)ptr) > + : "r" (x) > + : "memory"); > + break; > + } > asm volatile("// __xchg8\n" > "1: ldxr %0, %2\n" > " stlxr %w1, %3, %2\n" > @@ -75,6 +108,14 @@ static inline bool __cmpxchg_case_##name(volatile void *ptr, \ > unsigned long oldval; \ > unsigned long res; \ > \ > + if (system_uses_lse_atomics()) { \ > + asm volatile(__LSE_PREAMBLE \ > + " cas" #sz " %" #w "0, %" #w "2, %1" \ > + : "+r" (*old), "+Q" (*(volatile unsigned long *)ptr) \ > + : "r" (new)); \ > + return true; \ > + } \ > + \ > do { \ > asm volatile("// __cmpxchg_case_" #name "\n" \ > " ldxr" #sz " %" #w "1, %2\n" \ > -- > 2.47.3 >