Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp688820ybz; Wed, 22 Apr 2020 06:15:31 -0700 (PDT) X-Google-Smtp-Source: APiQypL5XmQijvmol4jJsB9ChZ8/RYraIkrAhGDKiCQFkd9LGTHi+FSvY5Z/gU5zAoeLdbLOn/Ck X-Received: by 2002:a17:906:4cc3:: with SMTP id q3mr17077704ejt.170.1587561331188; Wed, 22 Apr 2020 06:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587561331; cv=none; d=google.com; s=arc-20160816; b=LTFZlmrlO8z57VELm2BCZVYZQaDnRmzV5JGaYXNgs3Hl5tprVqbb9OhlnI5dkYRksy ZUO4mzhrE8kB9IESQruUZzxRnNS8mXzcoF0oZy0IYnN0HGfBaVz6oEEKzhSWBhjHoBy2 Krfnv/1TR0T1/tD7yhdHKXLIhGDxG125XD7JhiNDDlKKCDEkX+vG7vxS3A2nTxERZ2fe FDqa0dFypvTwD+u6l012TmGlfgvyg34Pfh0jdL2SZzag94Q+6Wz5U1TyUpet+Mebfbqp f4obfeUBabVnc7ttVnJT0ZmvVcdYU5K4lh0q5nz6Wt2NECoBStb1EYqIytWh0ImynXL6 yY4g== 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:dkim-signature; bh=F9ptB6ZyfdLU+jcHiT7fa0yvQEJF8TGN3Q6g+XPRlcU=; b=cpwZQiEkRqKRo7m7K4Khdam1ZZ6Q4IwzJqOdM/IVobTWlQZdPNWQl/S1yHJmA/6H5M EhaBQHlUuD6R/rw3G4psLBo+Gp1WLuscfX9OMBFE+10apbPVEHhwMhMJjeEpbcCOUF8Z H+hPTXmCoR78ykvfMv222QgX9swiVKA3gpRtsMAaK5dJfVRhNI7FTtMSPeHZtaH9Yc5a W5+rHmdEctrAAwUswzGwE09qCiI7Bdxv+bhHcuL+oT2J6Wr+JEwBXSaDp8JzCQ0/gA3n 73J31WrLKT4ikOoFgka7ufXYgxoSeYA55P4ZiNJ0Ksvjk92tWGXq3Snv8Vf3KN7xBntV FB+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v6jRO1wq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si3717526edj.328.2020.04.22.06.15.01; Wed, 22 Apr 2020 06:15:31 -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; dkim=pass header.i=@kernel.org header.s=default header.b=v6jRO1wq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726470AbgDVNLg (ORCPT + 99 others); Wed, 22 Apr 2020 09:11:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:49440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725968AbgDVNLf (ORCPT ); Wed, 22 Apr 2020 09:11:35 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 B6185206EC; Wed, 22 Apr 2020 13:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587561095; bh=Tu2PhKwHoYwGdCMbzyqBBm0RFMgjXtqVtWkHT7kOUgs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=v6jRO1wqjLWNb15qOHzZPEh06O5wuzuJ6stgN9cO44T8aCtBV74dCkm9xQU3/jxmh ZfyIYbNNNjpeqEBnsZjgmGaQYC9+8QKkkvWMyjOFORT6GUk2ocvRg1btJSjKFB36Hk NuonA+CD6aDAtMRoDAs3KegQJoCcz74fIi3x3wdk= Date: Wed, 22 Apr 2020 14:11:29 +0100 From: Will Deacon To: Segher Boessenkool Cc: Rasmus Villemoes , 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: <20200422131129.GC676@willie-the-truck> References: <20200421151537.19241-1-will@kernel.org> <20200421151537.19241-9-will@kernel.org> <6cbc8ae1-8eb1-a5a0-a584-2081fca1c4aa@rasmusvillemoes.dk> <20200422114807.GW26902@gate.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422114807.GW26902@gate.crashing.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 22, 2020 at 06:48:07AM -0500, Segher Boessenkool wrote: > 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 :-( Damn, that's quite a cool hack! Maybe we'll be able to implement it in a few years time ;) WIll