Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1705988rwb; Thu, 8 Dec 2022 14:17:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf4vwl8yLsYmJg/lEk6+3JFSQ1xRg2aZxv2FN3IKdv7sGvYwO+jsrH+lXhpTSBWsFlb65sTO X-Received: by 2002:a05:6402:28cb:b0:463:b0de:c210 with SMTP id ef11-20020a05640228cb00b00463b0dec210mr6983414edb.10.1670537824705; Thu, 08 Dec 2022 14:17:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670537824; cv=none; d=google.com; s=arc-20160816; b=HeQkMOGOtO/pRj+A75AlFMbOBU2XZW/EUEM6AzAgN2GR130quNxPGv8gGeoJppvbyA CxPB2ktNe/MEVRO4I6YLQcJRkjuqUhT8K+RghxZwPybrS4YTXL24QYP1nqp0QBFLj8Ph 6QbBTd426fGkSrY6ClryzxEpjAaQHP3p1Bn3qE4Lxk37hOXN/majhnujveZcbQnfitxx cFkZsA0bvmDA0RNhPFCzhLJFug74HmftiARt/nsQHRY1fjRUEQkTH8dCL2rJND4pFq9a cltoimU9Ml3EKasGiPgztFH4I986qrwHO26vnJX59vXVWHnPMKWaxg86pXe0J1goA743 Bwow== 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=5ulK6GFeti1Hk34Didy6AJYVY4Q/A8LGojyIGpJwbzk=; b=ojv1BZRsUVREZ7teB/JXisa71d9aZaYii7ye3EaTa2tQCqwlqbX2wmO65PZBX/nvW3 GBtZqQhEuIOaT91AeZ6pAmpFBBVF5GptR7R4Eo8CofnvnIU1+Y/25klaUAudK2rMeNcz BF3lyBeDwLoTbWu6owbfwTMrQaaP5rKWfzztKvyGleaB8KKxZAhTEIU6uzOM3krbTP5v 0H5gyKlrFYAtwcBbw5t36I+xDEQdC/QbMMxV/1WOHX3thDGSfK8Idkp7WxL5LwvRzLV9 HD9t1nqHg3hXFoq3Nyt53q5/cCFZNyIRSLmKRY7w0OWARFhIbxm7cjbuNNaijSs3vWyR eAQg== 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 eg55-20020a05640228b700b00462e7873c10si6490069edb.337.2022.12.08.14.16.46; Thu, 08 Dec 2022 14:17:04 -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 S229791AbiLHVho (ORCPT + 73 others); Thu, 8 Dec 2022 16:37:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbiLHVhl (ORCPT ); Thu, 8 Dec 2022 16:37:41 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 1890E10B6 for ; Thu, 8 Dec 2022 13:37:36 -0800 (PST) Received: (qmail 744325 invoked by uid 1000); 8 Dec 2022 16:37:35 -0500 Date: Thu, 8 Dec 2022 16:37:35 -0500 From: "stern@rowland.harvard.edu" To: Boqun Feng Cc: Jonas Oberhauser , "paulmck@kernel.org" , "parri.andrea@gmail.com" , "will@kernel.org" , "peterz@infradead.org" , "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 v2] tools: memory-model: Make plain accesses carry dependencies Message-ID: References: <20221203204405.GW4001@paulmck-ThinkPad-P17-Gen-1> <20221203231122.GZ4001@paulmck-ThinkPad-P17-Gen-1> <43c7ea9ebdd14497b85633950b014240@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 Tue, Dec 06, 2022 at 12:52:47PM -0800, Boqun Feng wrote: > On Tue, Dec 06, 2022 at 12:46:58PM -0800, Boqun Feng wrote: > > Thank you, Alan! One question though, can a "smart" compiler optimize > > out the case below, with the same logic? > > > > void P0(int *x, int *y, int *a) > > { > > int r1, r2; > > > > r1 = READ_ONCE(*x); // A > > > > *a = r1 & 0xffff; // B > > > > r2 = *a & 0xffff0000; // C > > > > WRITE_ONCE(*y, r2); // D > > > > } > > > > I think we have A ->data B ->rfi C ->data D, however a "smart" compiler > > can figure out that r2 is actually zero, right? And the code get > > optimized to: > > > > r1 = READ_ONCE(*x); > > r2 = 0; > > WRITE_ONCE(*y, r2); > > *a = r1 & 0xffff; > > > > and break the dependency. Yes, that could happen. > > I know that our memory model is actually unware of the differences of > > syntatics dependencies vs semantics syntatics, so one may argue that in > > the (data; rfi) example above the compiler optimization is outside the > > scope of LKMM, but won't the same reasoning apply to the (addr; rfi) > > example from you? The WRITE_ONCE() _syntatically_ depends on load of > > a[r1], therefore even a "smart" compiler can figure out the value, LKMM > > I guess it should be that r2 (i.e. the load of a[r1]) _syntatically_ > depends on the value of r1. Yes. But more to the point, the LKMM already has this problem for ordinary dependencies. If you do: r1 = READ_ONCE(*x); r2 = r1 & 0x0000ffff; r3 = r2 & 0xffff0000; WRITE_ONCE(*y, r3); then the LKMM will think there is a dependency (because there is a _syntactic_ dependency), but the compiler is likely to realize that there isn't a _semantic_ dependency and will destroy the ordering. We warn people about this possibility, and the same warning applies to dependencies carried by plain accesses. So I don't think this is a reason to object to Jonas's carries-dep relation. Alan