Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp793108ybb; Fri, 20 Mar 2020 08:10:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtoxpkzJUq256q+wsv7c+2Y9+s1HlfBqYa1b1sosQBn0ECFoMlluc82wJ9V8C5IXhy4K/AZ X-Received: by 2002:aca:450a:: with SMTP id s10mr6684744oia.25.1584717033589; Fri, 20 Mar 2020 08:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584717033; cv=none; d=google.com; s=arc-20160816; b=R777JK0CDHs1bYS2sw/Rw5qykH8dBu86c0WkARa2bY/wvRe3qAjS1u+r9v8vEv/kMr /wj7Rc3sZeOaq1ttNy/N3J0jtLH2w7sOjfYxgeUgLKiFOMlx4u7oes9HzBuy6sh6LXEb 4KkRQcfLsCjlAi3OpMCZELYx0naFLidjGtZFqJ+quchh48Ey/I6bzMAZm6hF6T3QU7GS Q3wBhMShV5YElpozhYcamlRGvaByNiePjEEm8Tv8frsSxVodOVbHkZHzQ1Mn0LUEr/NL LRLCzdes61FR8EO4H4i9rX9V+uZdPevp38twTtInw8w5HNIjGz3SuhaxHquBB4CrrRo2 /Ssw== 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:in-reply-to :subject:cc:to:from:date; bh=ZzvLzE55dZhlO6udvOY6XDx2bS6eigeYs3zKjkzsr9E=; b=qttAbb+LytSg51Mk3rKm3GaDWoAgTaDwR1xacKxenFWW5X+4uhHFsY67dUWbYrEjiP I9kSRp1Mdq/254LnO2Llu/9IXPnrkf/783yo8ar7ygbIYrgTtekIiuEGpmDUpyBqiBoX +i0TpvUBd9tjOHpUeU2iWU7jvdz/ZiJbHjRlQDxK5jte9mTIXgmlhxcmPK6jrBIhXkBr CS1rwZ3JrQL1CutANxS+B1MgSiuge+NCBW//IJkpt3TtsT4fNyrOB4B8O7glUeKkoxTT MyCBZQf+7UpU1jMC4gZifq1lFhwnQB4o2SblOuPjHczJWQWfeu7Km/3fjFNHksr7PPbZ Swjw== 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 u9si2985328otq.92.2020.03.20.08.10.03; Fri, 20 Mar 2020 08:10:33 -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 S1727060AbgCTPHL (ORCPT + 99 others); Fri, 20 Mar 2020 11:07:11 -0400 Received: from netrider.rowland.org ([192.131.102.5]:48463 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726778AbgCTPHL (ORCPT ); Fri, 20 Mar 2020 11:07:11 -0400 Received: (qmail 29646 invoked by uid 500); 20 Mar 2020 11:07:10 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 20 Mar 2020 11:07:10 -0400 Date: Fri, 20 Mar 2020 11:07:10 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Andrea Parri cc: "Joel Fernandes (Google)" , , Akira Yokosawa , Boqun Feng , Daniel Lustig , David Howells , Jade Alglave , , Luc Maranget , Nicholas Piggin , "Paul E. McKenney" , Peter Zijlstra , Will Deacon Subject: Re: [PATCH 1/3] LKMM: Add litmus test for RCU GP guarantee where updater frees object In-Reply-To: <20200320102603.GA22784@andrea> 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 On Fri, 20 Mar 2020, Andrea Parri wrote: > On Fri, Mar 20, 2020 at 02:55:50AM -0400, Joel Fernandes (Google) wrote: > > This adds an example for the important RCU grace period guarantee, which > > shows an RCU reader can never span a grace period. > > > > Signed-off-by: Joel Fernandes (Google) > > --- > > .../litmus-tests/RCU+sync+free.litmus | 40 +++++++++++++++++++ > > 1 file changed, 40 insertions(+) > > create mode 100644 tools/memory-model/litmus-tests/RCU+sync+free.litmus > > > > diff --git a/tools/memory-model/litmus-tests/RCU+sync+free.litmus b/tools/memory-model/litmus-tests/RCU+sync+free.litmus > > new file mode 100644 > > index 0000000000000..c4682502dd296 > > --- /dev/null > > +++ b/tools/memory-model/litmus-tests/RCU+sync+free.litmus > > @@ -0,0 +1,40 @@ > > +C RCU+sync+free > > + > > +(* > > + * Result: Never > > + * > > + * This litmus test demonstrates that an RCU reader can never see a write after > > + * the grace period, if it saw writes that happen before the grace period. This > > + * is a typical pattern of RCU usage, where the write before the grace period > > + * assigns a pointer, and the writes after destroy the object that the pointer > > + * points to. > > + * > > + * This guarantee also implies, an RCU reader can never span a grace period and > > + * is an important RCU grace period memory ordering guarantee. > > + *) > > + > > +{ > > +x = 1; > > +y = x; > > +z = 1; > > FYI, this could become a little more readable if we wrote it as follows: > > int x = 1; > int *y = &x; > int z = 1; Also, the test won't work with klitmus7 unless you do this. > The LKMM tools are happy either way, just a matter of style/preference; > and yes, MP+onceassign+derefonce isn't currently following mine... ;-/ > > > > +} > > + > > +P0(int *x, int *z, int **y) > > +{ > > + int r0; > > This would need to be "int *r0;" in order to make klitmus7(+gcc) happy. > > > > + int r1; > > + > > + rcu_read_lock(); > > + r0 = rcu_dereference(*y); > > + r1 = READ_ONCE(*r0); > > + rcu_read_unlock(); > > +} > > + > > +P1(int *x, int *z, int **y) > > +{ > > + rcu_assign_pointer(*y, z); > > AFAICT, you don't need this "RELEASE"; e.g., compare this test with the > example in: > > https://www.kernel.org/doc/Documentation/RCU/Design/Requirements/Requirements.html#Grace-Period%20Guarantee > > What am I missing? If z were not a simple variable but a more complicated structure, the RELEASE would be necessary to ensure that all P1's prior changes to z became visible before the write to y. Besides, it's good form always to match rcu_dereference() with rcu_assign_pointer(), for code documentation if nothing else. Alan