From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796297325; b=mKTYb5BWqbimeFwAHYH4crHt8+hTNoXn5VI6YcTl6p88Swho9/fOx0Sje+i+h0+afshj bqdzjC8UbKKLSIyrNPzsgRO0wJSiNSqnFWBOTeCGMxortoiYRv8l97e0bJvtuD6VXEZ3n /EWeUAqrGMPPldjeS20l4c1uYFkV53LSiB5Htc10EYkcUWqF1bb2EDEmWv0hD37e02m/j 5FjfrLg9LXneh057gjRAgqfslwUuutmR6uWHkm3XuMzLHCad0KGxgLVhFMdzfeB0TODR9 CY9QMXdJ88sLSa4v8LNQ+/007M1gdKIyN0iYPHOvK00qOultT0p14gxSG5E0JUbkfTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796297325; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=gy0adwlkoJczzMZFHQgJQdO7yLRFt37m2lU09tLvYSw=; b=xY3aiRR9AjXe3nayiGinjVYZj3P+HTDwOGdA0HYA+S8dTdQJH3p48oi9Z7h+jBApGoBH O9m2928nnd4Vlv7tAH3s5C++Dm2Niur4asOXRPy35CVEHIQI/zkDWxyFQVgu0dpEWC3oO 1KJmII2ereK++mqJEmwf3IbokcWvvSYncrLbZWQkQBs2RxjxAyXpoXZSUa3pHsntfG0oJ 74jEYd0rBwhY2aN5uWFse0oDFHywwDDQp3pf9DQ+wR9i3ScBTji0LZ47DV4ejeaQrlSiw 48yre2BsdWoN6PvmnLnidYCMGRc2lGjZdKwVexJQehw/T4/2uQX5zk+g8nOMb+SeeUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZjGocvqZ; arc=none smtp.remote-ip=209.85.221.45 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59FE9606A322 for ; Thu, 3 Dec 2026 11:28:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 59FE9606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZjGocvqZ Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-4acb44dcd7bso12445882f8f.0 for ; Thu, 03 Dec 2026 03:28:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796297323; x=1796902123; darn=lists.linux.dev; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=gy0adwlkoJczzMZFHQgJQdO7yLRFt37m2lU09tLvYSw=; b=ZjGocvqZQkZXG9fQxGNTpIBE6XmlzLd2Z6F1ESo/mEJ+n4gdE0Qb0SInx4oD990nBN w+KTKAoLlNEC4ul15EjZkOJN4dU/sqkB6d/OwNE/WAY25toDL0BdpfeZsWzAiDZ/e7r0 jLtod3IA5sDgI8er99ZjrHJI4EQawBC2pIbKNjo8uumUt/Wwom2/3Z8ewQyQK+Dfppyc vC9SOPFyqHayA9Z+jineMAFlKKOrWneG/Bvq0UzO+paHzv6XZgKeBK8uu+/Y0Bfm/Uds dxx/CH0eHkbcenDwpQxsUrQuIl0Yh39TzPOLDjncooylrGpMAwPMFG92Vsz6YLTWoe9s Pn5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796297323; x=1796902123; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=gy0adwlkoJczzMZFHQgJQdO7yLRFt37m2lU09tLvYSw=; b=AYCvwnDRwkBpMyBQZVq0KvtlxCLP2Tl62ngeIpaNWbcKviytC84IeM+6ERvNVcZ5r+ vrYEesdmWCOIrZBO0nAug+l0yyTx/b2QMa6+1HL4QimPia2UL6+0iw8jzqBxEVfbXJ5P C0xSCG2as7rKElzdsQXC1ETAfgOBfYO6STHjlbO3G430+Om+9l8yariLlvhI6YldvLYN 4YdZqZNFDsD2O9pTj4UDVvRUwB+twTdAu+S13RRHno4C1c+wCEB6AeoS1Aj4cGFrnwH7 rKqickgaQgD4r0pL0hrkb6JFcREM67cg7s4XqNkT693HiJaM5UaJhpB4BKWqHPGZ5W9R uAIg== X-Forwarded-Encrypted: i=1; AL+hErEXU52fvm0O5OCG+qo8vFQrkBk8xnWmGYsf9veQ7MiE1XtgvBtU6waxnbgmMiUo+5NCCA5w@lists.linux.dev X-Gm-Message-State: APuU4Z/eRxicX4FeDSrj7FdKghiO39fC4X3qvPaOrusEL31YYzNOF2HL 6F3+ead/EplZf0z4PP7ixM9hF4z8Zqv/K0lpnVEJTRINCXHi+TzPfr7N X-Gm-Gg: AZFdTZfaEOPpajMI3jCd0uVJMkirnlPjtLhBc6JwJwniLPvRYLM/v9A6/P6hmcjmdvd kjF+/VyG7/GRyg2fWeBnzN3xm2Qyhcf+7CT32HeMCGSH8U/YclOLzksoIlhIOM2t20YCgoi4q35 2fOmjT3BeLza4fZ+mn+0R9JDerFyVq/bVpS7Kbo+flqBJyyfaxZUgwZgm9Da5GQafAYLtD38/5+ M+jbnnlAzuBr8pDKlwGcGC1c6KcKsUqEj+D0jhVuFhETDw/aDJuq6bgU5oyrzu7adKels0Da8k2 EKLi2Wn59ndjlbz4fNoW3yadzzJ6cXh3wSD8udGqjNChokejptJDGypSwrE8ONzTrtV/RWSgjoO ri41YxXadoFfpoxbmj1zOPyf//Vk7LvNLq3D94sNZo2Ax4Ic34pMuff99iRBCM+1PAxgPzQefEL WDMj4lklhXkhIA6zjDTT+AhCUSywQYszIuww8OwZSjGr2fOzxzQrrNjz5zA291HVOzfkDhtv8sS 6vZVx+26NdMXSypNKriVWHqohGlIg/yQxSsUGKFtqWCP2zhquggCc5aa44gDgd0lPYktTBQ5wuS AaYDL2yrdvKq0tRXKQhUMuW6fMfGLkjKe0nPlENTkub/eKIpUew/9OZSs/9N2J/zwRwnP0eWTr+ Bbi/aRda7RBc= X-Received: by 2002:a05:600c:a09:b0:4a2:1a:a129 with SMTP id 5b1f17b1804b1-4bb88829115mr898409695e9.35.1796297323235; Thu, 03 Dec 2026 03:28:43 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe005543esm74525675e9.5.2026.12.03.03.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 03:28:42 -0800 (PST) Date: Thu, 3 Dec 2026 11:28:41 +0000 From: David Laight To: "Christophe Leroy (CS GROUP)" Cc: "Nysal Jan K.A." , linuxppc-dev@lists.ozlabs.org, Jeevitha Palanisamy , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Ritesh Harjani (IBM)" , Shrikanth Hegde , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Andrew Morton , "David Hildenbrand (Arm)" , Ryan Roberts , Andreas Larsson , Usama Arif , Kevin Brodsky , "Kiryl Shutsemau (Meta)" , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH 1/3] powerpc: Add support for 128-bit cmpxchg Message-ID: <20261203112841.29d4d09b@pumpkin> In-Reply-To: <30fbd121-8ada-4619-bb61-08ded9af6268@kernel.org> References: <20261125174035.1412724-1-nysal@linux.ibm.com> <20261125174035.1412724-2-nysal@linux.ibm.com> <82516881-5ffa-40f6-9d6a-549fcbb0ab00@kernel.org> <20261202095747.0009eb79@pumpkin> <2b03573f-da09-479c-a87d-6ac41737caa8@kernel.org> <20261202175227.68aedaa6@pumpkin> <30fbd121-8ada-4619-bb61-08ded9af6268@kernel.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) X-Mailing-List: llvm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, 3 Dec 2026 10:41:27 +0100 "Christophe Leroy (CS GROUP)" wrote: > Le 02/12/2026 =C3=A0 18:52, David Laight a =C3=A9crit=C2=A0: > > On Wed, 2 Dec 2026 11:13:24 +0100 > > "Christophe Leroy (CS GROUP)" wrote: > > =20 > >> Le 02/12/2026 =C3=A0 10:57, David Laight a =C3=A9crit=C2=A0: =20 > >>> On Mon, 30 Nov 2026 18:58:11 +0100 > >>> "Christophe Leroy (CS GROUP)" wrote: > >>> =20 > >>>> Why a memory clobber ? Is it to get a barrier ? Otherwise I see no > >>>> direct hidden memory modification in the sequence. =20 > >>> > >>> I found something horrid during testing: > >>> The compiler (gcc) will spill the value of a memory operand to stack. > >>> So: > >>> long f(long *p) > >>> { > >>> register long x asm("r3"); > >>> > >>> asm( "opcode %[x],%[p]" : [x] "=3D&r" (x) : [p] "m" (*p)); > >>> return x; > >>> } > >>> compiles to: > >>> f: > >>> ld 9,0(3) > >>> std 9,-16(1) > >>> ori 2,2,0 > >>> opcode 3,-16(1) > >>> blr =20 > >> > >> What 'opcode' is that ? Because powerpc is a RISC processor, there is = no > >> way ALU operation can operate on something else than registers. =20 > >=20 > > A memory read would do. > > I was playing around trying to get the compiler to generate addressing > > modes that lq doesn't support. > > The point is that the asm block isn't given a reference to the address > > it expects. > > It also means that the size of the variable has to be right. > > If it can do the same for an output then asm blocks that try to do > > atomic operations will do them on a copy. > >=20 > > Or consider (with -mno-altivec) this: > > u128 f(int xx, u128 *p) > > { > > register u128 x asm("r4"); > >=20 > > asm( "lq %[x],%[p]" : [x] "=3D&r" (x) : [p] "m" (*p)); > > return x; > > } > > generates: > > f: > > ld 9,0(4) > > ld 10,8(4) > > std 9,-16(1) > > std 10,-8(1) > > ori 2,2,0 > > lq 4,-16(1) > > mr 3,4 > > mr 4,5 > > blr > >=20 > > A little contrived and the byte order is wrong but it is failing to > > do the expected atomic read of the 128bit value. =20 >=20 > Looks like the "m" generates the copy. > When you use "+m" it doesn't. More likely 'it hasn't been seen to do so'. If it can spill an input memory argument to stack I suspect the logic is there to spill an output parameter as well. If you try really hard I bet you can get it to do the double copy for "+" as well. > By the way you should use "+Q" instead of "+m" I think. For lq/stq you definitely need to use "Q". Both "Z" and "m" can generate 'reg + reg' which they don't support but gas doesn't actually reject but treats the one register number as an immediate offset - which only fails because it didn't use r16. >=20 > With: >=20 > u128 f(int xx, u128 *p) > { > register u128 x asm("r4"); >=20 > asm volatile("lq %[x],%[mem]" : [x] "=3D&r" (x), [mem] "+Q" (*p)); >=20 > return x; > } >=20 > I get >=20 > 0000000000005490 : > 5490: 78 23 89 7c mr r9,r4 > 5494: 00 00 89 e0 lq r4,0(r9) > 5498: 78 23 83 7c mr r3,r4 > 549c: 78 2b a4 7c mr r4,r5 > 54a0: 20 00 80 4e blr Indeed - I tried all sorts of combinations. But there isn't anything there that actually stops the value being spilled. So constrain the register allocation further and it might still spill the value. This also means that code that uses a 'fake' "m" argument to indicate that some specific memory is accessed by an asm block is fundamentally broken because that "m" argument can refer to a copy. If the asm is in a real function it is likely to have been checked once. But if inlined it will depend on the call site - and 99% could be ok. David >=20 > Christophe