Skip to contentSkip to conversation

mptcp: pm: more fixes around the ID 0

PATCH In review Matthieu Baerts (NGI0) 3 participants 8 messages Aug 9, 2024 – Aug 21, 2024

Subsystems (3)
lore
Share & tools
lore

Matthieu Baerts (NGI0)

author maintainer
#0 lore raw

v7 cover mptcp: pm: more fixes around the ID 0

The 8 first patches from the previous version have already been applied.

Last fix: the subflow is not closed when receiving a TCP+FIN, when there are other available subflows.

The last patch is not for -next. Something that sounds better to do.

---
Changes in v7:
- See the individual changelog.
- Link to v6: https://lore.kernel.org/r/[email protected]

---
Matthieu Baerts (NGI0) (3):
mptcp: close subflow when receiving TCP+FIN
selftests: mptcp: join: cannot rm sf if closed
mptcp: pm: send ACK on non stale subflows

 net/mptcp/pm_netlink.c                          | 14 +++++++++++---
 net/mptcp/protocol.c                            |  5 ++++-
 net/mptcp/subflow.c                             |  8 ++++++--
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 11 ++++-------
 4 files changed, 25 insertions(+), 13 deletions(-)

---
base-commit: beede3e0f15d8869512b5b51e580829ab6939f92
change-id: 20240620-mptcp-pm-avail-f5e3957be441

Best regards,

Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
author maintainer
#1 lore raw

PATCH v7 1/3 mptcp: close subflow when receiving TCP+FIN

When a peer decides to close one subflow in the middle of a connection having multiple subflows, the receiver of the first FIN should accept that, and close the subflow on its side as well. If not, the subflow will stay half closed, and would even continue to be used until the end of the MPTCP connection or a reset from the network.

The issue has not been seen before, probably because the in-kernel path-manager always sends a RM_ADDR before closing the subflow. Upon the reception of this RM_ADDR, the other peer will initiate the closure on its side as well. On the other hand, if the RM_ADDR is lost, or if the path-manager of the other peer only closes the subflow without sending a RM_ADDR, the subflow would switch to TCP_CLOSE_WAIT, but that's it, leaving the subflow half-closed.

So now, when the subflow switches to the TCP_CLOSE_WAIT state, and if the MPTCP connection has not been closed before with a DATA_FIN, the kernel owning the subflow schedules its worker to initiate the closure on its side as well.

This issue can be easily reproduced with packetdrill, as visible in [1], by creating an additional subflow, injecting a FIN+ACK before sending the DATA_FIN, and expecting a FIN+ACK in return.

Fixes 40947e13997a ("mptcp: schedule worker when subflow is closed")

---
Notes:
- v7:
- use ssk_state instead of ssk->sk_state. (Mat)

---
 net/mptcp/protocol.c | 5 ++++-
 net/mptcp/subflow.c  | 8 ++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +4 -1
index 13777c35496c..9ad48c798144 100644
@@ -2533,8 +2533,11 @@ static void __mptcp_close_subflow(struct sock *sk)
 
 	mptcp_for_each_subflow_safe(msk, subflow, tmp) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+		int ssk_state = inet_sk_state_load(ssk);
 
-		if (inet_sk_state_load(ssk) != TCP_CLOSE)
+		if (ssk_state != TCP_CLOSE &&
+		    (ssk_state != TCP_CLOSE_WAIT ||
+		     inet_sk_state_load(sk) != TCP_ESTABLISHED))
 			continue;
 
 		/* 'subflow_data_ready' will re-sched once rx queue is empty */
net/mptcp/subflow.c +6 -2
index a7fb4d46e024..723cd3fbba32 100644
@@ -1255,12 +1255,16 @@ static void mptcp_subflow_discard_data(struct sock *ssk, struct sk_buff *skb,
 /* sched mptcp worker to remove the subflow if no more data is pending */
 static void subflow_sched_work_if_closed(struct mptcp_sock *msk, struct sock *ssk)
 {
-	if (likely(ssk->sk_state != TCP_CLOSE))
+	struct sock *sk = (struct sock *)msk;
+
+	if (likely(ssk->sk_state != TCP_CLOSE &&
+		   (ssk->sk_state != TCP_CLOSE_WAIT ||
+		    inet_sk_state_load(sk) != TCP_ESTABLISHED)))
 		return;
 
 	if (skb_queue_empty(&ssk->sk_receive_queue) &&
 	    !test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
-		mptcp_schedule_work((struct sock *)msk);
+		mptcp_schedule_work(sk);
 }
 
 static bool subflow_can_fallback(struct mptcp_subflow_context *subflow)
Signature · 1 line
2.45.2
author maintainer
#2 lore raw

PATCH v7 2/3 selftests: mptcp: join: cannot rm sf if closed

In reply to Matthieu Baerts (NGI0)

Thanks to the previous commit, the MPTCP subflows are now closed on both directions even when only the MPTCP path-manager of one peer asks for their closure.

In the two tests modified here -- "userspace pm add & remove address" and "userspace pm create destroy subflow" -- one peer is controlled by the userspace PM, and the other one by the in-kernel PM. When the userspace PM sends a RM_ADDR notification, the in-kernel PM will automatically react by closing all subflows using this address. Now, thanks to the previous commit, the subflows are properly closed on both directions, the userspace PM can then no longer closes the same subflows if they are already closed. Before, it was OK to do that, because the subflows were still half-opened, still OK to send a RM_ADDR.

In other words, thanks to the previous commit closing the subflows, an error will be returned to the userspace if it tries to close a subflow that has already been closed. So no need to run this command, which mean that the linked counters will then not be incremented.

These tests are then no longer sending both a RM_ADDR, then closing the linked subflow just after. The test with the userspace PM on the server side is now removing one subflow linked to one address, then sending a RM_ADDR for another address. The test with the userspace PM on the client side is now only removing the subflow that was previously created.

Fixes 4369c198e599 ("selftests: mptcp: test userspace pm out of transfer")

---
Notes:
- v7:
- clarify behaviour without the previous patch. (Mat)

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +4 -7
index ea954ba85969..4129952fd9ec 100755
@@ -3408,14 +3408,12 @@ userspace_tests()
 			"signal"
 		userspace_pm_chk_get_addr "${ns1}" "10" "id 10 flags signal 10.0.2.1"
 		userspace_pm_chk_get_addr "${ns1}" "20" "id 20 flags signal 10.0.3.1"
-		userspace_pm_rm_addr $ns1 10
 		userspace_pm_rm_sf $ns1 "::ffff:10.0.2.1" $MPTCP_LIB_EVENT_SUB_ESTABLISHED
 		userspace_pm_chk_dump_addr "${ns1}" \
-			"id 20 flags signal 10.0.3.1" "after rm_addr 10"
+			"id 20 flags signal 10.0.3.1" "after rm_sf 10"
 		userspace_pm_rm_addr $ns1 20
-		userspace_pm_rm_sf $ns1 10.0.3.1 $MPTCP_LIB_EVENT_SUB_ESTABLISHED
 		userspace_pm_chk_dump_addr "${ns1}" "" "after rm_addr 20"
-		chk_rm_nr 2 2 invert
+		chk_rm_nr 1 1 invert
 		chk_mptcp_info subflows 0 subflows 0
 		chk_subflows_total 1 1
 		kill_events_pids
@@ -3439,12 +3437,11 @@ userspace_tests()
 			"id 20 flags subflow 10.0.3.2" \
 			"subflow"
 		userspace_pm_chk_get_addr "${ns2}" "20" "id 20 flags subflow 10.0.3.2"
-		userspace_pm_rm_addr $ns2 20
 		userspace_pm_rm_sf $ns2 10.0.3.2 $MPTCP_LIB_EVENT_SUB_ESTABLISHED
 		userspace_pm_chk_dump_addr "${ns2}" \
 			"" \
-			"after rm_addr 20"
-		chk_rm_nr 1 1
+			"after rm_sf 20"
+		chk_rm_nr 0 1
 		chk_mptcp_info subflows 0 subflows 0
 		chk_subflows_total 1 1
 		kill_events_pids
Signature · 1 line
2.45.2
author maintainer
#3 lore raw

PATCH v7 3/3 mptcp: pm: send ACK on non stale subflows

In reply to Matthieu Baerts (NGI0)

If the subflow is considered as "staled", it is better to avoid it to send an ACK carrying an ADD_ADDR or RM_ADDR. Another subflow, if any, will then be selected.

---
Notes:
- It sounds safer to do this modification in -next. I also wonder if we should not add more check, e.g. not on backup flow except if there are no other non-backup ones, or still pick a staled one if there are no others, etc. But maybe we don't need to care for an ACK? And we can always improve that later!
- v7:
- Include the Squash-to patch. (Mat)

---
 net/mptcp/pm_netlink.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
net/mptcp/pm_netlink.c +11 -3
index d3b1b459e6f3..3bdb0219188f 100644
@@ -762,7 +762,7 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 
 void mptcp_pm_nl_addr_send_ack(struct mptcp_sock *msk)
 {
-	struct mptcp_subflow_context *subflow;
+	struct mptcp_subflow_context *subflow, *alt = NULL;
 
 	msk_owned_by_me(msk);
 	lockdep_assert_held(&msk->pm.lock);
@@ -773,10 +773,18 @@ void mptcp_pm_nl_addr_send_ack(struct mptcp_sock *msk)
 
 	mptcp_for_each_subflow(msk, subflow) {
 		if (__mptcp_subflow_active(subflow)) {
-			mptcp_pm_send_ack(msk, subflow, false, false);
-			break;
+			if (!subflow->stale) {
+				mptcp_pm_send_ack(msk, subflow, false, false);
+				return;
+			}
+
+			if (!alt)
+				alt = subflow;
 		}
 	}
+
+	if (alt)
+		mptcp_pm_send_ack(msk, alt, false, false);
 }
 
 int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,
Signature · 1 line
2.45.2
maintainer
#4 lore raw

Re: [PATCH mptcp-net v7 3/3] mptcp: pm: send ACK on non stale subflows

Quoted 4 lines · On Fri, 9 Aug 2024, Matthieu Baerts (NGI0) wrote:

If the subflow is considered as "staled", it is better to avoid it to send an ACK carrying an ADD_ADDR or RM_ADDR. Another subflow, if any, will then be selected.

Quoted 8 lines

---
Notes:
- It sounds safer to do this modification in -next. I also wonder if we should not add more check, e.g. not on backup flow except if there are no other non-backup ones, or still pick a staled one if there are no others, etc. But maybe we don't need to care for an ACK? And we can always improve that later!

+1 for the -next tree.

I don't think fancier logic is called for, if all subflows are stale a single ACK on a backup subflow (if it happens to be first in the list) does not seem like a problem. If all were stale, for reliability it might make sense to send the ACK on all subflows! For this corner case, I think the current patch is sufficient.

- Mat

#5 lore raw
In reply to Matthieu Baerts (NGI0)

Hi Matthieu,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/10319599535

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

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 v7 series
#6 lore raw
In reply to Matthieu Baerts (NGI0)
Quoted 5 lines · On Fri, 9 Aug 2024, Matthieu Baerts (NGI0) wrote:

The 8 first patches from the previous version have already been applied.

Last fix: the subflow is not closed when receiving a TCP+FIN, when there are other available subflows.

Quoted 8 lines

The last patch is not for -next. Something that sounds better to do.

---
Changes in v7:
- See the individual changelog.
- Link to v6: https://lore.kernel.org/r/[email protected]

Thanks Matthieu, series LGTM (see #3 for responses to your questions there):

Quoted 20 lines

---
Matthieu Baerts (NGI0) (3):
mptcp: close subflow when receiving TCP+FIN
selftests: mptcp: join: cannot rm sf if closed
mptcp: pm: send ACK on non stale subflows

net/mptcp/pm_netlink.c                          | 14 +++++++++++---
net/mptcp/protocol.c                            |  5 ++++-
net/mptcp/subflow.c                             |  8 ++++++--
tools/testing/selftests/net/mptcp/mptcp_join.sh | 11 ++++-------
4 files changed, 25 insertions(+), 13 deletions(-)

---
base-commit: beede3e0f15d8869512b5b51e580829ab6939f92
change-id: 20240620-mptcp-pm-avail-f5e3957be441

Best regards,

Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
author maintainer
#7 lore raw
In reply to Matthieu Baerts (NGI0)

Hi Mat,

Quoted 5 lines · On 09/08/2024 14:37, Matthieu Baerts (NGI0) wrote:

The 8 first patches from the previous version have already been applied.

Last fix: the subflow is not closed when receiving a TCP+FIN, when there are other available subflows.

Quoted 7 lines

The last patch is not for -next. Something that sounds better to do.

---
Changes in v7:
- See the individual changelog.
- Link to v6: https://lore.kernel.org/r/[email protected]

Thank you for the review, and your comment!

Now in our tree:

New patches for t/upstream-net and t/upstream:
- 45e7e7bb1d53: mptcp: close subflow when receiving TCP+FIN
- 4dff13e9b19e: selftests: mptcp: join: cannot rm sf if closed
- Results: 479b0f0c640c..c025238d573a (export-net)
- Results: a6b7b898cddd..8d90262870c8 (export)

New patches for t/upstream:
- cee0b5912a36: mptcp: pm: send ACK on non stale subflows
- Results: 8d90262870c8..a2eeb886f736 (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/e9099bcf17a9d3c1b60dddc620e47c4307b8bb99/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/2c2279cec7af565f971bfe2805b325af05cc6039/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/133016fd5500a67dd98db80bf60e300367431966/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.