[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230114174802.GE2948950@paulmck-ThinkPad-P17-Gen-1>
Date: Sat, 14 Jan 2023 09:48:02 -0800
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Alan Stern <stern@...land.harvard.edu>
Cc: Jonas Oberhauser <jonas.oberhauser@...wei.com>,
Peter Zijlstra <peterz@...radead.org>,
"parri.andrea" <parri.andrea@...il.com>, will <will@...nel.org>,
"boqun.feng" <boqun.feng@...il.com>, npiggin <npiggin@...il.com>,
dhowells <dhowells@...hat.com>,
"j.alglave" <j.alglave@....ac.uk>,
"luc.maranget" <luc.maranget@...ia.fr>, akiyks <akiyks@...il.com>,
dlustig <dlustig@...dia.com>, joel <joel@...lfernandes.org>,
urezki <urezki@...il.com>,
quic_neeraju <quic_neeraju@...cinc.com>,
frederic <frederic@...nel.org>,
Kernel development list <linux-kernel@...r.kernel.org>
Subject: Re: Internal vs. external barriers (was: Re: Interesting LKMM litmus
test)
On Sat, Jan 14, 2023 at 12:40:39PM -0500, Alan Stern wrote:
> On Fri, Jan 13, 2023 at 12:32:41PM -0800, Paul E. McKenney wrote:
> > > Making LKMM correctly model all of this has been on my todo list for an
> > > embarrassingly long time.
> >
> > But there is no time like the present...
> >
> > Here is what mainline has to recognize SRCU read-side critical sections:
> >
> > ------------------------------------------------------------------------
> >
> > (* Compute matching pairs of nested Srcu-lock and Srcu-unlock *)
> > let srcu-rscs = let rec
> > unmatched-locks = Srcu-lock \ domain(matched)
> > and unmatched-unlocks = Srcu-unlock \ range(matched)
> > and unmatched = unmatched-locks | unmatched-unlocks
> > and unmatched-po = ([unmatched] ; po ; [unmatched]) & loc
> > and unmatched-locks-to-unlocks =
> > ([unmatched-locks] ; po ; [unmatched-unlocks]) & loc
> > and matched = matched | (unmatched-locks-to-unlocks \
> > (unmatched-po ; unmatched-po))
> > in matched
> >
> > (* Validate nesting *)
> > flag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-locking
> > flag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-locking
> >
> > (* Check for use of synchronize_srcu() inside an RCU critical section *)
> > flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep
> >
> > (* Validate SRCU dynamic match *)
> > flag ~empty different-values(srcu-rscs) as srcu-bad-nesting
> >
> > ------------------------------------------------------------------------
> >
> > And here is what I just now tried:
> >
> > ------------------------------------------------------------------------
> >
> > (* Compute matching pairs of Srcu-lock and Srcu-unlock *)
> > let srcu-rscs = ([Srcu-lock] ; rfi ; [Srcu-unlock]) & loc
>
> This doesn't make sense. Herd treats srcu_read_lock() as a load
> operation (it takes a pointer as argument and returns a value) and
> srcu_read_unlock() as a store operation (it takes both a pointer and a
> value as arguments and returns nothing). So you can't connect them
> with an rfi link; stores don't "read-from" loads.
>
> I suppose you might be able to connect them with a data dependency,
> though. But then how would you handle situations where two unlock
> calls both use the value returned from a single lock call? You'd have
> to check explicitly that srcu-rscs connected each lock with only one
> unlock.
Thank you! I will give the dependencies a try.
Thanx, Paul
> Alan
>
> > (* Validate nesting *)
> > flag empty srcu-rscs as no-srcu-readers
> > flag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-locking
> > flag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-locking
> >
> > (* Check for use of synchronize_srcu() inside an RCU critical section *)
> > flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep
> >
> > (* Validate SRCU dynamic match *)
> > flag ~empty different-values(srcu-rscs) as srcu-bad-nesting
> >
> > ------------------------------------------------------------------------
> >
> > This gets me "Flag no-srcu-readers" when running this litmus test:
> >
> > ------------------------------------------------------------------------
> >
> > C C-srcu-nest-1
> >
> > (*
> > * Result: Never
> > *)
> >
> > {}
> >
> > P0(int *x, int *y, struct srcu_struct *s)
> > {
> > int r1;
> > int r2;
> > int r3;
> >
> > r3 = srcu_read_lock(s);
> > r1 = READ_ONCE(*x);
> > srcu_read_unlock(s, r3);
> > r3 = srcu_read_lock(s);
> > r2 = READ_ONCE(*y);
> > srcu_read_unlock(s, r3);
> > }
> >
> > P1(int *x, int *y, struct srcu_struct *s)
> > {
> > WRITE_ONCE(*y, 1);
> > synchronize_srcu(s);
> > WRITE_ONCE(*x, 1);
> > }
> >
> > locations [0:r1]
> > exists (0:r1=1 /\ 0:r2=0)
> >
> > ------------------------------------------------------------------------
> >
> > So what did I mess up this time? ;-)
> >
> > Thanx, Paul
Powered by blists - more mailing lists