Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp99346iof; Sun, 5 Jun 2022 22:20:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1yaGbGgKx7eJTdwC0c0W7ItEnP8o/NEhGnmZrrocGBJtRRc1ePSxveBJs9C5kNgOFfDW7 X-Received: by 2002:a17:90b:3e85:b0:1e8:8f2f:bd2f with SMTP id rj5-20020a17090b3e8500b001e88f2fbd2fmr1301548pjb.120.1654492822930; Sun, 05 Jun 2022 22:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654492822; cv=none; d=google.com; s=arc-20160816; b=IHoRLsWoB8UcpvhoWcEHYUE56MN0wwol2TxpTrjVDgVns76iL05Aymo0YexuLrSQwv DVH69SGlvz3hlRP+HbYVR+JAYMUBFVfsN3kEunq5Kk0v/qCP/+ikMXcn04TQBg7gXXQP t7kt6FA8ZC5wKHCwcVZiikEMfQpdPJT7OQCYsbtutveaVyRmXHlLkOxln7dFoDz7Ztur vr+NMOKcWCiHsllpWMCP9qS2zt6jWFZ3I+qCVDh9tJ3t+vCEIxytCzARL1GxoxjNFwcS rwZkb2j65vPvgL0r9DQn2bHVTTlANJbmv6RDqkNYWxF1D4D0n/SbVY+JEzZNSHbCqpH7 4+pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Cll8FEFdyXUiVesupbNEgqewfbCJRxSTJ4VQxVEJUNU=; b=egtVt6i+3mI+QiDw9scURK8Rq4J3t9NZ8q4vIt5sJxzOI1oftcQlpao6ZNCMWO48KZ C07r5YTP1kFDI7RwwPygoEOt61dFoZkiRCLqSJ2r182LJz9XDOdKNn6WpEnK6h3Qv9mc hhxQBcsL4Gpg6WuG1tMMjqs/LUj0vo46VorQTSkJLfI2r48stYE3ZAWxznJf4K4W0131 9rMO1XLNAT6KXDNTxutFLy6nJzcmvWdEIitVwyxuK5wTarM0sqYKSjC88I7xbq9E1ZCO +BdAb4cEiCBCnLPpeVjXul/jz0P62ebjMeFI/NxAr+cBo7+3w4RQNYDQhL3ehG1ZCIhU Dr2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c4-20020a056a000ac400b00518dcc47bc7si21709264pfl.55.2022.06.05.22.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:20:22 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 23B7D20A738; Sun, 5 Jun 2022 21:31:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245197AbiFCOsS (ORCPT + 99 others); Fri, 3 Jun 2022 10:48:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235709AbiFCOsQ (ORCPT ); Fri, 3 Jun 2022 10:48:16 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 799C41D0E9 for ; Fri, 3 Jun 2022 07:48:15 -0700 (PDT) Received: (qmail 303183 invoked by uid 1000); 3 Jun 2022 10:48:14 -0400 Date: Fri, 3 Jun 2022 10:48:14 -0400 From: Alan Stern To: Paul =?iso-8859-1?Q?Heidekr=FCger?= Cc: Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Marco Elver Subject: Re: (Non-) Ctrl Dependency in litmus-tests.txt? Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 03, 2022 at 04:12:37PM +0200, Paul Heidekr?ger wrote: > Hi all, > > I was going through litmus-tests.txt and came across the following: > > > LIMITATIONS > > =========== > > > > Limitations of the Linux-kernel memory model (LKMM) include: > > > > 1.Compiler optimizations are not accurately modeled. Of course, > > the use of READ_ONCE() and WRITE_ONCE() limits the compiler's > > ability to optimize, but under some circumstances it is possible > > for the compiler to undermine the memory model. For more > > information, see Documentation/explanation.txt (in particular, > > the "THE PROGRAM ORDER RELATION: po AND po-loc" and "A WARNING" > > sections). > > > > Note that this limitation in turn limits LKMM's ability to > > accurately model address, control, and data dependencies. > > For example, if the compiler can deduce the value of some variable > > carrying a dependency, then the compiler can break that dependency > > by substituting a constant of that value. > > > > Conversely, LKMM sometimes doesn't recognize that a particular > > optimization is not allowed, and as a result, thinks that a > > dependency is not present (because the optimization would break it). > > The memory model misses some pretty obvious control dependencies > > because of this limitation. A simple example is: > > > > r1 = READ_ONCE(x); > > if (r1 == 0) > > smp_mb(); > > WRITE_ONCE(y, 1); > > > > There is a control dependency from the READ_ONCE to the WRITE_ONCE, > > even when r1 is nonzero, but LKMM doesn't realize this and thinks > > that the write may execute before the read if r1 != 0. (Yes, that > > doesn't make sense if you think about it, but the memory model's > > intelligence is limited.) > > I'm unclear as to why the documentation sees a control dependency from > the READ_ONCE() to the WRITE_ONCE() here. > > Quoting from explanation.txt: > > Finally, a read event and another memory access event are linked by a > > control dependency if the value obtained by the read affects whether > > the second event is executed at all. > > Architectures might consider this control-dependent, yes, but since the > value of the if condition does not affect whether the WRITE_ONCE() is > executed at all, I'm not sure why this should be considered > control-dependent in LKMM? > > I might have another question about explanation.txt's definition of > control dependencies as per above, but will address it more thoroughly > in another email :-) You're right; strictly speaking this isn't a control dependency. In fact it's not a dependency at all, just an ordering restriction that's connected with a conditional test. If you would like to submit a patch updating the text, please feel free to do so. Alan