Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2088044ybi; Thu, 20 Jun 2019 08:56:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2RYPpG6iWDlpA/uInblMLYpVymBdRJhD1W/oaJtPme1zGFmYJ1ieSliJNJxMTr+8Xjkm7 X-Received: by 2002:aa7:8dd2:: with SMTP id j18mr61300311pfr.88.1561046217070; Thu, 20 Jun 2019 08:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561046217; cv=none; d=google.com; s=arc-20160816; b=SqQRJQ+/sKWAwZbOYnxDJNpimJnXGwaYHkZngEihpCCeP9wcco5HLCIYcL4lJkxaVP yIrSddI/zH6xBvBE7e1YwUJ8cyhXjEaGpbc5o4ICuA8rfh+XqfqCmJ+QnT73ODR6mfty XZEz32HopauFcux0YjmkDl3CP0k6YjtdKj8JWEXjDGjxmcslG393c7QCp+7sMKbI69xV Ql0U+/e/AXXnZ3uD3ydY/vM1ehS6nbrfnfrgKDvPK62zr4hRsMswS4Be3In94m5mZj1p 1jPK+/6vkYNiTDBdDqJEDIoY1iuhb6oyBuXzpLsffk26b5LxaMbJYDurpL0i4uEPeC4y jUyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:subject:cc:to :from:date; bh=vjV8bo3fkSdSU2VsKc8Zn3uKCT1GRqqvtoU0cZhrfjA=; b=fwVCm4x+X6jrufJk/cBGp8mAyTwZ6vbeulkVQHef2MZ//iBXb2aGF0iWyKnyS4+JZv Dwy/Bt+szHfMZqta+5IpjvaNh83pBOg+L9uk+ChEbCG7q+6Q61soETB6wWskC/ug51ft cmXaEr7HAwGZZEqOu6A27Z8T8vgj8xe6np89Cp0EpZuBf+0+SLkBK/Cx9Ud2Ipg/yKJy 4lbHACJCi+BMwquNXII9v/2YbPFyfOgEcVVxUmBKrW0IEimEzqEmD9oRiOJTkPPYOw8F 2Eo8gJpTButh/Uq689hdNP16mQgOPALb2bj6tHg9hHhkksZavF7kw1pWDwpIaz2spb4g hysg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11si80398plm.390.2019.06.20.08.56.40; Thu, 20 Jun 2019 08:56:56 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731940AbfFTPz7 (ORCPT + 99 others); Thu, 20 Jun 2019 11:55:59 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:44988 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726551AbfFTPz7 (ORCPT ); Thu, 20 Jun 2019 11:55:59 -0400 Received: (qmail 4721 invoked by uid 2102); 20 Jun 2019 11:55:58 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 20 Jun 2019 11:55:58 -0400 Date: Thu, 20 Jun 2019 11:55:58 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: 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 cc: Herbert Xu , Kernel development list Subject: [PATCH 3/3] tools: memory-model: Improve data-race detection Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Herbert Xu recently reported a problem concerning RCU and compiler barriers. In the course of discussing the problem, he put forth a litmus test which illustrated a serious defect in the Linux Kernel Memory Model's data-race-detection code. The defect was that the LKMM assumed visibility and executes-before ordering of plain accesses had to be mediated by marked accesses. In Herbert's litmus test this wasn't so, and the LKMM claimed the litmus test was allowed and contained a data race although neither is true. In fact, plain accesses can be ordered by fences even in the absence of marked accesses. In most cases this doesn't matter, because most fences only order accesses within a single thread. But the rcu-fence relation is different; it can order (and induce visibility between) accesses in different threads -- events which otherwise might be concurrent. This makes it relevant to data-race detection. This patch makes two changes to the memory model to incorporate the new insight: If a store is separated by a fence from another access, the store is necessarily visible to the other access (as reflected in the ww-vis and wr-vis relations). Similarly, if a load is separated by a fence from another access then the load necessarily executes before the other access (as reflected in the rw-xbstar relation). If a store is separated by a strong fence from a marked access then it is necessarily visible to any access that executes after the marked access (as reflected in the ww-vis and wr-vis relations). With these changes, the LKMM gives the desired result for Herbert's litmus test and other related ones. Signed-off-by: Alan Stern Reported-by: Herbert Xu --- tools/memory-model/linux-kernel.cat | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 @@ -181,9 +181,11 @@ let r-post-bounded = (nonrw-fence | ([~N [Marked] (* Visibility and executes-before for plain accesses *) -let ww-vis = w-post-bounded ; vis ; w-pre-bounded -let wr-vis = w-post-bounded ; vis ; r-pre-bounded -let rw-xbstar = r-post-bounded ; xbstar ; w-pre-bounded +let ww-vis = fence | (strong-fence ; xbstar ; w-pre-bounded) | + (w-post-bounded ; vis ; w-pre-bounded) +let wr-vis = fence | (strong-fence ; xbstar ; r-pre-bounded) | + (w-post-bounded ; vis ; r-pre-bounded) +let rw-xbstar = fence | (r-post-bounded ; xbstar ; w-pre-bounded) (* Potential races *) let pre-race = ext & ((Plain * M) | ((M \ IW) * Plain))