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=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=no 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 D6D45C433E0 for ; Thu, 2 Jul 2020 11:19:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 A48982070C for ; Thu, 2 Jul 2020 11:19:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ufXr52c+"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="TEOri34U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A48982070C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wRYAhtGJ1BfZ9IWL7cnqfgg4fVlMzxkOQPZvJQyRjFI=; b=ufXr52c+rDS0vqzPilb1p1f+9 vpHw0OnoWnmR0WADLZxAjQM814rH9vSx0Gwdr3m2vuVE+zwWyjcdceObsNX5vU4I/sfLIMTGaSiJ8 0pt+b1UI8lNgCf86xIoc4EyFvJZWe1UNX3W4mREd064LUoQjmmOHhA9UmnnCLH35MSr0tp0CT1O5V kRIlq93OGOla8ojrTr6FlCoQf5ecML3aeSWPUgfDbRzlPBdehaJbzdjlWNeKohlp1sMwctkwjDqQ9 wMZRxn5R1zVuhdeBUjEnxOwjtfrUdCiRkAn9Onz/rDg7scUcNfMxorz20RBgnGI4kyUQ9kafeXA8z EOjk4zPzQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqxEp-00013v-8C; Thu, 02 Jul 2020 11:18:43 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqxEm-000132-DU for linux-arm-kernel@lists.infradead.org; Thu, 02 Jul 2020 11:18:41 +0000 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 70F432070C; Thu, 2 Jul 2020 11:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593688719; bh=h84qaL3tEGgL2zFfFCmV5wFzP3FSpcWjx8fMB+KEr/4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TEOri34UXEVBKgcj4rLGB/bJmudCDMyJL+tLvCgKpyoj8RzaK4APPbgu5RGOTP3p5 5oXOCWMbf39NFuDmH+wlYd4Dc7VUwtHetvygZjh2VEHqUUXg8xiVgAGsUh4qOeP1r9 KRGIfHHvKVj65yixb+M3JOkgh2dE76YFoeN4R2m4= Date: Thu, 2 Jul 2020 12:18:33 +0100 From: Will Deacon To: Arnd Bergmann Subject: Re: [PATCH 04/18] alpha: Override READ_ONCE() with barriered implementation Message-ID: <20200702111832.GC16418@willie-the-truck> References: <20200630173734.14057-1-will@kernel.org> <20200630173734.14057-5-will@kernel.org> <20200702093239.GA15391@C02TD0UTHF1T.local> <20200702094833.GA16248@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200702_071840_605586_79670EF9 X-CRM114-Status: GOOD ( 20.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Marco Elver , Kees Cook , "Paul E. McKenney" , "Michael S. Tsirkin" , Peter Zijlstra , Catalin Marinas , Jason Wang , Nick Desaulniers , "linux-kernel@vger.kernel.org" , Josh Triplett , Ivan Kokshaysky , Sami Tolvanen , alpha , Alan Stern , Matt Turner , virtualization@lists.linux-foundation.org, Android Kernel Team , Boqun Feng , Linux ARM , Richard Henderson Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jul 02, 2020 at 12:08:41PM +0200, Arnd Bergmann wrote: > On Thu, Jul 2, 2020 at 11:48 AM Will Deacon wrote: > > On Thu, Jul 02, 2020 at 10:32:39AM +0100, Mark Rutland wrote: > > > On Tue, Jun 30, 2020 at 06:37:20PM +0100, Will Deacon wrote: > > > > -#define read_barrier_depends() __asm__ __volatile__("mb": : :"memory") > > > > +#define __smp_load_acquire(p) \ > > > > +({ \ > > > > + __unqual_scalar_typeof(*p) ___p1 = \ > > > > + (*(volatile typeof(___p1) *)(p)); \ > > > > + compiletime_assert_atomic_type(*p); \ > > > > + ___p1; \ > > > > +}) > > > > > > Sorry if I'm being thick, but doesn't this need a barrier after the > > > volatile access to provide the acquire semantic? > > > > > > IIUC prior to this commit alpha would have used the asm-generic > > > __smp_load_acquire, i.e. > > > > > > | #ifndef __smp_load_acquire > > > | #define __smp_load_acquire(p) \ > > > | ({ \ > > > | __unqual_scalar_typeof(*p) ___p1 = READ_ONCE(*p); \ > > > | compiletime_assert_atomic_type(*p); \ > > > | __smp_mb(); \ > > > | (typeof(*p))___p1; \ > > > | }) > > > | #endif > > I also have a question that I didn't dare ask when the same > code came up before (I guess it's also what's in the kernel today): > > With the cast to 'typeof(*p)' at the end, doesn't that mean we > lose the effect of __unqual_scalar_typeof() again, so any "volatile" > pointer passed into __READ_ONCE_SCALAR() or > __smp_load_acquire() still leads to a volatile load of the original > variable, plus another volatile access to ___p1 after > spilling it to the stack as a non-volatile variable? Not sure I follow you here, but I can confirm that what you're worried about doesn't happen for the usual case of a pointer-to-volatile scalar. For example, ignoring dependency ordering: unsigned long foo(volatile unsigned long *p) { return smp_load_acquire(p) + 1; } Ends up looking like: unsigned long ___p1 = *(const volatile unsigned long *)p; smp_mb(); (volatile unsigned long)___p1; My understanding is that casting a non-pointer type to volatile doesn't do anything, so we're good. On the other hand, you can still cause the stack reload if you use volatile pointers to volatile: volatile unsigned long *bar(volatile unsigned long * volatile *ptr) { return READ_ONCE(*ptr); } but this is pretty weird code, I think. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel