Message ID | 20241106153213.38896-3-frederic@kernel.org (mailing list archive) |
---|---|
State | Accepted |
Commit | 2996980e20b7a54a1869df15b3445374b850b155 |
Headers | show |
Series | RCU NOCB for v6.13 | expand |
> diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h > index 16865475120b..2605dd234a13 100644 > --- a/kernel/rcu/tree_nocb.h > +++ b/kernel/rcu/tree_nocb.h > @@ -891,7 +891,18 @@ static void nocb_cb_wait(struct rcu_data *rdp) > swait_event_interruptible_exclusive(rdp->nocb_cb_wq, > nocb_cb_wait_cond(rdp)); > if (kthread_should_park()) { > - kthread_parkme(); > + /* > + * kthread_park() must be preceded by an rcu_barrier(). > + * But yet another rcu_barrier() might have sneaked in between > + * the barrier callback execution and the callbacks counter > + * decrement. > + */ > + if (rdp->nocb_cb_sleep) { Is READ_ONCE() not required here? - Neeraj > + rcu_nocb_lock_irqsave(rdp, flags); > + WARN_ON_ONCE(rcu_segcblist_n_cbs(&rdp->cblist)); > + rcu_nocb_unlock_irqrestore(rdp, flags); > + kthread_parkme(); > + } > } else if (READ_ONCE(rdp->nocb_cb_sleep)) { > WARN_ON(signal_pending(current)); > trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("WokeEmpty"));
Le Mon, Nov 11, 2024 at 01:07:16PM +0530, Neeraj Upadhyay a écrit : > > > diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h > > index 16865475120b..2605dd234a13 100644 > > --- a/kernel/rcu/tree_nocb.h > > +++ b/kernel/rcu/tree_nocb.h > > @@ -891,7 +891,18 @@ static void nocb_cb_wait(struct rcu_data *rdp) > > swait_event_interruptible_exclusive(rdp->nocb_cb_wq, > > nocb_cb_wait_cond(rdp)); > > if (kthread_should_park()) { > > - kthread_parkme(); > > + /* > > + * kthread_park() must be preceded by an rcu_barrier(). > > + * But yet another rcu_barrier() might have sneaked in between > > + * the barrier callback execution and the callbacks counter > > + * decrement. > > + */ > > + if (rdp->nocb_cb_sleep) { > > Is READ_ONCE() not required here? No because it can't be written concurrently at this point. The value observed here if kthread_should_park() must have been written locally on the previous call to nocb_cb_wait(). Thanks. > > > - Neeraj > > > + rcu_nocb_lock_irqsave(rdp, flags); > > + WARN_ON_ONCE(rcu_segcblist_n_cbs(&rdp->cblist)); > > + rcu_nocb_unlock_irqrestore(rdp, flags); > > + kthread_parkme(); > > + } > > } else if (READ_ONCE(rdp->nocb_cb_sleep)) { > > WARN_ON(signal_pending(current)); > > trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("WokeEmpty")); >
On 11/13/2024 3:07 AM, Frederic Weisbecker wrote: > Le Mon, Nov 11, 2024 at 01:07:16PM +0530, Neeraj Upadhyay a écrit : >> >>> diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h >>> index 16865475120b..2605dd234a13 100644 >>> --- a/kernel/rcu/tree_nocb.h >>> +++ b/kernel/rcu/tree_nocb.h >>> @@ -891,7 +891,18 @@ static void nocb_cb_wait(struct rcu_data *rdp) >>> swait_event_interruptible_exclusive(rdp->nocb_cb_wq, >>> nocb_cb_wait_cond(rdp)); >>> if (kthread_should_park()) { >>> - kthread_parkme(); >>> + /* >>> + * kthread_park() must be preceded by an rcu_barrier(). >>> + * But yet another rcu_barrier() might have sneaked in between >>> + * the barrier callback execution and the callbacks counter >>> + * decrement. >>> + */ >>> + if (rdp->nocb_cb_sleep) { >> >> Is READ_ONCE() not required here? > > No because it can't be written concurrently at this point. The value observed > here if kthread_should_park() must have been written locally on the previous > call to nocb_cb_wait(). > Ok, got it. I was not aware of any other flow (other than the one described in this fix) which can race with it. So, asked. - Neeraj
diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h index 16865475120b..2605dd234a13 100644 --- a/kernel/rcu/tree_nocb.h +++ b/kernel/rcu/tree_nocb.h @@ -891,7 +891,18 @@ static void nocb_cb_wait(struct rcu_data *rdp) swait_event_interruptible_exclusive(rdp->nocb_cb_wq, nocb_cb_wait_cond(rdp)); if (kthread_should_park()) { - kthread_parkme(); + /* + * kthread_park() must be preceded by an rcu_barrier(). + * But yet another rcu_barrier() might have sneaked in between + * the barrier callback execution and the callbacks counter + * decrement. + */ + if (rdp->nocb_cb_sleep) { + rcu_nocb_lock_irqsave(rdp, flags); + WARN_ON_ONCE(rcu_segcblist_n_cbs(&rdp->cblist)); + rcu_nocb_unlock_irqrestore(rdp, flags); + kthread_parkme(); + } } else if (READ_ONCE(rdp->nocb_cb_sleep)) { WARN_ON(signal_pending(current)); trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("WokeEmpty"));