The current export branch suffers of the following issue:
Subsystems (3)
Paolo Abeni
cover The current export branch suffers of the following issue:
https://github.com/multipath-tcp/mptcp_net-next/issues/97
To fix the above, MPTCP needs to be able to cope with memory allocation failure in do_tcp_sendpages().
In this iteration the patches are rebased on top of:
"bpf:selftests: add bpf_mptcp_sock() verifier tests"
and should apply without fuzz on net-next.
patch 1/2 went through some lifting to be hopefully more acceptable upstream.
This will cause a few conflicts in later patch, specifically in "mptcp: move page frag allocation in mptcp_sendmsg()". Possibly the simpler/better would be squashing 2/2 in there.
The plan is to send 1/2 and "tcp: factor out __tcp_close() helper" as RFC upstream soon/while net-next is closed to try to understand if that could be acceptable. The 2 TCP patches alone, without the full series to hopefully make the review simpler/less cumbersome.
Any feedback more than welcome!!!
Paolo Abeni (2):
tcp: factor out tcp_build_frag()
mptcp: use tcp_build_frag()
include/net/tcp.h | 3 ++ net/ipv4/tcp.c | 119 ++++++++++++++++++++++++------------------- net/mptcp/protocol.c | 25 +++------ 3 files changed, 78 insertions(+), 69 deletions(-)
Signature · 1 line
2.26.2
Paolo Abeni
PATCH 1/2 tcp: factor out tcp_build_frag()
Will be needed by the next patch, as MPTCP needs to handle directly the error/memory-allocation-needed path.
No functional changes intented.
---
RFC -> v1:
- rename do_tcp_sendfrag() -> tcp_buildfrag()
- changed return type and argument list to
simplify the caller
--- include/net/tcp.h | 3 ++ net/ipv4/tcp.c | 119 ++++++++++++++++++++++++++-------------------- 2 files changed, 70 insertions(+), 52 deletions(-)
include/net/tcp.h +3 -0
@@ -322,6 +322,7 @@ void tcp_shutdown(struct sock *sk, int how);int tcp_v4_early_demux (struct sk_buff *skb);int tcp_v4_rcv (struct sk_buff *skb); +void tcp_remove_empty_skb (struct sock *sk,struct sk_buff *skb);int tcp_v4_tw_remember_stamp (struct inet_timewait_sock *tw);int tcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t size);int tcp_sendmsg_locked (struct sock *sk,struct msghdr *msg,size_t size);
@@ -329,6 +330,8 @@ int tcp_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags);int tcp_sendpage_locked (struct sock *sk,struct page *page,int offset,size_t size,int flags); +struct sk_buff *tcp_build_frag (struct sock *sk,int size_goal,int flags, +struct page *page,int offset,size_t *size);ssize_t do_tcp_sendpages (struct sock *sk,struct page *page,int offset,size_t size,int flags);int tcp_send_mss (struct sock *sk,int *size_goal,int flags);
net/ipv4/tcp.c +67 -52
140 lines not on this page · raw message
Signature · 1 line
2.26.2
Paolo Abeni
PATCH 2/2 mptcp: use tcp_build_frag()
In reply to Paolo Abenimptcp_push_pending() is called even on orphaned msk (and orphaned subflows), if there is outstanding data at close() time.
To cope with the above MPTCP needs to handle explicitly the allocation failure on xmit. The newly introduced do_tcp_sendfrag() allows that, just plug it.
We can additionally drop a couple of sanity checks, duplicate in the TCP code.
--- net/mptcp/protocol.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
net/mptcp/protocol.c +8 -17
@@ -956,17 +956,13 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, psize =min_t (size_t, dfrag->data_len, avail_size); } -/* tell the TCP stack to delay the push so that we can safely -* access the skb after the sendpages call -*/ - ret =do_tcp_sendpages (ssk, page, offset, psize, - msg->msg_flags |MSG_SENDPAGE_NOTLAST |MSG_DONTWAIT ); -if (ret <=0 ) { -if (!retransmission) -iov_iter_revert (&msg->msg_iter, psize); -return ret; + tail =tcp_build_frag (ssk, psize, msg->msg_flags, page, offset, &psize); +if (!tail) { +tcp_remove_empty_skb (sk,tcp_write_queue_tail (ssk)); +return -ENOMEM ; } + ret = psize; frag_truesize += ret;if (!retransmission) {if (unlikely (ret < psize))
@@ -990,20 +986,15 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, sk->sk_forward_alloc -= frag_truesize; } -/* if the tail skb extension is still the cached one, collapsing -* really happened. Note: we can't check for 'same skb' as the sk_buff -* hdr on tail can be transmitted, freed and re-allocated by the -* do_tcp_sendpages() call +/* if the tail skb is still the cached one, collapsing really happened. */ - tail =tcp_write_queue_tail (ssk); -if (mpext && tail && mpext ==skb_ext_find (tail,SKB_EXT_MPTCP )) { +if (skb == tail) {WARN_ON_ONCE (!can_collapse); mpext->data_len += ret; goto out; } - skb =tcp_write_queue_tail (ssk); - mpext =__skb_ext_set (skb,SKB_EXT_MPTCP , msk->cached_ext); + mpext =__skb_ext_set (tail,SKB_EXT_MPTCP , msk->cached_ext); msk->cached_ext =NULL ;memset (mpext,0 ,sizeof (*mpext));
Signature · 1 line
2.26.2
Mat Martineau
[MPTCP] Re: [PATCH net-next 1/2] tcp: factor out tcp_build_frag()
In reply to Paolo AbeniQuoted 4 lines · Paolo Abeni
Will be needed by the next patch, as MPTCP needs to handle directly the error/memory-allocation-needed path.
No functional changes intented.
Minor: "intended"
Worth mentioning the change to tcp_remove_empty_skb() visibility too?
Quoted 132 lines
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>---
RFC -> v1:
- renamedo_tcp_sendfrag()->tcp_buildfrag()
- changed return type and argument list to
simplify the caller
---include/net/tcp.h| 3 ++net/ipv4/tcp.c| 119 ++++++++++++++++++++++++++--------------------2 files changed, 70 insertions(+), 52 deletions(-)include/net/tcp.h +3
-0@@ -322,6 +322,7 @@ void tcp_shutdown(struct sock *sk, int how);int tcp_v4_early_demux (struct sk_buff *skb);int tcp_v4_rcv (struct sk_buff *skb); +void tcp_remove_empty_skb (struct sock *sk,struct sk_buff *skb);int tcp_v4_tw_remember_stamp (struct inet_timewait_sock *tw);int tcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t size);int tcp_sendmsg_locked (struct sock *sk,struct msghdr *msg,size_t size);@@ -329,6 +330,8 @@ int tcp_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags);int tcp_sendpage_locked (struct sock *sk,struct page *page,int offset,size_t size,int flags); +struct sk_buff *tcp_build_frag (struct sock *sk,int size_goal,int flags, +struct page *page,int offset,size_t *size);ssize_t do_tcp_sendpages (struct sock *sk,struct page *page,int offset,size_t size,int flags);int tcp_send_mss (struct sock *sk,int *size_goal,int flags);net/ipv4/tcp.c +63
-14@@ -952,7 +952,7 @@ int tcp_send_mss(struct sock *sk, int *size_goal, int flags)* importantly be able to generate EPOLLOUT for Edge Trigger epoll() * users. */ -static void tcp_remove_empty_skb (struct sock *sk,struct sk_buff *skb) +void tcp_remove_empty_skb (struct sock *sk,struct sk_buff *skb) {if (skb && !skb->len) {tcp_unlink_write_queue (skb, sk);@@ -962,6 +962,68 @@ static void tcp_remove_empty_skb(struct sock *sk, struct sk_buff *skb) } } +struct sk_buff *tcp_build_frag (struct sock *sk,int size_goal,int flags, +struct page *page,int offset,size_t *size) +{ +struct sk_buff *skb =tcp_write_queue_tail (sk); +struct tcp_sock *tp =tcp_sk (sk); +bool can_coalesce; +int copy, i; + +if (!skb || (copy = size_goal - skb->len) <=0 || + !tcp_skb_can_collapse_to (skb)) { +new_segment: +if (!sk_stream_memory_free (sk)) +return NULL ; + + skb =sk_stream_alloc_skb (sk,0 , sk->sk_allocation, +tcp_rtx_and_write_queues_empty (sk)); +if (!skb) +return NULL ; + +#ifdef CONFIG_TLS_DEVICE + skb->decrypted = !!(flags &MSG_SENDPAGE_DECRYPTED ); +#endif +skb_entail (sk, skb); + copy = size_goal; + } + +if (copy > *size) + copy = *size; + + i =skb_shinfo (skb)->nr_frags; + can_coalesce =skb_can_coalesce (skb, i, page, offset); +if (!can_coalesce && i >= sysctl_max_skb_frags) { +tcp_mark_push (tp, skb); + goto new_segment; + } +if (!sk_wmem_schedule (sk, copy)) +return NULL ; + +if (can_coalesce) { +skb_frag_size_add (&skb_shinfo (skb)->frags[i -1 ], copy); + }else { +get_page (page); +skb_fill_page_desc (skb, i, page, offset, copy); + } + +if (!(flags &MSG_NO_SHARED_FRAGS )) +skb_shinfo (skb)->tx_flags |=SKBTX_SHARED_FRAG ; + + skb->len += copy; + skb->data_len += copy; + skb->truesize += copy; +sk_wmem_queued_add (sk, copy); +sk_mem_charge (sk, copy); + skb->ip_summed =CHECKSUM_PARTIAL ; +WRITE_ONCE (tp->write_seq, tp->write_seq + copy); +TCP_SKB_CB (skb)->end_seq += copy; +tcp_skb_pcount_set (skb,0 ); + + *size = copy; +return skb; +} +ssize_t do_tcp_sendpages (struct sock *sk,struct page *page,int offset,size_t size,int flags) {@@ -997,60 +1059,13 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset, goto out_err;while (size >0 ) { -struct sk_buff *skb =tcp_write_queue_tail (sk); -int copy, i; -bool can_coalesce; - -if (!skb || (copy = size_goal - skb->len) <=0 || - !tcp_skb_can_collapse_to (skb)) { -new_segment: -if (!sk_stream_memory_free (sk)) - goto wait_for_space; - - skb =sk_stream_alloc_skb (sk,0 , sk->sk_allocation, -tcp_rtx_and_write_queues_empty (sk)); -if (!skb)
net/ipv4/tcp.c ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset, · line 1063
Quoted 10 lines
net/ipv4/tcp.c +2
-8- goto wait_for_space; - -#ifdef CONFIG_TLS_DEVICE - skb->decrypted = !!(flags &MSG_SENDPAGE_DECRYPTED ); -#endif -skb_entail (sk, skb); - copy = size_goal; - } +struct sk_buff *skb; +size_t copy = size;
This initialization is the only thing that needed a deeper look, but following how it's used in tcp_build_frag() the behavior does look the same.
This patch (with commit message comments above) and #2 look good to post to netdev for feedback.
Thanks,
Mat
Quoted 44 lines
net/ipv4/tcp.c +2
-30-if (copy > size) - copy = size; - - i =skb_shinfo (skb)->nr_frags; - can_coalesce =skb_can_coalesce (skb, i, page, offset); -if (!can_coalesce && i >= sysctl_max_skb_frags) { -tcp_mark_push (tp, skb); - goto new_segment; - } -if (!sk_wmem_schedule (sk, copy)) + skb =tcp_build_frag (sk, size_goal, flags, page, offset, ©); +if (!skb) goto wait_for_space; -if (can_coalesce) { -skb_frag_size_add (&skb_shinfo (skb)->frags[i -1 ], copy); - }else { -get_page (page); -skb_fill_page_desc (skb, i, page, offset, copy); - } - -if (!(flags &MSG_NO_SHARED_FRAGS )) -skb_shinfo (skb)->tx_flags |=SKBTX_SHARED_FRAG ; - - skb->len += copy; - skb->data_len += copy; - skb->truesize += copy; -sk_wmem_queued_add (sk, copy); -sk_mem_charge (sk, copy); - skb->ip_summed =CHECKSUM_PARTIAL ; -WRITE_ONCE (tp->write_seq, tp->write_seq + copy); -TCP_SKB_CB (skb)->end_seq += copy; -tcp_skb_pcount_set (skb,0 ); -if (!copied)TCP_SKB_CB (skb)->tcp_flags &= ~TCPHDR_PSH ;Signature · 4 lines
2.26.2 _______________________________________________ mptcp mailing list -- mptcp(a)lists.01.org To unsubscribe send an email to mptcp-leave(a)lists.01.org
--
Mat Martineau
Intel
Matthieu Baerts
Hi Paolo, Mat,
Quoted 14 lines · Paolo Abeni
https://github.com/multipath-tcp/mptcp_net-next/issues/97
To fix the above, MPTCP needs to be able to cope with memory allocation failure in
do_tcp_sendpages().In this iteration the patches are rebased on top of:
"bpf:selftests: add
bpf_mptcp_sock()verifier tests"and should apply without fuzz on net-next.
patch 1/2 went through some lifting to be hopefully more acceptable upstream.
Quoted 8 lines
This will cause a few conflicts in later patch, specifically in "mptcp: move page frag allocation in
mptcp_sendmsg()". Possibly the simpler/better would be squashing 2/2 in there.The plan is to send 1/2 and "tcp: factor out
__tcp_close()helper" as RFC upstream soon/while net-next is closed to try to understand if that could be acceptable. The 2 TCP patches alone, without the full series to hopefully make the review simpler/less cumbersome.
Thank you for the patches and the reviews!
I just applied these two patches on top of "tcp: factor out __tcp_close() helper", just before your sendmsg refactor series:
- 325abb8bd3d0: tcp: factor out tcp_build_frag()
- Note: I took the version you sent to netdev for this one
- c573a4caa599: mptcp: use tcp_build_frag()
- 7b6333e0b375: conflict in t/mptcp-move-page-frag-allocation-in-mptcp_sendmsg
- Results: a26726f4d29b..653eafae048c
May you have a look at resolution of the conflicts I did please?
Tests + export are going in progress!
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net