From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796233951; b=NQ1cbtsM3+S1HJorV8wtlM1dPFrJOlHe70C+sWDvrwjge/5dBtTiv5uS8OVlZxS3qGnQ NU+sH/Pfsn1Pwn4W9OMa2JiXHsZC/eCZAyvtfq/waIDv8vC6EwD2uDvI2REwX1jTC1Dlm SvCWhysrOq9H1lUpfgtL94B+J+ijEQJBCIjTmlz69YbbxTO5xed/q5l9VZyH29E9gevCI bEMM8DUw77S0ogItNrYE9CrYocwZO1jBXLFEpLrtFLvDBVltTINh6VpL1ZIb+FM6pqVom o8dmVSEcw9ZFd66QA2LaiakKoS69srtAAYrHF7FjV4o9JZ8BC5zMlEvKnvdJoYRWtjA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796233951; 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=ooN7LWd2/Oot+GtAZAuSg6pIqoHZxWRvkEziR3/kiEU=; b=s3cYN+pSSBCzbiE+I/xEZwBS+oiYmg2Ge2MHVuqdt9EWJ1C0MiIuT6DTg/4s4lVX036t D6erhXfNHSMxhr2RJbCWDmNgqx1TCJjyliqFcBJ6PLBNRQymEj3tL/EjgjI+KzSqxzzCl 4afbADEjjfVvqo1gO3k/Jcj4KGsiQYGMcCBQpNonvC4L1SeLd+zvPchXydYZCnRASnrJ9 pkyuxiRbAnFVP3izUwXzzDs6AioWPIZfkDe+EoityRiIwAprcTToxs7angqBHG4pU9Kvr 2O89CgaXKg5SLfgOCvr5wYsq6/AsJHLBQ8YeHiZoP7hb6G4BN7fLP2LUkd6zjsicQ8Q== 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=a+TEtkDz; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 04232606A32D for ; Wed, 2 Dec 2026 17:52:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 04232606A32D 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=a+TEtkDz Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4a9a8d6cea8so1068465e9.1 for ; Wed, 02 Dec 2026 09:52:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796233949; x=1796838749; 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=ooN7LWd2/Oot+GtAZAuSg6pIqoHZxWRvkEziR3/kiEU=; b=a+TEtkDzBeBrNInW8IAxzZcJ2WlnYxdZxG9orUC46+yg6t9Vb6SGfS07IpeX29Vgrx r/ewrR5sRWub8EZjvhPPnQ5bPfL7RGs3DUwiHRhAbKF0L+cfAKQLUerqi2TeFphVd41e VyFbVSgyjrUwKq0l6GaWGlZcB+ee9yS0yF1Ls89qXLudD+hOGuXOVCxwhVIH7ILj+w8p 0JXOZG0OH8ye3MjCu9g3cVFCbC7m6t/ReeFn2xrZhax10jX4O4MCueMVD1S5cQh1TwTE To11SrBne6/qJX3dUbPyU/D11FzCfuZuMlqa4GmM+SQ9OOkxdXoJ/nlThzijsjsGGBB3 eu2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796233949; x=1796838749; 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=ooN7LWd2/Oot+GtAZAuSg6pIqoHZxWRvkEziR3/kiEU=; b=yptVbjnekQZWk5M5fio+jeeMiImXYKQT/xm5gOQGsGUuHtUAiWw3/9P7ebsKlmH3kG STn6DKh5Y0I9mQu39KJ0Pnkj60ABCDtstaXE+bIeO4DGNjzAPQ9mxXCZLPN18uqUCFyU AqDmM5n0+9/p0NAiHXJi4blsmNSJ8WyUWYPa2eTlL0icwSOgw3PDAG3mZ0LJ7XrKRqiX 65qK4KAgqjcuqWZqbF2ced8F8/tIo7hLllEQ/YjlInobrkoWyXeqUslZknkODGneHqYQ wQ+RgBjZ/6H7zFuhSORTsyaWOySXmoXHw4j4S8H+ymgf8TwImBAx/g4689vrvzFw3iq/ Hang== X-Forwarded-Encrypted: i=1; AL+hErFY20kHf0FBH3SkDZfaUCi9ksb48RIoZe7SlBnoL1aERckUl0HwG0BZe1ELhK0ABINujbE8@lists.linux.dev X-Gm-Message-State: APuU4Z++UXxWFI4Mptq6yO5skdx05RRyaa4ANES1d3XdTJQgRNfWopSx bXOpnbSWzuoLyJsdU/wCcgyyok/1+kHb0cICcRb2nMq9hmcfCwbTj/Rs X-Gm-Gg: AZFdTZfZdblxDqwSw72SdJe1rmh/Wg4eh8UwwKht04EumnYV7QOBwOukjHHlpQcpiEE YE98T89dRlax/8b4vO9azP93eGOB1GcUX7JEpL+pp8tQrShG71WTFLleJbdwNcmY1AuyhS345GP eP1TJwvF/l2yBWngiVvWaDg5cjllaKDyP0UKk982g90PMU9h/18E52/BOxEsWR/22iTMBnmAIrx 0pnrDIN4XflMluhNO9b+kqT2ECxgkyEBeuMQ+g3lo78sjV7c9E2QqOITM8uPzeF1LGhmFReDZzw fP93ojbFrDq8zHTrnsfrsHqWPg+97CwOF1+sy5YfS8cjJJv3bZDEcmBO8r8Uj+rIX5QFD0O3F/2 RL6C3PkCKggGslzzEASJrrUxOalC0knAkBp/9/9AfoTLMYrNMyKS1a8fkYeKjaRzBIKvIzLKNNd TRvrFBXSunharwBn2DHcdWenkDuMdV4CbWN6Z7ZAk4mkBk726P8kdUUeVzpCvLXHOP9pkydQw6A vhs/Fh5A0c9tSivN3MCr/TBCRfth41VxDASvSNsfpRbZzjN7JC+IYlSCaf278vpIlgrH4rDdtQW IShFwuBjdEjHVIp1yPWtFN3l6ZVFo4alq0M/fjlcnH0Z5/TOVsALxmVph2tYzozU X-Received: by 2002:a05:600c:3b10:b0:4bb:db77:2a59 with SMTP id 5b1f17b1804b1-4bbdb7730a3mr34441425e9.14.1796233949361; Wed, 02 Dec 2026 09:52:29 -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-4bbe00dafdfsm3196845e9.12.2026.12.02.09.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 09:52:29 -0800 (PST) Date: Wed, 2 Dec 2026 17:52:27 +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: <20261202175227.68aedaa6@pumpkin> In-Reply-To: <2b03573f-da09-479c-a87d-6ac41737caa8@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> 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 Wed, 2 Dec 2026 11:13:24 +0100 "Christophe Leroy (CS GROUP)" wrote: > Le 02/12/2026 =C3=A0 10:57, David Laight a =C3=A9crit=C2=A0: > > 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 > >=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"); > >=20 > > 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 >=20 > What 'opcode' is that ? Because powerpc is a RISC processor, there is no= =20 > 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] "=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 A little contrived and the byte order is wrong but it is failing to do the expected atomic read of the 128bit value. David >=20 > With xor as opcode I get: >=20 > 11 .previous > 12 .type f, @function > 13 .L.f: > 14 .LFB0: > 15 ???? 00000010 .cfi_startproc > 15 00000000 > 15 017A5200 > 15 04784101 > 15 1B0C0100 > 16 ???? E9230000 ld 9,0(3) > 17 ???? F921FFF0 std 9,-16(1) > 18 ???? 60420000 ori 2,2,0 > 19 #APP > 20 # 5 "toto.c" 1 > 21 ???? 7E030278 xor 3,-16(1) > **** Error: operand out of range (-16 is not between 0 and 31) > **** Error: syntax error; found `(', expected `,' > 22 # 0 "" 2 > 23 #NO_APP > 24 ???? 4E800020 blr >=20 >=20 > > That really isn't what was intended. > > (I suspect it can also to the same for an output.) > > The only way I can see to avoid that is to explicitly pass the address > > in a register and use a memory clobber. > >=20 > > I wonder how much asm assumes a "m" operand references the > > 'obvious' memory area. > >=20 > > I'm not sure what the 'ori 2,2,0' is for. > > I also tried casting the pointer to a struct with a 'char x[]' > > member - that generated an ICE when it tried to copy it. > > Using volatile makes no difference. > >=20 > > David > >=20 > > =20 >=20 > Christophe