Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1540459ybt; Thu, 2 Jul 2020 07:56:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIOHKpzY4xsoM5bLhNYLFXgwj/IjGvJ09jyLiy/6aufBdhMxcFzvllzKOJLMJnHKtA4QGh X-Received: by 2002:a17:906:a242:: with SMTP id bi2mr23108898ejb.243.1593701772402; Thu, 02 Jul 2020 07:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593701772; cv=none; d=google.com; s=arc-20160816; b=U8QjBJXs6zBSQK8MP7NVjWCxFbTs1g7b1XvZQUr1o5ogbeXqRRfB2ACwpj2FcmOw8B A440aFrBqiZjVT1mZgfElMZ+DoDhZ72SQBn8nfLe2AN15ahDRrvj3B6V0kslpsgx63zd p6Tl6fBeuIewmo1t6S1PnNQ5lf1S8I2Ip4pyOREV7iVPcDfnhMSq40560fTez1QHZ2QH PI6kdnINCOxT1ajg08SD6RBDYLIj3QsfOw9o3R8rVGHdbOuuYVpEquPqeM6AgpQlaM7m O1/mWbnQHaJ/+YM9w8fA0Ikh82PczqLeCfHcSulKUDBWd5RUa1V+rkVakW/qVbrw/2pE NGmw== 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=KFU6w73kgm0vriYORwPiDwnUeFitzjXbo4HBle4xvgo=; b=yqP4V8KTpig6w22slhEiGgpSdosIb5oNN3iLp0Up9o2jCQ5yM63th58loqOdiT1X8j 1aP4too5sKLskThVqsXJpGo/AnVjH1RKC7arAfaTiby1emPUvJh31D3kyIwuhVepd3D+ CItmfPCq+V24rP+pQHbffM9N935loFpquImm0NkiIe18SDXv8dBrZcks0wivLmUVHABU cRcS1ruwDxGry2J0rXJhe7lbI27SOyesmXc4Fv29nPvSBkWOINhYTr/MvDzmxvBqodxS YA0V1KpuUqpoCxcWgCECj5z+Kp4E3Z+5d0GmFozv9HpP9rSSzzfyCzMqZHGbTCa/euOj bibA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PcEiNPxu; 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 b22si6111963edt.334.2020.07.02.07.55.50; Thu, 02 Jul 2020 07:56:12 -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=PcEiNPxu; 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 S1729518AbgGBOzn (ORCPT + 99 others); Thu, 2 Jul 2020 10:55:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:37196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726032AbgGBOzm (ORCPT ); Thu, 2 Jul 2020 10:55:42 -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 1105F2075D; Thu, 2 Jul 2020 14:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593701741; bh=nbXe6nJCNrMku6QIpQkPDTVx3nVSr/HZ3tO6LrfZY8Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PcEiNPxuhlEyLh2HMXcrpBV1EC5XLsFjtMKSlRSdePnrAVWjczQYEysgptdOEIbNb QjfUU6jDXo4nj7OwF7ffPzJvSQ1L4KMCNuYjhVu7foez1h5841jqZdO+/Wfss7iN0Y tyFLYFMHbSNeYbjpimnr2GDt6pYflThH5++ITr0w= Date: Thu, 2 Jul 2020 15:55:33 +0100 From: Will Deacon To: Joel Fernandes Cc: LKML , Sami Tolvanen , Nick Desaulniers , Kees Cook , Marco Elver , "Paul E. McKenney" , Josh Triplett , Matt Turner , Ivan Kokshaysky , Richard Henderson , Peter Zijlstra , Alan Stern , "Michael S. Tsirkin" , Jason Wang , Arnd Bergmann , Boqun Feng , Catalin Marinas , Mark Rutland , "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , linux-alpha@vger.kernel.org, virtualization@lists.linux-foundation.org, "Cc: Android Kernel" , "Joel Fernandes (Google)" Subject: Re: [PATCH 04/18] alpha: Override READ_ONCE() with barriered implementation Message-ID: <20200702145532.GB16999@willie-the-truck> References: <20200630173734.14057-1-will@kernel.org> <20200630173734.14057-5-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 Hi Joel, On Thu, Jul 02, 2020 at 10:43:55AM -0400, Joel Fernandes wrote: > On Tue, Jun 30, 2020 at 1:38 PM Will Deacon wrote: > > diff --git a/arch/alpha/include/asm/barrier.h b/arch/alpha/include/asm/barrier.h > > index 92ec486a4f9e..2ecd068d91d1 100644 > > --- a/arch/alpha/include/asm/barrier.h > > +++ b/arch/alpha/include/asm/barrier.h > > - * For example, the following code would force ordering (the initial > > - * value of "a" is zero, "b" is one, and "p" is "&a"): > > - * > > - * > > - * CPU 0 CPU 1 > > - * > > - * b = 2; > > - * memory_barrier(); > > - * p = &b; q = p; > > - * read_barrier_depends(); > > - * d = *q; > > - * > > - * > > - * because the read of "*q" depends on the read of "p" and these > > - * two reads are separated by a read_barrier_depends(). However, > > - * the following code, with the same initial values for "a" and "b": > > - * > > Would it be Ok to keep this example in the kernel sources? I think it > serves as good documentation and highlights the issue in the Alpha > architecture well. I'd _really_ like to remove it, as I think it only serves to confuse people on a topic that is confusing enough already. Paul's perfbook [1] already has plenty of information about this, so I don't think we need to repeat that here. I could add a citation, perhaps? > > - * > > - * CPU 0 CPU 1 > > - * > > - * a = 2; > > - * memory_barrier(); > > - * b = 3; y = b; > > - * read_barrier_depends(); > > - * x = a; > > - * > > - * > > - * does not enforce ordering, since there is no data dependency between > > - * the read of "a" and the read of "b". Therefore, on some CPUs, such > > - * as Alpha, "y" could be set to 3 and "x" to 0. Use rmb() > > - * in cases like this where there are no data dependencies. > > - */ > > -#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; \ > > +}) > > I had the same question as Mark about the need for a memory barrier > here, otherwise alpha will again break right? Looking forward to the > future fix you mentioned. Yeah, sorry about that. It went missing somehow during the rebase, it seems. > BTW, do you know any architecture where speculative execution of > address-dependent loads can cause similar misorderings? That would be > pretty insane though. In Alpha's case it is not speculation but rather > the split local cache design as the docs mention. The reason I ask > is it is pretty amusing that control-dependent loads do have such > misordering issues due to speculative branch execution and I wondered > what other games the CPUs are playing. FWIW I ran into [1] which talks > about analogy between memory dependence and control dependence. I think you're asking about value prediction, and the implications it would have on address-dependent loads where the address can itself be predicted. I'm not aware of an CPUs where that is observable architecturally. arm64 has some load instructions that do not honour address dependencies, but I believe that's mainly to enable alternative cache designs for things like non-temporal and large vector loads. Will [1] https://mirrors.edge.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html