Skip to contentSkip to conversation

rcuupdate: Do a single rhp->func read in rcu_head_after_call_rcu

PATCH In review Neeraj Upadhyay 2 participants 4 messages Mar 11, 2019 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rcuupdate: Do a single rhp->func read in rcu_head_after_call_rcu

Read rhp->func pointer in rcu_head_after_call_rcu() only once, to avoid warning in the case, where call_rcu() happens between two reads of rhp->func.

---
 include/linux/rcupdate.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
include/linux/rcupdate.h +3 -2
index 6cdb1db..174768e 100644
@@ -878,9 +878,10 @@ static inline void rcu_head_init(struct rcu_head *rhp)
 static inline bool
 rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f)
 {
-	if (READ_ONCE(rhp->func) == f)
+	rcu_callback_t func = READ_ONCE(rhp->func);
+	if (func == f)
 		return true;
-	WARN_ON_ONCE(READ_ONCE(rhp->func) != (rcu_callback_t)~0L);
+	WARN_ON_ONCE(func != (rcu_callback_t)~0L);
 	return false;
 }
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw
Quoted 5 lines · Neeraj Upadhyay

Read rhp->func pointer in rcu_head_after_call_rcu() only once, to avoid warning in the case, where call_rcu() happens between two reads of rhp->func.

This would more gracefully handle racing rcu_head_after_call_rcu() with call_rcu().

But this thing is not yet used, so let's see what Neil Brown says. If he isn't going to use it, my thought is to instead just remove this.

Thanx, Paul

Quoted 25 lines
---
 include/linux/rcupdate.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
include/linux/rcupdate.h +3 -2
index 6cdb1db..174768e 100644
@@ -878,9 +878,10 @@ static inline void rcu_head_init(struct rcu_head *rhp)
 static inline bool
 rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f)
 {
-	if (READ_ONCE(rhp->func) == f)
+	rcu_callback_t func = READ_ONCE(rhp->func);
+	if (func == f)
 		return true;
-	WARN_ON_ONCE(READ_ONCE(rhp->func) != (rcu_callback_t)~0L);
+	WARN_ON_ONCE(func != (rcu_callback_t)~0L);
 	return false;
 }
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation
#2 lore raw
Quoted 7 lines · Paul E. McKenney
Quoted 5 lines · Neeraj Upadhyay

Read rhp->func pointer in rcu_head_after_call_rcu() only once, to avoid warning in the case, where call_rcu() happens between two reads of rhp->func.

Quoted 9 lines

This would more gracefully handle racing rcu_head_after_call_rcu() with call_rcu().

But this thing is not yet used, so let's see what Neil Brown says. If he isn't going to use it, my thought is to instead just remove this.

Thanx, Paul

Agree, makes sense.

Thanks
Neeraj

Quoted 26 lines
Quoted 25 lines
---
  include/linux/rcupdate.h | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
include/linux/rcupdate.h +3 -2
index 6cdb1db..174768e 100644
@@ -878,9 +878,10 @@ static inline void rcu_head_init(struct rcu_head *rhp)
  static inline bool
  rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f)
  {
-	if (READ_ONCE(rhp->func) == f)
+	rcu_callback_t func = READ_ONCE(rhp->func);
+	if (func == f)
  		return true;
-	WARN_ON_ONCE(READ_ONCE(rhp->func) != (rcu_callback_t)~0L);
+	WARN_ON_ONCE(func != (rcu_callback_t)~0L);
  	return false;
  }
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation
#3 lore raw
Quoted 10 lines · Neeraj Upadhyay
Quoted 7 lines · Paul E. McKenney
Quoted 5 lines · Neeraj Upadhyay

Read rhp->func pointer in rcu_head_after_call_rcu() only once, to avoid warning in the case, where call_rcu() happens between two reads of rhp->func.

Quoted 8 lines
Quoted 6 lines

This would more gracefully handle racing rcu_head_after_call_rcu() with call_rcu().

But this thing is not yet used, so let's see what Neil Brown says. If he isn't going to use it, my thought is to instead just remove this.

Agree, makes sense.

And Neil said that he intends to use it, so I applied your patch, updated as shown below. Ah, and please use scripts/checkpatch.pl -- it sometimes gets overly enthusiastic, but the blank line following the declarations is good practice.

Thanx, Paul

------------------------------------------------------------------------

commit fcf4326ee3fb7e0925fe0f299c385c31f5d62fbf

Author: Neeraj Upadhyay <[email protected]>
Date:   Mon Mar 11 17:28:03 2019 +0530

rcu: Do a single rhp->func read in rcu_head_after_call_rcu()

The rcu_head_after_call_rcu() function reads the rhp->func pointer twice, which can result in a false-positive WARN_ON_ONCE() if the callback were passed to call_rcu() between the two reads. Although racing rcu_head_after_call_rcu() with call_rcu() is to be a dubious use case (the return value is not reliable in that case), intermittent and irreproducible warnings are also quite dubious. This commit therefore uses a single READ_ONCE() to pick up the value of rhp->func once, then tests that value twice, thus guaranteeing consistent processing within rcu_head_after_call_rcu()().

Neverthless, racing rcu_head_after_call_rcu() with call_rcu() is still a dubious use case.

[ paulmck: Add blank line after declaration per checkpatch.pl. ]
include/linux/rcupdate.h +4 -2
index 6cdb1db776cf..922bb6848813 100644
@@ -878,9 +878,11 @@ static inline void rcu_head_init(struct rcu_head *rhp)
 static inline bool
 rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f)
 {
-	if (READ_ONCE(rhp->func) == f)
+	rcu_callback_t func = READ_ONCE(rhp->func);
+
+	if (func == f)
 		return true;
-	WARN_ON_ONCE(READ_ONCE(rhp->func) != (rcu_callback_t)~0L);
+	WARN_ON_ONCE(func != (rcu_callback_t)~0L);
 	return false;
 }