netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Xing <kerneljasonxing@gmail.com>
To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org,
	martineau@kernel.org, geliang@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, davem@davemloft.net
Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org,
	kerneljasonxing@gmail.com, Jason Xing <kernelxing@tencent.com>
Subject: [PATCH net-next 2/2] tcp: annotate a data-race around sysctl_tcp_wmem[0]
Date: Fri,  8 Mar 2024 19:25:04 +0800	[thread overview]
Message-ID: <20240308112504.29099-3-kerneljasonxing@gmail.com> (raw)
In-Reply-To: <20240308112504.29099-1-kerneljasonxing@gmail.com>

From: Jason Xing <kernelxing@tencent.com>

When reading wmem[0], it could be changed concurrently without
READ_ONCE() protection. So add one annotation here.

Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index c5b83875411a..e3904c006e63 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -975,7 +975,7 @@ int tcp_wmem_schedule(struct sock *sk, int copy)
 	 * Use whatever is left in sk->sk_forward_alloc and tcp_wmem[0]
 	 * to guarantee some progress.
 	 */
-	left = sock_net(sk)->ipv4.sysctl_tcp_wmem[0] - sk->sk_wmem_queued;
+	left = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[0]) - sk->sk_wmem_queued;
 	if (left > 0)
 		sk_forced_mem_schedule(sk, min(left, copy));
 	return min(copy, sk->sk_forward_alloc);
-- 
2.37.3


  parent reply	other threads:[~2024-03-08 11:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 11:25 [PATCH net-next 0/2] annotate data-races around sysctl_tcp_wmem[0] Jason Xing
2024-03-08 11:25 ` [PATCH net-next 1/2] mptcp: annotate a data-race " Jason Xing
2024-03-08 12:54   ` Eric Dumazet
2024-03-08 20:26   ` Mat Martineau
2024-03-08 11:25 ` Jason Xing [this message]
2024-03-08 12:51   ` [PATCH net-next 2/2] tcp: " Eric Dumazet
2024-03-11 19:39 ` [PATCH net-next 0/2] annotate data-races " patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240308112504.29099-3-kerneljasonxing@gmail.com \
    --to=kerneljasonxing@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=geliang@kernel.org \
    --cc=kernelxing@tencent.com \
    --cc=kuba@kernel.org \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).