From: Paolo Abeni <pabeni@redhat.com>
To: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next 2/4] mptcp: stop relaying on tcp_tx_skb_cache.
Date: Thu, 02 Sep 2021 17:00:21 +0200 [thread overview]
Message-ID: <ea1f947cc9661d26b25c3c4e8f5d5698352d91aa.camel@redhat.com> (raw)
In-Reply-To: <77a77e43a30e0338a1b7a0c811b8e6451862eb02.1630591985.git.pabeni@redhat.com>
On Thu, 2021-09-02 at 16:20 +0200, Paolo Abeni wrote:
> We want to revert the skb TX cache, but MPTCP is currently
> using it unconditionally.
>
> Rework the MPTCP tx code, so that tcp_tx_skb_cache is not
> needed anymore: do the whole coalescing check, skb allocation
> skb initialization/update inside mptcp_sendmsg_frag(), quite
> alike the current TCP code.
>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
> net/mptcp/protocol.c | 131 +++++++++++++++++++++++++------------------
> 1 file changed, 76 insertions(+), 55 deletions(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index faf6e7000d18..98fdb0ebd68d 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -1224,6 +1224,7 @@ static struct sk_buff *__mptcp_do_alloc_tx_skb(struct sock *sk, gfp_t gfp)
> if (likely(__mptcp_add_ext(skb, gfp))) {
> skb_reserve(skb, MAX_TCP_HEADER);
> skb->reserved_tailroom = skb->end - skb->tail;
> + INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
> return skb;
> }
> __kfree_skb(skb);
> @@ -1233,31 +1234,23 @@ static struct sk_buff *__mptcp_do_alloc_tx_skb(struct sock *sk, gfp_t gfp)
> return NULL;
> }
>
> -static bool __mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, gfp_t gfp)
> +static struct sk_buff *__mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, gfp_t gfp)
> {
> struct sk_buff *skb;
>
> - if (ssk->sk_tx_skb_cache) {
> - skb = ssk->sk_tx_skb_cache;
> - if (unlikely(!skb_ext_find(skb, SKB_EXT_MPTCP) &&
> - !__mptcp_add_ext(skb, gfp)))
> - return false;
> - return true;
> - }
> -
> skb = __mptcp_do_alloc_tx_skb(sk, gfp);
> if (!skb)
> - return false;
> + return NULL;
>
> if (likely(sk_wmem_schedule(ssk, skb->truesize))) {
> - ssk->sk_tx_skb_cache = skb;
> - return true;
> + skb_entail(ssk, skb);
> + return skb;
> }
> kfree_skb(skb);
> - return false;
> + return NULL;
> }
>
> -static bool mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, bool data_lock_held)
> +static struct sk_buff *mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, bool data_lock_held)
> {
> gfp_t gfp = data_lock_held ? GFP_ATOMIC : sk->sk_allocation;
>
> @@ -1287,23 +1280,29 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
> struct mptcp_sendmsg_info *info)
> {
> u64 data_seq = dfrag->data_seq + info->sent;
> + int offset = dfrag->offset + info->sent;
> struct mptcp_sock *msk = mptcp_sk(sk);
> bool zero_window_probe = false;
> struct mptcp_ext *mpext = NULL;
> - struct sk_buff *skb, *tail;
> - bool must_collapse = false;
> - int size_bias = 0;
> - int avail_size;
> - size_t ret = 0;
> + bool can_coalesce = false;
> + bool reuse_skb = true;
> + struct sk_buff *skb;
> + size_t copy;
> + int i = 0;
>
> pr_debug("msk=%p ssk=%p sending dfrag at seq=%llu len=%u already sent=%u",
> msk, ssk, dfrag->data_seq, dfrag->data_len, info->sent);
>
> + if (WARN_ON_ONCE(info->sent > info->limit ||
> + info->limit > dfrag->data_len))
> + return 0;
> +
> /* compute send limit */
> info->mss_now = tcp_send_mss(ssk, &info->size_goal, info->flags);
> - avail_size = info->size_goal;
> + copy = info->size_goal;
> +
> skb = tcp_write_queue_tail(ssk);
> - if (skb) {
> + if (skb && (copy > skb->len)) {
> /* Limit the write to the size available in the
> * current skb, if any, so that we create at most a new skb.
> * Explicitly tells TCP internals to avoid collapsing on later
> @@ -1316,53 +1315,75 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
> goto alloc_skb;
> }
>
> - must_collapse = (info->size_goal - skb->len > 0) &&
> - (skb_shinfo(skb)->nr_frags < sysctl_max_skb_frags);
> - if (must_collapse) {
> - size_bias = skb->len;
> - avail_size = info->size_goal - skb->len;
> + i = skb_shinfo(skb)->nr_frags;
> + can_coalesce = skb_can_coalesce(skb, i, dfrag->page, offset);
> + if (!can_coalesce && i >= sysctl_max_skb_frags) {
> + tcp_mark_push(tcp_sk(ssk), skb);
> + goto alloc_skb;
> }
> - }
>
> + copy -= skb->len;
> + } else {
> alloc_skb:
> - if (!must_collapse && !ssk->sk_tx_skb_cache &&
> - !mptcp_alloc_tx_skb(sk, ssk, info->data_lock_held))
> - return 0;
> + skb = mptcp_alloc_tx_skb(sk, ssk, info->data_lock_held);
> + if (!skb)
> + return -ENOMEM;
> +
> + reuse_skb = false;
Uhm... looks like I need to fetch again 'skb_shinfo(skb)->nr_frags'
here. That could be possibly the cause of the OoB I'm observing. Will
send a v2 soon after some more testing.
/P
next prev parent reply other threads:[~2021-09-02 15:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-02 14:20 [PATCH mptcp-next 0/4] mptcp: just another xmit path refactor Paolo Abeni
2021-09-02 14:20 ` [PATCH mptcp-next 1/4] tcp: expose the tcp_mark_push() and skb_entail() helpers Paolo Abeni
2021-09-02 14:20 ` [PATCH mptcp-next 2/4] mptcp: stop relaying on tcp_tx_skb_cache Paolo Abeni
2021-09-02 15:00 ` Paolo Abeni [this message]
2021-09-02 14:20 ` [PATCH mptcp-next 3/4] Partially revert "tcp: factor out tcp_build_frag()" Paolo Abeni
2021-09-02 14:20 ` [PATCH mptcp-next 4/4] tcp: remove sk_{tr}x_skb_cache Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea1f947cc9661d26b25c3c4e8f5d5698352d91aa.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=mptcp@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox