The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: Zqiang <qiang1.zhang@intel.com>
Cc: paulmck@kernel.org, quic_neeraju@quicinc.com,
	joel@joelfernandes.org, rcu@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] rcu: Fix the start_poll_synchronize_rcu_expedited() be invoked very early
Date: Thu, 12 Jan 2023 14:18:08 +0100	[thread overview]
Message-ID: <Y8AIkL0ZT7nhiYFK@lothringen> (raw)
In-Reply-To: <20230112075629.1661429-1-qiang1.zhang@intel.com>

On Thu, Jan 12, 2023 at 03:56:29PM +0800, Zqiang wrote:
> Currently, the start_poll_synchronize_rcu_expedited() can be invoked
> very early. before rcu_init(), the rcu_data structure's->mynode is not
> initialized, if invoke start_poll_synchronize_rcu_expedited() before
> rcu_init(), will trigger a null rcu_node structure's->exp_seq_poll access.
> 
> This commit add boot_exp_seq_poll_rq member to rcu_state structure to
> store seq number return by invoke start_poll_synchronize_rcu_expedited()
> very early.
> 
> Fixes: d96c52fe4907 ("rcu: Add polled expedited grace-period primitives")
> Signed-off-by: Zqiang <qiang1.zhang@intel.com>

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>

Just a nit below:

> ---
>  kernel/rcu/tree.c     | 3 ++-
>  kernel/rcu/tree.h     | 1 +
>  kernel/rcu/tree_exp.h | 6 ++++--
>  3 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index 63545d79da51..12f0891ce7f4 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -92,6 +92,7 @@ static struct rcu_state rcu_state = {
>  	.exp_mutex = __MUTEX_INITIALIZER(rcu_state.exp_mutex),
>  	.exp_wake_mutex = __MUTEX_INITIALIZER(rcu_state.exp_wake_mutex),
>  	.ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED,
> +	.boot_exp_seq_poll_rq = RCU_GET_STATE_COMPLETED,
>  };
>  
>  /* Dump rcu_node combining tree at boot to verify correct setup. */
> @@ -4938,7 +4939,7 @@ void __init rcu_init(void)
>  		qovld_calc = qovld;
>  
>  	// Kick-start any polled grace periods that started early.
> -	if (!(per_cpu_ptr(&rcu_data, cpu)->mynode->exp_seq_poll_rq & 0x1))
> +	if (!(rcu_state.boot_exp_seq_poll_rq & 0x1))

This can be "if (!(rcu_state.boot_exp_seq_poll_rq == RCU_GET_STATE_COMPLETED))" 

>  		(void)start_poll_synchronize_rcu_expedited();
>  
>  	rcu_test_sync_prims();
> diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
> index 192536916f9a..ae50ca6853ad 100644
> --- a/kernel/rcu/tree.h
> +++ b/kernel/rcu/tree.h
> @@ -397,6 +397,7 @@ struct rcu_state {
>  						/* Synchronize offline with */
>  						/*  GP pre-initialization. */
>  	int nocb_is_setup;			/* nocb is setup from boot */
> +	unsigned long boot_exp_seq_poll_rq;

A comment on the right can mention: "/* exp seq poll request before rcu_init() */"

Thanks!

>  };
>  
>  /* Values for rcu_state structure's gp_flags field. */
> diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h
> index 956cd459ba7f..1b35a1e233d9 100644
> --- a/kernel/rcu/tree_exp.h
> +++ b/kernel/rcu/tree_exp.h
> @@ -1068,9 +1068,11 @@ unsigned long start_poll_synchronize_rcu_expedited(void)
>  	if (rcu_init_invoked())
>  		raw_spin_lock_irqsave(&rnp->exp_poll_lock, flags);
>  	if (!poll_state_synchronize_rcu(s)) {
> -		rnp->exp_seq_poll_rq = s;
> -		if (rcu_init_invoked())
> +		if (rcu_init_invoked()) {
> +			rnp->exp_seq_poll_rq = s;
>  			queue_work(rcu_gp_wq, &rnp->exp_poll_wq);
> +		} else
> +			rcu_state.boot_exp_seq_poll_rq = s;
>  	}
>  	if (rcu_init_invoked())
>  		raw_spin_unlock_irqrestore(&rnp->exp_poll_lock, flags);
> -- 
> 2.25.1
> 

  reply	other threads:[~2023-01-12 13:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12  7:56 [PATCH v2] rcu: Fix the start_poll_synchronize_rcu_expedited() be invoked very early Zqiang
2023-01-12 13:18 ` Frederic Weisbecker [this message]
2023-01-12 14:54 ` Joel Fernandes
2023-01-12 19:06 ` Paul E. McKenney
2023-01-13  9:12   ` Zhang, Qiang1
2023-01-13 12:10     ` Zhang, Qiang1
2023-01-13 12:19       ` Zhang, Qiang1
2023-01-13 14:49       ` Paul E. McKenney
2023-01-13 15:02         ` Zhang, Qiang1
2023-01-13 15:27           ` Paul E. McKenney

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=Y8AIkL0ZT7nhiYFK@lothringen \
    --to=frederic@kernel.org \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=qiang1.zhang@intel.com \
    --cc=quic_neeraju@quicinc.com \
    --cc=rcu@vger.kernel.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