Skip to content

Commit

Permalink
net: lockless implementation of SO_TXREHASH
Browse files Browse the repository at this point in the history
sk->sk_txrehash readers are already safe against
concurrent change of this field.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Oct 1, 2023
1 parent 28b24f9 commit 5eef0b8
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,16 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
WRITE_ONCE(sk->sk_pacing_rate, ulval);
return 0;
}
case SO_TXREHASH:
if (val < -1 || val > 1)
return -EINVAL;
if ((u8)val == SOCK_TXREHASH_DEFAULT)
val = READ_ONCE(sock_net(sk)->core.sysctl_txrehash);
/* Paired with READ_ONCE() in tcp_rtx_synack()
* and sk_getsockopt().
*/
WRITE_ONCE(sk->sk_txrehash, (u8)val);
return 0;
}

sockopt_lock_sock(sk);
Expand Down Expand Up @@ -1528,19 +1538,6 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
break;
}

case SO_TXREHASH:
if (val < -1 || val > 1) {
ret = -EINVAL;
break;
}
if ((u8)val == SOCK_TXREHASH_DEFAULT)
val = READ_ONCE(sock_net(sk)->core.sysctl_txrehash);
/* Paired with READ_ONCE() in tcp_rtx_synack()
* and sk_getsockopt().
*/
WRITE_ONCE(sk->sk_txrehash, (u8)val);
break;

default:
ret = -ENOPROTOOPT;
break;
Expand Down

0 comments on commit 5eef0b8

Please sign in to comment.