Skip to contentSkip to conversation

srcu/tiny: Remove preempt_disable/enable() in srcu_gp_start_if_needed()

PATCH Superseded Zqiang 3 participants 8 messages Sep 9, 2025 – Sep 11, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zqiang

author reviewer
#0 lore raw

PATCH v2 1/1 srcu/tiny: Remove preempt_disable/enable() in srcu_gp_start_if_needed()

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() and adds a call to lockdep_assert_preemption_disabled() in order to enable lockdep to diagnose mistaken invocations of this function from preempts-enabled code.

Fixes 65b4a59557f6 ("srcu: Make Tiny SRCU explicitly disable preemption")
---
 kernel/rcu/srcutiny.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/rcu/srcutiny.c +1 -3
index b52ec45698e8..b2da188133fc 100644
@@ -181,10 +181,9 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 	unsigned long cookie;
 
-	preempt_disable();  // Needed for PREEMPT_LAZY
+	lockdep_assert_preemption_disabled();
 	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 +193,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();
 }
 
 /*
Signature · 1 line
2.48.1
maintainer
#1 lore raw
Quoted 9 lines · Zqiang

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() and adds a call to lockdep_assert_preemption_disabled() in order to enable lockdep to diagnose mistaken invocations of this function from preempts-enabled code.

Fixes 65b4a59557f6 ("srcu: Make Tiny SRCU explicitly disable preemption")

Very good, applied for testing and further review, thank you!

Thanx, Paul

Quoted 31 lines
---
 kernel/rcu/srcutiny.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/rcu/srcutiny.c +1 -3
index b52ec45698e8..b2da188133fc 100644
@@ -181,10 +181,9 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 	unsigned long cookie;
 
-	preempt_disable();  // Needed for PREEMPT_LAZY
+	lockdep_assert_preemption_disabled();
 	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 +193,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();
 }
 
 /*
Signature · 1 line
2.48.1
maintainer
#2 lore raw

[..]

Quoted 11 lines
Quoted 11 lines
 kernel/rcu/srcutiny.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/rcu/srcutiny.c +0 -0
index b52ec45698e8..b2da188133fc 100644
@@ -181,10 +181,9 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 	unsigned long cookie;
 
Quoted 2 lines

kernel/rcu/srcutiny.c static void srcu_gp_start_if_needed(struct srcu_struct *ssp) · line 184

Quoted 2 lines
kernel/rcu/srcutiny.c +1 -1
-	preempt_disable();  // Needed for PREEMPT_LAZY
+	lockdep_assert_preemption_disabled();

nit: Do we still want to keep the comment that the expectation of preemption being disabled is for the LAZY case?

thanks,

- Joel

Quoted 17 lines
Quoted 17 lines
kernel/rcu/srcutiny.c +0 -2
 	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 +193,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();
 }
 
 /*
Signature · 1 line
2.48.1
maintainer
#3 lore raw
Quoted 12 lines · Joel Fernandes

[..]

Quoted 11 lines
Quoted 11 lines
 kernel/rcu/srcutiny.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/rcu/srcutiny.c +0 -0
index b52ec45698e8..b2da188133fc 100644
@@ -181,10 +181,9 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 	unsigned long cookie;
 
Quoted 5 lines
Quoted 2 lines

kernel/rcu/srcutiny.c static void srcu_gp_start_if_needed(struct srcu_struct *ssp) · line 184

Quoted 2 lines
kernel/rcu/srcutiny.c +1 -1
-	preempt_disable();  // Needed for PREEMPT_LAZY
+	lockdep_assert_preemption_disabled();

nit: Do we still want to keep the comment that the expectation of preemption being disabled is for the LAZY case?

Good point, and I do believe that we do. Zqiang, any reason not to add this comment back in?

Thanx, Paul

Quoted 22 lines

thanks,

- Joel

Quoted 17 lines
Quoted 17 lines
kernel/rcu/srcutiny.c +0 -2
 	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 +193,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();
 }
 
 /*
Signature · 1 line
2.48.1
author reviewer
#4 lore raw
Quoted 16 lines · Joel Fernandes
Quoted 14 lines

[..]

Quoted 11 lines

kernel/rcu/srcutiny.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
kernel/rcu/srcutiny.c +0 -0
index b52ec45698e8..b2da188133fc 100644
@@ -181,10 +181,9 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 unsigned long cookie;
 
Quoted 8 lines
Quoted 6 lines

kernel/rcu/srcutiny.c static void srcu_gp_start_if_needed(struct srcu_struct *ssp) · line 184

Quoted 2 lines
kernel/rcu/srcutiny.c +1 -1
- preempt_disable(); // Needed for PREEMPT_LAZY
+ lockdep_assert_preemption_disabled();

nit: Do we still want to keep the comment that the expectation of preemption being disabled is for the LAZY case?

Good point, and I do believe that we do. Zqiang, any reason not to add this comment back in?

in rcu-tree, this commit:

(935147775c977 "EXP srcu: Enable Tiny SRCU On all CONFIG_SMP=n kernels")

make preempt disable needed for CONFIG_PREEMPT=y or CONFIG_PREEMPT_LAZY=y when the CONFIG_SMP=n. do we need to replace "Needed for PREEMPT_LAZY" comments with "Needed for PREEMPT or PREEMPT_LAZY"?

Thanks
Zqiang

Quoted 28 lines

Thanx, Paul

Quoted 24 lines

thanks,

- Joel

Quoted 17 lines
kernel/rcu/srcutiny.c +0 -2
 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 +193,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();
 }
 
 /*
Signature · 1 line
2.48.1
maintainer
#5 lore raw
Quoted 25 lines · Zqiang
Quoted 16 lines · Joel Fernandes
Quoted 14 lines

[..]

Quoted 11 lines

kernel/rcu/srcutiny.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
kernel/rcu/srcutiny.c +0 -0
index b52ec45698e8..b2da188133fc 100644
@@ -181,10 +181,9 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 unsigned long cookie;
 
Quoted 8 lines
Quoted 6 lines

kernel/rcu/srcutiny.c static void srcu_gp_start_if_needed(struct srcu_struct *ssp) · line 184

Quoted 2 lines
kernel/rcu/srcutiny.c +1 -1
- preempt_disable(); // Needed for PREEMPT_LAZY
+ lockdep_assert_preemption_disabled();

nit: Do we still want to keep the comment that the expectation of preemption being disabled is for the LAZY case?

Good point, and I do believe that we do. Zqiang, any reason not to add this comment back in?

Quoted 7 lines

in rcu-tree, this commit:

(935147775c977 "EXP srcu: Enable Tiny SRCU On all CONFIG_SMP=n kernels")

make preempt disable needed for CONFIG_PREEMPT=y or CONFIG_PREEMPT_LAZY=y when the CONFIG_SMP=n. do we need to replace "Needed for PREEMPT_LAZY" comments with "Needed for PREEMPT or PREEMPT_LAZY"?

Good point as well, thank you! And I need to decide whether I should send that patch upstream. Its original purpose was to test PREEMPT_LAZY=y better than could be tested with PREEMPT_LAZY.

Thoughts?

Thanx, Paul

Quoted 32 lines

Thanks
Zqiang

Quoted 28 lines

Thanx, Paul

Quoted 24 lines

thanks,

- Joel

Quoted 17 lines
kernel/rcu/srcutiny.c +0 -2
 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 +193,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();
 }
 
 /*
Signature · 1 line
2.48.1
author reviewer
#6 lore raw
Quoted 36 lines · Zqiang
Quoted 26 lines · Joel Fernandes
Quoted 14 lines

[..]

Quoted 11 lines

kernel/rcu/srcutiny.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
kernel/rcu/srcutiny.c +0 -0
index b52ec45698e8..b2da188133fc 100644
@@ -181,10 +181,9 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 unsigned long cookie;
 
Quoted 6 lines

kernel/rcu/srcutiny.c static void srcu_gp_start_if_needed(struct srcu_struct *ssp) · line 184

Quoted 2 lines
kernel/rcu/srcutiny.c +1 -1
- preempt_disable(); // Needed for PREEMPT_LAZY
+ lockdep_assert_preemption_disabled();

nit: Do we still want to keep the comment that the expectation of preemption being disabled is for the LAZY case?

Good point, and I do believe that we do. Zqiang, any reason not to add this comment back in?

Quoted 8 lines

in rcu-tree, this commit:

(935147775c977 "EXP srcu: Enable Tiny SRCU On all CONFIG_SMP=n kernels")

make preempt disable needed for CONFIG_PREEMPT=y or CONFIG_PREEMPT_LAZY=y when the CONFIG_SMP=n. do we need to replace "Needed for PREEMPT_LAZY" comments with "Needed for PREEMPT or PREEMPT_LAZY"?

Quoted 5 lines

Good point as well, thank you! And I need to decide whether I should send that patch upstream. Its original purpose was to test PREEMPT_LAZY=y better than could be tested with PREEMPT_LAZY.

Thoughts?

I will add "Needed for PREEMPT_LAZY" comments, if this commit (935147775c977) is send to upstream, will update comments again in the future.

Thanks
Zqiang

Quoted 37 lines

Thanx, Paul

Quoted 33 lines

Thanks
Zqiang

Thanx, Paul

Quoted 24 lines

thanks,

- Joel

Quoted 17 lines
kernel/rcu/srcutiny.c +0 -2
 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 +193,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();
 }
 
 /*
Signature · 1 line
2.48.1
maintainer
#7 lore raw
Quoted 36 lines · Zqiang
Quoted 36 lines · Zqiang
Quoted 34 lines · Joel Fernandes
Quoted 14 lines

[..]

Quoted 11 lines

kernel/rcu/srcutiny.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
kernel/rcu/srcutiny.c +0 -0
index b52ec45698e8..b2da188133fc 100644
@@ -181,10 +181,9 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
 {
 unsigned long cookie;
 
Quoted 6 lines

kernel/rcu/srcutiny.c static void srcu_gp_start_if_needed(struct srcu_struct *ssp) · line 184

Quoted 2 lines
kernel/rcu/srcutiny.c +1 -1
- preempt_disable(); // Needed for PREEMPT_LAZY
+ lockdep_assert_preemption_disabled();

nit: Do we still want to keep the comment that the expectation of preemption being disabled is for the LAZY case?

Good point, and I do believe that we do. Zqiang, any reason not to add this comment back in?

in rcu-tree, this commit:

(935147775c977 "EXP srcu: Enable Tiny SRCU On all CONFIG_SMP=n kernels")

make preempt disable needed for CONFIG_PREEMPT=y or CONFIG_PREEMPT_LAZY=y when the CONFIG_SMP=n. do we need to replace "Needed for PREEMPT_LAZY" comments with "Needed for PREEMPT or PREEMPT_LAZY"?

Quoted 8 lines
Quoted 5 lines

Good point as well, thank you! And I need to decide whether I should send that patch upstream. Its original purpose was to test PREEMPT_LAZY=y better than could be tested with PREEMPT_LAZY.

Thoughts?

I will add "Needed for PREEMPT_LAZY" comments, if this commit (935147775c977) is send to upstream, will update comments again in the future.

That sounds good to me, thank you!

Thanx, Paul

Quoted 40 lines

Thanks
Zqiang

Quoted 37 lines

Thanx, Paul

Quoted 33 lines

Thanks
Zqiang

Thanx, Paul

Quoted 24 lines

thanks,

- Joel

Quoted 17 lines
kernel/rcu/srcutiny.c +0 -2
 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 +193,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();
 }
 
 /*
Signature · 1 line
2.48.1