Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6116698ybi; Tue, 4 Jun 2019 19:22:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLw04M0G8nEuL41Yv/KxTDQhqxUdvzM8RauTBpEb6u2xZ7nJTTx4xWhnn/E9z629exoegU X-Received: by 2002:a63:7ca:: with SMTP id 193mr958842pgh.240.1559701377399; Tue, 04 Jun 2019 19:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559701377; cv=none; d=google.com; s=arc-20160816; b=gAu6KPN9XIWdwX8akVwBjEdoL6OmTaSbSUDE+QEIFPdSHOigkWEAPtfjsfLZK4yvAY hx1mHs2JjdHxgLH0GfUSrwtjRf8v420j+J0cQc4EQqX5DV2Zxt7wnkhwF/6C/NwqofMa GGzX/G5IpkTDP63LZ8zEgbI1IWpAAjJo9JnWPTplwUAoemhjhU05htJyw/W2ODi7Q14Y yehcHY4NDKiokVt1BTpKc+8WfhtrSu1hpeETeZhf+PfSHF/9ZgirvSF177UW0m6TbJqM Dks2HHs5v+tOxi8rCG/6uWQHqkR2DYk0zi25u/MVrVP7YyjWtq4YO+1ZAlBUkMV5BnXd 9+/Q== 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; bh=olAdX2d47J9syABxMHu+52lwF1Uk+p1PasVOjO6lcww=; b=DXmurY34ApvmaOjdpSsUSp+u4tpdlGgdhv06M/D+TCaDi8v8+oLqoWsDjH77f9XyKQ PGzEDYuVVr2v2bStjLRVtdvTgUpp4mAg8cIdiORwEKu9HuKUcEqA29NIY8VHlX40qFcu PmEPNrb3ZJ7bwnA7sMsrxeU37s6Fuluu4l5KC1KpROAKkYC/I+RBhy7H0Xmap8DX2xZ4 zvbewVjof1XsmC7MeosYZ/Z28q2q4c8IYb8zpFwVVa4XqWdz95eLMM7gBfkNhTW8GdI3 fVSWbtRpV86iNPFIWBDtXZ7pJl51rh9YyL38DTImzg/bLnxoBBBUlRMlZS6Sm0ELRHFd Kvaw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16si24216187plp.185.2019.06.04.19.22.40; Tue, 04 Jun 2019 19:22:57 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726527AbfFECVe (ORCPT + 99 others); Tue, 4 Jun 2019 22:21:34 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:52958 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfFECVd (ORCPT ); Tue, 4 Jun 2019 22:21:33 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1hYLYL-0004MT-Ux; Wed, 05 Jun 2019 10:21:26 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1hYLYD-0001by-GF; Wed, 05 Jun 2019 10:21:17 +0800 Date: Wed, 5 Jun 2019 10:21:17 +0800 From: Herbert Xu To: "Paul E. McKenney" Cc: Linus Torvalds , Frederic Weisbecker , Boqun Feng , Fengguang Wu , LKP , LKML , Netdev , "David S. Miller" Subject: Re: rcu_read_lock lost its compiler barrier Message-ID: <20190605022117.kw6tldcwhdkyqd6u@gondor.apana.org.au> References: <20150921193045.GA13674@lerouge> <20150921204327.GH4029@linux.vnet.ibm.com> <20190602055607.bk5vgmwjvvt4wejd@gondor.apana.org.au> <20190603000617.GD28207@linux.ibm.com> <20190603030324.kl3bckqmebzis2vw@gondor.apana.org.au> <20190603195304.GK28207@linux.ibm.com> <20190604211449.GU28207@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190604211449.GU28207@linux.ibm.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 04, 2019 at 02:14:49PM -0700, Paul E. McKenney wrote: > > Yeah, I know, even with the "volatile" keyword, it is not entirely clear > how much reordering the compiler is allowed to do. I was relying on > https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html, which says: The volatile keyword doesn't give any guarantees of this kind. The key to ensuring ordering between unrelated variable/register reads/writes is the memory clobber: 6.47.2.6 Clobbers and Scratch Registers ... "memory" The "memory" clobber tells the compiler that the assembly code performs memory reads or writes to items other than those listed in the input and output operands (for example, accessing the memory pointed to by one of the input parameters). To ensure memory contains correct values, GCC may need to flush specific register values to memory before executing the asm. Further, the compiler does not assume that any values read from memory before an asm remain unchanged after that asm; it reloads them as needed. Using the "memory" clobber effectively forms a read/write memory barrier for the compiler. Note that this clobber does not prevent the processor from doing speculative reads past the asm statement. To prevent that, you need processor-specific fence instructions. IOW you need a barrier(). Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt