From: Peter Zijlstra <peterz@infradead.org>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Frederic Weisbecker <frederic@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Boqun Feng <boqun.feng@gmail.com>,
Joel Fernandes <joel@joelfernandes.org>,
Josh Triplett <josh@joshtriplett.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Neeraj Upadhyay <neeraj.upadhyay@amd.com>,
Steven Rostedt <rostedt@goodmis.org>,
Uladzislau Rezki <urezki@gmail.com>, rcu <rcu@vger.kernel.org>,
Zqiang <qiang.zhang1211@gmail.com>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
matz@suse.de, ubizjak@gmail.com
Subject: Re: [PATCH 2/4] rcu/tasks: Handle new PF_IDLE semantics
Date: Tue, 31 Oct 2023 10:52:02 +0100 [thread overview]
Message-ID: <20231031095202.GC35651@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <622438a5-4d20-4bc9-86b9-f3de55ca6cda@paulmck-laptop>
On Mon, Oct 30, 2023 at 01:11:41PM -0700, Paul E. McKenney wrote:
> On Mon, Oct 30, 2023 at 09:21:38AM +0100, Peter Zijlstra wrote:
> > On Fri, Oct 27, 2023 at 04:41:30PM -0700, Paul E. McKenney wrote:
> > > On Sat, Oct 28, 2023 at 12:46:28AM +0200, Peter Zijlstra wrote:
> >
> > > > Nah, this is more or less what I feared. I just worry people will come
> > > > around and put WRITE_ONCE() on the other end. I don't think that'll buy
> > > > us much. Nor do I think the current READ_ONCE()s actually matter.
> > >
> > > My friend, you trust compilers more than I ever will. ;-)
> >
> > Well, we only use the values {0,1,2}, that's contained in the first
> > byte. Are we saying compiler will not only byte-split but also
> > bit-split the loads?
> >
> > But again, lacking the WRITE_ONCE() counterpart, this READ_ONCE() isn't
> > getting you anything, and if you really worried about it, shouldn't you
> > have proposed a patch making it all WRITE_ONCE() back when you did this
> > tasks-rcu stuff?
>
> There are not all that many of them. If such a WRITE_ONCE() patch would
> be welcome, I would be happy to put it together.
>
> > > > But perhaps put a comment there, that we don't care for the races and
> > > > only need to observe a 0 once or something.
> > >
> > > There are these two passagers in the big lock comment preceding the
> > > RCU Tasks code:
> >
> > > // rcu_tasks_pregp_step():
> > > // Invokes synchronize_rcu() in order to wait for all in-flight
> > > // t->on_rq and t->nvcsw transitions to complete. This works because
> > > // all such transitions are carried out with interrupts disabled.
> >
> > > Does that suffice, or should we add more?
> >
> > Probably sufficient. If one were to have used the search option :-)
> >
> > Anyway, this brings me to nvcsw, exact same problem there, except
> > possibly worse, because now we actually do care about the full word.
> >
> > No WRITE_ONCE() write side, so the READ_ONCE() don't help against
> > store-tearing (however unlikely that actually is in this case).
>
> Again, if such a WRITE_ONCE() patch would be welcome, I would be happy
> to put it together.
Welcome is not the right word. What bugs me most is that this was never
raised when this code was written :/
Mostly my problem is that GCC generates such utter shite when you
mention volatile. See, the below patch changes the perfectly fine and
non-broken:
0148 1d8: 49 83 06 01 addq $0x1,(%r14)
into:
0148 1d8: 49 8b 06 mov (%r14),%rax
014b 1db: 48 83 c0 01 add $0x1,%rax
014f 1df: 49 89 06 mov %rax,(%r14)
For absolutely no reason :-(
At least clang doesn't do this, it stays:
0403 413: 49 ff 45 00 incq 0x0(%r13)
irrespective of the volatile.
---
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 802551e0009b..d616211b9151 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6575,8 +6575,8 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
*/
static void __sched notrace __schedule(unsigned int sched_mode)
{
struct task_struct *prev, *next;
- unsigned long *switch_count;
+ volatile unsigned long *switch_count;
unsigned long prev_state;
struct rq_flags rf;
struct rq *rq;
next prev parent reply other threads:[~2023-10-31 9:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20231027144050.110601-1-frederic@kernel.org>
[not found] ` <20231027144050.110601-3-frederic@kernel.org>
2023-10-27 19:20 ` Peter Zijlstra
2023-10-27 21:23 ` Paul E. McKenney
2023-10-27 22:46 ` Peter Zijlstra
2023-10-27 23:41 ` Paul E. McKenney
2023-10-30 8:21 ` Peter Zijlstra
2023-10-30 20:11 ` Paul E. McKenney
2023-10-31 9:52 ` Peter Zijlstra [this message]
2023-10-31 14:16 ` Michael Matz
2023-10-31 14:43 ` Paul E. McKenney
2023-10-31 15:16 ` Peter Zijlstra
2023-10-31 15:55 ` Michael Matz
2023-10-31 16:23 ` Peter Zijlstra
2023-10-31 16:49 ` Michael Matz
2023-10-31 17:10 ` Paul E. McKenney
2023-10-31 14:24 ` Paul E. McKenney
2023-10-31 15:20 ` Peter Zijlstra
2023-10-31 18:12 ` Paul E. McKenney
2023-11-15 9:04 ` [tip: sched/core] sched: Use WRITE_ONCE() for p->on_rq tip-bot2 for Paul E. McKenney
2023-10-27 19:23 ` [PATCH 0/4] rcu: Fix PF_IDLE related issues v3 Peter Zijlstra
2023-10-24 21:46 [PATCH 0/4] rcu: Fix PF_IDLE related issues v2 Frederic Weisbecker
2023-10-24 21:46 ` [PATCH 2/4] rcu/tasks: Handle new PF_IDLE semantics Frederic Weisbecker
2023-10-25 8:40 ` Peter Zijlstra
2023-10-25 10:31 ` Frederic Weisbecker
2023-10-26 12:15 ` Z qiang
2023-10-26 14:34 ` Frederic Weisbecker
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=20231031095202.GC35651@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Liam.Howlett@oracle.com \
--cc=boqun.feng@gmail.com \
--cc=frederic@kernel.org \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=matz@suse.de \
--cc=neeraj.upadhyay@amd.com \
--cc=paulmck@kernel.org \
--cc=qiang.zhang1211@gmail.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=ubizjak@gmail.com \
--cc=urezki@gmail.com \
/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
Powered by JetHome