Skip to contentSkip to conversation

mptcp: sync the msk->sndbuf at accept() time

PATCH In review Gang Yan 3 participants 6 messages Apr 11 – Apr 17

Subsystems (3)
lore
Share & tools
lore

Gang Yan

author
#0 lore raw

v4 cover mptcp: sync the msk->sndbuf at accept() time

From: Gang Yan <[email protected]>

Changelog:
v4:
- Update the coomit log to show the root cause.
- Remove the '__mptcp_propagate_sndbuf' in 'mptcp_sk_clone_init' according to Paolo's advice.
- Replace 'grep' with 'sed' according to AI's suggestions.
- Crete a packetdrill PR for test:
https://github.com/multipath-tcp/packetdrill/pull/193
v3:
- Add a check in diag.sh to check the sndbuf of the server side.

Gang Yan (2):
mptcp: sync the msk->sndbuf at accept() time
selftests: mptcp: add a check for sndbuf of S/C

 net/mptcp/protocol.c                      |  2 +-
 tools/testing/selftests/net/mptcp/diag.sh | 28 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v4 1/2 mptcp: sync the msk->sndbuf at accept() time

From: Gang Yan <[email protected]>

On passive MPTCP connections, the msk sndbuf is not updated correctly.

The root cause is a timing issue in the accept path:
- tcp_check_req() -> subflow_syn_recv_sock() -> mptcp_sk_clone_init() calls __mptcp_propagate_sndbuf() to copy the ssk sndbuf into msk
- Later, tcp_child_process() -> tcp_init_transfer() -> tcp_sndbuf_expand() grows the ssk sndbuf.

So __mptcp_propagate_sndbuf() runs before the ssk sndbuf has been expanded and the msk ends up with a much smaller sndbuf than the subflow:
MPTCP: msk->sndbuf:20480, msk->first->sndbuf:2626560

Fix this by removing the __mptcp_propagate_sndbuf() call in mptcp_sk_clone_init(), as the ssk sndbuf is not yet finalized there. Instead, call __mptcp_propagate_sndbuf() at accept() time, when the ssk sndbuf has been fully expanded by tcp_sndbuf_expand().

Fixes 8005184fd1ca ("mptcp: refactor sndbuf auto-tuning")
---
 net/mptcp/protocol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/protocol.c +1 -1
index 17b9a8c13ebf..6b486fc94c16 100644
@@ -3594,7 +3594,6 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
 	 * uses the correct data
 	 */
 	mptcp_copy_inaddrs(nsk, ssk);
-	__mptcp_propagate_sndbuf(nsk, ssk);
 
 	mptcp_rcv_space_init(msk, ssk);
 	msk->rcvq_space.time = mptcp_stamp();
@@ -4252,6 +4251,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
 
 		mptcp_graft_subflows(newsk);
 		mptcp_rps_record_subflows(msk);
+		__mptcp_propagate_sndbuf(newsk, mptcp_subflow_tcp_sock(subflow));
 
 		/* Do late cleanup for the first subflow as necessary. Also
 		 * deal with bad peers not doing a complete shutdown.
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v4 2/2 selftests: mptcp: add a check for sndbuf of S/C

In reply to Gang Yan

From: Gang Yan <[email protected]>

Add a new chk_sndbuf() helper to diag.sh that extracts the sndbuf (the 'tb' field from 'ss -m' skmem output) for both server and client MPTCP sockets, and verifies they are equal.

Without the previous patch, it will fail:

'''
07 ....chk sndbuf server/client [FAIL] sndbuf S=20480 != C=2630656
'''

---
 tools/testing/selftests/net/mptcp/diag.sh | 28 +++++++++++++++++++++++
 1 file changed, 28 insertions(+)
tools/testing/selftests/net/mptcp/diag.sh +28 -0
index d847ff1737c3..27cbda68144e 100755
@@ -322,6 +322,33 @@ wait_connected()
 	done
 }
 
+chk_sndbuf()
+{
+	local server_sndbuf client_sndbuf msg
+	local port=${1}
+
+	msg="....chk sndbuf server/client"
+	server_sndbuf=$(ss -N "${ns}" -inmHM "sport" "${port}" | \
+			sed -n 's/.*tb\([0-9]\+\).*/\1/p')
+	client_sndbuf=$(ss -N "${ns}" -inmHM "dport" "${port}" | \
+			sed -n 's/.*tb\([0-9]\+\).*/\1/p')
+
+	mptcp_lib_print_title "${msg}"
+	if [ -z "${server_sndbuf}" ] || [ -z "${client_sndbuf}" ]; then
+		mptcp_lib_pr_fail "sndbuf S=${server_sndbuf} C=${client_sndbuf}"
+		mptcp_lib_result_fail "${msg}"
+		ret=${KSFT_FAIL}
+	elif [ "${server_sndbuf}" != "${client_sndbuf}" ]; then
+		mptcp_lib_pr_fail "sndbuf S=${server_sndbuf} != C=${client_sndbuf}"
+		mptcp_lib_result_fail "${msg}"
+		ret=${KSFT_FAIL}
+	else
+		mptcp_lib_pr_ok
+		mptcp_lib_result_pass "${msg}"
+	fi
+}
+
+
 trap cleanup EXIT
 mptcp_lib_ns_init ns
 
@@ -341,6 +368,7 @@ echo "b" | \
 				127.0.0.1 >/dev/null &
 wait_connected $ns 10000
 chk_msk_nr 2 "after MPC handshake"
+chk_sndbuf 10000
 chk_last_time_info 10000
 chk_msk_remote_key_nr 2 "....chk remote_key"
 chk_msk_fallback_nr 0 "....chk no fallback"
Signature · 1 line
2.43.0
#3 lore raw
In reply to Gang Yan

Hi Gang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_mp_reset ⚠️
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/24274365063

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/414e68b0e64e
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1080031

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-normal

For 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)

maintainer Reviewed-by on the v4 series
#4 lore raw
In reply to Gang Yan

Hi Gang,

Quoted 10 lines · Gang Yan

From: Gang Yan <[email protected]>

Changelog:
v4:
- Update the coomit log to show the root cause.
- Remove the '__mptcp_propagate_sndbuf' in 'mptcp_sk_clone_init' according to Paolo's advice.
- Replace 'grep' with 'sed' according to AI's suggestions.
- Crete a packetdrill PR for test:
https://github.com/multipath-tcp/packetdrill/pull/193

Thank you for the new version and the new packetdrill test. It looks good to me.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#5 lore raw
In reply to Gang Yan

Hi Gang,

Quoted 10 lines · Gang Yan

From: Gang Yan <[email protected]>

Changelog:
v4:
- Update the coomit log to show the root cause.
- Remove the '__mptcp_propagate_sndbuf' in 'mptcp_sk_clone_init' according to Paolo's advice.
- Replace 'grep' with 'sed' according to AI's suggestions.
- Crete a packetdrill PR for test:
https://github.com/multipath-tcp/packetdrill/pull/193

Thank you for these patches. Now in our tree:

New patches for t/upstream-net and t/upstream:
- 3fb2d76a499a: mptcp: sync the msk->sndbuf at accept() time
- a30244625bec: selftests: mptcp: add a check for sndbuf of S/C
- Results: 04a2a52011ad..46cef22df2cd (export-net)
- Results: f4ace5138b04..bbaa3169f0ab (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/c654c5c9b558ff5c29ceb069e91a2a23f9aadce4/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/b587e221edde5e92c4aed7fd8c58f258ee164de1/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.