Skip to contentSkip to conversation

rcu: Add sparse check for RCU_INIT_POINTER()

RFC PATCH In review Pranith Kumar 2 participants 3 messages Sep 25, 2014 RCU

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 rcu: Add sparse check for RCU_INIT_POINTER()

Add a sparse check when RCU_INIT_POINTER() is used to assign a non __rcu annotated pointer.

---
 include/linux/rcupdate.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/rcupdate.h +1 -0
index a4a819f..a033d8b 100644
@@ -1047,6 +1047,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
  */
 #define RCU_INIT_POINTER(p, v) \
 	do { \
+		rcu_dereference_sparse(p, __rcu); \
 		p = RCU_INITIALIZER(v); \
 	} while (0)
 
Signature · 1 line
2.1.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Pranith Kumar

Add a sparse check when RCU_INIT_POINTER() is used to assign a non __rcu annotated pointer.

Have you checked if this introduces a significant number of new warnings in the kernel?

If not:

Quoted 18 lines
 include/linux/rcupdate.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/rcupdate.h +1 -0
index a4a819f..a033d8b 100644
@@ -1047,6 +1047,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
  */
 #define RCU_INIT_POINTER(p, v) \
 	do { \
+		rcu_dereference_sparse(p, __rcu); \
 		p = RCU_INITIALIZER(v); \
 	} while (0)
 
Signature · 1 line
2.1.0
#2 lore raw
Quoted 4 lines · On Thu, Sep 25, 2014 at 2:10 PM, <[email protected]> wrote:
Quoted 3 lines · Pranith Kumar

Add a sparse check when RCU_INIT_POINTER() is used to assign a non __rcu annotated pointer.

Quoted 8 lines
Quoted 1 line

Have you checked if this introduces a significant number of new warnings in the kernel?

If not:

I tested the above patch on a small test case where we are assigning to a non __rcu annotated pointer and sparse does warn in that case.

I tried doing that and there were too many address space warnings (maybe?) not related to __rcu annotation.

May be a diff of previous warnings and later warnings should show up if any new warnings are being generated...

diff before.log after.log

Quoted 1 line

drivers/md/dm.c:2239:9: error: incompatible types in comparison expression (different address spaces)

Looking at this it shows that RCU_INIT_POINTER() is being used on a non __rcu pointer. I will send in a patch fixing that.

Thanks!

Signature · 1 line
Pranith