From mboxrd@z Thu Jan 1 00:00:00 1970 From: Will Deacon Subject: Re: [PATCH v4 08/11] READ_ONCE: Drop pointer qualifiers when reading from scalar types Date: Wed, 22 Apr 2020 14:11:29 +0100 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 Return-path: Content-Disposition: inline In-Reply-To: <20200422114807.GW26902@gate.crashing.org> Sender: linux-kernel-owner@vger.kernel.org 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 List-Id: linux-arch.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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Date: Wed, 22 Apr 2020 14:11:29 +0100 From: Will Deacon 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> Sender: linux-arch-owner@vger.kernel.org List-ID: 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 Message-ID: <20200422131129.WNovYwE3ostUcTddXfxV6VWFvMfql-LwcU-Q2-8aqTY@z> 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