rcu: Remove unnecessary READ_ONCE in rcu_preempt_read_enter/exit
PATCH 1/1 rcu: Remove unnecessary READ_ONCE in rcu_preempt_read_enter/exit
The two READ_ONCEs here imply that there might be updater concurrently modifies rcu_read_lock_nesting, although it's true there could be interrupt handlers enter rcu RSCS, but rcu_read_lock_nesting should remain unchanged after they finished. That is, READ_ONCE and then WRITE_ONCE the same variable is not a valid pattern, this patch thus removes the two READ_ONCEs.
--- kernel/rcu/tree_plugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/tree_plugin.h +2 -2
@@ -376,12 +376,12 @@ static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)static void rcu_preempt_read_enter (void ) { -WRITE_ONCE (current->rcu_read_lock_nesting,READ_ONCE (current->rcu_read_lock_nesting) +1 ); +WRITE_ONCE (current->rcu_read_lock_nesting, current->rcu_read_lock_nesting +1 ); }static int rcu_preempt_read_exit (void ) { -int ret =READ_ONCE (current->rcu_read_lock_nesting) -1 ; +int ret = current->rcu_read_lock_nesting -1 ;WRITE_ONCE (current->rcu_read_lock_nesting, ret);return ret;
Signature · 1 line
2.34.1
Paul E. McKenney
maintainerQuoted 6 lines · Alan Huang
The two
READ_ONCEshere imply that there might be updater concurrently modifiesrcu_read_lock_nesting, although it's true there could be interrupt handlers enter rcu RSCS, butrcu_read_lock_nestingshould remain unchanged after they finished. That is,READ_ONCEand thenWRITE_ONCEthe same variable is not a valid pattern, this patch thus removes the twoREAD_ONCEs.
This is true, but I will take the READ_ONCE() calls over the KCSAN complaints. So I must avoid taking this one.
Please note that RCU uses strict KCSAN configuration [1].
Thanx, Paul
[1] https://docs.google.com/document/d/1FwZaXSg3A55ivVoWffA9iMuhJ3_Gmj_E494dLYjjyLQ/edit?usp=sharing
Quoted 28 lines
Signed-off-by Alan Huang <[email protected]>--- kernel/rcu/tree_plugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/tree_plugin.h +2
-2@@ -376,12 +376,12 @@ static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)static void rcu_preempt_read_enter (void ) { -WRITE_ONCE (current->rcu_read_lock_nesting,READ_ONCE (current->rcu_read_lock_nesting) +1 ); +WRITE_ONCE (current->rcu_read_lock_nesting, current->rcu_read_lock_nesting +1 ); }static int rcu_preempt_read_exit (void ) { -int ret =READ_ONCE (current->rcu_read_lock_nesting) -1 ; +int ret = current->rcu_read_lock_nesting -1 ;WRITE_ONCE (current->rcu_read_lock_nesting, ret);return ret;Signature · 1 line
2.34.1