Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1397785lqe; Mon, 8 Apr 2024 07:52:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqVlSrJYhHyqeV+fKowteB6gdrND70xUy655aYxmMTm+X0990YbL8yI5TU0foYzADMgv0/GDfi5/zX+YmW1Z3oepEUfQWSMUjgXegauQ== X-Google-Smtp-Source: AGHT+IFEU+gM3Rn018xVk1iRlPckXb448/a69scAw9PeS1hu0iepIJrcGpCcTvWGm+IwR8Rc2NtO X-Received: by 2002:a05:6512:3c8e:b0:514:88df:88b9 with SMTP id h14-20020a0565123c8e00b0051488df88b9mr8842982lfv.45.1712587931541; Mon, 08 Apr 2024 07:52:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712587931; cv=pass; d=google.com; s=arc-20160816; b=THfFIQr/KKw7U+loJhVhvXHN6Fz3BDfgoXVKx+kx2W2lReDhGSKdhusUXpKLajkF0n f+VFWIYCpgIhZ2LHCHBH4dtxOb+6aIqIDCjC34R1+7mVyhTo+NmIzhQFW+Rspsxl0GCY pn9fyh5D+me0NeXzE4F1hujMmLOfxotHlkjBujc9aziDfVyLkIDqoYlkI0FhMG8gGInM uvw5cSocZlFodMFzx4rK94WEsszL4Ty2vvaaTC01SCe9JFyl4xuN6ei41nLSMzYxIaoe kmx6pUb6qY3+6JUu9N9m3i7Yu7u/d6N3SIvgW0zp/L+XvZa53bcF6VLZsWnUTT4Dfo1M Y17A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=MNHRRjI6vNVHS29NESaVtVH92wM/wfaBYK2cTPWarwU=; fh=wU2X0rO14WhnoGu/wV8eel2oU3lfsXfbVh2f1uOOmF4=; b=lRJ9AhqElkoIdBDHDEw5vPDbKPZjaQSpc06z2uhfx/Apa9o2aBM4yj/JHKHVU/O/Os OjwlQwuRJPp2Nt5LsMX+5cCuVuPAIgeSiDexfIZGcivusLdxPbIjZ2/ZWIA4dZsz+/lj lZLMLFBbS+u7LvS1rXlpVt334hutiDWU+ZKc7Hy+V4wYheEyF/KWsxEnS6EM7JBh9CoW wttJZTg4dGG1R8hzaRjCpDosxiZeNojRK5712AynyzTsMD/jBGuuKgIL1cXDNZFFmLvQ GnCkTqRvNkvqg0/bkD+/uvz+ETrilhSCEIlMw7LWCy4g9F9tWHdObQJ3Jt42xGKApKkf Y+JA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-135556-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135556-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a9-20020a509b49000000b0056715a786ffsi3644151edj.544.2024.04.08.07.52.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 07:52:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135556-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-135556-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135556-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 36E761F21ED8 for ; Mon, 8 Apr 2024 14:52:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF3B813F423; Mon, 8 Apr 2024 14:52:01 +0000 (UTC) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5459313F00A for ; Mon, 8 Apr 2024 14:51:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.86.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712587921; cv=none; b=Qu6MvNRbEipkm7AD3BWDbO+u6lbrnHLeSLJv24kxkHcNttHSHrXehkhm5x6L/G9yTDZiE9c7QP/QbpFaSE/bWbotHO057sTDWkHXmjkzO5uYoftNKeG8qWrrimRd8ubHVm0yLk3d6u+HhSc3DBsqvB9Iak+MYhv4lRXPoKojZzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712587921; c=relaxed/simple; bh=joBS4N+InEhxAxePrDedqkg1DBS7fYz8aPowxWmurS4=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=F9Cbp7vmZbyiHCbHbdU1GYHsNE4WvkNRdP5utmZP7jF3IKLkZ2QaBbXMnGM9YWMChEQ26igt27LqzxGkls6nlg5huFVBvaLieEn6uQekjyJ2A9ofFWUj4OHS7QoiGsgCqfLe36VzDbLlVioTO4bPHpdyvdciQfuHGu2CWJ2sFsQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.86.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-71-6TRe-qOWOSiRkJM3kA_YFw-1; Mon, 08 Apr 2024 15:51:48 +0100 X-MC-Unique: 6TRe-qOWOSiRkJM3kA_YFw-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 8 Apr 2024 15:51:13 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 8 Apr 2024 15:51:13 +0100 From: David Laight To: 'Haris Okanovic' , "linux-kernel@vger.kernel.org" , "linux-pm@vger.kernel.org" , "linux-assembly@vger.kernel.org" CC: "peterz@infradead.org" Subject: RE: [PATCH 2/3] arm64: add __READ_ONCE_EX() Thread-Topic: [PATCH 2/3] arm64: add __READ_ONCE_EX() Thread-Index: AQHahJ/HcAF4vsIbZ0CGgbWFvfkyfLFefKGg Date: Mon, 8 Apr 2024 14:51:13 +0000 Message-ID: <1b659ba3fa50482a8338b1a6942884cc@AcuMS.aculab.com> References: <20240402014706.3969151-1-harisokn@amazon.com> <20240402014706.3969151-2-harisokn@amazon.com> In-Reply-To: <20240402014706.3969151-2-harisokn@amazon.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: Haris Okanovic > Sent: 02 April 2024 02:47 >=20 > Perform an exclusive load, which atomically loads a word and arms the > execusive monitor to enable wfe() polling of an address. >=20 > Adding this macro in preparation for an arm64 cpuidle driver which > supports a wfe() based polling state. >=20 > https://developer.arm.com/documentation/dht0008/a/arm-synchronization-pri= mitives/exclusive- > accesses/exclusive-monitors >=20 > Signed-off-by: Haris Okanovic > --- > arch/arm64/include/asm/readex.h | 46 +++++++++++++++++++++++++++++++++ > 1 file changed, 46 insertions(+) > create mode 100644 arch/arm64/include/asm/readex.h >=20 > diff --git a/arch/arm64/include/asm/readex.h b/arch/arm64/include/asm/rea= dex.h > new file mode 100644 > index 000000000000..51963c3107e1 > --- /dev/null > +++ b/arch/arm64/include/asm/readex.h > @@ -0,0 +1,46 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Based on arch/arm64/include/asm/rwonce.h > + * > + * Copyright (C) 2020 Google LLC. > + * Copyright (C) 2024 Amazon.com, Inc. or its affiliates. > + */ > + > +#ifndef __ASM_READEX_H > +#define __ASM_READEX_H > + > +#define __LOAD_EX(sfx, regs...) "ldaxr" #sfx "\t" #regs > + > +#define __READ_ONCE_EX(x)=09=09=09=09=09=09\ > +({=09=09=09=09=09=09=09=09=09\ > +=09typeof(&(x)) __x =3D &(x);=09=09=09=09=09\ > +=09int atomic =3D 1;=09=09=09=09=09=09=09\ > +=09union { __unqual_scalar_typeof(*__x) __val; char __c[1]; } __u;=09\ > +=09switch (sizeof(x)) {=09=09=09=09=09=09\ > +=09case 1:=09=09=09=09=09=09=09=09\ > +=09=09asm volatile(__LOAD_EX(b, %w0, %1)=09=09=09\ > +=09=09=09: "=3Dr" (*(__u8 *)__u.__c)=09=09=09\ > +=09=09=09: "Q" (*__x) : "memory");=09=09=09\ > +=09=09break;=09=09=09=09=09=09=09\ > +=09case 2:=09=09=09=09=09=09=09=09\ > +=09=09asm volatile(__LOAD_EX(h, %w0, %1)=09=09=09\ > +=09=09=09: "=3Dr" (*(__u16 *)__u.__c)=09=09=09\ > +=09=09=09: "Q" (*__x) : "memory");=09=09=09\ > +=09=09break;=09=09=09=09=09=09=09\ > +=09case 4:=09=09=09=09=09=09=09=09\ > +=09=09asm volatile(__LOAD_EX(, %w0, %1)=09=09=09\ > +=09=09=09: "=3Dr" (*(__u32 *)__u.__c)=09=09=09\ > +=09=09=09: "Q" (*__x) : "memory");=09=09=09\ > +=09=09break;=09=09=09=09=09=09=09\ > +=09case 8:=09=09=09=09=09=09=09=09\ > +=09=09asm volatile(__LOAD_EX(, %0, %1)=09=09=09\ > +=09=09=09: "=3Dr" (*(__u64 *)__u.__c)=09=09=09\ > +=09=09=09: "Q" (*__x) : "memory");=09=09=09\ > +=09=09break;=09=09=09=09=09=09=09\ > +=09default:=09=09=09=09=09=09=09\ > +=09=09atomic =3D 0;=09=09=09=09=09=09\ > +=09}=09=09=09=09=09=09=09=09\ > +=09atomic ? (typeof(*__x))__u.__val : (*(volatile typeof(__x))__x);\ I'm pretty sure that doesn't work the way you expect. The ?: operator promotes 'unsigned char' to 'int'. So you can fall foul of signedness tests (eg in min()). It also isn't going to work for non-scalers. Replacing the ?: with __builtin_choose_expr() may help. (This is probably a bug in the code you copied.) =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)