Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2707162yba; Mon, 22 Apr 2019 11:28:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzth9kxFgSKitQrOqpeLeLPZpmZ8n9/Nbz3YlLBTj/IXP/Y45dpi+WkblRpuaaa/6ryxGiH X-Received: by 2002:a65:6088:: with SMTP id t8mr20423299pgu.2.1555957716145; Mon, 22 Apr 2019 11:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555957716; cv=none; d=google.com; s=arc-20160816; b=UgUCWY0eoyybCS8n+U0y2amvA8QEINK360duUJibpFstiJ+C2UGHZCJ/Fz4hjEQT0A uIpDHBKQPQBLq+erDUFgB9SrvV6YsfV3FzwPcxwix+aHYeinIQ0TQl4UFt2e+4dZRkWz OiNlKQH/RRq5CCsvR9YgMH+cNpUuL73W4y5UQUDVrHmkK9EoGNIO4tupgdKmqvH6uIju 8ux9MK8mNSyeUpaGJRGRn3cEFUCmzwMOAfidSJ1xUGgcBWMb30AF99XwZnBhgL2qMQM5 GXJ33sLuS9G2fPuFyF9tpgMpOZLQQyxF1H2U1h+PgPjUZ1nkYZevzLqUTxUG2GgmNObg YKfw== 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=gGv5rq25KX9Pfg3IF5jSRXgCQjJ75/2oeaM8/ADLYRE=; b=D/tb7cXXu4QqprFgsCJY1OZIKRZ3d80ow1bPQk9vnhrmwbUQQ+uJ97xbG8k3H67RSE y0pXdlQsb+7owxi+Ub28ZyCFlX/t1ldGIVtMB5nPO21VwrQoldE1jRSWE6/pCk+wuOSH dZP+Xp9ExC6YsMOKGyOJ2URHSj18ReDBVs10IPAeAB+0GIZOBoADmFtPB5CVg+xSy1Yi a0zU+RfX//bDYjqTwBebVye564lzJ8CNsSZuZBRhWunykF53//wUTih/uJs1QoDSbhin 5YsqFq2P1jiAUdSdiRFTG8ob9giA8Rqoau480s1I5MqNTHQtv0EfFniNlhUISlj4Ptdx bNrQ== 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 v5si12492381pgr.121.2019.04.22.11.28.21; Mon, 22 Apr 2019 11:28:36 -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 S1728049AbfDVQSK (ORCPT + 99 others); Mon, 22 Apr 2019 12:18:10 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:37822 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726098AbfDVQSK (ORCPT ); Mon, 22 Apr 2019 12:18:10 -0400 Received: (qmail 5437 invoked by uid 2102); 22 Apr 2019 12:18:09 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 22 Apr 2019 12:18:09 -0400 Date: Mon, 22 Apr 2019 12:18:09 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: "Paul E. McKenney" cc: LKMM Maintainers -- Akira Yokosawa , Andrea Parri , Boqun Feng , Daniel Lustig , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , Peter Zijlstra , Will Deacon , Kernel development list , Joel Fernandes Subject: [PATCH 3/3] tools: memory-model: Add 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 This patch adds data-race detection to the Linux-Kernel Memory Model. As part of this effort, support is added for: compiler barriers (the barrier() function), and a new Preserved Program Order term: (addr ; [Plain] ; wmb) Data races are marked with a special Flag warning in herd. It is not guaranteed that the model will provide accurate predictions when a data race is present. The patch does not include documentation for the data-race detection facility. The basic design has been explained in various emails, and a separate documentation patch will be submitted later. This work is based on an earlier formulation of data races for the LKMM by Andrea Parri. Signed-off-by: Alan Stern --- tools/memory-model/linux-kernel.bell | 1 tools/memory-model/linux-kernel.cat | 50 ++++++++++++++++++++++++++++++++++- tools/memory-model/linux-kernel.def | 1 3 files changed, 51 insertions(+), 1 deletion(-) Index: usb-devel/tools/memory-model/linux-kernel.bell =================================================================== --- usb-devel.orig/tools/memory-model/linux-kernel.bell +++ usb-devel/tools/memory-model/linux-kernel.bell @@ -24,6 +24,7 @@ instructions RMW[{'once,'acquire,'releas enum Barriers = 'wmb (*smp_wmb*) || 'rmb (*smp_rmb*) || 'mb (*smp_mb*) || + 'barrier (*barrier*) || 'rcu-lock (*rcu_read_lock*) || 'rcu-unlock (*rcu_read_unlock*) || 'sync-rcu (*synchronize_rcu*) || 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 @@ -46,6 +46,9 @@ let strong-fence = mb | gp let nonrw-fence = strong-fence | po-rel | acq-po let fence = nonrw-fence | wmb | rmb +let barrier = fencerel(Barrier | Rmb | Wmb | Mb | Sync-rcu | Sync-srcu | + Before-atomic | After-atomic | Acquire | Release) | + (po ; [Release]) | ([Acquire] ; po) (**********************************) (* Fundamental coherence ordering *) @@ -66,7 +69,7 @@ empty rmw & (fre ; coe) as atomic let dep = addr | data let rwdep = (dep | ctrl) ; [W] let overwrite = co | fr -let to-w = rwdep | (overwrite & int) +let to-w = rwdep | (overwrite & int) | (addr ; [Plain] ; wmb) let to-r = addr | (dep ; [Marked] ; rfi) let ppo = to-r | to-w | fence | (po-unlock-rf-lock-po & int) @@ -149,3 +152,48 @@ irreflexive rb as rcu * let xb = hb | pb | rb * acyclic xb as executes-before *) + +(*********************************) +(* Plain accesses and data races *) +(*********************************) + +(* Warn about plain writes and marked accesses in the same region *) +let mixed-accesses = ([Plain & W] ; (po-loc \ barrier) ; [Marked]) | + ([Marked] ; (po-loc \ barrier) ; [Plain & W]) +flag ~empty mixed-accesses as mixed-accesses + +(* Executes-before and visibility *) +let xbstar = (hb | pb | rb)* +let full-fence = strong-fence | (po ; rcu-fence ; po?) +let vis = cumul-fence* ; rfe? ; [Marked] ; + ((full-fence ; [Marked] ; xbstar) | (xbstar & int)) + +(* Boundaries for lifetimes of plain accesses *) +let w-pre-bounded = [Marked] ; (addr | fence)? +let r-pre-bounded = [Marked] ; (addr | nonrw-fence | + ([R4rmb] ; fencerel(Rmb) ; [~Noreturn]))? +let w-post-bounded = fence? ; [Marked] +let r-post-bounded = (nonrw-fence | ([~Noreturn] ; fencerel(Rmb) ; [R4rmb]))? ; + [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 + +(* Potential races *) +let pre-race = ext & ((Plain * M) | ((M \ IW) * Plain)) + +(* Coherence requirements for plain accesses *) +let wr-incoh = pre-race & rf & rw-xbstar^-1 +let rw-incoh = pre-race & fr & wr-vis^-1 +let ww-incoh = pre-race & co & ww-vis^-1 +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 rw-race = (pre-race & fr) \ rw-xbstar + +flag ~empty (ww-race | wr-race | rw-race) as data-race Index: usb-devel/tools/memory-model/linux-kernel.def =================================================================== --- usb-devel.orig/tools/memory-model/linux-kernel.def +++ usb-devel/tools/memory-model/linux-kernel.def @@ -24,6 +24,7 @@ smp_mb__before_atomic() { __fence{before smp_mb__after_atomic() { __fence{after-atomic}; } smp_mb__after_spinlock() { __fence{after-spinlock}; } smp_mb__after_unlock_lock() { __fence{after-unlock-lock}; } +barrier() { __fence{barrier}; } // Exchange xchg(X,V) __xchg{mb}(X,V)