Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1735739imm; Sat, 2 Jun 2018 07:43:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLstToRH87Iply5+HIBGTBA7n8i/8+4D9YRmszHH1PwtorNSVawPX/aPa7ZIFXnahEtTb3E X-Received: by 2002:a62:db05:: with SMTP id f5-v6mr9503322pfg.123.1527950625036; Sat, 02 Jun 2018 07:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527950624; cv=none; d=google.com; s=arc-20160816; b=05iMEIzaiInBUTCQDuqeMMo2+U0d+Slcw0EYhVhSQuwon6DeN68IFHIA2ahGsgvVmx Eoi42JRsC+gmecsrS9E5IQTRY5hamadeXM/O9IuwtUPeU7owcqrqxbFy0uKe9yyX8EZa ib6QUfNWjDsRaFDRmJBH0P9fQh3Rm61SH3vkjI2Fl4dM1jr+jwUE0OtZ0oH0DwNdOTov J7WEv+Ub5zpB2XE1K9+bw6kCVWlNeb6frH+tjYrn/sPJD4AJK4d8tklnMDmWCLyAhKb3 ytIWNwV+kneqf0gzKXegjL46X0VDzvnCFEOa5heLMCnJxkxj1PvHApElWNmHVrgB9F9l 8TTQ== 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=IJXMuCgyg5KZvhmmSqC7ZYEjzdfNAqeaIyANDTMG7QI=; b=Zd7rcS9848bzSEamnu6FJ+PxjMSvFWuBHVVI6GtzxEY71jebDz1nLVw14K/ULwPLYE MdgAnpd8xvqdaUaRHYgnmzpa6dGs8BgOREhmjCks1KPvk8PtR5oJmcs2lCB3JkFhrsF/ uOjTafKGzmYZV//3xgP5DCUcJoAOpvLwgbL0+Xf7C0nSdZe6OeBuENGadbKi1MVlU+hQ vnYwoFA/p4H2qxApid3XmOesMo+W7cnANa6sZRyFiMRVxue18Plwcsv8QB8vnNGn76Fv ANE0XpGnfR972/TG/dAXvuCealUD5VHrFl9mpAhkEU1elgjRpKAOjIn4u9Y0YI7vNA3G 3Jng== 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 l70-v6si43289174pfk.129.2018.06.02.07.43.29; Sat, 02 Jun 2018 07:43:44 -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 S1751653AbeFBOnD (ORCPT + 99 others); Sat, 2 Jun 2018 10:43:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60408 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751068AbeFBOnB (ORCPT ); Sat, 2 Jun 2018 10:43:01 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w52EccIu037912 for ; Sat, 2 Jun 2018 10:43:00 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jbq4a9t2n-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 02 Jun 2018 10:43:00 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 2 Jun 2018 10:42:59 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Sat, 2 Jun 2018 10:42:55 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w52Egsdw10420488 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 2 Jun 2018 14:42:54 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 011ABB2064; Sat, 2 Jun 2018 11:44:31 -0400 (EDT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A138FB205F; Sat, 2 Jun 2018 11:44:30 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.165.93]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Sat, 2 Jun 2018 11:44:30 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 15A0C16C6529; Sat, 2 Jun 2018 07:44:40 -0700 (PDT) Date: Sat, 2 Jun 2018 07:44:40 -0700 From: "Paul E. McKenney" To: Alan Stern Cc: Linus Torvalds , 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: <20180530231441.GO7063@linux.vnet.ibm.com> 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: 18060214-0060-0000-0000-000002765FCB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009115; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01041257; UDB=6.00533081; IPR=6.00820386; MB=3.00021427; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-02 14:42:58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060214-0061-0000-0000-000045507660 Message-Id: <20180602144440.GI3593@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-02_07:,, 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-1806020174 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 31, 2018 at 10:27:33AM -0400, Alan Stern wrote: > On Wed, 30 May 2018, Paul E. McKenney wrote: > > > On Wed, May 30, 2018 at 05:01:01PM -0500, Linus Torvalds wrote: > > > On Wed, May 30, 2018 at 2:08 PM Alan Stern wrote: > > > > > > > > Indeed. The very first line Linus quoted in his first reply to me > > > > (elided above) was: > > > > > > > > Putting this into herd would be extremely difficult, if not impossible, > > > > because it involves analyzing code that was not executed. > > > > > > > > It should be clear from this that I was talking about herd. Not gcc or > > > > real hardware. > > > > > > So what does herd actually work on? The source code or the executable, > > > or a trace? > > > > The source code, that is, the source code of the litmus test. > > There are definitions for the various Linux operations, partly within > > the herd tool and partly in the linux.def file in tools/memory-model. > > The problem we are having is nailing down control dependencies and > > compiler optimizations. The bit about limiting control dependencies > > through the end of "if" statement itself works well in a great many cases, > > but this clearly is not one of them. > > > > > I found the herd paper, but I'm on the road helping my daughter in > > > college move, and I don't have the background to skim the paper > > > quickly and come up with the obvious answer, so I'l just ask. > > > > It is not a short learning curve. > > > > > Because I really think that from our memory model standpoint, we > > > really do have the rule that > > > > > > load -> cond -> store > > > > > > is ordered - even if the store address and store data is in no way > > > dependent on the load. The only thing that matters is that there's a > > > conditional that is dependent on the load in between the load and the > > > store. > > This is true for all the architectures supported by the Linux kernel. > However, in the future it might not always hold. I can imagine that > CPU designers would want to include an optimization that checks a > conditional branch to see if it skips over only the following > instruction (and the following instruction can't affect the flow of > control); in that situation, they might decide there doesn't need to be > a control dependency to future stores. Such an optimization would not > violate the C11 memory model. > > Of course, this is purely theoretical. And if anybody does decide to > try doing that, the memory-model people might scream at them so hard > they change their minds. :-) > > ... > > > > But I don't know what level 'herd' works on. If it doesn't see > > > compiler barriers (eg our own "barrier()" macro that literally is just > > > that), only sees the generated code, then it really has no other > > > information than what he compiler _happened_ to do - it doesn't know > > > if the compiler did the store after the conditional because it *had* > > > to do so, or whether it was just a random instruction scheduling > > > decision. > > > > The 'herd' tool works on litmus-test source, and has almost no idea of > > what compilers get up to. In this particular case, it would be better > > off being even more ignorant of what compilers get up to. ;-) > > In more detail, herd analyzes the source code and constructs a set of > all possible candidate executions. herd then checks each execution to > see if it violates the rules of the memory model as expressed in the > .bell and .cat files. If any of the non-violating executions satisfies > the litmus test's final "exists" condition, herd reports that the test > is allowed. > > The point here is that when herd checks any one particular execution, > it pays attention _only_ to the statements which are part of that > execution. Statements belonging to an untaken "if" branch are ignored > completely. That's why I think it would be difficult to make herd do > exactly what we want in this case. One crude but effective workaround is to replicate the code following the "if" statement into both legs of the "if" statement. This has the effect of extending the control dependency to cover all of the code that used to follow the "if" statement, leveraging herd's current limited knowledge of compiler optimization. This workaround would of course be hopeless for general Linux-kernel code, but should be at least semi-acceptable for the very small snippets of code that can be accommodated within litmus tests. Please see the litmus test shown below, which uses this workaround, allowing the smp_store_release() to be downgraded to WRITE_ONCE(). Given this workaround, crude though it might be, I believe that we can take a more measured approach to identifying a longer-term solution. Thoughts? Thanx, Paul ------------------------------------------------------------------------ C C-RomanPenyaev-list-rcu-rr-WA (* * The same as C-RomanPenyaev-list-rcu-rr.litmus, but working around herd's * having just the wrong level of understanding of compiler optimizations * for that particular litmus test. The trick is to replicate the code * following the "if" statement into both legs of that "if" statement. *) { int *z=1; (* List: v->w->x->y->z. Noncircular, but long enough. *) int *y=z; int *x=y; int *w=x; int *v=w; (* List head is v. *) int *c=w; (* Cache, emulating ppcpu_con. *) } P0(int *c, int *v, int *w, int *x, int *y) { rcu_assign_pointer(*w, y); /* Remove x from list. */ synchronize_rcu(); r1 = READ_ONCE(*c); if (r1 == x) { WRITE_ONCE(*c, 0); /* Invalidate cache. */ synchronize_rcu(); WRITE_ONCE(*x, 0); /* Emulate kfree(x). */ } else { WRITE_ONCE(*x, 0); /* Emulate kfree(x). */ } } P1(int *c, int *v) { rcu_read_lock(); r1 = READ_ONCE(*c); /* Pick up cache. */ if (r1 == 0) { r1 = READ_ONCE(*v); /* Cache empty, start from head. */ } r2 = rcu_dereference(*r1); /* Advance to next element. */ smp_store_release(c, r2); /* Update cache. */ rcu_read_unlock(); /* And repeat. */ rcu_read_lock(); r3 = READ_ONCE(*c); if (r3 == 0) { r3 = READ_ONCE(*v); } r4 = rcu_dereference(*r3); smp_store_release(c, r4); rcu_read_unlock(); } locations [0:r1; 1:r1; 1:r3; c; v; w; x; y] exists (1:r1=0 \/ 1:r2=0 \/ 1:r3=0 \/ 1:r4=0) (* Better not be freed!!! *)