From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796297325; b=FaLEluNVQcS9nzp2DzeVR9AZiAWgYFIDFPyh9c09Lz6x/TobegNggMw+pg0OYNs/nyHJ VgUlAUKPAHmmKG7kIR5cThmTC4wOhhusS3ZYMPf0JND0MdnCN5XSnC+h0AGvBmNNrDQjK unNjNmbxHJ8lZbeZN0rSefii8Lxx/3VdxgCzN3L2AFdbqAVSL1bAUa/R9asqKfEb3Ai9G 9UbKsyJ2vM6diixeFuT+6IMtwl1dn0rJzR8Lu5iLroXOJPHhLySkZYRKP9I8LDz+iPlo/ mGN8+FkLfyVHqrw9O8wUHz87VnOqFBLM7pUGW6aDl1mILrKkTonqK5e/KvPdmXL44fw== 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=hP1hcgDf/oLNkjtpBqFAlmA/1P2Jsl4EK2uKIpY6ch2omkvkK2xVqHxZFtAwH/xc5vrP ZjU8JsWO7MVP+SzpDONJ4vFvYuoLXlf+QuH+Q+bPJu2VpwpoczDf1xXIb0EGdtyJbjrBV rSvq5/cVnr5tmXAOuPB/W/l2tTSnQtROYoLwH+Z6JHXt0rl9MLyk9nh3lLxA8Rnpqp7k0 YENbTOGHBc/0hgWZ+NUtzvFnBW8+FiX1tjg4oPGtGNNfy0qiAOIQtBjqxO6Oru79/YERj Na6U8NEvbyfgxrtsc3349SJIQyS/Ob0NXWBagQ0k2QK+hK/laqZuYa5rik1As9gF15A== 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=vtBGJDZI; arc=none smtp.remote-ip=209.85.128.50 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 10FB4606A32C for ; Thu, 3 Dec 2026 11:28:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 10FB4606A32C 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=vtBGJDZI Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4a3517554f7so126763225e9.2 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=vger.kernel.org; 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=vtBGJDZI3EzXK0eVBcp4pPdt9y7uU46bM1TsjiyBGauBRKAa4W3okYijEt9J6wNkfq RlxoCC7u+gmlcLTh8X37QeZ7RHH2wiaPfmCUn2aDHwW75MsYOF/Rv3FV1JyYrlOe6s/o yR9/BRwZggqPBcKjkIf1iBxRJJrBY3FaxVq9PPKpqqfJerrVu8he5KcRAvpCRaiZv2lk Jloua7YzINdVmXLYvjWMtBjoFuGTNRoxLKp2drm0jN5o/no+TwcDSWWf03xFRFJWekDg +YxXA73nIr/m6F0iEWXSX/tmVBMFtvbXPBZ+m6ulIQP4xkIVzPUMVJPjEOgq95SN3f9Z Yg3A== 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=SsAsJkzZiMjUjJcgATstF6Oc3LwDSjAXpgIETSojSqSKH5sQ0QHcU3POZ+EkBO6jFr eEjGbX+zFXIUn/l2YrJ+lhQeEbJ8xJ8joONlgMsSRBwTmb+vmudeihIyWSce7+NsCb5d QoOCMRQ2MpVhTh/HxZQMC/yCXgWhzUDK3eCf+gc+bUhrk4hY8CqHcYugUe+5I668BlBZ yHo27hMhvo4OmD5a2FeA97UM0t4jfwlb9ogoEN8vhqd5TVoIGpiU7MMymwXcF6CBZnaH ldf/3aszWmb9Zo5Tq3H9BEjDvFdkMPbSTdibxuWbS8a8gfketXYenvNx+1w+MiEIEGtZ 0BMQ== X-Forwarded-Encrypted: i=1; AL+hErGEQTS5QsWvnmKdFffr0qZz2Cl6/wbHwrnBA4+FJ4bp2WHV3KnmfMBjsvMHjIyPaamCMnLXtc/1a5rbdsU=@vger.kernel.org X-Gm-Message-State: APuU4Z/qjgbNioJWqxegtRq1ZiCf51p5/8pJQgEmetQUvqXsv/1xJRqi eYe+Oh8x7EgujWypGHxUQQ8s9y4ytVeHvzlcb8xAE7caXu1R3q3FTdpp X-Gm-Gg: AZFdTZfTyWnUej51q99nwrTAwCSnbG//Vz5SGNWRmAS7SJsK+CP4/QaHE3JFIC/WAva vm5JVtriUXd1Y+lunjz7l6+wQV+o06F0DiJX5C4h8Xig9HlIMAJ7EoQw3sFAGADlNQgssm2n8nB mgJ5ixlTfipy+5BiYhAMwPvMzw3HUcuuN5XNiteUTdV+jWppvQ1D4R5O3qYGL/DK81Ks3Sdq1TY /62m4LMgfxHR5oQt+/WZsUVYmsvvPcn5M1EwXL4vNxgBQaYOVwtWNLDcKLuZHYETVC5FEJSUhOE jWQrVmWGE64LoxXnNRxpIle+Rg1IChO11HwDE03FqyxmgIZ2CQsaP5z8V+cOZXyAZlAOHQ28OUx 2hflFXC/F7/07I5jeDHinaWyKHJJ3HCoxEqT1mjFj8aADf8cgsJWTQOw057M0L+AMABvTB7LoBJ P1ZuKjdzPeBiXrbtLmIF/zc2bJIcM1KmKG7J8vIf4sXO+FVsBHHA+JRiLVYrdv0XEUyRdoUWGKl qt4BK0OOozpjr3COhFDSCvk+Mdl6l6Rhvq8DrzIzHSudzEsLLWP+xRJPEW6xdhevH9sexxRWpnr Oss8xiuBVZ03lfjzJlXiYmy3+6bNq884VBGw4g3o+BO0XuTeIDHPYXDGVb98IPegx/9b+gtRROX Zpj8oCv7sgtk= 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: linux-kernel@vger.kernel.org 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