Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93106C54E94 for ; Wed, 25 Jan 2023 19:09:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236156AbjAYTJo (ORCPT ); Wed, 25 Jan 2023 14:09:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236029AbjAYTJO (ORCPT ); Wed, 25 Jan 2023 14:09:14 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 64B785CE6D for ; Wed, 25 Jan 2023 11:09:00 -0800 (PST) Received: (qmail 222384 invoked by uid 1000); 25 Jan 2023 14:08:59 -0500 Date: Wed, 25 Jan 2023 14:08:59 -0500 From: Alan Stern To: "Paul E. McKenney" Cc: Jonas Oberhauser , Andrea Parri , Jonas Oberhauser , Peter Zijlstra , will , "boqun.feng" , npiggin , dhowells , "j.alglave" , "luc.maranget" , akiyks , dlustig , joel , urezki , quic_neeraju , frederic , Kernel development list Subject: Re: Internal vs. external barriers (was: Re: Interesting LKMM litmus test) Message-ID: References: <2788294a-972e-acbc-84ce-25d2bb4d26d6@huaweicloud.com> <20230124221524.GV2948950@paulmck-ThinkPad-P17-Gen-1> <20230124225449.GY2948950@paulmck-ThinkPad-P17-Gen-1> <20230125022019.GB2948950@paulmck-ThinkPad-P17-Gen-1> <20230125150520.GG2948950@paulmck-ThinkPad-P17-Gen-1> <20230125171832.GH2948950@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230125171832.GH2948950@paulmck-ThinkPad-P17-Gen-1> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 25, 2023 at 09:18:32AM -0800, Paul E. McKenney wrote: > ------------------------------------------------------------------------ > > C C-srcu-observed-4 > > (* > * Result: Sometimes > * > * The Linux-kernel implementation is suspected to forbid this. > *) > > {} > > P0(int *x, int *y, int *z, struct srcu_struct *s) > { > int r1; > > r1 = srcu_read_lock(s); > WRITE_ONCE(*y, 2); > WRITE_ONCE(*x, 1); > srcu_read_unlock(s, r1); > } > > P1(int *x, int *y, int *z, struct srcu_struct *s) > { > int r1; > > WRITE_ONCE(*y, 1); > synchronize_srcu(s); > WRITE_ONCE(*z, 2); > } > > P2(int *x, int *y, int *z, struct srcu_struct *s) > { > WRITE_ONCE(*z, 1); > smp_store_release(x, 2); > } > > exists (x=1 /\ y=1 /\ z=1) > > ------------------------------------------------------------------------ > > We get the following from herd7: > > ------------------------------------------------------------------------ > > $ herd7 -conf linux-kernel.cfg C-srcu-observed-4.litmus > Test C-srcu-observed-4 Allowed > States 8 > x=1; y=1; z=1; > x=1; y=1; z=2; > x=1; y=2; z=1; > x=1; y=2; z=2; > x=2; y=1; z=1; > x=2; y=1; z=2; > x=2; y=2; z=1; > x=2; y=2; z=2; > Ok > Witnesses > Positive: 1 Negative: 7 > Condition exists (x=1 /\ y=1 /\ z=1) > Observation C-srcu-observed-4 Sometimes 1 7 > Time C-srcu-observed-4 0.02 > Hash=8b6020369b73ac19070864a9db00bbf8 > > ------------------------------------------------------------------------ > > This does not seem to me to be consistent with your "The RCU guarantee > about writes in a read-side critical section becoming visible to all > CPUs before a later grace period ends". Let's see. That guarantee requires only that x=1 and y=2 become visible to P1 and P2 before the grace period ends. And since synchronize_srcu is a strong fence, y=1 must become visible to P0 and P2 before the grace period ends. Presumably after y=2 does, because it overwrites y=2. Okay so far. Now at some point P2 executes x=2. If this were to happen after the grace period ended, it would overwrite x=1. Therefore it must happen before the grace period ends, and therefore P2 must also write z=1 before the grace period ends. So we have P2 writing z=1 before P1 writes z=2. But this doesn't mean z=2 has to overwrite z=1! (You had a diagram illustrating this point in one of your own slides for a talk about the LKMM.) Overwriting is required only when the earlier write becomes visible to the later write's CPU before the later write occurs, and nothing in this test forces z=2 to propagate to P1 before the z=1 write executes. So the litmus test's outcome can happen without violating my guarantee. > So what am I missing here? Can't tell. I'm not sure why you think the litmus test isn't consistent with the guarantee. > Again, I am OK with LKMM allowing C-srcu-observed-4.litmus, as long as > the actual Linux-kernel implementation forbids it. Why do you want the implementation to forbid it? The pattern of the litmus test resembles 3+3W, and you don't care whether the kernel allows that pattern. Do you? Alan