linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: Jonas Oberhauser <jonas.oberhauser@huaweicloud.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	Andrea Parri <parri.andrea@gmail.com>,
	Jonas Oberhauser <jonas.oberhauser@huawei.com>,
	Peter Zijlstra <peterz@infradead.org>, will <will@kernel.org>,
	"boqun.feng" <boqun.feng@gmail.com>, npiggin <npiggin@gmail.com>,
	dhowells <dhowells@redhat.com>, "j.alglave" <j.alglave@ucl.ac.uk>,
	"luc.maranget" <luc.maranget@inria.fr>, akiyks <akiyks@gmail.com>,
	dlustig <dlustig@nvidia.com>, joel <joel@joelfernandes.org>,
	urezki <urezki@gmail.com>,
	quic_neeraju <quic_neeraju@quicinc.com>,
	frederic <frederic@kernel.org>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: Internal vs. external barriers (was: Re: Interesting LKMM litmus test)
Date: Thu, 26 Jan 2023 10:48:02 -0800	[thread overview]
Message-ID: <20230126184802.GF2948950@paulmck-ThinkPad-P17-Gen-1> (raw)
In-Reply-To: <0ef2e974-5c3a-6195-62d5-a4c436bd7d82@huaweicloud.com>

On Thu, Jan 26, 2023 at 01:17:49PM +0100, Jonas Oberhauser wrote:
> 
> 
> On 1/26/2023 2:53 AM, Paul E. McKenney wrote:
> > On Wed, Jan 25, 2023 at 08:45:44PM -0500, Alan Stern wrote:
> > > On Wed, Jan 25, 2023 at 03:33:08PM -0800, Paul E. McKenney wrote:
> > > > Ah, and returning to the earlier question as to whether srcu_read_unlock()
> > > > can use release semantics instead of smp_mb(), at the very least, this
> > > > portion of the synchronize_srcu() function's header comment must change:
> > > > 
> > > > 	On systems with more than one CPU, when synchronize_srcu()
> > > > 	returns, each CPU is guaranteed to have executed a full
> > > > 	memory barrier since the end of its last corresponding SRCU
> > > > 	read-side critical section whose beginning preceded the call
> > > > 	to synchronize_srcu().
> > > 
> > > Of course, there might be code relying on a guarantee that
> > > srcu_read_unlock() executes a full memory barrier.  This guarantee would
> > > certainly no longer hold.  But as I understand it, this guarantee was
> > > never promised by the SRCU subsystem.
> > That indented sentence was copied from the synchronize_srcu() function's
> > header comment, which might be interpreted by some as a promise by the
> > SRCU subsystem.
> 
> I think we understand that it is a promise of the SRCU subsystem, the
> question is just what the promise is.
> As Alan said, if the promise is interpreted as something like
> 
> "every store that propagated to the read side critical section must have
> propagated to all CPUs before the  synchronize_srcu() ends" (where the RSCS
> and synchronize_srcu() calls are those from the promise)
> 
> then that guarantee holds even if you only use a release fence to
> communicate the end of the RSCS to the GP. Note that this interpretation is
> analogous to the promise of smp_mb__after_unlock_lock(), which says that an
> UNLOCK+LOCK pair act as a full fence: here the read-side unlock+gp act as a
> full memory barrier.

Good point that the existing smp_mb__after_unlock_lock() can be used for
any use cases relying on the more literal interpretation of this promise.
We already have the work-around!  ;-)

> On the other hand, if the promise is more literally interpreted as
> 
> "there is a (possibly virtual) instruction in the reader-side execution
> stream that acts as a full memory barrier, and that instruction is executed
> before the  synchronize_srcu() ends"
> 
> then that guarantee is violated, and I suppose you might be able to write
> some absurd client that inspects every store of the reader thread and sees
> that there is no line in the reader side code that acts like a full fence.
> But it would take a lot of effort to discern this.

The usual litmus test is shown at the end of this email.  If you remove
the "//" from any of those smp_mb() calls, the test is forbidden, but
with all of them commented out, it is allowed.  Which illustrates the
utility of smp_mb__after_unlock_lock().  It also shows that LKMM does
not model this guarantee from synchronize_srcu()'s comment header.
Which might be fine, actually.

Of course, I just now wrote this litmus test, so it should be viewed
with extreme suspicion.

> Perhaps someone interpreting the promise like this might however come to the
> conclusion that because the only part of the code that is actually under
> control of srcu, and hence the only code where that full barrier could be
> hidden, would be inside the srcu_unlock(), they might expect to always find
> this full barrier there and treat srcu_unlock() in general as a full
> barrier. Considering that the wording explicitly isn't "an srcu_unlock() is
> a full barrier", I hope few people would have this unhealthy idea. But you
> never know.

Given that the more literal interpretation is not unreasonable, we should
assume that someone somewhere might have interpreted it that way.

But I agree that the odds of someone actually relying on this are low,
and any such use case can be fixed with smp_mb__before_srcu_read_unlock(),
similar to smp_mb__after_srcu_read_unlock() that you note is already in use.

It would still be good to scan SRCU use for this sort of pattern, maybe
manually, maybe via something like coccinelle.  Alternatively, I could
post on my blog (with right of first refusal to LWN and you guys as
co-authors) telling the community of our intent to change this and see
what people say.  Probably both rather than either/or.

Thoughts?

							Thanx, Paul

------------------------------------------------------------------------

C C-srcu-observed-6

(*
 * Result: Sometimes
 *
 * The result is Never if any of the smp_mb() calls is uncommented.
 *)

{}

P0(int *a, int *b, int *c, int *d, struct srcu_struct *s)
{
	int r1;
	int r2;
	int r3;
	int r4;

	r1 = srcu_read_lock(s);
	WRITE_ONCE(*b, 2);
	r2 = READ_ONCE(*a);
	// smp_mb();
	srcu_read_unlock(s, r1);
	// smp_mb();
	r3 = READ_ONCE(*c);
	// smp_mb();
	r4 = READ_ONCE(*d);
}

P1(int *a, int *b, int *c, int *d, struct srcu_struct *s)
{
	WRITE_ONCE(*b, 1);
	synchronize_srcu(s);
	WRITE_ONCE(*c, 1);
}

P2(int *a, int *b, int *c, int *d, struct srcu_struct *s)
{
	WRITE_ONCE(*d, 1);
	smp_mb();
	WRITE_ONCE(*a, 1);
}

exists (0:r2=1 /\ 0:r3=1 /\ 0:r4=0 /\ b=1)

  reply	other threads:[~2023-01-26 18:48 UTC|newest]

Thread overview: 161+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220921173109.GA1214281@paulmck-ThinkPad-P17-Gen-1>
     [not found] ` <YytfFiMT2Xsdwowf@rowland.harvard.edu>
     [not found]   ` <YywXuzZ/922LHfjI@hirez.programming.kicks-ass.net>
     [not found]     ` <114ECED5-FED1-4361-94F7-8D9BC02449B7>
     [not found]       ` <YzSAnclenTz7KQyt@rowland.harvard.edu>
     [not found]         ` <f763bd5ff835458d8750b61da47fe316@huawei.com>
2023-01-03 18:56           ` Internal vs. external barriers (was: Re: Interesting LKMM litmus test) Alan Stern
2023-01-04 15:37             ` Andrea Parri
2023-01-04 20:58               ` Alan Stern
     [not found]             ` <ee186bc17a5e48298a5373f688496dce@huawei.com>
2023-01-05 17:32               ` Paul E. McKenney
     [not found]                 ` <bea712c82e6346f8973399a5711ff78a@huawei.com>
2023-01-11 15:06                   ` Alan Stern
     [not found]                     ` <768ffe7edc7f4ddfacd5b0a8e844ed84@huawei.com>
2023-01-11 17:01                       ` Alan Stern
     [not found]                         ` <07579baee4b84532a76ea8b0b33052bb@huawei.com>
2023-01-12 21:57                           ` Paul E. McKenney
2023-01-13 16:38                             ` Alan Stern
2023-01-13 19:54                               ` Paul E. McKenney
     [not found]                               ` <06a8aef7eb8d46bca34521a80880dae3@huawei.com>
2023-01-14 17:42                                 ` Paul E. McKenney
     [not found]                             ` <e51c82a113484b6bb62354a49376f248@huawei.com>
2023-01-14 16:42                               ` Alan Stern
2023-01-17 17:48                                 ` Jonas Oberhauser
2023-01-17 21:19                                   ` Alan Stern
2023-01-18 11:25                                     ` Jonas Oberhauser
2023-01-19  2:28                                       ` Alan Stern
2023-01-19 11:22                                         ` Jonas Oberhauser
2023-01-19 16:41                                           ` Alan Stern
2023-01-19 18:43                                             ` Paul E. McKenney
2023-01-23 16:16                                             ` Jonas Oberhauser
2023-01-23 19:58                                               ` Alan Stern
2023-01-23 20:06                                                 ` Jonas Oberhauser
2023-01-23 20:41                                                   ` Alan Stern
2023-01-24 13:21                                                     ` Jonas Oberhauser
2023-01-24 15:54                                             ` Jonas Oberhauser
2023-01-24 17:22                                               ` Alan Stern
     [not found]                     ` <4c1abc7733794519ad7c5153ae8b58f9@huawei.com>
2023-01-13 16:28                       ` Alan Stern
2023-01-13 20:07                         ` Paul E. McKenney
2023-01-13 20:32                           ` Paul E. McKenney
2023-01-14 17:40                             ` Alan Stern
2023-01-14 17:48                               ` Paul E. McKenney
     [not found]                             ` <136d019d8c8049f6b737627df830e66f@huawei.com>
2023-01-14 17:53                               ` Paul E. McKenney
2023-01-14 18:15                                 ` Paul E. McKenney
2023-01-14 19:58                                   ` Alan Stern
2023-01-15  5:19                                     ` Paul E. McKenney
2023-01-14 20:19                                   ` Alan Stern
2023-01-15  5:15                                     ` Paul E. McKenney
2023-01-15 16:23                                       ` Alan Stern
2023-01-15 18:10                                         ` Paul E. McKenney
2023-01-15 20:46                                           ` Alan Stern
2023-01-16  4:23                                             ` Paul E. McKenney
2023-01-16 18:11                                               ` Alan Stern
2023-01-16 19:06                                                 ` Paul E. McKenney
2023-01-16 19:20                                                   ` Alan Stern
2023-01-16 22:13                                                     ` Paul E. McKenney
2023-01-17 11:46                                                       ` Andrea Parri
2023-01-17 15:14                                                         ` Paul E. McKenney
2023-01-17 15:56                                                           ` Alan Stern
2023-01-17 17:43                                                             ` Paul E. McKenney
2023-01-17 18:27                                                               ` Jonas Oberhauser
2023-01-17 18:55                                                                 ` Paul E. McKenney
2023-01-17 20:20                                                                   ` Jonas Oberhauser
2023-01-17 20:15                                                               ` Alan Stern
2023-01-18  3:50                                                                 ` Paul E. McKenney
2023-01-18 16:50                                                                   ` Alan Stern
2023-01-18 19:42                                                                     ` Jonas Oberhauser
2023-01-18 20:19                                                                       ` Paul E. McKenney
2023-01-18 20:30                                                                         ` Jonas Oberhauser
2023-01-18 21:12                                                                           ` Paul E. McKenney
2023-01-18 21:24                                                                             ` Jonas Oberhauser
2023-01-19  0:11                                                                               ` Paul E. McKenney
2023-01-19 13:39                                                                                 ` Jonas Oberhauser
2023-01-19 18:41                                                                                   ` Paul E. McKenney
2023-01-19 19:51                                                                                     ` Alan Stern
2023-01-19 21:53                                                                                       ` Paul E. McKenney
2023-01-19 22:04                                                                                         ` Alan Stern
2023-01-19 23:03                                                                                           ` Paul E. McKenney
2023-01-20  9:43                                                                                         ` Jonas Oberhauser
2023-01-20 15:39                                                                                           ` Paul E. McKenney
2023-01-20 20:46                                                                                             ` Jonas Oberhauser
2023-01-20 21:37                                                                                               ` Paul E. McKenney
2023-01-20 22:36                                                                                                 ` Jonas Oberhauser
2023-01-20 23:19                                                                                                   ` Paul E. McKenney
2023-01-21  0:03                                                                                                     ` Jonas Oberhauser
2023-01-21  0:34                                                                                                       ` Paul E. McKenney
2023-01-20  3:55                                                                                       ` Paul E. McKenney
2023-01-20  9:20                                                                                         ` Jonas Oberhauser
2023-01-20 12:34                                                                                         ` Jonas Oberhauser
2023-01-20 12:51                                                                                           ` Jonas Oberhauser
2023-01-20 15:32                                                                                             ` Paul E. McKenney
2023-01-20 20:56                                                                                               ` Jonas Oberhauser
2023-01-20 21:40                                                                                                 ` Paul E. McKenney
2023-01-20 16:14                                                                                         ` Alan Stern
2023-01-20 17:30                                                                                           ` Paul E. McKenney
2023-01-20 18:15                                                                                             ` Alan Stern
2023-01-20 18:59                                                                                               ` Paul E. McKenney
2023-01-20 10:13                                                                                     ` Jonas Oberhauser
2023-01-20 15:47                                                                                       ` Paul E. McKenney
2023-01-20 22:21                                                                                         ` Jonas Oberhauser
2023-01-20 16:18                                                                                       ` Alan Stern
2023-01-20 21:41                                                                                         ` Jonas Oberhauser
2023-01-21  4:38                                                                                           ` Paul E. McKenney
2023-01-21 17:36                                                                                           ` Alan Stern
2023-01-21 18:40                                                                                             ` Paul E. McKenney
2023-01-21 19:56                                                                                               ` Alan Stern
2023-01-21 20:10                                                                                                 ` Paul E. McKenney
2023-01-21 21:03                                                                                                   ` Alan Stern
2023-01-21 23:49                                                                                                     ` Paul E. McKenney
2023-01-23 11:48                                                                                             ` Jonas Oberhauser
2023-01-23 15:55                                                                                               ` Alan Stern
2023-01-23 19:40                                                                                                 ` Jonas Oberhauser
2023-01-23 20:34                                                                                                   ` Alan Stern
2023-01-18 20:06                                                                     ` Paul E. McKenney
2023-01-18 20:54                                                                       ` Alan Stern
2023-01-18 21:05                                                                         ` Jonas Oberhauser
2023-01-19  0:02                                                                         ` Paul E. McKenney
2023-01-19  2:19                                                                           ` Alan Stern
2023-01-19 11:23                                                                             ` Paul E. McKenney
2023-01-20 16:01                                                                           ` Alan Stern
2023-01-20 17:58                                                                             ` Paul E. McKenney
2023-01-20 18:37                                                                               ` Alan Stern
2023-01-20 19:20                                                                                 ` Paul E. McKenney
2023-01-20 20:36                                                                                   ` Alan Stern
2023-01-20 21:20                                                                                     ` Paul E. McKenney
2023-01-22 20:32                                                                                       ` Alan Stern
2023-01-23 20:16                                                                                         ` Paul E. McKenney
2023-01-24  2:18                                                                                           ` Alan Stern
2023-01-24  4:06                                                                                             ` Paul E. McKenney
2023-01-24 11:09                                                                                               ` Andrea Parri
2023-01-24 14:54                                                                                                 ` Paul E. McKenney
2023-01-24 15:11                                                                                                   ` Jonas Oberhauser
2023-01-24 16:22                                                                                                     ` Paul E. McKenney
2023-01-24 16:39                                                                                                       ` Jonas Oberhauser
2023-01-24 17:26                                                                                                         ` Paul E. McKenney
2023-01-24 19:30                                                                                                           ` Jonas Oberhauser
2023-01-24 22:15                                                                                                             ` Paul E. McKenney
2023-01-24 22:35                                                                                                               ` Alan Stern
2023-01-24 22:54                                                                                                                 ` Paul E. McKenney
2023-01-25  1:54                                                                                                                   ` Alan Stern
2023-01-25  2:20                                                                                                                     ` Paul E. McKenney
2023-01-25 13:10                                                                                                                       ` Jonas Oberhauser
2023-01-25 15:05                                                                                                                         ` Paul E. McKenney
2023-01-25 15:34                                                                                                                           ` Alan Stern
2023-01-25 17:18                                                                                                                             ` Paul E. McKenney
2023-01-25 17:42                                                                                                                               ` Jonas Oberhauser
2023-01-25 19:08                                                                                                                               ` Alan Stern
2023-01-25 19:46                                                                                                                                 ` Paul E. McKenney
2023-01-25 20:36                                                                                                                                   ` Andrea Parri
2023-01-25 21:10                                                                                                                                     ` Jonas Oberhauser
2023-01-25 21:23                                                                                                                                       ` Paul E. McKenney
2023-01-25 20:46                                                                                                                                   ` Alan Stern
2023-01-25 21:38                                                                                                                                     ` Paul E. McKenney
2023-01-25 23:33                                                                                                                                       ` Paul E. McKenney
2023-01-26  1:45                                                                                                                                         ` Alan Stern
2023-01-26  1:53                                                                                                                                           ` Paul E. McKenney
2023-01-26 12:17                                                                                                                                             ` Jonas Oberhauser
2023-01-26 18:48                                                                                                                                               ` Paul E. McKenney [this message]
2023-01-27 15:03                                                                                                                                                 ` Jonas Oberhauser
2023-01-27 16:50                                                                                                                                                   ` Paul E. McKenney
2023-01-27 16:54                                                                                                                                                     ` Paul E. McKenney
2023-01-18 19:57                                                                   ` Jonas Oberhauser
2023-01-18 21:06                                                                     ` Paul E. McKenney
2023-01-18  2:15                                                               ` Alan Stern
2023-01-18  5:17                                                                 ` Paul E. McKenney
2023-01-18 16:03                                                                   ` Alan Stern
2023-01-18 16:59                                                                     ` Boqun Feng
2023-01-18 17:08                                                                       ` Alan Stern
2023-01-18 17:41                                                                     ` Paul E. McKenney
2023-01-19 19:07                                                                       ` Paul E. McKenney
2023-01-14 16:55                           ` Alan Stern
2023-01-14 17:35                             ` Paul E. McKenney
     [not found]                         ` <17078dd97cb6480f9c51e27058af3197@huawei.com>
2023-01-14 17:27                           ` Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230126184802.GF2948950@paulmck-ThinkPad-P17-Gen-1 \
    --to=paulmck@kernel.org \
    --cc=akiyks@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dlustig@nvidia.com \
    --cc=frederic@kernel.org \
    --cc=j.alglave@ucl.ac.uk \
    --cc=joel@joelfernandes.org \
    --cc=jonas.oberhauser@huawei.com \
    --cc=jonas.oberhauser@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luc.maranget@inria.fr \
    --cc=npiggin@gmail.com \
    --cc=parri.andrea@gmail.com \
    --cc=peterz@infradead.org \
    --cc=quic_neeraju@quicinc.com \
    --cc=stern@rowland.harvard.edu \
    --cc=urezki@gmail.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).