srcu: Make Tiny SRCU synchronize_srcu() more complete

Message ID 20221109073638.935473-1-qiang1.zhang@intel.com
State New
Headers
Series srcu: Make Tiny SRCU synchronize_srcu() more complete |

Commit Message

Zqiang Nov. 9, 2022, 7:36 a.m. UTC
  This commit add lockdep detection for illegal use synchronize_srcu()
in same-type SRCU (or in RCU) read-side critical section and support
early boot operations.

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
---
 kernel/rcu/srcutiny.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Comments

Paul E. McKenney Nov. 11, 2022, 8:04 a.m. UTC | #1
On Wed, Nov 09, 2022 at 03:36:38PM +0800, Zqiang wrote:
> This commit add lockdep detection for illegal use synchronize_srcu()
> in same-type SRCU (or in RCU) read-side critical section and support
> early boot operations.
> 
> Signed-off-by: Zqiang <qiang1.zhang@intel.com>

Queued and pushed with the usual wordsmithing (please check), thank you!

							Thanx, Paul

> ---
>  kernel/rcu/srcutiny.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
> index 33adafdad261..b12fb0cec44d 100644
> --- a/kernel/rcu/srcutiny.c
> +++ b/kernel/rcu/srcutiny.c
> @@ -197,6 +197,16 @@ void synchronize_srcu(struct srcu_struct *ssp)
>  {
>  	struct rcu_synchronize rs;
>  
> +	RCU_LOCKDEP_WARN(lockdep_is_held(ssp) ||
> +			lock_is_held(&rcu_bh_lock_map) ||
> +			lock_is_held(&rcu_lock_map) ||
> +			lock_is_held(&rcu_sched_lock_map),
> +			"Illegal synchronize_srcu() in same-type SRCU (or in RCU) read-side critical section");
> +
> +	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
> +		return;
> +
> +	might_sleep();
>  	init_rcu_head_on_stack(&rs.head);
>  	init_completion(&rs.completion);
>  	call_srcu(ssp, &rs.head, wakeme_after_rcu);
> -- 
> 2.25.1
>
  
Zqiang Nov. 11, 2022, 11:09 a.m. UTC | #2
On Wed, Nov 09, 2022 at 03:36:38PM +0800, Zqiang wrote:
> This commit add lockdep detection for illegal use synchronize_srcu()
> in same-type SRCU (or in RCU) read-side critical section and support
> early boot operations.
> 
> Signed-off-by: Zqiang <qiang1.zhang@intel.com>
>
>Queued and pushed with the usual wordsmithing (please check), thank you!

Thanks for  wordsmithing,  I have seen the new commit message 😊.

>
>							Thanx, Paul
>
> ---
>  kernel/rcu/srcutiny.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
> index 33adafdad261..b12fb0cec44d 100644
> --- a/kernel/rcu/srcutiny.c
> +++ b/kernel/rcu/srcutiny.c
> @@ -197,6 +197,16 @@ void synchronize_srcu(struct srcu_struct *ssp)
>  {
>  	struct rcu_synchronize rs;
>  
> +	RCU_LOCKDEP_WARN(lockdep_is_held(ssp) ||
> +			lock_is_held(&rcu_bh_lock_map) ||
> +			lock_is_held(&rcu_lock_map) ||
> +			lock_is_held(&rcu_sched_lock_map),
> +			"Illegal synchronize_srcu() in same-type SRCU (or in RCU) read-side critical section");
> +
> +	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
> +		return;
> +
> +	might_sleep();
>  	init_rcu_head_on_stack(&rs.head);
>  	init_completion(&rs.completion);
>  	call_srcu(ssp, &rs.head, wakeme_after_rcu);
> -- 
> 2.25.1
>
  

Patch

diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
index 33adafdad261..b12fb0cec44d 100644
--- a/kernel/rcu/srcutiny.c
+++ b/kernel/rcu/srcutiny.c
@@ -197,6 +197,16 @@  void synchronize_srcu(struct srcu_struct *ssp)
 {
 	struct rcu_synchronize rs;
 
+	RCU_LOCKDEP_WARN(lockdep_is_held(ssp) ||
+			lock_is_held(&rcu_bh_lock_map) ||
+			lock_is_held(&rcu_lock_map) ||
+			lock_is_held(&rcu_sched_lock_map),
+			"Illegal synchronize_srcu() in same-type SRCU (or in RCU) read-side critical section");
+
+	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
+		return;
+
+	might_sleep();
 	init_rcu_head_on_stack(&rs.head);
 	init_completion(&rs.completion);
 	call_srcu(ssp, &rs.head, wakeme_after_rcu);