[PATCH] srcu/tiny: Remove preempt_disable/enable() in srcu_gp_start_if_needed()

Zqiang posted 1 patch 1 day, 15 hours ago
There is a newer version of this series
kernel/rcu/srcutiny.c | 3 ---
1 file changed, 3 deletions(-)
[PATCH] srcu/tiny: Remove preempt_disable/enable() in srcu_gp_start_if_needed()
Posted by Zqiang 1 day, 15 hours ago
Currently, the srcu_gp_start_if_needed() is always be invoked in
preempt disable's critical section, this commit therefore remove
redundant preempt_disable/enable() in srcu_gp_start_if_needed().

Fixes: 65b4a59557f6 ("srcu: Make Tiny SRCU explicitly disable preemption")
Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 kernel/rcu/srcutiny.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
index b52ec45698e8..417bd0e4457c 100644
--- a/kernel/rcu/srcutiny.c
+++ b/kernel/rcu/srcutiny.c
@@ -181,10 +181,8 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 	unsigned long cookie;
 
-	preempt_disable();  // Needed for PREEMPT_LAZY
 	cookie = get_state_synchronize_srcu(ssp);
 	if (ULONG_CMP_GE(READ_ONCE(ssp->srcu_idx_max), cookie)) {
-		preempt_enable();
 		return;
 	}
 	WRITE_ONCE(ssp->srcu_idx_max, cookie);
@@ -194,7 +192,6 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 		else if (list_empty(&ssp->srcu_work.entry))
 			list_add(&ssp->srcu_work.entry, &srcu_boot_list);
 	}
-	preempt_enable();
 }
 
 /*
-- 
2.48.1
Re: [PATCH] srcu/tiny: Remove preempt_disable/enable() in srcu_gp_start_if_needed()
Posted by Paul E. McKenney 1 day, 14 hours ago
On Mon, Sep 08, 2025 at 08:31:55AM +0800, Zqiang wrote:
> Currently, the srcu_gp_start_if_needed() is always be invoked in
> preempt disable's critical section, this commit therefore remove
> redundant preempt_disable/enable() in srcu_gp_start_if_needed().
> 
> Fixes: 65b4a59557f6 ("srcu: Make Tiny SRCU explicitly disable preemption")
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>

Looks good, but what would be a good way to make this code defend itself
against being invoked from someplace else that did have preemption
enabled?  Especially given that the Tree SRCU version of this function
does get invoked with preemption enabled?

							Thanx, Paul

> ---
>  kernel/rcu/srcutiny.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
> index b52ec45698e8..417bd0e4457c 100644
> --- a/kernel/rcu/srcutiny.c
> +++ b/kernel/rcu/srcutiny.c
> @@ -181,10 +181,8 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
>  {
>  	unsigned long cookie;
>  
> -	preempt_disable();  // Needed for PREEMPT_LAZY
>  	cookie = get_state_synchronize_srcu(ssp);
>  	if (ULONG_CMP_GE(READ_ONCE(ssp->srcu_idx_max), cookie)) {
> -		preempt_enable();
>  		return;
>  	}
>  	WRITE_ONCE(ssp->srcu_idx_max, cookie);
> @@ -194,7 +192,6 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
>  		else if (list_empty(&ssp->srcu_work.entry))
>  			list_add(&ssp->srcu_work.entry, &srcu_boot_list);
>  	}
> -	preempt_enable();
>  }
>  
>  /*
> -- 
> 2.48.1
>
Re: [PATCH] srcu/tiny: Remove preempt_disable/enable() in srcu_gp_start_if_needed()
Posted by Zqiang 1 day, 2 hours ago
> 
> On Mon, Sep 08, 2025 at 08:31:55AM +0800, Zqiang wrote:
> 
> > 
> > Currently, the srcu_gp_start_if_needed() is always be invoked in
> >  preempt disable's critical section, this commit therefore remove
> >  redundant preempt_disable/enable() in srcu_gp_start_if_needed().
> >  
> >  Fixes: 65b4a59557f6 ("srcu: Make Tiny SRCU explicitly disable preemption")
> >  Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> > 
> Looks good, but what would be a good way to make this code defend itself
> against being invoked from someplace else that did have preemption
> enabled? Especially given that the Tree SRCU version of this function
> does get invoked with preemption enabled?

ok, maybe we can add lockdep_assert_preemption_disabled() in
the srcu_gp_start_if_needed() ?

Thanks
Zqiang


> 
>  Thanx, Paul
> 
> > 
> > ---
> >  kernel/rcu/srcutiny.c | 3 ---
> >  1 file changed, 3 deletions(-)
> >  
> >  diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
> >  index b52ec45698e8..417bd0e4457c 100644
> >  --- a/kernel/rcu/srcutiny.c
> >  +++ b/kernel/rcu/srcutiny.c
> >  @@ -181,10 +181,8 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
> >  {
> >  unsigned long cookie;
> >  
> >  - preempt_disable(); // Needed for PREEMPT_LAZY
> >  cookie = get_state_synchronize_srcu(ssp);
> >  if (ULONG_CMP_GE(READ_ONCE(ssp->srcu_idx_max), cookie)) {
> >  - preempt_enable();
> >  return;
> >  }
> >  WRITE_ONCE(ssp->srcu_idx_max, cookie);
> >  @@ -194,7 +192,6 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
> >  else if (list_empty(&ssp->srcu_work.entry))
> >  list_add(&ssp->srcu_work.entry, &srcu_boot_list);
> >  }
> >  - preempt_enable();
> >  }
> >  
> >  /*
> >  -- 
> >  2.48.1
> >
>
Re: [PATCH] srcu/tiny: Remove preempt_disable/enable() in srcu_gp_start_if_needed()
Posted by Paul E. McKenney 15 hours ago
On Mon, Sep 08, 2025 at 01:19:44PM +0000, Zqiang wrote:
> > 
> > On Mon, Sep 08, 2025 at 08:31:55AM +0800, Zqiang wrote:
> > 
> > > 
> > > Currently, the srcu_gp_start_if_needed() is always be invoked in
> > >  preempt disable's critical section, this commit therefore remove
> > >  redundant preempt_disable/enable() in srcu_gp_start_if_needed().
> > >  
> > >  Fixes: 65b4a59557f6 ("srcu: Make Tiny SRCU explicitly disable preemption")
> > >  Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> > > 
> > Looks good, but what would be a good way to make this code defend itself
> > against being invoked from someplace else that did have preemption
> > enabled? Especially given that the Tree SRCU version of this function
> > does get invoked with preemption enabled?
> 
> ok, maybe we can add lockdep_assert_preemption_disabled() in
> the srcu_gp_start_if_needed() ?

That sounds like a good idea to me!

							Thanx, Paul

> Thanks
> Zqiang
> 
> 
> > 
> >  Thanx, Paul
> > 
> > > 
> > > ---
> > >  kernel/rcu/srcutiny.c | 3 ---
> > >  1 file changed, 3 deletions(-)
> > >  
> > >  diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
> > >  index b52ec45698e8..417bd0e4457c 100644
> > >  --- a/kernel/rcu/srcutiny.c
> > >  +++ b/kernel/rcu/srcutiny.c
> > >  @@ -181,10 +181,8 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
> > >  {
> > >  unsigned long cookie;
> > >  
> > >  - preempt_disable(); // Needed for PREEMPT_LAZY
> > >  cookie = get_state_synchronize_srcu(ssp);
> > >  if (ULONG_CMP_GE(READ_ONCE(ssp->srcu_idx_max), cookie)) {
> > >  - preempt_enable();
> > >  return;
> > >  }
> > >  WRITE_ONCE(ssp->srcu_idx_max, cookie);
> > >  @@ -194,7 +192,6 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
> > >  else if (list_empty(&ssp->srcu_work.entry))
> > >  list_add(&ssp->srcu_work.entry, &srcu_boot_list);
> > >  }
> > >  - preempt_enable();
> > >  }
> > >  
> > >  /*
> > >  -- 
> > >  2.48.1
> > >
> >