Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4769299pxb; Tue, 25 Jan 2022 19:05:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyi6zaRVPtZbZbeZqHmKpwkFfoqGlludNIMoNt5Jyz4oYqtGORVrIJ3O4SiQ3RmBslCkCpl X-Received: by 2002:a05:6402:84e:: with SMTP id b14mr6281028edz.112.1643166308188; Tue, 25 Jan 2022 19:05:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643166308; cv=none; d=google.com; s=arc-20160816; b=C+dbxM4SMhoZclxWZWXvbvgYkNZiz0XZ2aRrOc66KaRg1P1dhYyEMc6d+i11ucAvlp 4qPeWx4lfF2EbJFzfIC2K8+vrvvGbZrg0pZuENvOc5Es6XS8/GoKc/PyjWqTL6zNscW5 2AwOzP2QykRSesnKrvQeRsI1XxNtkcJE6IT8yOoyRb0k2jZ9jc06gTxs8f8PsqSP6auX 0C0eb3eDY8NM/q1ZnqARcDoMhH22ri7SPTw7JAha707PZ7VSS9WseCmLqlr0b1Ys5uoS ubLK9llP605cxAcOZLX8XXPrP24WqRc8M1JjZKG3QQVVhk4Fp5O26BZZOnQ/4GcoFUaF uRxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=MVRIkncvZSalRjm922B0FYLK/IIFBgZxRRoiUWmbYOE=; b=QNZrreM4jIaHARJtutNKHBKw2QuVhmM+LjpFhP6q5YzijGPjpy4Nd8AlVSxOGM1+18 TpVcxP3nkZ/l/fucxF7Z+t5J6d/fSdi8P7gCk+96eTuHexS//q+LkAIi8Y8CKi1V0wg8 kDn9akRPKO8idkNPrBd+UJ420fjzgereTaeZ+0PtROtjeL/L9ZUXLiKGqK8oqCpegmW5 SPB1G1f0/SfuCPfH4mOjHaBRaow3ryCkdGLVsBsHKN6FC+1xPZ+jUD0178WBGSnb2E/D wUyn3GjdcgA9MGz8Iz0+bp/bxQ84nLRW1XCkw8kDs5Ce5/TZOzOPpP9/hfYZUVBH2wBL E0jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=tum.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ej2si7631395edb.38.2022.01.25.19.04.43; Tue, 25 Jan 2022 19:05:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=tum.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237577AbiAYRgS (ORCPT + 99 others); Tue, 25 Jan 2022 12:36:18 -0500 Received: from mail-out1.in.tum.de ([131.159.0.8]:55806 "EHLO mail-out1.informatik.tu-muenchen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378673AbiAYRfS (ORCPT ); Tue, 25 Jan 2022 12:35:18 -0500 X-Greylist: delayed 339 seconds by postgrey-1.27 at vger.kernel.org; Tue, 25 Jan 2022 12:35:17 EST Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mail-out1.informatik.tu-muenchen.de (Postfix) with ESMTP id 52A5B2400D3; Tue, 25 Jan 2022 18:29:30 +0100 (CET) Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id 4EFA85A1; Tue, 25 Jan 2022 18:29:30 +0100 (CET) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id 2CF6F591; Tue, 25 Jan 2022 18:29:30 +0100 (CET) Received: from mail.in.tum.de (mailproxy.in.tum.de [IPv6:2a09:80c0::78]) by mailrelay1.rbg.tum.de (Postfix) with ESMTPS id 2905A585; Tue, 25 Jan 2022 18:29:30 +0100 (CET) Received: by mail.in.tum.de (Postfix, from userid 112) id 2598D4A03D1; Tue, 25 Jan 2022 18:29:30 +0100 (CET) Received: (Authenticated sender: heidekrp) by mail.in.tum.de (Postfix) with ESMTPSA id BFD324A00C7; Tue, 25 Jan 2022 18:29:29 +0100 (CET) (Extended-Queue-bit xtech_ed@fff.in.tum.de) From: =?UTF-8?q?Paul=20Heidekr=C3=BCger?= To: Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , =?UTF-8?q?Paul=20Heidekr=C3=BCger?= , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Cc: Marco Elver , Charalampos Mainas , Pramod Bhatotia Subject: [PATCH] tools/memory-model: Clarify syntactic and semantic dependencies Date: Tue, 25 Jan 2022 17:28:19 +0000 Message-Id: <20220125172819.3087760-1-paul.heidekrueger@in.tum.de> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dependencies which are purely syntactic, i.e. not semantic, might imply ordering at first glance. However, since they do not affect defined behavior, compilers are within their rights to remove such dependencies when optimizing code. Since syntactic dependencies are not related to any kind of dependency in particular, explicitly distinguish syntactic and semantic dependencies as part of the 'A WARNING' section in explanation.txt, which gives examples of how compilers might affect the LKMM's dependency orderings in general. Link: https://lore.kernel.org/all/20211102190138.GA1497378@rowland.harvard.edu/ Signed-off-by: Paul Heidekrüger Cc: Marco Elver Cc: Charalampos Mainas Cc: Pramod Bhatotia --- .../Documentation/explanation.txt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/memory-model/Documentation/explanation.txt b/tools/memory-model/Documentation/explanation.txt index 5d72f3112e56..6d679e5ebdf9 100644 --- a/tools/memory-model/Documentation/explanation.txt +++ b/tools/memory-model/Documentation/explanation.txt @@ -411,6 +411,31 @@ Given this version of the code, the LKMM would predict that the load from x could be executed after the store to y. Thus, the memory model's original prediction could be invalidated by the compiler. +Caution is also advised when dependencies are purely syntactic, i.e. +not semantic. A dependency between two marked accesses is purely +syntactic iff the defined behavior of the second access is unaffected +by its dependency. + +Compilers are aware of syntactic dependencies and are within their +rights to remove them as part of optimizations, thereby breaking any +guarantees of ordering. + +Notable cases are dependencies eliminated through constant propagation +or those where only one value leads to defined behavior as in the +following example: + + int a[1]; + int i; + + r1 = READ_ONCE(i); + r2 = READ_ONCE(a[r1]); + +The formal LKMM is unaware of syntactic dependencies and therefore +predicts ordering. However, since any other value than 0 for r1 would +result in an out-of-bounds access, which is undefined behavior, r2 is +not affected by its dependency to r1, making the above a purely +syntactic dependency. + Another issue arises from the fact that in C, arguments to many operators and function calls can be evaluated in any order. For example: -- 2.33.1