Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3686727imm; Tue, 29 May 2018 11:36:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ1JsoRUVflJjMxW7H6H+ftIRLRWPeSunYsFgwTi3U4N+cMsu+NneK9az5KDKodo9uYc7J9 X-Received: by 2002:a63:a702:: with SMTP id d2-v6mr9563682pgf.246.1527618987219; Tue, 29 May 2018 11:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527618987; cv=none; d=google.com; s=arc-20160816; b=ucDE47WX1shEs+FBDNiLD+ZwwkuQnGvcnOkQq9OJC2i8N4NlP+uAMshgkkIK9z7IPL 4nL7oPDkgMsxU1Y8WeocpYBjHMd7HhRR8akiLu+24i/1xuCTpx5eNcAeMsTdWfS1A9B0 LEnZc+Fe5bfKUxmU+EllWA923eNJRDgJl26FjfmOpNkTmDJoL68GsNh6m8S8sp3Hqy9D /RcqGPjbns2fjuSQg0s2YwhiujuiYwX6rVcq1W6rmhJy+GJ/LYNlpEs1JP/52iloJOfW h0SdTvT3nDn7UDLC6M4fxD/wKmhkrxvnJ689kRbqokg7GQjthyqU6cV2h24S0o1xr2j8 FYyA== 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:arc-authentication-results; bh=dhjMqv1PpfVXoT3lxHwmpyOL/3QKpDL7cHT672x1Dfk=; b=Xnzh7kNcdqceWfMIusM054HLux2AEDgM5q2tGPseA593jOj8cjuQbptM+7MQGYyBeS pwkRsfwxvJIzCc5TPspELZ/RCfPY+aEVLCOer64hn/LKBAv3seaoNQYQ7VdlnGHYlaVk 2QRpklixnd7SjzJLkiJjsK5p/RsAd7SkmUgvFNMy5zk7thuJwh+daE+jydi6Bmaw+ySz nQGImVAI12on5YQf8/1sTXdP7yZ8QTdzYt9YfXhPiQc2E7NaYvZSZ1J1rUJZhQ2HyKJP 7OjmUGjPY1x1p1zpL9cIzbK/oDNn+oX0CEfEoallkamjVMa5wdZ0wNhXT2QlF+YMeZPq Mmtw== 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 x15-v6si21804704pge.686.2018.05.29.11.36.13; Tue, 29 May 2018 11:36:27 -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 S965973AbeE2Sfi (ORCPT + 99 others); Tue, 29 May 2018 14:35:38 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:46516 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S965885AbeE2Sff (ORCPT ); Tue, 29 May 2018 14:35:35 -0400 Received: (qmail 4490 invoked by uid 2102); 29 May 2018 14:35:34 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 29 May 2018 14:35:34 -0400 Date: Tue, 29 May 2018 14:35:34 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: "Paul E. McKenney" cc: linux-kernel@vger.kernel.org, , , , , , , , , , , , , Subject: Re: LKMM litmus test for Roman Penyaev's rcu-rr In-Reply-To: <20180528220811.GA5221@linux.vnet.ibm.com> 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 Mon, 28 May 2018, Paul E. McKenney wrote: > Hello! > > The litmus test below is a first attempt to model Roman's rcu-rr > round-robin RCU-protected linked list. His test code, which includes > the algorithm under test, may be found here: > > https://github.com/rouming/rcu-rr/blob/master/rcu-rr.c > > The P0() process below roughly corresponds to remove_conn_from_arr(), > with litmus-test variable "c" standing in for the per-CPU ppcpu_con. > Similarly, P1() roughly corresponds to get_next_conn_rr(). It claims > that the algorithm is safe, and also claims that it becomes unsafe if > either synchronize_rcu() is removed. This algorithm (the one in the litmus test; I haven't looked at Roman's code) does seem valid. In addition to removing either synchronize_rcu(), interchanging the order of the stores in P0 (c first, then w) would also invalidate it. This is a little unusual in that c is written by more than one thread with no protection. It works because the writes are all stores of a single pointer. Why does the litmus test use smp_store_release() in three places? There doesn't seem to be any need; WRITE_ONCE() would be sufficient. Alan > Does this in fact realistically model Roman's algorithm? Either way, > is there a better approach? > > Thanx, Paul > > ------------------------------------------------------------------------ > > C C-RomanPenyaev-list-rcu-rr > > { > int *z=1; (* List: v->w->x->y->z. Noncircular, but long enough. *) > int *y=z; > int *x=y; > int *w=x; > int *v=w; (* List head is v. *) > int *c=w; (* Cache, emulating ppcpu_con. *) > } > > P0(int *c, int *v, int *w, int *x, int *y) > { > rcu_assign_pointer(*w, y); /* Remove x from list. */ > synchronize_rcu(); > r1 = READ_ONCE(*c); > if (r1 == x) { > WRITE_ONCE(*c, 0); /* Invalidate cache. */ > synchronize_rcu(); > } > smp_store_release(x, 0); /* Emulate kfree(x). */ > } > > P1(int *c, int *v) > { > rcu_read_lock(); > r1 = READ_ONCE(*c); /* Pick up cache. */ > if (r1 == 0) { > r1 = READ_ONCE(*v); /* Cache empty, start from head. */ > } > r2 = rcu_dereference(*r1); /* Advance to next element. */ > smp_store_release(c, r2); /* Update cache. */ > rcu_read_unlock(); > > /* And repeat. */ > rcu_read_lock(); > r3 = READ_ONCE(*c); > if (r3 == 0) { > r3 = READ_ONCE(*v); > } > r4 = rcu_dereference(*r3); > smp_store_release(c, r4); > rcu_read_unlock(); > } > > locations [0:r1; 1:r1; 1:r3; c; v; w; x; y] > exists (1:r1=0 \/ 1:r2=0 \/ 1:r3=0 \/ 1:r4=0) (* Better not be freed!!! *)