Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3653449rwb; Sat, 3 Dec 2022 08:20:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf5P2npFjQ5BXaFFwHdAXI4OT2AuWrWjp3V/iYaW7/uF9dt1fkhEqkzHbcH4EHVq/VOwT+2I X-Received: by 2002:a17:902:e8d5:b0:186:a636:b135 with SMTP id v21-20020a170902e8d500b00186a636b135mr69617656plg.93.1670084456197; Sat, 03 Dec 2022 08:20:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670084456; cv=none; d=google.com; s=arc-20160816; b=1D845cnmIW6a3IeGSOf26cOLMTC4W14C5PTQCYhesqf/K/QxH00/L4OcOp/wRdrhOS wUfcY3/qHJTAk/Tzqylg2OqH6dRPsyic3zzTt/SvEKvhk1b5yb5vwiC3Rlo5CD+zo9nD 3l0U0GbsSoYYaX0lN1AUdSdcALP5ZLnY8yjyquzt3bez4tLKOeIPnWuZ2GYcI0KBOwUH 4R3p+nmijYxNKqmWCgeEGiLwUH30mV6AU5ZC/uIHgRltucwB5DeNouSlHdB0u9nXbHQ5 NdyC/pJMXXbts8FBENekK9NpZvry4pV1QS6lTiS9/uSCdeVVXCjxUts7xD1vXll/N2Td //+A== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=c+XcvoF718SZWXBuUSLv7djrEewocFJM62ExcCadCpA=; b=yjkT+nO0gHTGSEiGNRCTeTeu/vzhYVrnBPAI4/V19Q4YCOqY4GMYjwvEzbosPZBT4/ Ff2HxPGSTD06o8rn7Re9zGiCdSluSUlYNwuOTeLUqDef4T0SwJS6YJZ+IU0jyHpLj2Q2 OT1y6EF82JwlkWAxReOtSkAJkCBEVkh6vXgZR6m3fAp6OQ5M8DJeT839zw1o8UE8eRDn YqOKmu7n+yulbFZhOuRFzC+KajFKywqHqEZ4VyxSF0l9ZsU0At8Ql+1CmffJS0PajKO9 3WVm63HRBJp6/HsclatoQdDllwlX8RJJ0kMscHcDYPFgjXr2RTwK8vdlCz8EADt59H3Z /faA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt19-20020a17090af2d300b002182cd7d958si12143617pjb.46.2022.12.03.08.20.45; Sat, 03 Dec 2022 08:20:56 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbiLCPUc (ORCPT + 82 others); Sat, 3 Dec 2022 10:20:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbiLCPUb (ORCPT ); Sat, 3 Dec 2022 10:20:31 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id EAB2520348 for ; Sat, 3 Dec 2022 07:20:29 -0800 (PST) Received: (qmail 562353 invoked by uid 1000); 3 Dec 2022 10:20:29 -0500 Date: Sat, 3 Dec 2022 10:20:28 -0500 From: Alan Stern To: Jonas Oberhauser Cc: Jonas Oberhauser , "paulmck@kernel.org" , "parri.andrea@gmail.com" , "will@kernel.org" , "peterz@infradead.org" , "boqun.feng@gmail.com" , "npiggin@gmail.com" , "dhowells@redhat.com" , "j.alglave@ucl.ac.uk" , "luc.maranget@inria.fr" , "akiyks@gmail.com" , "dlustig@nvidia.com" , "joel@joelfernandes.org" , "urezki@gmail.com" , "quic_neeraju@quicinc.com" , "frederic@kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] tools: memory-model: Make plain accesses carry dependencies Message-ID: References: <20221201121808.20785-1-jonas.oberhauser@huaweicloud.com> <6abbb72eef6149eb842a3351ecea7af5@huawei.com> <4905c14d2bc547a391d626416a20a2e9@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS 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 Sat, Dec 03, 2022 at 11:47:06AM +0000, Jonas Oberhauser wrote: > > > -----Original Message----- > From: Alan Stern [mailto:stern@rowland.harvard.edu] > Sent: Friday, December 2, 2022 9:22 PM > > > > void *y[2]; > > > void *x[2] = { (void*)&y[1], (void*)&y[0] }; > > > > > > P0() { > > > void **t = (void**)(x[0]); > > > Now t holds a pointer to y[1]. > > Unfortunately, this kind of inductive reasoning (arguing about what happens based on what happened "before") is not possible with memory models that allow OOTA; as you put it, one must allow for loads reading from stores that haven't happened yet. > One such store (I promise!(*)) is a store to x[0] which writes &x[1]. Let's consider the alternative universe where we read from this future store, so now t holds a pointer to x[1]. > > > > *t = (void*)(t-1); > > > And now y[1] holds a pointer to y[0]. > > In our alternative universe, x[1] now holds a pointer to x[0]. > > > > > } > > > P1() { > > > void **u = (void**)(x[1]); > > > Now u holds a pointer to y[0]. > > In our alternative universe, u holds the pointer to x[0] stored by P0(). > > > > *u = (void*)(u+1); > > > And now y[0] holds a pointer to y[1]. > > In our alternative universe, now x[0] holds a pointer to x[1]. Behold, the store I promised would happen! > > > > } > > > The contents of x[] never get changed, so there's no question about the values of t and u. > > They might get changed, by the stores *t=... and *u=... Okay, now I understand. Yes, this counts as an example of values appearing out of thin air, even though the values are constrained. The same sort of thing can happen in a less exotic form, such as: P0 P1 ------ ----------- x = y; y = x & ~1; Then in an OOTA execution, x and y can end up holding any _even_ value. Yes, constraining a value to be even is less drastic than constraining it to be &x[0] as in your example, but it's still a constraint. One can easily extend this example in various directions. Alan