mptcp: address stall under memory pressure
Subsystems (4)
Paolo Abeni
maintainercover mptcp: address stall under memory pressure
This an attempt to fix the data transfer stall reported by Geliang and Gang more carefully enforcing memory constraints at the MPTCP level.
Patch 1/9 moves the bound check before entering the TCP socket. Patch 2, 3 and 4 are cleanups/refactors finalized to safely re-using TCP helpers on MPTCP skbs.
Patch 5 makes TCP pruning related helpers available to MPTCP and patch 6 makes use of them. Patch 7 addresses an edge scenario that could still lead to transfer stall under memory pressure.
Finally patch 8 and 9 improve the MPTCP-level retransmission schema to make recovery from memory pressure significanly faster.
Note that the diffstat is biases by the quite large patch 4/9, which contains mechanical transformation of existing code; "real" changes are noticiable smaller.
Tested successfully vs the test cases proposed by Geliang and Gang.
---
RFC -> v1:
- dropped old patch 4 & 5
- addressed AI reported comments
- added retrans refactor.
Paolo Abeni (9):
mptcp: move checks vs rcvbuf size earlier in the RX path
mptcp: drop the mptcp_ooo_try_coalesce() helper
mptcp: remove CB offset field
mptcp: sync mptcp skb cb layout with tcp one
tcp: expose the tcp_collapse_ofo_queue() helper to mptcp usage, too
mptcp: implemented OoO queue pruning
mptcp: track prune recovery status
mptcp: move the retrans loop to a separate helper
mptcp: let the retrans scheduler do its job.
include/net/tcp.h | 8 ++ net/ipv4/tcp_input.c | 55 +++++--- net/mptcp/fastopen.c | 1 - net/mptcp/mib.c | 3 + net/mptcp/mib.h | 3 + net/mptcp/options.c | 55 +++++++- net/mptcp/protocol.c | 328 ++++++++++++++++++++++++++++--------------- net/mptcp/protocol.h | 11 +- net/mptcp/subflow.c | 2 + 9 files changed, 323 insertions(+), 143 deletions(-)
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 1/9 mptcp: move checks vs rcvbuf size earlier in the RX path
Currently the enforcement of the rcvbuf constraint is implemented when moving the skbs into the msk receive or OoO queue.
Under significant memory pressure the above can cause permanent data transfer stalls. Move the checks early on, before landing even in the subflow queues.
---
RFC -> v1:
- limit vs actual buffer size
- use CB info instead of skb->len
Note that:
- this needs the follow-up patches to really fix the stall
- the memory comparison is intentionally very rough, as the msk socket lock is not currently held where the condition is now enforced. This should require some refinement, shared as-is to avoid more latency on my side
--- net/mptcp/options.c | 18 ++++++++++++++++-- net/mptcp/protocol.c | 10 ++-------- 2 files changed, 18 insertions(+), 10 deletions(-)
net/mptcp/options.c +16 -2
@@ -1158,8 +1158,16 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,return hmac == mp_opt->ahmac; } -/* Return false in case of error (or subflow has been reset), -* else return true. +static bool mptcp_over_limit (const struct sock *sk,struct sk_buff *skb) +{ +if (TCP_SKB_CB (skb)->seq ==TCP_SKB_CB (skb)->end_seq) +return false; + +return sk_rmem_alloc_get (sk) >READ_ONCE (sk->sk_rcvbuf); +} + +/* Return false when the caller must drop the packet, i.e. in case of error, +* subflow has been reset, or over memory limits. */ bool mptcp_incoming_options (struct sock *sk,struct sk_buff *skb) {
@@ -1185,6 +1193,9 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)__mptcp_data_acked (subflow->conn);mptcp_data_unlock (subflow->conn); + +if (mptcp_over_limit (subflow->conn, skb)) +return false;return true; }
@@ -1263,6 +1274,9 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)return true; } +if (mptcp_over_limit (subflow->conn, skb)) +return false; + mpext =skb_ext_add (skb,SKB_EXT_MPTCP );if (!mpext)return false;
net/mptcp/protocol.c +2 -8
@@ -739,7 +739,7 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,mptcp_init_skb (ssk, skb, offset, len); -if (own_msk &&sk_rmem_alloc_get (sk) < sk->sk_rcvbuf) { +if (own_msk) {mptcp_subflow_lend_fwdmem (subflow, skb); ret |=__mptcp_move_skb (sk, skb); }else {
@@ -2197,10 +2197,6 @@ static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delt *delta =0 ;while (1 ) { -/* If the msk recvbuf is full stop, don't drop */ -if (sk_rmem_alloc_get (sk) > sk->sk_rcvbuf) -break ; -prefetch (skb->next);list_del (&skb->list); *delta += skb->truesize;
@@ -2228,9 +2224,7 @@ static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skbs)DEBUG_NET_WARN_ON_ONCE (msk->backlog_unaccounted && sk->sk_socket &&mem_cgroup_from_sk (sk)); -/* Don't spool the backlog if the rcvbuf is full. */ -if (list_empty (&msk->backlog_list) || -sk_rmem_alloc_get (sk) > sk->sk_rcvbuf) +if (list_empty (&msk->backlog_list))return false;INIT_LIST_HEAD (skbs);
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 2/9 mptcp: drop the mptcp_ooo_try_coalesce() helper
In reply to Paolo AbeniIt's used to save an additional comparison for in-order skbs, but is also a barrier to remove CB offset. Remove the helper, let __mptcp_try_coalesce() always perform the sequence check and remove duplicate checks from the callers.
--- net/mptcp/protocol.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
net/mptcp/protocol.c +6 -15
@@ -159,7 +159,8 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to, {int limit =READ_ONCE (sk->sk_rcvbuf); -if (unlikely (MPTCP_SKB_CB (to)->cant_coalesce) || +if (MPTCP_SKB_CB (from)->map_seq !=MPTCP_SKB_CB (to)->end_seq || +unlikely (MPTCP_SKB_CB (to)->cant_coalesce) ||MPTCP_SKB_CB (from)->offset || ((to->len + from->len) > (limit >>3 )) || !skb_try_coalesce (to, from, fragstolen, delta))
@@ -192,15 +193,6 @@ static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,return true; } -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_rcvbuf_grow(), main difference: * - mptcp does not maintain a msk-level window clamp * - returns true when the receive buffer is actually updated
@@ -275,7 +267,7 @@ 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_try_coalesce (sk, msk->ooo_last_skb, skb)) {MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_OFOMERGE );MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_OFOQUEUETAIL );return ;
@@ -321,7 +313,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_DUPDATA ); goto merge_right; } - }else if (mptcp_ooo_try_coalesce (msk, skb1, skb)) { + }else if (mptcp_try_coalesce (sk, skb1, skb)) {MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_OFOMERGE );return ; }
@@ -672,8 +664,7 @@ static void __mptcp_add_backlog(struct sock *sk,if (!list_empty (&msk->backlog_list)) tail = list_last_entry(&msk->backlog_list, struct sk_buff, list); -if (tail &&MPTCP_SKB_CB (skb)->map_seq ==MPTCP_SKB_CB (tail)->end_seq && - ssk == tail->sk && +if (tail && ssk == tail->sk &&__mptcp_try_coalesce (sk, tail, skb, &fragstolen, &delta)) { skb->truesize -= delta;kfree_skb_partial (skb, fragstolen);
@@ -797,7 +788,7 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk) 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)) { +if (!tail || !mptcp_try_coalesce (sk, tail, skb)) {int delta = msk->ack_seq -MPTCP_SKB_CB (skb)->map_seq;/* skip overlapping data, if any */
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 3/9 mptcp: remove CB offset field
In reply to Paolo AbeniInstead, to track the bytes already consumed inside each skb, use a msk-level new field, tracking the amount of bytes already copied to user-space, alike what TCP is already doing.
This simplify a bit the code and will make possible the next patch.
---
Note: this has the potential to break almost everything. On the flip side the CB->offset vs copied_seq difference from TCP is quite confusing and removing it will be for the good.
Also this explicitly relays on "mptcp: do not drop partial packets" to avoid dropping partially consumed packets
--- net/mptcp/fastopen.c | 1 - net/mptcp/protocol.c | 30 +++++++++++------------------- net/mptcp/protocol.h | 2 +- net/mptcp/subflow.c | 1 + 4 files changed, 13 insertions(+), 21 deletions(-)
net/mptcp/fastopen.c +0 -1
@@ -44,7 +44,6 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf/* Only the sequence delta is relevant */ MPTCP_SKB_CB (skb)->map_seq = -skb->len;MPTCP_SKB_CB (skb)->end_seq =0 ; -MPTCP_SKB_CB (skb)->offset =0 ;MPTCP_SKB_CB (skb)->has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;MPTCP_SKB_CB (skb)->cant_coalesce =1 ;
net/mptcp/protocol.c +11 -19
@@ -161,7 +161,6 @@ static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,if (MPTCP_SKB_CB (from)->map_seq !=MPTCP_SKB_CB (to)->end_seq ||unlikely (MPTCP_SKB_CB (to)->cant_coalesce) || -MPTCP_SKB_CB (from)->offset || ((to->len + from->len) > (limit >>3 )) || !skb_try_coalesce (to, from, fragstolen, delta))return false;
@@ -343,8 +342,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)skb_set_owner_r (skb, sk); } -static void mptcp_init_skb (struct sock *ssk,struct sk_buff *skb,int offset, -int copy_len) +static void mptcp_init_skb (struct sock *ssk,struct sk_buff *skb,int offset) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk);bool has_rxtstamp =TCP_SKB_CB (skb)->has_rxtstamp;
@@ -353,9 +351,8 @@ static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int 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; +MPTCP_SKB_CB (skb)->map_seq =mptcp_subflow_get_mapped_dsn (subflow) - offset; +MPTCP_SKB_CB (skb)->end_seq =MPTCP_SKB_CB (skb)->map_seq + skb->len;MPTCP_SKB_CB (skb)->has_rxtstamp = has_rxtstamp;MPTCP_SKB_CB (skb)->cant_coalesce =0 ;
@@ -728,7 +725,7 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,if (offset < skb->len) {size_t len = skb->len - offset; -mptcp_init_skb (ssk, skb, offset, len); +mptcp_init_skb (ssk, skb, offset);if (own_msk) {mptcp_subflow_lend_fwdmem (subflow, skb);
@@ -795,8 +792,6 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk)pr_debug ("uncoalesced seq=%llx ack seq=%llx delta=%d\n" ,MPTCP_SKB_CB (skb)->map_seq, msk->ack_seq, delta); -MPTCP_SKB_CB (skb)->offset += delta; -MPTCP_SKB_CB (skb)->map_seq += delta;__skb_queue_tail (&sk->sk_receive_queue, skb); } msk->bytes_received += end_seq - msk->ack_seq;
@@ -2050,7 +2045,7 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,int copied =0 ; skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) { -u32 delta, offset =MPTCP_SKB_CB (skb)->offset; +u32 delta, offset = msk->copied_seq -MPTCP_SKB_CB (skb)->map_seq;u32 data_len = skb->len - offset;u32 count;int err;
@@ -2088,11 +2083,9 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,if (!(flags &MSG_PEEK )) { msk->bytes_consumed += count; -if (count < data_len) { -MPTCP_SKB_CB (skb)->offset += count; -MPTCP_SKB_CB (skb)->map_seq += count; + msk->copied_seq += count; +if (count < data_len)break ; - }mptcp_eat_recv_skb (sk, skb); }else {
@@ -3457,6 +3450,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)/* for fallback's sake */ WRITE_ONCE (msk->ack_seq,0 ); +WRITE_ONCE (msk->copied_seq,0 );WRITE_ONCE (sk->sk_shutdown,0 );sk_error_report (sk);
@@ -4340,7 +4334,7 @@ static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)mptcp_move_skbs (sk);while ((skb =skb_peek (&sk->sk_receive_queue)) !=NULL ) { - offset =MPTCP_SKB_CB (skb)->offset; + offset = msk->copied_seq -MPTCP_SKB_CB (skb)->map_seq;if (offset < skb->len) { *off = offset;return skb;
@@ -4382,11 +4376,9 @@ static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc, copied += count; msk->bytes_consumed += count; -if (count < data_len) { -MPTCP_SKB_CB (skb)->offset += count; -MPTCP_SKB_CB (skb)->map_seq += count; + msk->copied_seq += count; +if (count < data_len)break ; - }mptcp_eat_recv_skb (sk, skb); }
net/mptcp/protocol.h +1 -1
@@ -128,7 +128,6 @@struct mptcp_skb_cb {u64 map_seq;u64 end_seq; -u32 offset;u8 has_rxtstamp;u8 cant_coalesce; };
@@ -289,6 +288,7 @@ struct mptcp_sock {u64 bytes_sent;u64 snd_nxt;u64 bytes_received; +u64 copied_seq;u64 ack_seq;atomic64_t rcv_wnd_sent;u64 rcv_data_fin_seq;
net/mptcp/subflow.c +1 -0
@@ -494,6 +494,7 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,WRITE_ONCE (msk->remote_key, subflow->remote_key);WRITE_ONCE (msk->ack_seq, subflow->iasn); +WRITE_ONCE (msk->copied_seq, subflow->iasn);WRITE_ONCE (msk->can_ack, true);atomic64_set (&msk->rcv_wnd_sent, subflow->iasn); }
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 4/9 mptcp: sync mptcp skb cb layout with tcp one
In reply to Paolo AbeniThe MPTCP protocol uses a significantly different CB layout WRT TCP, as it includes different information and use 64 bits for the sequence numbers.
As the msk-level rcvbuf buffer size is limited by the core socket code the INT_MAX, we can safely use 32 bits for MPTCP-level sequence number. This allow updating the MPTCP CB layout so that fields with a corresponding TCP-level data use the same area inside the CB itself.
Add build time check the unsure the latter invariant.
---
rfc -> v1:
- keep ack_seq up2date
--- net/mptcp/protocol.c | 81 ++++++++++++++++++++++++++------------------ net/mptcp/protocol.h | 6 ++-- 2 files changed, 52 insertions(+), 35 deletions(-)
net/mptcp/protocol.c +48 -33
@@ -28,7 +28,7 @@#include "protocol.h" #include "mib.h" -static unsigned int mptcp_inq_hint (const struct sock *sk); +static int mptcp_inq_hint (const struct sock *sk);#define CREATE_TRACE_POINTS #include <trace/events/mptcp.h>
@@ -165,7 +165,7 @@ 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\n" , +pr_debug ("colesced seq %x into %x new len %d new end seq %x\n" ,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;
@@ -235,20 +235,20 @@ 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; +u32 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 =atomic64_read (&msk->rcv_wnd_sent); -pr_debug ("msk=%p seq=%llx limit=%llx empty=%d\n" , msk, seq, max_seq, +pr_debug ("msk=%p seq=%x limit=%x empty=%d\n" , msk, seq, max_seq,RB_EMPTY_ROOT (&msk->out_of_order_queue)); -if (after64 (end_seq, max_seq)) { +if (after (end_seq, max_seq)) {/* out of window */ mptcp_drop (sk, skb); -pr_debug ("oow by %lld, rcv_wnd_sent %llu\n" , - (unsigned long long )end_seq - (unsigned long )max_seq, +pr_debug ("oow by %d, rcv_wnd_sent %llu\n" , + end_seq - max_seq, (unsigned long long )atomic64_read (&msk->rcv_wnd_sent));MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_NODSSWINDOW );return ;
@@ -273,7 +273,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) }/* 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)) { +if (!before (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;
@@ -285,18 +285,18 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)while (*p) { parent = *p; skb1 =rb_to_skb (parent); -if (before64 (seq,MPTCP_SKB_CB (skb1)->map_seq)) { +if (before (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)) { +if (before (seq,MPTCP_SKB_CB (skb1)->end_seq)) { +if (!after (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)) { +if (after (seq,MPTCP_SKB_CB (skb1)->map_seq)) {/* partial overlap: * | skb | * | skb1 |
@@ -327,7 +327,7 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb) 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)) +if (before (end_seq,MPTCP_SKB_CB (skb1)->end_seq))break ;rb_erase (&skb1->rbnode, &msk->out_of_order_queue);mptcp_drop (sk, skb1);
@@ -349,10 +349,11 @@ static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset)/* the skb map_seq accounts for the skb offset: * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq -* value +* value; note that seq numbers are truncated to 32bits */ MPTCP_SKB_CB (skb)->map_seq =mptcp_subflow_get_mapped_dsn (subflow) - offset;MPTCP_SKB_CB (skb)->end_seq =MPTCP_SKB_CB (skb)->map_seq + skb->len; +MPTCP_SKB_CB (skb)->flags =0 ;MPTCP_SKB_CB (skb)->has_rxtstamp = has_rxtstamp;MPTCP_SKB_CB (skb)->cant_coalesce =0 ;
@@ -364,13 +365,14 @@ static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset)static bool __mptcp_move_skb (struct sock *sk,struct sk_buff *skb) { -u64 copy_len =MPTCP_SKB_CB (skb)->end_seq -MPTCP_SKB_CB (skb)->map_seq; +u32 copy_len =MPTCP_SKB_CB (skb)->end_seq -MPTCP_SKB_CB (skb)->map_seq;struct mptcp_sock *msk =mptcp_sk (sk); +u32 ack_seq = msk->ack_seq;struct sk_buff *tail;mptcp_borrow_fwdmem (sk, skb); -if (MPTCP_SKB_CB (skb)->map_seq == msk->ack_seq) { +if (MPTCP_SKB_CB (skb)->map_seq == ack_seq) {/* in sequence */ msk->bytes_received += copy_len;WRITE_ONCE (msk->ack_seq, msk->ack_seq + copy_len);
@@ -381,7 +383,7 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *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)) { + }else if (after (MPTCP_SKB_CB (skb)->map_seq, ack_seq)) {mptcp_data_queue_ofo (msk, skb);return false; }
@@ -762,40 +764,40 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk) {struct sock *sk = (struct sock *)msk;struct sk_buff *skb, *tail; +u32 seq_delta, ack_seq;bool moved = false;struct rb_node *p; -u64 end_seq; p =rb_first (&msk->out_of_order_queue);pr_debug ("msk=%p empty=%d\n" , msk,RB_EMPTY_ROOT (&msk->out_of_order_queue));while (p) { + ack_seq = msk->ack_seq; skb =rb_to_skb (p); -if (after64 (MPTCP_SKB_CB (skb)->map_seq, msk->ack_seq)) +if (after (MPTCP_SKB_CB (skb)->map_seq, 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))) { +if (unlikely (!after (MPTCP_SKB_CB (skb)->end_seq, ack_seq))) {mptcp_drop (sk, skb);MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_DUPDATA );continue ; } - end_seq =MPTCP_SKB_CB (skb)->end_seq; + seq_delta =MPTCP_SKB_CB (skb)->end_seq - ack_seq; tail =skb_peek_tail (&sk->sk_receive_queue);if (!tail || !mptcp_try_coalesce (sk, tail, skb)) { -int delta = msk->ack_seq -MPTCP_SKB_CB (skb)->map_seq; +int delta = ack_seq -MPTCP_SKB_CB (skb)->map_seq;/* skip overlapping data, if any */ -pr_debug ("uncoalesced seq=%llx ack seq=%llx delta=%d\n" , -MPTCP_SKB_CB (skb)->map_seq, msk->ack_seq, +pr_debug ("uncoalesced seq=%x ack seq=%x delta=%d\n" , +MPTCP_SKB_CB (skb)->map_seq, ack_seq, delta);__skb_queue_tail (&sk->sk_receive_queue, skb); } - msk->bytes_received += end_seq - msk->ack_seq; -WRITE_ONCE (msk->ack_seq, end_seq); + msk->bytes_received += seq_delta; +WRITE_ONCE (msk->ack_seq, msk->ack_seq + seq_delta); moved = true; }return moved;
@@ -2243,19 +2245,20 @@ static bool mptcp_move_skbs(struct sock *sk)return enqueued; } -static unsigned int mptcp_inq_hint (const struct sock *sk) +static int mptcp_inq_hint (const struct sock *sk) {const struct mptcp_sock *msk =mptcp_sk (sk);const struct sk_buff *skb; skb =skb_peek (&sk->sk_receive_queue);if (skb) { -u64 hint_val =READ_ONCE (msk->ack_seq) -MPTCP_SKB_CB (skb)->map_seq; +int hint_val = (u32 )READ_ONCE (msk->ack_seq) - +MPTCP_SKB_CB (skb)->map_seq; -if (hint_val >=INT_MAX ) -return INT_MAX ; +if (hint_val <0 ) +return -hint_val; -return (unsigned int )hint_val; +return hint_val; }if (sk->sk_state ==TCP_CLOSE || (sk->sk_shutdown &RCV_SHUTDOWN ))
@@ -2363,7 +2366,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,tcp_recv_timestamp (msg, sk, &tss);if (cmsg_flags &MPTCP_CMSG_INQ ) { -unsigned int inq =mptcp_inq_hint (sk); +int inq =mptcp_inq_hint (sk);put_cmsg (msg,SOL_TCP ,TCP_CM_INQ ,sizeof (inq), &inq); }
@@ -4583,11 +4586,23 @@ static int mptcp_napi_poll(struct napi_struct *napi, int budget)return work_done; } +#define CHK_CB_FIELD (mptcp_field, tcp_field) \ + ({ \ + BUILD_BUG_ON(offsetof(struct mptcp_skb_cb, mptcp_field) != \ + offsetof(struct tcp_skb_cb, tcp_field)); \ + BUILD_BUG_ON(offsetofend(struct mptcp_skb_cb, mptcp_field) != \ + offsetofend(struct tcp_skb_cb, tcp_field)); \ + }) +void __init mptcp_proto_init (void ) {struct mptcp_delegated_action *delegated;int cpu; +CHK_CB_FIELD (map_seq, seq); +CHK_CB_FIELD (end_seq, end_seq); +CHK_CB_FIELD (flags, tcp_flags); + mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo;if (percpu_counter_init (&mptcp_sockets_allocated,0 ,GFP_KERNEL ))
net/mptcp/protocol.h +4 -2
@@ -126,8 +126,10 @@#define MPTCP_SYNC_SNDBUF 7struct mptcp_skb_cb { -u64 map_seq; -u64 end_seq; +u32 map_seq; +u32 end_seq; +u32 unused; +u16 flags;u8 has_rxtstamp;u8 cant_coalesce; };
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 5/9 tcp: expose the tcp_collapse_ofo_queue() helper to mptcp usage, too
In reply to Paolo AbeniThe end goal is to avoid duplicating the quite untrivial strategy at MPTCP level.
After the previous patch, the mentioned helpers could process skbs standing in MPTCP-level queues without any CB-related adaptation.
The only additional adjustment needed is explicitly providing the OoO queue reference, to cope with different sk layout.
Additionally rename the helper to clearly document its hybrid nature and let it return the number of collapsed skbs, to allow proper accounting from the future MPTCP caller.
---
rfc -> v1:
- fix arg typo
Note:
- this will need a significant amount of testing at the TCP level and explicit approval from Eric, which I can't guess if we can hope.
--- include/net/tcp.h | 8 +++++++ net/ipv4/tcp_input.c | 55 ++++++++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 20 deletions(-)
include/net/tcp.h +8 -0
@@ -1828,6 +1828,14 @@ extern void tcp_openreq_init_rwin(struct request_sock *req,void tcp_enter_memory_pressure (struct sock *sk);void tcp_leave_memory_pressure (struct sock *sk); +unsigned int xtcp_collapse (struct sock *sk,struct sk_buff_head *list, +struct rb_root *root,struct sk_buff *head, +struct sk_buff *tail,u32 start,u32 end, +u8 scaling_ratio); +unsigned int xtcp_collapse_ofo_queue (struct sock *sk, +struct rb_root *out_of_order_queue, +struct sk_buff **ooo_last_skb, +u8 scaling_ratio);static inline int keepalive_intvl_when (const struct tcp_sock *tp) {
net/ipv4/tcp_input.c +35 -20
130 lines not on this page · raw message
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 6/9 mptcp: implemented OoO queue pruning
In reply to Paolo AbeniLeverage the hybrid helper to implement the receive queue and OoO queue collapsing at ingress time when reaching memory bounds.
If the msk is owned by the user-space at incoming skb time, perform the pruning in the release_cb. The prune check is additionally performed when the skb reaches the msk-level queues.
Pruning is not needed for fallback socket, as their MPTCP-level OoO queue must always be empty: remove the ingress check for such scenario and relay on the TCP-level one..
---
RFC -> v1:
- use data_seq only when available
- avoid ack_seq lockless access
- drop limit on fallback
- collapse rcvqueue, too
- drop only when pruning is not possible and over rcvbuf * 2
Notes:
- Similarly to path 'mptcp: move checks vs rcvbuf size earlier in the RX path', some cleanup/tuning in mptcp_over_limit() will be needed
- Pruning in the release_cb() is likely not needed, should probably be removed (after more testing).
--- net/mptcp/mib.c | 3 ++ net/mptcp/mib.h | 3 ++ net/mptcp/options.c | 40 +++++++++++++++++++++++--- net/mptcp/protocol.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 2 ++ 5 files changed, 112 insertions(+), 4 deletions(-)
net/mptcp/mib.c +3 -0
@@ -85,6 +85,9 @@ static const struct snmp_mib mptcp_snmp_list[] = {SNMP_MIB_ITEM ("SimultConnectFallback" ,MPTCP_MIB_SIMULTCONNFALLBACK ),SNMP_MIB_ITEM ("FallbackFailed" ,MPTCP_MIB_FALLBACKFAILED ),SNMP_MIB_ITEM ("WinProbe" ,MPTCP_MIB_WINPROBE ), +SNMP_MIB_ITEM ("OfoPruned" ,MPTCP_MIB_OFO_PRUNED ), +SNMP_MIB_ITEM ("RcvPruned" ,MPTCP_MIB_RCVPRUNED ), + SNMP_MIB_ITEM("RcvCollapsed", MPTCP_MIB_RCVCOLLAPSED), };/* mptcp_mib_alloc - allocate percpu mib counters
net/mptcp/mib.h +3 -0
@@ -88,6 +88,9 @@ enum linux_mptcp_mib_field {MPTCP_MIB_SIMULTCONNFALLBACK ,/* Simultaneous connect */ MPTCP_MIB_FALLBACKFAILED ,/* Can't fallback due to msk status */ MPTCP_MIB_WINPROBE ,/* MPTCP-level zero window probe */ +MPTCP_MIB_OFO_PRUNED ,/* MPTCP-level OoO queue pruned */ +MPTCP_MIB_RCVPRUNED ,/* Dropped due to memory constrains */ +MPTCP_MIB_RCVCOLLAPSED ,/* Collapsed due to memory pressure */ __MPTCP_MIB_MAX };
net/mptcp/options.c +36 -4
@@ -1158,12 +1158,40 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,return hmac == mp_opt->ahmac; } -static bool mptcp_over_limit (const struct sock *sk,struct sk_buff *skb) +static bool mptcp_over_limit (struct sock *sk,struct sk_buff *skb, +const struct mptcp_options_received *mp_opt) { +struct mptcp_sock *msk =mptcp_sk (sk); +bool ret; +if (TCP_SKB_CB (skb)->seq ==TCP_SKB_CB (skb)->end_seq)return false; -return sk_rmem_alloc_get (sk) >READ_ONCE (sk->sk_rcvbuf); +/* Allow some slack for backlog processing */ +if (sk_rmem_alloc_get (sk) <READ_ONCE (sk->sk_rcvbuf)) +return false; + +mptcp_data_lock (sk); +if (!sock_owned_by_user (sk)) { +/* When the data seqence is not (yet) available for the, +* incoming skb, allow pruning the whole OoO queue +*/ +u32 seq = !mp_opt->use_map || mp_opt->mpc_map ? msk->ack_seq : + mp_opt->data_seq; + +__mptcp_check_prune (sk, seq); + ret =sk_rmem_alloc_get (sk) >READ_ONCE (sk->sk_rcvbuf); + }else { +u64 limit = ((u64 )READ_ONCE (sk->sk_rcvbuf)) <<1 ; + +/* Pruning will take place later in the RX path, allow +* some extra slack. +*/ + ret =sk_rmem_alloc_get (sk) > limit; +__set_bit (MPTCP_PRUNE , &msk->cb_flags); + } +mptcp_data_unlock (sk); +return ret; }/* Return false when the caller must drop the packet, i.e. in case of error,
@@ -1194,7 +1222,11 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)__mptcp_data_acked (subflow->conn);mptcp_data_unlock (subflow->conn); -if (mptcp_over_limit (subflow->conn, skb)) +/* Will use ack_seq as limit for OoO pruning; any value would do +* as OoO queue must be empty. +*/ + mp_opt.use_map =0 ; +if (mptcp_over_limit (subflow->conn, skb, &mp_opt))return false;return true; }
@@ -1274,7 +1306,7 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)return true; } -if (mptcp_over_limit (subflow->conn, skb)) +if (mptcp_over_limit (subflow->conn, skb, &mp_opt))return false; mpext =skb_ext_add (skb,SKB_EXT_MPTCP );
net/mptcp/protocol.c +68 -0
86 lines not on this page · raw message
net/mptcp/protocol.h +2 -0
@@ -124,6 +124,7 @@#define MPTCP_FLUSH_JOIN_LIST 5#define MPTCP_SYNC_STATE 6#define MPTCP_SYNC_SNDBUF 7 +#define MPTCP_PRUNE 8struct mptcp_skb_cb {u32 map_seq;
@@ -829,6 +830,7 @@ bool __mptcp_close(struct sock *sk, long timeout);void mptcp_cancel_work (struct sock *sk);void __mptcp_unaccepted_force_close (struct sock *sk);void mptcp_set_state (struct sock *sk,int state); +bool __mptcp_check_prune (struct sock *sk,u32 seq);bool mptcp_addresses_equal (const struct mptcp_addr_info *a,const struct mptcp_addr_info *b,bool use_port);
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 7/9 mptcp: track prune recovery status
In reply to Paolo AbeniAfter dropping any data already acked at the TCP level, the MPTCP must avoid inducing TCP-level retransmission until the pruned data has been successfully acked at MPTCP level. Otherwise the subflows could keep retransmitting skbs carring OoO MPTCP data, preventing reinjections and stalling completely the data transfer.
Explicitly keep track of the highest pruned MPTCP-level seq number and stop dropping at TCP level until such sequence has been acked.
--- net/mptcp/options.c | 7 ++++++- net/mptcp/protocol.c | 14 +++++++++++++- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 1 + 4 files changed, 21 insertions(+), 2 deletions(-)
net/mptcp/options.c +6 -1
@@ -1191,7 +1191,12 @@ static bool mptcp_over_limit(struct sock *sk, struct sk_buff *skb,__set_bit (MPTCP_PRUNE , &msk->cb_flags); }mptcp_data_unlock (sk); -return ret; + +/* After pruning any packets ensure that MPTCP-driven drops do not +* cause TCP-level retransmission +*/ +return ret && + !before (READ_ONCE (msk->ack_seq),READ_ONCE (msk->pruned_seq)); }/* Return false when the caller must drop the packet, i.e. in case of error,
net/mptcp/protocol.c +13 -1
@@ -369,12 +369,14 @@ static void mptcp_prune_ofo_queue(struct sock *sk, u32 seq)struct mptcp_sock *msk =mptcp_sk (sk);struct rb_node *node, *prev;bool pruned = false; +u32 pruned_seq;if (RB_EMPTY_ROOT (&msk->out_of_order_queue))return ; node = &msk->ooo_last_skb->rbnode; + pruned_seq = msk->pruned_seq; do { struct sk_buff *skb = rb_to_skb(node);
@@ -385,16 +387,21 @@ static void mptcp_prune_ofo_queue(struct sock *sk, u32 seq) pruned = true; prev =rb_prev (node);rb_erase (node, &msk->out_of_order_queue); +if (after (MPTCP_SKB_CB (skb)->end_seq, pruned_seq)) + pruned_seq =MPTCP_SKB_CB (skb)->end_seq;mptcp_drop (sk, skb); msk->ooo_last_skb =rb_to_skb (prev); +if (atomic_read (&sk->sk_rmem_alloc) < sk->sk_rcvbuf)break ; node = prev; }while (node); -if (pruned) +if (pruned) { +WRITE_ONCE (msk->pruned_seq, pruned_seq);NET_INC_STATS (sock_net (sk),MPTCP_MIB_OFO_PRUNED ); + } }bool __mptcp_check_prune (struct sock *sk,u32 seq)
@@ -433,6 +440,8 @@ static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)mptcp_borrow_fwdmem (sk, skb);if (__mptcp_check_prune (sk,MPTCP_SKB_CB (skb)->map_seq)) { +if (after (MPTCP_SKB_CB (skb)->end_seq, msk->pruned_seq)) +WRITE_ONCE (msk->pruned_seq,MPTCP_SKB_CB (skb)->end_seq);MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_RCVPRUNED );mptcp_drop (sk, skb);return false;
@@ -866,6 +875,8 @@ static bool __mptcp_ofo_queue(struct mptcp_sock *msk)WRITE_ONCE (msk->ack_seq, msk->ack_seq + seq_delta); moved = true; } +if (after (msk->ack_seq, msk->pruned_seq)) +WRITE_ONCE (msk->pruned_seq, (u32 )msk->ack_seq);return moved; }
@@ -3520,6 +3531,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)/* for fallback's sake */ WRITE_ONCE (msk->ack_seq,0 );WRITE_ONCE (msk->copied_seq,0 ); +WRITE_ONCE (msk->pruned_seq,0 );WRITE_ONCE (sk->sk_shutdown,0 );sk_error_report (sk);
net/mptcp/protocol.h +1 -0
@@ -306,6 +306,7 @@ struct mptcp_sock {u64 bytes_acked;u64 snd_una;u64 wnd_end; +u32 pruned_seq;/* if after ack_seq, highest seq pruned */ u32 last_data_sent;u32 last_data_recv;u32 last_ack_recv;
net/mptcp/subflow.c +1 -0
@@ -495,6 +495,7 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,WRITE_ONCE (msk->remote_key, subflow->remote_key);WRITE_ONCE (msk->ack_seq, subflow->iasn);WRITE_ONCE (msk->copied_seq, subflow->iasn); +WRITE_ONCE (msk->pruned_seq, subflow->iasn);WRITE_ONCE (msk->can_ack, true);atomic64_set (&msk->rcv_wnd_sent, subflow->iasn); }
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 8/9 mptcp: move the retrans loop to a separate helper
In reply to Paolo AbeniThis is a cleanup in order to make the next patch simpler. No functional change intended.
--- net/mptcp/protocol.c | 74 +++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 31 deletions(-)
net/mptcp/protocol.c +43 -31
@@ -2820,41 +2820,14 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)sk_error_report (sk); } -static void __mptcp_retrans (struct sock *sk) +/* Retransmit the specified data fragment on all the selected subflows. */ +static int __mptcp_push_retrans (struct sock *sk,struct mptcp_data_frag *dfrag) {struct mptcp_sendmsg_info info = { .data_lock_held = true, };struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_subflow_context *subflow; -struct mptcp_data_frag *dfrag;struct sock *ssk; -int ret, err; -u16 len =0 ; - -mptcp_clean_una_wakeup (sk); - -/* first check ssk: need to kick "stale" logic */ - err =mptcp_sched_get_retrans (msk); - dfrag =mptcp_rtx_head (sk); -if (!dfrag) { -if (mptcp_data_fin_enabled (msk)) { -struct inet_connection_sock *icsk =inet_csk (sk); - -WRITE_ONCE (icsk->icsk_retransmits, - icsk->icsk_retransmits +1 ); -mptcp_set_datafin_timeout (sk); -mptcp_send_ack (msk); - - goto reset_timer; - } - -if (!mptcp_send_head (sk)) - goto clear_scheduled; - - goto reset_timer; - } - -if (err) - goto reset_timer; +int ret, len =0 ;mptcp_for_each_subflow (msk, subflow) {if (READ_ONCE (subflow->scheduled)) {
@@ -2882,7 +2855,7 @@ static void __mptcp_retrans(struct sock *sk) !msk->allow_subflows) {spin_unlock_bh (&msk->fallback_lock);release_sock (ssk); - goto clear_scheduled; +return -1 ; }while (info.sent < info.limit) {
@@ -2905,6 +2878,45 @@ static void __mptcp_retrans(struct sock *sk)release_sock (ssk); } } +return len; +} + +static void __mptcp_retrans (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct mptcp_subflow_context *subflow; +struct mptcp_data_frag *dfrag; +int err, len; + +mptcp_clean_una_wakeup (sk); + +/* first check ssk: need to kick "stale" logic */ + err =mptcp_sched_get_retrans (msk); + dfrag =mptcp_rtx_head (sk); +if (!dfrag) { +if (mptcp_data_fin_enabled (msk)) { +struct inet_connection_sock *icsk =inet_csk (sk); + +WRITE_ONCE (icsk->icsk_retransmits, + icsk->icsk_retransmits +1 ); +mptcp_set_datafin_timeout (sk); +mptcp_send_ack (msk); + + goto reset_timer; + } + +if (!mptcp_send_head (sk)) + goto clear_scheduled; + + goto reset_timer; + } + +if (err) + goto reset_timer; + + len =__mptcp_push_retrans (sk, dfrag); +if (len <0 ) + goto clear_scheduled; msk->bytes_retrans += len; dfrag->already_sent =max (dfrag->already_sent, len);
Signature · 1 line
2.53.0
Paolo Abeni
maintainerPATCH 9/9 mptcp: let the retrans scheduler do its job.
In reply to Paolo AbeniCurrently the MPTCP core enforces that when MPTCP-level retrans timer fires, at most a single dfrag is retransmitted. If some corner-cases it may be necessary retransmit multiple dfrags, and the MPTCP socket will need to wait multiple retrans timeout to accomplish that.
Remove the mentioned constraint, allowing to transmit multiple dfrags per retrans period, as long as the scheduler keeps selecting subflows for retransmissions and pending data is available in the rtx queue. The default scheduler will transmit a dfrag per available subflow.
--- net/mptcp/protocol.c | 84 +++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 37 deletions(-)
net/mptcp/protocol.c +47 -37
@@ -1187,13 +1187,6 @@ static void __mptcp_clean_una_wakeup(struct sock *sk)mptcp_write_space (sk); } -static void mptcp_clean_una_wakeup (struct sock *sk) -{ -mptcp_data_lock (sk); -__mptcp_clean_una_wakeup (sk); -mptcp_data_unlock (sk); -} -static void mptcp_enter_memory_pressure (struct sock *sk) {struct mptcp_subflow_context *subflow;
@@ -2820,8 +2813,12 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)sk_error_report (sk); } -/* Retransmit the specified data fragment on all the selected subflows. */ -static int __mptcp_push_retrans (struct sock *sk,struct mptcp_data_frag *dfrag) +/* +* Retransmit the specified data fragment on all the selected subflows, +* starting from the specified sequence +*/ +static int __mptcp_push_retrans (struct sock *sk,struct mptcp_data_frag *dfrag, +u64 retrans_seq) {struct mptcp_sendmsg_info info = { .data_lock_held = true, };struct mptcp_sock *msk =mptcp_sk (sk);
@@ -2840,7 +2837,7 @@ static int __mptcp_push_retrans(struct sock *sk, struct mptcp_data_frag *dfrag)lock_sock (ssk);/* limit retransmission to the bytes already sent on some subflows */ - info.sent =0 ; + info.sent = retrans_seq - dfrag->data_seq; info.limit =READ_ONCE (msk->csum_enabled) ? dfrag->data_len : dfrag->already_sent;
@@ -2886,42 +2883,55 @@ static void __mptcp_retrans(struct sock *sk)struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_subflow_context *subflow;struct mptcp_data_frag *dfrag; +u64 retrans_seq;int err, len; -mptcp_clean_una_wakeup (sk); - -/* first check ssk: need to kick "stale" logic */ - err =mptcp_sched_get_retrans (msk); - dfrag =mptcp_rtx_head (sk); -if (!dfrag) { -if (mptcp_data_fin_enabled (msk)) { -struct inet_connection_sock *icsk =inet_csk (sk); +mptcp_data_lock (sk); +__mptcp_clean_una_wakeup (sk); + retrans_seq = msk->snd_una; +mptcp_data_unlock (sk); -WRITE_ONCE (icsk->icsk_retransmits, - icsk->icsk_retransmits +1 ); -mptcp_set_datafin_timeout (sk); -mptcp_send_ack (msk); +for (;;) { +/* first check ssk: need to kick "stale" logic */ + err =mptcp_sched_get_retrans (msk); + dfrag =mptcp_rtx_head (sk); +if (!dfrag) { +if (mptcp_data_fin_enabled (msk)) { +struct inet_connection_sock *icsk =inet_csk (sk); + +WRITE_ONCE (icsk->icsk_retransmits, + icsk->icsk_retransmits +1 ); +mptcp_set_datafin_timeout (sk); +mptcp_send_ack (msk); +break ; + } - goto reset_timer; +if (!mptcp_send_head (sk)) + goto clear_scheduled; +break ; } -if (!mptcp_send_head (sk)) - goto clear_scheduled; - - goto reset_timer; - } - -if (err) - goto reset_timer; +if (err) +break ; - len =__mptcp_push_retrans (sk, dfrag); -if (len <0 ) - goto clear_scheduled; +/* Skip the data already retransmitted in this run */ +while (dfrag && !before64 (retrans_seq, dfrag->data_seq + + dfrag->already_sent)) + dfrag =list_is_last (&dfrag->list, &msk->rtx_queue) ?NULL : +list_next_entry (dfrag, list); +if (!dfrag || !dfrag->already_sent) +break ; - msk->bytes_retrans += len; - dfrag->already_sent =max (dfrag->already_sent, len); + len =__mptcp_push_retrans (sk, dfrag, retrans_seq); +if (len <0 ) + goto clear_scheduled; +if (!len) +break ; -reset_timer: + retrans_seq += len; + msk->bytes_retrans += len; + dfrag->already_sent =max (dfrag->already_sent, len); + }mptcp_check_and_set_pending (sk);if (!mptcp_rtx_timer_pending (sk))
Signature · 1 line
2.53.0
Hi Paolo,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Unstable: 7 failed test(s): packetdrill_fastopen packetdrill_regressions selftest_mptcp_connect selftest_mptcp_connect_checksum selftest_mptcp_connect_mmap selftest_mptcp_connect_sendfile selftest_mptcp_connect_splice ⚠️
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Critical: 2 Call Trace(s) - Critical: Global Timeout ❌
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Unstable: 2 failed test(s): bpftest_test_progs-no_alu32_mptcp bpftest_test_progs_mptcp ⚠️
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/24894934320
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/cceb6849cdf8
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1085225
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Geliang Tang
reviewerHi Paolo,
Thanks for these fixes.
Quoted 17 lines · Paolo Abeni
This an attempt to fix the data transfer stall reported by Geliang and
Gang more carefully enforcing memory constraints at the MPTCP level.Patch 1/9 moves the bound check before entering the TCP socket. Patch 2, 3 and 4 are cleanups/refactors finalized to safely re-using TCP
helpers on MPTCP skbs.
Patch 5 makes TCP pruning related helpers available to MPTCP and patch 6
makes use of them. Patch 7 addresses an edge scenario that could still
lead to transfer stall under memory pressure.
Finally patch 8 and 9 improve the MPTCP-level retransmission schema to
make recovery from memory pressure significanly faster.
Quoted 6 lines
Note that the diffstat is biases by the quite large patch 4/9, which contains mechanical transformation of existing code; "real" changes are
noticiable smaller.Tested successfully vs the test cases proposed by Geliang and Gang.
We found this issue while testing the MPTCP TLS selftests (tools/testing/selftests/net/tls.c). The multi_chunk.c test was actually extracted from chunked_sendfile() function in tls.c. The tls.c file contains many test groups, and chunked_sendfile() is just one of them. Therefore, passing the chunked_sendfile tests does not guarantee that all tests in tls.c will pass in the future. So we will provide you with a test similar to multi_chunk.c shortly, but includes a more complete set of the tests from tls.c.
Quoted 10 lines
---
RFC -> v1:
- dropped old patch 4 & 5
- addressed AI reported comments
- added retrans refactor.Paolo Abeni (9):
mptcp: move checks vs rcvbuf size earlier in the RX path
mptcp: drop themptcp_ooo_try_coalesce()helper
mptcp: remove CB offset field
When implementing MPTCP KTLS, I used this offset field. Please see the implementation in [1], including mptcp_read_done() and mptcp_get_skb_seq(). After removing the offset field, I think the new version should be implemented as follows:
static void mptcp_read_done(struct sock *sk, size_t len)
{
struct mptcp_sock *msk = mptcp_sk(sk);
struct sk_buff *skb;
size_t left;
u32 offset;
msk_owned_by_me(msk);
if (sk->sk_state == TCP_LISTEN)
return;
left = len;
while (left && (skb = mptcp_recv_skb(sk, &offset)) != NULL) {
int used;
used = min_t(size_t, skb->len - offset, left);
msk->bytes_consumed += used;
msk->copied_seq += used;
left -= used;
if (skb->len > offset + used)
break;
mptcp_eat_recv_skb(sk, skb);
}
mptcp_rcv_space_adjust(msk, len - left);
/* Clean up data we have read: This will do ACK frames. */
if (left != len)
mptcp_cleanup_rbuf(msk, len - left);
}static u32 mptcp_get_skb_seq(struct sk_buff *skb)
{
return MPTCP_SKB_CB(skb)->map_seq;
}But unfortunately, after this modification, with all your patches in this set, the newly added MPTCP test cases in tls.c did not all pass. Are there any obvious issues with my modification in these two function?
Thanks again, and I will continue to follow up and test this series.
-Geliang
Quoted 18 lines
mptcp: sync mptcp skb cb layout with tcp one
tcp: expose thetcp_collapse_ofo_queue()helper to mptcp usage, too
mptcp: implemented OoO queue pruning
mptcp: track prune recovery status
mptcp: move the retrans loop to a separate helper
mptcp: let the retrans scheduler do its job.include/net/tcp.h | 8 ++
net/ipv4/tcp_input.c | 55 +++++---
net/mptcp/fastopen.c | 1 -
net/mptcp/mib.c | 3 +
net/mptcp/mib.h | 3 +
net/mptcp/options.c | 55 +++++++-
net/mptcp/protocol.c | 328 ++++++++++++++++++++++++++++------------- --
net/mptcp/protocol.h | 11 +-
net/mptcp/subflow.c | 2 +9 files changed, 323 insertions(+), 143 deletions(-)
Geliang Tang
reviewerHi Paolo,
Quoted 32 lines · Geliang Tang
Hi Paolo,
Thanks for these fixes.
Quoted 19 lines · Paolo Abeni
This an attempt to fix the data transfer stall reported by Geliang and
Gang more carefully enforcing memory constraints at the MPTCP level.Patch 1/9 moves the bound check before entering the TCP socket. Patch 2, 3 and 4 are cleanups/refactors finalized to safely re- using
TCP
helpers on MPTCP skbs.
Patch 5 makes TCP pruning related helpers available to MPTCP and patch 6
makes use of them. Patch 7 addresses an edge scenario that could still
lead to transfer stall under memory pressure.
Finally patch 8 and 9 improve the MPTCP-level retransmission schema to
make recovery from memory pressure significanly faster.Quoted 7 lines
Note that the diffstat is biases by the quite large patch 4/9, which
contains mechanical transformation of existing code; "real" changes are
noticiable smaller.Tested successfully vs the test cases proposed by Geliang and Gang.
Quoted 11 lines
We found this issue while testing the MPTCP TLS selftests (
tools/testing/selftests/net/tls.c). Themulti_chunk.ctest was actually extracted fromchunked_sendfile()function intls.c. Thetls.c
file contains many test groups, andchunked_sendfile()is just one of them. Therefore, passing thechunked_sendfiletests does not guarantee
that all tests intls.cwill pass in the future. So we will provide you
with a test similar tomulti_chunk.cshortly, but includes a more complete set of the tests fromtls.c.
I have attached a new test that basically covers all the tests in tls.c. This test uses MPTCP sockets without TLS encryption.
When I ran it on v5 of Gang's patches in [1], all test items passed; however, when I ran it on v2 of this series, several test items failed, accompanied by an OOM error:
# ok 7 mptcp.mutliproc_sendpage_even # # RUN mptcp.mutliproc_writers ... # # mutliproc_writers: Test terminated by timeout # # FAIL mptcp.mutliproc_writers # not ok 8 mptcp.mutliproc_writers # # RUN mptcp.mutliproc_readers ... # # mutliproc_readers: Test terminated by timeout # # FAIL mptcp.mutliproc_readers # not ok 9 mptcp.mutliproc_readers # # RUN mptcp.mutliproc_even ... root@mptcpdev:/home/tgl/mptcp_net-next# [ 83.031990][ T458] kworker/13:2: page allocation failure: order:0, mode:0x40820(GFP_ATOMIC|__GFP_COMP), nodemask=(null),cpuset=/,mems_allowed=0 [ 83.032214][ T465] SLUB: Unable to allocate memory on CPU 20 (of node 0) on node -1, gfp=0x920(GFP_ATOMIC|__GFP_ZERO) [ 83.032956][ T458] CPU: 13 UID: 0 PID: 458 Comm: kworker/13:2 Not tainted 7.1.0-rc1+ #85 PREEMPT(full) [ 83.032959][ T458] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 [ 83.032961][ T458] Workqueue: events mptcp_worker [ 83.032969][ T458] Call Trace: [ 83.032971][ T458] <TASK> [ 83.032973][ T458] dump_stack_lvl+0x6f/0xb0 [ 83.032982][ T458] warn_alloc.cold+0x9b/0x1c4 [ 83.032987][ T458] ? __pfx_warn_alloc+0x10/0x10 [ 83.033000][ T458] __alloc_pages_slowpath.constprop.0+0xa3e/0x1770 [ 83.033005][ T458] ? __pfx___alloc_pages_slowpath.constprop.0+0x10/0x10 [ 83.033011][ T458] __alloc_frozen_pages_noprof+0x2f3/0x380
I hope this test is useful to you. If you need me to do any testing, I am very willing to help, just let me know.
Thanks,
-Geliang
[1]
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
Quoted 62 lines
Quoted 11 lines
---
RFC -> v1:
- dropped old patch 4 & 5
- addressed AI reported comments
- added retrans refactor.Paolo Abeni (9):
mptcp: move checks vs rcvbuf size earlier in the RX path
mptcp: drop themptcp_ooo_try_coalesce()helper
mptcp: remove CB offset fieldWhen implementing MPTCP KTLS, I used this offset field. Please see the
implementation in [1], includingmptcp_read_done()andmptcp_get_skb_seq(). After removing the offset field, I think the new version should be implemented as follows:static void
mptcp_read_done(struct sock *sk, size_t len){
structmptcp_sock*msk =mptcp_sk(sk); structsk_buff*skb;
size_tleft;
u32 offset;
msk_owned_by_me(msk);if (
sk->sk_state==TCP_LISTEN)
return;left = len;
while (left && (skb =mptcp_recv_skb(sk, &offset)) != NULL) { int used;used =
min_t(size_t, skb->len - offset, left);msk->bytes_consumed+= used;msk->copied_seq+= used;
left -= used;if (
skb->len> offset + used)
break;
mptcp_eat_recv_skb(sk, skb);
}
mptcp_rcv_space_adjust(msk, len - left);/* Clean up data we have read: This will do ACK frames. */ if (left != len)
mptcp_cleanup_rbuf(msk, len - left);
}static u32
mptcp_get_skb_seq(struct sk_buff *skb)
{
return MPTCP_SKB_CB(skb)->map_seq;
}But unfortunately, after this modification, with all your patches in this set, the newly added MPTCP test cases in
tls.cdid not all pass. Are there any obvious issues with my modification in these two function?
Quoted 27 lines
Thanks again, and I will continue to follow up and test this series.
-Geliang
Quoted 20 lines
mptcp: sync mptcp skb cb layout with tcp one
tcp: expose thetcp_collapse_ofo_queue()helper to mptcp usage, too
mptcp: implemented OoO queue pruning
mptcp: track prune recovery status
mptcp: move the retrans loop to a separate helper
mptcp: let the retrans scheduler do its job.include/net/tcp.h | 8 ++
net/ipv4/tcp_input.c | 55 +++++---net/mptcp/fastopen.c| 1 -
net/mptcp/mib.c | 3 +
net/mptcp/mib.h | 3 +
net/mptcp/options.c | 55 +++++++-net/mptcp/protocol.c| 328 ++++++++++++++++++++++++++++----------- --
--
net/mptcp/protocol.h | 11 +-
net/mptcp/subflow.c | 2 +9 files changed, 323 insertions(+), 143 deletions(-)
From ff5ed6aaed973bf97f568e008b4a78a3dc0369b3 Mon Sep 17 00:00:00 2001
Message-ID: <ff5ed6aaed973bf97f568e008b4a78a3dc0369b3.1777363110.git.tanggeliang@kylinos.cn>
From: Gang Yan <[email protected]>
Date: Mon, 27 Apr 2026 16:03:31 +0800
Subject: [PATCH] selftest: mptcp: add some trasnfer mode like tls
This patch adds a test using transfer mode like tls without ktls configuration.
But the msg_more and msg_more_unsent will fail, I think it's not a big deal with, so just cancel it temprorily.
--- tools/testing/selftests/net/mptcp/Makefile | 1 + .../testing/selftests/net/mptcp/mptcp_data.c | 1240 +++++++++++++++++ .../testing/selftests/net/mptcp/mptcp_data.sh | 45 + 3 files changed, 1286 insertions(+) create mode 100644 tools/testing/selftests/net/mptcp/mptcp_data.c create mode 100755 tools/testing/selftests/net/mptcp/mptcp_data.sh
tools/testing/selftests/net/mptcp/Makefile +1 -0
@@ -25,6 +25,7 @@ TEST_GEN_FILES := \ mptcp_inq \ mptcp_sockopt \ pm_nl_ctl \ + mptcp_data \ # end of TEST_GEN_FILES TEST_FILES := \
tools/testing/selftests/net/mptcp/mptcp_data.c new file +1240 -0
1,240 lines not on this page · raw message
tools/testing/selftests/net/mptcp/mptcp_data.sh new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.53.0