Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4556681imm; Wed, 30 May 2018 07:47:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ21bmgziNUVHIvtKj2y/dXCbDbc4RG6BVQn5qK1AySCIoLrXv13rA3J5ZLUaKnC7vCY+gy X-Received: by 2002:a62:6883:: with SMTP id d125-v6mr3098577pfc.26.1527691656886; Wed, 30 May 2018 07:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527691656; cv=none; d=google.com; s=arc-20160816; b=gT4+NF2ORPcyESZHmf5JzDEQEKtZDd+fu2m1Vy+iuD5RmxfshozIhB+d5E8doWkC5s dvZMIGj8m6kknD7NNd3tmHP6ZOl4n92yA5VW1alJk7lP01dN/0h9/Zi0+KK9z3m5y0ZE RIXNcGHVwZoimtIZ1Kt9/fpXvNguk6R/KraNezPF+LwL3xng+EFflkzyBO7KjtSIFcRm BwBDnUpRQo1je2n54UoEF/AJsYMU1TTlTe/T5aJdfyn+GxmSN7PFchc4xOBNEoXyGXt8 GQ7AsK4GRVnjmDb9v/sKSeQauVyZHFjSHVJukytrCa0UmufXQweqgO+HBBIgMFibRn2L RWgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date:arc-authentication-results; bh=1DjDRd6WCIJ95OXlGizo/jDFEP4FIkq1iBuLv81aaps=; b=kp/lIsBYXlqG5uYWFbYrDuhirGiOpaFvivIaNYt1s/FRE4XUJlErPJfeXm6gheLa68 7ond7mBWXHFUQQYxoo2FGy4uH5lXrM19MHEesV0yq3RL3BgpC1OYWMpNQgLJkFt2sjKG ZDC+/DfAGch/a9oKfx6aQxL+C/Zs3ZuYH7C3WW6PywZ0UCLzlmEtf7i1NXYG6BLeGfpa trv5lwfzHRu52VcC1tGwLQyBopQziHJNIu3CSQ1JJybTy9h2dUPW10NGFrPTiSIArGdP 6Eu3Rvz1pccrP2szOCS5H/5XnXkXOQtcIJ74YrdQJHJpHsGSmMIfZeE8XGRD/xwNJeJE 98rQ== 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 92-v6si33895811plw.299.2018.05.30.07.47.22; Wed, 30 May 2018 07:47:36 -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 S1753302AbeE3Oqq (ORCPT + 99 others); Wed, 30 May 2018 10:46:46 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:36504 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1750914AbeE3Oqm (ORCPT ); Wed, 30 May 2018 10:46:42 -0400 Received: (qmail 2524 invoked by uid 2102); 30 May 2018 10:46:41 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 30 May 2018 10:46:41 -0400 Date: Wed, 30 May 2018 10:46:41 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: "Paul E. McKenney" cc: Linus Torvalds , Linux Kernel Mailing List , linux-arch , , Will Deacon , Peter Zijlstra , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Ingo Molnar , Roman Pen Subject: Re: LKMM litmus test for Roman Penyaev's rcu-rr In-Reply-To: <20180529225321.GQ3803@linux.vnet.ibm.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 29 May 2018, Paul E. McKenney wrote: > On Tue, May 29, 2018 at 04:10:02PM -0500, Linus Torvalds wrote: > > On Tue, May 29, 2018 at 3:49 PM Alan Stern > > wrote: > > > > > Putting this into herd would be extremely difficult, if not impossible, > > > because it involves analyzing code that was not executed. > > One (ugly) way to handle it, assuming we are correct about what it > happening, would be to place ordering on the other side of the "if" > that is at least as strong as on the first side. Probably some example > that completely breaks this approach, though... > > > Does it? > > > > Can't we simplify the whole sequence as basically > > > > A > > if (!B) > > D > > > > for that "not B" case, and just think about that. IOW, let's ignore the > > whole "not executed" code. > > > > If B depends on A like you state, then that already implies that the write > > in D cannot come before the read of A. > > > > You fundamentally cannot do a conditional write before the read that the > > write condition depends on. So *any* write after a conditional is dependent > > on the read. > > > > So the existence of C - whether it has a barrier or not - is entirely > > immaterial at run-time. > > > > Now, the *compiler* can use the whole existence of that memory barrier in C > > to determine whether it can re-order the write to D or not, of course, but > > that's a separate issue, and then the whole "code that isn't executed" is > > not the issue any more. The compiler obviously sees all code, whether > > executing or not. > > > > Or am I being stupid and missing something entirely? That's possible. > > This will take some analysis, both to make sure that I got Roman's > example correct and to get to the bottom of exactly what LKMM thinks > can be reordered. I am shifting timezones eastward, so I am not going > to dig into it today. > > But here are a couple of things that take some getting used to: > > 1. The "if (r1 == x)" would likely be "if (r1 == &x)" in the Linux > kernel. > > 2. Unless there is something explicit stopping the reordering, the > herd tool assumes that the compiler can reorder unrelated code > completely across the entirety of an "if" statement. It might > well have decided that it could do so in this case, due to the > fact that the "if" statement isn't doing anything with x (just > with its address). > > But yes, given that r1 comes from the load from *c, it would > be difficult (at best) to actually apply that optimization in > this case. > > But let's find out what is really happening. Easy to speculate, but > much harder to speculate correctly. ;-) What's really happening is that herd doesn't realize the load from *c must execute before the store to x (as in your 2 above). You can see this if you add the following to linux-kernel.cat: let prop2 = ((prop \ id) & int) and then run the modified litmus test through herd with "-show prop -doshow prop2 -gv". The output graph has a prop2 link from the store to x leading back to the load from c, indicating that in this execution, the store must execute before the load. Alan