From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E5E6C38A2A for ; Thu, 7 May 2020 20:29:45 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E7A0E208CA for ; Thu, 7 May 2020 20:29:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="gwIjJPwh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7A0E208CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jWn94-00064Y-9I; Thu, 07 May 2020 20:29:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jWn92-00064S-NT for xen-devel@lists.xenproject.org; Thu, 07 May 2020 20:29:24 +0000 X-Inumbo-ID: 6f5e0ea6-90a1-11ea-9887-bc764e2007e4 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6f5e0ea6-90a1-11ea-9887-bc764e2007e4; Thu, 07 May 2020 20:29:24 +0000 (UTC) Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7B66B208CA; Thu, 7 May 2020 20:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588883361; bh=C/FjtARnN2djUbFPhCW9yNk/5S3TNogKH8l7LXGiYC4=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=gwIjJPwh6mEzOkMf/Tm/IoswjhNZx/MzBVpfXnGoP0ZGaQglVkoTK7gFLlotlMN7z NMDKd3WpkjX47AA9FjTu0l8PTR6Z5yL/84JxDVVBOSVTToPbYAxsaasye4LTCCW+eO m68+qlOBr+RTl/bgnl5I3MkydVRB2E3MfeoY2ilI= Date: Thu, 7 May 2020 13:29:21 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Julien Grall Subject: Re: [PATCH for-4.14 1/3] xen/arm: atomic: Allow read_atomic() to be used in more cases In-Reply-To: <20200502160700.19573-2-julien@xen.org> Message-ID: References: <20200502160700.19573-1-julien@xen.org> <20200502160700.19573-2-julien@xen.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , xen-devel@lists.xenproject.org, Julien Grall , Stefano Stabellini , Volodymyr Babchuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On Sat, 2 May 2020, Julien Grall wrote: > From: Julien Grall > > The current implementation of read_atomic() on Arm will not allow to: > 1) Read a value from a pointer to const because the temporary > variable will be const and therefore it is not possible to assign > any value. This can be solved by using a union between the type and > a char[0]. > 2) Read a pointer value (e.g void *) because the switch contains > cast from other type than the size of a pointer. This can be solved by > by introducing a static inline for the switch and use void * for the > pointer. > > Reported-by: Juergen Gross > Signed-off-by: Julien Grall > --- > xen/include/asm-arm/atomic.h | 37 +++++++++++++++++++++++++++--------- > 1 file changed, 28 insertions(+), 9 deletions(-) > > diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h > index e81bf80e305c..3c3d6bb04ee8 100644 > --- a/xen/include/asm-arm/atomic.h > +++ b/xen/include/asm-arm/atomic.h > @@ -71,18 +71,37 @@ build_add_sized(add_u32_sized, "", WORD, uint32_t) > #undef build_atomic_write > #undef build_add_sized > > +void __bad_atomic_read(const volatile void *p, void *res); > void __bad_atomic_size(void); > > +static always_inline void read_atomic_size(const volatile void *p, > + void *res, > + unsigned int size) > +{ > + switch ( size ) > + { > + case 1: > + *(uint8_t *)res = read_u8_atomic(p); > + break; > + case 2: > + *(uint16_t *)res = read_u16_atomic(p); > + break; > + case 4: > + *(uint32_t *)res = read_u32_atomic(p); > + break; > + case 8: > + *(uint64_t *)res = read_u64_atomic(p); > + break; > + default: > + __bad_atomic_read(p, res); > + break; > + } > +} > + > #define read_atomic(p) ({ \ > - typeof(*p) __x; \ > - switch ( sizeof(*p) ) { \ > - case 1: __x = (typeof(*p))read_u8_atomic((uint8_t *)p); break; \ > - case 2: __x = (typeof(*p))read_u16_atomic((uint16_t *)p); break; \ > - case 4: __x = (typeof(*p))read_u32_atomic((uint32_t *)p); break; \ > - case 8: __x = (typeof(*p))read_u64_atomic((uint64_t *)p); break; \ > - default: __x = 0; __bad_atomic_size(); break; \ > - } \ > - __x; \ > + union { typeof(*p) val; char c[0]; } x_; \ > + read_atomic_size(p, x_.c, sizeof(*p)); \ Wouldn't it be better to pass x_ as follows: read_atomic_size(p, &x_, sizeof(*p)); ? In my tests both ways works. I prefer the version with &x_ but given that it works either way: Reviewed-by: Stefano Stabellini > + x_.val; \ > }) > > #define write_atomic(p, x) ({ \ > -- > 2.17.1 >