annotate data-races around sysctl_tcp_wmem[0]
Subsystems (4)
cover annotate data-races around sysctl_tcp_wmem[0]
From: Jason Xing <[email protected]>
Adding simple READ_ONCE() can avoid reading the sysctl knob meanwhile someone is trying to change it.
Jason Xing (2):
mptcp: annotate a data-race around sysctl_tcp_wmem[0]
tcp: annotate a data-race around sysctl_tcp_wmem[0]
net/ipv4/tcp.c | 2 +- net/mptcp/protocol.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.37.3
PATCH 1/2 mptcp: annotate a data-race around sysctl_tcp_wmem[0]
From: Jason Xing <[email protected]>
It's possible that writer and the reader can manipulate the same sysctl knob concurrently. Using READ_ONCE() to prevent reading an old value.
--- net/mptcp/protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/protocol.h +1 -1
@@ -850,7 +850,7 @@ static inline void __mptcp_sync_sndbuf(struct sock *sk)if (sk->sk_userlocks &SOCK_SNDBUF_LOCK )return ; - new_sndbuf =sock_net (sk)->ipv4.sysctl_tcp_wmem[0 ]; + new_sndbuf =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_wmem[0 ]);mptcp_for_each_subflow (mptcp_sk (sk), subflow) { ssk_sndbuf =READ_ONCE (mptcp_subflow_tcp_sock (subflow)->sk_sndbuf);
Signature · 1 line
2.37.3
Re: [PATCH net-next 1/2] mptcp: annotate a data-race around sysctl_tcp_wmem[0]
Quoted 8 lines · Jason Xing
From: Jason Xing <[email protected]>
It's possible that writer and the reader can manipulate the same sysctl knob concurrently. Using
READ_ONCE()to prevent reading an old value.Signed-off-by Jason Xing <[email protected]>
Re: [PATCH net-next 1/2] mptcp: annotate a data-race around sysctl_tcp_wmem[0]
In reply to Jason XingQuoted 16 lines · Jason Xing
From: Jason Xing <[email protected]>
It's possible that writer and the reader can manipulate the same sysctl knob concurrently. Using
READ_ONCE()to prevent reading an old value.Signed-off-by Jason Xing <[email protected]>---
net/mptcp/protocol.h| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)net/mptcp/protocol.h +0
-0
net/mptcp/protocol.h static inline void __mptcp_sync_sndbuf(struct sock *sk) · line 856
Quoted 8 lines
net/mptcp/protocol.h +1
-1@@ -850,7 +850,7 @@ static inline void __mptcp_sync_sndbuf(struct sock *sk)if (sk->sk_userlocks &SOCK_SNDBUF_LOCK )return ; - new_sndbuf =sock_net (sk)->ipv4.sysctl_tcp_wmem[0 ]; + new_sndbuf =READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_wmem[0 ]);mptcp_for_each_subflow (mptcp_sk (sk), subflow) { ssk_sndbuf =READ_ONCE (mptcp_subflow_tcp_sock (subflow)->sk_sndbuf);
Looks good to me, thanks Jason.
PATCH 2/2 tcp: annotate a data-race around sysctl_tcp_wmem[0]
In reply to Jason XingFrom: Jason Xing <[email protected]>
When reading wmem[0], it could be changed concurrently without READ_ONCE() protection. So add one annotation here.
--- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -1
@@ -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);
Signature · 1 line
2.37.3
Re: tcp: annotate a data-race around sysctl_tcp_wmem[0]: Tests Results
Hi Jason,
Thank you for your modifications, that's great!
Our CI (GitHub Action) did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8202785775
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/e55bd7ed14f5
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Re: [PATCH net-next 2/2] tcp: annotate a data-race around sysctl_tcp_wmem[0]
In reply to Jason XingQuoted 16 lines · Jason Xing
From: Jason Xing <[email protected]>
When reading wmem[0], it could be changed concurrently without
READ_ONCE()protection. So add one annotation here.Signed-off-by Jason Xing <[email protected]>--- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/tcp.c +0
-0
net/ipv4/tcp.c int tcp_wmem_schedule(struct sock *sk, int copy) · line 978
Quoted 5 lines
net/ipv4/tcp.c +1
-1@@ -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;
SGTM, you could have split the long line...
Re: tcp: annotate a data-race around sysctl_tcp_wmem[0]: Tests Results
In reply to Jason XingHi Jason,
Thank you for your modifications, that's great!
Our CI (Cirrus) did some validations with a debug kernel and here is its report:
- KVM Validation: debug (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5015312026828800
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5015312026828800/summary/summary.txt
- KVM Validation: debug (only selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/6141211933671424
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6141211933671424/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/e55bd7ed14f5
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-debugFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 10 lines · On Fri, 8 Mar 2024 19:25:02 +0800 you wrote:
From: Jason Xing <[email protected]>
Adding simple
READ_ONCE()can avoid reading the sysctl knob meanwhile someone is trying to change it.Jason Xing (2):
mptcp: annotate a data-race around sysctl_tcp_wmem[0]
tcp: annotate a data-race around sysctl_tcp_wmem[0][...]
Here is the summary with links:
- [net-next,1/2] mptcp: annotate a data-race around sysctl_tcp_wmem[0]
https://git.kernel.org/netdev/net-next/c/9eb430d40e44 - [net-next,2/2] tcp: annotate a data-race around sysctl_tcp_wmem[0] https://git.kernel.org/netdev/net-next/c/683a67da9561
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html