From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796290905; b=3GCXwbR6xVmbXn6jh6/9iifeoXd3MA2QemJIhz1/sXftydVq6tuyVSFRmYjGh4bl3+4q McqFzQywbNB33mOGrHGuRGOPehS9Ic4v4nj+dsUQY/dgjCszon/e4xT8CcB4mzhNqcTv+ RbOgbybIM45zcAEas8zsIVcABfME0gFGkO3Gx9ZaCOfaGxUjUdO0u/M+ECYL0kmkAd9h6 OzsA+WmpZgsxs2E8uBVBpqSHINzvb/ay6JdK6YcLalzzc3NLTFfFFbBPZKYpZbJ0Hy9VX 0KRf9aRSB6PIscXEUJMJbXPXxnjQobhQ+P+GYlAN/L7QkCUOgpQGHLMNdOIq+Y9TFmw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796290905; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=E8yItthxEGpNKxO4V1u22xeKpjOW/FL7zCSi5I6vDPI=; b=jsSzkfP9hwbqQl42uybycNtnDKcW6qzLwbPCbhni1yrkdgd5Ut+oghd2XnZktaR/+YRY ClP9MXwHFQOQTB71/Ofo+cWutJ9r2zdK7b0mNjY+Nw5a85ERCpy/mXRlAeGqrvdu/X2+o +pgC0oGJ9JwxDtPYSmdy7Ppn3uM3jTLwzU0k97PYEPf9ywV9WD5yWLa6EZgGwlJdoHZwD HSz+nfW8FMHGZGPJ3J89MWyUNSLRULgJfWsxYqGElIrnmmVr4VfA0b1gha3tim+bLXMZ1 jEs3/uCaksjpDmzF8hJT43oAHG1vg7u5xqUwT1mMWH4fpo1vAHvxznqTdtyVIvdhKVQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GtTLCCgA; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37602606A322; Thu, 3 Dec 2026 09:41:45 +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=GtTLCCgA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 266E91F00893; Thu, 3 Dec 2026 09:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796290904; bh=E8yItthxEGpNKxO4V1u22xeKpjOW/FL7zCSi5I6vDPI=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=GtTLCCgA5Bap2VqSoxAgNgnGD+u7MLqC5L0ycbU9NsxX/hqXRq4cKmXbxJ/DZqlYG I8/U2PNRr4k8yFdwfNAikW+TRQuiptWZRPc+IHz47LDyKhtohvEB1Pav5rrIl6saws XIb5K7hJqv7s4ZEo9KEFxSKDm96mKLHg0xfSgfch6yPEOnb0vMitSIXm6cIdC4MIes TOqw5Vx8VgrBLX3HEcrBG4McALLBeG5Xyg6bJapa+B31w6ryUX3Wt7bZqbNCe4WOg2 5rY/dgrOnoY8NiCa7EPJuyg9KKI2pX2Vrik0S5L481lgPZpSwc+KEgw6y7m5zLcMge +vfkbWWro3OVg== Message-ID: <30fbd121-8ada-4619-bb61-08ded9af6268@kernel.org> Date: Thu, 3 Dec 2026 10:41:27 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] powerpc: Add support for 128-bit cmpxchg To: David Laight 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 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> Content-Language: fr-FR From: "Christophe Leroy (CS GROUP)" In-Reply-To: <20261202175227.68aedaa6@pumpkin> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 02/12/2026 à 18:52, David Laight a écrit : > On Wed, 2 Dec 2026 11:13:24 +0100 > "Christophe Leroy (CS GROUP)" wrote: > >> Le 02/12/2026 à 10:57, David Laight a écrit : >>> On Mon, 30 Nov 2026 18:58:11 +0100 >>> "Christophe Leroy (CS GROUP)" wrote: >>> >>>> Why a memory clobber ? Is it to get a barrier ? Otherwise I see no >>>> direct hidden memory modification in the sequence. >>> >>> 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] "=&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 >> >> What 'opcode' is that ? Because powerpc is a RISC processor, there is no >> way ALU operation can operate on something else than registers. > > 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. > > Or consider (with -mno-altivec) this: > u128 f(int xx, u128 *p) > { > register u128 x asm("r4"); > > asm( "lq %[x],%[p]" : [x] "=&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 > > A little contrived and the byte order is wrong but it is failing to > do the expected atomic read of the 128bit value. Looks like the "m" generates the copy. When you use "+m" it doesn't. By the way you should use "+Q" instead of "+m" I think. With: u128 f(int xx, u128 *p) { register u128 x asm("r4"); asm volatile("lq %[x],%[mem]" : [x] "=&r" (x), [mem] "+Q" (*p)); return x; } I get 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 Christophe