[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240512165529.GD7541@redhat.com>
Date: Sun, 12 May 2024 18:55:29 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: "Paul E. McKenney" <paulmck@...nel.org>
Cc: "Uladzislau Rezki (Sony)" <urezki@...il.com>, RCU <rcu@...r.kernel.org>,
Neeraj upadhyay <Neeraj.Upadhyay@....com>,
Boqun Feng <boqun.feng@...il.com>, Hillf Danton <hdanton@...a.com>,
Joel Fernandes <joel@...lfernandes.org>,
LKML <linux-kernel@...r.kernel.org>,
Oleksiy Avramchenko <oleksiy.avramchenko@...y.com>,
Frederic Weisbecker <frederic@...nel.org>,
Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH] rcu/sync: don't read rcu_sync->gp_count lockless
On 05/12, Paul E. McKenney wrote:
>
> --- a/kernel/rcu/sync.c
> +++ b/kernel/rcu/sync.c
> @@ -151,15 +151,11 @@ void rcu_sync_enter(struct rcu_sync *rsp)
> */
> void rcu_sync_exit(struct rcu_sync *rsp)
> {
> - int gpc;
> -
> WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_IDLE);
> - WARN_ON_ONCE(READ_ONCE(rsp->gp_count) == 0);
>
> spin_lock_irq(&rsp->rss_lock);
> - gpc = rsp->gp_count - 1;
> - WRITE_ONCE(rsp->gp_count, gpc);
> - if (!gpc) {
> + WARN_ON_ONCE(rsp->gp_count == 0);
> + if (!--rsp->gp_count) {
> if (rsp->gp_state == GP_PASSED) {
> WRITE_ONCE(rsp->gp_state, GP_EXIT);
> rcu_sync_call(rsp);
> @@ -178,10 +174,10 @@ void rcu_sync_dtor(struct rcu_sync *rsp)
> {
> int gp_state;
>
> - WARN_ON_ONCE(READ_ONCE(rsp->gp_count));
> WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_PASSED);
>
> spin_lock_irq(&rsp->rss_lock);
> + WARN_ON_ONCE(rsp->gp_count);
> if (rsp->gp_state == GP_REPLAY)
> WRITE_ONCE(rsp->gp_state, GP_EXIT);
> gp_state = rsp->gp_state;
Thanks Paul!
But then I think this change can also revert this chunk from the previous
patch:
@@ -122,7 +122,7 @@ void rcu_sync_enter(struct rcu_sync *rsp)
* we are called at early boot time but this shouldn't happen.
*/
}
- rsp->gp_count++;
+ WRITE_ONCE(rsp->gp_count, rsp->gp_count + 1);
spin_unlock_irq(&rsp->rss_lock);
if (gp_state == GP_IDLE) {
Thanks again,
Oleg.
Powered by blists - more mailing lists