From: "Paul E. McKenney" <paulmck@kernel.org>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com,
dipankar@in.ibm.com, akpm@linux-foundation.org,
mathieu.desnoyers@efficios.com, josh@joshtriplett.org,
tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org,
dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com,
oleg@redhat.com, joel@joelfernandes.org
Subject: Re: [PATCH tip/core/rcu 05/13] rcu: Always set .need_qs from __rcu_read_lock() for strict GPs
Date: Sun, 6 Sep 2020 19:33:52 -0700 [thread overview]
Message-ID: <20200907023352.GZ29330@paulmck-ThinkPad-P72> (raw)
In-Reply-To: <20200907001155.GG7503@debian-boqun.qqnc3lrjykvubdpftowmye0fmh.lx.internal.cloudapp.net>
On Mon, Sep 07, 2020 at 08:11:55AM +0800, Boqun Feng wrote:
> On Fri, Sep 04, 2020 at 06:41:42AM -0700, Paul E. McKenney wrote:
> > On Fri, Sep 04, 2020 at 12:05:34PM +0800, Boqun Feng wrote:
> > > Hi Paul,
> > >
> > > On Mon, Aug 31, 2020 at 11:11:12AM -0700, paulmck@kernel.org wrote:
> > > > From: "Paul E. McKenney" <paulmck@kernel.org>
> > > >
> > > > The ->rcu_read_unlock_special.b.need_qs field in the task_struct
> > > > structure indicates that the RCU core needs a quiscent state from the
> > > > corresponding task. The __rcu_read_unlock() function checks this (via
> > > > an eventual call to rcu_preempt_deferred_qs_irqrestore()), and if set
> > > > reports a quiscent state immediately upon exit from the outermost RCU
> > > > read-side critical section.
> > > >
> > > > Currently, this flag is only set when the scheduling-clock interrupt
> > > > decides that the current RCU grace period is too old, as in about
> > > > one full second too old. But if the kernel has been built with
> > > > CONFIG_RCU_STRICT_GRACE_PERIOD=y, we clearly do not want to wait that
> > > > long. This commit therefore sets the .need_qs field immediately at the
> > > > start of the RCU read-side critical section from within __rcu_read_lock()
> > > > in order to unconditionally enlist help from __rcu_read_unlock().
> > > >
> > >
> > > So why not make rcu_preempt_deferred_qs_irqrestore() always treat
> > > need_qs is true if CONFIG_RCU_STRICT_GRACE_PERIOD = y? IOW:
> > >
> > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
> > > index 982fc5be5269..2a9f31545453 100644
> > > --- a/kernel/rcu/tree_plugin.h
> > > +++ b/kernel/rcu/tree_plugin.h
> > > @@ -449,6 +449,8 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags)
> > > * t->rcu_read_unlock_special cannot change.
> > > */
> > > special = t->rcu_read_unlock_special;
> > > + if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) && rcu_state.gp_kthread)
> > > + special.b.need_qs = true;
> > > rdp = this_cpu_ptr(&rcu_data);
> > > if (!special.s && !rdp->exp_deferred_qs) {
> > > local_irq_restore(flags);
> > >
> > > , and in this way, you can save one store for each rcu_read_lock() ;-)
> >
> > Because unless I am missing something subtle, if the .need_qs
> > flag is not set, execution is not guaranteed to reach
> > rcu_preempt_deferred_qs_irqrestore().
>
> Fair enough. Although I think we can also add IS_ENABLED(...) check to
> make the outermost rcu_read_unlock() to call rcu_read_unlock_special()
> unconditionally, but that's too much I think.
You are quite right that there are several ways to make this
work. So yes, one alternative would be the IS_ENABLED() check in
rcu_read_unlock() in conjunction with your suggested added check in
rcu_preempt_deferred_qs_irqrestore(). But from what I know at the moment,
the current state is favored. Smaller change and all that.
Thanx, Paul
> Regards,
> Boqun
>
> > Thanx, Paul
> >
> > > Regards,
> > > Boqun
> > >
> > > > But note the additional check for rcu_state.gp_kthread, which prevents
> > > > attempts to awaken RCU's grace-period kthread during early boot before
> > > > there is a scheduler. Leaving off this check results in early boot hangs.
> > > > So early that there is no console output. Thus, this additional check
> > > > fails until such time as RCU's grace-period kthread has been created,
> > > > avoiding these empty-console hangs.
> > > >
> > > > Reported-by Jann Horn <jannh@google.com>
> > > > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > > > ---
> > > > kernel/rcu/tree_plugin.h | 2 ++
> > > > 1 file changed, 2 insertions(+)
> > > >
> > > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
> > > > index 44cf77d..668bbd2 100644
> > > > --- a/kernel/rcu/tree_plugin.h
> > > > +++ b/kernel/rcu/tree_plugin.h
> > > > @@ -376,6 +376,8 @@ void __rcu_read_lock(void)
> > > > rcu_preempt_read_enter();
> > > > if (IS_ENABLED(CONFIG_PROVE_LOCKING))
> > > > WARN_ON_ONCE(rcu_preempt_depth() > RCU_NEST_PMAX);
> > > > + if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) && rcu_state.gp_kthread)
> > > > + WRITE_ONCE(current->rcu_read_unlock_special.b.need_qs, true);
> > > > barrier(); /* critical section after entry code. */
> > > > }
> > > > EXPORT_SYMBOL_GPL(__rcu_read_lock);
> > > > --
> > > > 2.9.5
> > > >
next prev parent reply other threads:[~2020-09-07 2:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-31 18:11 [PATCH tip/core/rcu 0/13] Add strict grace periods for KASAN use for v5.10 Paul E. McKenney
2020-08-31 18:11 ` [PATCH tip/core/rcu 01/13] rcu: Add Kconfig option for strict RCU grace periods paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 02/13] rcu: Reduce leaf fanout " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 03/13] rcu: Restrict default jiffies_till_first_fqs for strict RCU GPs paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 04/13] rcu: Force DEFAULT_RCU_BLIMIT to 1000 " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 05/13] rcu: Always set .need_qs from __rcu_read_lock() for strict GPs paulmck
2020-09-04 4:05 ` Boqun Feng
2020-09-04 13:41 ` Paul E. McKenney
2020-09-07 0:11 ` Boqun Feng
2020-09-07 2:33 ` Paul E. McKenney [this message]
2020-08-31 18:11 ` [PATCH tip/core/rcu 06/13] rcu: Do full report for .need_qs " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 07/13] rcu: Attempt QS when CPU discovers GP " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 08/13] rcu: IPI all CPUs at GP start " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 09/13] rcu: IPI all CPUs at GP end " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 10/13] rcu: Provide optional RCU-reader exit delay " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 11/13] rcu: Execute RCU reader shortly after rcu_core " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 12/13] rcu: Report QS for outermost PREEMPT=n rcu_read_unlock() " paulmck
2020-08-31 18:11 ` [PATCH tip/core/rcu 13/13] rcu: Remove unused "cpu" parameter from rcu_report_qs_rdp() paulmck
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=20200907023352.GZ29330@paulmck-ThinkPad-P72 \
--to=paulmck@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=boqun.feng@gmail.com \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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