Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3429585imw; Mon, 11 Jul 2022 08:29:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vrqipd8G9PoE8+tGoWsHZVkp0M/vUjN+pbzAziVyLlhtid0zH9wZad9kgIICpA4vmfmmBf X-Received: by 2002:a63:6404:0:b0:415:fa99:e287 with SMTP id y4-20020a636404000000b00415fa99e287mr5780995pgb.220.1657553382400; Mon, 11 Jul 2022 08:29:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657553382; cv=none; d=google.com; s=arc-20160816; b=dR4NsKXYl3bSC0ZAmFmW1XqMHHi1r+kPG6jCiJibQkm8mf1qgiKMTTRneG34AA8ZHh 1Ql711xRL2V2Mba6TNChwfb/hTeGq8bJM1KogiTyT0EuYpXOglTy22nHQ3vovstbYgbI N8qLiClmPY4TpTxp7XL3t4ag/KeWwMN91neO6D9Wvuyoy5hRyjADfPhIz+SObDdaarUh eBm6UzbQw/xQx6UiKWyAD9uYHEFOwfNVWMt8vrmZd0xGMfQj4OYJHko7ZnvVW1K9LVYU MuMrl4jWY2sUlP5OEc3/qqN88MzFJdQnHEhtXNPA+W15p0ySWN6++lsOnRxXxPz+bmiv bNXw== 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=AG32tvZWUQivMY7wa6JiB6OXo61E9jsHNTjxNqoKtOk=; b=xLeg5GUBo7TJcIIp6L+3jFXA+WnluR2p1tGKMckK3FUJXUlbacZFSXdnxdERCgDNX/ cjT+SclfEK++EMLYJI4cZz3kx75uWkF8PlKb7UTjj9XuS2VSj76K+ihaKsZ9qI7NXF56 X7ZzZb3fiGbMOChEHcjad1wDkFUvjVuwVV/SuJcOcA7PHypK23ddbgXJUEQCYzyi0O1k nMQSPWt4VErnWT32ATshGkPqumEPHuomPfiQ2NFdZItmRQlhEBbvKRyU0PgCFy9++7Wl LcaW4QnxTC+r+BHfBbzzU8bYRE7YmIg6TlXm0a/BFD/T3F13+h2Th8pjzWVSEoFJ6RdV lzEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@in.tum.de header.s=20220209 header.b="t/0qy6Kt"; 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 v23-20020a17090abb9700b001efbd2c53c2si12532559pjr.180.2022.07.11.08.29.30; Mon, 11 Jul 2022 08:29:42 -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="t/0qy6Kt"; 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 S231310AbiGKPPH (ORCPT + 99 others); Mon, 11 Jul 2022 11:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbiGKPPE (ORCPT ); Mon, 11 Jul 2022 11:15:04 -0400 Received: from mailout1.rbg.tum.de (mailout1.rbg.tum.de [131.159.0.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79ADF23BF7; Mon, 11 Jul 2022 08:15:02 -0700 (PDT) Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mailout1.rbg.tum.de (Postfix) with ESMTPS id EB29193; Mon, 11 Jul 2022 17:14:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=in.tum.de; s=20220209; t=1657552496; bh=AG32tvZWUQivMY7wa6JiB6OXo61E9jsHNTjxNqoKtOk=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=t/0qy6KtydlTlh072BHXr0e5Y5cYKjoDu6nLgO9tv+4nVOyV1aLpjdErggDvTfEPt MCkliDAiuS65oTeh6T0Z0sPqsDdU4HeQLS5WK8hUQcoZNfZRH+QYbPAn0MiiqwToPh 2faLC7KYI/EPb+ZZl2ahWDTFvTIyoEvyHGf/wrMjRZKsJe0YrTesZOOjLRElZ+dJIX SVYjGPO97eNLbiO3d67AChO5hN+TsCAjSjKom1TiwGeba+7tw2/hyvkHZnnonItoGQ EhVzSL3yq/7FlHApuNiKkugFzkVfKWiOxNih0ewuXzVNU6B4pf8OgJDZQKFCL0Et5m iRYbYyprdJCng== Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id E3807D6; Mon, 11 Jul 2022 17:14:56 +0200 (CEST) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id B52B6D2; Mon, 11 Jul 2022 17:14:56 +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 B0AA9CE; Mon, 11 Jul 2022 17:14:56 +0200 (CEST) Received: by mail.in.tum.de (Postfix, from userid 112) id A3A1F4A0129; Mon, 11 Jul 2022 17:14:56 +0200 (CEST) Received: (Authenticated sender: heidekrp) by mail.in.tum.de (Postfix) with ESMTPSA id 229EA4A0115; Mon, 11 Jul 2022 17:14:56 +0200 (CEST) (Extended-Queue-bit xtech_gw@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: <20220708184749.GW1790663@paulmck-ThinkPad-P17-Gen-1> Date: Mon, 11 Jul 2022 17:14:55 +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> To: "Paul E. McKenney" X-Mailer: Apple Mail (2.3696.100.31) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 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 Looks great - my first commit in the Linux kernel! Thanks everyone! Paul > = ------------------------------------------------------------------------ >=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.