Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1613040pxb; Thu, 4 Mar 2021 16:22:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBac0EhZJ54hbK8sE6Z7KlS35AbAtEo+x9IjxUuL8CkZIApsawux4WIgkh0mvaPtN7HJ+v X-Received: by 2002:a50:c00b:: with SMTP id r11mr7023412edb.35.1614903768688; Thu, 04 Mar 2021 16:22:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614903768; cv=none; d=google.com; s=arc-20160816; b=LUHUzSb2IUl8ly7f5AAXg68XVzocW0aorcO/B6KSb7+eQRKfbXrT6EnlYt19Ku4PWG GIhYyo0W0MrCPd1vbMk4B3mFGMZJfXfb57A5JUIGJo9SCJV1eOIvaeBzcr9XIvIU7hVe LVnHJzfa6K/jwPU7d+cqDMn6CIyByQL89yxevkUb61ld6dLEk9JJrsLztDWJqZPgiywT aF9tutFNRd9uR3tp0w4qVmtOjJYYiXfhXlB7ilmb8tvi6T37zmrt8kCBcuBJQVOjaWlQ tizXgbzcUUONM916rxFa4OTltbnuvdzFeyBjDeQBS1QA15PSXk9w3F8UoogUVTopHX8h Fmhw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ytLGHAyQEbCTk3kE3vEpb15WMXzGH65Bqe0l8YsaAVQ=; b=q60Kvtkfq26T3MbO7tdpvQXX4ivdKeZZBqftBZZZjfQBxM9OD5/gSYKqQbSMeKewqN 6kht3ULtj+RoDibLCEjyuN30lmFaTjJUdEuBl+TSBYipMdogqZptnzV0DuFvXVbgo/3m cGz+R4HpuH0kiAKYcgAFulv0RZzIgmtR9buwaGVcpmwdW5To0Bxc5Ofc3xWl1eEKsT4n kE0ziFTARewVlZXpuvR8ttg9nql+UwR9P44h7cilXdAnBww4ujar1BFYSsn2Q9fyNt/s pYPn8r3csW7lOqTPGaQAzYvNUZA4LnLdQh6El4aXwPydASIqpBgLbX4Pg1tMaDJHNPQj i6+g== 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 cf2si413597ejb.332.2021.03.04.16.22.26; Thu, 04 Mar 2021 16:22:48 -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 S235381AbhCDQMh (ORCPT + 99 others); Thu, 4 Mar 2021 11:12:37 -0500 Received: from netrider.rowland.org ([192.131.102.5]:42035 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S236552AbhCDQMX (ORCPT ); Thu, 4 Mar 2021 11:12:23 -0500 Received: (qmail 1614672 invoked by uid 1000); 4 Mar 2021 11:11:42 -0500 Date: Thu, 4 Mar 2021 11:11:42 -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: <20210304161142.GB1612307@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> <20210304031322.GA1594980@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 02:33:32PM +0800, Boqun Feng wrote: > Right, I was thinking about something unrelated.. but how about the > following case: > > local_v = &y; > r1 = READ_ONCE(*x); // f > > if (r1 == 1) { > local_v = &y; // e > } else { > local_v = &z; // d > } > > p = READ_ONCE(local_v); // g > > r2 = READ_ONCE(*p); // h > > if r1 == 1, we definitely think we have: > > f ->ctrl e ->rfi g ->addr h > > , and if we treat ctrl;rfi as "to-r", then we have "f" happens before > "h". However compile can optimze the above as: > > local_v = &y; > > r1 = READ_ONCE(*x); // f > > if (r1 != 1) { > local_v = &z; // d > } > > p = READ_ONCE(local_v); // g > > r2 = READ_ONCE(*p); // h > > , and when this gets executed, I don't think we have the guarantee we > have "f" happens before "h", because CPU can do optimistic read for "g" > and "h". In your example, which accesses are supposed to be to actual memory and which to registers? Also, remember that the memory model assumes the hardware does not reorder loads if there is an address dependency between them. > Part of this is because when we take plain access into consideration, we > won't guarantee a read-from or other relations exists if compiler > optimization happens. > > Maybe I'm missing something subtle, but just try to think through the > effect of making dep; rfi as "to-r". Forget about local variables for the time being and just consider dep ; [Plain] ; rfi For example: A: r1 = READ_ONCE(x); y = r1; B: r2 = READ_ONCE(y); Should B be ordered after A? I don't see how any CPU could hope to excute B before A, but maybe I'm missing something. There's another twist, connected with the fact that herd7 can't detect control dependencies caused by unexecuted code. If we have: A: r1 = READ_ONCE(x); if (r1) WRITE_ONCE(y, 5); r2 = READ_ONCE(y); B: WRITE_ONCE(z, r2); then in executions where x == 0, herd7 doesn't see any control dependency. But CPUs do see control dependencies whenever there is a conditional branch, whether the branch is taken or not, and so they will never reorder B before A. One last thing to think about: My original assessment or Bj?rn's problem wasn't right, because the dep in (dep ; rfi) doesn't include control dependencies. Only data and address. So I believe that the LKMM wouldn't consider A to be ordered before B in this example even if x was nonzero. Alan