Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4769600imm; Wed, 30 May 2018 11:37:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLwq++2fAN5J09SrcBWzMoX9hrGw0+/vwORbAdwlpw+PPVcUnGcnqMaBxhO7oBXAgYLm22e X-Received: by 2002:a17:902:24e:: with SMTP id 72-v6mr3814494plc.87.1527705452648; Wed, 30 May 2018 11:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527705452; cv=none; d=google.com; s=arc-20160816; b=rXVkEzpfTwsj4BIduChs19oZA9M1ZenRC1dKR0FjzaPmi4IQknlbKvZ1LRUpQWjbxs hLFhcx/OzWOj48mCXo0ZeEB9CdPzYH4X1jldaYJQj6LDOPfCa15aF9kGur7jXSxn29VR qaaMsca/cHPH1XDYY72I9UusxPylJry/VPx90//3e0gj2JuEHJlHTNsTwLopeWKc6ctI 5lnUE5EpZxBY03XaxpI5EjmMQjnDWlPg2AfkFDSli/MZgNQI47r7o1t7bTh7KsC8wLqd +vx+yBMwllE0MyehaXGzuIzWFotPjnT8c3ZR46r6K6PkZpDNaWL2yq/iCAfW7BMTufa3 HjaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date:arc-authentication-results; bh=ukbKA/oLEYEUhoUyAF8Q7k/SlAIFUSXPh8JP9CDcZyU=; b=EkfXLy67FkSphPRgLLHC/k91mOmm4LY2oWPnoDQK4hvHo66DZ8vKn0BU3AKcvGjLyX SlA/swh9pRpwY0Z3dd9LodQpMkUE/pNScfbhSm/CxuJDXcv+83FMlYlOaIb1nuxlzWp1 rTfO+UiOARq56qmq/xmeu1eeK1Em3fzj5Cb7vOucxovzwqQouBQLrljfvn17brOawmpk tZhvWDI0Y7HdJPk200HYHcGfNqGeVq6xxOzCfxrsLXg8FvhDf66fo1zL5wtz254ClfCW nelJRIGSxkdU0sC31putFRNY0ZP89lPcc05xY4Py9VWrWlb4Sk/2Iok74J0cmBmKIdtv +Hgg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w135-v6si35311291pff.340.2018.05.30.11.37.17; Wed, 30 May 2018 11:37:32 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932099AbeE3Sgx (ORCPT + 99 others); Wed, 30 May 2018 14:36:53 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:52730 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751684AbeE3Sgu (ORCPT ); Wed, 30 May 2018 14:36:50 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4UIYUKA124295 for ; Wed, 30 May 2018 14:36:50 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ja0vqhtf3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 30 May 2018 14:36:50 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 30 May 2018 14:36:48 -0400 Received: from b01cxnp23033.gho.pok.ibm.com (9.57.198.28) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 30 May 2018 14:36:43 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4UIaheh13566214 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 30 May 2018 18:36:43 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2332B2074; Wed, 30 May 2018 15:38:22 -0400 (EDT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C512AB206C; Wed, 30 May 2018 15:38:22 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.143.195]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 30 May 2018 15:38:22 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 0388A16C62CB; Wed, 30 May 2018 11:38:26 -0700 (PDT) Date: Wed, 30 May 2018 11:38:26 -0700 From: "Paul E. McKenney" To: Linus Torvalds Cc: Alan Stern , Linux Kernel Mailing List , linux-arch , andrea.parri@amarulasolutions.com, 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 Reply-To: paulmck@linux.vnet.ibm.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18053018-2213-0000-0000-000002B041A5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009099; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000264; SDB=6.01039938; UDB=6.00532201; IPR=6.00819071; MB=3.00021380; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-30 18:36:47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18053018-2214-0000-0000-00005A4D29B1 Message-Id: <20180530183826.GI7063@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-30_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1805300197 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 30, 2018 at 09:59:28AM -0500, Linus Torvalds wrote: > On Wed, May 30, 2018 at 9:29 AM Alan Stern > wrote: > > > > > > > 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. > > No. You're confused. > > You're confused because you're conflating two *entirely* different things. > > You're conflating the static source code with the dynamic execution. They > are NOT THE SAME. I am going to go out on a limb and assert that Linus is talking about what gcc and hardware do, while Alan is talking about what the tool and memory model do. In a perfect world, these would be the same, but it appears that the world might not be perfect just now. My current guess is that we need to change the memory-model tool. If that is the case, here are some possible resolutions: 1. Make herd's C-language control dependencies work the same as its assembly language, so that they extend beyond the end of the "if" statement. I believe that this would make Roman's case work, but it could claim that other situations are safe that are actually problematic due to compiler optimizations. The fact that the model currently handles only READ_ONCE() and WRITE_ONCE() and not unmarked reads and writes make this option more attractive than it otherwise be, compilers not being allowed to reorder volatile accesses, but we are likely to introduce unmarked accesses sometime in the future. 2. Like #1 above, but only if something in one of the "if"'s branches would prevent the compiler from reordering (smp_mb(), synchronize_rcu(), value-returning non-relaxed RMW atomic, ...). Easy for me to say, but I am guessing that much violence would be needed to the tooling to make this work. ;-) If I understand Alan correctly, there is not an obvious way to make this change within the confines of the memory model's .bell and .cat files. Thanx, Paul > It really should be: > > > A > > if (!B) > > ; // NOP > > D > > No it really really shouldn't. > > There are two completely different situations: > > (1) there is the source code: > > A > if (B) > C > D > > where C contains a barrier, and B depends on A and is not statically > determinable. > > In the source code, 'D' looks unconditional BUT IT DAMN WELL IS NOT. > > It's not unconditional - it's just done in both conditions! That's a big > big difference. > > > In other words, D should be beyond the end of the "if" statement, not > > inside one of the branches. > > You're just completely confused. > > What you are stating makes no sense at all. > > Seriously, your reading of the code is entirely monsenscal, and seems to be > about syntax, not about semantics. Which is crazy. > > Lookie here, you can change the syntactic model of that code to just be > > A > if (B) > C > D > else > D > > and that code obviously has the EXACT SAME SEMANTICS. > > So if you get hung up on trivial syntactic issues, you are by definition > confused, and your tool is garbage. You're doing memory ordering analysis, > not syntax parsing, for chrissake! > > > 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.) > > You cannot do it as a move-conditional, since that code generation would > have been buggy shit, exactly because of C. But that's a code generation > issue, not a run-time decision. > > So at run-time, the code ends up being > > A > if (!B) > D > > and D cannot be written before A has been read, because B depends on A, and > you cannot expose specutive writes before the preconditions have been > evaluated. > > > 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.) > > Again, the above is nothing but confused bullshit. > > D depends on B, which depends on A. > > Really. Really really. > > Anybody - or any tool - that doesn't see that is fundamentally wrong, and > has been confused by syntax. > > A *compiler* will very much also make that distinction. If it doesn't make > that distinction, it's not a compiler, it's a buggy piece of shit. > > Because semantics matter. > > Think about it. > > Linus >