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 D2607606A322 for ; Thu, 3 Dec 2026 00:59:08 +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=OIQpKikw Received: from list by lists.xenproject.org with outflank-mailman.1511358.1703798 (Exim 4.92) (envelope-from ) id 1xYv9q-0003Ka-Os; Thu, 03 Dec 2026 00:58:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1511358.1703798; Thu, 03 Dec 2026 00:58:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYv9q-0003KT-LO; Thu, 03 Dec 2026 00:58:46 +0000 Received: by outflank-mailman (input) for mailman id 1511358; Thu, 03 Dec 2026 00:58:45 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYv9p-0003KN-8a for xen-devel@lists.xenproject.org; Thu, 03 Dec 2026 00:58:45 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xYv9o-002CH6-LT for xen-devel@lists.xenproject.org; Thu, 03 Dec 2026 01:58:44 +0100 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b10bec0-e002-0a2a0a5209dd-0a2a450b9290-2 for ; Thu, 03 Dec 2026 01:58:44 +0100 Received: from [172.234.252.31] (helo=sea.source.kernel.org) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b10bec2-b7e8-0a2a450b0019-aceafc1fb94a-3 for ; Thu, 03 Dec 2026 01:58:44 +0100 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 333B943658; Thu, 3 Dec 2026 00:58:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0709D1F000C1; Thu, 3 Dec 2026 00:58:40 +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=1796259522; bh=0v6csctQGvFnKLn1sdlTay5KBADApBeDog2EyheeE2c=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=OIQpKikwyjOuZ4/quj1KpDz91UxwSOIJrCzYp9F2D45I3+9MTvTyraCJUAz15T7Q4 cz84DWibGrNFIqff3pRP7oCPEFc2HYlVMRm+62rT5ZOfXh96JDcE6wMxKCDlgKJaZH zrb1n3nIRMXePqJWsXlKYeA57M5duV0qn1xp6Xx08a6Osq0EWxkw3G99accA9ZZ6hD +CW1unbB5Y2JDiiREZiq/I8aYnzRQp8Quom9+YkVebOL8uK3sGfOSNTZ8fXgZ8Wpu5 V0so++jLdYCx4MrsNr6CbjcgUZfLgXcNNLZsViQeI8DMVUCTimekSaKWyq/FIXvas7 agroVRNC3eMqw== Date: Wed, 2 Dec 2026 16:58:40 -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 2/5] xen/arm64: use LSE in the atomic_t operations In-Reply-To: <20261201160817.466800-3-luca@edera.dev> Message-ID: <7c14276d-682d-dea5-8b15-07056cf19d99@kernel.org> References: <20261201160817.466800-1-luca@edera.dev> <20261201160817.466800-3-luca@edera.dev> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-purgate-ID: tlsNG-42698a/1796259524-AA4DB9EA-6627D5C5/0/0 X-purgate-type: clean X-purgate-size: 3675 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: > On a two-socket Graviton4 every pCPU of a socket spun in the exclusive > loop of atomic_add_return() on dom0's p2m rwlock, and dom0 hung at boot. > Use the LSE instruction for each operation when the CPU has it, with the > same barriers; CPUs without LSE keep the exclusive loops. > > Assisted-by: Claude:claude-opus-5-5 > Signed-off-by: Luca Di Maio > --- > xen/arch/arm/include/asm/arm64/atomic.h | 55 +++++++++++++++++++++++++ > 1 file changed, 55 insertions(+) > > diff --git a/xen/arch/arm/include/asm/arm64/atomic.h b/xen/arch/arm/include/asm/arm64/atomic.h > index 4460165295..a113401db6 100644 > --- a/xen/arch/arm/include/asm/arm64/atomic.h > +++ b/xen/arch/arm/include/asm/arm64/atomic.h > @@ -22,6 +22,8 @@ > #ifndef __ARCH_ARM_ARM64_ATOMIC > #define __ARCH_ARM_ARM64_ATOMIC > > +#include > + > /* > * AArch64 UP and SMP safe atomic ops. We use load exclusive and > * store exclusive to ensure that these are atomic. We may loop > @@ -32,6 +34,14 @@ static inline void atomic_add(int i, atomic_t *v) > unsigned long tmp; > int result; > > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > +" stadd %w1, %0" > + : "+Q" (v->counter) > + : "r" (i)); > + return; > + } > + > asm volatile("// atomic_add\n" > "1: ldxr %w0, %2\n" > " add %w0, %w0, %w3\n" > @@ -46,6 +56,16 @@ static inline int atomic_add_return(int i, atomic_t *v) > unsigned long tmp; > int result; > > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > +" ldaddal %w2, %w0, %1" > + : "=&r" (result), "+Q" (v->counter) > + : "r" (i) > + : "memory"); > + smp_mb(); > + return (int)((unsigned int)result + i); > + } LDADDAL should already be fully ordered so the barrier is not needed. Same is true elsewhere. Other than that it is OK. > asm volatile("// atomic_add_return\n" > "1: ldxr %w0, %2\n" > " add %w0, %w0, %w3\n" > @@ -64,6 +84,14 @@ static inline void atomic_sub(int i, atomic_t *v) > unsigned long tmp; > int result; > > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > +" stadd %w1, %0" > + : "+Q" (v->counter) > + : "r" (-(unsigned int)i)); > + return; > + } > + > asm volatile("// atomic_sub\n" > "1: ldxr %w0, %2\n" > " sub %w0, %w0, %w3\n" > @@ -78,6 +106,16 @@ static inline int atomic_sub_return(int i, atomic_t *v) > unsigned long tmp; > int result; > > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > +" ldaddal %w2, %w0, %1" > + : "=&r" (result), "+Q" (v->counter) > + : "r" (-(unsigned int)i) > + : "memory"); > + smp_mb(); > + return (int)((unsigned int)result - i); > + } > + > asm volatile("// atomic_sub_return\n" > "1: ldxr %w0, %2\n" > " sub %w0, %w0, %w3\n" > @@ -96,6 +134,14 @@ static inline void atomic_and(int m, atomic_t *v) > unsigned long tmp; > int result; > > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > +" stclr %w1, %0" > + : "+Q" (v->counter) > + : "r" (~m)); > + return; > + } > + > asm volatile("// atomic_and\n" > "1: ldxr %w0, %2\n" > " and %w0, %w0, %w3\n" > @@ -112,6 +158,15 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new) > > smp_mb(); > > + if (system_uses_lse_atomics()) { > + asm volatile(__LSE_PREAMBLE > +" cas %w0, %w2, %1" > + : "+r" (old), "+Q" (v->counter) > + : "r" (new)); > + smp_mb(); > + return old; > + } > + > asm volatile("// atomic_cmpxchg\n" > "1: ldxr %w1, %2\n" > " cmp %w1, %w3\n" > -- > 2.47.3 >