Re: [PATCH net/tipc] Replace rcu_swap_protected() with rcu_replace_pointer()

From: Paul E. McKenney
Date: Tue Dec 10 2019 - 17:38:32 EST


On Tue, Dec 10, 2019 at 10:36:59PM +0800, Ying Xue wrote:
> On 12/10/19 11:31 AM, Paul E. McKenney wrote:
> > This commit replaces the use of rcu_swap_protected() with the more
> > intuitively appealing rcu_replace_pointer() as a step towards removing
> > rcu_swap_protected().
> >
> > Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@xxxxxxxxxxxxxx/
> > Reported-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> > Reported-by: kbuild test robot <lkp@xxxxxxxxx>
> > Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
> > Cc: Jon Maloy <jon.maloy@xxxxxxxxxxxx>
> > Cc: Ying Xue <ying.xue@xxxxxxxxxxxxx>
> > Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
> > Cc: <netdev@xxxxxxxxxxxxxxx>
> > Cc: <tipc-discussion@xxxxxxxxxxxxxxxxxxxxx>
> >
> > diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> > index 990a872..64cf831 100644
> > --- a/net/tipc/crypto.c
> > +++ b/net/tipc/crypto.c
> > @@ -258,7 +258,7 @@ static char *tipc_key_change_dump(struct tipc_key old, struct tipc_key new,
> > rcu_dereference_protected((rcu_ptr), lockdep_is_held(lock))
> >
> > #define tipc_aead_rcu_swap(rcu_ptr, ptr, lock) \
> > - rcu_swap_protected((rcu_ptr), (ptr), lockdep_is_held(lock))
> > + rcu_replace_pointer((rcu_ptr), (ptr), lockdep_is_held(lock))
>
> (ptr) = rcu_replace_pointer((rcu_ptr), (ptr), lockdep_is_held(lock))
>
> >
> > #define tipc_aead_rcu_replace(rcu_ptr, ptr, lock) \
> > do { \
> > @@ -1189,7 +1189,7 @@ static bool tipc_crypto_key_try_align(struct tipc_crypto *rx, u8 new_pending)
> >
> > /* Move passive key if any */
> > if (key.passive) {
> > - tipc_aead_rcu_swap(rx->aead[key.passive], tmp2, &rx->lock);
> > + tmp2 = rcu_replace_pointer(rx->aead[key.passive], tmp2, &rx->lock);
>
> tipc_aead_rcu_swap() is only called here in TIPC module. If we use
> rcu_replace_pointer() to switch pointers instead of calling
> tipc_aead_rcu_swap() macro, I think we should completely remove
> tipc_aead_rcu_swap().

Good catch, thank you! How about the following instead?

Thanx, Paul

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

commit 4ee8e2c68b076867b7a5af82a38010fffcab611c
Author: Paul E. McKenney <paulmck@xxxxxxxxxx>
Date: Mon Dec 9 19:13:45 2019 -0800

net/tipc: Replace rcu_swap_protected() with rcu_replace_pointer()

This commit replaces the use of rcu_swap_protected() with the more
intuitively appealing rcu_replace_pointer() as a step towards removing
rcu_swap_protected().

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@xxxxxxxxxxxxxx/
Reported-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Reported-by: kbuild test robot <lkp@xxxxxxxxx>
Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
Cc: Jon Maloy <jon.maloy@xxxxxxxxxxxx>
Cc: Ying Xue <ying.xue@xxxxxxxxxxxxx>
Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
Cc: <netdev@xxxxxxxxxxxxxxx>
Cc: <tipc-discussion@xxxxxxxxxxxxxxxxxxxxx>

diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index 990a872..978d2db 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -257,9 +257,6 @@ static char *tipc_key_change_dump(struct tipc_key old, struct tipc_key new,
#define tipc_aead_rcu_ptr(rcu_ptr, lock) \
rcu_dereference_protected((rcu_ptr), lockdep_is_held(lock))

-#define tipc_aead_rcu_swap(rcu_ptr, ptr, lock) \
- rcu_swap_protected((rcu_ptr), (ptr), lockdep_is_held(lock))
-
#define tipc_aead_rcu_replace(rcu_ptr, ptr, lock) \
do { \
typeof(rcu_ptr) __tmp = rcu_dereference_protected((rcu_ptr), \
@@ -1189,7 +1186,7 @@ static bool tipc_crypto_key_try_align(struct tipc_crypto *rx, u8 new_pending)

/* Move passive key if any */
if (key.passive) {
- tipc_aead_rcu_swap(rx->aead[key.passive], tmp2, &rx->lock);
+ tmp2 = rcu_replace_pointer(rx->aead[key.passive], tmp2, &rx->lock);
x = (key.passive - key.pending + new_pending) % KEY_MAX;
new_passive = (x <= 0) ? x + KEY_MAX : x;
}