Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3535463imw; Mon, 11 Jul 2022 10:25:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uav1CWubKx/w3ZuoD04E/00ndAIH8VOv2mIoYk/x4Ee5OI426BbCgIw8myieBNUYw8T8Zs X-Received: by 2002:a17:907:1612:b0:722:e1b9:45d0 with SMTP id hb18-20020a170907161200b00722e1b945d0mr19595118ejc.439.1657560315144; Mon, 11 Jul 2022 10:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657560315; cv=none; d=google.com; s=arc-20160816; b=G4urqMAwe8EkIJ/8/MZCwOBj7qB+sn0Xq8Q7zfz93AydSZQO/JStdm0eI21mK9V4LY 9kYwdW/n9FRXTTXiAlgbLT2+8xJyemh3P9npdErNQoJtyqhyd1I6lIHgBD6Dnmpejdkc xfuMftwtalYR2ro1KXs1pzELYTNs9bA9i9c53JnN07ioCUkPxAa3DHap5fwddFtYPKzd U5JRZS/HhSVibv4/c2ZaolY4BnVR4BMLGMczDOsTxcjjwK0hCwzRGSkL/Af/9pNAkaYa EKuDD+ZDNlg68veOZpRObbXynD1/ME9+EIT1kXB4vpUsQaauU3uXcx7wFqe+IJbXGDmL FC5Q== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=82iJG9xAOlzR9gcxQgrn79m37+5GKreu1NODfOqkE+0=; b=K+znKmNWQefF4UlZ9ibxNKEElovngzYNez2ww8X0vyK5c2w31SQJQ+m4oeW5/6c+Dw 0+fZvDnLUl5o8tiRBEvjwghdSmdT2fxDXTDoAQ+rhAUlyZNp1/b7DgWD2OwAGJOak0Mc +wX9B6oZOOmOpnnI8+Mj3Ersj/0rZP1x2II9NrhD//vTQgfdEZTJx0yxdPq89uptFLGl y7fUibWfDSZoM7KfDO3MnHxeCK9MkmHJJhnZvsC3kIq99SBt8t2rmZ8Lkpyq+yZFxfZP KkTA7OJOH7WlLiMyH0ZoBpCSG8P9z1DFwlrtnhFjDl0P02jVhNRH27MKfP7hCxEnNDLI 29qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sW4BxRBT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q29-20020a056402249d00b0043a91cd3039si144032eda.628.2022.07.11.10.24.49; Mon, 11 Jul 2022 10:25:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sW4BxRBT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbiGKQaT (ORCPT + 99 others); Mon, 11 Jul 2022 12:30:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbiGKQaQ (ORCPT ); Mon, 11 Jul 2022 12:30:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5BC311C09; Mon, 11 Jul 2022 09:30:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 35AAFB8105D; Mon, 11 Jul 2022 16:30:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3B8DC34115; Mon, 11 Jul 2022 16:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657557011; bh=mvqPbuaTIeF07jDnNksf18FEDwVUT+8krl/Dwsc6qno=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=sW4BxRBTLmwTu7pEMQct6C84C9TbhXs+7hJQQIh/SBV8ml9HL8ngYkDl842xy671o cNstVweeRHTuUPPJL/2PXsbAr8d3TXWeBJQmkGrP1vS+InJilS7jK9HCo0bSaEuQTD 0HQHaa5RKQBq9BL6+yzMsFqvPEvMkj18aZf7tjq7OL+fzhF9qyVU7+ZOfdstXom6JM FPOSpk+KmezzAmH0MksG8opnbea9yOLH29jIVy/ygiWftyhP9fiwlqbsQ+KtiqU5z9 e/zbzBSNaFMfjOu+94vfFrtZJfMOVuyKJp+FlQkeeMBui3jggDiGKF9kpXTTAOzY1B cfUpNlnkxl+wA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 78BFF5C03B9; Mon, 11 Jul 2022 09:30:11 -0700 (PDT) Date: Mon, 11 Jul 2022 09:30:11 -0700 From: "Paul E. McKenney" To: Paul =?iso-8859-1?Q?Heidekr=FCger?= Cc: Alan Stern , Marco Elver , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Daniel Lustig , Joel Fernandes , LKML , linux-arch , Charalampos Mainas , Pramod Bhatotia , Soham Chakraborty , Martin Fink Subject: Re: [PATCH v2] tools/memory-model: Clarify LKMM's limitations in litmus-tests.txt Message-ID: <20220711163011.GN1790663@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220614154812.1870099-1-paul.heidekrueger@in.tum.de> <20220708184749.GW1790663@paulmck-ThinkPad-P17-Gen-1> 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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mon, Jul 11, 2022 at 05:14:55PM +0200, Paul Heidekr?ger wrote: > > On 8. Jul 2022, at 20:47, Paul E. McKenney wrote: > > > > On Fri, Jul 08, 2022 at 10:45:06AM -0400, Alan Stern wrote: > >> On Fri, Jul 08, 2022 at 01:44:06PM +0200, Marco Elver wrote: > >>> On Tue, 14 Jun 2022 at 17:49, Paul Heidekr?ger > >>> wrote: > >>>> As discussed, clarify LKMM not recognizing certain kinds of orderings. > >>>> In particular, highlight the fact that LKMM might deliberately make > >>>> weaker guarantees than compilers and architectures. > >>>> > >>>> Link: https://lore.kernel.org/all/YpoW1deb%2FQeeszO1@ethstick13.dse.in.tum.de/T/#u > >>>> Signed-off-by: Paul Heidekr?ger > >>>> Co-developed-by: Alan Stern > >>> > >>> Reviewed-by: Marco Elver > >>> > >>> However with the Co-developed-by, this is missing Alan's SOB. > >> > >> For the record: > >> > >> Signed-off-by: Alan Stern > >> > >> (Note that according to Documentation/process/submitting-patches.rst, > >> the submitting author's SOB is supposed to come last.) > > > > And this is what I ended up with. Please provide additional feedback > > as needed, and in the meantime, thank you all! > > > > Thanx, Paul > > Looks great - my first commit in the Linux kernel! Congratulations!!! ;-) My commits for the upcoming merge window, which is probably 2-3 weeks from now, are already set. So this is targeted at the merge window after that, which is likely to be in late September or early October. So it is well on its way! Thanx, Paul > Thanks everyone! > > Paul > > > ------------------------------------------------------------------------ > > > > commit 3c7753e959706f39e1ee183ef8dcde3b4cfbb4c7 > > Author: Paul Heidekr?ger > > Date: Tue Jun 14 15:48:11 2022 +0000 > > > > tools/memory-model: Clarify LKMM's limitations in litmus-tests.txt > > > > As discussed, clarify LKMM not recognizing certain kinds of orderings. > > In particular, highlight the fact that LKMM might deliberately make > > weaker guarantees than compilers and architectures. > > > > Link: https://lore.kernel.org/all/YpoW1deb%2FQeeszO1@ethstick13.dse.in.tum.de/T/#u > > Co-developed-by: Alan Stern > > Signed-off-by: Alan Stern > > Signed-off-by: Paul Heidekr?ger > > Reviewed-by: Marco Elver > > Reviewed-by: Joel Fernandes (Google) > > Cc: Charalampos Mainas > > Cc: Pramod Bhatotia > > Cc: Soham Chakraborty > > Cc: Martin Fink > > Signed-off-by: Paul E. McKenney > > > > diff --git a/tools/memory-model/Documentation/litmus-tests.txt b/tools/memory-model/Documentation/litmus-tests.txt > > index 8a9d5d2787f9e..cc355999815cb 100644 > > --- a/tools/memory-model/Documentation/litmus-tests.txt > > +++ b/tools/memory-model/Documentation/litmus-tests.txt > > @@ -946,22 +946,39 @@ Limitations of the Linux-kernel memory model (LKMM) include: > > 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: > > + Conversely, LKMM will sometimes overestimate the amount of > > + reordering compilers and CPUs can carry out, leading it to miss > > + some pretty obvious cases of ordering. 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.) > > + The WRITE_ONCE() does not depend on the READ_ONCE(), and as a > > + result, LKMM does not claim ordering. However, even though no > > + dependency is present, the WRITE_ONCE() will not be executed before > > + the READ_ONCE(). There are two reasons for this: > > + > > + The presence of the smp_mb() in one of the branches > > + prevents the compiler from moving the WRITE_ONCE() > > + up before the "if" statement, since the compiler has > > + to assume that r1 will sometimes be 0 (but see the > > + comment below); > > + > > + CPUs do not execute stores before po-earlier conditional > > + branches, even in cases where the store occurs after the > > + two arms of the branch have recombined. > > + > > + It is clear that it is not dangerous in the slightest for LKMM to > > + make weaker guarantees than architectures. In fact, it is > > + desirable, as it gives compilers room for making optimizations. > > + For instance, suppose that a 0 value in r1 would trigger undefined > > + behavior elsewhere. Then a clever compiler might deduce that r1 > > + can never be 0 in the if condition. As a result, said clever > > + compiler might deem it safe to optimize away the smp_mb(), > > + eliminating the branch and any ordering an architecture would > > + guarantee otherwise. > > > > 2. Multiple access sizes for a single variable are not supported, > > and neither are misaligned or partially overlapping accesses.