Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4040366imw; Mon, 11 Jul 2022 23:47:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uXbsjvJzuksywH6bAjQxwaEPMhN4N8vhxLVwh+IdsLUiOMG21PZU8UNdIrIqqwDHKbL8Mt X-Received: by 2002:a17:902:da87:b0:16c:56d7:e002 with SMTP id j7-20020a170902da8700b0016c56d7e002mr4240070plx.27.1657608467290; Mon, 11 Jul 2022 23:47:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657608467; cv=none; d=google.com; s=arc-20160816; b=lzqX9C2kXxTe2+jW/mM/EdfVK9AVS9X+JqD8xo/Sh7bOgv70wMzdiewE8X/dM2ohdl Wu6r0vdNWSdBKkiEDfW7XkZI8Zc2kvp+oJJFzAunjxZkDkYtb5NrbyriehpJGts8yIfd iKeAl8wO0swf/jP5UoEhZrYxtXNPJQmdBpzUhwGPwtxewW4YDE8NDpge3xB3tr2Fc/N2 Lla6mjiC994ZnARivYfoulPEo2Nr46KAvo3p4FgYAP+oW6v+FjreLcShs6uwGbyyINxf kc/vkMZjbeiZrI88edbWWszkouOoZBaLL/EgfGXbOTAyTweGL3rNym1uhLUMqJga8G/B 0tVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=L5z0BKhZwBpamcT5arrYS2KRI63KC15oA+S8b1j4SMg=; b=s6rWlTMDKyiH/WhVutWUEgjmZNpXF1PXJhHlo16bYjrm4ngJw2TNw/PIrfx5hrw1+Z TBpmCebkpLjEgcKWLZY0QhkmEVn+mZdn0cp258S0dh51C/sOhM7x1k/nZ5KxjRpkLbA2 IrrF4baTy1aQeht93f6UWQA0ntS0FUx8cerUQ4x6PJlfuvUFYU5AaMUm26ZLmB4T4wDz Zk6AHvvfEH01Did9UgDfOCtKaLuKTJ7LJQppYxT0axotZcG5Ar9aQf3pOBYHHyR6ziQh 08CkdvkRrPdUs9+HPl5xE/moh1A6IjSbG4hMGOy03xrdgCKH45bYeM1zMl4KIjihu6wI 7yeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@in.tum.de header.s=20220209 header.b=QBRhqAxa; 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=tum.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o126-20020a634184000000b00412aa441addsi13040955pga.479.2022.07.11.23.47.34; Mon, 11 Jul 2022 23:47:47 -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=@in.tum.de header.s=20220209 header.b=QBRhqAxa; 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=tum.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232036AbiGLGp5 (ORCPT + 99 others); Tue, 12 Jul 2022 02:45:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbiGLGp4 (ORCPT ); Tue, 12 Jul 2022 02:45:56 -0400 Received: from mailout3.rbg.tum.de (mailout3.rbg.tum.de [131.159.0.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD2663DF1D; Mon, 11 Jul 2022 23:45:54 -0700 (PDT) Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mailout3.rbg.tum.de (Postfix) with ESMTPS id 12757101223; Tue, 12 Jul 2022 08:45:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=in.tum.de; s=20220209; t=1657608353; bh=L5z0BKhZwBpamcT5arrYS2KRI63KC15oA+S8b1j4SMg=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=QBRhqAxas4IG1fxQv/MvRjH/BMxY20t/HbGA7X8ZxqyB5ckEiF4mFvpSEW02mRhSz otNcnC1HooIAjLRxhgEDv+6SVVrBel7RNtfyzN363OvgM7wgIJtAOoTY8MCrEjlRyr mW1iTldHbMwsTY7g5OkmNyTeOZraRC+C/x0X0hT/nzCme1gv+UXMTKsb6l1YJM/Vh5 dINUDh4XF/8AaltlLQRmQuY+Uh+wlzOGqUAMJe05u4r4ancDtTtPH9UJzvG79b21KU u1ZuxZjSbLNPcSvz0wZjQOCnUkNgBDK2dtZbUGbH9sDTi1679emMitvAj24fenB6PI 4JjSjTNEVIuCg== Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id 0E5D1D6; Tue, 12 Jul 2022 08:45:53 +0200 (CEST) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id DF028D2; Tue, 12 Jul 2022 08:45:52 +0200 (CEST) Received: from mail.in.tum.de (vmrbg426.in.tum.de [131.159.0.73]) by mailrelay1.rbg.tum.de (Postfix) with ESMTPS id DAB1DCE; Tue, 12 Jul 2022 08:45:52 +0200 (CEST) Received: by mail.in.tum.de (Postfix, from userid 112) id D6B054A0226; Tue, 12 Jul 2022 08:45:52 +0200 (CEST) Received: (Authenticated sender: heidekrp) by mail.in.tum.de (Postfix) with ESMTPSA id F37204A0033; Tue, 12 Jul 2022 08:45:51 +0200 (CEST) (Extended-Queue-bit xtech_ma@fff.in.tum.de) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) Subject: Re: [PATCH v2] tools/memory-model: Clarify LKMM's limitations in litmus-tests.txt From: =?utf-8?Q?Paul_Heidekr=C3=BCger?= In-Reply-To: <20220711163011.GN1790663@paulmck-ThinkPad-P17-Gen-1> Date: Tue, 12 Jul 2022 08:45:51 +0200 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 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20220614154812.1870099-1-paul.heidekrueger@in.tum.de> <20220708184749.GW1790663@paulmck-ThinkPad-P17-Gen-1> <20220711163011.GN1790663@paulmck-ThinkPad-P17-Gen-1> To: "Paul E. McKenney" X-Mailer: Apple Mail (2.3696.100.31) X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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 Paul E. McKenney wrote: > On Mon, Jul 11, 2022 at 05:14:55PM +0200, Paul Heidekr=C3=BCger wrote: >>> On 8. Jul 2022, at 20:47, Paul E. McKenney = wrote: >>>=20 >>> 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=C3=BCger >>>>> 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. >>>>>>=20 >>>>>> Link: = https://lore.kernel.org/all/YpoW1deb%2FQeeszO1@ethstick13.dse.in.tum.de/T/= #u >>>>>> Signed-off-by: Paul Heidekr=C3=BCger = >>>>>> Co-developed-by: Alan Stern >>>>>=20 >>>>> Reviewed-by: Marco Elver >>>>>=20 >>>>> However with the Co-developed-by, this is missing Alan's SOB. >>>>=20 >>>> For the record: >>>>=20 >>>> Signed-off-by: Alan Stern >>>>=20 >>>> (Note that according to = Documentation/process/submitting-patches.rst,=20 >>>> the submitting author's SOB is supposed to come last.) >>>=20 >>> And this is what I ended up with. Please provide additional feedback >>> as needed, and in the meantime, thank you all! >>>=20 >>> Thanx, Paul >>=20 >> Looks great - my first commit in the Linux kernel! >=20 > Congratulations!!! ;-) Thanks! Hopefully many more to come :-) > 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. >=20 > So it is well on its way! Awesome! Many thanks, Paul > Thanx, Paul >=20 >> Thanks everyone! >>=20 >> Paul >>=20 >>> = ------------------------------------------------------------------------ >>>=20 >>> commit 3c7753e959706f39e1ee183ef8dcde3b4cfbb4c7 >>> Author: Paul Heidekr=C3=BCger >>> Date: Tue Jun 14 15:48:11 2022 +0000 >>>=20 >>> tools/memory-model: Clarify LKMM's limitations in litmus-tests.txt >>>=20 >>> 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. >>>=20 >>> 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=C3=BCger >>> 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 >>>=20 >>> 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. >>>=20 >>> - 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: >>>=20 >>> r1 =3D READ_ONCE(x); >>> if (r1 =3D=3D 0) >>> smp_mb(); >>> WRITE_ONCE(y, 1); >>>=20 >>> - 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 !=3D 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.=20= >>> + 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. >>>=20 >>> 2. Multiple access sizes for a single variable are not supported, >>> and neither are misaligned or partially overlapping accesses.