Skip to content

Commit 7c68fa2

Browse files
edumazetdavem330
authored andcommitted
net: annotate lockless accesses to sk->sk_pacing_shift
sk->sk_pacing_shift can be read and written without lock synchronization. This patch adds annotations to document this fact and avoid future syzbot complains. This might also avoid unexpected false sharing in sk_pacing_shift_update(), as the compiler could remove the conditional check and always write over sk->sk_pacing_shift : if (sk->sk_pacing_shift != val) sk->sk_pacing_shift = val; Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cad4603 commit 7c68fa2

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

include/net/sock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,9 +2588,9 @@ static inline int sk_get_rmem0(const struct sock *sk, const struct proto *proto)
25882588
*/
25892589
static inline void sk_pacing_shift_update(struct sock *sk, int val)
25902590
{
2591-
if (!sk || !sk_fullsock(sk) || sk->sk_pacing_shift == val)
2591+
if (!sk || !sk_fullsock(sk) || READ_ONCE(sk->sk_pacing_shift) == val)
25922592
return;
2593-
sk->sk_pacing_shift = val;
2593+
WRITE_ONCE(sk->sk_pacing_shift, val);
25942594
}
25952595

25962596
/* if a socket is bound to a device, check that the given device

net/core/sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
29162916

29172917
sk->sk_max_pacing_rate = ~0UL;
29182918
sk->sk_pacing_rate = ~0UL;
2919-
sk->sk_pacing_shift = 10;
2919+
WRITE_ONCE(sk->sk_pacing_shift, 10);
29202920
sk->sk_incoming_cpu = -1;
29212921

29222922
sk_rx_queue_clear(sk);

net/ipv4/tcp_bbr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ static u32 bbr_tso_segs_goal(struct sock *sk)
306306
/* Sort of tcp_tso_autosize() but ignoring
307307
* driver provided sk_gso_max_size.
308308
*/
309-
bytes = min_t(unsigned long, sk->sk_pacing_rate >> sk->sk_pacing_shift,
309+
bytes = min_t(unsigned long,
310+
sk->sk_pacing_rate >> READ_ONCE(sk->sk_pacing_shift),
310311
GSO_MAX_SIZE - 1 - MAX_TCP_HEADER);
311312
segs = max_t(u32, bytes / tp->mss_cache, bbr_min_tso_segs(sk));
312313

net/ipv4/tcp_output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ static u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now,
17251725
u32 bytes, segs;
17261726

17271727
bytes = min_t(unsigned long,
1728-
sk->sk_pacing_rate >> sk->sk_pacing_shift,
1728+
sk->sk_pacing_rate >> READ_ONCE(sk->sk_pacing_shift),
17291729
sk->sk_gso_max_size - 1 - MAX_TCP_HEADER);
17301730

17311731
/* Goal is to send at least one packet per ms,
@@ -2260,7 +2260,7 @@ static bool tcp_small_queue_check(struct sock *sk, const struct sk_buff *skb,
22602260

22612261
limit = max_t(unsigned long,
22622262
2 * skb->truesize,
2263-
sk->sk_pacing_rate >> sk->sk_pacing_shift);
2263+
sk->sk_pacing_rate >> READ_ONCE(sk->sk_pacing_shift));
22642264
if (sk->sk_pacing_status == SK_PACING_NONE)
22652265
limit = min_t(unsigned long, limit,
22662266
sock_net(sk)->ipv4.sysctl_tcp_limit_output_bytes);

0 commit comments

Comments
 (0)