net: annotate data-races around sk->sk_reserved_mem

[ Upstream commit fe11fdcb42 ]

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: 2bb2f5fb21 ("net: add new socket option SO_RESERVE_MEM")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Wei Wang <weiwan@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Eric Dumazet 2023-07-28 15:03:08 +00:00 committed by Greg Kroah-Hartman
parent 9da9ea9b13
commit 60d92bc9c0
1 changed files with 4 additions and 3 deletions

View File

@ -996,7 +996,7 @@ static void sock_release_reserved_memory(struct sock *sk, int bytes)
bytes = round_down(bytes, PAGE_SIZE);
WARN_ON(bytes > sk->sk_reserved_mem);
sk->sk_reserved_mem -= bytes;
WRITE_ONCE(sk->sk_reserved_mem, sk->sk_reserved_mem - bytes);
sk_mem_reclaim(sk);
}
@ -1033,7 +1033,8 @@ static int sock_reserve_memory(struct sock *sk, int bytes)
}
sk->sk_forward_alloc += pages << PAGE_SHIFT;
sk->sk_reserved_mem += pages << PAGE_SHIFT;
WRITE_ONCE(sk->sk_reserved_mem,
sk->sk_reserved_mem + (pages << PAGE_SHIFT));
return 0;
}
@ -1922,7 +1923,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
break;
case SO_RESERVE_MEM:
v.val = sk->sk_reserved_mem;
v.val = READ_ONCE(sk->sk_reserved_mem);
break;
case SO_TXREHASH: