Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1229565pxb; Thu, 4 Mar 2021 06:38:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6vl5eO6VusPfYB5t+bCpvuYH3SSt79q6LfLxRcIfvpmhicxmRRBKAkPcoRnbfhz8x1zr8 X-Received: by 2002:a17:906:ccde:: with SMTP id ot30mr4624839ejb.550.1614868700083; Thu, 04 Mar 2021 06:38:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614868700; cv=none; d=google.com; s=arc-20160816; b=lEqRD/tTiXKDY79NItoeoW+2GSV93WwzOTkuwYcssBpapAmeWR/0H/HL6X6K6qkHr9 2g/PS1343XLU2tj6mxzbXrOA4I2NeerhDWOdPlQd4NezGNw6moUZeRu9FhuPWmgbO81b ELvcP5DAsMxPrJ789xe+w/9JQoftOodBh1V3UIGFHy2AbFm8sQKi/vgfR9CwzZ1WGzfk XuPXdnBX9Ips/fdcO6FyKq6sqzvPNRv/JHHhch9pSX3iGkIwx74RGb8fYWFTnaIRk1OR EPJh6HmM43/gfxgrX2slqMhd3b7wvsSYvtKopEMXnDLKWv/R/OzGx39wUiNC+ZPaX0L+ zsvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=/K25JmffsSG5civxbQ5LbpxAR6TLzv5Eg2aaxU8D2/M=; b=jdfVADmBGKrEcojyV3++nwm7lfvjIPotutoqguakq2npEFFw6DAgdKLaVX95gKl8+W c+B2vMSgt8GWjSE9s0aiZ6iiHJFp3Tc6eurxa3guPOUl3YNACg8PFZiYiBZtKuGq/B77 lCVLsbVekYx7XHe+kLqsFvV0e+wVEtU2a056VHIBs0pXRu4UccY0X6Aj6szat2yHg281 gR8hWXeHNZgLpgGd9AdK2zKUalP2GnaLymZBhRFRXvtzfv7r09PA9qnD76QG71e4fsQS GszZFzSN5qX3ModFG7qoKsCrCsReKSHRbEzm2V7Y4LjegkBQdtEPwhrVlKXw6ttKXqhG QjnQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz2si13700613ejb.140.2021.03.04.06.37.56; Thu, 04 Mar 2021 06:38:20 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232141AbhCDDOF (ORCPT + 99 others); Wed, 3 Mar 2021 22:14:05 -0500 Received: from netrider.rowland.org ([192.131.102.5]:57049 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S232255AbhCDDOD (ORCPT ); Wed, 3 Mar 2021 22:14:03 -0500 Received: (qmail 1595805 invoked by uid 1000); 3 Mar 2021 22:13:22 -0500 Date: Wed, 3 Mar 2021 22:13:22 -0500 From: Alan Stern To: Boqun Feng Cc: "Paul E. McKenney" , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , bpf , LKML , parri.andrea@gmail.com, Will Deacon , Peter Zijlstra , npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, dlustig@nvidia.com, joel@joelfernandes.org, Toke =?iso-8859-1?Q?H=F8iland-J=F8rgensen?= , "Karlsson, Magnus" Subject: Re: XDP socket rings, and LKMM litmus tests Message-ID: <20210304031322.GA1594980@rowland.harvard.edu> References: <20210302211446.GA1541641@rowland.harvard.edu> <20210302235019.GT2696@paulmck-ThinkPad-P72> <20210303171221.GA1574518@rowland.harvard.edu> <20210303174022.GD2696@paulmck-ThinkPad-P72> <20210303202246.GC1582185@rowland.harvard.edu> 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 04, 2021 at 09:26:31AM +0800, Boqun Feng wrote: > On Wed, Mar 03, 2021 at 03:22:46PM -0500, Alan Stern wrote: > > Which brings us back to the case of the > > > > dep ; rfi > > > > dependency relation, where the accesses in the middle are plain and > > non-racy. Should the LKMM be changed to allow this? > > > > For this particular question, do we need to consider code as the follow? > > r1 = READ_ONCE(x); // f > if (r == 1) { > local_v = &y; // g > do_something_a(); > } > else { > local_v = &y; > do_something_b(); > } > > r2 = READ_ONCE(*local_v); // e > > , do we have the guarantee that the first READ_ONCE() happens before the > second one? Can compiler optimize the code as: > > r2 = READ_ONCE(y); > r1 = READ_ONCE(x); Well, it can't do that because the compiler isn't allowed to reorder volatile accesses (which includes READ_ONCE). But the compiler could do: r1 = READ_ONCE(x); r2 = READ_ONCE(y); > if (r == 1) { > do_something_a(); > } > else { > do_something_b(); > } > > ? Although we have: > > f ->dep g ->rfi ->addr e This would be an example of a problem Paul has described on several occasions, where both arms of an "if" statement store the same value (in this case to local_v). This problem arises even when local variables are not involved. For example: if (READ_ONCE(x) == 0) { WRITE_ONCE(y, 1); do_a(); } else { WRITE_ONCE(y, 1); do_b(); } The compiler can change this to: r = READ_ONCE(x); WRITE_ONCE(y, 1); if (r == 0) do_a(); else do_b(); thus allowing the marked accesses to be reordered by the CPU and breaking the apparent control dependency. So the answer to your question is: No, we don't have this guarantee, but the reason is because of doing the same store in both arms, not because of the use of local variables. Alan