Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2362937pxk; Sat, 3 Oct 2020 18:41:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx005XP7GeCKPbgYVdM1oh9qdE7bgE6tfKIERg5S3V9im37B+dHpPiC2sFsHkLw94Xfrb5m X-Received: by 2002:aa7:ca17:: with SMTP id y23mr11086682eds.245.1601775710904; Sat, 03 Oct 2020 18:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601775710; cv=none; d=google.com; s=arc-20160816; b=e8vrztPanZ8SXiE9D08V6bCQskpfGn5566mi/BGEH6QlinLlypOdIKXL45iknKz/Vc FvP142erygWW3crzQs2X6Yjy1BAfq9P1fsTsyHCcL+AiDEvFE/Vsn86iWIe+4/rJzjH0 qiNv0+WHS9X0irNPkqDfEx/VMomE9H8DoeJrLX5ZSNY5uhlVTRpK63AvhkKcl5rtTrQd ZKwsn4+vJauFvNN1ur+LDsNGTzl4GEgyly76pItnLUU0KZFWxOMyDVMrFlhoufYdOYPy OSXNCsOl5QhtfBuNqrlqHMZ476KXtQBPxkrw/yZkpl1cFJ2shzWOXk6nFGxy5GfwrRdT fuxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=LFkyFACkxWVJcsznu2GBUl0qNZ9jBWtw+qKAgzAVN6k=; b=G7cCrkDMoumVbnRL2EZvBulZHQi651tvYX4TbEdcD+qoafHRO1eXIrliyMDG6v/+Aq 7Y1SVA9ihbTaCCJhmZ4SIrqFUX+87vQ55v/VZ7B1lGh3j5kbY0JyPvuX6tbunn/HVfjs clg//NCBlzmIhnDZLG3FhPCFSkzr4VXsmT+s387D2kYP+42tc3G2W2Ue6VQ28qv7mjMm alwPujyMulSaoi5jPw31P2dlhnBRWxgkA2FpnctpYX9ubYdfoc/evybwUaLnrjygIVgm EU9821uhhKGV3Yi6D5v7diZHTBrBH+j3c+knzcVR7JTRqOZuT+auiIYw4NoLcyzzWC+Y 1K5Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p15si4122071ejm.293.2020.10.03.18.41.27; Sat, 03 Oct 2020 18:41:50 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726195AbgJDBkY (ORCPT + 99 others); Sat, 3 Oct 2020 21:40:24 -0400 Received: from netrider.rowland.org ([192.131.102.5]:36373 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726122AbgJDBkX (ORCPT ); Sat, 3 Oct 2020 21:40:23 -0400 Received: (qmail 332975 invoked by uid 1000); 3 Oct 2020 21:40:22 -0400 Date: Sat, 3 Oct 2020 21:40:22 -0400 From: Alan Stern To: "Paul E. McKenney" Cc: Akira Yokosawa , 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, dlustig@nvidia.com, joel@joelfernandes.org, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH] tools: memory-model: Document that the LKMM can easily miss control dependencies Message-ID: <20201004014022.GA332600@rowland.harvard.edu> References: <20201001045116.GA5014@paulmck-ThinkPad-P72> <20201001161529.GA251468@rowland.harvard.edu> <20201001213048.GF29330@paulmck-ThinkPad-P72> <20201003132212.GB318272@rowland.harvard.edu> <045c643f-6a70-dfdf-2b1e-f369a667f709@gmail.com> <20201003171338.GA323226@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201003171338.GA323226@rowland.harvard.edu> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a small section to the litmus-tests.txt documentation file for the Linux Kernel Memory Model explaining that the memory model often fails to recognize certain control dependencies. Suggested-by: Akira Yokosawa Signed-off-by: Alan Stern --- tools/memory-model/Documentation/litmus-tests.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) Index: usb-devel/tools/memory-model/Documentation/litmus-tests.txt =================================================================== --- usb-devel.orig/tools/memory-model/Documentation/litmus-tests.txt +++ usb-devel/tools/memory-model/Documentation/litmus-tests.txt @@ -946,6 +946,23 @@ Limitations of the Linux-kernel memory m carrying a dependency, then the compiler can break that dependency by substituting a constant of that value. + 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: + + r1 = READ_ONCE(x); + if (r1 == 0) + smp_mb(); + WRITE_ONCE(y, 1); + + 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 != 0. (Yes, that + doesn't make sense if you think about it, but the memory model's + intelligence is limited.) + 2. Multiple access sizes for a single variable are not supported, and neither are misaligned or partially overlapping accesses.