From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D08DC43603 for ; Tue, 10 Dec 2019 21:51:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5227D205C9 for ; Tue, 10 Dec 2019 21:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576014667; bh=Kj9F+E8kssmWLrGlaaPjGhscFWLYKxX1BArT3M5lpTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mNi5676rJmUWKfDL4sJ7C9XFhG/zqlLdBs0w7SOHW8vykIf/gsbiLgtQQv2UTEUBz BK69a+3cMPis/I5lv1Dc6IOZO1DIQJ+untsqWc8/SZrgwrmbAA5ck82X9k3W6sOUTx VfUtvHkuXuPEPHj2wO0CzkrhtAZoYt0Lhhjs9TgE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729770AbfLJVvG (ORCPT ); Tue, 10 Dec 2019 16:51:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:55182 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727665AbfLJVII (ORCPT ); Tue, 10 Dec 2019 16:08:08 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0C01D2469E; Tue, 10 Dec 2019 21:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576012087; bh=Kj9F+E8kssmWLrGlaaPjGhscFWLYKxX1BArT3M5lpTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sEOTgXibgN3Dp5Nz+PJwq3YRioGG2gReyaAJCovVKKqVQV1V0sSD7NgSyksGwI+Tm /fMGuTJCrje0+oWjxPGqh+1ziZvx6aqQ6AoRAl1BFBDuYTc85ssCl4dZOzFsd67auI WF6frQMlAbTYQDD/EzK1hlVOMp82VMvjN7lACtXM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alan Stern , Andrea Parri , "Paul E . McKenney" , Sasha Levin , linux-arch@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 065/350] tools/memory-model: Fix data race detection for unordered store and load Date: Tue, 10 Dec 2019 16:02:50 -0500 Message-Id: <20191210210735.9077-26-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191210210735.9077-1-sashal@kernel.org> References: <20191210210735.9077-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Stern [ Upstream commit daebf24a8e8c6064cba3a330db9fe9376a137d2c ] Currently the Linux Kernel Memory Model gives an incorrect response for the following litmus test: C plain-WWC {} P0(int *x) { WRITE_ONCE(*x, 2); } P1(int *x, int *y) { int r1; int r2; int r3; r1 = READ_ONCE(*x); if (r1 == 2) { smp_rmb(); r2 = *x; } smp_rmb(); r3 = READ_ONCE(*x); WRITE_ONCE(*y, r3 - 1); } P2(int *x, int *y) { int r4; r4 = READ_ONCE(*y); if (r4 > 0) WRITE_ONCE(*x, 1); } exists (x=2 /\ 1:r2=2 /\ 2:r4=1) The memory model says that the plain read of *x in P1 races with the WRITE_ONCE(*x) in P2. The problem is that we have a write W and a read R related by neither fre or rfe, but rather W ->coe W' ->rfe R, where W' is an intermediate write (the WRITE_ONCE() in P0). In this situation there is no particular ordering between W and R, so either a wr-vis link from W to R or an rw-xbstar link from R to W would prove that the accesses aren't concurrent. But the LKMM only looks for a wr-vis link, which is equivalent to assuming that W must execute before R. This is not necessarily true on non-multicopy-atomic systems, as the WWC pattern demonstrates. This patch changes the LKMM to accept either a wr-vis or a reverse rw-xbstar link as a proof of non-concurrency. Signed-off-by: Alan Stern Acked-by: Andrea Parri Signed-off-by: Paul E. McKenney Signed-off-by: Sasha Levin --- tools/memory-model/linux-kernel.cat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/memory-model/linux-kernel.cat b/tools/memory-model/linux-kernel.cat index ea2ff4b940749..2a9b4fe4a84eb 100644 --- a/tools/memory-model/linux-kernel.cat +++ b/tools/memory-model/linux-kernel.cat @@ -197,7 +197,7 @@ empty (wr-incoh | rw-incoh | ww-incoh) as plain-coherence (* Actual races *) let ww-nonrace = ww-vis & ((Marked * W) | rw-xbstar) & ((W * Marked) | wr-vis) let ww-race = (pre-race & co) \ ww-nonrace -let wr-race = (pre-race & (co? ; rf)) \ wr-vis +let wr-race = (pre-race & (co? ; rf)) \ wr-vis \ rw-xbstar^-1 let rw-race = (pre-race & fr) \ rw-xbstar flag ~empty (ww-race | wr-race | rw-race) as data-race -- 2.20.1