Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp616847ybz; Wed, 22 Apr 2020 04:53:14 -0700 (PDT) X-Google-Smtp-Source: APiQypJhldtEDpIJS8QVQ2/JvNkOMRXMQClc77QBEIyTanYuMBFAVLl9Zcs2P8dCiTlJQh1B/i/k X-Received: by 2002:a05:6402:b4c:: with SMTP id bx12mr16314331edb.247.1587556393873; Wed, 22 Apr 2020 04:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587556393; cv=none; d=google.com; s=arc-20160816; b=vYrkJW11LI2Cd1eQPT3gzZTaTR4klopOO5eZEaQX1Ym7tcv8WZSfpzo7PR9ogUs4c6 gysM+g18wMfo7lb2CL0CJod5YyrdNxiHKrgF822nVdthvv9M3NjwbrMQR/YK/6UviYng GrxUwIu/OciYVBNyydNaJiOMgAyyYnZDizMw4DwC1EQyrxXITX2Rzd/cW4vGkQsbK+lK jNgho2WcuaB2dE8PHqA7aaLIQxz138vybXKtwOoh2uzNnWIF3nvBIAaTVqPArTGBWjgS CCh5cjeSCvoRtJ/l864YeaaibWkqUrITlGwjBfGObxBAT0wWakLohOWgBAtVPi4cw7Ti X2Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=bvx9YB7TS01yDOdbJPnSki6YrgALag/kcrsrT263Nos=; b=O0PwtzSoK++edpqsSaAvfuN/0AzUP1eWJ6HVE4dNipQyHSy7EVW67h0VXq+4siHlmx nOCmt+LZYbDoSmTDfudqlYY0BIdv5ZyYS/uR3xDJUDCkZ5wV6GJAxh8P7SWyeX3wx0hx 1OfSoo1OYLtXgJ1IpN1gE1xtabLCXvthLe1h2PHeiUfDkMF9wYJvN46lOPJsCirh0Ngf 6n/yKQpJ+ilMQj2v5bBVIrt/+2Vd3UkfxA7zHezcipb6s6L+UMuJ7dhgfkjvc23wWBLb 9nN5p4nKYWS/3fB8WqeHZLO1Mb75W+mPuLbLQcy7Sxuuoi/adsUspaNFMJXLi0eZtUt/ g7gA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s16si3474330ejr.170.2020.04.22.04.52.49; Wed, 22 Apr 2020 04:53:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726886AbgDVLsj (ORCPT + 99 others); Wed, 22 Apr 2020 07:48:39 -0400 Received: from gate.crashing.org ([63.228.1.57]:54711 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbgDVLsi (ORCPT ); Wed, 22 Apr 2020 07:48:38 -0400 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 03MBm8vc003770; Wed, 22 Apr 2020 06:48:08 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 03MBm775003769; Wed, 22 Apr 2020 06:48:07 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Wed, 22 Apr 2020 06:48:07 -0500 From: Segher Boessenkool To: Rasmus Villemoes Cc: Will Deacon , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@android.com, Mark Rutland , Michael Ellerman , Peter Zijlstra , Linus Torvalds , Christian Borntraeger , Luc Van Oostenryck , Arnd Bergmann , Peter Oberparleiter , Masahiro Yamada , Nick Desaulniers Subject: Re: [PATCH v4 08/11] READ_ONCE: Drop pointer qualifiers when reading from scalar types Message-ID: <20200422114807.GW26902@gate.crashing.org> References: <20200421151537.19241-1-will@kernel.org> <20200421151537.19241-9-will@kernel.org> <6cbc8ae1-8eb1-a5a0-a584-2081fca1c4aa@rasmusvillemoes.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6cbc8ae1-8eb1-a5a0-a584-2081fca1c4aa@rasmusvillemoes.dk> User-Agent: Mutt/1.4.2.3i Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! On Wed, Apr 22, 2020 at 12:25:03PM +0200, Rasmus Villemoes wrote: > On 21/04/2020 17.15, Will Deacon wrote: > > Unfortunately, dropping pointer qualifiers inside the macro poses quite > > a challenge, especially since the pointed-to type is permitted to be an > > aggregate, and this is relied upon by mm/ code accessing things like > > 'pmd_t'. Based on numerous hacks and discussions on the mailing list, > > this is the best I've managed to come up with. > > Hm, maybe this can be brought to work, only very lightly tested. It > basically abuses what -Wignored-qualifiers points out: > > warning: type qualifiers ignored on function return type > > Example showing the idea: > > const int c(void); > volatile int v(void); > > int hack(int x, int y) > { > typeof(c()) a = x; > typeof(v()) b = y; > > a += b; > b += a; > a += b; > return a; > } Nasty. I like it :-) > Since that compiles, a cannot be const-qualified, and the generated code > certainly suggests that b is not volatile-qualified. So something like > > #define unqual_type(x) _unqual_type(x, unique_id_dance) > #define _unqual_type(x, id) typeof( ({ > typeof(x) id(void); > id(); > }) ) > > and perhaps some _Pragma("GCC diagnostic push")/_Pragma("GCC diagnostic > ignored -Wignored-qualifiers")/_Pragma("GCC diagnostic pop") could > prevent the warning (which is in -Wextra, so I don't think it would > appear in a normal build anyway). > > No idea how well any of this would work across gcc versions or with clang. https://gcc.gnu.org/legacy-ml/gcc-patches/2016-05/msg01054.html This is defined to work this way in ISO C since C11. But, it doesn't work with GCC before GCC 7 :-( Segher