Skip to content

Commit fe11fdc

Browse files
edumazetdavem330
authored andcommitted
net: annotate data-races around sk->sk_reserved_mem
sk_getsockopt() runs locklessly. This means sk->sk_reserved_mem can be read while other threads are changing its value. Add missing annotations where they are needed. Fixes: 2bb2f5f ("net: add new socket option SO_RESERVE_MEM") Signed-off-by: Eric Dumazet <[email protected]> Cc: Wei Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7938cd1 commit fe11fdc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

net/core/sock.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ static void sock_release_reserved_memory(struct sock *sk, int bytes)
10071007
bytes = round_down(bytes, PAGE_SIZE);
10081008

10091009
WARN_ON(bytes > sk->sk_reserved_mem);
1010-
sk->sk_reserved_mem -= bytes;
1010+
WRITE_ONCE(sk->sk_reserved_mem, sk->sk_reserved_mem - bytes);
10111011
sk_mem_reclaim(sk);
10121012
}
10131013

@@ -1044,7 +1044,8 @@ static int sock_reserve_memory(struct sock *sk, int bytes)
10441044
}
10451045
sk->sk_forward_alloc += pages << PAGE_SHIFT;
10461046

1047-
sk->sk_reserved_mem += pages << PAGE_SHIFT;
1047+
WRITE_ONCE(sk->sk_reserved_mem,
1048+
sk->sk_reserved_mem + (pages << PAGE_SHIFT));
10481049

10491050
return 0;
10501051
}
@@ -1973,7 +1974,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
19731974
break;
19741975

19751976
case SO_RESERVE_MEM:
1976-
v.val = sk->sk_reserved_mem;
1977+
v.val = READ_ONCE(sk->sk_reserved_mem);
19771978
break;
19781979

19791980
case SO_TXREHASH:

0 commit comments

Comments
 (0)