Skip to contentSkip to conversation

mptcp: multiple xmit substreams support

RFC PATCH In review Paolo Abeni 2 participants 32 messages Jul 31, 2020 – Aug 4, 2020

Subsystems (3)
lore
Share & tools
lore

Paolo Abeni

author
#0 lore raw

cover mptcp: multiple xmit substreams support

This is an early RFC to gather feedback and comments on the current status.

Needs the bugfix patch I sent before to avoid exploding badly on the first packet - can still explode after a few ones.

It refactor send space notifications, introduces OoO handling via RBtree, sndbuf autotuning, allows the PM to create non backup subflows and finally a basic scheduler and some self-tests.

The pain point is the in-window check:

on the receiver side msk rcv window is set at tcp_space(msk) - which should be a quite rough over-estimante of a more correct value.

on the sender side no limit is imposed on the xmitted sequence number, except the one given by the sndbuf. The msk sndbuf is autotuned to the subflows largest sndbuf size.

With all the above I observe several out of [MPTCP] window on the RX side, to the point that if affects the bandwidth (self-tests fail, as they basically looks at virtual link utilization).

Any comment more than welcome, especially about better mptcp window checks.

This has been quite painful, so I would propose to consider accepting on export branch even a suboptimal version and then improve incrementally.

Paolo Abeni (12):
mptcp: msk is writable according to msk write space
mptcp: set data_ready status bit in subflow_check_data_avail()
mptcp: trigger msk processing even for OoO data
mptcp: basic sndbuf autotuning
mptcp: introduce and use mptcp_try_coalesce()
mptcp: move ooo skbs into msk out of order queue.
mptcp: cleanup mptcp_subflow_discard_data()
mptcp: add OoO related mibs
mptcp: move address attribute into mptcp_addr_info
mptcp: allow creating non-backup subflows
mptcp: allow picking different xmit subflows
mptcp: simult flow self-tests

 net/mptcp/mib.c                               |   5 +
 net/mptcp/mib.h                               |   5 +
 net/mptcp/pm_netlink.c                        |  38 +-
 net/mptcp/protocol.c                          | 459 ++++++++++++++----
 net/mptcp/protocol.h                          |  18 +-
 net/mptcp/subflow.c                           |  91 ++--
 .../selftests/net/mptcp/simult_flows.sh       | 290 +++++++++++
 7 files changed, 743 insertions(+), 163 deletions(-)
 create mode 100755 tools/testing/selftests/net/mptcp/simult_flows.sh
Signature · 1 line
2.26.2
author
#1 lore raw

RFC PATCH 1/12 mptcp: msk is writable according to msk write space

Currently, when checking for the 'msk is writable' condition, we look at the individual subflows write space. That works well while we sends data via a single subflow, but will not as soon as we will enable concurrent xmit on multiple subflows.

Let's use the msk write space instead.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 42 ++++++++++++++++++++++++------------------
 net/mptcp/subflow.c  |  3 +--
 2 files changed, 25 insertions(+), 20 deletions(-)
net/mptcp/protocol.c +24 -18
index 3b9ae98c67bb..d51b1d95dfb8 100644
@@ -612,8 +612,15 @@ static void mptcp_clean_una(struct sock *sk)
 		sk_mem_reclaim_partial(sk);
 
 		/* Only wake up writers if a subflow is ready */
-		if (test_bit(MPTCP_SEND_SPACE, &msk->flags))
+		if (sk_stream_is_writeable(sk)) {
+			set_bit(MPTCP_SEND_SPACE, &mptcp_sk(sk)->flags);
+			smp_mb__after_atomic();
+
+			/* set SEND_SPACE before sk_stream_write_space clears
+			 * NOSPACE
+			 */
 			sk_stream_write_space(sk);
+		}
 	}
 }
 
@@ -799,21 +806,27 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	return ret;
 }
 
-static void mptcp_nospace(struct mptcp_sock *msk, struct socket *sock)
+static void mptcp_nospace(struct sock *sk, struct sock *ssk)
 {
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct socket *sock;
+
 	clear_bit(MPTCP_SEND_SPACE, &msk->flags);
 	smp_mb__after_atomic(); /* msk->flags is changed by write_space cb */
 
 	/* enables sk->write_space() callbacks */
-	set_bit(SOCK_NOSPACE, &sock->flags);
+	sock = READ_ONCE(ssk->sk_socket);
+	if (sock)
+		set_bit(SOCK_NOSPACE, &sock->flags);
 }
 
 static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
 {
 	struct mptcp_subflow_context *subflow;
+	struct sock *sk = (struct sock *)msk;
 	struct sock *backup = NULL;
 
-	sock_owned_by_me((const struct sock *)msk);
+	sock_owned_by_me(sk);
 
 	if (!mptcp_ext_cache_refill(msk))
 		return NULL;
@@ -821,12 +834,8 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 
-		if (!sk_stream_memory_free(ssk)) {
-			struct socket *sock = ssk->sk_socket;
-
-			if (sock)
-				mptcp_nospace(msk, sock);
-
+		if (!sk_stream_memory_free(sk)) {
+			mptcp_nospace(sk, ssk);
 			return NULL;
 		}
 
@@ -843,16 +852,12 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
 	return backup;
 }
 
-static void ssk_check_wmem(struct mptcp_sock *msk, struct sock *ssk)
+static void ssk_check_wmem(struct sock *sk, struct sock *ssk)
 {
-	struct socket *sock;
-
-	if (likely(sk_stream_is_writeable(ssk)))
+	if (likely(sk_stream_is_writeable(sk)))
 		return;
 
-	sock = READ_ONCE(ssk->sk_socket);
-	if (sock)
-		mptcp_nospace(msk, sock);
+	mptcp_nospace(sk, ssk);
 }
 
 static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
@@ -976,6 +981,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 				 * Wakeup will happen via mptcp_clean_una().
 				 */
 				mptcp_set_timeout(sk, ssk);
+				mptcp_nospace(sk, ssk);
 				release_sock(ssk);
 				goto wait_for_sndbuf;
 			}
@@ -992,7 +998,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 			mptcp_reset_timer(sk);
 	}
 
-	ssk_check_wmem(msk, ssk);
+	ssk_check_wmem(sk, ssk);
 	release_sock(ssk);
 out:
 	release_sock(sk);
net/mptcp/subflow.c +1 -2
index 7e838bc6e364..bd2201d62ae6 100644
@@ -926,8 +926,7 @@ static void subflow_write_space(struct sock *sk)
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct sock *parent = subflow->conn;
 
-	sk_stream_write_space(sk);
-	if (sk_stream_is_writeable(sk)) {
+	if (sk_stream_is_writeable(parent)) {
 		set_bit(MPTCP_SEND_SPACE, &mptcp_sk(parent)->flags);
 		smp_mb__after_atomic();
 		/* set SEND_SPACE before sk_stream_write_space clears NOSPACE */
Signature · 1 line
2.26.2
author
#4 lore raw

RFC PATCH 2/12 mptcp: set data_ready status bit in subflow_check_data_avail()

In reply to Paolo Abeni

This simplify mptcp_subflow_data_available() and will made follow-up patches simpler.

Additionally remove the unneeded checks on subflow copied_seq:
we always whole skbs out of subflows.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

---
 net/mptcp/subflow.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
net/mptcp/subflow.c +8 -11
index bd2201d62ae6..54d89f9379e1 100644
@@ -755,6 +755,8 @@ static bool subflow_check_data_avail(struct sock *ssk)
 
 	pr_debug("msk=%p ssk=%p data_avail=%d skb=%p", subflow->conn, ssk,
 		 subflow->data_avail, skb_peek(&ssk->sk_receive_queue));
+	if (!skb_peek(&ssk->sk_receive_queue))
+		subflow->data_avail = 0;
 	if (subflow->data_avail)
 		return true;
 
@@ -779,6 +781,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
 			subflow->map_data_len = skb->len;
 			subflow->map_subflow_seq = tcp_sk(ssk)->copied_seq -
 						   subflow->ssn_offset;
+			subflow->data_avail = 1;
 			return true;
 		}
 
@@ -806,8 +809,10 @@ static bool subflow_check_data_avail(struct sock *ssk)
 		ack_seq = mptcp_subflow_get_mapped_dsn(subflow);
 		pr_debug("msk ack_seq=%llx subflow ack_seq=%llx", old_ack,
 			 ack_seq);
-		if (ack_seq == old_ack)
+		if (ack_seq == old_ack) {
+			subflow->data_avail = 1;
 			break;
+		}
 
 		/* only accept in-sequence mapping. Old values are spurious
 		 * retransmission; we can hit "future" values on active backup
@@ -852,13 +857,13 @@ static bool subflow_check_data_avail(struct sock *ssk)
 	ssk->sk_error_report(ssk);
 	tcp_set_state(ssk, TCP_CLOSE);
 	tcp_send_active_reset(ssk, GFP_ATOMIC);
+	subflow->data_avail = 0;
 	return false;
 }
 
 bool mptcp_subflow_data_available(struct sock *sk)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
-	struct sk_buff *skb;
 
 	/* check if current mapping is still valid */
 	if (subflow->map_valid &&
@@ -871,15 +876,7 @@ bool mptcp_subflow_data_available(struct sock *sk)
 			 subflow->map_data_len);
 	}
 
-	if (!subflow_check_data_avail(sk)) {
-		subflow->data_avail = 0;
-		return false;
-	}
-
-	skb = skb_peek(&sk->sk_receive_queue);
-	subflow->data_avail = skb &&
-		       before(tcp_sk(sk)->copied_seq, TCP_SKB_CB(skb)->end_seq);
-	return subflow->data_avail;
+	return subflow_check_data_avail(sk);
 }
 
 /* If ssk has an mptcp parent socket, use the mptcp rcvbuf occupancy,
Signature · 1 line
2.26.2
author
#5 lore raw

RFC PATCH 3/12 mptcp: trigger msk processing even for OoO data

In reply to Paolo Abeni

This is a pre requiste to allow receiving data from multiple subflows without re-injection.

Instead of dropping the OoO - "future" data in subflow_check_data_avail(), call into __mptcp_move_skbs() and let the msk drop that.

To avoid code duplication factor out the mptcp_subflow_discard_data() helper.

Note that __mptcp_move_skbs() can now find multiple subflows with data avail (comprising to-be-discarded data), so must update the byte counter incrementally.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 33 +++++++++++++++----
 net/mptcp/protocol.h |  6 +++-
 net/mptcp/subflow.c  | 78 ++++++++++++++++++++++++--------------------
 3 files changed, 75 insertions(+), 42 deletions(-)
net/mptcp/protocol.c +27 -6
index d51b1d95dfb8..f8e14d43ac55 100644
@@ -169,7 +169,8 @@ static bool mptcp_subflow_dsn_valid(const struct mptcp_sock *msk,
 		return true;
 
 	subflow->data_avail = 0;
-	return mptcp_subflow_data_available(ssk);
+	mptcp_subflow_data_available(ssk);
+	return subflow->data_avail == MPTCP_SUBFLOW_DATA_AVAIL;
 }
 
 static void mptcp_check_data_fin_ack(struct sock *sk)
@@ -316,11 +317,18 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
 	struct tcp_sock *tp;
 	bool done = false;
 
-	if (!mptcp_subflow_dsn_valid(msk, ssk)) {
-		*bytes = 0;
+	pr_debug("msk=%p ssk=%p data avail=%d valid=%d empty=%d",
+		 msk, ssk, subflow->data_avail,
+		 mptcp_subflow_dsn_valid(msk, ssk),
+		 !skb_peek(&ssk->sk_receive_queue));
+	if (subflow->data_avail == MPTCP_SUBFLOW_OOO_DATA) {
+		mptcp_subflow_discard_data(ssk, subflow->map_data_len);
 		return false;
 	}
 
+	if (!mptcp_subflow_dsn_valid(msk, ssk))
+		return false;
+
 	tp = tcp_sk(ssk);
 	do {
 		u32 map_remaining, offset;
@@ -379,7 +387,7 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
 		}
 	} while (more_data_avail);
 
-	*bytes = moved;
+	*bytes += moved;
 
 	/* If the moves have caught up with the DATA_FIN sequence number
 	 * it's time to ack the DATA_FIN and change socket state, but
@@ -418,9 +426,17 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)
 
 void mptcp_data_ready(struct sock *sk, struct sock *ssk)
 {
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
 	struct mptcp_sock *msk = mptcp_sk(sk);
+	bool wake;
 
-	set_bit(MPTCP_DATA_READY, &msk->flags);
+	/* move_skbs_to_msk below can legitly clear the data_avail flag,
+	 * but we will need later to properly woke the reader, cache its
+	 * value
+	 */
+	wake = subflow->data_avail == MPTCP_SUBFLOW_DATA_AVAIL;
+	if (wake)
+		set_bit(MPTCP_DATA_READY, &msk->flags);
 
 	if (atomic_read(&sk->sk_rmem_alloc) < READ_ONCE(sk->sk_rcvbuf) &&
 	    move_skbs_to_msk(msk, ssk))
@@ -441,7 +457,8 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)
 		move_skbs_to_msk(msk, ssk);
 	}
 wake:
-	sk->sk_data_ready(sk);
+	if (wake)
+		sk->sk_data_ready(sk);
 }
 
 static void __mptcp_flush_join_list(struct mptcp_sock *msk)
@@ -1264,6 +1281,9 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 		set_bit(MPTCP_DATA_READY, &msk->flags);
 	}
 out_err:
+	pr_debug("msk=%p data_ready=%d rx queue empty=%d copied=%d",
+		 msk, test_bit(MPTCP_DATA_READY, &msk->flags),
+		 skb_queue_empty(&sk->sk_receive_queue), copied);
 	mptcp_rcv_space_adjust(msk, copied);
 
 	release_sock(sk);
@@ -2295,6 +2315,7 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
 	sock_poll_wait(file, sock, wait);
 
 	state = inet_sk_state_load(sk);
+	pr_debug("msk=%p state=%d flags=%lx", msk, state, msk->flags);
 	if (state == TCP_LISTEN)
 		return mptcp_check_readable(msk);
 
net/mptcp/protocol.h +5 -1
index beb34b8a5363..e964f3670d75 100644
@@ -268,6 +268,9 @@ mptcp_subflow_rsk(const struct request_sock *rsk)
 	return (struct mptcp_subflow_request_sock *)rsk;
 }
 
+#define MPTCP_SUBFLOW_DATA_AVAIL	1
+#define MPTCP_SUBFLOW_OOO_DATA		2
+
 /* MPTCP subflow context */
 struct mptcp_subflow_context {
 	struct	list_head node;/* conn_list of subflows */
@@ -292,7 +295,7 @@ struct mptcp_subflow_context {
 		map_valid : 1,
 		mpc_map : 1,
 		backup : 1,
-		data_avail : 1,
+		data_avail : 2,
 		rx_eof : 1,
 		use_64bit_ack : 1, /* Set when we received a 64-bit DSN */
 		can_ack : 1;	    /* only after processing the remote a key */
@@ -347,6 +350,7 @@ int mptcp_is_enabled(struct net *net);
 void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
 				     struct mptcp_options_received *mp_opt);
 bool mptcp_subflow_data_available(struct sock *sk);
+int mptcp_subflow_discard_data(struct sock *sk, unsigned limit);
 void __init mptcp_subflow_init(void);
 
 /* called with sk socket lock held */
net/mptcp/subflow.c +43 -35

107 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#9 lore raw

RFC PATCH 4/12 mptcp: basic sndbuf autotuning

In reply to Paolo Abeni

Let the msk sendbuf track the size of the larger subflow's send buffer.

The update is performed just before try to send any data.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +13 -4
index f8e14d43ac55..c2fbd039f730 100644
@@ -837,7 +837,8 @@ static void mptcp_nospace(struct sock *sk, struct sock *ssk)
 		set_bit(SOCK_NOSPACE, &sock->flags);
 }
 
-static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
+static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk,
+					   int *sndbuf)
 {
 	struct mptcp_subflow_context *subflow;
 	struct sock *sk = (struct sock *)msk;
@@ -845,6 +846,7 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
 
 	sock_owned_by_me(sk);
 
+	*sndbuf = 0;
 	if (!mptcp_ext_cache_refill(msk))
 		return NULL;
 
@@ -856,6 +858,7 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
 			return NULL;
 		}
 
+		*sndbuf = max(ssk->sk_sndbuf, *sndbuf);
 		if (subflow->backup) {
 			if (!backup)
 				backup = ssk;
@@ -884,6 +887,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	struct page_frag *pfrag;
 	size_t copied = 0;
 	struct sock *ssk;
+	int sndbuf;
 	bool tx_ok;
 	long timeo;
 
@@ -911,7 +915,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 wait_for_sndbuf:
 	__mptcp_flush_join_list(msk);
-	ssk = mptcp_subflow_get_send(msk);
+	ssk = mptcp_subflow_get_send(msk, &sndbuf);
 	while (!sk_stream_memory_free(sk) ||
 	       !ssk ||
 	       !mptcp_page_frag_refill(ssk, pfrag)) {
@@ -934,13 +938,18 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 		mptcp_clean_una(sk);
 
-		ssk = mptcp_subflow_get_send(msk);
+		ssk = mptcp_subflow_get_send(msk, &sndbuf);
 		if (list_empty(&msk->conn_list)) {
 			ret = -ENOTCONN;
 			goto out;
 		}
 	}
 
+	/* do auto tuning */
+	if (!(sk->sk_userlocks & SOCK_RCVBUF_LOCK) &&
+	    sndbuf > READ_ONCE(sk->sk_sndbuf))
+		WRITE_ONCE(sk->sk_sndbuf, sndbuf);
+
 	pr_debug("conn_list->subflow=%p", ssk);
 
 	lock_sock(ssk);
@@ -1532,7 +1541,7 @@ static int mptcp_init_sock(struct sock *sk)
 
 	sk_sockets_allocated_inc(sk);
 	sk->sk_rcvbuf = sock_net(sk)->ipv4.sysctl_tcp_rmem[1];
-	sk->sk_sndbuf = sock_net(sk)->ipv4.sysctl_tcp_wmem[2];
+	sk->sk_sndbuf = sock_net(sk)->ipv4.sysctl_tcp_wmem[1];
 
 	return 0;
 }
Signature · 1 line
2.26.2
author
#11 lore raw

RFC PATCH 5/12 mptcp: introduce and use mptcp_try_coalesce()

In reply to Paolo Abeni

Factor-out existing code, will be re-used by the
next patch.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)
net/mptcp/protocol.c +19 -12
index c2fbd039f730..d50d51f26d18 100644
@@ -112,6 +112,22 @@ static int __mptcp_socket_create(struct mptcp_sock *msk)
 	return 0;
 }
 
+static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
+			       struct sk_buff *from)
+{
+	bool fragstolen;
+	int delta;
+
+	if (MPTCP_SKB_CB(from)->offset ||
+	    !skb_try_coalesce(to, from, &fragstolen, &delta))
+		return false;
+
+	kfree_skb_partial(from, fragstolen);
+	atomic_add(delta, &sk->sk_rmem_alloc);
+	sk_mem_charge(sk, delta);
+	return true;
+}
+
 static void __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
 			     struct sk_buff *skb,
 			     unsigned int offset, size_t copy_len)
@@ -123,24 +139,15 @@ static void __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
 
 	skb_ext_reset(skb);
 	skb_orphan(skb);
+	MPTCP_SKB_CB(skb)->offset = offset;
 	msk->ack_seq += copy_len;
 
 	tail = skb_peek_tail(&sk->sk_receive_queue);
-	if (offset == 0 && tail) {
-		bool fragstolen;
-		int delta;
-
-		if (skb_try_coalesce(tail, skb, &fragstolen, &delta)) {
-			kfree_skb_partial(skb, fragstolen);
-			atomic_add(delta, &sk->sk_rmem_alloc);
-			sk_mem_charge(sk, delta);
-			return;
-		}
-	}
+	if (tail && mptcp_try_coalesce(sk, tail, skb))
+		return;
 
 	skb_set_owner_r(skb, sk);
 	__skb_queue_tail(&sk->sk_receive_queue, skb);
-	MPTCP_SKB_CB(skb)->offset = offset;
 }
 
 static void mptcp_stop_timer(struct sock *sk)
Signature · 1 line
2.26.2
author
#13 lore raw

RFC PATCH 6/12 mptcp: move ooo skbs into msk out of order queue.

In reply to Paolo Abeni

Add an RB-tree to cope with OoO (at MPTCP level) data. __mptcp_move_skb() insert into the RB tree "future" data, eventually coalescing skb as allowed by the MPTCP DSN.

To simplify sequence accounting, move the DSN inside the cb.

After successfully enqueing in sequence data, check if we can use any data from the RB tree.

The RB tree code is copied as verbatim as possible from tcp_data_queue_ofo(), with a few simplifications due to the fact that MPTCP don't need to cope with sacks. All bugs here added by me.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 242 ++++++++++++++++++++++++++++++++++---------
 net/mptcp/protocol.h |   2 +
 net/mptcp/subflow.c  |   1 +
 3 files changed, 198 insertions(+), 47 deletions(-)
net/mptcp/protocol.c +195 -47
index d50d51f26d18..a400f6bf2bba 100644
@@ -34,6 +34,8 @@ struct mptcp6_sock {
 #endif
 
 struct mptcp_skb_cb {
+	u64 map_seq;
+	u64 end_seq;
 	u32 offset;
 };
 
@@ -112,6 +114,12 @@ static int __mptcp_socket_create(struct mptcp_sock *msk)
 	return 0;
 }
 
+static void mptcp_drop(struct sock *sk, struct sk_buff *skb)
+{
+	sk_drops_add(sk, skb);
+	__kfree_skb(skb);
+}
+
 static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
 			       struct sk_buff *from)
 {
@@ -122,16 +130,127 @@ static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
 	    !skb_try_coalesce(to, from, &fragstolen, &delta))
 		return false;
 
+	MPTCP_SKB_CB(to)->end_seq = MPTCP_SKB_CB(from)->end_seq;
 	kfree_skb_partial(from, fragstolen);
 	atomic_add(delta, &sk->sk_rmem_alloc);
 	sk_mem_charge(sk, delta);
 	return true;
 }
 
-static void __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
-			     struct sk_buff *skb,
-			     unsigned int offset, size_t copy_len)
+static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
+				   struct sk_buff *from)
+{
+	if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq)
+		return false;
+
+	return mptcp_try_coalesce((struct sock*)msk, to, from);
+}
+
+/* "inspired" by tcp_data_queue_ofo(), main differences:
+ * - use mptcp seqs
+ * - don't cope with sacks
+ */
+static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
+{
+	struct sock *sk = (struct sock *)msk;
+	struct rb_node **p, *parent;
+	u64 seq, end_seq, max_seq;
+	struct sk_buff *skb1;
+
+	seq = MPTCP_SKB_CB(skb)->map_seq;
+	end_seq = MPTCP_SKB_CB(skb)->end_seq;
+	max_seq = tcp_space(sk);
+	max_seq = max_seq > 0 ? max_seq + msk->ack_seq: msk->ack_seq;
+
+	if (after64(seq, max_seq)) {
+		/* out of window */
+		mptcp_drop(sk, skb);
+		return;
+	}
+
+	p = &msk->out_of_order_queue.rb_node;
+	if (RB_EMPTY_ROOT(&msk->out_of_order_queue)) {
+		rb_link_node(&skb->rbnode, NULL, p);
+		rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
+		msk->ooo_last_skb = skb;
+		goto end;
+	}
+
+	/* with 2 subflows, adding at end of ooo queue is quite likely
+	 * Use of ooo_last_skb avoids the O(Log(N)) rbtree lookup.
+	 */
+	if (mptcp_ooo_try_coalesce(msk, msk->ooo_last_skb, skb))
+		return;
+
+	/* Can avoid an rbtree lookup if we are adding skb after ooo_last_skb */
+	if (!before64(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq)) {
+		parent = &msk->ooo_last_skb->rbnode;
+		p = &parent->rb_right;
+		goto insert;
+	}
+
+	/* Find place to insert this segment. Handle overlaps on the way. */
+	parent = NULL;
+	while (*p) {
+		parent = *p;
+		skb1 = rb_to_skb(parent);
+		if (before64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
+			p = &parent->rb_left;
+			continue;
+		}
+		if (before64(seq, MPTCP_SKB_CB(skb1)->end_seq)) {
+			if (!after64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) {
+				/* All the bits are present. Drop. */
+				mptcp_drop(sk, skb);
+				return;
+			}
+			if (after64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
+				/* partial overlap:
+				 *     |     skb      |
+				 *  |     skb1    |
+				 * continue traversing
+				 */
+			} else {
+				/* skb's seq == skb1's seq and skb covers skb1.
+				 * Replace skb1 with skb.
+				 */
+				rb_replace_node(&skb1->rbnode, &skb->rbnode,
+						&msk->out_of_order_queue);
+				mptcp_drop(sk, skb1);
+				goto merge_right;
+			}
+		} else if (mptcp_ooo_try_coalesce(msk, skb1, skb)) {
+			return;
+		}
+		p = &parent->rb_right;
+	}
+insert:
+	/* Insert segment into RB tree. */
+	rb_link_node(&skb->rbnode, parent, p);
+	rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
+
+merge_right:
+	/* Remove other segments covered by skb. */
+	while ((skb1 = skb_rb_next(skb)) != NULL) {
+		if (before64(end_seq, MPTCP_SKB_CB(skb1)->end_seq))
+			break;
+		rb_erase(&skb1->rbnode, &msk->out_of_order_queue);
+		mptcp_drop(sk, skb1);
+	}
+	/* If there is no skb after us, we are the last_skb ! */
+	if (!skb1)
+		msk->ooo_last_skb = skb;
+
+end:
+	skb_condense(skb);
+	skb_set_owner_r(skb, sk);
+}
+
+static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
+			     struct sk_buff *skb, unsigned int offset,
+			     size_t copy_len)
 {
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
 	struct sock *sk = (struct sock *)msk;
 	struct sk_buff *tail;
 
@@ -139,15 +258,35 @@ static void __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
 
 	skb_ext_reset(skb);
 	skb_orphan(skb);
+
+	/* the skb map_seq accounts for the skb offset:
+	 * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
+	 * value
+	 */
+	MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow);
+	MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
 	MPTCP_SKB_CB(skb)->offset = offset;
-	msk->ack_seq += copy_len;
 
-	tail = skb_peek_tail(&sk->sk_receive_queue);
-	if (tail && mptcp_try_coalesce(sk, tail, skb))
-		return;
+	if (MPTCP_SKB_CB(skb)->map_seq == msk->ack_seq) {
+		/* in sequence */
+		msk->ack_seq += copy_len;
+		tail = skb_peek_tail(&sk->sk_receive_queue);
+		if (tail && mptcp_try_coalesce(sk, tail, skb))
+			return true;
 
-	skb_set_owner_r(skb, sk);
-	__skb_queue_tail(&sk->sk_receive_queue, skb);
+		skb_set_owner_r(skb, sk);
+		__skb_queue_tail(&sk->sk_receive_queue, skb);
+		return true;
+	} else if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq)) {
+		mptcp_data_queue_ofo(msk, skb);
+		return false;
+	}
+
+	/* old data, keep it simple and drop the whole pkt, sender
+	 * will retransmit as needed, if needed.
+	 */
+	mptcp_drop(sk, skb);
+	return false;
 }
 
 static void mptcp_stop_timer(struct sock *sk)
@@ -158,28 +297,6 @@ static void mptcp_stop_timer(struct sock *sk)
 	mptcp_sk(sk)->timer_ival = 0;
 }
 
-/* both sockets must be locked */
-static bool mptcp_subflow_dsn_valid(const struct mptcp_sock *msk,
-				    struct sock *ssk)
-{
-	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
-	u64 dsn = mptcp_subflow_get_mapped_dsn(subflow);
-
-	/* revalidate data sequence number.
-	 *
-	 * mptcp_subflow_data_available() is usually called
-	 * without msk lock.  Its unlikely (but possible)
-	 * that msk->ack_seq has been advanced since the last
-	 * call found in-sequence data.
-	 */
-	if (likely(dsn == msk->ack_seq))
-		return true;
-
-	subflow->data_avail = 0;
-	mptcp_subflow_data_available(ssk);
-	return subflow->data_avail == MPTCP_SUBFLOW_DATA_AVAIL;
-}
-
 static void mptcp_check_data_fin_ack(struct sock *sk)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
@@ -324,18 +441,7 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
 	struct tcp_sock *tp;
 	bool done = false;
 
-	pr_debug("msk=%p ssk=%p data avail=%d valid=%d empty=%d",
-		 msk, ssk, subflow->data_avail,
-		 mptcp_subflow_dsn_valid(msk, ssk),
-		 !skb_peek(&ssk->sk_receive_queue));
-	if (subflow->data_avail == MPTCP_SUBFLOW_OOO_DATA) {
-		mptcp_subflow_discard_data(ssk, subflow->map_data_len);
-		return false;
-	}
-
-	if (!mptcp_subflow_dsn_valid(msk, ssk))
-		return false;
-
+	pr_debug("msk=%p ssk=%p", msk, ssk);
 	tp = tcp_sk(ssk);
 	do {
 		u32 map_remaining, offset;
@@ -373,9 +479,9 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
 			if (tp->urg_data)
 				done = true;
 
-			__mptcp_move_skb(msk, ssk, skb, offset, len);
+			if (__mptcp_move_skb(msk, ssk, skb, offset, len))
+				moved += len;
 			seq += len;
-			moved += len;
 
 			if (WARN_ON_ONCE(map_remaining < len))
 				break;
@@ -408,6 +514,44 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
 	return done;
 }
 
+static bool mptcp_ofo_queue(struct mptcp_sock *msk)
+{
+	struct sock *sk = (struct sock *)msk;
+	struct sk_buff *skb, *tail;
+	bool moved = false;
+	struct rb_node *p;
+	u64 end_seq;
+
+	p = rb_first(&msk->out_of_order_queue);
+	while (p) {
+		skb = rb_to_skb(p);
+		if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq))
+			break;
+
+		p = rb_next(p);
+		rb_erase(&skb->rbnode, &msk->out_of_order_queue);
+
+		if (unlikely(!after64(MPTCP_SKB_CB(skb)->end_seq,
+				      msk->ack_seq))) {
+			mptcp_drop(sk, skb);
+			continue;
+		}
+
+		end_seq = MPTCP_SKB_CB(skb)->end_seq;
+		tail = skb_peek_tail(&sk->sk_receive_queue);
+		if (!tail || !mptcp_ooo_try_coalesce(msk, tail, skb)) {
+			int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
+
+			/* skip overlapping data, if any */
+			MPTCP_SKB_CB(skb)->offset += delta;
+			__skb_queue_tail(&sk->sk_receive_queue, skb);
+		}
+		msk->ack_seq = end_seq;
+		moved = true;
+	}
+	return moved;
+}
+
 /* In most cases we will be able to lock the mptcp socket.  If its already
  * owned, we need to defer to the work queue to avoid ABBA deadlock.
  */
@@ -423,8 +567,10 @@ static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)
 		return false;
 
 	/* must re-check after taking the lock */
-	if (!READ_ONCE(sk->sk_lock.owned))
+	if (!READ_ONCE(sk->sk_lock.owned)) {
 		__mptcp_move_skbs_from_subflow(msk, ssk, &moved);
+		mptcp_ofo_queue(msk);
+	}
 
 	spin_unlock_bh(&sk->sk_lock.slock);
 
@@ -1201,7 +1347,7 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 		release_sock(ssk);
 	} while (!done);
 
-	return moved > 0;
+	return mptcp_ofo_queue(msk) || moved > 0;
 }
 
 static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
@@ -1512,6 +1658,7 @@ static int __mptcp_init_sock(struct sock *sk)
 	INIT_LIST_HEAD(&msk->rtx_queue);
 	__set_bit(MPTCP_SEND_SPACE, &msk->flags);
 	INIT_WORK(&msk->work, mptcp_worker);
+	msk->out_of_order_queue = RB_ROOT;
 
 	msk->first = NULL;
 	inet_csk(sk)->icsk_sync_mss = mptcp_sync_mss;
@@ -1856,6 +2003,7 @@ static void mptcp_destroy(struct sock *sk)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
 
+	skb_rbtree_purge(&msk->out_of_order_queue);
 	mptcp_token_destroy(msk);
 	if (msk->cached_ext)
 		__skb_ext_put(msk->cached_ext);
net/mptcp/protocol.h +2 -0
index e964f3670d75..2b93c2c56316 100644
@@ -204,6 +204,8 @@ struct mptcp_sock {
 	bool		snd_data_fin_enable;
 	spinlock_t	join_list_lock;
 	struct work_struct work;
+	struct sk_buff  *ooo_last_skb;
+	struct rb_root  out_of_order_queue;
 	struct list_head conn_list;
 	struct list_head rtx_queue;
 	struct list_head join_list;
net/mptcp/subflow.c +1 -0
index b7394ae1c54d..b926f4f4fb9f 100644
@@ -352,6 +352,7 @@ static void mptcp_sock_destruct(struct sock *sk)
 		sock_orphan(sk);
 	}
 
+	skb_rbtree_purge(&mptcp_sk(sk)->out_of_order_queue);
 	mptcp_token_destroy(mptcp_sk(sk));
 	inet_sock_destruct(sk);
 }
Signature · 1 line
2.26.2
author
#14 lore raw

RFC PATCH 7/12 mptcp: cleanup mptcp_subflow_discard_data()

In reply to Paolo Abeni
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.h |  1 -
 net/mptcp/subflow.c  | 53 ++++++++++----------------------------------
 2 files changed, 12 insertions(+), 42 deletions(-)
net/mptcp/protocol.h +0 -1
index 2b93c2c56316..dfcd7eab35ad 100644
@@ -352,7 +352,6 @@ int mptcp_is_enabled(struct net *net);
 void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
 				     struct mptcp_options_received *mp_opt);
 bool mptcp_subflow_data_available(struct sock *sk);
-int mptcp_subflow_discard_data(struct sock *sk, unsigned limit);
 void __init mptcp_subflow_init(void);
 
 /* called with sk socket lock held */
net/mptcp/subflow.c +12 -41

68 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#17 lore raw

RFC PATCH 8/12 mptcp: add OoO related mibs

In reply to Paolo Abeni

Add a bunch of MPTCP mibs related to MPTCP OoO data processing.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/mib.c      |  5 +++++
 net/mptcp/mib.h      |  5 +++++
 net/mptcp/protocol.c | 24 +++++++++++++++++++++++-
 net/mptcp/subflow.c  |  1 +
 4 files changed, 34 insertions(+), 1 deletion(-)
net/mptcp/mib.c +5 -0
index 0a6a15f3456d..056986c7a228 100644
@@ -22,6 +22,11 @@ static const struct snmp_mib mptcp_snmp_list[] = {
 	SNMP_MIB_ITEM("MPJoinAckHMacFailure", MPTCP_MIB_JOINACKMAC),
 	SNMP_MIB_ITEM("DSSNotMatching", MPTCP_MIB_DSSNOMATCH),
 	SNMP_MIB_ITEM("InfiniteMapRx", MPTCP_MIB_INFINITEMAPRX),
+	SNMP_MIB_ITEM("OFOQueueTail", MPTCP_MIB_OFOQUEUETAIL),
+	SNMP_MIB_ITEM("OFOQueue", MPTCP_MIB_OFOQUEUE),
+	SNMP_MIB_ITEM("OFOMerge", MPTCP_MIB_OFOMERGE),
+	SNMP_MIB_ITEM("NoDSSInWindow", MPTCP_MIB_NODSSWINDOW),
+	SNMP_MIB_ITEM("DuplicateData", MPTCP_MIB_DUPDATA),
 	SNMP_MIB_SENTINEL
 };
 
net/mptcp/mib.h +5 -0
index d7de340fc997..937a177729f1 100644
@@ -15,6 +15,11 @@ enum linux_mptcp_mib_field {
 	MPTCP_MIB_JOINACKMAC,		/* HMAC was wrong on ACK + MP_JOIN */
 	MPTCP_MIB_DSSNOMATCH,		/* Received a new mapping that did not match the previous one */
 	MPTCP_MIB_INFINITEMAPRX,	/* Received an infinite mapping */
+	MPTCP_MIB_OFOQUEUETAIL,	/* Segments inserted into OoO queue tail */
+	MPTCP_MIB_OFOQUEUE,		/* Segments inserted into OoO queue */
+	MPTCP_MIB_OFOMERGE,		/* Segments merged in OoO queue */
+	MPTCP_MIB_NODSSWINDOW,		/* Segments not in MPTCP windows */
+	MPTCP_MIB_DUPDATA,		/* Segments discarded due to duplicate DSS */
 	__MPTCP_MIB_MAX
 };
 
net/mptcp/protocol.c +23 -1
index a400f6bf2bba..ef5b68c4ff49 100644
@@ -130,6 +130,9 @@ static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
 	    !skb_try_coalesce(to, from, &fragstolen, &delta))
 		return false;
 
+	pr_debug("colesced seq %llx into %llx new len %d new end seq %llx",
+		 MPTCP_SKB_CB(from)->map_seq, MPTCP_SKB_CB(to)->map_seq,
+		 to->len, MPTCP_SKB_CB(from)->end_seq);
 	MPTCP_SKB_CB(to)->end_seq = MPTCP_SKB_CB(from)->end_seq;
 	kfree_skb_partial(from, fragstolen);
 	atomic_add(delta, &sk->sk_rmem_alloc);
@@ -162,13 +165,17 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
 	max_seq = tcp_space(sk);
 	max_seq = max_seq > 0 ? max_seq + msk->ack_seq: msk->ack_seq;
 
+	pr_debug("msk=%p seq=%llx limit=%llx empty=%d", msk, seq, max_seq,
+		 RB_EMPTY_ROOT(&msk->out_of_order_queue));
 	if (after64(seq, max_seq)) {
 		/* out of window */
 		mptcp_drop(sk, skb);
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_NODSSWINDOW);
 		return;
 	}
 
 	p = &msk->out_of_order_queue.rb_node;
+	MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUE);
 	if (RB_EMPTY_ROOT(&msk->out_of_order_queue)) {
 		rb_link_node(&skb->rbnode, NULL, p);
 		rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
@@ -179,11 +186,15 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
 	/* with 2 subflows, adding at end of ooo queue is quite likely
 	 * Use of ooo_last_skb avoids the O(Log(N)) rbtree lookup.
 	 */
-	if (mptcp_ooo_try_coalesce(msk, msk->ooo_last_skb, skb))
+	if (mptcp_ooo_try_coalesce(msk, msk->ooo_last_skb, skb)) {
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
 		return;
+	}
 
 	/* Can avoid an rbtree lookup if we are adding skb after ooo_last_skb */
 	if (!before64(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq)) {
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
 		parent = &msk->ooo_last_skb->rbnode;
 		p = &parent->rb_right;
 		goto insert;
@@ -202,6 +213,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
 			if (!after64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) {
 				/* All the bits are present. Drop. */
 				mptcp_drop(sk, skb);
+				MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
 				return;
 			}
 			if (after64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
@@ -217,13 +229,16 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
 				rb_replace_node(&skb1->rbnode, &skb->rbnode,
 						&msk->out_of_order_queue);
 				mptcp_drop(sk, skb1);
+				MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
 				goto merge_right;
 			}
 		} else if (mptcp_ooo_try_coalesce(msk, skb1, skb)) {
+			MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
 			return;
 		}
 		p = &parent->rb_right;
 	}
+
 insert:
 	/* Insert segment into RB tree. */
 	rb_link_node(&skb->rbnode, parent, p);
@@ -236,6 +251,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
 			break;
 		rb_erase(&skb1->rbnode, &msk->out_of_order_queue);
 		mptcp_drop(sk, skb1);
+		MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
 	}
 	/* If there is no skb after us, we are the last_skb ! */
 	if (!skb1)
@@ -285,6 +301,7 @@ static bool __mptcp_move_skb(struct mptcp_sock *msk, struct sock *ssk,
 	/* old data, keep it simple and drop the whole pkt, sender
 	 * will retransmit as needed, if needed.
 	 */
+	MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
 	mptcp_drop(sk, skb);
 	return false;
 }
@@ -523,6 +540,7 @@ static bool mptcp_ofo_queue(struct mptcp_sock *msk)
 	u64 end_seq;
 
 	p = rb_first(&msk->out_of_order_queue);
+	pr_debug("msk=%p empty=%d", msk, RB_EMPTY_ROOT(&msk->out_of_order_queue));
 	while (p) {
 		skb = rb_to_skb(p);
 		if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq))
@@ -534,6 +552,7 @@ static bool mptcp_ofo_queue(struct mptcp_sock *msk)
 		if (unlikely(!after64(MPTCP_SKB_CB(skb)->end_seq,
 				      msk->ack_seq))) {
 			mptcp_drop(sk, skb);
+			MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
 			continue;
 		}
 
@@ -543,6 +562,9 @@ static bool mptcp_ofo_queue(struct mptcp_sock *msk)
 			int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
 
 			/* skip overlapping data, if any */
+			pr_debug("uncoalesced seq=%llx ack seq=%llx delta=%d",
+				 MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq,
+				 delta);
 			MPTCP_SKB_CB(skb)->offset += delta;
 			__skb_queue_tail(&sk->sk_receive_queue, skb);
 		}
net/mptcp/subflow.c +1 -0
index b2bde12b5933..5cedb836693b 100644
@@ -746,6 +746,7 @@ static int mptcp_subflow_discard_data(struct sock *ssk, struct sk_buff *skb,
 
 	pr_debug("discarding=%d len=%d seq=%d", incr, skb->len,
 		 subflow->map_subflow_seq);
+	MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DUPDATA);
 	tcp_sk(ssk)->copied_seq += incr;
 	if (incr >= skb->len)
 		sk_eat_skb(ssk, skb);
Signature · 1 line
2.26.2
author
#21 lore raw

RFC PATCH 9/12 mptcp: move address attribute into mptcp_addr_info

In reply to Paolo Abeni

So that can be accessed easily from subflow creation helper. No functional change intended.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/pm_netlink.c | 38 +++++++++++++++++++-------------------
 net/mptcp/protocol.h   |  5 +++--
 net/mptcp/subflow.c    |  5 ++---
 3 files changed, 24 insertions(+), 24 deletions(-)
net/mptcp/pm_netlink.c +19 -19
index c8820c4156e6..b15fb3c20146 100644
@@ -23,8 +23,6 @@ static int pm_nl_pernet_id;
 
 struct mptcp_pm_addr_entry {
 	struct list_head	list;
-	unsigned int		flags;
-	int			ifindex;
 	struct mptcp_addr_info	addr;
 	struct rcu_head		rcu;
 };
@@ -119,7 +117,7 @@ select_local_address(const struct pm_nl_pernet *pernet,
 	rcu_read_lock();
 	spin_lock_bh(&msk->join_list_lock);
 	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
-		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
+		if (!(entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
 			continue;
 
 		/* avoid any address already in use by subflows and
@@ -150,7 +148,7 @@ select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos)
 	 * can lead to additional addresses not being announced.
 	 */
 	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
-		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
+		if (!(entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
 			continue;
 		if (i++ == pos) {
 			ret = entry;
@@ -210,8 +208,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 			msk->pm.subflows++;
 			check_work_pending(msk);
 			spin_unlock_bh(&msk->pm.lock);
-			__mptcp_subflow_connect(sk, local->ifindex,
-						&local->addr, &remote);
+			__mptcp_subflow_connect(sk, &local->addr, &remote);
 			spin_lock_bh(&msk->pm.lock);
 			return;
 		}
@@ -257,13 +254,13 @@ void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
 	local.family = remote.family;
 
 	spin_unlock_bh(&msk->pm.lock);
-	__mptcp_subflow_connect((struct sock *)msk, 0, &local, &remote);
+	__mptcp_subflow_connect((struct sock *)msk, &local, &remote);
 	spin_lock_bh(&msk->pm.lock);
 }
 
 static bool address_use_port(struct mptcp_pm_addr_entry *entry)
 {
-	return (entry->flags &
+	return (entry->addr.flags &
 		(MPTCP_PM_ADDR_FLAG_SIGNAL | MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==
 		MPTCP_PM_ADDR_FLAG_SIGNAL;
 }
@@ -293,9 +290,9 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
 			goto out;
 	}
 
-	if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
+	if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
 		pernet->add_addr_signal_max++;
-	if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+	if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
 		pernet->local_addr_max++;
 
 	entry->addr.id = pernet->next_id++;
@@ -345,8 +342,9 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 	if (!entry)
 		return -ENOMEM;
 
-	entry->flags = 0;
 	entry->addr = skc_local;
+	entry->addr.ifindex = 0;
+	entry->addr.flags = 0;
 	ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
 	if (ret < 0)
 		kfree(entry);
@@ -460,14 +458,16 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
 		entry->addr.addr.s_addr = nla_get_in_addr(tb[addr_addr]);
 
 skip_family:
-	if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX])
-		entry->ifindex = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
+	if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX]) {
+		u32 val = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
+		entry->addr.ifindex = val;
+	}
 
 	if (tb[MPTCP_PM_ADDR_ATTR_ID])
 		entry->addr.id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
 
 	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
-		entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
+		entry->addr.flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
 
 	return 0;
 }
@@ -535,9 +535,9 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 		ret = -EINVAL;
 		goto out;
 	}
-	if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
+	if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
 		pernet->add_addr_signal_max--;
-	if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+	if (entry->addr.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
 		pernet->local_addr_max--;
 
 	pernet->addrs--;
@@ -593,10 +593,10 @@ static int mptcp_nl_fill_addr(struct sk_buff *skb,
 		goto nla_put_failure;
 	if (nla_put_u8(skb, MPTCP_PM_ADDR_ATTR_ID, addr->id))
 		goto nla_put_failure;
-	if (nla_put_u32(skb, MPTCP_PM_ADDR_ATTR_FLAGS, entry->flags))
+	if (nla_put_u32(skb, MPTCP_PM_ADDR_ATTR_FLAGS, entry->addr.flags))
 		goto nla_put_failure;
-	if (entry->ifindex &&
-	    nla_put_s32(skb, MPTCP_PM_ADDR_ATTR_IF_IDX, entry->ifindex))
+	if (entry->addr.ifindex &&
+	    nla_put_s32(skb, MPTCP_PM_ADDR_ATTR_IF_IDX, entry->addr.ifindex))
 		goto nla_put_failure;
 
 	if (addr->family == AF_INET &&
net/mptcp/protocol.h +3 -2
index dfcd7eab35ad..5467eb1adebd 100644
@@ -140,6 +140,8 @@ struct mptcp_addr_info {
 	sa_family_t		family;
 	__be16			port;
 	u8			id;
+	unsigned int		flags;
+	int			ifindex;
 	union {
 		struct in_addr addr;
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
@@ -355,8 +357,7 @@ bool mptcp_subflow_data_available(struct sock *sk);
 void __init mptcp_subflow_init(void);
 
 /* called with sk socket lock held */
-int __mptcp_subflow_connect(struct sock *sk, int ifindex,
-			    const struct mptcp_addr_info *loc,
+int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 			    const struct mptcp_addr_info *remote);
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
net/mptcp/subflow.c +2 -3
index 5cedb836693b..867fd8496fb8 100644
@@ -963,8 +963,7 @@ static void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
 #endif
 }
 
-int __mptcp_subflow_connect(struct sock *sk, int ifindex,
-			    const struct mptcp_addr_info *loc,
+int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 			    const struct mptcp_addr_info *remote)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
@@ -1008,7 +1007,7 @@ int __mptcp_subflow_connect(struct sock *sk, int ifindex,
 	if (loc->family == AF_INET6)
 		addrlen = sizeof(struct sockaddr_in6);
 #endif
-	ssk->sk_bound_dev_if = ifindex;
+	ssk->sk_bound_dev_if = loc->ifindex;
 	err = kernel_bind(sf, (struct sockaddr *)&addr, addrlen);
 	if (err)
 		goto failed;
Signature · 1 line
2.26.2
author
#23 lore raw

RFC PATCH 10/12 mptcp: allow creating non-backup subflows

In reply to Paolo Abeni

Currently the 'backup' attribute of local endpoint is ignored. Let's use it for the MP_JOIN handshake

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/subflow.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/subflow.c +2 -1
index 867fd8496fb8..3582f80e520a 100644
@@ -20,6 +20,7 @@
 #include <net/ip6_route.h>
 #endif
 #include <net/mptcp.h>
+#include <uapi/linux/mptcp.h>
 #include "protocol.h"
 #include "mib.h"
 
@@ -1018,7 +1019,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 	subflow->remote_token = remote_token;
 	subflow->local_id = local_id;
 	subflow->request_join = 1;
-	subflow->request_bkup = 1;
+	subflow->request_bkup = !!(loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
 	mptcp_info2sockaddr(remote, &addr);
 
 	err = kernel_connect(sf, (struct sockaddr *)&addr, addrlen, O_NONBLOCK);
Signature · 1 line
2.26.2
author
#24 lore raw

RFC PATCH 11/12 mptcp: allow picking different xmit subflows

In reply to Paolo Abeni

Update the scheduler to less trivial heuristic: cache the last used subflow, and try to send on it a reasonably long burst of data. When the burst or the subflow send space is exausted, move to the next one with available send space.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 112 +++++++++++++++++++++++++++++++++++++------
 net/mptcp/protocol.h |   6 ++-
 2 files changed, 101 insertions(+), 17 deletions(-)
net/mptcp/protocol.c +97 -15
index ef5b68c4ff49..89c0400593d1 100644
@@ -1012,39 +1012,112 @@ static void mptcp_nospace(struct sock *sk, struct sock *ssk)
 		set_bit(SOCK_NOSPACE, &sock->flags);
 }
 
+static bool mptcp_subflow_active(struct mptcp_subflow_context *subflow,
+				 bool fallback)
+{
+	struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+	/* subflow must be open for write */
+	if ((1 << ssk->sk_state) &
+	    (TCPF_CLOSE | TCPF_LAST_ACK | TCPF_CLOSING | TCPF_FIN_WAIT2 |
+	     TCPF_FIN_WAIT1))
+		return false;
+
+	/* we can xmit on MPC and fallen back subflows in
+	 * TCP_SYN_SENT/TCP_SYN_RECV status, but we need fully established
+	 * MP_JOIN subflows.
+	 */
+	return !subflow->request_join ||
+	       (subflow->fully_established && !fallback);
+}
+
+#define MPTCP_SEND_BURST_SIZE		(1 << 15)
+
+static struct list_head *mptcp_next_subflow(struct mptcp_sock *msk,
+					    struct list_head *pos,
+					    bool wrap_around)
+{
+	if (list_is_last(pos, &msk->conn_list) && wrap_around)
+		return msk->conn_list.next;
+	return pos->next;
+}
+
 static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk,
 					   int *sndbuf)
 {
+	int next_wspace = 0, next_bu_wspace = 0, last_snd_wspace = 0;
+	bool fallback = __mptcp_check_fallback(msk);
 	struct mptcp_subflow_context *subflow;
-	struct sock *sk = (struct sock *)msk;
-	struct sock *backup = NULL;
+	struct sock *next_backup = NULL;
+	struct list_head *pos, *start;
+	struct sock *next_ssk = NULL;
+	bool wrap_around;
 
-	sock_owned_by_me(sk);
+	sock_owned_by_me((struct sock *)msk);
 
 	*sndbuf = 0;
 	if (!mptcp_ext_cache_refill(msk))
 		return NULL;
 
-	mptcp_for_each_subflow(msk, subflow) {
-		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+	/* lookup the first writeable subflow and first writable back subflow
+	 * starting from last used, with wrap-around
+	 */
+	if (msk->last_snd) {
+		start = &mptcp_subflow_ctx(msk->last_snd)->node;
+		wrap_around = true;
+	} else {
+		start = &msk->conn_list;
+		wrap_around = false;
+	}
+	pr_debug("msk=%p start=%p pos=%p wrap_around=%d last=%p", msk, start,
+		 mptcp_next_subflow(msk, start, wrap_around), wrap_around,
+		 msk->last_snd);
+	for (pos = mptcp_next_subflow(msk, start, wrap_around); pos != start;
+	     pos = mptcp_next_subflow(msk, pos, wrap_around)) {
+		struct sock *ssk;
+		int wspace;
 
-		if (!sk_stream_memory_free(sk)) {
-			mptcp_nospace(sk, ssk);
-			return NULL;
-		}
+		subflow = list_entry(pos, struct mptcp_subflow_context, node);
+		ssk =  mptcp_subflow_tcp_sock(subflow);
+		if (!mptcp_subflow_active(subflow, fallback))
+			continue;
 
 		*sndbuf = max(ssk->sk_sndbuf, *sndbuf);
-		if (subflow->backup) {
-			if (!backup)
-				backup = ssk;
-
+		wspace = sk_stream_wspace(ssk);
+		if (wspace <= 0)
 			continue;
+
+		if (!subflow->backup && !next_ssk) {
+			next_ssk = ssk;
+			next_wspace = wspace;
 		}
 
-		return ssk;
+		if (subflow->backup && !next_backup) {
+			next_backup = ssk;
+			next_bu_wspace = wspace;
+		}
+	}
+	if (!next_ssk) {
+		next_ssk = next_backup;
+		next_wspace = next_bu_wspace;
 	}
+	if (msk->last_snd) {
+		*sndbuf = max(msk->last_snd->sk_sndbuf, *sndbuf);
+		last_snd_wspace = sk_stream_wspace(msk->last_snd);
+	}
+	pr_debug("msk=%p ssk=%p last=%p wspace=%d last wspace=%d burst=%d", msk,
+		 next_ssk, msk->last_snd, next_wspace, last_snd_wspace,
+		 msk->snd_burst);
 
-	return backup;
+	/* use the looked-up subflow if the previusly used has exauted the burst
+	 * or is not writable
+	 */
+	if (next_ssk && (last_snd_wspace <= 0 || msk->snd_burst <= 0)) {
+		msk->last_snd = next_ssk;
+		msk->snd_burst = min(MPTCP_SEND_BURST_SIZE, next_wspace);
+		last_snd_wspace = next_wspace;
+	}
+	return last_snd_wspace > 0 ? msk->last_snd : NULL;
 }
 
 static void ssk_check_wmem(struct sock *sk, struct sock *ssk)
@@ -1142,6 +1215,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		}
 
 		copied += ret;
+		msk->snd_burst -= ret;
 
 		tx_ok = msg_data_left(msg);
 		if (!tx_ok)
@@ -1358,6 +1432,10 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 	unsigned int moved = 0;
 	bool done;
 
+	if (((struct sock *)msk)->sk_state == TCP_CLOSE)
+		return false;
+
+	__mptcp_flush_join_list(msk);
 	do {
 		struct sock *ssk = mptcp_subflow_recv_lookup(msk);
 
@@ -1513,6 +1591,7 @@ static void mptcp_retransmit_timer(struct timer_list *t)
  */
 static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)
 {
+	bool fallback = __mptcp_check_fallback(msk);
 	struct mptcp_subflow_context *subflow;
 	struct sock *backup = NULL;
 
@@ -1521,6 +1600,9 @@ static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 
+		if (!mptcp_subflow_active(subflow, fallback))
+			continue;
+
 		/* still data outstanding at TCP level?  Don't retransmit. */
 		if (!tcp_write_queue_empty(ssk))
 			return NULL;
net/mptcp/protocol.h +4 -2
index 5467eb1adebd..0381e63d866d 100644
@@ -196,6 +196,8 @@ struct mptcp_sock {
 	u64		write_seq;
 	u64		ack_seq;
 	u64		rcv_data_fin_seq;
+	struct sock	*last_snd;
+	int		snd_burst;
 	atomic64_t	snd_una;
 	unsigned long	timer_ival;
 	u32		token;
@@ -469,12 +471,12 @@ static inline bool before64(__u64 seq1, __u64 seq2)
 
 void mptcp_diag_subflow_init(struct tcp_ulp_ops *ops);
 
-static inline bool __mptcp_check_fallback(struct mptcp_sock *msk)
+static inline bool __mptcp_check_fallback(const struct mptcp_sock *msk)
 {
 	return test_bit(MPTCP_FALLBACK_DONE, &msk->flags);
 }
 
-static inline bool mptcp_check_fallback(struct sock *sk)
+static inline bool mptcp_check_fallback(const struct sock *sk)
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
Signature · 1 line
2.26.2
author
#30 lore raw

RFC PATCH 12/12 mptcp: simult flow self-tests

In reply to Paolo Abeni

Add a bunch of test-cases for multiple subflow xmit:
create multiple subflows simulating different links condition via netem and verify that the msk is able to use completely the aggregated bandwidth.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 .../selftests/net/mptcp/simult_flows.sh       | 290 ++++++++++++++++++
 1 file changed, 290 insertions(+)
 create mode 100755 tools/testing/selftests/net/mptcp/simult_flows.sh
tools/testing/selftests/net/mptcp/simult_flows.sh new file +290 -0
new file mode 100755
index 000000000000..0d91a3f87e3f
@@ -0,0 +1,290 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
+ns1="ns1-$rndh"
+ns2="ns2-$rndh"
+ns3="ns3-$rndh"
+capture=false
+ksft_skip=4
+timeout=30
+test_cnt=1
+ret=0
+bail=0
+
+usage() {
+	echo "Usage: $0 [ -b ] [ -c ] [ -d ]"
+	echo -e "\t-b: bail out after first error, otherwise runs al testcases"
+	echo -e "\t-c: capture packets for each test using tcpdump (default: no capture)"
+	echo -e "\t-d: debug this script"
+}
+
+cleanup()
+{
+	rm -f "$cin" "$cout"
+	rm -f "$sin" "$sout"
+	rm -f "$capout"
+
+	local netns
+	for netns in "$ns1" "$ns2" "$ns3";do
+		ip netns del $netns
+	done
+}
+
+ip -Version > /dev/null 2>&1
+if [ $? -ne 0 ];then
+	echo "SKIP: Could not run test without ip tool"
+	exit $ksft_skip
+fi
+
+#  "$ns1"              ns2                    ns3
+#     ns1eth1    ns2eth1   ns2eth3      ns3eth1
+#            netem
+#     ns1eth2    ns2eth2
+#            netem
+
+setup()
+{
+	large=$(mktemp)
+	small=$(mktemp)
+	sout=$(mktemp)
+	cout=$(mktemp)
+	capout=$(mktemp)
+	size=$((2048 * 4096))
+	dd if=/dev/zero of=$small bs=4096 count=20 >/dev/null 2>&1
+	dd if=/dev/zero of=$large bs=4096 count=$((size / 4096)) >/dev/null 2>&1
+
+	trap cleanup EXIT
+
+	for i in "$ns1" "$ns2" "$ns3";do
+		ip netns add $i || exit $ksft_skip
+		ip -net $i link set lo up
+	done
+
+	ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
+	ip link add ns1eth2 netns "$ns1" type veth peer name ns2eth2 netns "$ns2"
+	ip link add ns2eth3 netns "$ns2" type veth peer name ns3eth1 netns "$ns3"
+
+	ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth1
+	ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth1 nodad
+	ip -net "$ns1" link set ns1eth1 up mtu 1500
+	ip -net "$ns1" route add default via 10.0.1.2
+	ip -net "$ns1" route add default via dead:beef:1::2
+
+	ip -net "$ns1" addr add 10.0.2.1/24 dev ns1eth2
+	ip -net "$ns1" addr add dead:beef:2::1/64 dev ns1eth2 nodad
+	ip -net "$ns1" link set ns1eth2 up mtu 1500
+	ip -net "$ns1" route add default via 10.0.2.2 metric 101
+	ip -net "$ns1" route add default via dead:beef:2::2 metric 101
+
+	ip netns exec "$ns1" ./pm_nl_ctl limits 1 1
+	ip netns exec "$ns1" ./pm_nl_ctl add 10.0.2.1 dev ns1eth2 flags subflow
+	ip netns exec "$ns1" sysctl -q net.ipv4.conf.all.rp_filter=0
+
+	ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1
+	ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad
+	ip -net "$ns2" link set ns2eth1 up mtu 1500
+
+	ip -net "$ns2" addr add 10.0.2.2/24 dev ns2eth2
+	ip -net "$ns2" addr add dead:beef:2::2/64 dev ns2eth2 nodad
+	ip -net "$ns2" link set ns2eth2 up mtu 1500
+
+	ip -net "$ns2" addr add 10.0.3.2/24 dev ns2eth3
+	ip -net "$ns2" addr add dead:beef:3::2/64 dev ns2eth3 nodad
+	ip -net "$ns2" link set ns2eth3 up mtu 1500
+	ip netns exec "$ns2" sysctl -q net.ipv4.ip_forward=1
+	ip netns exec "$ns2" sysctl -q net.ipv6.conf.all.forwarding=1
+
+	ip -net "$ns3" addr add 10.0.3.3/24 dev ns3eth1
+	ip -net "$ns3" addr add dead:beef:3::3/64 dev ns3eth1 nodad
+	ip -net "$ns3" link set ns3eth1 up mtu 1500
+	ip -net "$ns3" route add default via 10.0.3.2
+	ip -net "$ns3" route add default via dead:beef:3::2
+
+	ip netns exec "$ns3" ./pm_nl_ctl limits 1 1
+}
+
+# $1: ns, $2: port
+wait_local_port_listen()
+{
+	local listener_ns="${1}"
+	local port="${2}"
+
+	local port_hex i
+
+	port_hex="$(printf "%04X" "${port}")"
+	for i in $(seq 10); do
+		ip netns exec "${listener_ns}" cat /proc/net/tcp* | \
+			awk "BEGIN {rc=1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=0; exit}} END {exit rc}" &&
+			break
+		sleep 0.1
+	done
+}
+
+do_transfer()
+{
+	local cin=$1
+	local sin=$2
+	local max_time=$3
+	local port
+	port=$((10000+$test_cnt))
+	test_cnt=$((test_cnt+1))
+
+	:> "$cout"
+	:> "$sout"
+	:> "$capout"
+
+	local addr_port
+	addr_port=$(printf "%s:%d" ${connect_addr} ${port})
+
+	if $capture; then
+		local capuser
+		if [ -z $SUDO_USER ] ; then
+			capuser=""
+		else
+			capuser="-Z $SUDO_USER"
+		fi
+
+		local capfile="${rndh}-${port}"
+		local capopt="-i any -s 65535 -B 32768 ${capuser}"
+
+		ip netns exec ${ns3}  tcpdump ${capopt} -w "${capfile}-listener.pcap"  >> "${capout}" 2>&1 &
+		local cappid_listener=$!
+
+		ip netns exec ${ns1} tcpdump ${capopt} -w "${capfile}-connector.pcap" >> "${capout}" 2>&1 &
+		local cappid_connector=$!
+
+		sleep 1
+	fi
+
+	ip netns exec ${ns3} ./mptcp_connect -jt $timeout -l -p $port 0.0.0.0 < "$sin" > "$sout" &
+	local spid=$!
+
+	wait_local_port_listen "${ns3}" "${port}"
+
+	local start
+	start=$(date +%s%3N)
+	ip netns exec ${ns1} ./mptcp_connect -jt $timeout -p $port 10.0.3.3 < "$cin" > "$cout" &
+	local cpid=$!
+
+	wait $cpid
+	local retc=$?
+	wait $spid
+	local rets=$?
+
+	local stop
+	stop=$(date +%s%3N)
+
+	if $capture; then
+		sleep 1
+		kill ${cappid_listener}
+		kill ${cappid_connector}
+	fi
+
+	local duration
+	duration=$((stop-start))
+
+	cmp $sin $cout > /dev/null 2>&1
+	local cmps=$?
+	cmp $cin $sout > /dev/null 2>&1
+	local cmpc=$?
+
+	printf "%16s" "$duration max $max_time "
+	if [ $retc -eq 0 ] && [ $rets -eq 0 ] && \
+	   [ $cmpc -eq 0 ] && [ $cmps -eq 0 ] && \
+	   [ $duration -lt $max_time ]; then
+		echo "[ OK ]"
+		cat "$capout"
+		return 0
+	fi
+
+	echo " [ fail ]"
+	echo "client exit code $retc, server $rets" 1>&2
+	echo "\nnetns ${ns3} socket stat for $port:" 1>&2
+	ip netns exec ${ns3} ss -nita 1>&2 -o "sport = :$port"
+	echo "\nnetns ${ns1} socket stat for $port:" 1>&2
+	ip netns exec ${ns1} ss -nita 1>&2 -o "dport = :$port"
+	ls -l $sin $cout
+	ls -l $cin $sout
+
+	cat "$capout"
+	return 1
+}
+
+run_test()
+{
+	local rate1=$1
+	local rate2=$2
+	local delay1=$3
+	local delay2=$4
+	local lret
+	local dev
+	shift 4
+	local msg=$*
+
+	[ $delay1 -gt 0 ] && delay1="delay $delay1" || delay1=""
+	[ $delay2 -gt 0 ] && delay2="delay $delay2" || delay2=""
+
+	for dev in ns1eth1 ns1eth2; do
+		tc -n $ns1 qdisc del dev $dev root >/dev/null 2>&1
+	done
+	for dev in ns2eth1 ns2eth2; do
+		tc -n $ns2 qdisc del dev $dev root >/dev/null 2>&1
+	done
+	tc -n $ns1 qdisc add dev ns1eth1 root netem rate ${rate1}mbit $delay1
+	tc -n $ns1 qdisc add dev ns1eth2 root netem rate ${rate2}mbit $delay2
+	tc -n $ns2 qdisc add dev ns2eth1 root netem rate ${rate1}mbit $delay1
+	tc -n $ns2 qdisc add dev ns2eth2 root netem rate ${rate2}mbit $delay2
+
+	# time is measure in ms
+	local time=$((size * 8 * 1000 / (( $rate1 + $rate2) * 1024 *1024) ))
+
+	# mptcp_connect will sleep a bit to allow for mp_join completion
+	time=$((time + 1000))
+
+	printf "%-50s" "$msg"
+	do_transfer $small $large $((time * 11 / 10))
+	lret=$?
+	if [ $lret -ne 0 ]; then
+		ret=$lret
+		[ $bail -eq 0 ] || exit $ret
+	fi
+
+	printf "%-50s" "$msg - reverse direction"
+	do_transfer $large $small $((time * 11 / 10))
+	lret=$?
+	if [ $lret -ne 0 ]; then
+		ret=$lret
+		[ $bail -eq 0 ] || exit $ret
+	fi
+}
+
+while getopts "bcdh" option;do
+	case "$option" in
+	"h")
+		usage $0
+		exit 0
+		;;
+	"b")
+		bail=1
+		;;
+	"c")
+		capture=true
+		;;
+	"d")
+		set -x
+		;;
+	"?")
+		usage $0
+		exit 1
+		;;
+	esac
+done
+
+setup
+run_test 10 10 0 0 "balanced bwidth"
+run_test 10 10 1 50 "balanced bwidth with unbalanced delay"
+run_test 30 10 0 0 "unbalanced bwidth"
+run_test 30 10 1 50 "unbalanced bwidth with unbalanced delay"
+run_test 30 10 50 1 "unbalanced bwidth with opposed, unbalanced delay"
+exit $ret
\ No newline at end of file
Signature · 1 line
2.26.2
#2 lore raw

[MPTCP] Re: [RFC PATCH 01/12] mptcp: msk is writable according to msk write space

In reply to Paolo Abeni
Quoted 6 lines · Paolo Abeni

Currently, when checking for the 'msk is writable' condition, we look at the individual subflows write space. That works well while we sends data via a single subflow, but will not as soon as we will enable concurrent xmit on multiple subflows.

Let's use the msk write space instead.

Why do we need MPTCP_SEND_SPACE bit after this change?

Quoted 11 lines
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 42 ++++++++++++++++++++++++------------------
 net/mptcp/subflow.c  |  3 +--
 2 files changed, 25 insertions(+), 20 deletions(-)
net/mptcp/protocol.c +0 -0
index 3b9ae98c67bb..d51b1d95dfb8 100644

net/mptcp/protocol.c static void mptcp_clean_una(struct sock *sk) · line 616

Quoted 6 lines
net/mptcp/protocol.c +2 -1
@@ -612,8 +612,15 @@ static void mptcp_clean_una(struct sock *sk)
 		sk_mem_reclaim_partial(sk);
 
 		/* Only wake up writers if a subflow is ready */
-		if (test_bit(MPTCP_SEND_SPACE, &msk->flags))
+		if (sk_stream_is_writeable(sk)) {
+			set_bit(MPTCP_SEND_SPACE, &mptcp_sk(sk)->flags);

mptcp sk has enough wmem, so MPTCP_SEND_SPACE is set.

net/mptcp/protocol.c static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, · line 814

Quoted 11 lines
net/mptcp/protocol.c +4 -1
@@ -799,21 +806,27 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	return ret;
 }
 
-static void mptcp_nospace(struct mptcp_sock *msk, struct socket *sock)
+static void mptcp_nospace(struct sock *sk, struct sock *ssk)
 {
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct socket *sock;
+
 	clear_bit(MPTCP_SEND_SPACE, &msk->flags);

This clears it, helper is called when msk wmem occupancy is too large.

net/mptcp/subflow.c static void subflow_write_space(struct sock *sk) · line 930

Quoted 12 lines
net/mptcp/subflow.c +1 -2
index 7e838bc6e364..bd2201d62ae6 100644
@@ -926,8 +926,7 @@ static void subflow_write_space(struct sock *sk)
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct sock *parent = subflow->conn;
 
-	sk_stream_write_space(sk);
-	if (sk_stream_is_writeable(sk)) {
+	if (sk_stream_is_writeable(parent)) {
 		set_bit(MPTCP_SEND_SPACE, &mptcp_sk(parent)->flags);

here, its set again when wmem occupancy of msk is low enough again.

So, AFAICS we can just remove it completely.

If not, perhaps add a comment as to what its signalling vs. 'msk is writeable/not writeable'.

Otherwise looks like a good cleanup to me.

#6 lore raw

[MPTCP] Re: [RFC PATCH 03/12] mptcp: trigger msk processing even for OoO data

In reply to Paolo Abeni

net/mptcp/protocol.h mptcp_subflow_rsk(const struct request_sock *rsk) · line 272

Quoted 10 lines · Paolo Abeni
net/mptcp/protocol.h +2 -0
index beb34b8a5363..e964f3670d75 100644
@@ -268,6 +268,9 @@ mptcp_subflow_rsk(const struct request_sock *rsk)
 	return (struct mptcp_subflow_request_sock *)rsk;
 }
 
+#define MPTCP_SUBFLOW_DATA_AVAIL	1
+#define MPTCP_SUBFLOW_OOO_DATA		2

Nit: maybe make this an enum. OTOH, at the end of the series, OOO_DATA seems to be set but never used?
Is this for a future patch [or maybe i made a mistake applying the series to my local tree and its used after all...]

net/mptcp/protocol.h struct mptcp_subflow_context { · line 298

Quoted 9 lines
net/mptcp/protocol.h +1 -1
 /* MPTCP subflow context */
 struct mptcp_subflow_context {
 	struct	list_head node;/* conn_list of subflows */
@@ -292,7 +295,7 @@ struct mptcp_subflow_context {
 		map_valid : 1,
 		mpc_map : 1,
 		backup : 1,
-		data_avail : 1,
+		data_avail : 2,

... so this is 'enum mptcp_data_avail data_avail'. Just a suggestion of course.

#10 lore raw

[MPTCP] Re: [RFC PATCH 04/12] mptcp: basic sndbuf autotuning

In reply to Paolo Abeni
Quoted 4 lines · Paolo Abeni

Let the msk sendbuf track the size of the larger subflow's send buffer.

The update is performed just before try to send any data.

Looks good, small nit:

net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 951

Quoted 4 lines
net/mptcp/protocol.c +4 -0
+	/* do auto tuning */
+	if (!(sk->sk_userlocks & SOCK_RCVBUF_LOCK) &&
+	    sndbuf > READ_ONCE(sk->sk_sndbuf))
+		WRITE_ONCE(sk->sk_sndbuf, sndbuf);

SOCK_SNDBUF_LOCK

Acked-by on v1 5/12
#12 lore raw

[MPTCP] Re: [RFC PATCH 05/12] mptcp: introduce and use mptcp_try_coalesce()

In reply to Paolo Abeni
Quoted 2 lines · Paolo Abeni

Factor-out existing code, will be re-used by the
next patch.

Acked-by Florian Westphal <fw(a)strlen.de>
#15 lore raw

[MPTCP] Re: [RFC PATCH 07/12] mptcp: cleanup mptcp_subflow_discard_data()

In reply to Paolo Abeni

Paolo Abeni <pabeni(a)redhat.com> wrote:

Hmmm, a changelog would have been nice 8-)

net/mptcp/subflow.c static enum mapping_status get_mapping_status(struct sock *ssk, · line 769

Quoted 10 lines
net/mptcp/subflow.c +0 -10
-	/* discard mapped data */
-	pr_debug("discarding %zu bytes, current map len=%d", delta,
-		 map_remaining);
-	if (delta) {
-		read_descriptor_t desc = {
-			.count = delta,
-		};
-		int ret;
-
-		ret = tcp_read_sock(ssk, &desc, subflow_read_actor);

tcp_read_sock tosses 'delta' bytes, and may zap multiple skbs, but after this change only at most one skb gets tossed.

Quoted 2 lines

return 0;
}

Nit: After this change, mptcp_subflow_discard_data() always returns 0.

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 828

Quoted 7 lines
net/mptcp/subflow.c +1 -1
@@ -853,7 +824,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
 		/* only accept in-sequence mapping. Old values are spurious
 		 * retransmission
 		 */
-		if (mptcp_subflow_discard_data(ssk, old_ack - ack_seq))
+		if (mptcp_subflow_discard_data(ssk, skb, old_ack - ack_seq))
 			goto fatal;

... so this conditional can be removed.

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 829

Quoted 1 line
net/mptcp/subflow.c +0 -0
 		return false;

Wouldn't it make sense to get rid of the return false too so that this checks if there is another skb to process? This would also obsolete my 'may zap multiple skbs' comment above since the caller would invoke the discard helper again if next skb is also outdated.

#18 lore raw

[MPTCP] Re: [RFC PATCH 08/12] mptcp: add OoO related mibs

In reply to Paolo Abeni
Quoted 2 lines · Paolo Abeni

Add a bunch of MPTCP mibs related to MPTCP OoO data processing.

It also adds a few pr_debug, was that intentional to mix it? I don't mind, just asking.

Having these MIB is a good thing, thanks for adding them.

#22 lore raw

[MPTCP] Re: [RFC PATCH 09/12] mptcp: move address attribute into mptcp_addr_info

In reply to Paolo Abeni

net/mptcp/protocol.h struct mptcp_addr_info { · line 144

Quoted 10 lines · Paolo Abeni
net/mptcp/protocol.h +2 -0
index dfcd7eab35ad..5467eb1adebd 100644
@@ -140,6 +140,8 @@ struct mptcp_addr_info {
 	sa_family_t		family;
 	__be16			port;
 	u8			id;
+	unsigned int		flags;
+	int			ifindex;

Nit: u8 flags? There are only 3 so far AFAICS.

#25 lore raw

[MPTCP] Re: [RFC PATCH 11/12] mptcp: allow picking different xmit subflows

In reply to Paolo Abeni
Quoted 20 lines · Paolo Abeni

Update the scheduler to less trivial heuristic: cache the last used subflow, and try to send on it a reasonably long burst of data. When the burst or the subflow send space is exausted, move to the next one with available send space.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 112 +++++++++++++++++++++++++++++++++++++------
 net/mptcp/protocol.h |   6 ++-
 2 files changed, 101 insertions(+), 17 deletions(-)
net/mptcp/protocol.c +0 -0
index ef5b68c4ff49..89c0400593d1 100644
@@ -1012,39 +1012,112 @@ static void mptcp_nospace(struct sock *sk, struct sock *ssk)
 		set_bit(SOCK_NOSPACE, &sock->flags);
 }
 

net/mptcp/protocol.c static void mptcp_nospace(struct sock *sk, struct sock *ssk) · line 1024

Quoted 10 lines
net/mptcp/protocol.c +10 -0
+static bool mptcp_subflow_active(struct mptcp_subflow_context *subflow,
+				 bool fallback)
+{
+	struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+	/* subflow must be open for write */
+	if ((1 << ssk->sk_state) &
+	    (TCPF_CLOSE | TCPF_LAST_ACK | TCPF_CLOSING | TCPF_FIN_WAIT2 |
+	     TCPF_FIN_WAIT1))
+		return false;

Hmmm, why is this not checking for TCP_ESTABLISHED -> true, rather than checking 'states i do not want'?

net/mptcp/protocol.c static void mptcp_nospace(struct sock *sk, struct sock *ssk) · line 1029

Quoted 4 lines
net/mptcp/protocol.c +4 -0
+	/* we can xmit on MPC and fallen back subflows in
+	 * TCP_SYN_SENT/TCP_SYN_RECV status, but we need fully established
+	 * MP_JOIN subflows.
+	 */

I don't understand this comment. The part with 'fully established MP_JOIN' is clear to me.

Is this about SYN_SENT state is fine if ssk tested is the 'msk->first' subflow?

If so, it might make sense to re-arrange the check to something like 'subflow->request_join && established && subflow->fully_established && !fallback' -> return true
else, return state == ESTABLISHED?

or even, ".. else subflow requal to msk->first and state eq ESTABLISHED return true'?

net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 1218

Quoted 6 lines
net/mptcp/protocol.c +1 -0
 static void ssk_check_wmem(struct sock *sk, struct sock *ssk)
@@ -1142,6 +1215,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		}
 
 		copied += ret;
+		msk->snd_burst -= ret;

Maybe add a comment that ret > snd_burst is fine.

net/mptcp/protocol.c static bool __mptcp_move_skbs(struct mptcp_sock *msk) · line 1436

Quoted 8 lines
net/mptcp/protocol.c +2 -0
 		tx_ok = msg_data_left(msg);
 		if (!tx_ok)
@@ -1358,6 +1432,10 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 	unsigned int moved = 0;
 	bool done;
 
+	if (((struct sock *)msk)->sk_state == TCP_CLOSE)
+		return false;

This looks funny -- why is this needed?

net/mptcp/protocol.c static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk) · line 1604

Quoted 12 lines
net/mptcp/protocol.c +3 -0
 static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)
 {
+	bool fallback = __mptcp_check_fallback(msk);
 	struct mptcp_subflow_context *subflow;
 	struct sock *backup = NULL;
@@ -1521,6 +1600,9 @@ static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 
+		if (!mptcp_subflow_active(subflow, fallback))
+			continue;

Hmm, should this be a separate bug fix (prevent non-fully-established-join)?

#31 lore raw
In reply to Paolo Abeni
Quoted 4 lines · Paolo Abeni

The pain point is the in-window check:

on the receiver side msk rcv window is set at tcp_space(msk) - which should be a quite rough over-estimante of a more correct value.

Can you elaborate?

Quoted 3 lines

on the sender side no limit is imposed on the xmitted sequence number, except the one given by the sndbuf. The msk sndbuf is autotuned to the subflows largest sndbuf size.

Yes, I agree the amount of data we can send should be capped by the last dss-rwin we saw as well, which we don't track ATM.

But this can be added later, sndbuf alone is good enough for the initial step i think.

author
#7 lore raw

[MPTCP] Re: [RFC PATCH 03/12] mptcp: trigger msk processing even for OoO data

In reply to Florian Westphal
Quoted 9 lines · Florian Westphal
Quoted 8 lines · Paolo Abeni
net/mptcp/protocol.h +0 -0
index beb34b8a5363..e964f3670d75 100644
@@ -268,6 +268,9 @@ mptcp_subflow_rsk(const struct request_sock *rsk)
 	return (struct mptcp_subflow_request_sock *)rsk;
 }
 
Quoted 4 lines

net/mptcp/protocol.h mptcp_subflow_rsk(const struct request_sock *rsk) · line 272

Quoted 2 lines
net/mptcp/protocol.h +2 -0
+#define MPTCP_SUBFLOW_DATA_AVAIL	1
+#define MPTCP_SUBFLOW_OOO_DATA		2

Nit: maybe make this an enum.

And move it outside the bitfield, right? well, looks like the standard should allows that, but I would prefer not mixing enum and int into the bitfield...

Quoted 2 lines

OTOH, at the end of the series,
OOO_DATA seems to be set but never used?

It' used "indirectly" in mptcp_data_ready(). The latter is called when data_avail != 0, but wakes-up the reader only if

	data_avail == MPTCP_SUBFLOW_DATA_AVAIL

otherwise (data_avail == MPTCP_SUBFLOW_OOO_DATA) moves only the data to the ooo queue.

Thanks!

/P

author
#16 lore raw

[MPTCP] Re: [RFC PATCH 07/12] mptcp: cleanup mptcp_subflow_discard_data()

In reply to Florian Westphal
Quoted 3 lines · Florian Westphal

Paolo Abeni <pabeni(a)redhat.com> wrote:

Hmmm, a changelog would have been nice 8-)

whoops... I added the comments to most patch just before the submit, but I forgot about this one...

Quoted 30 lines

net/mptcp/subflow.c static enum mapping_status get_mapping_status(struct sock *ssk, · line 769

Quoted 11 lines
net/mptcp/subflow.c +0 -10
-	/* discard mapped data */
-	pr_debug("discarding %zu bytes, current map len=%d", delta,
-		 map_remaining);
-	if (delta) {
-		read_descriptor_t desc = {
-			.count = delta,
-		};
-		int ret;
-
-		ret = tcp_read_sock(ssk, &desc, subflow_read_actor);

tcp_read_sock tosses 'delta' bytes, and may zap multiple skbs, but after this change only at most one skb gets tossed.

Quoted 2 lines

return 0;
}

Nit: After this change, mptcp_subflow_discard_data() always returns 0.

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 828

Quoted 7 lines
net/mptcp/subflow.c +1 -1
@@ -853,7 +824,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
 		/* only accept in-sequence mapping. Old values are spurious
 		 * retransmission
 		 */
-		if (mptcp_subflow_discard_data(ssk, old_ack - ack_seq))
+		if (mptcp_subflow_discard_data(ssk, skb, old_ack - ack_seq))
 			goto fatal;

... so this conditional can be removed.

Quoted 6 lines

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 829

Quoted 1 line
net/mptcp/subflow.c +0 -0
 		return false;

Wouldn't it make sense to get rid of the return false too so that this checks if there is another skb to process? This would also obsolete my 'may zap multiple skbs' comment above since the caller would invoke the discard helper again if next skb is also outdated.

Yep, will look at this option.

Thanks!

/P

author
#26 lore raw

[MPTCP] Re: [RFC PATCH 11/12] mptcp: allow picking different xmit subflows

In reply to Florian Westphal
Quoted 21 lines · Florian Westphal
Quoted 20 lines · Paolo Abeni

Update the scheduler to less trivial heuristic: cache the last used subflow, and try to send on it a reasonably long burst of data. When the burst or the subflow send space is exausted, move to the next one with available send space.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 112 +++++++++++++++++++++++++++++++++++++------
 net/mptcp/protocol.h |   6 ++-
 2 files changed, 101 insertions(+), 17 deletions(-)
net/mptcp/protocol.c +0 -0
index ef5b68c4ff49..89c0400593d1 100644
@@ -1012,39 +1012,112 @@ static void mptcp_nospace(struct sock *sk, struct sock *ssk)
 		set_bit(SOCK_NOSPACE, &sock->flags);
 }
 
Quoted 13 lines

net/mptcp/protocol.c static void mptcp_nospace(struct sock *sk, struct sock *ssk) · line 1024

Quoted 10 lines
net/mptcp/protocol.c +10 -0
+static bool mptcp_subflow_active(struct mptcp_subflow_context *subflow,
+				 bool fallback)
+{
+	struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+	/* subflow must be open for write */
+	if ((1 << ssk->sk_state) &
+	    (TCPF_CLOSE | TCPF_LAST_ACK | TCPF_CLOSING | TCPF_FIN_WAIT2 |
+	     TCPF_FIN_WAIT1))
+		return false;

Hmmm, why is this not checking for TCP_ESTABLISHED -> true, rather than checking 'states i do not want'?

I think we can pick a subflow for xmit even after receiving a TCP FIN on such subflows, so the subflow status could be different from TCP_ESTABLISHED.

To my twiested mind was more natural check for not allowed states, I can flip to allowed one if needed.

Quoted 10 lines

net/mptcp/protocol.c static void mptcp_nospace(struct sock *sk, struct sock *ssk) · line 1029

Quoted 4 lines
net/mptcp/protocol.c +4 -0
+	/* we can xmit on MPC and fallen back subflows in
+	 * TCP_SYN_SENT/TCP_SYN_RECV status, but we need fully established
+	 * MP_JOIN subflows.
+	 */

I don't understand this comment. The part with 'fully established MP_JOIN' is clear to me.

Is this about SYN_SENT state is fine if ssk tested is the 'msk->first' subflow?

yes, exactly.

Quoted 7 lines

If so, it might make sense to re-arrange the check to something like 'subflow->request_join && established && subflow->fully_established && !fallback' -> return true
else, return state == ESTABLISHED?

or even, ".. else subflow requal to msk->first and state eq ESTABLISHED return true'?

I think we need to check for more TCP states than ESTABLISHED for both first and MP_JOIN subflow. For '->first' we should additionally allow SYN_SENT and TCP_SYN_RECV. Not sure the above will simplify ?!?

Quoted 16 lines

net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 1218

Quoted 7 lines
net/mptcp/protocol.c +1 -0
 static void ssk_check_wmem(struct sock *sk, struct sock *ssk)
@@ -1142,6 +1215,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		}
 
 		copied += ret;
+		msk->snd_burst -= ret;

Maybe add a comment that ret > snd_burst is fine.

Quoted 6 lines
net/mptcp/protocol.c +0 -0
 		tx_ok = msg_data_left(msg);
 		if (!tx_ok)
@@ -1358,6 +1432,10 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 	unsigned int moved = 0;
 	bool done;
 
Quoted 4 lines

net/mptcp/protocol.c static bool __mptcp_move_skbs(struct mptcp_sock *msk) · line 1436

Quoted 2 lines
net/mptcp/protocol.c +2 -0
+	if (((struct sock *)msk)->sk_state == TCP_CLOSE)
+		return false;

This looks funny -- why is this needed?

mptcp workqueue is called on a subflow with empty rx queue - flushed by __mptcp_close_ssk - and not null data_avail. __mptcp_move_skbs() will loop forever. I can likely clear data_avail in __mptcp_close_ssk(), but never tried.

Quoted 6 lines
Quoted 6 lines
net/mptcp/protocol.c +1 -0
 static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)
 {
+	bool fallback = __mptcp_check_fallback(msk);
 	struct mptcp_subflow_context *subflow;
 	struct sock *backup = NULL;
Quoted 8 lines

net/mptcp/protocol.c static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk) · line 1604

Quoted 6 lines
net/mptcp/protocol.c +2 -0
@@ -1521,6 +1600,9 @@ static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
 
+		if (!mptcp_subflow_active(subflow, fallback))
+			continue;

Hmm, should this be a separate bug fix (prevent non-fully-established-join)?

I think the bug is only apparent after we have non backup subflows and/or remove addr support ?!?

reinjection will likely need revisiting, but I haven't looked at that yet.

/P

author
#19 lore raw

[MPTCP] Re: [RFC PATCH 08/12] mptcp: add OoO related mibs

In reply to Florian Westphal
Quoted 6 lines · Florian Westphal
Quoted 2 lines · Paolo Abeni

Add a bunch of MPTCP mibs related to MPTCP OoO data processing.

It also adds a few pr_debug, was that intentional to mix it? I don't mind, just asking.

Sort of intentional, I squashed some local patches and I kept the debug message here because somehow related.

Can be moved or dropped, as you prefer.

Thanks,

Paolo

#8 lore raw

[MPTCP] Re: [RFC PATCH 03/12] mptcp: trigger msk processing even for OoO data

In reply to Paolo Abeni
Quoted 10 lines · Paolo Abeni
Quoted 9 lines · Florian Westphal
Quoted 8 lines · Paolo Abeni
net/mptcp/protocol.h +0 -0
index beb34b8a5363..e964f3670d75 100644
@@ -268,6 +268,9 @@ mptcp_subflow_rsk(const struct request_sock *rsk)
 	return (struct mptcp_subflow_request_sock *)rsk;
 }
 
Quoted 8 lines
Quoted 4 lines

net/mptcp/protocol.h mptcp_subflow_rsk(const struct request_sock *rsk) · line 272

Quoted 2 lines
net/mptcp/protocol.h +2 -0
+#define MPTCP_SUBFLOW_DATA_AVAIL	1
+#define MPTCP_SUBFLOW_OOO_DATA		2

Nit: maybe make this an enum.

And move it outside the bitfield, right? well, looks like the standard should allows that, but I would prefer not mixing enum and int into the bitfield...

I would not mix it with bitfield either.

Quoted 7 lines
Quoted 2 lines

OTOH, at the end of the series,
OOO_DATA seems to be set but never used?

It' used "indirectly" in mptcp_data_ready(). The latter is called when data_avail != 0, but wakes-up the reader only if

	data_avail == MPTCP_SUBFLOW_DATA_AVAIL

Ah, yes, thanks for explaining.

#20 lore raw

[MPTCP] Re: [RFC PATCH 08/12] mptcp: add OoO related mibs

In reply to Paolo Abeni
Quoted 5 lines · Paolo Abeni
Quoted 4 lines · Florian Westphal
Quoted 2 lines · Paolo Abeni

Add a bunch of MPTCP mibs related to MPTCP OoO data processing.

Quoted 7 lines
Quoted 2 lines

It also adds a few pr_debug, was that intentional to mix it? I don't mind, just asking.

Sort of intentional, I squashed some local patches and I kept the debug message here because somehow related.

Can be moved or dropped, as you prefer.

I think its good as-is.

#27 lore raw

[MPTCP] Re: [RFC PATCH 11/12] mptcp: allow picking different xmit subflows

In reply to Paolo Abeni
Quoted 36 lines · Paolo Abeni
Quoted 21 lines · Florian Westphal
Quoted 20 lines · Paolo Abeni

Update the scheduler to less trivial heuristic: cache the last used subflow, and try to send on it a reasonably long burst of data. When the burst or the subflow send space is exausted, move to the next one with available send space.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 112 +++++++++++++++++++++++++++++++++++++------
 net/mptcp/protocol.h |   6 ++-
 2 files changed, 101 insertions(+), 17 deletions(-)
net/mptcp/protocol.c +0 -0
index ef5b68c4ff49..89c0400593d1 100644
@@ -1012,39 +1012,112 @@ static void mptcp_nospace(struct sock *sk, struct sock *ssk)
 		set_bit(SOCK_NOSPACE, &sock->flags);
 }
 
Quoted 13 lines

net/mptcp/protocol.c static void mptcp_nospace(struct sock *sk, struct sock *ssk) · line 1024

Quoted 10 lines
net/mptcp/protocol.c +10 -0
+static bool mptcp_subflow_active(struct mptcp_subflow_context *subflow,
+				 bool fallback)
+{
+	struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+	/* subflow must be open for write */
+	if ((1 << ssk->sk_state) &
+	    (TCPF_CLOSE | TCPF_LAST_ACK | TCPF_CLOSING | TCPF_FIN_WAIT2 |
+	     TCPF_FIN_WAIT1))
+		return false;

Hmmm, why is this not checking for TCP_ESTABLISHED -> true, rather than checking 'states i do not want'?

Quoted 6 lines

I think we can pick a subflow for xmit even after receiving a TCP FIN on such subflows, so the subflow status could be different from TCP_ESTABLISHED.

To my twiested mind was more natural check for not allowed states, I can flip to allowed one if needed.

I would prefer that. Otherwise I have to invert manually during review, and this makes no sense to me when I do the negation:

States:
TCPF_ESTABLISHED = (1 << TCP_ESTABLISHED),

TCPF_SYN_SENT    = (1 << TCP_SYN_SENT),
TCPF_SYN_RECV    = (1 << TCP_SYN_RECV),
TCPF_FIN_WAIT1   = (1 << TCP_FIN_WAIT1),
TCPF_FIN_WAIT2   = (1 << TCP_FIN_WAIT2),
TCPF_TIME_WAIT   = (1 << TCP_TIME_WAIT),
TCPF_CLOSE       = (1 << TCP_CLOSE),
TCPF_CLOSE_WAIT  = (1 << TCP_CLOSE_WAIT),
TCPF_LAST_ACK    = (1 << TCP_LAST_ACK),
TCPF_LISTEN      = (1 << TCP_LISTEN),
TCPF_CLOSING     = (1 << TCP_CLOSING),

TCPF_NEW_SYN_RECV = (1 << TCP_NEW_SYN_RECV),

So, above checks disables:

TCPF_CLOSE       = (1 << TCP_CLOSE),
TCPF_LAST_ACK    = (1 << TCP_LAST_ACK),
TCPF_CLOSING     = (1 << TCP_CLOSING),
TCPF_FIN_WAIT1   = (1 << TCP_FIN_WAIT1),
TCPF_FIN_WAIT2   = (1 << TCP_FIN_WAIT2),

... which makes following ok:

TCPF_ESTABLISHED = (1 << TCP_ESTABLISHED),

Agree on that.

TCPF_SYN_SENT = (1 << TCP_SYN_SENT),

we don't know yet if connection will complete, or if mptcp will be available.

TCPF_SYN_RECV = (1 << TCP_SYN_RECV),

same.

TCPF_TIME_WAIT = (1 << TCP_TIME_WAIT),

This is also strange, this is a quiesence period to catch in-flight packets. I don't think this subflow should still be used for xmit.

TCPF_CLOSE_WAIT = (1 << TCP_CLOSE_WAIT),

Agree on this one as well -- its ok to xmit here.

TCPF_LISTEN = (1 << TCP_LISTEN),

Should not happen of course, but its definitely
not usable :-)

TCPF_NEW_SYN_RECV = (1 << TCP_NEW_SYN_RECV),

and that is... mhhh... strange. Why is this one ok?

Checking 'fallback' made no sense to me. Why do we need to check for this?

Am I missing anything? If yes, please add a comment explaining that scenario. Same for fallback, I do not understand how fallback yes/no makes a difference here.

Quoted 7 lines
Quoted 5 lines

I don't understand this comment. The part with 'fully established MP_JOIN' is clear to me.

Is this about SYN_SENT state is fine if ssk tested is the 'msk->first' subflow?

yes, exactly.

Ok. Would still like to understand how this can occur (data to transmit, first connection not established yet).

Quoted 11 lines
Quoted 7 lines

If so, it might make sense to re-arrange the check to something like 'subflow->request_join && established && subflow->fully_established && !fallback' -> return true
else, return state == ESTABLISHED?

or even, ".. else subflow requal to msk->first and state eq ESTABLISHED return true'?

I think we need to check for more TCP states than ESTABLISHED for both first and MP_JOIN subflow. For '->first' we should additionally allow SYN_SENT and TCP_SYN_RECV. Not sure the above will simplify ?!?

Check for syn sent/recv makes no sense to me. How can we get data to send at this point?

I would propose something like:

static bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);

/* can't send if JOIN hasn't completed yet (i.e. is usable for mptcp) */ if (subflow->request_join && !subflow->fully_established)

     return false;

/* only send if our side has not closed yet */
return ((1 << ssk->sk_state) & (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT));
}

Way less cases/tests. What breaks/is missing here?

Quoted 9 lines
Quoted 8 lines

net/mptcp/protocol.c static bool __mptcp_move_skbs(struct mptcp_sock *msk) · line 1436

Quoted 6 lines
net/mptcp/protocol.c +2 -0
@@ -1358,6 +1432,10 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk)
 	unsigned int moved = 0;
 	bool done;
 
+	if (((struct sock *)msk)->sk_state == TCP_CLOSE)
+		return false;

This looks funny -- why is this needed?

Quoted 4 lines

mptcp workqueue is called on a subflow with empty rx queue - flushed by __mptcp_close_ssk - and not null data_avail. __mptcp_move_skbs() will loop forever. I can likely clear data_avail in __mptcp_close_ssk(), but never tried.

Ok, if that doesn't work please just add a small comment with above explanation. Thanks.

Quoted 4 lines
Quoted 1 line

Hmm, should this be a separate bug fix (prevent non-fully-established-join)?

I think the bug is only apparent after we have non backup subflows and/or remove addr support ?!?

What about other mptcp stack peer? Couldn't they create a non-backup flow?

[ I don't mind if you don't want a separate patch for this, it just looked like a small fix to me that could be applied already ]

author
#28 lore raw

[MPTCP] Re: [RFC PATCH 11/12] mptcp: allow picking different xmit subflows

Quoted 93 lines · Florian Westphal
Quoted 36 lines · Paolo Abeni
Quoted 21 lines · Florian Westphal
Quoted 20 lines · Paolo Abeni

Update the scheduler to less trivial heuristic: cache the last used subflow, and try to send on it a reasonably long burst of data. When the burst or the subflow send space is exausted, move to the next one with available send space.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 112 +++++++++++++++++++++++++++++++++++++------
 net/mptcp/protocol.h |   6 ++-
 2 files changed, 101 insertions(+), 17 deletions(-)
net/mptcp/protocol.c +0 -0
index ef5b68c4ff49..89c0400593d1 100644
@@ -1012,39 +1012,112 @@ static void mptcp_nospace(struct sock *sk, struct sock *ssk)
 		set_bit(SOCK_NOSPACE, &sock->flags);
 }
 
Quoted 13 lines

net/mptcp/protocol.c static void mptcp_nospace(struct sock *sk, struct sock *ssk) · line 1024

Quoted 10 lines
net/mptcp/protocol.c +10 -0
+static bool mptcp_subflow_active(struct mptcp_subflow_context *subflow,
+				 bool fallback)
+{
+	struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+	/* subflow must be open for write */
+	if ((1 << ssk->sk_state) &
+	    (TCPF_CLOSE | TCPF_LAST_ACK | TCPF_CLOSING | TCPF_FIN_WAIT2 |
+	     TCPF_FIN_WAIT1))
+		return false;

Hmmm, why is this not checking for TCP_ESTABLISHED -> true, rather than checking 'states i do not want'?

Quoted 6 lines

I think we can pick a subflow for xmit even after receiving a TCP FIN on such subflows, so the subflow status could be different from TCP_ESTABLISHED.

To my twiested mind was more natural check for not allowed states, I can flip to allowed one if needed.

I would prefer that. Otherwise I have to invert manually during review, and this makes no sense to me when I do the negation:

States:
TCPF_ESTABLISHED = (1 << TCP_ESTABLISHED),

TCPF_SYN_SENT    = (1 << TCP_SYN_SENT),
TCPF_SYN_RECV    = (1 << TCP_SYN_RECV),
TCPF_FIN_WAIT1   = (1 << TCP_FIN_WAIT1),
TCPF_FIN_WAIT2   = (1 << TCP_FIN_WAIT2),
TCPF_TIME_WAIT   = (1 << TCP_TIME_WAIT),
TCPF_CLOSE       = (1 << TCP_CLOSE),
TCPF_CLOSE_WAIT  = (1 << TCP_CLOSE_WAIT),
TCPF_LAST_ACK    = (1 << TCP_LAST_ACK),
TCPF_LISTEN      = (1 << TCP_LISTEN),
TCPF_CLOSING     = (1 << TCP_CLOSING),

TCPF_NEW_SYN_RECV = (1 << TCP_NEW_SYN_RECV),

So, above checks disables:

TCPF_CLOSE       = (1 << TCP_CLOSE),
TCPF_LAST_ACK    = (1 << TCP_LAST_ACK),
TCPF_CLOSING     = (1 << TCP_CLOSING),
TCPF_FIN_WAIT1   = (1 << TCP_FIN_WAIT1),
TCPF_FIN_WAIT2   = (1 << TCP_FIN_WAIT2),

... which makes following ok:

TCPF_ESTABLISHED = (1 << TCP_ESTABLISHED),

Agree on that.

TCPF_SYN_SENT = (1 << TCP_SYN_SENT),

we don't know yet if connection will complete, or if mptcp will be available.

TCPF_SYN_RECV = (1 << TCP_SYN_RECV),

same.

TCPF_TIME_WAIT = (1 << TCP_TIME_WAIT),

This is also strange, this is a quiesence period to catch in-flight packets. I don't think this subflow should still be used for xmit.

TCPF_CLOSE_WAIT = (1 << TCP_CLOSE_WAIT),

Agree on this one as well -- its ok to xmit here.

Quoted 8 lines

TCPF_LISTEN = (1 << TCP_LISTEN),

Should not happen of course, but its definitely
not usable :-)

TCPF_NEW_SYN_RECV = (1 << TCP_NEW_SYN_RECV),

and that is... mhhh... strange. Why is this one ok?

Agreed to the above - we also aready have sk_stream_wait_connect() if state is not TCPF_ESTABLISHED | TCPF_CLOSE_WAIT.

Quoted 1 line

Checking 'fallback' made no sense to me. Why do we need to check for this?

In teory we should not have additional subflows in the fallback status, but we can have an MPJ handskake and fallback racing togethar, so we end-up with msk in fallback status and one or more fully established subflows. If/when that happen we must avoid picking mpj subflows.

Perhaps is just easier/clearer add an explict (unlikely???) case in mptcp_subflow_get_send() and mptcp_subflow_get_retrans()

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Hmm, should this be a separate bug fix (prevent non-fully-established-join)?

I think the bug is only apparent after we have non backup subflows and/or remove addr support ?!?

What about other mptcp stack peer? Couldn't they create a non-backup flow?

[ I don't mind if you don't want a separate patch for this, it just looked like a small fix to me that could be applied already ]

yep, we can have non backup subflows with mptcp.org peers. I still would opt for a single patch ;)

/P

#29 lore raw

[MPTCP] Re: [RFC PATCH 11/12] mptcp: allow picking different xmit subflows

Quoted 6 lines · Paolo Abeni
Quoted 1 line

Checking 'fallback' made no sense to me. Why do we need to check for this?

In teory we should not have additional subflows in the fallback status, but we can have an MPJ handskake and fallback racing togethar, so we end-up with msk in fallback status and one or more fully established subflows. If/when that happen we must avoid picking mpj subflows.

That sounds bad. I'd suggest to make sure that we only use msk->first if msk is marked fallback.

Quoted 2 lines

Perhaps is just easier/clearer add an explict (unlikely???) case in mptcp_subflow_get_send() and mptcp_subflow_get_retrans()

Agree, its easier to understand, at least.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Hmm, should this be a separate bug fix (prevent non-fully-established-join)?

I think the bug is only apparent after we have non backup subflows and/or remove addr support ?!?

Quoted 7 lines
Quoted 4 lines

What about other mptcp stack peer? Couldn't they create a non-backup flow?

[ I don't mind if you don't want a separate patch for this, it just looked like a small fix to me that could be applied already ]

yep, we can have non backup subflows with mptcp.org peers. I still would opt for a single patch ;)

Ok, fair enough, I thought you could split that from the series and get it merged already.

author
#3 lore raw

[MPTCP] Re: [RFC PATCH 01/12] mptcp: msk is writable according to msk write space

In reply to Florian Westphal
Quoted 9 lines · Florian Westphal
Quoted 6 lines · Paolo Abeni

Currently, when checking for the 'msk is writable' condition, we look at the individual subflows write space. That works well while we sends data via a single subflow, but will not as soon as we will enable concurrent xmit on multiple subflows.

Let's use the msk write space instead.

Why do we need MPTCP_SEND_SPACE bit after this change?

I'm testing without it, I see the following:

the msk is writable, but all the subflows have sk_stream_wspace() < 0.

The above can happen because we account the full truesize to ssk, while only the page frag size to the msk.

Note that checking:

	sk_stream_wspace(sk) > 0 && sk_stream_is_writeable(parent)

in subflow_write_space() is not enough, we also need mptcp_poll() returning a mask with EPOLLOUT cleared when all subflows have no write space.

Overall I think that keeping the flag around is the simplest option.

Cheers,

Paolo