Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4046787ybl; Mon, 13 Jan 2020 07:01:38 -0800 (PST) X-Google-Smtp-Source: APXvYqyu741/ej7LdLXyoBYbFz08TxfJ1k8pWG3HX1WhuUcwlJ0NTJnN5AcA2yhASqlFZ8ya1H21 X-Received: by 2002:a9d:6a5a:: with SMTP id h26mr13856891otn.103.1578927698722; Mon, 13 Jan 2020 07:01:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578927698; cv=none; d=google.com; s=arc-20160816; b=K6SIqrJoQNHaWbhhDekOawnXN7o4pZalnA3kbUjvtc49SpIwo6b5jQqPTfJn+SBEGj rcXIy3rqWsrHEy4/4CHISEjTaH3hQGbYgc5wQD9ICJLMIxpdijBVbZNcPang/HHAiba6 hNeyF5zaCYqEbq27F1QHHaIKUlgHk2dBaDFqUUOwEQYFQIFDTQ/MJMsH9n4iiLyivkdM odh3dsOAy79rpLpJ3/QRK1mRg1Klac68J7ybis5AG1uIzUph9W7o9jjoPaMPow9q3Zx/ g1/BurU34yTfvwlrx2OMzjATWcT8Gf/+jzPHQBmncP33gIrOmhwL4yDcREYgwyrE6N6o kGLg== 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=71lG7pepW5KN1uffJR+IzwFP/48f/rqvMyewL9Ow7GY=; b=DdVR5PHpteCiPiXErhRs2DlJ5TYQ6TRiZOti6fw2mQz776nDAAjtWtsiLWZ3gnHgzM Gkp6oPkhwCCNDi2ByCATkl7EpXV2uZ2+YqP6NROt4U9Yoy3yvYheZsXO3U0C9KKzIcpt iXZv1AKmnczAbcyznP7Vj/yb0VVUsQrfWLSA/IojIpl0v7iSqIlbIGBpqjao2z5nMGa1 7T7PnJVADVkimaR3P+C6UObKKOdKj5Y4AarDJ0adC6tUKcY9mKHvkswYUjcVwhSJeSAE AxJkgYHmKJKgwL80N7/zmCIo1yE4ig7qrpbHo7etKpLe0xYuGBDk/kD41ctgFa4HVcAY rSLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w+RfN76o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id w1si6479185oia.169.2020.01.13.07.01.25; Mon, 13 Jan 2020 07:01:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w+RfN76o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728984AbgAMPAB (ORCPT + 99 others); Mon, 13 Jan 2020 10:00:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:59178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728843AbgAMPAA (ORCPT ); Mon, 13 Jan 2020 10:00:00 -0500 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 EE9D6207FF; Mon, 13 Jan 2020 14:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578927599; bh=aa9EO2uekBujHfVtcvhLTBuPFLejzJ8R98SroFJlRlQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=w+RfN76orFFirc2tM4axk9pWZCEaqU4hy00VCYWN+oAs799sNABs+VESEs1g/ToMM fESl4+A/K/hkPREmlcWrobsTIMmVBBSNfUUpARLK6wwitllEcSBIbwOsARsS3ujke5 UtpTmgNbX2M2cjeOzC6Gg/BLqtMGpCm3T14KGats= Date: Mon, 13 Jan 2020 14:59:54 +0000 From: Will Deacon To: Linus Torvalds Cc: Linux Kernel Mailing List , linux-arch , Android Kernel Team , Michael Ellerman , Peter Zijlstra , Segher Boessenkool , Christian Borntraeger , Luc Van Oostenryck , Arnd Bergmann Subject: Re: [RFC PATCH 6/8] READ_ONCE: Drop pointer qualifiers when reading from scalar types Message-ID: <20200113145954.GB4458@willie-the-truck> References: <20200110165636.28035-1-will@kernel.org> <20200110165636.28035-7-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Fri, Jan 10, 2020 at 10:54:27AM -0800, Linus Torvalds wrote: > On Fri, Jan 10, 2020 at 8:56 AM Will Deacon wrote: > > > > +/* Declare an unqualified scalar type. Leaves non-scalar types unchanged. */ > > +#define __unqual_scalar_typeof(x) typeof( \ > > Ugh. My eyes. That's horrendous. > > I can't see any better alternatives, but it does make me go "Eww". I can't disagree with that, but the only option we've come up with so far that solves this in the READ_ONCE() macro itself is the thing from PeterZ: // Insert big fat comment here #define unqual_typeof(x) typeof(({_Atomic typeof(x) ___x __maybe_unused; ___x; })) That apparently *requires* GCC 4.8, but I think the question is more about whether it's easier to stomach the funny use of _Atomic or the nested __builtin_choose_expr() I have here. I'm also worried about how reliable the _Atomic thing is, or whether it's just an artifact of how GCC happens to work today. > Well, I do see one possible alternative: just re-write the bitop > implementations in terms of "atomic_long_t", and just avoid the issue > entirely. > > IOW, do something like the attached (but fleshed out and tested - this > patch has not seen a compiler, much less any thought at all). The big downside of this approach in preference to the proposal here is that as long as we've got volatile-qualified pointer arguments describing shared memory, I fear that we'll be playing a constant game of whack-a-mole adding non-volatile casts as you do below. The same problem manifests for the acquire/release accessors, which is why having something like __unqual_typeof() would be beneficial and at least the awfulness is contained in one place. So I suppose my question is: how ill does this code really make you feel? The disassembly is really nice! Will > include/asm-generic/bitops/lock.h | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/include/asm-generic/bitops/lock.h b/include/asm-generic/bitops/lock.h > index 3ae021368f48..071d8bfd86e5 100644 > --- a/include/asm-generic/bitops/lock.h > +++ b/include/asm-generic/bitops/lock.h > @@ -6,6 +6,12 @@ > #include > #include > > +/* Drop the volatile, we will be doing READ_ONCE by hand */ > +static inline atomic_long_t *atomic_long_bit_word(unsigned int nr, volatile unsigned long *p) > +{ > + return BIT_WORD(nr) + (atomic_long_t *)p; > +} > + > /** > * test_and_set_bit_lock - Set a bit and return its old value, for lock > * @nr: Bit to set > @@ -20,12 +26,12 @@ static inline int test_and_set_bit_lock(unsigned int nr, > { > long old; > unsigned long mask = BIT_MASK(nr); > + atomic_long_t *loc = atomic_long_bit_word(nr, p); > > - p += BIT_WORD(nr); > - if (READ_ONCE(*p) & mask) > + if (atomic_read(loc) & mask) > return 1; > > - old = atomic_long_fetch_or_acquire(mask, (atomic_long_t *)p); > + old = atomic_long_fetch_or_acquire(mask, loc); > return !!(old & mask); > } >