Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4540710imm; Wed, 30 May 2018 07:30:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJE2GOFmevd/S3vLV3Zr6/J3QkODO9g7KzfqhGaH33MpG+UumnGbpKUP2ZbTAPuFdsS4F5m X-Received: by 2002:a65:4a87:: with SMTP id b7-v6mr2428866pgu.271.1527690626830; Wed, 30 May 2018 07:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527690626; cv=none; d=google.com; s=arc-20160816; b=KMOSr9tfOvlUCbmouC1sZ6Y1F2G7KZfYvVfJSo9guNUnh3Bby9yyrxqp26TCWA8DLB aaiAoDRfZ5uS3n748Ah6TLaG6ntKpn1q8yckFkXnFdiL5Ek8rXycApuy409Xr0KoaPh6 b/HjO/T94RAeBOubwn5KI9vo8vmrg8mnaqtmQtmaKRAlRsigXsuNCneIniGdfyLELVJ9 1CR0u18rHW7DXKoqstAi8aUQA/HQ8/887vxoTb02+SM4lZQ7u3ULLxYSkiFdQ/zy+cYg H5emkw2xNfnKTSBz1qux0b4MEfn2X5UBnICiRjoZgWi4TuzPj24myhJ5v2jzdCyKOO8B +fcg== 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=9nDdLMlOwI1N+hCLgqGXlH0O2Rivr3LcB8r6o5Trj+Q=; b=wtqA3cH0+arWS1864YqQ92c9+wMvVzkc4/wFFWw3Vdrdu5Y5+Yj5SvgwZMLvYl/0Jm t054GqUKfcqRwUIOw74vSG5KT+4+5RIBkE86Gq6NMmVUao9T5CrZ2Ie4+nv+PckEa597 Grqd5td3lk6xrFOQJLcJhoG3p6aD90b7c0oy7umKy4SybwtOczi/ir8LOyazRwIOjStr WzVJ4HR4efG3kJydKx89hZOtYyjWwgDG5rkhlI5DtMdpj7xW+P1GCIX+MHWeXc/3kKU5 6CK3Q05AII9GsWbOFyT+k2YHBjHDZOQCkpVQMhiKjg6Hncudf3FWvg/e7/hDZd1kY+3N lUsA== 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 b3-v6si28380303pgr.76.2018.05.30.07.30.11; Wed, 30 May 2018 07:30:26 -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 S1753044AbeE3O3c (ORCPT + 99 others); Wed, 30 May 2018 10:29:32 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:36206 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751566AbeE3O3R (ORCPT ); Wed, 30 May 2018 10:29:17 -0400 Received: (qmail 1698 invoked by uid 2102); 30 May 2018 10:29:15 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 30 May 2018 10:29:15 -0400 Date: Wed, 30 May 2018 10:29:15 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Linus Torvalds cc: Paul McKenney , 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: 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, 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. > > 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. Your listing is slightly misleading. It really should be: A if (!B) ; // NOP D In other words, D should be beyond the end of the "if" statement, not inside one of the branches. At run time, of course, it doesn't matter; CPUs don't try to detect where the two branches of an "if" recombine. (Leaving aside issues like implementing an "if" as a move-conditional.) > 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. Remember, the original code was: A if (!B) C D So the execution of D is _not_ conditional, and it doesn't depend on A or B. (Again, CPUs don't make this distinction, but compilers do.) > 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. Not at all -- that point about the compiler is exactly what I was trying to get at. The object code the compiler generates depends on the contents of _both_ branches of the "if" statement, even though only one branch is executed at run time. Hence an analysis based entirely on what instructions are executed in a particular run (which is what herd does) will necessarily be incomplete. That's what happened here. The LKMM herd model treats statements beyond the end of an "if" statement as though the compiler can reorder them before the start of the "if", unless something in the branch which was taken prevents this reordering. But herd ignores the contents of the untaken branch, even when they would block the reordering. Alan