Linux RCU subsystem development
 help / color / mirror / Atom feed
From: Pingfan Liu <kernelfans@gmail.com>
To: rcu@vger.kernel.org
Cc: Pingfan Liu <kernelfans@gmail.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	"Zhang, Qiang1" <qiang1.zhang@intel.com>
Subject: [PATCH 2/3] srcu: protect against concurrent srcu_gp_end()
Date: Mon, 28 Nov 2022 16:28:15 +0800	[thread overview]
Message-ID: <20221128082816.28518-3-kernelfans@gmail.com> (raw)
In-Reply-To: <20221128082816.28518-1-kernelfans@gmail.com>

At present, the code chunk "Transition to big if needed" is out of the
lock srcu_cb_mutex, which allows the following scene:

    srcu_gp_end() on cpu1                srcu_gp_end() on cpu2

    init_srcu_struct_nodes()
    ^^  scheduled out in the middle
                                         init_srcu_struct_nodes()
                                         ^^ overwrite the context set up by cpu1

Squashing out the race window by putting the code chunk under the
protection of srcu_cb_mutex.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: "Zhang, Qiang1" <qiang1.zhang@intel.com>
To: rcu@vger.kernel.org
---
 kernel/rcu/srcutree.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index fe0759d89c2d..281cd69fe804 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -811,6 +811,13 @@ static void srcu_gp_end(struct srcu_struct *ssp)
 			spin_unlock_irqrestore_rcu_node(sdp, flags);
 		}
 
+	/* Transition to big if needed. */
+	if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
+		if (ss_state == SRCU_SIZE_ALLOC)
+			init_srcu_struct_nodes(ssp, GFP_KERNEL);
+		else
+			smp_store_release(&ssp->srcu_size_state, ss_state + 1);
+	}
 	/* Callback initiation done, allow grace periods after next. */
 	mutex_unlock(&ssp->srcu_cb_mutex);
 
@@ -826,13 +833,6 @@ static void srcu_gp_end(struct srcu_struct *ssp)
 		spin_unlock_irq_rcu_node(ssp);
 	}
 
-	/* Transition to big if needed. */
-	if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
-		if (ss_state == SRCU_SIZE_ALLOC)
-			init_srcu_struct_nodes(ssp, GFP_KERNEL);
-		else
-			smp_store_release(&ssp->srcu_size_state, ss_state + 1);
-	}
 }
 
 /*
-- 
2.31.1


  parent reply	other threads:[~2022-11-28  8:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28  8:28 [PATCH 0/3] srcu: shrink the num of srcu_size_state Pingfan Liu
2022-11-28  8:28 ` [PATCH 1/3] srcu: Eliminate the requirement of SRCU_SIZE_WAIT_CALL Pingfan Liu
2022-11-28  8:40   ` Zhang, Qiang1
2022-11-28 14:01     ` Pingfan Liu
2022-11-29  0:41       ` Paul E. McKenney
2022-11-30  3:34   ` [PATCHv2] " Pingfan Liu
2022-12-02 22:17     ` Paul E. McKenney
2022-12-13 12:51       ` Pingfan Liu
2022-12-13 20:02         ` Paul E. McKenney
2022-12-15  3:37           ` Pingfan Liu
2022-12-16 16:54             ` Paul E. McKenney
2022-11-28  8:28 ` Pingfan Liu [this message]
2022-11-28  9:20   ` [PATCH 2/3] srcu: protect against concurrent srcu_gp_end() Zhang, Qiang1
2022-11-28 14:36     ` Pingfan Liu
2022-11-28 14:47       ` Zhang, Qiang1
2022-11-30  3:36         ` Pingfan Liu
2022-11-28  8:28 ` [PATCH 3/3] srcu: Decrease the srcu size state numbers Pingfan Liu

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=20221128082816.28518-3-kernelfans@gmail.com \
    --to=kernelfans@gmail.com \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=qiang1.zhang@intel.com \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.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