Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp3584062ybe; Sun, 8 Sep 2019 17:23:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGDdSlgQXECQHftb/PlJyeSkE2/6ccUZ/Wooe9+5Up1wBoNgOwo8/n+b0z5nXJs6YN+9iM X-Received: by 2002:a50:9fe5:: with SMTP id c92mr21798760edf.280.1567988598633; Sun, 08 Sep 2019 17:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567988598; cv=none; d=google.com; s=arc-20160816; b=kZkldAsD0POGWbMmqagV1QQzsvRO0YRmmyynoIBkXL5HApXNrxoO3PRYsiQKM2kjGQ JDD5uKs9SknobjfJYrRzFfhfoj5SyGgObxYMXmDcJCd6bU0QFF/hO6AdubXSEqE5h0tM ZNNoyU3KFjlnbtf4p++XPFRl8VbFrSXyrY1/Ysbpl3K0ySTWxszAm9LnDtXaNXSDfSx6 DlfJsdttsv2vZoQFOqfeVVT++ifW6BUuI477MnLIh3NKogQEhQWMNSbBCvTxJLkIfI+t 2oV7f2ioEZB7vxf6R8HcgMWkH5cJwevBFWaNB4ASK4oqBFVTd7ZryBh8O+PCrmtgA+O1 r2pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=42HbQUbYUhXg4byuPVE8BGhFBqgKNEXYjrh99ot7wwc=; b=Pkvg1od2FkF8ghMOWMl65xWwIuIT/mu/JJBBglBQ6FHkuwyJSZeFKOu5ciel+nHxwX 25HLwvyd7OrH3hQxIM04r/igBheHB4Iljc+mvECHy4J9s3IulhnDPbmJ08b9ZDRpYryC aFtPQ0yCQcYeNPNB/MudPNVwr486BQteSAwh/zsHS6o6wTavqGirye/BG1P7rHRGTaUC zbObnubnIMWo62NU6P0/4b7stMSr/jWl7+8ptHOEg6iNhYnZtFTSX5WwD0CZk0/bcem6 rgLrskYsMy7c+suC0bp6X4ZUEkYHewu1uDk53YFg/hULAhMzWi2jMZRIv9lIhF3xFeDQ 0J8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vuq4ksDt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14si7424138edd.417.2019.09.08.17.22.41; Sun, 08 Sep 2019 17:23:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vuq4ksDt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406767AbfIGP5J (ORCPT + 99 others); Sat, 7 Sep 2019 11:57:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:39636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406760AbfIGP5I (ORCPT ); Sat, 7 Sep 2019 11:57:08 -0400 Received: from paulmck-ThinkPad-P72 (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB245218AC; Sat, 7 Sep 2019 15:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567871827; bh=8+SRY4VXi7n58FbZc4gmkkL77BnU5IJr2rZXjzK87y4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=Vuq4ksDtuQ0kFld8hjRajz+vpugLjAjt7HHwfQbR49wZjJwYgJN6MuYYEPTFvQiVO NyqtnJZYPn8i18jTv44tjuvr7aR8kMWCnUBI4NVf7HWM+AlDOu5gcG1TcgK13qp8Wu JNZ3W6dT/RLaqTD/Ezi1H8zBbAMn4CoO9ACJ6eIo= Date: Sat, 7 Sep 2019 08:57:06 -0700 From: "Paul E. McKenney" To: Alan Stern Cc: LKMM Maintainers -- Akira Yokosawa , Andrea Parri , Boqun Feng , Daniel Lustig , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , "Paul E. McKenney" , Peter Zijlstra , Will Deacon , Kernel development list Subject: Re: [PATCH RFC] tools/memory-model: Fix data race detection for unordered store and load Message-ID: <20190907155706.GA27893@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 06, 2019 at 04:57:22PM -0400, Alan Stern wrote: > 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 Queued and pushed for review and testing, thank you very much! Thanx, Paul > --- > > tools/memory-model/linux-kernel.cat | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > Index: usb-devel/tools/memory-model/linux-kernel.cat > =================================================================== > --- usb-devel.orig/tools/memory-model/linux-kernel.cat > +++ usb-devel/tools/memory-model/linux-kernel.cat > @@ -197,7 +197,7 @@ empty (wr-incoh | rw-incoh | ww-incoh) a > (* 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 >