LCOV - code coverage report
Current view: top level - mptcp/protocol.c (source / functions) Coverage Total Hit
Test: export-net Lines: 90.9 % 2714 2466
Test Date: 2026-11-27 21:22:29 Functions: 94.4 % 161 152
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 68.4 % 1751 1198

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-2.0
       2                 :             : /* Multipath TCP
       3                 :             :  *
       4                 :             :  * Copyright (c) 2017 - 2019, Intel Corporation.
       5                 :             :  */
       6                 :             : 
       7                 :             : #define pr_fmt(fmt) "MPTCP: " fmt
       8                 :             : 
       9                 :             : #include <linux/kernel.h>
      10                 :             : #include <linux/module.h>
      11                 :             : #include <linux/netdevice.h>
      12                 :             : #include <linux/sched/signal.h>
      13                 :             : #include <linux/atomic.h>
      14                 :             : #include <net/aligned_data.h>
      15                 :             : #include <net/rps.h>
      16                 :             : #include <net/sock.h>
      17                 :             : #include <net/inet_common.h>
      18                 :             : #include <net/inet_hashtables.h>
      19                 :             : #include <net/protocol.h>
      20                 :             : #include <net/tcp_states.h>
      21                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
      22                 :             : #include <net/transp_v6.h>
      23                 :             : #endif
      24                 :             : #include <net/mptcp.h>
      25                 :             : #include <net/hotdata.h>
      26                 :             : #include <net/xfrm.h>
      27                 :             : #include <asm/ioctls.h>
      28                 :             : #include "protocol.h"
      29                 :             : #include "mib.h"
      30                 :             : 
      31                 :             : static unsigned int mptcp_inq_hint(const struct sock *sk);
      32                 :             : 
      33                 :             : #define CREATE_TRACE_POINTS
      34                 :             : #include <trace/events/mptcp.h>
      35                 :             : 
      36                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
      37                 :             : struct mptcp6_sock {
      38                 :             :         struct mptcp_sock msk;
      39                 :             :         struct ipv6_pinfo np;
      40                 :             : };
      41                 :             : #endif
      42                 :             : 
      43                 :             : enum {
      44                 :             :         MPTCP_CMSG_TS = BIT(0),
      45                 :             :         MPTCP_CMSG_INQ = BIT(1),
      46                 :             : };
      47                 :             : 
      48                 :             : static struct percpu_counter mptcp_sockets_allocated ____cacheline_aligned_in_smp;
      49                 :             : 
      50                 :             : static void __mptcp_destroy_sock(struct sock *sk);
      51                 :             : static void mptcp_check_send_data_fin(struct sock *sk);
      52                 :             : 
      53                 :             : DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions) = {
      54                 :             :         .bh_lock = INIT_LOCAL_LOCK(bh_lock),
      55                 :             : };
      56                 :             : static struct net_device *mptcp_napi_dev;
      57                 :             : 
      58                 :             : /* Returns end sequence number of the receiver's advertised window */
      59                 :          36 : static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
      60                 :             : {
      61                 :     1590686 :         return READ_ONCE(msk->wnd_end);
      62                 :             : }
      63                 :             : 
      64                 :         178 : static const struct proto_ops *mptcp_fallback_tcp_ops(const struct sock *sk)
      65                 :             : {
      66                 :         178 :         unsigned short family = READ_ONCE(sk->sk_family);
      67                 :             : 
      68                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
      69            [ + ]:         178 :         if (family == AF_INET6)
      70                 :             :                 return &inet6_stream_ops;
      71                 :             : #endif
      72            [ + ]:          88 :         WARN_ON_ONCE(family != AF_INET);
      73                 :             :         return &inet_stream_ops;
      74                 :             : }
      75                 :             : 
      76                 :         220 : bool __mptcp_try_fallback(struct mptcp_sock *msk, int fb_mib)
      77                 :             : {
      78                 :         220 :         struct net *net = sock_net((struct sock *)msk);
      79                 :             : 
      80       [ + ][ + ]:         220 :         if (__mptcp_check_fallback(msk))
      81                 :             :                 return true;
      82                 :             : 
      83                 :             :         /* The caller possibly is not holding the msk socket lock, but
      84                 :             :          * in the fallback case only the current subflow is touching
      85                 :             :          * the OoO queue.
      86                 :             :          */
      87       [ + ][ + ]:         220 :         if (!RB_EMPTY_ROOT(&msk->out_of_order_queue))
      88                 :             :                 return false;
      89                 :             : 
      90                 :         220 :         spin_lock_bh(&msk->fallback_lock);
      91    [ + ][ +  + ]:         220 :         if (!msk->allow_infinite_fallback) {
      92                 :           6 :                 spin_unlock_bh(&msk->fallback_lock);
      93                 :           6 :                 return false;
      94                 :             :         }
      95                 :             : 
      96                 :         214 :         msk->allow_subflows = false;
      97                 :         214 :         set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
      98                 :         214 :         clear_bit(MPTCP_RTX_ENABLED, &msk->flags);
      99       [ - ][ - ]:         214 :         __MPTCP_INC_STATS(net, fb_mib);
     100                 :         214 :         spin_unlock_bh(&msk->fallback_lock);
     101                 :         214 :         return true;
     102                 :             : }
     103                 :             : 
     104                 :        3514 : static int __mptcp_socket_create(struct mptcp_sock *msk)
     105                 :             : {
     106                 :        3514 :         struct mptcp_subflow_context *subflow;
     107                 :        3514 :         struct sock *sk = (struct sock *)msk;
     108                 :        3514 :         struct socket *ssock;
     109                 :        3514 :         int err;
     110                 :             : 
     111                 :        3514 :         err = mptcp_subflow_create_socket(sk, sk->sk_family, &ssock);
     112       [ - ][ - ]:        3514 :         if (err)
     113                 :             :                 return err;
     114                 :             : 
     115            [ + ]:        3514 :         msk->scaling_ratio = tcp_sk(ssock->sk)->scaling_ratio;
     116                 :        3514 :         WRITE_ONCE(msk->first, ssock->sk);
     117            [ - ]:        3514 :         subflow = mptcp_subflow_ctx(ssock->sk);
     118            [ - ]:        3514 :         list_add(&subflow->node, &msk->conn_list);
     119                 :        3514 :         sock_hold(ssock->sk);
     120                 :        3514 :         subflow->request_mptcp = 1;
     121                 :        3514 :         subflow->subflow_id = msk->subflow_id++;
     122                 :             : 
     123                 :             :         /* This is the first subflow, always with id 0 */
     124                 :        3514 :         WRITE_ONCE(subflow->local_id, 0);
     125                 :        3514 :         mptcp_sock_graft(msk->first, sk->sk_socket);
     126                 :        3514 :         iput(SOCK_INODE(ssock));
     127                 :             : 
     128                 :        3514 :         return 0;
     129                 :             : }
     130                 :             : 
     131                 :             : /* If the MPC handshake is not started, returns the first subflow,
     132                 :             :  * eventually allocating it.
     133                 :             :  */
     134                 :       10295 : struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk)
     135                 :             : {
     136                 :       10295 :         struct sock *sk = (struct sock *)msk;
     137                 :       10295 :         int ret;
     138                 :             : 
     139    [ + ][ +  + ]:       10295 :         if (!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
     140                 :             :                 return ERR_PTR(-EINVAL);
     141                 :             : 
     142       [ + ][ + ]:       10277 :         if (!msk->first) {
     143                 :        3514 :                 ret = __mptcp_socket_create(msk);
     144       [ + ][ + ]:        3514 :                 if (ret)
     145                 :           0 :                         return ERR_PTR(ret);
     146                 :             :         }
     147                 :             : 
     148                 :       10277 :         return msk->first;
     149                 :             : }
     150                 :             : 
     151                 :         478 : static void mptcp_drop(struct sock *sk, struct sk_buff *skb)
     152                 :             : {
     153                 :             :         /* The skb forward memory was already transferred to sk by
     154                 :             :          * mptcp_borrow_fwdmem(), even before setting the destructor.
     155                 :             :          */
     156            [ + ]:         478 :         if (!skb->destructor)
     157                 :         241 :                 sk_mem_reclaim(sk);
     158                 :             : 
     159                 :         478 :         sk_drops_skbadd(sk, skb);
     160                 :         478 :         __kfree_skb(skb);
     161                 :         478 : }
     162                 :             : 
     163                 :      574582 : static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
     164                 :             :                                  struct sk_buff *from, bool *fragstolen,
     165                 :             :                                  int *delta)
     166                 :             : {
     167                 :      574582 :         int limit = READ_ONCE(sk->sk_rcvbuf);
     168                 :             : 
     169            [ + ]:      574582 :         if (unlikely(MPTCP_SKB_CB(to)->cant_coalesce) ||
     170            [ + ]:      574557 :             MPTCP_SKB_CB(from)->offset ||
     171         [ +  + ]:     1104836 :             ((to->len + from->len) > (limit >> 3)) ||
     172                 :      530289 :             !skb_try_coalesce(to, from, fragstolen, delta))
     173                 :      161170 :                 return false;
     174                 :             : 
     175         [ -  - ]:      413412 :         pr_debug("colesced seq %llx into %llx new len %d new end seq %llx\n",
     176                 :             :                  MPTCP_SKB_CB(from)->map_seq, MPTCP_SKB_CB(to)->map_seq,
     177                 :             :                  to->len, MPTCP_SKB_CB(from)->end_seq);
     178                 :      413412 :         MPTCP_SKB_CB(to)->end_seq = MPTCP_SKB_CB(from)->end_seq;
     179                 :      413412 :         return true;
     180                 :             : }
     181                 :             : 
     182                 :      502710 : static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
     183                 :             :                                struct sk_buff *from)
     184                 :             : {
     185                 :      502710 :         bool fragstolen;
     186                 :      502710 :         int delta;
     187                 :             : 
     188       [ + ][ + ]:      502710 :         if (!__mptcp_try_coalesce(sk, to, from, &fragstolen, &delta))
     189                 :             :                 return false;
     190                 :             : 
     191                 :             :         /* note the fwd memory can reach a negative value after accounting
     192                 :             :          * for the delta, but the later skb free will restore a non
     193                 :             :          * negative one
     194                 :             :          */
     195                 :      373258 :         atomic_add(delta, &sk->sk_rmem_alloc);
     196       [ - ][ - ]:      373258 :         sk_mem_charge(sk, delta);
     197            [ + ]:      373258 :         kfree_skb_partial(from, fragstolen);
     198                 :             : 
     199                 :             :         /* release what is left of the borrowed 'from' truesize */
     200                 :      373258 :         sk_mem_reclaim(sk);
     201                 :             : 
     202                 :      373258 :         return true;
     203                 :             : }
     204                 :             : 
     205                 :           0 : static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
     206                 :             :                                    struct sk_buff *from)
     207                 :             : {
     208       [ + ][ + ]:       32058 :         if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq)
     209                 :             :                 return false;
     210                 :             : 
     211                 :      196722 :         return mptcp_try_coalesce((struct sock *)msk, to, from);
     212                 :             : }
     213                 :             : 
     214                 :             : /* "inspired" by tcp_rcvbuf_grow(), main difference:
     215                 :             :  * - mptcp does not maintain a msk-level window clamp
     216                 :             :  * - returns true when  the receive buffer is actually updated
     217                 :             :  */
     218                 :        4931 : static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval)
     219                 :             : {
     220            [ + ]:        4931 :         struct mptcp_sock *msk = mptcp_sk(sk);
     221            [ - ]:        4931 :         const struct net *net = sock_net(sk);
     222                 :        4931 :         u32 rcvwin, rcvbuf, cap, oldval;
     223                 :        4931 :         u64 grow;
     224                 :             : 
     225                 :        4931 :         oldval = msk->rcvq_space.space;
     226                 :        4931 :         msk->rcvq_space.space = newval;
     227       [ - ][ - ]:        4931 :         if (!READ_ONCE(net->ipv4.sysctl_tcp_moderate_rcvbuf) ||
     228       [ + ][ + ]:        4931 :             (sk->sk_userlocks & SOCK_RCVBUF_LOCK))
     229                 :             :                 return false;
     230                 :             : 
     231                 :             :         /* DRS is always one RTT late. */
     232                 :        4931 :         rcvwin = newval << 1;
     233                 :             : 
     234                 :             :         /* slow start: allow the sender to double its rate. */
     235                 :        4931 :         grow = (u64)rcvwin * (newval - oldval);
     236                 :        4931 :         do_div(grow, oldval);
     237                 :        4931 :         rcvwin += grow << 1;
     238                 :             : 
     239                 :        4931 :         cap = READ_ONCE(net->ipv4.sysctl_tcp_rmem[2]);
     240                 :             : 
     241                 :        4931 :         rcvbuf = min_t(u32, mptcp_space_from_win(sk, rcvwin), cap);
     242       [ + ][ + ]:        4931 :         if (rcvbuf > sk->sk_rcvbuf) {
     243                 :        2685 :                 WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
     244                 :        2685 :                 return true;
     245                 :             :         }
     246                 :             :         return false;
     247                 :             : }
     248                 :             : 
     249                 :             : /* "Inspired" from the TCP version; main difference: stop as soon as the MPTCP
     250                 :             :  * socket is under memory limit.
     251                 :             :  */
     252                 :           5 : static void mptcp_prune_ofo_queue(struct sock *sk,
     253                 :             :                                   const struct sk_buff *in_skb)
     254                 :             : {
     255            [ + ]:           5 :         struct mptcp_sock *msk = mptcp_sk(sk);
     256                 :           5 :         struct rb_node *node, *prev;
     257                 :           5 :         bool pruned = false;
     258                 :           5 :         u64 mem;
     259                 :             : 
     260       [ - ][ + ]:           5 :         if (RB_EMPTY_ROOT(&msk->out_of_order_queue))
     261                 :             :                 return;
     262                 :             : 
     263                 :           4 :         node = &msk->ooo_last_skb->rbnode;
     264                 :             : 
     265                 :           4 :         do {
     266                 :           4 :                 struct sk_buff *skb = rb_to_skb(node);
     267                 :             : 
     268                 :             :                 /* Stop pruning if the incoming skb would land in OoO tail. */
     269       [ + ][ # ]:           4 :                 if (after64(MPTCP_SKB_CB(in_skb)->map_seq,
     270                 :             :                             MPTCP_SKB_CB(skb)->map_seq))
     271                 :             :                         break;
     272                 :             : 
     273                 :           1 :                 pruned = true;
     274                 :           1 :                 prev = rb_prev(node);
     275                 :           1 :                 rb_erase(node, &msk->out_of_order_queue);
     276                 :           1 :                 mptcp_drop(sk, skb);
     277                 :           1 :                 msk->ooo_last_skb = rb_to_skb(prev);
     278                 :             : 
     279            [ + ]:           1 :                 mem = (unsigned int)sk_rmem_alloc_get(sk);
     280       [ + ][ # ]:           1 :                 if (mem <= sk->sk_rcvbuf)
     281                 :             :                         break;
     282                 :             : 
     283                 :           0 :                 node = prev;
     284       [ # ][ # ]:           0 :         } while (node);
     285                 :             : 
     286       [ + ][ # ]:           4 :         if (pruned)
     287       [ - ][ # ]:           1 :                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOPRUNED);
     288                 :             : }
     289                 :             : 
     290                 :             : /* The stack can't drop packets for fallback socket at the msk level, or the
     291                 :             :  * stream will break.
     292                 :             :  */
     293                 :      995746 : static bool mptcp_can_ingest(const struct sock *sk)
     294                 :             : {
     295 [ +  + ][ +  + ]:      995755 :         return likely(sk_rmem_alloc_get(sk) <= READ_ONCE(sk->sk_rcvbuf)) ||
     296       [ + ][ + ]:           9 :                __mptcp_check_fallback(mptcp_sk(sk));
     297                 :             : }
     298                 :             : 
     299                 :      995741 : static bool mptcp_try_rmem_schedule(struct sock *sk, const struct sk_buff *skb)
     300                 :             : {
     301            [ + ]:      995741 :         if (!mptcp_can_ingest(sk)) {
     302                 :           5 :                 mptcp_prune_ofo_queue(sk, skb);
     303                 :           5 :                 return mptcp_can_ingest(sk);
     304                 :             :         }
     305                 :             :         return true;
     306                 :             : }
     307                 :             : 
     308                 :             : /* "inspired" by tcp_data_queue_ofo(), main differences:
     309                 :             :  * - use mptcp seqs
     310                 :             :  * - don't cope with sacks
     311                 :             :  */
     312                 :      179256 : static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
     313                 :             : {
     314                 :      179256 :         struct sock *sk = (struct sock *)msk;
     315                 :      179256 :         struct rb_node **p, *parent;
     316                 :      179256 :         u64 seq, end_seq, max_seq;
     317                 :      179256 :         struct sk_buff *skb1;
     318                 :             : 
     319                 :      179256 :         seq = MPTCP_SKB_CB(skb)->map_seq;
     320                 :      179256 :         end_seq = MPTCP_SKB_CB(skb)->end_seq;
     321            [ - ]:      179256 :         max_seq = atomic64_read(&msk->rcv_wnd_sent);
     322                 :             : 
     323 [ -  - ][ -  - ]:      179256 :         pr_debug("msk=%p seq=%llx limit=%llx empty=%d\n", msk, seq, max_seq,
     324                 :             :                  RB_EMPTY_ROOT(&msk->out_of_order_queue));
     325       [ + ][ + ]:      179256 :         if (after64(end_seq, max_seq)) {
     326                 :             :                 /* out of window */
     327                 :          17 :                 mptcp_drop(sk, skb);
     328 [ #  # ][ -  - ]:          17 :                 pr_debug("oow by %lld, rcv_wnd_sent %llu\n",
     329                 :             :                          (unsigned long long)end_seq - (unsigned long)max_seq,
     330                 :             :                          (unsigned long long)atomic64_read(&msk->rcv_wnd_sent));
     331       [ # ][ # ]:          17 :                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_NODSSWINDOW);
     332                 :          17 :                 return;
     333                 :             :         }
     334                 :             : 
     335       [ + ][ + ]:      179239 :         if (!mptcp_try_rmem_schedule(sk, skb)) {
     336       [ - ][ # ]:           3 :                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVPRUNED);
     337                 :           3 :                 mptcp_drop(sk, skb);
     338                 :           3 :                 return;
     339                 :             :         }
     340                 :             : 
     341                 :      179236 :         p = &msk->out_of_order_queue.rb_node;
     342       [ - ][ # ]:      179236 :         MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUE);
     343       [ + ][ + ]:      179236 :         if (RB_EMPTY_ROOT(&msk->out_of_order_queue)) {
     344                 :        5841 :                 rb_link_node(&skb->rbnode, NULL, p);
     345                 :        5841 :                 rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
     346                 :        5841 :                 msk->ooo_last_skb = skb;
     347                 :        5841 :                 goto end;
     348                 :             :         }
     349                 :             : 
     350                 :             :         /* with 2 subflows, adding at end of ooo queue is quite likely
     351                 :             :          * Use of ooo_last_skb avoids the O(Log(N)) rbtree lookup.
     352                 :             :          */
     353 [ +  + ][ +  + ]:      324491 :         if (mptcp_ooo_try_coalesce(msk, msk->ooo_last_skb, skb)) {
     354       [ - ][ # ]:      136138 :                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
     355       [ - ][ # ]:      136138 :                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
     356                 :      136138 :                 return;
     357                 :             :         }
     358                 :             : 
     359                 :             :         /* Can avoid an rbtree lookup if we are adding skb after ooo_last_skb */
     360       [ + ][ + ]:       37257 :         if (!before64(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq)) {
     361       [ - ][ # ]:       21325 :                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
     362                 :       21325 :                 parent = &msk->ooo_last_skb->rbnode;
     363                 :       21325 :                 p = &parent->rb_right;
     364                 :       21325 :                 goto insert;
     365                 :             :         }
     366                 :             : 
     367                 :             :         /* Find place to insert this segment. Handle overlaps on the way. */
     368                 :             :         parent = NULL;
     369       [ + ][ + ]:       86763 :         while (*p) {
     370                 :       81649 :                 parent = *p;
     371                 :       81649 :                 skb1 = rb_to_skb(parent);
     372       [ + ][ + ]:       81649 :                 if (before64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
     373                 :       23653 :                         p = &parent->rb_left;
     374                 :       23653 :                         continue;
     375                 :             :                 }
     376       [ + ][ + ]:       57996 :                 if (before64(seq, MPTCP_SKB_CB(skb1)->end_seq)) {
     377       [ + ][ + ]:         337 :                         if (!after64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) {
     378                 :             :                                 /* All the bits are present. Drop. */
     379                 :         192 :                                 mptcp_drop(sk, skb);
     380       [ - ][ # ]:         192 :                                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
     381                 :         192 :                                 return;
     382                 :             :                         }
     383       [ + ][ + ]:         145 :                         if (after64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
     384                 :             :                                 /* partial overlap:
     385                 :             :                                  *     |     skb      |
     386                 :             :                                  *  |     skb1    |
     387                 :             :                                  * continue traversing
     388                 :             :                                  */
     389                 :             :                         } else {
     390                 :             :                                 /* skb's seq == skb1's seq and skb covers skb1.
     391                 :             :                                  * Replace skb1 with skb.
     392                 :             :                                  */
     393                 :          15 :                                 rb_replace_node(&skb1->rbnode, &skb->rbnode,
     394                 :             :                                                 &msk->out_of_order_queue);
     395                 :          15 :                                 mptcp_drop(sk, skb1);
     396       [ - ][ # ]:          15 :                                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
     397                 :          15 :                                 goto merge_right;
     398                 :             :                         }
     399 [ +  + ][ +  + ]:       71722 :                 } else if (mptcp_ooo_try_coalesce(msk, skb1, skb)) {
     400       [ - ][ # ]:       10611 :                         MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
     401                 :       10611 :                         return;
     402                 :             :                 }
     403                 :       47178 :                 p = &parent->rb_right;
     404                 :             :         }
     405                 :             : 
     406                 :        5114 : insert:
     407                 :             :         /* Insert segment into RB tree. */
     408                 :       26439 :         rb_link_node(&skb->rbnode, parent, p);
     409                 :       26439 :         rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
     410                 :             : 
     411                 :             : merge_right:
     412                 :             :         /* Remove other segments covered by skb. */
     413       [ + ][ + ]:       26529 :         while ((skb1 = skb_rb_next(skb)) != NULL) {
     414       [ + ][ + ]:        5204 :                 if (before64(end_seq, MPTCP_SKB_CB(skb1)->end_seq))
     415                 :             :                         break;
     416                 :          75 :                 rb_erase(&skb1->rbnode, &msk->out_of_order_queue);
     417                 :          75 :                 mptcp_drop(sk, skb1);
     418       [ - ][ # ]:          75 :                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
     419                 :             :         }
     420                 :             :         /* If there is no skb after us, we are the last_skb ! */
     421       [ + ][ + ]:       26454 :         if (!skb1)
     422                 :       21325 :                 msk->ooo_last_skb = skb;
     423                 :             : 
     424                 :        5129 : end:
     425                 :       32295 :         skb_condense(skb);
     426                 :       32295 :         skb_set_owner_r(skb, sk);
     427                 :             : 
     428                 :             :         /* skb_condense() can shrink the truesize borrowed from the subflow */
     429                 :       32295 :         sk_mem_reclaim(sk);
     430                 :             : }
     431                 :             : 
     432                 :     1035940 : static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
     433                 :             :                            int copy_len)
     434                 :             : {
     435                 :     1035940 :         struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
     436                 :     1035940 :         bool has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
     437                 :             : 
     438                 :             :         /* the skb map_seq accounts for the skb offset:
     439                 :             :          * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
     440                 :             :          * value
     441                 :             :          */
     442                 :     1035940 :         MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow);
     443                 :     1035940 :         MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
     444                 :     1035940 :         MPTCP_SKB_CB(skb)->offset = offset;
     445                 :     1035940 :         MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
     446                 :     1035940 :         MPTCP_SKB_CB(skb)->cant_coalesce = 0;
     447                 :             : 
     448                 :     1035940 :         __skb_unlink(skb, &ssk->sk_receive_queue);
     449                 :             : 
     450                 :     1035940 :         skb_ext_reset(skb);
     451            [ + ]:     1035940 :         skb_dst_drop(skb);
     452                 :     1035940 : }
     453                 :             : 
     454                 :      995786 : static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
     455                 :             : {
     456                 :      995786 :         u64 copy_len = MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;
     457            [ + ]:      995786 :         struct mptcp_sock *msk = mptcp_sk(sk);
     458                 :      995786 :         struct sk_buff *tail;
     459                 :             : 
     460                 :      995786 :         mptcp_borrow_fwdmem(sk, skb);
     461                 :             : 
     462       [ + ][ + ]:      995786 :         if (MPTCP_SKB_CB(skb)->map_seq == msk->ack_seq) {
     463                 :             :                 /* in sequence */
     464                 :      816502 : insert:
     465       [ + ][ + ]:      816502 :                 if (!mptcp_try_rmem_schedule(sk, skb)) {
     466       [ # ][ # ]:           1 :                         MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RCVPRUNED);
     467                 :           1 :                         mptcp_drop(sk, skb);
     468                 :           1 :                         return false;
     469                 :             :                 }
     470                 :             : 
     471                 :      816501 :                 msk->bytes_received += copy_len;
     472                 :      816501 :                 WRITE_ONCE(msk->ack_seq, msk->ack_seq + copy_len);
     473       [ + ][ + ]:      816501 :                 tail = skb_peek_tail(&sk->sk_receive_queue);
     474 [ -  + ][ -  + ]:      305988 :                 if (tail && mptcp_try_coalesce(sk, tail, skb))
     475                 :             :                         return true;
     476                 :             : 
     477                 :      603000 :                 skb_set_owner_r(skb, sk);
     478                 :      603000 :                 __skb_queue_tail(&sk->sk_receive_queue, skb);
     479                 :      603000 :                 return true;
     480       [ + ][ + ]:      179284 :         } else if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq)) {
     481                 :      179256 :                 mptcp_data_queue_ofo(msk, skb);
     482                 :      179256 :                 return false;
     483                 :             :         }
     484                 :             : 
     485                 :             :         /* Partial packet */
     486       [ + ][ + ]:          28 :         if (after64(MPTCP_SKB_CB(skb)->end_seq, msk->ack_seq)) {
     487                 :           0 :                 copy_len = MPTCP_SKB_CB(skb)->end_seq - msk->ack_seq;
     488                 :           0 :                 MPTCP_SKB_CB(skb)->offset += msk->ack_seq -
     489                 :             :                                              MPTCP_SKB_CB(skb)->map_seq;
     490                 :           0 :                 MPTCP_SKB_CB(skb)->map_seq += msk->ack_seq -
     491                 :             :                                               MPTCP_SKB_CB(skb)->map_seq;
     492                 :           0 :                 goto insert;
     493                 :             :         }
     494                 :             : 
     495                 :             :         /* Completely old data */
     496       [ - ][ # ]:          28 :         MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
     497                 :          28 :         mptcp_drop(sk, skb);
     498                 :          28 :         return false;
     499                 :             : }
     500                 :             : 
     501                 :       34865 : static void mptcp_stop_rtx_timer(struct sock *sk)
     502                 :             : {
     503                 :       34865 :         sk_stop_timer(sk, &sk->mptcp_retransmit_timer);
     504            [ + ]:       34865 :         mptcp_sk(sk)->timer_ival = 0;
     505                 :       34865 : }
     506                 :             : 
     507                 :        6059 : static void mptcp_close_wake_up(struct sock *sk)
     508                 :             : {
     509            [ + ]:        6059 :         if (sock_flag(sk, SOCK_DEAD))
     510                 :             :                 return;
     511                 :             : 
     512                 :        4478 :         sk->sk_state_change(sk);
     513            [ + ]:        4478 :         if (sk->sk_shutdown == SHUTDOWN_MASK ||
     514            [ + ]:        2245 :             sk->sk_state == TCP_CLOSE)
     515                 :        2289 :                 sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
     516                 :             :         else
     517                 :        2189 :                 sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
     518                 :             : }
     519                 :             : 
     520                 :        2436 : static void mptcp_shutdown_subflows(struct mptcp_sock *msk)
     521                 :             : {
     522                 :        2436 :         struct mptcp_subflow_context *subflow;
     523                 :             : 
     524            [ + ]:        5708 :         mptcp_for_each_subflow(msk, subflow) {
     525                 :        3272 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
     526                 :        3272 :                 bool slow;
     527                 :             : 
     528                 :        3272 :                 slow = lock_sock_fast(ssk);
     529                 :        3272 :                 tcp_shutdown(ssk, SEND_SHUTDOWN);
     530                 :        3272 :                 unlock_sock_fast(ssk, slow);
     531                 :             :         }
     532                 :        2436 : }
     533                 :             : 
     534                 :             : /* called under the msk socket lock */
     535                 :      389512 : static bool mptcp_pending_data_fin_ack(struct sock *sk)
     536                 :             : {
     537            [ + ]:      389512 :         struct mptcp_sock *msk = mptcp_sk(sk);
     538                 :             : 
     539                 :      208379 :         return ((1 << sk->sk_state) &
     540    [ + ][ +  + ]:      389512 :                 (TCPF_FIN_WAIT1 | TCPF_CLOSING | TCPF_LAST_ACK)) &&
     541       [ + ][ + ]:       74326 :                msk->write_seq == READ_ONCE(msk->snd_una);
     542                 :             : }
     543                 :             : 
     544                 :       12632 : static void mptcp_check_data_fin_ack(struct sock *sk)
     545                 :             : {
     546            [ + ]:       12632 :         struct mptcp_sock *msk = mptcp_sk(sk);
     547                 :             : 
     548                 :             :         /* Look for an acknowledged DATA_FIN */
     549            [ + ]:       12632 :         if (mptcp_pending_data_fin_ack(sk)) {
     550                 :        2525 :                 WRITE_ONCE(msk->snd_data_fin_enable, 0);
     551                 :             : 
     552      [ +  +  - ]:        2525 :                 switch (sk->sk_state) {
     553                 :        1369 :                 case TCP_FIN_WAIT1:
     554                 :        1369 :                         mptcp_set_state(sk, TCP_FIN_WAIT2);
     555                 :        1369 :                         break;
     556                 :        1156 :                 case TCP_CLOSING:
     557                 :             :                 case TCP_LAST_ACK:
     558                 :        1156 :                         mptcp_shutdown_subflows(msk);
     559                 :        1156 :                         mptcp_set_state(sk, TCP_CLOSE);
     560                 :        1156 :                         break;
     561                 :             :                 }
     562                 :             : 
     563                 :        2525 :                 mptcp_close_wake_up(sk);
     564                 :             :         }
     565                 :       12632 : }
     566                 :             : 
     567                 :             : /* can be called with no lock acquired */
     568                 :      912908 : static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
     569                 :             : {
     570            [ + ]:      912908 :         struct mptcp_sock *msk = mptcp_sk(sk);
     571                 :             : 
     572         [ +  + ]:      947526 :         if (READ_ONCE(msk->rcv_data_fin) &&
           [ +  +  +  + ]
         [ +  +  + ][ + ]
     573       [ + ][ + ]:          34 :             ((1 << inet_sk_state_load(sk)) &
     574                 :             :              (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {
     575                 :       33903 :                 u64 rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
     576                 :             : 
     577       [ + ][ + ]:       33903 :                 if (READ_ONCE(msk->ack_seq) == rcv_data_fin_seq) {
     578       [ + ][ + ]:        3251 :                         if (seq)
     579                 :        2642 :                                 *seq = rcv_data_fin_seq;
     580                 :             : 
     581                 :        3251 :                         return true;
     582                 :             :                 }
     583                 :             :         }
     584                 :             : 
     585                 :             :         return false;
     586                 :             : }
     587                 :             : 
     588                 :        1387 : static void mptcp_set_datafin_timeout(struct sock *sk)
     589                 :             : {
     590                 :        1387 :         struct inet_connection_sock *icsk = inet_csk(sk);
     591                 :        1387 :         u32 rto_min = READ_ONCE(icsk->icsk_rto_min);
     592                 :        1387 :         u32 rto_max = READ_ONCE(icsk->icsk_rto_max);
     593                 :        1387 :         u32 retransmits;
     594                 :             : 
     595                 :             :         /* The sysctls are validated independently: rto_min > rto_max is
     596                 :             :          * possible, guard against ilog2(0).
     597                 :             :          */
     598            [ + ]:        1387 :         retransmits = min_t(u32, icsk->icsk_retransmits,
     599                 :             :                             ilog2(max_t(u32, rto_max / rto_min, 1)));
     600                 :             : 
     601    [ + ][ +  + ]:        1387 :         mptcp_sk(sk)->timer_ival = rto_min << retransmits;
     602                 :        1387 : }
     603                 :             : 
     604                 :     1032109 : static void __mptcp_set_timeout(struct sock *sk, long tout)
     605                 :             : {
     606         [ +  + ]:     1326353 :         mptcp_sk(sk)->timer_ival = tout > 0 ? tout :
     607                 :      294244 :                                    READ_ONCE(inet_csk(sk)->icsk_rto_min);
     608                 :     1032109 : }
     609                 :             : 
     610                 :          36 : static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subflow)
     611                 :             : {
     612                 :     1411576 :         const struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
     613                 :             : 
     614 [ +  + ][ +  + ]:     1174515 :         return inet_csk(ssk)->icsk_pending && !subflow->stale_count ?
     615 [ +  + ][ +  + ]:     2412239 :                tcp_timeout_expires(ssk) - jiffies : 0;
     616                 :             : }
     617                 :             : 
     618                 :      340344 : static void mptcp_set_timeout(struct sock *sk)
     619                 :             : {
     620                 :      340344 :         struct mptcp_subflow_context *subflow;
     621                 :      340344 :         long tout = 0;
     622                 :             : 
     623      [ +  +  + ]:      767721 :         mptcp_for_each_subflow(mptcp_sk(sk), subflow)
     624            [ + ]:      748949 :                 tout = max(tout, mptcp_timeout_from_subflow(subflow));
     625                 :      340344 :         __mptcp_set_timeout(sk, tout);
     626                 :      340344 : }
     627                 :             : 
     628                 :        6521 : void __mptcp_subflow_send_ack(struct sock *ssk)
     629                 :             : {
     630            [ + ]:        6521 :         if (tcp_can_send_ack(ssk))
     631                 :        6198 :                 tcp_send_ack(ssk);
     632                 :        6521 : }
     633                 :             : 
     634                 :        5465 : static void mptcp_subflow_send_ack(struct sock *ssk)
     635                 :             : {
     636                 :        5465 :         bool slow;
     637                 :             : 
     638                 :        5465 :         slow = lock_sock_fast(ssk);
     639                 :        5465 :         __mptcp_subflow_send_ack(ssk);
     640                 :        5465 :         unlock_sock_fast(ssk, slow);
     641                 :        5465 : }
     642                 :             : 
     643                 :        3870 : static void mptcp_send_ack(struct mptcp_sock *msk)
     644                 :             : {
     645                 :        3870 :         struct mptcp_subflow_context *subflow;
     646                 :             : 
     647            [ + ]:        9335 :         mptcp_for_each_subflow(msk, subflow)
     648                 :        5465 :                 mptcp_subflow_send_ack(mptcp_subflow_tcp_sock(subflow));
     649                 :        3870 : }
     650                 :             : 
     651                 :      476544 : static void mptcp_subflow_cleanup_rbuf(struct sock *ssk, int copied)
     652                 :             : {
     653                 :      476544 :         bool slow;
     654                 :             : 
     655                 :      476544 :         slow = lock_sock_fast(ssk);
     656            [ + ]:      476544 :         if (tcp_can_send_ack(ssk))
     657                 :      474312 :                 tcp_cleanup_rbuf(ssk, copied);
     658                 :      476544 :         unlock_sock_fast(ssk, slow);
     659                 :      476544 : }
     660                 :             : 
     661                 :     1310749 : static bool mptcp_subflow_could_cleanup(const struct sock *ssk, bool rx_empty)
     662                 :             : {
     663                 :     1310749 :         const struct inet_connection_sock *icsk = inet_csk(ssk);
     664                 :     1310749 :         u8 ack_pending = READ_ONCE(icsk->icsk_ack.pending);
     665            [ + ]:     1310749 :         const struct tcp_sock *tp = tcp_sk(ssk);
     666                 :             : 
     667            [ + ]:     1310749 :         return (ack_pending & ICSK_ACK_SCHED) &&
     668                 :      607938 :                 ((READ_ONCE(tp->rcv_nxt) - READ_ONCE(tp->rcv_wup) >
     669         [ +  + ]:      607938 :                   READ_ONCE(icsk->icsk_ack.rcv_mss)) ||
     670            [ + ]:      138941 :                  (rx_empty && ack_pending &
     671                 :             :                               (ICSK_ACK_PUSHED2 | ICSK_ACK_PUSHED)));
     672                 :             : }
     673                 :             : 
     674                 :     1237769 : static void mptcp_cleanup_rbuf(struct mptcp_sock *msk, int copied)
     675                 :             : {
     676                 :     1237769 :         int old_space = READ_ONCE(msk->old_wspace);
     677                 :     1237769 :         struct mptcp_subflow_context *subflow;
     678                 :     1237769 :         struct sock *sk = (struct sock *)msk;
     679                 :     1237769 :         int space =  __mptcp_space(sk);
     680                 :     1237769 :         bool cleanup, rx_empty;
     681                 :             : 
     682      [ +  +  + ]:     1237769 :         cleanup = (space > 0) && (space >= (old_space << 1)) && copied;
     683 [ +  + ][ +  + ]:     1237769 :         rx_empty = !sk_rmem_alloc_get(sk) && copied;
     684                 :             : 
     685       [ + ][ + ]:     2789753 :         mptcp_for_each_subflow(msk, subflow) {
     686       [ + ][ + ]:     1551984 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
     687                 :             : 
     688 [ +  + ][ +  + ]:     1551984 :                 if (cleanup || mptcp_subflow_could_cleanup(ssk, rx_empty))
     689                 :      476544 :                         mptcp_subflow_cleanup_rbuf(ssk, copied);
     690                 :             :         }
     691                 :     1237769 : }
     692                 :             : 
     693                 :      168288 : static void mptcp_check_data_fin(struct sock *sk)
     694                 :             : {
     695            [ + ]:      168288 :         struct mptcp_sock *msk = mptcp_sk(sk);
     696                 :      168288 :         u64 rcv_data_fin_seq;
     697                 :             : 
     698                 :             :         /* Need to ack a DATA_FIN received from a peer while this side
     699                 :             :          * of the connection is in ESTABLISHED, FIN_WAIT1, or FIN_WAIT2.
     700                 :             :          * msk->rcv_data_fin was set when parsing the incoming options
     701                 :             :          * at the subflow level and the msk lock was not held, so this
     702                 :             :          * is the first opportunity to act on the DATA_FIN and change
     703                 :             :          * the msk state.
     704                 :             :          *
     705                 :             :          * If we are caught up to the sequence number of the incoming
     706                 :             :          * DATA_FIN, send the DATA_ACK now and do state transition.  If
     707                 :             :          * not caught up, do nothing and let the recv code send DATA_ACK
     708                 :             :          * when catching up.
     709                 :             :          */
     710                 :             : 
     711            [ + ]:      168288 :         if (mptcp_pending_data_fin(sk, &rcv_data_fin_seq)) {
     712                 :        2642 :                 WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
     713                 :        2642 :                 WRITE_ONCE(msk->rcv_data_fin, 0);
     714                 :             : 
     715                 :        2642 :                 WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
     716                 :             :                 /* on fallback, also emulated after a reset: check for a FIN */
     717            [ + ]:        2642 :                 if (!__mptcp_check_fallback(msk) ||
     718         [ -  - ]:         159 :                     (msk->first && sock_flag(msk->first, SOCK_DONE)))
     719                 :        2642 :                         sock_set_flag(sk, SOCK_DONE);
     720                 :        2642 :                 smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
     721                 :             : 
     722   [ +  +  +  - ]:        2642 :                 switch (sk->sk_state) {
     723                 :             :                 case TCP_ESTABLISHED:
     724                 :        1073 :                         mptcp_set_state(sk, TCP_CLOSE_WAIT);
     725                 :        1073 :                         break;
     726                 :         289 :                 case TCP_FIN_WAIT1:
     727                 :         289 :                         mptcp_set_state(sk, TCP_CLOSING);
     728                 :         289 :                         break;
     729                 :        1280 :                 case TCP_FIN_WAIT2:
     730                 :        1280 :                         mptcp_shutdown_subflows(msk);
     731                 :        1280 :                         mptcp_set_state(sk, TCP_CLOSE);
     732                 :        1280 :                         break;
     733                 :             :                 default:
     734                 :             :                         /* Other states not expected */
     735                 :           0 :                         WARN_ON_ONCE(1);
     736                 :           0 :                         break;
     737                 :             :                 }
     738                 :             : 
     739            [ + ]:        2642 :                 if (!__mptcp_check_fallback(msk))
     740                 :        2483 :                         mptcp_send_ack(msk);
     741                 :        2642 :                 mptcp_close_wake_up(sk);
     742                 :             :         }
     743                 :      168288 : }
     744                 :             : 
     745                 :           0 : static void mptcp_dss_corruption(struct mptcp_sock *msk, struct sock *ssk)
     746                 :             : {
     747       [ # ][ # ]:           0 :         if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSCORRUPTIONFALLBACK)) {
     748       [ # ][ # ]:           0 :                 MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSCORRUPTIONRESET);
     749                 :           0 :                 mptcp_subflow_reset(ssk);
     750                 :             :         }
     751                 :           0 : }
     752                 :             : 
     753                 :      229766 : static void __mptcp_add_backlog(struct sock *sk,
     754                 :             :                                 struct mptcp_subflow_context *subflow,
     755                 :             :                                 struct sk_buff *skb)
     756                 :             : {
     757            [ + ]:      229766 :         struct mptcp_sock *msk = mptcp_sk(sk);
     758                 :      229766 :         struct sk_buff *tail = NULL;
     759                 :      229766 :         struct sock *ssk = skb->sk;
     760                 :      229766 :         bool fragstolen;
     761                 :      229766 :         u64 limit;
     762                 :      229766 :         int delta;
     763                 :             : 
     764            [ + ]:      229766 :         if (unlikely(sk->sk_state == TCP_CLOSE)) {
     765                 :           0 :                 kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
     766                 :           0 :                 return;
     767                 :             :         }
     768                 :             : 
     769                 :             :         /* Similar additional allowance as plain TCP. */
     770                 :      229766 :         limit = READ_ONCE(sk->sk_rcvbuf);
     771                 :      229766 :         limit += (limit >> 1) + 64 * 1024;
     772                 :      229766 :         limit = min_t(u64, limit, UINT_MAX);
     773 [ +  - ][ +  - ]:      229766 :         if (msk->backlog_len > limit && !__mptcp_check_fallback(msk)) {
     774       [ # ][ # ]:           0 :                 __MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_BACKLOGDROP);
     775                 :           0 :                 kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_BACKLOG);
     776                 :           0 :                 return;
     777                 :             :         }
     778                 :             : 
     779                 :             :         /* Try to coalesce with the last skb in our backlog */
     780       [ + ][ + ]:      229766 :         if (!list_empty(&msk->backlog_list))
     781                 :       72474 :                 tail = list_last_entry(&msk->backlog_list, struct sk_buff, list);
     782                 :             : 
     783 [ -  + ][ -  + ]:       72474 :         if (tail && MPTCP_SKB_CB(skb)->map_seq == MPTCP_SKB_CB(tail)->end_seq &&
     784 [ -  + ][ +  + ]:      143746 :             ssk == tail->sk &&
     785                 :       71872 :             __mptcp_try_coalesce(sk, tail, skb, &fragstolen, &delta)) {
     786                 :       40154 :                 skb->truesize -= delta;
     787            [ + ]:       40154 :                 kfree_skb_partial(skb, fragstolen);
     788                 :       40154 :                 __mptcp_subflow_lend_fwdmem(subflow, delta);
     789                 :       40154 :                 goto account;
     790                 :             :         }
     791                 :             : 
     792                 :      189612 :         list_add_tail(&skb->list, &msk->backlog_list);
     793                 :      189612 :         mptcp_subflow_lend_fwdmem(subflow, skb);
     794                 :      189612 :         delta = skb->truesize;
     795                 :             : 
     796                 :      229766 : account:
     797                 :      229766 :         WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta);
     798                 :             : }
     799                 :             : 
     800                 :      950130 : static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
     801                 :             :                                            struct sock *ssk, bool own_msk)
     802                 :             : {
     803            [ - ]:      950130 :         struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
     804                 :      950130 :         struct sock *sk = (struct sock *)msk;
     805                 :      950130 :         bool more_data_avail;
     806                 :      950130 :         struct tcp_sock *tp;
     807                 :      950130 :         bool ret = false;
     808                 :             : 
     809         [ -  - ]:      950130 :         pr_debug("msk=%p ssk=%p\n", msk, ssk);
     810            [ + ]:      950130 :         tp = tcp_sk(ssk);
     811                 :     1035990 :         do {
     812                 :     1035990 :                 u32 map_remaining, offset;
     813                 :     1035990 :                 u32 seq = tp->copied_seq;
     814                 :     1035990 :                 struct sk_buff *skb;
     815                 :     1035990 :                 bool fin;
     816                 :             : 
     817                 :             :                 /* try to move as much data as available */
     818                 :     2071980 :                 map_remaining = subflow->map_data_len -
     819                 :     1035990 :                                 mptcp_subflow_get_map_offset(subflow);
     820                 :             : 
     821            [ - ]:     1035990 :                 skb = skb_peek(&ssk->sk_receive_queue);
     822            [ - ]:     1035990 :                 if (unlikely(!skb))
     823                 :             :                         break;
     824                 :             : 
     825            [ + ]:     1035990 :                 if (__mptcp_check_fallback(msk)) {
     826                 :             :                         /* Under fallback skbs have no MPTCP extension and TCP could
     827                 :             :                          * collapse them between the dummy map creation and the
     828                 :             :                          * current dequeue. Be sure to adjust the map size.
     829                 :             :                          */
     830                 :       11591 :                         map_remaining = skb->len;
     831                 :       11591 :                         subflow->map_data_len = skb->len;
     832                 :             :                 }
     833                 :             : 
     834                 :     1035990 :                 offset = seq - TCP_SKB_CB(skb)->seq;
     835                 :     1035990 :                 fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
     836            [ + ]:     1035990 :                 if (fin)
     837                 :         160 :                         seq++;
     838                 :             : 
     839            [ + ]:     1035990 :                 if (offset < skb->len) {
     840                 :     1035940 :                         size_t len = skb->len - offset;
     841                 :             : 
     842                 :     1035940 :                         mptcp_init_skb(ssk, skb, offset, len);
     843                 :             : 
     844            [ + ]:     1035940 :                         if (own_msk) {
     845                 :      806174 :                                 mptcp_subflow_lend_fwdmem(subflow, skb);
     846                 :      806174 :                                 ret |= __mptcp_move_skb(sk, skb);
     847                 :             :                         } else {
     848                 :      229766 :                                 __mptcp_add_backlog(sk, subflow, skb);
     849                 :             :                         }
     850                 :     1035940 :                         seq += len;
     851                 :             : 
     852            [ + ]:     1035940 :                         if (unlikely(map_remaining < len)) {
     853                 :           0 :                                 DEBUG_NET_WARN_ON_ONCE(1);
     854                 :           0 :                                 mptcp_dss_corruption(msk, ssk);
     855                 :             :                         }
     856                 :             :                 } else {
     857                 :          50 :                         sk_eat_skb(ssk, skb);
     858                 :             : 
     859            [ - ]:          50 :                         if (unlikely(!fin)) {
     860                 :           0 :                                 DEBUG_NET_WARN_ON_ONCE(1);
     861                 :           0 :                                 mptcp_dss_corruption(msk, ssk);
     862                 :             :                         }
     863                 :             :                 }
     864                 :             : 
     865                 :     1035990 :                 WRITE_ONCE(tp->copied_seq, seq);
     866                 :     1035990 :                 more_data_avail = mptcp_subflow_data_available(ssk);
     867                 :             : 
     868            [ + ]:     1035990 :         } while (more_data_avail);
     869                 :             : 
     870            [ + ]:      950130 :         if (ret)
     871                 :      571872 :                 msk->last_data_recv = tcp_jiffies32;
     872                 :      950130 :         return ret;
     873                 :             : }
     874                 :             : 
     875                 :      901911 : static bool __mptcp_ofo_queue(struct mptcp_sock *msk)
     876                 :             : {
     877                 :      901911 :         struct sock *sk = (struct sock *)msk;
     878                 :      901911 :         struct sk_buff *skb, *tail;
     879                 :      901911 :         bool moved = false;
     880                 :      901911 :         struct rb_node *p;
     881                 :      901911 :         u64 end_seq;
     882                 :             : 
     883            [ + ]:      901911 :         p = rb_first(&msk->out_of_order_queue);
     884         [ -  - ]:      901911 :         pr_debug("msk=%p empty=%d\n", msk, RB_EMPTY_ROOT(&msk->out_of_order_queue));
     885       [ + ][ + ]:      934115 :         while (p) {
     886                 :      313595 :                 skb = rb_to_skb(p);
     887       [ + ][ + ]:      313595 :                 if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq))
     888                 :             :                         break;
     889                 :             : 
     890                 :       32204 :                 p = rb_next(p);
     891                 :       32204 :                 rb_erase(&skb->rbnode, &msk->out_of_order_queue);
     892                 :             : 
     893       [ + ][ + ]:       32204 :                 if (unlikely(!after64(MPTCP_SKB_CB(skb)->end_seq,
     894                 :             :                                       msk->ack_seq))) {
     895                 :         146 :                         mptcp_drop(sk, skb);
     896       [ - ][ # ]:         146 :                         MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
     897                 :         146 :                         continue;
     898                 :             :                 }
     899                 :             : 
     900                 :       32058 :                 end_seq = MPTCP_SKB_CB(skb)->end_seq;
     901       [ - ][ - ]:       32058 :                 tail = skb_peek_tail(&sk->sk_receive_queue);
     902 [ -  + ][ -  + ]:       63621 :                 if (!tail || !mptcp_ooo_try_coalesce(msk, tail, skb)) {
     903                 :       19050 :                         int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
     904                 :             : 
     905                 :             :                         /* skip overlapping data, if any */
     906 [ -  - ][ -  - ]:       19050 :                         pr_debug("uncoalesced seq=%llx ack seq=%llx delta=%d\n",
     907                 :             :                                  MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq,
     908                 :             :                                  delta);
     909                 :       19050 :                         MPTCP_SKB_CB(skb)->offset += delta;
     910                 :       19050 :                         MPTCP_SKB_CB(skb)->map_seq += delta;
     911                 :       19050 :                         __skb_queue_tail(&sk->sk_receive_queue, skb);
     912                 :             :                 }
     913                 :       32058 :                 msk->bytes_received += end_seq - msk->ack_seq;
     914                 :       32058 :                 WRITE_ONCE(msk->ack_seq, end_seq);
     915                 :       32058 :                 moved = true;
     916                 :             :         }
     917                 :      901911 :         return moved;
     918                 :             : }
     919                 :             : 
     920                 :        7796 : static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
     921                 :             : {
     922                 :        7796 :         int ssk_state;
     923                 :        7796 :         int err;
     924                 :             : 
     925                 :             :         /* only propagate errors on fallen-back sockets or
     926                 :             :          * on MPC connect
     927                 :             :          */
     928      [ +  +  + ]:        7796 :         if (sk->sk_state != TCP_SYN_SENT && !__mptcp_check_fallback(mptcp_sk(sk)))
     929                 :             :                 return false;
     930                 :             : 
     931            [ + ]:         252 :         err = sock_error(ssk);
     932       [ + ][ + ]:         153 :         if (!err)
     933                 :          99 :                 return false;
     934                 :             : 
     935                 :             :         /* We need to propagate only transition to CLOSE state.
     936                 :             :          * Orphaned socket will see such state change via
     937                 :             :          * subflow_sched_work_if_closed() and that path will properly
     938                 :             :          * destroy the msk as needed.
     939                 :             :          */
     940                 :          27 :         ssk_state = inet_sk_state_load(ssk);
     941                 :             :         /* a FIN received before still leads to EOF, as with TCP */
     942 [ +  - ][ +  - ]:          27 :         if (sock_flag(ssk, SOCK_DONE) && mptcp_pending_data_fin(sk, NULL))
     943                 :           1 :                 sock_set_flag(sk, SOCK_DONE);
     944                 :          27 :         WRITE_ONCE(sk->sk_err, -err);
     945 [ -  - ][ -  - ]:          27 :         if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD)) {
     946                 :             :                 /* This barrier is coupled with smp_rmb() in mptcp_poll() */
     947                 :          27 :                 smp_wmb();
     948                 :          27 :                 WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
     949                 :          27 :                 mptcp_set_state(sk, ssk_state);
     950                 :             :         }
     951                 :             : 
     952                 :             :         /* This barrier is coupled with smp_rmb() in mptcp_poll() */
     953                 :          27 :         smp_wmb();
     954                 :          27 :         sk_error_report(sk);
     955                 :          27 :         return true;
     956                 :             : }
     957                 :             : 
     958                 :        1038 : void __mptcp_error_report(struct sock *sk)
     959                 :             : {
     960                 :        1038 :         struct mptcp_subflow_context *subflow;
     961            [ + ]:        1038 :         struct mptcp_sock *msk = mptcp_sk(sk);
     962                 :             : 
     963            [ + ]:        2440 :         mptcp_for_each_subflow(msk, subflow)
     964            [ + ]:        1429 :                 if (__mptcp_subflow_error_report(sk, mptcp_subflow_tcp_sock(subflow)))
     965                 :             :                         break;
     966                 :        1038 : }
     967                 :             : 
     968                 :             : /* In most cases we will be able to lock the mptcp socket.  If its already
     969                 :             :  * owned, we need to defer to the work queue to avoid ABBA deadlock.
     970                 :             :  */
     971                 :      744619 : static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)
     972                 :             : {
     973                 :      744619 :         struct sock *sk = (struct sock *)msk;
     974                 :      744619 :         bool moved;
     975                 :             : 
     976                 :      744619 :         moved = __mptcp_move_skbs_from_subflow(msk, ssk, true);
     977                 :      744619 :         __mptcp_ofo_queue(msk);
     978            [ + ]:      744619 :         if (unlikely(READ_ONCE(ssk->sk_err)))
     979                 :           0 :                 __mptcp_subflow_error_report(sk, ssk);
     980                 :             : 
     981                 :             :         /* If the moves have caught up with the DATA_FIN sequence number
     982                 :             :          * it's time to ack the DATA_FIN and change socket state, but
     983                 :             :          * this is not a good place to change state. Let the workqueue
     984                 :             :          * do it.
     985                 :             :          */
     986            [ + ]:      744619 :         if (mptcp_pending_data_fin(sk, NULL))
     987                 :         608 :                 mptcp_schedule_work(sk);
     988                 :      744619 :         return moved;
     989                 :             : }
     990                 :             : 
     991                 :      950130 : static void mptcp_rcv_rtt_update(struct mptcp_sock *msk,
     992                 :             :                                  struct mptcp_subflow_context *subflow)
     993                 :             : {
     994            [ + ]:      950130 :         const struct tcp_sock *tp = tcp_sk(subflow->tcp_sock);
     995                 :      950130 :         u32 rtt_us = tp->rcv_rtt_est.rtt_us;
     996                 :      950130 :         int id;
     997                 :             : 
     998                 :             :         /* Update once per subflow per rcvwnd to avoid touching the msk
     999                 :             :          * too often.
    1000                 :             :          */
    1001 [ +  + ][ +  + ]:      950130 :         if (!rtt_us || tp->rcv_rtt_est.seq == subflow->prev_rtt_seq)
    1002                 :             :                 return;
    1003                 :             : 
    1004                 :       24208 :         subflow->prev_rtt_seq = tp->rcv_rtt_est.seq;
    1005                 :             : 
    1006                 :             :         /* Pairs with READ_ONCE() in mptcp_rtt_us_est(). */
    1007                 :       24208 :         id = msk->rcv_rtt_est.next_sample;
    1008                 :       24208 :         WRITE_ONCE(msk->rcv_rtt_est.samples[id], rtt_us);
    1009       [ + ][ + ]:       24208 :         if (++msk->rcv_rtt_est.next_sample == MPTCP_RTT_SAMPLES)
    1010                 :        4353 :                 msk->rcv_rtt_est.next_sample = 0;
    1011                 :             : 
    1012                 :             :         /* EWMA among the incoming subflows */
    1013                 :       24208 :         msk->scaling_ratio = ((msk->scaling_ratio << 3) - msk->scaling_ratio +
    1014                 :       24208 :                              tp->scaling_ratio) >> 3;
    1015                 :             : }
    1016                 :             : 
    1017                 :      950130 : void mptcp_data_ready(struct sock *sk, struct sock *ssk)
    1018                 :             : {
    1019            [ + ]:      950130 :         struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
    1020            [ + ]:      950130 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1021                 :             : 
    1022                 :             :         /* The peer can send data while we are shutting down this
    1023                 :             :          * subflow at subflow destruction time, but we must avoid enqueuing
    1024                 :             :          * more data to the msk receive queue
    1025                 :             :          */
    1026       [ - ][ - ]:      950130 :         if (unlikely(subflow->closing))
    1027                 :             :                 return;
    1028                 :             : 
    1029                 :      950130 :         mptcp_data_lock(sk);
    1030                 :      950130 :         mptcp_rcv_rtt_update(msk, subflow);
    1031       [ + ][ + ]:      950130 :         if (!sock_owned_by_user(sk)) {
    1032                 :             :                 /* Wake-up the reader only for in-sequence data */
    1033 [ +  - ][ +  - ]:      744619 :                 if (move_skbs_to_msk(msk, ssk) && mptcp_epollin_ready(sk))
    1034                 :      571872 :                         sk->sk_data_ready(sk);
    1035                 :             :         } else {
    1036                 :      205511 :                 __mptcp_move_skbs_from_subflow(msk, ssk, false);
    1037                 :             :         }
    1038                 :      950130 :         mptcp_data_unlock(sk);
    1039                 :             : }
    1040                 :             : 
    1041                 :        1206 : static void mptcp_subflow_joined(struct mptcp_sock *msk, struct sock *ssk)
    1042                 :             : {
    1043       [ + ][ + ]:        1206 :         mptcp_subflow_ctx(ssk)->map_seq = READ_ONCE(msk->ack_seq);
    1044                 :        1206 :         msk->allow_infinite_fallback = false;
    1045                 :             :         /* an active join is added once fully established, see options.c */
    1046       [ + ][ + ]:        1206 :         if (!mptcp_subflow_ctx(ssk)->request_join)
    1047                 :         612 :                 set_bit(MPTCP_JOINED, &msk->flags);
    1048                 :        1206 :         mptcp_event(MPTCP_EVENT_SUB_ESTABLISHED, msk, ssk, GFP_ATOMIC);
    1049                 :        1206 : }
    1050                 :             : 
    1051                 :         612 : static bool __mptcp_finish_join(struct mptcp_sock *msk, struct sock *ssk)
    1052                 :             : {
    1053                 :         612 :         struct sock *sk = (struct sock *)msk;
    1054                 :             : 
    1055            [ + ]:         612 :         if (sk->sk_state != TCP_ESTABLISHED)
    1056                 :             :                 return false;
    1057                 :             : 
    1058                 :         612 :         spin_lock_bh(&msk->fallback_lock);
    1059    [ + ][ +  + ]:         612 :         if (!msk->allow_subflows) {
    1060                 :           0 :                 spin_unlock_bh(&msk->fallback_lock);
    1061                 :           0 :                 return false;
    1062                 :             :         }
    1063                 :         612 :         mptcp_subflow_joined(msk, ssk);
    1064                 :         612 :         spin_unlock_bh(&msk->fallback_lock);
    1065                 :             : 
    1066                 :         612 :         mptcp_subflow_ctx(ssk)->subflow_id = msk->subflow_id++;
    1067                 :         612 :         mptcp_sockopt_sync_locked(msk, ssk);
    1068                 :         612 :         mptcp_stop_tout_timer(sk);
    1069       [ - ][ - ]:         612 :         __mptcp_propagate_sndbuf(sk, ssk);
    1070                 :             :         return true;
    1071                 :             : }
    1072                 :             : 
    1073                 :          33 : static void __mptcp_flush_join_list(struct sock *sk, struct list_head *join_list)
    1074                 :             : {
    1075                 :          33 :         struct mptcp_subflow_context *tmp, *subflow;
    1076            [ + ]:          33 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1077                 :             : 
    1078       [ + ][ + ]:          61 :         list_for_each_entry_safe(subflow, tmp, join_list, node) {
    1079                 :          28 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    1080                 :          28 :                 bool slow = lock_sock_fast(ssk);
    1081                 :             : 
    1082                 :          28 :                 list_move_tail(&subflow->node, &msk->conn_list);
    1083       [ + ][ + ]:          28 :                 if (!__mptcp_finish_join(msk, ssk))
    1084                 :           0 :                         mptcp_subflow_reset(ssk);
    1085                 :          28 :                 unlock_sock_fast(ssk, slow);
    1086                 :             :         }
    1087                 :          33 : }
    1088                 :             : 
    1089                 :           0 : static bool mptcp_rtx_timer_pending(struct sock *sk)
    1090                 :             : {
    1091 [ +  + ][ +  + ]:      636759 :         return timer_pending(&sk->mptcp_retransmit_timer);
    1092                 :             : }
    1093                 :             : 
    1094                 :      397803 : static void mptcp_reset_rtx_timer(struct sock *sk)
    1095                 :             : {
    1096            [ + ]:      397803 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1097                 :      397803 :         unsigned long tout;
    1098                 :             : 
    1099                 :             :         /* Prevent rescheduling on close and in case of fallback. */
    1100   [ +  -  -  + ]:      585063 :         if (!test_bit(MPTCP_RTX_ENABLED, &msk->flags))
           [ +  -  -  + ]
    1101                 :             :                 return;
    1102                 :             : 
    1103                 :      357001 :         tout = msk->timer_ival;
    1104                 :      357001 :         sk_reset_timer(sk, &sk->mptcp_retransmit_timer, jiffies + tout);
    1105                 :             : }
    1106                 :             : 
    1107                 :       17448 : bool mptcp_schedule_work(struct sock *sk)
    1108                 :             : {
    1109            [ + ]:       17448 :         if (inet_sk_state_load(sk) == TCP_CLOSE)
    1110                 :             :                 return false;
    1111                 :             : 
    1112                 :             :         /* Get a reference on this socket, mptcp_worker() will release it.
    1113                 :             :          * As mptcp_worker() might complete before us, we can not avoid
    1114                 :             :          * a sock_hold()/sock_put() if schedule_work() returns false.
    1115                 :             :          */
    1116                 :       15696 :         sock_hold(sk);
    1117                 :             : 
    1118         [ +  + ]:       15696 :         if (schedule_work(&mptcp_sk(sk)->work))
    1119                 :             :                 return true;
    1120                 :             : 
    1121                 :        1830 :         sock_put(sk);
    1122                 :        1830 :         return false;
    1123                 :             : }
    1124                 :             : 
    1125                 :      647771 : static bool mptcp_skb_can_collapse_to(u64 write_seq,
    1126                 :             :                                       const struct sk_buff *skb,
    1127                 :             :                                       const struct mptcp_ext *mpext)
    1128                 :             : {
    1129            [ + ]:      647771 :         if (!tcp_skb_can_collapse_to(skb))
    1130                 :             :                 return false;
    1131                 :             : 
    1132                 :             :         /* can collapse only if MPTCP level sequence is in order and this
    1133                 :             :          * mapping has not been xmitted yet
    1134                 :             :          */
    1135         [ -  + ]:     1201576 :         return mpext && mpext->data_seq + mpext->data_len == write_seq &&
    1136            [ + ]:      578808 :                !mpext->frozen;
    1137                 :             : }
    1138                 :             : 
    1139                 :             : /* we can append data to the given data frag if:
    1140                 :             :  * - there is space available in the backing page_frag
    1141                 :             :  * - the data frag tail matches the current page_frag free offset
    1142                 :             :  * - the data frag end sequence number matches the current write seq
    1143                 :             :  */
    1144                 :      597148 : static bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
    1145                 :             :                                        const struct page_frag *pfrag,
    1146                 :             :                                        const struct mptcp_data_frag *df)
    1147                 :             : {
    1148            [ - ]:      323626 :         return df && !df->eor &&
    1149            [ - ]:      323626 :                 pfrag->page == df->page &&
    1150            [ + ]:      323626 :                 pfrag->size - pfrag->offset > 0 &&
    1151         [ +  - ]:      758495 :                 pfrag->offset == (df->offset + df->data_len) &&
    1152            [ + ]:      161347 :                 df->data_seq + df->data_len == msk->write_seq;
    1153                 :             : }
    1154                 :             : 
    1155                 :           0 : static void dfrag_uncharge(struct sock *sk, int len)
    1156                 :             : {
    1157                 :      692350 :         sk_mem_uncharge(sk, len);
    1158                 :      692350 :         sk_wmem_queued_add(sk, -len);
    1159                 :      256582 : }
    1160                 :             : 
    1161                 :      435786 : static void dfrag_clear(struct sock *sk, struct mptcp_data_frag *dfrag)
    1162                 :             : {
    1163                 :      435786 :         int len = dfrag->data_len + dfrag->overhead;
    1164                 :             : 
    1165                 :      435786 :         list_del(&dfrag->list);
    1166                 :      435786 :         dfrag_uncharge(sk, len);
    1167                 :      435786 :         put_page(dfrag->page);
    1168                 :      435786 : }
    1169                 :             : 
    1170                 :             : /* called under both the msk socket lock and the data lock */
    1171                 :      376880 : static void __mptcp_clean_una(struct sock *sk)
    1172                 :             : {
    1173            [ + ]:      376880 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1174                 :      376880 :         struct mptcp_data_frag *dtmp, *dfrag;
    1175                 :      376880 :         u64 snd_una;
    1176                 :             : 
    1177                 :      376880 :         snd_una = msk->snd_una;
    1178       [ + ][ + ]:      812514 :         list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list) {
    1179       [ + ][ + ]:      760966 :                 if (after64(dfrag->data_seq + dfrag->data_len, snd_una))
    1180                 :             :                         break;
    1181                 :             : 
    1182       [ + ][ + ]:      435634 :                 if (unlikely(dfrag == msk->first_pending)) {
    1183                 :             :                         /* in recovery mode can see ack after the current snd head */
    1184    [ # ][ #  # ]:           0 :                         if (WARN_ON_ONCE(!msk->recovery))
    1185                 :             :                                 break;
    1186                 :             : 
    1187                 :           0 :                         msk->first_pending = mptcp_send_next(sk);
    1188                 :             :                 }
    1189                 :             : 
    1190                 :      435634 :                 dfrag_clear(sk, dfrag);
    1191                 :             :         }
    1192                 :             : 
    1193                 :      376880 :         dfrag = mptcp_rtx_head(sk);
    1194 [ +  + ][ +  + ]:      376880 :         if (dfrag && after64(snd_una, dfrag->data_seq)) {
    1195                 :      256582 :                 u64 delta = snd_una - dfrag->data_seq;
    1196                 :             : 
    1197                 :             :                 /* prevent wrap around in recovery mode */
    1198       [ + ][ + ]:      256582 :                 if (unlikely(delta > dfrag->already_sent)) {
    1199    [ # ][ #  # ]:           0 :                         if (WARN_ON_ONCE(!msk->recovery))
    1200                 :           0 :                                 goto out;
    1201 [ #  # ][ #  # ]:           0 :                         if (WARN_ON_ONCE(delta > dfrag->data_len))
    1202                 :           0 :                                 goto out;
    1203                 :           0 :                         dfrag->already_sent += delta - dfrag->already_sent;
    1204                 :             :                 }
    1205                 :             : 
    1206                 :      256582 :                 dfrag->data_seq += delta;
    1207                 :      256582 :                 dfrag->offset += delta;
    1208                 :      256582 :                 dfrag->data_len -= delta;
    1209                 :      256582 :                 dfrag->already_sent -= delta;
    1210                 :             : 
    1211                 :      256582 :                 dfrag_uncharge(sk, delta);
    1212                 :             :         }
    1213                 :             : 
    1214                 :             :         /* all retransmitted data acked, recovery completed */
    1215         [ +  + ]:      376880 :         if (unlikely(msk->recovery) && after64(msk->snd_una, msk->recovery_snd_nxt))
              [ +  +  + ]
    1216                 :          44 :                 msk->recovery = false;
    1217                 :             : 
    1218                 :      376740 : out:
    1219 [ +  + ][ +  + ]:      376880 :         if (snd_una == msk->snd_nxt && snd_una == msk->write_seq) {
    1220    [ + ][ +  + ]:       48858 :                 if (mptcp_rtx_timer_pending(sk) && !mptcp_data_fin_enabled(msk))
    1221                 :       29732 :                         mptcp_stop_rtx_timer(sk);
    1222                 :             :         } else {
    1223                 :      328022 :                 mptcp_reset_rtx_timer(sk);
    1224                 :             :         }
    1225                 :             : 
    1226       [ + ][ + ]:      376880 :         if (mptcp_pending_data_fin_ack(sk))
    1227                 :        2657 :                 mptcp_schedule_work(sk);
    1228                 :      376880 : }
    1229                 :             : 
    1230                 :       65930 : static void __mptcp_clean_una_wakeup(struct sock *sk)
    1231                 :             : {
    1232         [ -  + ]:      108145 :         lockdep_assert_held_once(&sk->sk_lock.slock);
    1233                 :             : 
    1234                 :      108145 :         __mptcp_clean_una(sk);
    1235                 :      108145 :         mptcp_write_space(sk);
    1236                 :      105094 : }
    1237                 :             : 
    1238                 :           0 : static void mptcp_enter_memory_pressure(struct sock *sk)
    1239                 :             : {
    1240                 :           0 :         struct mptcp_subflow_context *subflow;
    1241            [ # ]:           0 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1242                 :           0 :         bool first = true;
    1243                 :             : 
    1244            [ # ]:           0 :         mptcp_for_each_subflow(msk, subflow) {
    1245            [ # ]:           0 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    1246                 :             : 
    1247         [ #  # ]:           0 :                 if (first && !ssk->sk_bypass_prot_mem) {
    1248                 :           0 :                         tcp_enter_memory_pressure(ssk);
    1249                 :           0 :                         first = false;
    1250                 :             :                 }
    1251                 :             : 
    1252                 :           0 :                 sk_stream_moderate_sndbuf(ssk);
    1253                 :             :         }
    1254                 :           0 :         __mptcp_sync_sndbuf(sk);
    1255                 :           0 : }
    1256                 :             : 
    1257                 :             : /* ensure we get enough memory for the frag hdr, beyond some minimal amount of
    1258                 :             :  * data
    1259                 :             :  */
    1260                 :      435801 : static bool mptcp_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
    1261                 :             : {
    1262            [ + ]:      435801 :         if (likely(skb_page_frag_refill(32U + sizeof(struct mptcp_data_frag),
    1263                 :             :                                         pfrag, sk->sk_allocation)))
    1264                 :             :                 return true;
    1265                 :             : 
    1266                 :           0 :         mptcp_enter_memory_pressure(sk);
    1267                 :           0 :         return false;
    1268                 :             : }
    1269                 :             : 
    1270                 :             : static struct mptcp_data_frag *
    1271                 :      435801 : mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag,
    1272                 :             :                       int orig_offset)
    1273                 :             : {
    1274                 :      435801 :         int offset = ALIGN(orig_offset, sizeof(long));
    1275                 :      435801 :         struct mptcp_data_frag *dfrag;
    1276                 :             : 
    1277                 :      435801 :         dfrag = (struct mptcp_data_frag *)(page_to_virt(pfrag->page) + offset);
    1278                 :      435801 :         dfrag->data_len = 0;
    1279                 :      435801 :         dfrag->data_seq = msk->write_seq;
    1280                 :      435801 :         dfrag->overhead = offset - orig_offset + sizeof(struct mptcp_data_frag);
    1281                 :      435801 :         dfrag->offset = offset + sizeof(struct mptcp_data_frag);
    1282                 :      435801 :         dfrag->already_sent = 0;
    1283                 :      435801 :         dfrag->page = pfrag->page;
    1284                 :      435801 :         dfrag->eor = 0;
    1285                 :             : 
    1286                 :      435801 :         return dfrag;
    1287                 :             : }
    1288                 :             : 
    1289                 :             : struct mptcp_sendmsg_info {
    1290                 :             :         int mss_now;
    1291                 :             :         int size_goal;
    1292                 :             :         u16 limit;
    1293                 :             :         u16 sent;
    1294                 :             :         unsigned int flags;
    1295                 :             :         bool data_lock_held;
    1296                 :             : };
    1297                 :             : 
    1298                 :     1066116 : static size_t mptcp_check_allowed_size(const struct mptcp_sock *msk,
    1299                 :             :                                        struct sock *ssk, u64 data_seq,
    1300                 :             :                                        size_t avail_size)
    1301                 :             : {
    1302                 :     1066116 :         u64 window_end = mptcp_wnd_end(msk);
    1303                 :     1066116 :         u64 mptcp_snd_wnd;
    1304                 :             : 
    1305       [ + ][ + ]:     1066116 :         if (__mptcp_check_fallback(msk))
    1306                 :             :                 return avail_size;
    1307                 :             : 
    1308                 :     1006266 :         mptcp_snd_wnd = window_end - data_seq;
    1309                 :     1006266 :         avail_size = min(mptcp_snd_wnd, avail_size);
    1310                 :             : 
    1311 [ +  + ][ +  + ]:     1006266 :         if (unlikely(tcp_sk(ssk)->snd_wnd < mptcp_snd_wnd)) {
    1312            [ + ]:        9797 :                 tcp_sk(ssk)->snd_wnd = min_t(u64, U32_MAX, mptcp_snd_wnd);
    1313       [ - ][ # ]:        9797 :                 MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_SNDWNDSHARED);
    1314                 :             :         }
    1315                 :             : 
    1316                 :             :         return avail_size;
    1317                 :             : }
    1318                 :             : 
    1319                 :      553222 : static bool __mptcp_add_ext(struct sk_buff *skb, gfp_t gfp)
    1320                 :             : {
    1321                 :      553222 :         struct skb_ext *mpext = __skb_ext_alloc(gfp);
    1322                 :             : 
    1323            [ - ]:      553222 :         if (!mpext)
    1324                 :             :                 return false;
    1325                 :      553222 :         __skb_ext_set(skb, SKB_EXT_MPTCP, mpext);
    1326                 :      553222 :         return true;
    1327                 :             : }
    1328                 :             : 
    1329                 :      553222 : static struct sk_buff *__mptcp_do_alloc_tx_skb(struct sock *sk, gfp_t gfp)
    1330                 :             : {
    1331                 :      553222 :         struct sk_buff *skb;
    1332                 :             : 
    1333                 :      553222 :         skb = alloc_skb_fclone(MAX_TCP_HEADER, gfp);
    1334            [ - ]:      553222 :         if (likely(skb)) {
    1335            [ - ]:      553222 :                 if (likely(__mptcp_add_ext(skb, gfp))) {
    1336                 :      553222 :                         skb_reserve(skb, MAX_TCP_HEADER);
    1337                 :      553222 :                         skb->ip_summed = CHECKSUM_PARTIAL;
    1338                 :      553222 :                         INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
    1339                 :      553222 :                         return skb;
    1340                 :             :                 }
    1341                 :           0 :                 __kfree_skb(skb);
    1342                 :             :         } else {
    1343                 :           0 :                 mptcp_enter_memory_pressure(sk);
    1344                 :             :         }
    1345                 :             :         return NULL;
    1346                 :             : }
    1347                 :             : 
    1348                 :      553222 : static struct sk_buff *__mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, gfp_t gfp)
    1349                 :             : {
    1350                 :      553222 :         struct sk_buff *skb;
    1351                 :             : 
    1352                 :      553222 :         skb = __mptcp_do_alloc_tx_skb(sk, gfp);
    1353            [ + ]:      553222 :         if (!skb)
    1354                 :             :                 return NULL;
    1355                 :             : 
    1356                 :             :         /* like TCP, force the charge if nothing is queued */
    1357            [ + ]:      553222 :         if (tcp_rtx_and_write_queues_empty(ssk)) {
    1358                 :       67828 :                 sk_forced_mem_schedule(ssk, skb->truesize);
    1359            [ + ]:      485394 :         } else if (unlikely(!sk_wmem_schedule(ssk, skb->truesize))) {
    1360                 :           0 :                 tcp_skb_tsorted_anchor_cleanup(skb);
    1361                 :           0 :                 kfree_skb(skb);
    1362                 :           0 :                 return NULL;
    1363                 :             :         }
    1364                 :             : 
    1365                 :      553222 :         tcp_skb_entail(ssk, skb);
    1366                 :      553222 :         return skb;
    1367                 :             : }
    1368                 :             : 
    1369                 :          18 : static struct sk_buff *mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, bool data_lock_held)
    1370                 :             : {
    1371                 :      332011 :         gfp_t gfp = data_lock_held ? GFP_ATOMIC : sk->sk_allocation;
    1372                 :             : 
    1373                 :      553222 :         return __mptcp_alloc_tx_skb(sk, ssk, gfp);
    1374                 :             : }
    1375                 :             : 
    1376                 :             : /* note: this always recompute the csum on the whole skb, even
    1377                 :             :  * if we just appended a single frag. More status info needed
    1378                 :             :  */
    1379                 :      190087 : static void mptcp_update_data_checksum(struct sk_buff *skb, int added)
    1380                 :             : {
    1381            [ - ]:      190087 :         struct mptcp_ext *mpext = mptcp_get_ext(skb);
    1382                 :      190087 :         __wsum csum = ~csum_unfold(mpext->csum);
    1383                 :      190087 :         int offset = skb->len - added;
    1384                 :             : 
    1385       [ # ][ # ]:      190087 :         mpext->csum = csum_fold(csum_block_add(csum, skb_checksum(skb, offset, added, 0), offset));
    1386                 :      190087 : }
    1387                 :             : 
    1388                 :           2 : static void mptcp_update_infinite_map(struct mptcp_sock *msk,
    1389                 :             :                                       struct sock *ssk,
    1390                 :             :                                       struct mptcp_ext *mpext)
    1391                 :             : {
    1392       [ - ][ - ]:           2 :         if (!mpext)
    1393                 :             :                 return;
    1394                 :             : 
    1395                 :           2 :         mpext->infinite_map = 1;
    1396                 :           2 :         mpext->data_len = 0;
    1397                 :             : 
    1398       [ + ][ + ]:           2 :         if (!mptcp_try_fallback(ssk, MPTCP_MIB_INFINITEMAPTX)) {
    1399       [ # ][ # ]:           0 :                 MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED);
    1400                 :           0 :                 mptcp_subflow_reset(ssk);
    1401                 :           0 :                 return;
    1402                 :             :         }
    1403                 :             : 
    1404                 :           2 :         mptcp_subflow_ctx(ssk)->send_infinite_map = 0;
    1405                 :             : }
    1406                 :             : 
    1407                 :             : #define MPTCP_MAX_GSO_SIZE (GSO_LEGACY_MAX_SIZE - (MAX_TCP_HEADER + 1))
    1408                 :             : 
    1409                 :     1066117 : static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
    1410                 :             :                               struct mptcp_data_frag *dfrag,
    1411                 :             :                               struct mptcp_sendmsg_info *info)
    1412                 :             : {
    1413            [ + ]:     1066117 :         struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
    1414                 :     1066117 :         u64 data_seq = dfrag->data_seq + info->sent;
    1415                 :     1066117 :         int offset = dfrag->offset + info->sent;
    1416            [ + ]:     1066117 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1417                 :     1066117 :         bool zero_window_probe = false;
    1418                 :     1066117 :         struct mptcp_ext *mpext = NULL;
    1419                 :     1066117 :         bool can_coalesce = false;
    1420                 :     1066117 :         bool reuse_skb = true;
    1421                 :     1066117 :         struct sk_buff *skb;
    1422                 :     1066117 :         size_t copy;
    1423                 :     1066117 :         int avail;
    1424                 :     1066117 :         int i;
    1425                 :             : 
    1426         [ -  - ]:     1066117 :         pr_debug("msk=%p ssk=%p sending dfrag at seq=%llu len=%u already sent=%u\n",
    1427                 :             :                  msk, ssk, dfrag->data_seq, dfrag->data_len, info->sent);
    1428                 :             : 
    1429         [ -  + ]:     1066117 :         if (WARN_ON_ONCE(info->sent > info->limit ||
    1430                 :             :                          info->limit > dfrag->data_len))
    1431                 :           0 :                 return 0;
    1432                 :             : 
    1433       [ + ][ + ]:     1066117 :         if (unlikely(!__tcp_can_send(ssk)))
    1434                 :             :                 return -EAGAIN;
    1435                 :             : 
    1436                 :             :         /* compute send limit */
    1437       [ + ][ + ]:     1066116 :         if (unlikely(ssk->sk_gso_max_size > MPTCP_MAX_GSO_SIZE))
    1438                 :           0 :                 ssk->sk_gso_max_size = MPTCP_MAX_GSO_SIZE;
    1439                 :     1066116 :         info->mss_now = tcp_send_mss(ssk, &info->size_goal, info->flags);
    1440                 :     1066116 :         copy = info->size_goal;
    1441                 :             : 
    1442                 :             :         /* Once the infinite mapping is sent, the MSS no longer includes its DSS
    1443                 :             :          * option: send it in a single segment.
    1444                 :             :          */
    1445 [ +  - ][ +  - ]:     1066116 :         if (unlikely(mptcp_subflow_ctx(ssk)->send_infinite_map &&
    1446                 :             :                      !mptcp_subflow_ctx(ssk)->old_data_pending))
    1447                 :           2 :                 copy = info->mss_now;
    1448                 :             : 
    1449                 :             :         /* after a fallback, the subflow got all data below snd_nxt already */
    1450 [ +  + ][ +  + ]:     1066116 :         if (unlikely(__mptcp_check_fallback(msk) &&
    1451                 :             :                      before64(data_seq, msk->snd_nxt)))
    1452                 :           0 :                 return min_t(u64, msk->snd_nxt - data_seq,
    1453                 :             :                              info->limit - info->sent);
    1454                 :             : 
    1455       [ + ][ + ]:     1066116 :         skb = tcp_write_queue_tail(ssk);
    1456 [ -  + ][ -  + ]:      940512 :         if (skb && copy > skb->len) {
    1457                 :             :                 /* Limit the write to the size available in the
    1458                 :             :                  * current skb, if any, so that we create at most a new skb.
    1459                 :             :                  * Explicitly tells TCP internals to avoid collapsing on later
    1460                 :             :                  * queue management operation, to avoid breaking the ext <->
    1461                 :             :                  * SSN association set here
    1462                 :             :                  */
    1463            [ - ]:      647771 :                 mpext = mptcp_get_ext(skb);
    1464            [ + ]:      647771 :                 if (!mptcp_skb_can_collapse_to(data_seq, skb, mpext)) {
    1465                 :      134649 :                         TCP_SKB_CB(skb)->eor = 1;
    1466            [ + ]:      134649 :                         tcp_mark_push(tcp_sk(ssk), skb);
    1467                 :      134649 :                         goto alloc_skb;
    1468                 :             :                 }
    1469                 :             : 
    1470            [ + ]:      513122 :                 i = skb_shinfo(skb)->nr_frags;
    1471            [ + ]:      513122 :                 can_coalesce = skb_can_coalesce(skb, i, dfrag->page, offset);
    1472 [ +  + ][ +  + ]:      513122 :                 if (!can_coalesce && i >= READ_ONCE(net_hotdata.sysctl_max_skb_frags)) {
    1473       [ + ][ + ]:         228 :                         tcp_mark_push(tcp_sk(ssk), skb);
    1474                 :         228 :                         goto alloc_skb;
    1475                 :             :                 }
    1476                 :             : 
    1477                 :      512894 :                 copy -= skb->len;
    1478                 :             :         } else {
    1479       [ + ][ - ]:          18 : alloc_skb:
    1480    [ + ][ +  + ]:      553222 :                 skb = mptcp_alloc_tx_skb(sk, ssk, info->data_lock_held);
    1481       [ + ][ + ]:      553222 :                 if (!skb)
    1482                 :             :                         return -ENOMEM;
    1483                 :             : 
    1484            [ - ]:      553222 :                 i = skb_shinfo(skb)->nr_frags;
    1485                 :      553222 :                 reuse_skb = false;
    1486            [ - ]:      553222 :                 mpext = mptcp_get_ext(skb);
    1487                 :             :         }
    1488                 :             : 
    1489                 :             :         /* Zero window and all data acked? Probe. */
    1490                 :     1066116 :         copy = mptcp_check_allowed_size(msk, ssk, data_seq, copy);
    1491       [ + ][ + ]:     1066116 :         if (copy == 0) {
    1492                 :      261715 :                 u64 snd_una = READ_ONCE(msk->snd_una);
    1493                 :             : 
    1494                 :             :                 /* No need for zero probe if there are any data pending
    1495                 :             :                  * either at the msk or ssk level; skb is the current write
    1496                 :             :                  * queue tail and can be empty at this point.
    1497                 :             :                  */
    1498      [ +  -  + ]:      270774 :                 if (snd_una != msk->snd_nxt || skb->len ||
              [ +  -  + ]
         [ #  # ][ #  # ]
    1499       [ # ][ # ]:           0 :                     skb != tcp_send_head(ssk)) {
    1500                 :      259293 :                         tcp_remove_empty_skb(ssk);
    1501                 :      259293 :                         return 0;
    1502                 :             :                 }
    1503                 :             : 
    1504                 :             :                 /* a new probe would move old_data_end: one at a time */
    1505       [ + ][ + ]:        2422 :                 if (!tcp_rtx_queue_empty(ssk)) {
    1506                 :           0 :                         tcp_remove_empty_skb(ssk);
    1507                 :           0 :                         return 0;
    1508                 :             :                 }
    1509                 :             : 
    1510                 :        2422 :                 zero_window_probe = true;
    1511                 :        2422 :                 data_seq = snd_una - 1;
    1512                 :        2422 :                 copy = 1;
    1513                 :             :         }
    1514                 :             : 
    1515                 :             :         /* data acked without MPTCP opts: the peer may have fallen back, only
    1516                 :             :          * possible before a join, see RFC 8684
    1517                 :             :          */
    1518   [ +  +  -  -  :      809680 :         if (unlikely(before64(data_seq, msk->snd_nxt) &&
           +  +  + ][ +  
          +  -  -  +  +  
                      + ]
    1519                 :             :                      !test_bit(MPTCP_JOINED, &msk->flags) &&
    1520                 :             :                      after(tcp_sk(ssk)->snd_una, subflow->opt_ack_seq))) {
    1521                 :           0 :                 tcp_remove_empty_skb(ssk);
    1522       [ # ][ # ]:           0 :                 MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED);
    1523                 :           0 :                 subflow->reset_transient = 0;
    1524                 :           0 :                 subflow->reset_reason = MPTCP_RST_EMIDDLEBOX;
    1525                 :           0 :                 mptcp_subflow_reset(ssk);
    1526                 :           0 :                 return -EAGAIN;
    1527                 :             :         }
    1528                 :             : 
    1529                 :      806823 :         copy = min_t(size_t, copy, info->limit - info->sent);
    1530                 :             : 
    1531                 :             :         /* like TCP, allow some progress up to tcp_wmem[0] */
    1532                 :      806823 :         avail = tcp_wmem_schedule(ssk, copy);
    1533       [ + ][ + ]:      806823 :         if (avail <= 0) {
    1534                 :           0 :                 tcp_remove_empty_skb(ssk);
    1535                 :           0 :                 return -ENOMEM;
    1536                 :             :         }
    1537                 :      806823 :         copy = avail;
    1538                 :             : 
    1539       [ + ][ + ]:      806823 :         if (can_coalesce) {
    1540                 :       49905 :                 skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
    1541                 :             :         } else {
    1542                 :      756918 :                 get_page(dfrag->page);
    1543            [ + ]:      756936 :                 skb_fill_page_desc(skb, i, dfrag->page, offset, copy);
    1544                 :             :         }
    1545                 :             : 
    1546                 :      806823 :         skb->len += copy;
    1547                 :      806823 :         skb->data_len += copy;
    1548                 :      806823 :         skb->truesize += copy;
    1549       [ - ][ - ]:      806823 :         sk_wmem_queued_add(ssk, copy);
    1550       [ - ][ - ]:      806823 :         sk_mem_charge(ssk, copy);
    1551 [ +  + ][ +  + ]:      806823 :         WRITE_ONCE(tcp_sk(ssk)->write_seq, tcp_sk(ssk)->write_seq + copy);
    1552                 :      806823 :         TCP_SKB_CB(skb)->end_seq += copy;
    1553       [ + ][ + ]:      806823 :         tcp_skb_pcount_set(skb, 0);
    1554                 :             : 
    1555                 :             :         /* old data mapped again: no fallback until acked with MPTCP opts */
    1556       [ + ][ + ]:      806823 :         if (unlikely(before64(data_seq, msk->snd_nxt))) {
    1557       [ + ][ + ]:        6986 :                 mptcp_subflow_ctx(ssk)->old_data_end = tcp_sk(ssk)->write_seq;
    1558                 :        6986 :                 mptcp_subflow_ctx(ssk)->old_data_pending = 1;
    1559                 :             :         }
    1560                 :             : 
    1561                 :             :         /* on skb reuse we just need to update the DSS len */
    1562       [ + ][ + ]:      806823 :         if (reuse_skb) {
    1563                 :      324489 :                 TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_PSH;
    1564                 :      324489 :                 mpext->data_len += copy;
    1565                 :      324489 :                 goto out;
    1566                 :             :         }
    1567                 :             : 
    1568                 :      482334 :         memset(mpext, 0, sizeof(*mpext));
    1569                 :      482334 :         mpext->data_seq = data_seq;
    1570       [ - ][ - ]:      482334 :         mpext->subflow_seq = mptcp_subflow_ctx(ssk)->rel_write_seq;
    1571                 :      482334 :         mpext->data_len = copy;
    1572                 :      482334 :         mpext->use_map = 1;
    1573                 :      482334 :         mpext->dsn64 = 1;
    1574                 :             : 
    1575 [ -  - ][ -  - ]:      482334 :         pr_debug("data_seq=%llu subflow_seq=%u data_len=%u dsn64=%d\n",
    1576                 :             :                  mpext->data_seq, mpext->subflow_seq, mpext->data_len,
    1577                 :             :                  mpext->dsn64);
    1578                 :             : 
    1579       [ + ][ + ]:      482334 :         if (zero_window_probe) {
    1580       [ - ][ # ]:        2422 :                 MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_WINPROBE);
    1581       [ + ][ + ]:        2422 :                 mptcp_subflow_ctx(ssk)->rel_write_seq += copy;
    1582                 :        2422 :                 mpext->frozen = 1;
    1583    [ + ][ +  + ]:        2422 :                 if (READ_ONCE(msk->csum_enabled))
    1584                 :        1706 :                         mptcp_update_data_checksum(skb, copy);
    1585                 :        2422 :                 tcp_push_pending_frames(ssk);
    1586                 :        2422 :                 return 0;
    1587                 :             :         }
    1588                 :      479912 : out:
    1589    [ + ][ +  + ]:      804401 :         if (READ_ONCE(msk->csum_enabled))
    1590                 :      188381 :                 mptcp_update_data_checksum(skb, copy);
    1591                 :             : 
    1592                 :             :         /* the infinite map implies a fallback: wait for old data acks */
    1593       [ + ][ + ]:      804401 :         if (mptcp_subflow_ctx(ssk)->send_infinite_map &&
    1594       [ - ][ - ]:           2 :             !mptcp_subflow_ctx(ssk)->old_data_pending)
    1595                 :           2 :                 mptcp_update_infinite_map(msk, ssk, mpext);
    1596                 :      804401 :         trace_mptcp_sendmsg_frag(mpext);
    1597       [ + ][ + ]:      804401 :         mptcp_subflow_ctx(ssk)->rel_write_seq += copy;
    1598                 :             : 
    1599                 :             :         /* if this is the last chunk of a dfrag with MSG_EOR set,
    1600                 :             :          * mark the skb to prevent coalescing with subsequent data.
    1601                 :             :          */
    1602 [ +  + ][ +  + ]:      804401 :         if (dfrag->eor && info->sent + copy >= dfrag->data_len)
    1603                 :           6 :                 TCP_SKB_CB(skb)->eor = 1;
    1604                 :             : 
    1605                 :             :         return copy;
    1606                 :             : }
    1607                 :             : 
    1608                 :             : #define MPTCP_SEND_BURST_SIZE           ((1 << 16) - \
    1609                 :             :                                          sizeof(struct tcphdr) - \
    1610                 :             :                                          MAX_TCP_OPTION_SPACE - \
    1611                 :             :                                          sizeof(struct ipv6hdr) - \
    1612                 :             :                                          sizeof(struct frag_hdr))
    1613                 :             : 
    1614                 :             : struct subflow_send_info {
    1615                 :             :         struct sock *ssk;
    1616                 :             :         u64 linger_time;
    1617                 :             : };
    1618                 :             : 
    1619                 :         243 : void mptcp_subflow_set_active(struct mptcp_subflow_context *subflow)
    1620                 :             : {
    1621       [ + ][ + ]:         243 :         if (!subflow->stale)
    1622                 :             :                 return;
    1623                 :             : 
    1624                 :           0 :         subflow->stale = 0;
    1625       [ # ][ # ]:           0 :         MPTCP_INC_STATS(sock_net(mptcp_subflow_tcp_sock(subflow)), MPTCP_MIB_SUBFLOWRECOVER);
    1626                 :             : }
    1627                 :             : 
    1628                 :     1425528 : bool mptcp_subflow_active(struct mptcp_subflow_context *subflow)
    1629                 :             : {
    1630            [ + ]:     1425528 :         if (unlikely(subflow->stale)) {
    1631            [ + ]:       98456 :                 u32 rcv_tstamp = READ_ONCE(tcp_sk(mptcp_subflow_tcp_sock(subflow))->rcv_tstamp);
    1632                 :             : 
    1633            [ + ]:       98456 :                 if (subflow->stale_rcv_tstamp == rcv_tstamp)
    1634                 :             :                         return false;
    1635                 :             : 
    1636                 :           0 :                 mptcp_subflow_set_active(subflow);
    1637                 :             :         }
    1638                 :     1327072 :         return __mptcp_subflow_active(subflow);
    1639                 :             : }
    1640                 :             : 
    1641                 :             : #define SSK_MODE_ACTIVE 0
    1642                 :             : #define SSK_MODE_BACKUP 1
    1643                 :             : #define SSK_MODE_MAX    2
    1644                 :             : 
    1645                 :             : /* implement the mptcp packet scheduler;
    1646                 :             :  * returns the subflow that will transmit the next DSS
    1647                 :             :  * additionally updates the rtx timeout
    1648                 :             :  */
    1649                 :      691765 : struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
    1650                 :             : {
    1651                 :      691765 :         struct subflow_send_info send_info[SSK_MODE_MAX];
    1652                 :      691765 :         struct mptcp_subflow_context *subflow;
    1653                 :      691765 :         struct sock *sk = (struct sock *)msk;
    1654                 :      691765 :         u32 pace, burst, wmem;
    1655                 :      691765 :         int i, nr_active = 0;
    1656                 :      691765 :         struct sock *ssk;
    1657                 :      691765 :         u64 linger_time;
    1658                 :      691765 :         long tout = 0;
    1659                 :             : 
    1660                 :             :         /* pick the subflow with the lower wmem/wspace ratio */
    1661       [ + ][ + ]:     2075295 :         for (i = 0; i < SSK_MODE_MAX; ++i) {
    1662                 :     1383530 :                 send_info[i].ssk = NULL;
    1663                 :     1383530 :                 send_info[i].linger_time = -1;
    1664                 :             :         }
    1665                 :             : 
    1666       [ + ][ + ]:     1775418 :         mptcp_for_each_subflow(msk, subflow) {
    1667 [ +  + ][ +  + ]:     1083653 :                 bool backup = subflow->backup || subflow->request_bkup;
    1668                 :             : 
    1669                 :     1083653 :                 trace_mptcp_subflow_get_send(subflow);
    1670                 :     1083653 :                 ssk =  mptcp_subflow_tcp_sock(subflow);
    1671       [ + ][ + ]:     1083653 :                 if (!mptcp_subflow_active(subflow))
    1672                 :       99454 :                         continue;
    1673                 :             : 
    1674       [ + ][ + ]:      984199 :                 tout = max(tout, mptcp_timeout_from_subflow(subflow));
    1675                 :      984199 :                 nr_active += !backup;
    1676                 :      984199 :                 pace = subflow->avg_pacing_rate;
    1677       [ + ][ + ]:      984199 :                 if (unlikely(!pace)) {
    1678                 :             :                         /* init pacing rate from socket */
    1679                 :        3549 :                         subflow->avg_pacing_rate = READ_ONCE(ssk->sk_pacing_rate);
    1680                 :        3549 :                         pace = subflow->avg_pacing_rate;
    1681       [ + ][ + ]:        3549 :                         if (!pace)
    1682                 :           0 :                                 continue;
    1683                 :             :                 }
    1684                 :             : 
    1685            [ + ]:      984199 :                 linger_time = div_u64((u64)READ_ONCE(ssk->sk_wmem_queued) << 32, pace);
    1686       [ + ][ + ]:      984199 :                 if (linger_time < send_info[backup].linger_time) {
    1687                 :      786206 :                         send_info[backup].ssk = ssk;
    1688                 :      786206 :                         send_info[backup].linger_time = linger_time;
    1689                 :             :                 }
    1690                 :             :         }
    1691                 :      691765 :         __mptcp_set_timeout(sk, tout);
    1692                 :             : 
    1693                 :             :         /* pick the best backup if no other subflow is active */
    1694       [ + ][ + ]:      691765 :         if (!nr_active)
    1695                 :       39333 :                 send_info[SSK_MODE_ACTIVE].ssk = send_info[SSK_MODE_BACKUP].ssk;
    1696                 :             : 
    1697                 :             :         /* According to the blest algorithm, to avoid HoL blocking for the
    1698                 :             :          * faster flow, we need to:
    1699                 :             :          * - estimate the faster flow linger time
    1700                 :             :          * - use the above to estimate the amount of byte transferred
    1701                 :             :          *   by the faster flow
    1702                 :             :          * - check that the amount of queued data is greater than the above,
    1703                 :             :          *   otherwise do not use the picked, slower, subflow
    1704                 :             :          * We select the subflow with the shorter estimated time to flush
    1705                 :             :          * the queued mem, which basically ensure the above. We just need
    1706                 :             :          * to check that subflow has a non empty cwin.
    1707                 :             :          */
    1708                 :      691765 :         ssk = send_info[SSK_MODE_ACTIVE].ssk;
    1709 [ +  + ][ +  + ]:     1383493 :         if (!ssk || !sk_stream_memory_free(ssk))
    1710                 :      167195 :                 return NULL;
    1711                 :             : 
    1712                 :      524570 :         burst = min(MPTCP_SEND_BURST_SIZE, mptcp_wnd_end(msk) - msk->snd_nxt);
    1713                 :      524570 :         wmem = READ_ONCE(ssk->sk_wmem_queued);
    1714       [ + ][ + ]:      524570 :         if (!burst)
    1715                 :             :                 return ssk;
    1716                 :             : 
    1717                 :      334113 :         subflow = mptcp_subflow_ctx(ssk);
    1718                 :      334113 :         subflow->avg_pacing_rate = div_u64((u64)subflow->avg_pacing_rate * wmem +
    1719                 :      334113 :                                            READ_ONCE(ssk->sk_pacing_rate) * burst,
    1720                 :             :                                            burst + wmem);
    1721                 :      334113 :         msk->snd_burst = burst;
    1722                 :      334113 :         return ssk;
    1723                 :             : }
    1724                 :             : 
    1725                 :      396899 : static void mptcp_push_release(struct sock *ssk, struct mptcp_sendmsg_info *info)
    1726                 :             : {
    1727            [ + ]:      396899 :         if (info->mss_now)
    1728            [ + ]:      396898 :                 tcp_push(ssk, 0, info->mss_now, tcp_sk(ssk)->nonagle,
    1729                 :             :                          info->size_goal);
    1730                 :      396899 :         release_sock(ssk);
    1731                 :      396899 : }
    1732                 :             : 
    1733                 :      803961 : static void mptcp_update_post_push(struct mptcp_sock *msk,
    1734                 :             :                                    struct mptcp_data_frag *dfrag,
    1735                 :             :                                    u32 sent)
    1736                 :             : {
    1737                 :      803961 :         u64 snd_nxt_new = dfrag->data_seq;
    1738                 :             : 
    1739                 :      803961 :         dfrag->already_sent += sent;
    1740                 :             : 
    1741                 :      803961 :         msk->snd_burst -= sent;
    1742                 :             : 
    1743                 :      803961 :         snd_nxt_new += dfrag->already_sent;
    1744                 :             : 
    1745                 :             :         /* snd_nxt_new can be smaller than snd_nxt in case mptcp
    1746                 :             :          * is recovering after a failover. In that event, this re-sends
    1747                 :             :          * old segments.
    1748                 :             :          *
    1749                 :             :          * Thus compute snd_nxt_new candidate based on
    1750                 :             :          * the dfrag->data_seq that was sent and the data
    1751                 :             :          * that has been handed to the subflow for transmission
    1752                 :             :          * and skip update in case it was old dfrag.
    1753                 :             :          */
    1754            [ + ]:      803961 :         if (likely(after64(snd_nxt_new, msk->snd_nxt))) {
    1755                 :      799847 :                 msk->bytes_sent += snd_nxt_new - msk->snd_nxt;
    1756                 :      799847 :                 WRITE_ONCE(msk->snd_nxt, snd_nxt_new);
    1757                 :             :         }
    1758                 :      803961 : }
    1759                 :             : 
    1760                 :        4774 : void mptcp_check_and_set_pending(struct sock *sk)
    1761                 :             : {
    1762            [ + ]:        4774 :         if (mptcp_send_head(sk)) {
    1763                 :         284 :                 mptcp_data_lock(sk);
    1764            [ + ]:         284 :                 mptcp_sk(sk)->cb_flags |= BIT(MPTCP_PUSH_PENDING);
    1765                 :         284 :                 mptcp_data_unlock(sk);
    1766                 :             :         }
    1767                 :        4774 : }
    1768                 :             : 
    1769                 :      577019 : static int __subflow_push_pending(struct sock *sk, struct sock *ssk,
    1770                 :             :                                   struct mptcp_sendmsg_info *info)
    1771                 :             : {
    1772            [ + ]:      577019 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1773                 :          36 :         struct mptcp_data_frag *dfrag;
    1774                 :          36 :         int len, copied = 0, err = 0;
    1775                 :             : 
    1776            [ + ]:      917363 :         while ((dfrag = mptcp_send_head(sk))) {
    1777                 :      701235 :                 info->sent = dfrag->already_sent;
    1778                 :      701235 :                 info->limit = dfrag->data_len;
    1779                 :      701235 :                 len = dfrag->data_len - dfrag->already_sent;
    1780            [ + ]:     1505196 :                 while (len > 0) {
    1781                 :     1065677 :                         int ret = 0;
    1782                 :             : 
    1783                 :     1065677 :                         ret = mptcp_sendmsg_frag(sk, ssk, dfrag, info);
    1784            [ + ]:     1065677 :                         if (ret <= 0) {
    1785            [ + ]:      261716 :                                 err = copied ? : ret;
    1786                 :      261716 :                                 goto out;
    1787                 :             :                         }
    1788                 :             : 
    1789                 :      803961 :                         info->sent += ret;
    1790                 :      803961 :                         copied += ret;
    1791                 :      803961 :                         len -= ret;
    1792                 :             : 
    1793                 :      803961 :                         mptcp_update_post_push(msk, dfrag, ret);
    1794                 :             :                 }
    1795                 :      439519 :                 msk->first_pending = mptcp_send_next(sk);
    1796                 :             : 
    1797    [ +  + ][ - ]:      796345 :                 if (msk->snd_burst <= 0 ||
    1798    [ + ][ -  + ]:      340362 :                     !sk_stream_memory_free(ssk) ||
    1799                 :      340344 :                     !mptcp_subflow_active(mptcp_subflow_ctx(ssk))) {
    1800                 :       99175 :                         err = copied;
    1801                 :       99175 :                         goto out;
    1802                 :             :                 }
    1803                 :      340344 :                 mptcp_set_timeout(sk);
    1804                 :             :         }
    1805                 :             :         err = copied;
    1806                 :             : 
    1807                 :      577019 : out:
    1808            [ + ]:      577019 :         if (err > 0)
    1809                 :      387968 :                 msk->last_data_sent = tcp_jiffies32;
    1810                 :      577019 :         return err;
    1811                 :             : }
    1812                 :             : 
    1813                 :      650581 : void __mptcp_push_pending(struct sock *sk, unsigned int flags)
    1814                 :             : {
    1815                 :      650581 :         struct sock *prev_ssk = NULL, *ssk = NULL;
    1816            [ + ]:      650581 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1817                 :      650581 :         struct mptcp_sendmsg_info info = {
    1818                 :             :                                 .flags = flags,
    1819                 :             :         };
    1820                 :      650581 :         bool copied = false;
    1821                 :      650581 :         int push_count = 1;
    1822                 :             : 
    1823 [ +  + ][ +  + ]:     1081898 :         while (mptcp_send_head(sk) && (push_count > 0)) {
    1824                 :      484175 :                 struct mptcp_subflow_context *subflow;
    1825                 :      484175 :                 int ret = 0;
    1826                 :             : 
    1827       [ + ][ + ]:      484175 :                 if (mptcp_sched_get_send(msk))
    1828                 :             :                         break;
    1829                 :             : 
    1830                 :      431317 :                 push_count = 0;
    1831                 :             : 
    1832       [ + ][ + ]:      970936 :                 mptcp_for_each_subflow(msk, subflow) {
    1833    [ + ][ +  + ]:      539619 :                         if (READ_ONCE(subflow->scheduled)) {
    1834                 :      431317 :                                 mptcp_subflow_set_scheduled(subflow, false);
    1835                 :             : 
    1836                 :      431317 :                                 prev_ssk = ssk;
    1837       [ + ][ + ]:      431317 :                                 ssk = mptcp_subflow_tcp_sock(subflow);
    1838       [ + ][ + ]:      431317 :                                 if (ssk != prev_ssk) {
    1839                 :             :                                         /* First check. If the ssk has changed since
    1840                 :             :                                          * the last round, release prev_ssk
    1841                 :             :                                          */
    1842       [ + ][ + ]:      396899 :                                         if (prev_ssk)
    1843                 :         767 :                                                 mptcp_push_release(prev_ssk, &info);
    1844                 :             : 
    1845                 :             :                                         /* Need to lock the new subflow only if different
    1846                 :             :                                          * from the previous one, otherwise we are still
    1847                 :             :                                          * helding the relevant lock
    1848                 :             :                                          */
    1849                 :      396899 :                                         lock_sock(ssk);
    1850                 :             :                                 }
    1851                 :             : 
    1852                 :      431317 :                                 push_count++;
    1853                 :             : 
    1854                 :      431317 :                                 ret = __subflow_push_pending(sk, ssk, &info);
    1855       [ + ][ + ]:      431317 :                                 if (ret <= 0) {
    1856    [ + ][ +  - ]:      127989 :                                         if (ret != -EAGAIN ||
    1857       [ - ][ # ]:           1 :                                             (1 << ssk->sk_state) &
    1858                 :             :                                              (TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 | TCPF_CLOSE))
    1859                 :       62400 :                                                 push_count--;
    1860                 :      127989 :                                         continue;
    1861                 :             :                                 }
    1862                 :             :                                 copied = true;
    1863                 :             :                         }
    1864                 :             :                 }
    1865                 :             :         }
    1866                 :             : 
    1867                 :             :         /* at this point we held the socket lock for the last subflow we used */
    1868       [ + ][ + ]:      650581 :         if (ssk)
    1869                 :      396132 :                 mptcp_push_release(ssk, &info);
    1870                 :             : 
    1871                 :             :         /* also retry later if unsent data is left: no ack may trigger it */
    1872      [ +  +  + ]:      650581 :         if ((copied || mptcp_send_head(sk)) && !mptcp_rtx_timer_pending(sk))
              [ +  +  + ]
    1873                 :       67430 :                 mptcp_reset_rtx_timer(sk);
    1874       [ + ][ + ]:      650581 :         if (copied)
    1875                 :      278895 :                 mptcp_check_send_data_fin(sk);
    1876                 :      650581 : }
    1877                 :             : 
    1878                 :     1296537 : static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, bool first)
    1879                 :             : {
    1880            [ + ]:     1296537 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1881                 :     1296537 :         struct mptcp_sendmsg_info info = {
    1882                 :             :                 .data_lock_held = true,
    1883                 :             :         };
    1884                 :     1296537 :         bool keep_pushing = true;
    1885                 :     1296537 :         struct sock *xmit_ssk;
    1886                 :     1296537 :         int copied = 0;
    1887                 :             : 
    1888                 :     1296537 :         info.flags = 0;
    1889 [ +  + ][ +  + ]:     1447176 :         while (mptcp_send_head(sk) && keep_pushing) {
    1890            [ + ]:      266993 :                 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
    1891                 :      266993 :                 int ret = 0;
    1892                 :             : 
    1893                 :             :                 /* check for a different subflow usage only after
    1894                 :             :                  * spooling the first chunk of data
    1895                 :             :                  */
    1896            [ + ]:      266993 :                 if (first) {
    1897                 :        5423 :                         mptcp_subflow_set_scheduled(subflow, false);
    1898                 :        5423 :                         ret = __subflow_push_pending(sk, ssk, &info);
    1899                 :        5423 :                         first = false;
    1900            [ + ]:        5423 :                         if (ret <= 0)
    1901                 :             :                                 break;
    1902                 :        3887 :                         copied += ret;
    1903                 :        3887 :                         continue;
    1904                 :             :                 }
    1905                 :             : 
    1906            [ + ]:      261570 :                 if (mptcp_sched_get_send(msk))
    1907                 :      114818 :                         goto out;
    1908                 :             : 
    1909    [ + ][ +  + ]:      146752 :                 if (READ_ONCE(subflow->scheduled)) {
    1910                 :      140279 :                         mptcp_subflow_set_scheduled(subflow, false);
    1911                 :      140279 :                         ret = __subflow_push_pending(sk, ssk, &info);
    1912       [ + ][ + ]:      140279 :                         if (ret <= 0)
    1913                 :             :                                 keep_pushing = false;
    1914                 :             :                         else
    1915                 :       80753 :                                 copied += ret;
    1916                 :             :                 }
    1917                 :             : 
    1918       [ + ][ + ]:      356029 :                 mptcp_for_each_subflow(msk, subflow) {
    1919    [ + ][ +  + ]:      209277 :                         if (READ_ONCE(subflow->scheduled)) {
    1920       [ - ][ - ]:        6473 :                                 xmit_ssk = mptcp_subflow_tcp_sock(subflow);
    1921       [ - ][ - ]:        6473 :                                 if (xmit_ssk != ssk) {
    1922                 :        6473 :                                         mptcp_subflow_delegate(subflow,
    1923                 :             :                                                                MPTCP_DELEGATE_SEND);
    1924                 :        6473 :                                         keep_pushing = false;
    1925                 :             :                                 }
    1926                 :             :                         }
    1927                 :             :                 }
    1928                 :             :         }
    1929                 :             : 
    1930                 :     1181643 : out:
    1931                 :             :         /* __mptcp_alloc_tx_skb could have released some wmem and we are
    1932                 :             :          * not going to flush it via release_sock()
    1933                 :             :          */
    1934       [ + ][ + ]:     1296537 :         if (copied) {
    1935       [ + ][ + ]:       79063 :                 tcp_push(ssk, 0, info.mss_now, tcp_sk(ssk)->nonagle,
    1936                 :             :                          info.size_goal);
    1937                 :             : 
    1938    [ + ][ +  + ]:       79063 :                 if (msk->snd_data_fin_enable &&
    1939       [ + ][ + ]:       11010 :                     msk->snd_nxt + 1 == msk->write_seq)
    1940                 :         435 :                         mptcp_schedule_work(sk);
    1941                 :             :         }
    1942                 :             : 
    1943                 :             :         /* see __mptcp_push_pending() */
    1944      [ +  +  + ]:     1296537 :         if ((copied || mptcp_send_head(sk)) && !mptcp_rtx_timer_pending(sk))
              [ +  +  + ]
    1945                 :         381 :                 mptcp_reset_rtx_timer(sk);
    1946                 :     1296537 : }
    1947                 :             : 
    1948                 :             : static int mptcp_disconnect(struct sock *sk, int flags);
    1949                 :             : 
    1950                 :         112 : static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
    1951                 :             :                                   size_t len, int *copied_syn)
    1952                 :             : {
    1953                 :         112 :         unsigned int saved_flags = msg->msg_flags;
    1954            [ + ]:         112 :         struct mptcp_sock *msk = mptcp_sk(sk);
    1955                 :         112 :         struct sock *ssk;
    1956                 :         112 :         int ret;
    1957                 :             : 
    1958                 :             :         /* on flags based fastopen the mptcp is supposed to create the
    1959                 :             :          * first subflow right now. Otherwise we are in the defer_connect
    1960                 :             :          * path, and the first subflow must be already present.
    1961                 :             :          */
    1962            [ + ]:         112 :         if (msg->msg_flags & MSG_FASTOPEN) {
    1963                 :          76 :                 ssk = __mptcp_nmpc_sk(msk);
    1964            [ + ]:          76 :                 if (IS_ERR(ssk))
    1965                 :           6 :                         return PTR_ERR(ssk);
    1966                 :             :         }
    1967       [ - ][ - ]:         106 :         if (!msk->first)
    1968                 :             :                 return -EINVAL;
    1969                 :             : 
    1970                 :         106 :         ssk = msk->first;
    1971                 :             : 
    1972                 :         106 :         lock_sock(ssk);
    1973                 :             : 
    1974                 :             :         /* subflow aborted or disconnected: its error report may be deferred.
    1975                 :             :          * With MSG_FASTOPEN, the socket is disconnected below, as with TCP.
    1976                 :             :          */
    1977   [ +  +  -  -  :         142 :         if (unlikely(!(msg->msg_flags & MSG_FASTOPEN) &&
             -  +  -  -  
           + ][ +  +  -  
          -  -  +  -  -  
                      + ]
    1978                 :             :                      inet_test_bit(DEFER_CONNECT, sk) &&
    1979                 :             :                      !inet_test_bit(DEFER_CONNECT, ssk))) {
    1980                 :           0 :                 inet_clear_bit(DEFER_CONNECT, sk);
    1981                 :           0 :                 __mptcp_subflow_error_report(sk, ssk);
    1982                 :           0 :                 release_sock(ssk);
    1983                 :           0 :                 return 0;
    1984                 :             :         }
    1985                 :             : 
    1986                 :         106 :         msg->msg_flags |= MSG_DONTWAIT;
    1987                 :         106 :         msk->fastopening = 1;
    1988                 :         106 :         ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, NULL);
    1989                 :         106 :         msk->fastopening = 0;
    1990                 :         106 :         msg->msg_flags = saved_flags;
    1991                 :         106 :         release_sock(ssk);
    1992                 :             : 
    1993                 :         106 :         inet_clear_bit(DEFER_CONNECT, sk);
    1994                 :             : 
    1995                 :             :         /* do the blocking bits of inet_stream_connect outside the ssk socket lock */
    1996 [ -  + ][ -  + ]:         106 :         if (ret == -EINPROGRESS && !(msg->msg_flags & MSG_DONTWAIT)) {
    1997                 :          46 :                 ret = __inet_stream_connect(sk->sk_socket, msg->msg_name,
    1998                 :             :                                             msg->msg_namelen, msg->msg_flags, true);
    1999                 :             : 
    2000                 :             :                 /* Keep the same behaviour of plain TCP: zero the copied bytes in
    2001                 :             :                  * case of any error, except timeout or signal
    2002                 :             :                  */
    2003 [ +  - ][ +  - ]:          46 :                 if (ret && ret != -EINPROGRESS && ret != -ERESTARTSYS && ret != -EINTR)
    2004                 :           0 :                         *copied_syn = 0;
    2005 [ -  - ][ -  - ]:          60 :         } else if (ret && ret != -EINPROGRESS && sk->sk_state != TCP_LISTEN &&
    2006       [ # ][ # ]:           0 :                    sk->sk_socket->state != SS_CONNECTED) {
    2007                 :             :                 /* The disconnect() op called by tcp_sendmsg_fastopen()/
    2008                 :             :                  * __inet_stream_connect() can fail, due to looking check,
    2009                 :             :                  * see mptcp_disconnect().
    2010                 :             :                  * Attempt it again outside the problematic scope.
    2011                 :             :                  * A listener or a connected socket is not disconnected there,
    2012                 :             :                  * as with TCP.
    2013                 :             :                  */
    2014       [ # ][ # ]:           0 :                 if (!mptcp_disconnect(sk, 0)) {
    2015                 :           0 :                         sk->sk_disconnects++;
    2016                 :           0 :                         sk->sk_socket->state = SS_UNCONNECTED;
    2017                 :             :                 }
    2018                 :             :         }
    2019                 :             : 
    2020                 :             :         return ret;
    2021                 :             : }
    2022                 :             : 
    2023                 :      597148 : static int do_copy_data_nocache(struct sock *sk, int copy,
    2024                 :             :                                 struct iov_iter *from, char *to)
    2025                 :             : {
    2026            [ + ]:      597148 :         if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) {
    2027            [ # ]:           0 :                 if (!copy_from_iter_full_nocache(to, copy, from))
    2028                 :           0 :                         return -EFAULT;
    2029            [ + ]:      597148 :         } else if (!copy_from_iter_full(to, copy, from)) {
    2030                 :           6 :                 return -EFAULT;
    2031                 :             :         }
    2032                 :             :         return 0;
    2033                 :             : }
    2034                 :             : 
    2035                 :             : /* open-code sk_stream_memory_free() plus sent limit computation to
    2036                 :             :  * avoid indirect calls in fast-path.
    2037                 :             :  * Called under the msk socket lock, so we can avoid a bunch of ONCE
    2038                 :             :  * annotations.
    2039                 :             :  */
    2040                 :      602100 : static u32 mptcp_send_limit(const struct sock *sk)
    2041                 :             : {
    2042            [ + ]:      602100 :         const struct mptcp_sock *msk = mptcp_sk(sk);
    2043                 :      602100 :         u32 limit, not_sent;
    2044                 :             : 
    2045            [ + ]:      602100 :         if (sk->sk_wmem_queued >= READ_ONCE(sk->sk_sndbuf))
    2046                 :             :                 return 0;
    2047                 :             : 
    2048                 :      597154 :         limit = mptcp_notsent_lowat(sk);
    2049            [ + ]:      597154 :         if (limit == UINT_MAX)
    2050                 :             :                 return UINT_MAX;
    2051                 :             : 
    2052                 :          12 :         not_sent = msk->write_seq - msk->snd_nxt;
    2053            [ + ]:          12 :         if (not_sent >= limit)
    2054                 :             :                 return 0;
    2055                 :             : 
    2056                 :           6 :         return limit - not_sent;
    2057                 :             : }
    2058                 :             : 
    2059                 :     1339615 : static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
    2060                 :             : {
    2061                 :     1339615 :         struct mptcp_subflow_context *subflow;
    2062                 :             : 
    2063            [ + ]:     1339615 :         if (!rfs_is_needed())
    2064                 :             :                 return;
    2065                 :             : 
    2066            [ # ]:           0 :         mptcp_for_each_subflow(msk, subflow) {
    2067                 :           0 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    2068                 :             : 
    2069                 :           0 :                 sock_rps_record_flow(ssk);
    2070                 :             :         }
    2071                 :             : }
    2072                 :             : 
    2073                 :      432172 : static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
    2074                 :             : {
    2075            [ + ]:      432172 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2076                 :      432172 :         struct page_frag *pfrag;
    2077                 :      432172 :         size_t copied = 0;
    2078                 :      432172 :         int ret = 0;
    2079                 :      432172 :         long timeo;
    2080                 :             : 
    2081                 :             :         /* silently ignore everything else */
    2082                 :      432172 :         msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL |
    2083                 :             :                           MSG_FASTOPEN | MSG_EOR;
    2084                 :             : 
    2085                 :      432172 :         lock_sock(sk);
    2086                 :             : 
    2087                 :      432172 :         mptcp_rps_record_subflows(msk);
    2088                 :             : 
    2089   [ +  -  -  +  :      661680 :         if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
           + ][ +  -  -  
                   +  + ]
    2090                 :             :                      msg->msg_flags & MSG_FASTOPEN)) {
    2091                 :         112 :                 int copied_syn = 0;
    2092                 :             : 
    2093                 :         112 :                 ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn);
    2094                 :         112 :                 copied += copied_syn;
    2095 [ +  + ][ +  + ]:         112 :                 if (ret == -EINPROGRESS && copied_syn > 0)
    2096                 :          42 :                         goto out;
    2097       [ + ][ + ]:          70 :                 else if (ret)
    2098                 :          24 :                         goto do_error;
    2099                 :             :         }
    2100                 :             : 
    2101       [ + ][ + ]:      432106 :         timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
    2102                 :             : 
    2103    [ + ][ +  + ]:      432106 :         if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
    2104                 :          45 :                 ret = sk_stream_wait_connect(sk, &timeo);
    2105       [ - ][ - ]:          45 :                 if (ret)
    2106                 :          45 :                         goto do_error;
    2107                 :             :         }
    2108                 :             : 
    2109                 :      432061 :         ret = -EPIPE;
    2110 [ -  + ][ -  + ]:      432061 :         if (unlikely(READ_ONCE(sk->sk_err) || (sk->sk_shutdown & SEND_SHUTDOWN)))
    2111                 :           0 :                 goto do_error;
    2112                 :             : 
    2113            [ - ]:      432061 :         pfrag = sk_page_frag(sk);
    2114                 :             : 
    2115       [ + ][ + ]:     1034149 :         while (msg_data_left(msg)) {
    2116                 :      602100 :                 int total_ts, frag_truesize = 0;
    2117                 :      602100 :                 struct mptcp_data_frag *dfrag;
    2118                 :      602100 :                 bool dfrag_collapsed;
    2119                 :      602100 :                 size_t psize, offset;
    2120                 :      602100 :                 u32 copy_limit;
    2121                 :             : 
    2122                 :             :                 /* ensure fitting the notsent_lowat() constraint */
    2123                 :      602100 :                 copy_limit = mptcp_send_limit(sk);
    2124       [ + ][ + ]:      602100 :                 if (!copy_limit)
    2125                 :        4952 :                         goto wait_for_memory;
    2126                 :             : 
    2127                 :             :                 /* reuse tail pfrag, if possible, or carve a new one from the
    2128                 :             :                  * page allocator
    2129                 :             :                  */
    2130                 :      597148 :                 dfrag = mptcp_pending_tail(sk);
    2131                 :      597148 :                 dfrag_collapsed = mptcp_frag_can_collapse_to(msk, pfrag, dfrag);
    2132       [ + ][ + ]:      597148 :                 if (!dfrag_collapsed) {
    2133       [ + ][ + ]:      435801 :                         if (!mptcp_page_frag_refill(sk, pfrag))
    2134                 :           0 :                                 goto wait_for_memory;
    2135                 :             : 
    2136                 :      435801 :                         dfrag = mptcp_carve_data_frag(msk, pfrag, pfrag->offset);
    2137                 :      435801 :                         frag_truesize = dfrag->overhead;
    2138                 :             :                 }
    2139                 :             : 
    2140                 :             :                 /* we do not bound vs wspace, to allow a single packet.
    2141                 :             :                  * memory accounting will prevent execessive memory usage
    2142                 :             :                  * anyway
    2143                 :             :                  */
    2144                 :      597148 :                 offset = dfrag->offset + dfrag->data_len;
    2145                 :      597148 :                 psize = pfrag->size - offset;
    2146                 :      597148 :                 psize = min_t(size_t, psize, msg_data_left(msg));
    2147                 :      597148 :                 psize = min_t(size_t, psize, copy_limit);
    2148                 :      597148 :                 total_ts = psize + frag_truesize;
    2149                 :             : 
    2150       [ + ][ + ]:      597148 :                 if (!sk_wmem_schedule(sk, total_ts))
    2151                 :           0 :                         goto wait_for_memory;
    2152                 :             : 
    2153                 :      597166 :                 ret = do_copy_data_nocache(sk, psize, &msg->msg_iter,
    2154                 :      597148 :                                            page_address(dfrag->page) + offset);
    2155       [ + ][ + ]:      597148 :                 if (ret)
    2156                 :           6 :                         goto do_error;
    2157                 :             : 
    2158                 :             :                 /* data successfully copied into the write queue */
    2159       [ + ][ + ]:      597142 :                 sk_forward_alloc_add(sk, -total_ts);
    2160                 :      597142 :                 copied += psize;
    2161                 :      597142 :                 dfrag->data_len += psize;
    2162                 :      597142 :                 frag_truesize += psize;
    2163                 :      597142 :                 pfrag->offset += frag_truesize;
    2164                 :      597142 :                 WRITE_ONCE(msk->write_seq, msk->write_seq + psize);
    2165                 :             : 
    2166                 :             :                 /* charge data on mptcp pending queue to the msk socket
    2167                 :             :                  * Note: we charge such data both to sk and ssk
    2168                 :             :                  */
    2169       [ + ][ + ]:      597142 :                 sk_wmem_queued_add(sk, frag_truesize);
    2170       [ + ][ + ]:      597142 :                 if (!dfrag_collapsed) {
    2171                 :      435795 :                         get_page(dfrag->page);
    2172            [ + ]:      435795 :                         list_add_tail(&dfrag->list, &msk->rtx_queue);
    2173       [ + ][ + ]:      435795 :                         if (!msk->first_pending)
    2174                 :      273522 :                                 msk->first_pending = dfrag;
    2175                 :             :                 }
    2176 [ -  - ][ -  - ]:      597142 :                 pr_debug("msk=%p dfrag at seq=%llu len=%u sent=%u new=%d\n", msk,
    2177                 :             :                          dfrag->data_seq, dfrag->data_len, dfrag->already_sent,
    2178                 :             :                          !dfrag_collapsed);
    2179                 :             : 
    2180                 :      597142 :                 continue;
    2181                 :             : 
    2182                 :        4952 : wait_for_memory:
    2183                 :        4952 :                 sk_set_nospace(sk);
    2184                 :        4952 :                 __mptcp_push_pending(sk, msg->msg_flags);
    2185                 :        4952 :                 ret = sk_stream_wait_memory(sk, &timeo);
    2186       [ + ][ + ]:        4952 :                 if (ret)
    2187                 :           6 :                         goto do_error;
    2188                 :             :         }
    2189                 :             : 
    2190       [ + ][ + ]:      432049 :         if (copied) {
    2191                 :             :                 /* mark the last dfrag with EOR if MSG_EOR was set */
    2192       [ + ][ + ]:      431920 :                 if (msg->msg_flags & MSG_EOR) {
    2193                 :           6 :                         struct mptcp_data_frag *dfrag = mptcp_pending_tail(sk);
    2194                 :             : 
    2195       [ - ][ - ]:           6 :                         if (dfrag)
    2196                 :           6 :                                 dfrag->eor = 1;
    2197                 :             :                 }
    2198                 :      431920 :                 __mptcp_push_pending(sk, msg->msg_flags);
    2199                 :             :         }
    2200                 :             : 
    2201                 :         129 : out:
    2202                 :      432172 :         release_sock(sk);
    2203                 :      432172 :         return copied;
    2204                 :             : 
    2205                 :          81 : do_error:
    2206       [ + ][ + ]:          81 :         if (copied) {
    2207                 :          12 :                 __mptcp_push_pending(sk, msg->msg_flags);
    2208                 :          12 :                 goto out;
    2209                 :             :         }
    2210                 :             : 
    2211                 :          69 :         copied = sk_stream_error(sk, msg->msg_flags, ret);
    2212                 :          69 :         goto out;
    2213                 :             : }
    2214                 :             : 
    2215                 :             : static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied);
    2216                 :             : 
    2217                 :      621717 : static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
    2218                 :             : {
    2219                 :             :         /* avoid the indirect call, we know the destructor is sock_rfree */
    2220                 :      621717 :         skb->destructor = NULL;
    2221                 :      621717 :         skb->sk = NULL;
    2222                 :      621717 :         atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
    2223                 :      621717 :         sk_mem_uncharge(sk, skb->truesize);
    2224                 :      621717 :         __skb_unlink(skb, &sk->sk_receive_queue);
    2225                 :      621717 :         skb_attempt_defer_free(skb);
    2226                 :      621717 : }
    2227                 :             : 
    2228                 :     1061815 : static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
    2229                 :             :                                 size_t len, int flags, int copied_total,
    2230                 :             :                                 struct scm_timestamping_internal *tss,
    2231                 :             :                                 int *cmsg_flags, struct sk_buff **last)
    2232                 :             : {
    2233            [ + ]:     1061815 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2234                 :     1061815 :         struct sk_buff *skb, *tmp;
    2235                 :     1061815 :         int total_data_len = 0;
    2236                 :     1061815 :         int copied = 0;
    2237                 :             : 
    2238            [ + ]:     1597727 :         skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) {
    2239                 :      987467 :                 u32 delta, offset = MPTCP_SKB_CB(skb)->offset;
    2240                 :      987467 :                 u32 data_len = skb->len - offset;
    2241                 :      987467 :                 u32 count;
    2242                 :      987467 :                 int err;
    2243                 :             : 
    2244            [ + ]:      987467 :                 if (flags & MSG_PEEK) {
    2245                 :             :                         /* skip already peeked skbs */
    2246            [ + ]:       51959 :                         if (total_data_len + data_len <= copied_total) {
    2247                 :          10 :                                 total_data_len += data_len;
    2248                 :          10 :                                 *last = skb;
    2249                 :          10 :                                 continue;
    2250                 :             :                         }
    2251                 :             : 
    2252                 :             :                         /* skip the already peeked data in the current skb */
    2253                 :       51949 :                         delta = copied_total - total_data_len;
    2254                 :       51949 :                         offset += delta;
    2255                 :       51949 :                         data_len -= delta;
    2256                 :             :                 }
    2257                 :             : 
    2258                 :      987457 :                 count = min_t(size_t, len - copied, data_len);
    2259            [ - ]:      987457 :                 if (!(flags & MSG_TRUNC)) {
    2260                 :      987457 :                         err = skb_copy_datagram_msg(skb, offset, msg, count);
    2261            [ + ]:      987457 :                         if (unlikely(err < 0)) {
    2262         [ #  # ]:           0 :                                 if (!copied)
    2263                 :             :                                         return err;
    2264                 :             :                                 break;
    2265                 :             :                         }
    2266                 :             :                 }
    2267                 :             : 
    2268            [ + ]:      987457 :                 if (MPTCP_SKB_CB(skb)->has_rxtstamp) {
    2269                 :         761 :                         tcp_update_recv_tstamps(skb, tss);
    2270                 :         761 :                         *cmsg_flags |= MPTCP_CMSG_TS;
    2271                 :             :                 }
    2272                 :             : 
    2273                 :      987457 :                 copied += count;
    2274                 :             : 
    2275            [ + ]:      987457 :                 if (!(flags & MSG_PEEK)) {
    2276                 :      935508 :                         msk->bytes_consumed += count;
    2277            [ + ]:      935508 :                         if (count < data_len) {
    2278                 :      369985 :                                 MPTCP_SKB_CB(skb)->offset += count;
    2279                 :      369985 :                                 MPTCP_SKB_CB(skb)->map_seq += count;
    2280                 :      369985 :                                 break;
    2281                 :             :                         }
    2282                 :             : 
    2283                 :      565523 :                         mptcp_eat_recv_skb(sk, skb);
    2284                 :             :                 } else {
    2285                 :       51949 :                         *last = skb;
    2286                 :             :                 }
    2287                 :             : 
    2288            [ + ]:      617472 :                 if (copied >= len)
    2289                 :             :                         break;
    2290                 :             :         }
    2291                 :             : 
    2292            [ + ]:     1061815 :         if (!(flags & MSG_PEEK))
    2293                 :     1016910 :                 mptcp_rcv_space_adjust(msk, copied);
    2294                 :             :         return copied;
    2295                 :             : }
    2296                 :             : 
    2297                 :        2783 : static void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk)
    2298                 :             : {
    2299            [ + ]:        2783 :         const struct tcp_sock *tp = tcp_sk(ssk);
    2300                 :             : 
    2301                 :        2783 :         msk->rcvspace_init = 1;
    2302                 :        2783 :         msk->rcvq_space.copied = 0;
    2303                 :             : 
    2304                 :             :         /* initial rcv_space offering made to peer */
    2305                 :        2783 :         msk->rcvq_space.space = min_t(u32, tp->rcv_wnd,
    2306                 :             :                                       TCP_INIT_CWND * tp->advmss);
    2307            [ + ]:        2783 :         if (msk->rcvq_space.space == 0)
    2308                 :           3 :                 msk->rcvq_space.space = TCP_INIT_CWND * TCP_MSS_DEFAULT;
    2309                 :        2783 : }
    2310                 :             : 
    2311                 :             : /* receive buffer autotuning.  See tcp_rcv_space_adjust for more information.
    2312                 :             :  *
    2313                 :             :  * Only difference: Use lowest rtt estimate of the subflows in use, see
    2314                 :             :  * mptcp_rcv_rtt_update() and mptcp_rtt_us_est().
    2315                 :             :  */
    2316                 :     1108359 : static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied)
    2317                 :             : {
    2318                 :     1108359 :         struct mptcp_subflow_context *subflow;
    2319                 :     1108359 :         struct sock *sk = (struct sock *)msk;
    2320                 :     1108359 :         u32 time, rtt_us;
    2321                 :     1108359 :         u64 mstamp;
    2322                 :             : 
    2323                 :     1108359 :         msk_owned_by_me(msk);
    2324                 :             : 
    2325       [ + ][ + ]:     1108359 :         if (copied <= 0)
    2326                 :             :                 return;
    2327                 :             : 
    2328       [ + ][ + ]:      883062 :         if (!msk->rcvspace_init)
    2329                 :        1123 :                 mptcp_rcv_space_init(msk, msk->first);
    2330                 :             : 
    2331                 :      883062 :         msk->rcvq_space.copied += copied;
    2332                 :             : 
    2333                 :      883062 :         mstamp = mptcp_stamp();
    2334                 :      883062 :         time = tcp_stamp_us_delta(mstamp, READ_ONCE(msk->rcvq_space.time));
    2335                 :             : 
    2336                 :      883062 :         rtt_us = mptcp_rtt_us_est(msk);
    2337 [ +  + ][ +  + ]:      883062 :         if (rtt_us == U32_MAX || time < (rtt_us >> 3))
    2338                 :             :                 return;
    2339                 :             : 
    2340                 :       90472 :         copied = msk->rcvq_space.copied;
    2341                 :       90472 :         copied -= mptcp_inq_hint(sk);
    2342       [ + ][ + ]:       90472 :         if (copied <= msk->rcvq_space.space)
    2343                 :       85541 :                 goto new_measure;
    2344                 :             : 
    2345                 :        4931 :         trace_mptcp_rcvbuf_grow(sk, time);
    2346       [ + ][ + ]:        4931 :         if (mptcp_rcvbuf_grow(sk, copied)) {
    2347                 :             :                 /* Make subflows follow along.  If we do not do this, we
    2348                 :             :                  * get drops at subflow level if skbs can't be moved to
    2349                 :             :                  * the mptcp rx queue fast enough (announced rcv_win can
    2350                 :             :                  * exceed ssk->sk_rcvbuf).
    2351                 :             :                  */
    2352       [ + ][ + ]:        5556 :                 mptcp_for_each_subflow(msk, subflow) {
    2353                 :        2871 :                         struct sock *ssk;
    2354                 :        2871 :                         bool slow;
    2355                 :             : 
    2356                 :        2871 :                         ssk = mptcp_subflow_tcp_sock(subflow);
    2357                 :        2871 :                         slow = lock_sock_fast(ssk);
    2358                 :             :                         /* subflows can be added before tcp_init_transfer() */
    2359 [ +  - ][ +  - ]:        2871 :                         if (tcp_sk(ssk)->rcvq_space.space)
    2360                 :        2871 :                                 tcp_rcvbuf_grow(ssk, copied);
    2361                 :        2871 :                         unlock_sock_fast(ssk, slow);
    2362                 :             :                 }
    2363                 :             :         }
    2364                 :             : 
    2365                 :        4931 : new_measure:
    2366                 :       90472 :         msk->rcvq_space.copied = 0;
    2367                 :       90472 :         msk->rcvq_space.time = mstamp;
    2368                 :             : }
    2369                 :             : 
    2370                 :      157292 : static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delta)
    2371                 :             : {
    2372                 :      157292 :         struct sk_buff *skb = list_first_entry(skbs, struct sk_buff, list);
    2373            [ + ]:      157292 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2374                 :             :         bool moved = false;
    2375                 :             : 
    2376                 :      221932 :         while (1) {
    2377                 :      189612 :                 prefetch(skb->next);
    2378                 :      189612 :                 list_del(&skb->list);
    2379                 :      189612 :                 *delta += skb->truesize;
    2380                 :             : 
    2381                 :      189612 :                 moved |= __mptcp_move_skb(sk, skb);
    2382       [ + ][ + ]:      189612 :                 if (list_empty(skbs))
    2383                 :             :                         break;
    2384                 :             : 
    2385                 :       32320 :                 skb = list_first_entry(skbs, struct sk_buff, list);
    2386                 :             :         }
    2387                 :             : 
    2388                 :      157292 :         __mptcp_ofo_queue(msk);
    2389       [ + ][ + ]:      157292 :         if (!moved)
    2390                 :             :                 return false;
    2391                 :             : 
    2392                 :             :         /* Only the worker can close an orphan, as it must then destroy it */
    2393       [ - ][ - ]:      155181 :         if (!sock_flag(sk, SOCK_DEAD))
    2394                 :      155181 :                 mptcp_check_data_fin(sk);
    2395       [ # ][ # ]:           0 :         else if (mptcp_pending_data_fin(sk, NULL))
    2396                 :           0 :                 mptcp_schedule_work(sk);
    2397                 :             :         return true;
    2398                 :             : }
    2399                 :             : 
    2400                 :     1944449 : static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skbs)
    2401                 :             : {
    2402            [ + ]:     1944449 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2403                 :             : 
    2404            [ + ]:     1944449 :         if (list_empty(&msk->backlog_list))
    2405                 :             :                 return false;
    2406                 :             : 
    2407            [ - ]:      157292 :         INIT_LIST_HEAD(skbs);
    2408            [ - ]:      157292 :         list_splice_init(&msk->backlog_list, skbs);
    2409                 :             :         return true;
    2410                 :             : }
    2411                 :             : 
    2412                 :       18894 : static bool mptcp_move_skbs(struct sock *sk)
    2413                 :             : {
    2414            [ + ]:       18894 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2415                 :       18894 :         struct list_head skbs;
    2416                 :       18894 :         bool enqueued = false;
    2417                 :       18894 :         u32 moved = 0;
    2418                 :             : 
    2419                 :       18894 :         mptcp_data_lock(sk);
    2420            [ + ]:       57413 :         while (mptcp_can_spool_backlog(sk, &skbs)) {
    2421                 :       19625 :                 mptcp_data_unlock(sk);
    2422                 :       19625 :                 enqueued |= __mptcp_move_skbs(sk, &skbs, &moved);
    2423                 :             : 
    2424                 :       19625 :                 mptcp_data_lock(sk);
    2425                 :             :         }
    2426                 :       18894 :         WRITE_ONCE(msk->backlog_len, msk->backlog_len - moved);
    2427                 :       18894 :         mptcp_data_unlock(sk);
    2428                 :             : 
    2429         [ +  - ]:       18894 :         if (enqueued && mptcp_epollin_ready(sk))
    2430                 :       18252 :                 sk->sk_data_ready(sk);
    2431                 :             : 
    2432                 :       18894 :         return enqueued;
    2433                 :             : }
    2434                 :             : 
    2435                 :       90899 : static unsigned int mptcp_inq_hint(const struct sock *sk)
    2436                 :             : {
    2437            [ + ]:       90899 :         const struct mptcp_sock *msk = mptcp_sk(sk);
    2438                 :       90899 :         const struct sk_buff *skb;
    2439                 :             : 
    2440            [ + ]:       90899 :         skb = skb_peek(&sk->sk_receive_queue);
    2441            [ - ]:       55732 :         if (skb) {
    2442                 :       55732 :                 u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
    2443                 :             : 
    2444            [ - ]:       55732 :                 if (hint_val >= INT_MAX)
    2445                 :             :                         return INT_MAX;
    2446                 :             : 
    2447                 :       55732 :                 return (unsigned int)hint_val;
    2448                 :             :         }
    2449                 :             : 
    2450         [ +  + ]:       35167 :         if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
    2451                 :         282 :                 return 1;
    2452                 :             : 
    2453                 :             :         return 0;
    2454                 :             : }
    2455                 :             : 
    2456                 :      872549 : static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
    2457                 :             :                          int flags)
    2458                 :             : {
    2459            [ + ]:      872549 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2460                 :      872549 :         struct scm_timestamping_internal tss;
    2461                 :      872549 :         int copied = 0, cmsg_flags = 0;
    2462                 :      872549 :         int target;
    2463                 :      872549 :         long timeo;
    2464                 :             : 
    2465                 :             :         /* MSG_ERRQUEUE is really a no-op till we support IP_RECVERR */
    2466            [ + ]:      872549 :         if (unlikely(flags & MSG_ERRQUEUE))
    2467                 :           0 :                 return inet_recv_error(sk, msg, len);
    2468                 :             : 
    2469                 :      872549 :         lock_sock(sk);
    2470            [ + ]:      872549 :         if (unlikely(sk->sk_state == TCP_LISTEN)) {
    2471                 :           0 :                 copied = -ENOTCONN;
    2472                 :           0 :                 goto out_err;
    2473                 :             :         }
    2474                 :             : 
    2475                 :      872549 :         mptcp_rps_record_subflows(msk);
    2476                 :             : 
    2477            [ + ]:      872549 :         timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
    2478                 :             : 
    2479                 :      872549 :         len = min_t(size_t, len, INT_MAX);
    2480            [ + ]:      872549 :         target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
    2481                 :             : 
    2482            [ + ]:      872549 :         if (unlikely(msk->recvmsg_inq))
    2483                 :         427 :                 cmsg_flags = MPTCP_CMSG_INQ;
    2484                 :             : 
    2485       [ + ][ + ]:     1066603 :         while (copied < len) {
    2486                 :     1061815 :                 struct sk_buff *last = NULL;
    2487                 :     1061815 :                 int err, bytes_read;
    2488                 :             : 
    2489                 :     1061815 :                 bytes_read = __mptcp_recvmsg_mskq(sk, msg, len - copied, flags,
    2490                 :             :                                                   copied, &tss, &cmsg_flags,
    2491                 :             :                                                   &last);
    2492            [ + ]:     1061815 :                 if (unlikely(bytes_read < 0)) {
    2493            [ # ]:           0 :                         if (!copied)
    2494                 :           0 :                                 copied = bytes_read;
    2495                 :           0 :                         goto out_err;
    2496                 :             :                 }
    2497                 :             : 
    2498                 :     1061815 :                 copied += bytes_read;
    2499                 :             : 
    2500         [ +  + ]:     1061815 :                 if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk))
    2501                 :       13016 :                         continue;
    2502                 :             : 
    2503                 :             :                 /* only the MPTCP socket status is relevant here. The exit
    2504                 :             :                  * conditions mirror closely tcp_recvmsg()
    2505                 :             :                  */
    2506            [ + ]:     1048799 :                 if (copied >= target)
    2507                 :             :                         break;
    2508                 :             : 
    2509            [ + ]:      183033 :                 if (copied) {
    2510            [ - ]:           6 :                         if (tcp_recv_should_stop(sk) ||
    2511 [ -  + ][ -  + ]:           6 :                             !timeo)
    2512                 :             :                                 break;
    2513                 :             :                 } else {
    2514       [ + ][ + ]:      183027 :                         if (sock_flag(sk, SOCK_DONE))
    2515                 :             :                                 break;
    2516                 :             : 
    2517            [ + ]:      181052 :                         copied = sock_error(sk);
    2518       [ # ][ + ]:      166348 :                         if (copied)
    2519                 :             :                                 break;
    2520                 :             : 
    2521       [ - ][ - ]:      181051 :                         if (sk->sk_shutdown & RCV_SHUTDOWN)
    2522                 :             :                                 break;
    2523                 :             : 
    2524       [ + ][ + ]:      181051 :                         if (sk->sk_state == TCP_CLOSE) {
    2525                 :             :                                 copied = -ENOTCONN;
    2526                 :             :                                 break;
    2527                 :             :                         }
    2528                 :             : 
    2529       [ - ][ - ]:      181033 :                         if (!timeo) {
    2530                 :             :                                 copied = -EAGAIN;
    2531                 :             :                                 break;
    2532                 :             :                         }
    2533                 :             : 
    2534       [ + ][ + ]:      181033 :                         if (signal_pending(current)) {
    2535       [ + ][ - ]:           7 :                                 copied = sock_intr_errno(timeo);
    2536                 :             :                                 break;
    2537                 :             :                         }
    2538                 :             :                 }
    2539                 :             : 
    2540 [ -  - ][ -  - ]:      181038 :                 pr_debug("block timeout %ld\n", timeo);
    2541                 :      181038 :                 mptcp_cleanup_rbuf(msk, copied);
    2542                 :      181038 :                 err = sk_wait_data(sk, &timeo, last);
    2543       [ + ][ + ]:      181038 :                 if (err < 0) {
    2544       [ # ][ # ]:           0 :                         copied = copied ? : err;
    2545                 :           0 :                         goto out_err;
    2546                 :             :                 }
    2547                 :             :         }
    2548                 :             : 
    2549                 :      872549 :         mptcp_cleanup_rbuf(msk, copied);
    2550                 :             : 
    2551                 :      872549 : out_err:
    2552 [ +  - ][ +  - ]:      872549 :         if (cmsg_flags && copied >= 0) {
    2553       [ + ][ + ]:         727 :                 if (cmsg_flags & MPTCP_CMSG_TS)
    2554                 :         719 :                         tcp_recv_timestamp(msg, sk, &tss);
    2555                 :             : 
    2556       [ + ][ + ]:         727 :                 if (cmsg_flags & MPTCP_CMSG_INQ) {
    2557                 :         427 :                         unsigned int inq = mptcp_inq_hint(sk);
    2558                 :             : 
    2559                 :         427 :                         put_cmsg(msg, SOL_TCP, TCP_CM_INQ, sizeof(inq), &inq);
    2560                 :             :                 }
    2561                 :             :         }
    2562                 :             : 
    2563 [ -  - ][ -  - ]:      872549 :         pr_debug("msk=%p rx queue empty=%d copied=%d\n",
    2564                 :             :                  msk, skb_queue_empty(&sk->sk_receive_queue), copied);
    2565                 :             : 
    2566                 :      872549 :         release_sock(sk);
    2567                 :      872549 :         return copied;
    2568                 :             : }
    2569                 :             : 
    2570                 :        5762 : static void mptcp_retransmit_timer(struct timer_list *t)
    2571                 :             : {
    2572                 :        5762 :         struct sock *sk = timer_container_of(sk, t, mptcp_retransmit_timer);
    2573            [ + ]:        5762 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2574                 :             : 
    2575                 :        5762 :         bh_lock_sock(sk);
    2576       [ + ][ + ]:        5762 :         if (!sock_owned_by_user(sk)) {
    2577                 :             :                 /* we need a process context to retransmit */
    2578       [ - ][ - ]:        8531 :                 if (!test_and_set_bit(MPTCP_WORK_RTX, &msk->flags))
    2579                 :        5278 :                         mptcp_schedule_work(sk);
    2580                 :             :         } else {
    2581                 :             :                 /* delegate our work to tcp_release_cb() */
    2582      [ +  -  - ]:         484 :                 __set_bit(MPTCP_RETRANSMIT, &msk->cb_flags);
              [ +  -  - ]
    2583                 :             :         }
    2584                 :        5762 :         bh_unlock_sock(sk);
    2585                 :        5762 :         sock_put(sk);
    2586                 :        5762 : }
    2587                 :             : 
    2588                 :         138 : static void mptcp_tout_timer(struct timer_list *t)
    2589                 :             : {
    2590                 :         138 :         struct inet_connection_sock *icsk =
    2591                 :             :                 timer_container_of(icsk, t, mptcp_tout_timer);
    2592                 :         138 :         struct sock *sk = &icsk->icsk_inet.sk;
    2593                 :             : 
    2594                 :         138 :         mptcp_schedule_work(sk);
    2595                 :         138 :         sock_put(sk);
    2596                 :         138 : }
    2597                 :             : 
    2598                 :             : /* Find an idle subflow.  Return NULL if there is unacked data at tcp
    2599                 :             :  * level.
    2600                 :             :  *
    2601                 :             :  * A backup subflow is returned only if that is the only kind available.
    2602                 :             :  */
    2603                 :        5741 : struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk)
    2604                 :             : {
    2605                 :        5741 :         struct sock *backup = NULL, *pick = NULL;
    2606                 :        5741 :         struct mptcp_subflow_context *subflow;
    2607                 :        5741 :         int min_stale_count = INT_MAX;
    2608                 :             : 
    2609            [ + ]:       14657 :         mptcp_for_each_subflow(msk, subflow) {
    2610                 :        8916 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    2611                 :             : 
    2612            [ + ]:        8916 :                 if (!__mptcp_subflow_active(subflow))
    2613                 :        1858 :                         continue;
    2614                 :             : 
    2615                 :             :                 /* still data outstanding at TCP level? skip this */
    2616            [ + ]:        7058 :                 if (!tcp_rtx_and_write_queues_empty(ssk)) {
    2617                 :        3471 :                         min_stale_count = min_t(int, min_stale_count, subflow->stale_count);
    2618                 :        3471 :                         continue;
    2619                 :             :                 }
    2620                 :             : 
    2621      [ +  +  + ]:        3587 :                 if (subflow->backup || subflow->request_bkup) {
    2622            [ + ]:         107 :                         if (!backup)
    2623                 :          96 :                                 backup = ssk;
    2624                 :         107 :                         continue;
    2625                 :             :                 }
    2626                 :             : 
    2627            [ + ]:        3480 :                 if (!pick)
    2628                 :        2412 :                         pick = ssk;
    2629                 :             :         }
    2630                 :             : 
    2631            [ + ]:        5741 :         if (pick)
    2632                 :             :                 return pick;
    2633                 :             : 
    2634                 :             :         /* use backup only if there are no progresses anywhere */
    2635            [ + ]:        3329 :         return min_stale_count > 1 ? backup : NULL;
    2636                 :             : }
    2637                 :             : 
    2638                 :        2242 : bool __mptcp_retransmit_pending_data(struct sock *sk)
    2639                 :             : {
    2640                 :        2242 :         struct mptcp_data_frag *cur, *rtx_head;
    2641            [ + ]:        2242 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2642                 :             : 
    2643            [ + ]:        2242 :         if (__mptcp_check_fallback(msk))
    2644                 :             :                 return false;
    2645                 :             : 
    2646                 :             :         /* the closing socket has some data untransmitted and/or unacked:
    2647                 :             :          * some data in the mptcp rtx queue has not really xmitted yet.
    2648                 :             :          * keep it simple and re-inject the whole mptcp level rtx queue
    2649                 :             :          */
    2650                 :        2154 :         mptcp_data_lock(sk);
    2651                 :        2154 :         __mptcp_clean_una_wakeup(sk);
    2652                 :        2154 :         rtx_head = mptcp_rtx_head(sk);
    2653       [ + ][ + ]:        2154 :         if (!rtx_head) {
    2654                 :        2075 :                 mptcp_data_unlock(sk);
    2655                 :        2075 :                 return false;
    2656                 :             :         }
    2657                 :             : 
    2658                 :          79 :         msk->recovery_snd_nxt = msk->snd_nxt;
    2659                 :          79 :         msk->recovery = true;
    2660                 :          79 :         mptcp_data_unlock(sk);
    2661                 :             : 
    2662                 :          79 :         msk->first_pending = rtx_head;
    2663                 :          79 :         msk->snd_burst = 0;
    2664                 :             : 
    2665                 :             :         /* be sure to clear the "sent status" on all re-injected fragments */
    2666       [ + ][ + ]:        3844 :         list_for_each_entry(cur, &msk->rtx_queue, list) {
    2667       [ + ][ + ]:        3782 :                 if (!cur->already_sent)
    2668                 :             :                         break;
    2669                 :        3765 :                 cur->already_sent = 0;
    2670                 :             :         }
    2671                 :             : 
    2672                 :             :         return true;
    2673                 :             : }
    2674                 :             : 
    2675                 :             : /* flags for __mptcp_close_ssk() */
    2676                 :             : #define MPTCP_CF_PUSH           BIT(1)
    2677                 :             : 
    2678                 :             : /* be sure to send a reset only if the caller asked for it, also
    2679                 :             :  * clean completely the subflow status when the subflow reaches
    2680                 :             :  * TCP_CLOSE state
    2681                 :             :  */
    2682                 :        1827 : static void __mptcp_subflow_disconnect(struct sock *ssk,
    2683                 :             :                                        struct mptcp_subflow_context *subflow,
    2684                 :             :                                        bool fastclosing)
    2685                 :             : {
    2686         [ +  + ]:        1827 :         if (((1 << ssk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
              [ +  +  + ]
    2687                 :             :             fastclosing) {
    2688                 :             :                 /* The MPTCP code never wait on the subflow sockets, TCP-level
    2689                 :             :                  * disconnect should never fail
    2690                 :             :                  */
    2691       [ + ][ + ]:        1797 :                 WARN_ON_ONCE(tcp_disconnect(ssk, 0));
    2692                 :        1797 :                 mptcp_subflow_ctx_reset(subflow);
    2693                 :             :         } else {
    2694                 :          30 :                 tcp_shutdown(ssk, SEND_SHUTDOWN);
    2695                 :             :         }
    2696                 :        1827 : }
    2697                 :             : 
    2698                 :        2223 : static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk)
    2699                 :             : {
    2700            [ + ]:        2223 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2701                 :        2223 :         struct sk_buff *skb;
    2702                 :             : 
    2703                 :        2223 :         mptcp_data_lock(sk);
    2704       [ + ][ + ]:        2226 :         list_for_each_entry(skb, &msk->backlog_list, list) {
    2705            [ - ]:           3 :                 if (skb->sk != ssk)
    2706                 :           3 :                         continue;
    2707                 :             : 
    2708                 :           0 :                 atomic_sub(skb->truesize, &skb->sk->sk_rmem_alloc);
    2709                 :           0 :                 skb->sk = NULL;
    2710                 :             :         }
    2711                 :        2223 :         mptcp_data_unlock(sk);
    2712                 :        2223 : }
    2713                 :             : 
    2714                 :             : static void mptcp_check_fastclose(struct mptcp_sock *msk);
    2715                 :             : 
    2716                 :             : /* After the close, a pending DATA_FIN or MP_FASTCLOSE would be ignored */
    2717                 :         604 : static void mptcp_check_rcv_close(struct sock *sk)
    2718                 :             : {
    2719                 :             :         /* process the DATA_FIN after the data still in the backlog */
    2720         [ +  + ]:         604 :         if (READ_ONCE(mptcp_sk(sk)->rcv_data_fin)) {
              [ +  +  + ]
    2721                 :         132 :                 mptcp_move_skbs(sk);
    2722                 :         132 :                 mptcp_check_data_fin(sk);
    2723                 :             :         }
    2724                 :             : 
    2725       [ + ][ + ]:         604 :         mptcp_check_fastclose(mptcp_sk(sk));
    2726                 :         604 : }
    2727                 :             : 
    2728                 :             : /* subflow sockets can be either outgoing (connect) or incoming
    2729                 :             :  * (accept).
    2730                 :             :  *
    2731                 :             :  * Outgoing subflows use in-kernel sockets.
    2732                 :             :  * Incoming subflows do not have their own 'struct socket' allocated,
    2733                 :             :  * so we need to use tcp_close() after detaching them from the mptcp
    2734                 :             :  * parent socket.
    2735                 :             :  */
    2736                 :        8194 : static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
    2737                 :             :                               struct mptcp_subflow_context *subflow,
    2738                 :             :                               unsigned int flags)
    2739                 :             : {
    2740            [ + ]:        8194 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2741                 :        8194 :         bool dispose_it, need_push = false;
    2742                 :        8194 :         int fwd_remaining;
    2743                 :             : 
    2744                 :             :         /* Do not pass RX data to the msk, even if the subflow socket is not
    2745                 :             :          * going to be freed (i.e. even for the first subflow on graceful
    2746                 :             :          * subflow close.
    2747                 :             :          */
    2748                 :        8194 :         lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
    2749                 :        8194 :         subflow->closing = 1;
    2750                 :             : 
    2751            [ + ]:        8194 :         if (flags & MPTCP_CF_PUSH)
    2752                 :        2223 :                 mptcp_cleanup_ssk_backlog(sk, ssk);
    2753                 :             : 
    2754                 :             :         /* Borrow the fwd allocated page left-over; fwd memory for the subflow
    2755                 :             :          * could be negative at this point, but will be reach zero soon - when
    2756                 :             :          * the data allocated using such fragment will be freed.
    2757                 :             :          */
    2758            [ + ]:        8194 :         if (subflow->lent_mem_frag) {
    2759                 :        2903 :                 fwd_remaining = PAGE_SIZE - subflow->lent_mem_frag;
    2760                 :        2903 :                 sk_forward_alloc_add(sk, fwd_remaining);
    2761                 :        2903 :                 sk_forward_alloc_add(ssk, -fwd_remaining);
    2762                 :        2903 :                 subflow->lent_mem_frag = 0;
    2763                 :             :         }
    2764                 :             : 
    2765                 :             :         /* also before accept(), not to reset again in inet_child_forget() */
    2766         [ +  + ]:        8194 :         if (subflow->send_fastclose && ssk->sk_state != TCP_CLOSE)
    2767                 :         474 :                 tcp_set_state(ssk, TCP_CLOSE);
    2768                 :             : 
    2769                 :             :         /* If the first subflow moved to a close state before accept, e.g. due
    2770                 :             :          * to an incoming reset or listener shutdown, the subflow socket is
    2771                 :             :          * already deleted by inet_child_forget() and the mptcp socket can't
    2772                 :             :          * survive too.
    2773                 :             :          */
    2774      [ +  +  + ]:        8236 :         if (msk->in_accept_queue && msk->first == ssk &&
    2775            [ - ]:          42 :             (sock_flag(sk, SOCK_DEAD) || sock_flag(ssk, SOCK_DEAD))) {
    2776                 :             :                 /* ensure later check in mptcp_worker() will dispose the msk */
    2777                 :          42 :                 sock_set_flag(sk, SOCK_DEAD);
    2778                 :          42 :                 mptcp_set_close_tout(sk, tcp_jiffies32 - (mptcp_close_timeout(sk) + 1));
    2779                 :          42 :                 mptcp_subflow_drop_ctx(ssk);
    2780                 :          42 :                 goto out_release;
    2781                 :             :         }
    2782                 :             : 
    2783 [ +  + ][ +  + ]:        8152 :         dispose_it = msk->free_first || ssk != msk->first;
    2784                 :             :         if (dispose_it)
    2785                 :        6325 :                 list_del(&subflow->node);
    2786                 :             : 
    2787 [ +  + ][ +  + ]:        8152 :         need_push = (flags & MPTCP_CF_PUSH) && __mptcp_retransmit_pending_data(sk);
    2788       [ + ][ + ]:        8152 :         if (!dispose_it) {
    2789                 :        1827 :                 __mptcp_subflow_disconnect(ssk, subflow, msk->fastclosing);
    2790                 :        1827 :                 release_sock(ssk);
    2791                 :             : 
    2792                 :        1827 :                 goto out;
    2793                 :             :         }
    2794                 :             : 
    2795                 :        6325 :         subflow->disposable = 1;
    2796                 :             : 
    2797                 :             :         /* if ssk hit tcp_done(), tcp_cleanup_ulp() cleared the related ops
    2798                 :             :          * the ssk has been already destroyed, we just need to release the
    2799                 :             :          * reference owned by msk;
    2800                 :             :          */
    2801       [ + ][ + ]:        6325 :         if (!inet_csk(ssk)->icsk_ulp_ops) {
    2802       [ # ][ # ]:           0 :                 WARN_ON_ONCE(!sock_flag(ssk, SOCK_DEAD));
    2803                 :           0 :                 mptcp_subflow_free_ctx(subflow);
    2804                 :             :         } else {
    2805                 :             :                 /* otherwise tcp will dispose of the ssk and subflow ctx */
    2806                 :        6325 :                 __tcp_close(ssk, 0);
    2807                 :             : 
    2808                 :             :                 /* close acquired an extra ref */
    2809                 :        6325 :                 __sock_put(ssk);
    2810                 :             :         }
    2811                 :             : 
    2812                 :        6367 : out_release:
    2813                 :        6367 :         __mptcp_subflow_error_report(sk, ssk);
    2814                 :        6367 :         release_sock(ssk);
    2815                 :             : 
    2816                 :        6367 :         sock_put(ssk);
    2817                 :             : 
    2818       [ + ][ + ]:        6367 :         if (ssk == msk->first)
    2819                 :        5115 :                 WRITE_ONCE(msk->first, NULL);
    2820                 :             : 
    2821                 :        1252 : out:
    2822                 :        8194 :         __mptcp_sync_sndbuf(sk);
    2823       [ + ][ + ]:        8194 :         if (need_push)
    2824                 :          61 :                 __mptcp_push_pending(sk, 0);
    2825                 :             : 
    2826                 :             :         /* Catch every 'all subflows closed' scenario, including peers silently
    2827                 :             :          * closing them, e.g. due to timeout.
    2828                 :             :          * For established sockets, allow an additional timeout before closing,
    2829                 :             :          * as the protocol can still create more subflows.
    2830                 :             :          */
    2831      [ +  +  + ]:       12232 :         if (list_is_singular(&msk->conn_list) && msk->first &&
              [ +  +  + ]
         [ +  + ][ +  + ]
    2832       [ - ][ - ]:          42 :             inet_sk_state_load(msk->first) == TCP_CLOSE) {
    2833       [ + ][ + ]:        1761 :                 if (sock_flag(sk, SOCK_DEAD)) {
    2834                 :             :                         /* let the worker close and destroy the orphan */
    2835                 :        1135 :                         mptcp_set_close_tout(sk, tcp_jiffies32 -
    2836                 :        1135 :                                              (mptcp_close_timeout(sk) + 1));
    2837                 :        1135 :                         mptcp_schedule_work(sk);
    2838 [ +  + ][ +  + ]:         626 :                 } else if (sk->sk_state != TCP_ESTABLISHED ||
    2839                 :             :                            msk->in_accept_queue) {
    2840                 :         598 :                         mptcp_check_rcv_close(sk);
    2841                 :         598 :                         mptcp_set_state(sk, TCP_CLOSE);
    2842                 :         598 :                         WRITE_ONCE(sk->sk_shutdown,
    2843                 :             :                                    sk->sk_shutdown | SEND_SHUTDOWN);
    2844                 :         598 :                         mptcp_close_wake_up(sk);
    2845                 :             :                 } else {
    2846                 :          28 :                         mptcp_start_tout_timer(sk);
    2847                 :             :                 }
    2848      [ +  +  + ]:        6837 :         } else if (list_is_singular(&msk->conn_list) && msk->first &&
              [ +  +  + ]
    2849       [ # ][ # ]:           0 :                    mptcp_subflow_ctx(msk->first)->closing &&
    2850       [ # ][ # ]:           0 :                    !inet_csk(sk)->icsk_mtup.probe_timestamp &&
    2851       [ # ][ # ]:           0 :                    sk->sk_state != TCP_CLOSE) {
    2852                 :             :                 /* The initial subflow has only been shut down, and its later
    2853                 :             :                  * close will be ignored: start the close timeout now.
    2854                 :             :                  */
    2855                 :           0 :                 mptcp_start_tout_timer(sk);
    2856                 :             :         }
    2857                 :        8194 : }
    2858                 :             : 
    2859                 :        2267 : void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
    2860                 :             :                      struct mptcp_subflow_context *subflow)
    2861                 :             : {
    2862            [ + ]:        2267 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2863                 :             : 
    2864                 :             :         /* The first subflow can already be closed or disconnected */
    2865         [ +  + ]:        2267 :         if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
              [ +  +  + ]
    2866                 :             :                 return;
    2867                 :             : 
    2868                 :        2223 :         subflow->close_event_done = true;
    2869                 :             : 
    2870       [ + ][ + ]:        2223 :         if (sk->sk_state == TCP_ESTABLISHED)
    2871                 :         358 :                 mptcp_event(MPTCP_EVENT_SUB_CLOSED, msk, ssk, GFP_KERNEL);
    2872                 :             : 
    2873                 :             :         /* subflow aborted before reaching the fully_established status
    2874                 :             :          * attempt the creation of the next subflow
    2875                 :             :          */
    2876                 :        2223 :         mptcp_pm_subflow_check_next(msk, subflow);
    2877                 :             : 
    2878                 :             :         /* On fallback, the FIN of the first subflow is cleared when it is
    2879                 :             :          * disconnected: process the DATA_FIN emulated from it before.
    2880                 :             :          */
    2881 [ +  + ][ +  + ]:        2223 :         if (ssk == msk->first && __mptcp_check_fallback(msk) &&
    2882         [ +  - ]:          88 :             READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
              [ +  +  - ]
    2883                 :          10 :                 mptcp_move_skbs(sk);
    2884                 :          10 :                 mptcp_check_data_fin(sk);
    2885                 :             :         }
    2886                 :             : 
    2887                 :        2223 :         __mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
    2888                 :             : }
    2889                 :             : 
    2890                 :           0 : static unsigned int mptcp_sync_mss(struct sock *sk, u32 pmtu)
    2891                 :             : {
    2892                 :           0 :         return 0;
    2893                 :             : }
    2894                 :             : 
    2895                 :        1612 : static void __mptcp_close_subflow(struct sock *sk)
    2896                 :             : {
    2897                 :        1612 :         struct mptcp_subflow_context *subflow, *tmp;
    2898            [ + ]:        1612 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2899                 :             : 
    2900                 :        1612 :         might_sleep();
    2901                 :             : 
    2902       [ + ][ + ]:        4124 :         mptcp_for_each_subflow_safe(msk, subflow, tmp) {
    2903                 :        2512 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    2904                 :        2512 :                 int ssk_state = inet_sk_state_load(ssk);
    2905                 :             : 
    2906 [ +  + ][ +  + ]:        2512 :                 if (ssk_state != TCP_CLOSE &&
    2907       [ + ][ + ]:          73 :                     (ssk_state != TCP_CLOSE_WAIT ||
    2908       [ + ][ + ]:          42 :                      inet_sk_state_load(sk) != TCP_ESTABLISHED ||
         [ #  # ][ #  # ]
    2909                 :          42 :                      __mptcp_check_fallback(msk)))
    2910                 :         448 :                         continue;
    2911                 :             : 
    2912                 :             :                 /* 'subflow_data_ready' will re-sched once rx queue is empty */
    2913       [ + ][ + ]:        2064 :                 if (!skb_queue_empty_lockless(&ssk->sk_receive_queue))
    2914                 :           1 :                         continue;
    2915                 :             : 
    2916                 :        2063 :                 mptcp_close_ssk(sk, ssk, subflow);
    2917                 :             :         }
    2918                 :             : 
    2919                 :        1612 : }
    2920                 :             : 
    2921                 :       37896 : static bool mptcp_close_tout_expired(const struct sock *sk)
    2922                 :             : {
    2923            [ + ]:       37896 :         if (!inet_csk(sk)->icsk_mtup.probe_timestamp ||
    2924            [ + ]:       15939 :             sk->sk_state == TCP_CLOSE)
    2925                 :             :                 return false;
    2926                 :             : 
    2927                 :       12705 :         return time_after32(tcp_jiffies32,
    2928                 :             :                   inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk));
    2929                 :             : }
    2930                 :             : 
    2931                 :             : /* Would TCP abort this subflow if it were an orphan probing a zero window? */
    2932                 :           0 : static bool mptcp_subflow_probe_timed_out(struct sock *ssk)
    2933                 :             : {
    2934            [ # ]:           0 :         u8 retries2 = READ_ONCE(sock_net(ssk)->ipv4.sysctl_tcp_retries2);
    2935                 :           0 :         struct inet_connection_sock *icsk = inet_csk(ssk);
    2936       [ # ][ # ]:           0 :         const struct tcp_sock *tp = tcp_sk(ssk);
    2937                 :           0 :         unsigned long limit;
    2938                 :           0 :         bool slow, ret;
    2939                 :           0 :         u64 when;
    2940                 :             : 
    2941                 :           0 :         slow = lock_sock_fast_nested(ssk);
    2942       [ # ][ # ]:           0 :         limit = tcp_rto_max(ssk);
    2943       [ # ][ # ]:           0 :         if (tp->packets_out) {
    2944 [ #  # ][ #  # ]:           0 :                 ret = !tp->snd_wnd && icsk->icsk_rto >= limit;
    2945                 :             :         } else {
    2946       [ # ][ # ]:           0 :                 if (icsk->icsk_backoff < retries2)
    2947                 :           0 :                         limit *= 2;
    2948                 :             :                 /* a shift of 32 already exceeds the limit */
    2949                 :           0 :                 when = (u64)icsk->icsk_rto << min_t(u8, icsk->icsk_backoff, 32);
    2950      [ #  #  # ]:           0 :                 ret = tcp_send_head(ssk) && when >= limit;
              [ #  #  # ]
    2951                 :             :         }
    2952                 :           0 :         unlock_sock_fast(ssk, slow);
    2953                 :             : 
    2954                 :           0 :         return ret;
    2955                 :             : }
    2956                 :             : 
    2957                 :             : /* As TCP orphans: limited in number and memory */
    2958                 :        1433 : static bool mptcp_orphan_oom(struct sock *sk)
    2959                 :             : {
    2960       [ + ][ + ]:        1433 :         if (!tcp_check_oom(sk, 0))
    2961                 :             :                 return false;
    2962                 :             : 
    2963                 :           0 :         NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
    2964                 :           0 :         return true;
    2965                 :             : }
    2966                 :             : 
    2967                 :             : /* Before its DATA_FIN, keep an orphan while a subflow can send its data */
    2968                 :         315 : static bool mptcp_orphan_keep(struct sock *sk)
    2969                 :             : {
    2970            [ + ]:         315 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2971                 :         315 :         struct mptcp_subflow_context *subflow;
    2972                 :             : 
    2973         [ +  + ]:         315 :         if (!sock_flag(sk, SOCK_DEAD) || msk->snd_nxt == msk->write_seq)
    2974                 :             :                 return false;
    2975                 :             : 
    2976         [ +  + ]:          12 :         mptcp_for_each_subflow(msk, subflow) {
    2977                 :           6 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    2978                 :             : 
    2979                 :             :                 /* a live peer acks at least the probes, every TCP_RTO_MAX */
    2980            [ + ]:           6 :                 if (__mptcp_subflow_active(subflow) &&
    2981         [ #  # ]:           0 :                     tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
    2982            [ # ]:           0 :                     2 * TCP_RTO_MAX &&
    2983                 :           0 :                     !mptcp_subflow_probe_timed_out(ssk))
    2984                 :           0 :                         return !mptcp_orphan_oom(sk);
    2985                 :             :         }
    2986                 :             : 
    2987                 :             :         return false;
    2988                 :             : }
    2989                 :             : 
    2990                 :             : /* On fallback, TCP can send what an orphan gave to the subflow. As in
    2991                 :             :  * __mptcp_close(), unread data requires a reset, also in the backlog: stop
    2992                 :             :  * passing data to the msk first, TCP resets on what is received later.
    2993                 :             :  */
    2994                 :         315 : static bool mptcp_orphan_handover(struct sock *sk)
    2995                 :             : {
    2996            [ + ]:         315 :         struct mptcp_sock *msk = mptcp_sk(sk);
    2997                 :         315 :         struct mptcp_subflow_context *subflow;
    2998                 :             : 
    2999         [ +  + ]:         315 :         if (!sock_flag(sk, SOCK_DEAD) || !__mptcp_check_fallback(msk) ||
    3000            [ + ]:          21 :             msk->snd_nxt != msk->write_seq)
    3001                 :         294 :                 return false;
    3002                 :             : 
    3003            [ + ]:          42 :         mptcp_for_each_subflow(msk, subflow) {
    3004                 :          21 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    3005                 :             : 
    3006                 :          21 :                 lock_sock(ssk);
    3007                 :          21 :                 subflow->closing = 1;
    3008                 :          21 :                 release_sock(ssk);
    3009                 :             :         }
    3010                 :             : 
    3011         [ -  + ]:          21 :         return !mptcp_data_avail(msk) && !READ_ONCE(msk->backlog_len);
    3012                 :             : }
    3013                 :             : 
    3014                 :       13236 : static void mptcp_check_fastclose(struct mptcp_sock *msk)
    3015                 :             : {
    3016                 :       13236 :         struct mptcp_subflow_context *subflow, *tmp;
    3017                 :       13236 :         struct sock *sk = (struct sock *)msk;
    3018                 :             : 
    3019    [ + ][ +  + ]:       13236 :         if (likely(!READ_ONCE(msk->rcv_fastclose)))
    3020                 :             :                 return;
    3021                 :             : 
    3022                 :             :         /* a DATA_FIN received before still leads to EOF, as with TCP */
    3023    [ + ][ +  + ]:         333 :         if (READ_ONCE(msk->rcv_data_fin))
    3024                 :         145 :                 mptcp_move_skbs(sk);
    3025                 :         333 :         mptcp_check_data_fin(sk);
    3026                 :             : 
    3027                 :         333 :         mptcp_token_destroy(msk);
    3028                 :             : 
    3029       [ + ][ + ]:         700 :         mptcp_for_each_subflow_safe(msk, subflow, tmp) {
    3030                 :         367 :                 struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
    3031                 :         367 :                 bool slow;
    3032                 :             : 
    3033                 :         367 :                 slow = lock_sock_fast(tcp_sk);
    3034       [ + ][ + ]:         367 :                 if (tcp_sk->sk_state != TCP_CLOSE) {
    3035                 :          28 :                         mptcp_send_active_reset_reason(tcp_sk);
    3036                 :          28 :                         tcp_set_state(tcp_sk, TCP_CLOSE);
    3037                 :             :                 }
    3038                 :         367 :                 unlock_sock_fast(tcp_sk, slow);
    3039                 :             :         }
    3040                 :             : 
    3041                 :             :         /* Mirror the tcp_reset() error propagation */
    3042   [ -  +  +  + ]:         333 :         switch (sk->sk_state) {
           [ -  +  +  + ]
    3043                 :             :         case TCP_SYN_SENT:
    3044                 :           0 :                 WRITE_ONCE(sk->sk_err, ECONNREFUSED);
    3045                 :           0 :                 break;
    3046                 :             :         case TCP_CLOSE_WAIT:
    3047                 :          89 :                 WRITE_ONCE(sk->sk_err, EPIPE);
    3048                 :          89 :                 break;
    3049                 :             :         case TCP_CLOSE:
    3050                 :             :                 return;
    3051                 :             :         default:
    3052                 :          62 :                 WRITE_ONCE(sk->sk_err, ECONNRESET);
    3053                 :             :         }
    3054                 :             : 
    3055                 :         151 :         mptcp_set_state(sk, TCP_CLOSE);
    3056                 :         151 :         WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
    3057                 :         151 :         smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
    3058                 :         151 :         set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags);
    3059                 :             : 
    3060                 :             :         /* the calling mptcp_worker will properly destroy the socket */
    3061       [ + ][ + ]:         151 :         if (sock_flag(sk, SOCK_DEAD))
    3062                 :             :                 return;
    3063                 :             : 
    3064                 :         118 :         sk->sk_state_change(sk);
    3065                 :         118 :         sk_error_report(sk);
    3066                 :             : }
    3067                 :             : 
    3068                 :             : /*
    3069                 :             :  * Retransmit the specified data fragment on all the selected subflows,
    3070                 :             :  * starting from the specified sequence
    3071                 :             :  */
    3072                 :         400 : static int __mptcp_push_retrans(struct sock *sk, struct mptcp_data_frag *dfrag,
    3073                 :             :                                 u64 sent_seq)
    3074                 :             : {
    3075                 :         400 :         struct mptcp_sendmsg_info info = { .data_lock_held = true, };
    3076            [ + ]:         400 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3077                 :         400 :         struct mptcp_subflow_context *subflow;
    3078                 :         400 :         struct sock *ssk;
    3079                 :         400 :         int ret, len = 0;
    3080                 :             : 
    3081       [ + ][ + ]:        1374 :         mptcp_for_each_subflow(msk, subflow) {
    3082    [ + ][ +  + ]:         974 :                 if (READ_ONCE(subflow->scheduled)) {
    3083                 :         400 :                         u16 offset = sent_seq - dfrag->data_seq;
    3084                 :         400 :                         u16 copied = 0;
    3085                 :             : 
    3086                 :         400 :                         mptcp_subflow_set_scheduled(subflow, false);
    3087                 :             : 
    3088                 :         400 :                         ssk = mptcp_subflow_tcp_sock(subflow);
    3089                 :             : 
    3090                 :         400 :                         lock_sock(ssk);
    3091                 :             : 
    3092                 :             :                         /* limit retransmission to the bytes already sent on some subflows */
    3093                 :         400 :                         info.sent = offset;
    3094    [ + ][ +  + ]:         400 :                         info.limit = READ_ONCE(msk->csum_enabled) ? dfrag->data_len :
    3095                 :             :                                                                     dfrag->already_sent;
    3096                 :             : 
    3097                 :             :                         /*
    3098                 :             :                          * make the whole retrans decision, xmit, disallow
    3099                 :             :                          * fallback atomic, note that we can't retrans even
    3100                 :             :                          * when an infinite fallback is in progress, i.e. new
    3101                 :             :                          * subflows are disallowed.
    3102                 :             :                          */
    3103                 :         400 :                         spin_lock_bh(&msk->fallback_lock);
    3104       [ - ][ - ]:         400 :                         if (__mptcp_check_fallback(msk) ||
    3105    [ + ][ +  + ]:         400 :                             !msk->allow_subflows) {
    3106                 :           0 :                                 spin_unlock_bh(&msk->fallback_lock);
    3107                 :           0 :                                 release_sock(ssk);
    3108                 :           0 :                                 return -1;
    3109                 :             :                         }
    3110                 :             : 
    3111       [ + ][ + ]:         840 :                         while (info.sent < info.limit) {
    3112                 :         440 :                                 ret = mptcp_sendmsg_frag(sk, ssk, dfrag, &info);
    3113       [ - ][ - ]:         440 :                                 if (ret <= 0)
    3114                 :             :                                         break;
    3115                 :             : 
    3116       [ - ][ # ]:         440 :                                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RETRANSSEGS);
    3117                 :         440 :                                 copied += ret;
    3118                 :         440 :                                 info.sent += ret;
    3119                 :             :                         }
    3120       [ - ][ - ]:         400 :                         if (copied) {
    3121                 :         400 :                                 len = max(copied, len);
    3122       [ + ][ + ]:         400 :                                 tcp_push(ssk, 0, info.mss_now, tcp_sk(ssk)->nonagle,
    3123                 :             :                                          info.size_goal);
    3124                 :         400 :                                 msk->allow_infinite_fallback = false;
    3125                 :             :                         }
    3126                 :         400 :                         spin_unlock_bh(&msk->fallback_lock);
    3127                 :             : 
    3128                 :         400 :                         release_sock(ssk);
    3129                 :             :                 }
    3130                 :             :         }
    3131                 :             :         return len;
    3132                 :             : }
    3133                 :             : 
    3134                 :        5562 : static void __mptcp_retrans(struct sock *sk)
    3135                 :             : {
    3136            [ + ]:        5562 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3137                 :        5562 :         struct mptcp_subflow_context *subflow;
    3138                 :        5562 :         struct mptcp_data_frag *dfrag;
    3139                 :        5562 :         u64 retrans_seq, sent_seq;
    3140                 :        5562 :         bool need_retrans;
    3141                 :        5562 :         int err, len;
    3142                 :             : 
    3143                 :        5562 :         mptcp_pm_chk_stale(msk);
    3144                 :             : 
    3145                 :             :         /* Get an updated and consistent rtx queue status. */
    3146                 :        5562 :         mptcp_data_lock(sk);
    3147                 :        5562 :         __mptcp_clean_una_wakeup(sk);
    3148                 :        5562 :         retrans_seq = msk->snd_una;
    3149                 :        5562 :         dfrag = mptcp_rtx_head(sk);
    3150                 :        5562 :         need_retrans = !!dfrag;
    3151                 :        5562 :         mptcp_data_unlock(sk);
    3152                 :             : 
    3153                 :         182 :         for (;;) {
    3154                 :        5744 :                 bool already_acked;
    3155                 :             : 
    3156                 :        5744 :                 err = mptcp_sched_get_retrans(msk);
    3157       [ + ][ + ]:        5744 :                 if (err)
    3158                 :             :                         break;
    3159                 :             : 
    3160                 :             :                 /* `already_sent` can be 0 for `dfrag` belonging to the RTX
    3161                 :             :                  *  queue due to __mptcp_retransmit_pending_data().
    3162                 :             :                  */
    3163 [ +  - ][ +  - ]:        2447 :                 if (!dfrag || !dfrag->already_sent)
    3164                 :             :                         break;
    3165                 :             : 
    3166                 :             :                 /* Can fail only in case of fallback. */
    3167                 :         400 :                 len = __mptcp_push_retrans(sk, dfrag, retrans_seq);
    3168       [ + ][ + ]:         400 :                 if (len < 0)
    3169                 :           0 :                         goto clear_scheduled;
    3170                 :             : 
    3171                 :         400 :                 retrans_seq += len;
    3172                 :         400 :                 msk->bytes_retrans += len;
    3173                 :         400 :                 dfrag->already_sent = max_t(u16, dfrag->already_sent,
    3174                 :             :                                             retrans_seq - dfrag->data_seq);
    3175                 :             : 
    3176                 :             :                 /* With csum enabled, retransmission can send new data. */
    3177                 :         400 :                 sent_seq = dfrag->already_sent + dfrag->data_seq;
    3178       [ + ][ + ]:         400 :                 if (after64(sent_seq, msk->snd_nxt))
    3179                 :           0 :                         WRITE_ONCE(msk->snd_nxt, sent_seq);
    3180                 :             : 
    3181                 :             :                 /* Attempt the next fragment only if the current one is
    3182                 :             :                  * completely retransmitted.
    3183                 :             :                  */
    3184       [ + ][ + ]:         400 :                 if (before64(retrans_seq, dfrag->data_seq + dfrag->data_len))
    3185                 :             :                         break;
    3186                 :             : 
    3187       [ + ][ + ]:         397 :                 dfrag = list_is_last(&dfrag->list, &msk->rtx_queue) ?
    3188       [ + ][ + ]:         397 :                                 NULL : list_next_entry(dfrag, list);
    3189       [ - ][ - ]:         182 :                 if (!dfrag)
    3190                 :             :                         break;
    3191                 :             : 
    3192                 :             :                 /* Incoming acks can move snd_una after the current dfrag
    3193                 :             :                  * across loop iterations, if so start again from RTX head.
    3194                 :             :                  */
    3195                 :         182 :                 mptcp_data_lock(sk);
    3196                 :         182 :                 already_acked = !before64(msk->snd_una, dfrag->data_seq +
    3197       [ + ][ + ]:         182 :                                           dfrag->already_sent);
    3198       [ + ][ + ]:         182 :                 if (already_acked) {
    3199                 :          59 :                         __mptcp_clean_una_wakeup(sk);
    3200                 :          59 :                         retrans_seq = msk->snd_una;
    3201                 :          59 :                         dfrag = mptcp_rtx_head(sk);
    3202                 :          59 :                         need_retrans = !!dfrag;
    3203       [ + ][ + ]:         123 :                 } else if (after64(msk->snd_una, retrans_seq)) {
    3204                 :           0 :                         retrans_seq = msk->snd_una;
    3205                 :             :                 }
    3206                 :         182 :                 mptcp_data_unlock(sk);
    3207                 :             :         }
    3208                 :             : 
    3209                 :             :         /* Attempt data-fin retransmission only when the RTX queue is empty. */
    3210       [ + ][ + ]:        5562 :         if (!need_retrans) {
    3211       [ + ][ + ]:        2301 :                 if (mptcp_data_fin_enabled(msk)) {
    3212                 :        1387 :                         struct inet_connection_sock *icsk = inet_csk(sk);
    3213                 :             : 
    3214                 :        1387 :                         WRITE_ONCE(icsk->icsk_retransmits,
    3215                 :             :                                    icsk->icsk_retransmits + 1);
    3216                 :        1387 :                         mptcp_set_datafin_timeout(sk);
    3217                 :        1387 :                         mptcp_send_ack(msk);
    3218                 :        1387 :                         goto reset_timer;
    3219                 :             :                 }
    3220                 :             : 
    3221       [ + ][ + ]:         914 :                 if (!mptcp_send_head(sk))
    3222                 :         818 :                         goto clear_scheduled;
    3223                 :             :         }
    3224                 :             : 
    3225                 :        3357 : reset_timer:
    3226                 :        4744 :         mptcp_check_and_set_pending(sk);
    3227                 :             : 
    3228       [ - ][ + ]:        4744 :         if (!mptcp_rtx_timer_pending(sk))
    3229                 :          57 :                 mptcp_reset_rtx_timer(sk);
    3230                 :             : 
    3231                 :        4687 : clear_scheduled:
    3232                 :             :         /* If no rtx data was available or in case of fallback, there
    3233                 :             :          * could be left-over scheduled subflows; clear them all
    3234                 :             :          * or later xmit could use bad ones
    3235                 :             :          */
    3236       [ + ][ + ]:       14079 :         mptcp_for_each_subflow(msk, subflow)
    3237    [ + ][ +  + ]:        8517 :                 if (READ_ONCE(subflow->scheduled))
    3238                 :        2047 :                         mptcp_subflow_set_scheduled(subflow, false);
    3239                 :        5562 : }
    3240                 :             : 
    3241                 :             : /* schedule the timeout timer for the relevant event: either close timeout
    3242                 :             :  * or mp_fail timeout. The close timeout takes precedence on the mp_fail one
    3243                 :             :  */
    3244                 :        1633 : void mptcp_reset_tout_timer(struct mptcp_sock *msk, unsigned long fail_tout)
    3245                 :             : {
    3246                 :        1633 :         struct sock *sk = (struct sock *)msk;
    3247                 :        1633 :         unsigned long timeout, close_timeout;
    3248                 :             : 
    3249         [ +  - ]:        1633 :         if (!fail_tout && !inet_csk(sk)->icsk_mtup.probe_timestamp)
    3250                 :             :                 return;
    3251                 :             : 
    3252                 :        1633 :         close_timeout = (unsigned long)inet_csk(sk)->icsk_mtup.probe_timestamp -
    3253                 :        1633 :                         tcp_jiffies32;
    3254                 :        1633 :         close_timeout += jiffies + mptcp_close_timeout(sk);
    3255                 :             : 
    3256                 :             :         /* the close timeout takes precedence on the fail one, and here at least one of
    3257                 :             :          * them is active
    3258                 :             :          */
    3259            [ + ]:        1633 :         timeout = inet_csk(sk)->icsk_mtup.probe_timestamp ? close_timeout : fail_tout;
    3260                 :             : 
    3261                 :        1633 :         sk_reset_timer(sk, &inet_csk(sk)->mptcp_tout_timer, timeout);
    3262                 :             : }
    3263                 :             : 
    3264                 :           0 : static void mptcp_mp_fail_no_response(struct mptcp_sock *msk)
    3265                 :             : {
    3266                 :           0 :         struct sock *ssk = msk->first;
    3267                 :           0 :         bool slow;
    3268                 :             : 
    3269            [ # ]:           0 :         if (!ssk)
    3270                 :             :                 return;
    3271                 :             : 
    3272         [ #  # ]:           0 :         pr_debug("MP_FAIL doesn't respond, reset the subflow\n");
    3273                 :             : 
    3274                 :           0 :         slow = lock_sock_fast(ssk);
    3275                 :           0 :         mptcp_subflow_reset(ssk);
    3276                 :           0 :         WRITE_ONCE(mptcp_subflow_ctx(ssk)->fail_tout, 0);
    3277                 :           0 :         unlock_sock_fast(ssk, slow);
    3278                 :             : }
    3279                 :             : 
    3280                 :        5980 : static void mptcp_backlog_purge(struct sock *sk)
    3281                 :             : {
    3282            [ + ]:        5980 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3283                 :        5980 :         struct sk_buff *tmp, *skb;
    3284                 :        5980 :         LIST_HEAD(backlog);
    3285                 :             : 
    3286                 :        5980 :         mptcp_data_lock(sk);
    3287            [ + ]:        5980 :         list_splice_init(&msk->backlog_list, &backlog);
    3288                 :        5980 :         msk->backlog_len = 0;
    3289                 :        5980 :         mptcp_data_unlock(sk);
    3290                 :             : 
    3291            [ - ]:        5980 :         list_for_each_entry_safe(skb, tmp, &backlog, list) {
    3292                 :           0 :                 mptcp_borrow_fwdmem(sk, skb);
    3293                 :           0 :                 kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
    3294                 :             :         }
    3295                 :        5980 :         sk_mem_reclaim(sk);
    3296                 :        5980 : }
    3297                 :             : 
    3298                 :         725 : static void mptcp_do_fastclose(struct sock *sk)
    3299                 :             : {
    3300                 :         725 :         struct mptcp_subflow_context *subflow, *tmp;
    3301            [ + ]:         725 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3302                 :             : 
    3303                 :         725 :         mptcp_set_state(sk, TCP_CLOSE);
    3304                 :         725 :         mptcp_backlog_purge(sk);
    3305                 :         725 :         msk->fastclosing = 1;
    3306                 :             : 
    3307                 :             :         /* Explicitly send the fastclose reset, a plain one after a fallback */
    3308       [ + ][ + ]:        1532 :         mptcp_for_each_subflow_safe(msk, subflow, tmp) {
    3309                 :         807 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    3310                 :             : 
    3311                 :         807 :                 lock_sock(ssk);
    3312                 :             : 
    3313                 :             :                 /* Some subflow socket states don't allow/need a reset.*/
    3314    [ + ][ +  + ]:         807 :                 if ((1 << ssk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
    3315                 :         322 :                         goto unlock;
    3316                 :             : 
    3317                 :         485 :                 subflow->send_fastclose = 1;
    3318                 :             : 
    3319                 :             :                 /* no reset in SYN_SENT, but a close at once, as TCP does */
    3320       [ + ][ + ]:         485 :                 if (ssk->sk_state == TCP_SYN_SENT) {
    3321                 :           6 :                         tcp_set_state(ssk, TCP_CLOSE);
    3322                 :           6 :                         goto unlock;
    3323                 :             :                 }
    3324                 :             : 
    3325                 :             :                 /* Initialize rcv_mss to TCP_MIN_MSS to avoid division by 0
    3326                 :             :                  * issue in __tcp_select_window(), see tcp_disconnect().
    3327                 :             :                  */
    3328                 :         479 :                 inet_csk(ssk)->icsk_ack.rcv_mss = TCP_MIN_MSS;
    3329                 :             : 
    3330                 :         479 :                 tcp_send_active_reset(ssk, SK_RST_REASON_TCP_ABORT_ON_CLOSE);
    3331                 :         807 : unlock:
    3332                 :         807 :                 release_sock(ssk);
    3333                 :             :         }
    3334                 :         725 : }
    3335                 :             : 
    3336                 :       13821 : static void mptcp_worker(struct work_struct *work)
    3337                 :             : {
    3338                 :       13821 :         struct mptcp_sock *msk = container_of(work, struct mptcp_sock, work);
    3339                 :       13821 :         struct sock *sk = (struct sock *)msk;
    3340                 :       13821 :         unsigned long fail_tout;
    3341                 :       13821 :         int state;
    3342                 :             : 
    3343                 :       13821 :         lock_sock(sk);
    3344                 :       13821 :         state = sk->sk_state;
    3345    [ + ][ +  + ]:       13821 :         if (unlikely((1 << state) & (TCPF_CLOSE | TCPF_LISTEN)))
    3346                 :        1189 :                 goto unlock;
    3347                 :             : 
    3348                 :       12632 :         mptcp_check_fastclose(msk);
    3349                 :             : 
    3350                 :       12632 :         mptcp_pm_worker(msk);
    3351                 :             : 
    3352                 :       12632 :         mptcp_check_send_data_fin(sk);
    3353                 :       12632 :         mptcp_check_data_fin_ack(sk);
    3354                 :       12632 :         mptcp_check_data_fin(sk);
    3355                 :             : 
    3356       [ + ][ + ]:       19403 :         if (test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
    3357                 :        1612 :                 __mptcp_close_subflow(sk);
    3358                 :             : 
    3359 [ +  + ][ +  + ]:       12632 :         if (mptcp_close_tout_expired(sk) && mptcp_orphan_keep(sk)) {
    3360                 :           0 :                 mptcp_start_tout_timer(sk);
    3361                 :           0 :                 __mptcp_push_pending(sk, 0);
    3362                 :             :         }
    3363                 :             : 
    3364                 :             :         /* TCP will close the subflow, as with its own orphans */
    3365 [ +  + ][ +  + ]:       12632 :         if (mptcp_close_tout_expired(sk) && mptcp_orphan_handover(sk))
    3366                 :          21 :                 mptcp_set_state(sk, TCP_CLOSE);
    3367                 :             : 
    3368       [ + ][ + ]:       12632 :         if (mptcp_close_tout_expired(sk)) {
    3369                 :         294 :                 struct mptcp_subflow_context *subflow, *tmp;
    3370                 :             : 
    3371                 :         294 :                 mptcp_do_fastclose(sk);
    3372       [ + ][ + ]:         610 :                 mptcp_for_each_subflow_safe(msk, subflow, tmp)
    3373                 :         316 :                         __mptcp_close_ssk(sk, subflow->tcp_sock, subflow, 0);
    3374                 :         294 :                 WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
    3375                 :         294 :                 mptcp_close_wake_up(sk);
    3376                 :             :         }
    3377                 :             : 
    3378 [ +  + ][ +  + ]:       12632 :         if (sock_flag(sk, SOCK_DEAD) && sk->sk_state == TCP_CLOSE) {
    3379                 :        1374 :                 __mptcp_destroy_sock(sk);
    3380                 :        1374 :                 goto unlock;
    3381                 :             :         }
    3382                 :             : 
    3383       [ + ][ + ]:       17321 :         if (test_and_clear_bit(MPTCP_WORK_RTX, &msk->flags))
    3384                 :        5088 :                 __mptcp_retrans(sk);
    3385                 :             : 
    3386 [ -  - ][ -  - ]:       11258 :         fail_tout = msk->first ? READ_ONCE(mptcp_subflow_ctx(msk->first)->fail_tout) : 0;
    3387 [ -  - ][ -  - ]:       11258 :         if (fail_tout && time_after(jiffies, fail_tout))
    3388                 :           0 :                 mptcp_mp_fail_no_response(msk);
    3389                 :             : 
    3390                 :           0 : unlock:
    3391                 :       13821 :         release_sock(sk);
    3392                 :       13821 :         sock_put(sk);
    3393                 :       13821 : }
    3394                 :             : 
    3395                 :        5202 : static void __mptcp_init_sock(struct sock *sk)
    3396                 :             : {
    3397                 :        5202 :         struct inet_connection_sock *icsk = inet_csk(sk);
    3398            [ + ]:        5202 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3399            [ + ]:        5202 :         struct net *net = sock_net(sk);
    3400                 :             : 
    3401            [ + ]:        5202 :         INIT_LIST_HEAD(&msk->conn_list);
    3402                 :        5202 :         INIT_LIST_HEAD(&msk->join_list);
    3403                 :        5202 :         INIT_LIST_HEAD(&msk->rtx_queue);
    3404                 :        5202 :         INIT_LIST_HEAD(&msk->backlog_list);
    3405            [ + ]:        5202 :         INIT_WORK(&msk->work, mptcp_worker);
    3406                 :        5202 :         msk->out_of_order_queue = RB_ROOT;
    3407                 :        5202 :         msk->first_pending = NULL;
    3408                 :             : 
    3409                 :             :         /* msk does not go through tcp_init_sock(); seed RTO bounds. */
    3410                 :       10404 :         icsk->icsk_rto_min =
    3411       [ + ][ + ]:        5202 :                 usecs_to_jiffies(READ_ONCE(net->ipv4.sysctl_tcp_rto_min_us));
    3412                 :       10404 :         icsk->icsk_rto_max =
    3413       [ + ][ + ]:        5202 :                 msecs_to_jiffies(READ_ONCE(net->ipv4.sysctl_tcp_rto_max_ms));
    3414                 :        5202 :         msk->timer_ival = icsk->icsk_rto_min;
    3415                 :        5202 :         msk->scaling_ratio = TCP_DEFAULT_SCALING_RATIO;
    3416                 :        5202 :         msk->backlog_len = 0;
    3417                 :        5202 :         mptcp_init_rtt_est(msk);
    3418                 :             : 
    3419                 :        5202 :         WRITE_ONCE(msk->first, NULL);
    3420                 :        5202 :         inet_csk(sk)->icsk_sync_mss = mptcp_sync_mss;
    3421                 :        5202 :         WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk)));
    3422                 :        5202 :         msk->allow_infinite_fallback = true;
    3423                 :        5202 :         msk->allow_subflows = true;
    3424                 :        5202 :         msk->recovery = false;
    3425                 :        5202 :         msk->subflow_id = 1;
    3426                 :        5202 :         msk->last_data_sent = tcp_jiffies32;
    3427                 :        5202 :         msk->last_data_recv = tcp_jiffies32;
    3428                 :        5202 :         msk->last_ack_recv = tcp_jiffies32;
    3429                 :             : 
    3430                 :        5202 :         mptcp_pm_data_init(msk);
    3431                 :        5202 :         spin_lock_init(&msk->fallback_lock);
    3432                 :             : 
    3433                 :             :         /* re-use the csk retrans timer for MPTCP-level retrans */
    3434                 :        5202 :         timer_setup(&sk->mptcp_retransmit_timer, mptcp_retransmit_timer, 0);
    3435                 :        5202 :         timer_setup(&msk->sk.mptcp_tout_timer, mptcp_tout_timer, 0);
    3436                 :        5202 : }
    3437                 :             : 
    3438                 :        3644 : static void mptcp_ca_reset(struct sock *sk)
    3439                 :             : {
    3440                 :        3644 :         struct inet_connection_sock *icsk = inet_csk(sk);
    3441                 :             : 
    3442                 :        3644 :         tcp_assign_congestion_control(sk);
    3443            [ + ]:        3644 :         strscpy(mptcp_sk(sk)->ca_name, icsk->icsk_ca_ops->name,
    3444                 :             :                 sizeof(mptcp_sk(sk)->ca_name));
    3445                 :             : 
    3446                 :             :         /* no need to keep a reference to the ops, the name will suffice */
    3447                 :        3644 :         tcp_cleanup_congestion_control(sk);
    3448                 :        3644 :         icsk->icsk_ca_ops = NULL;
    3449                 :        3644 : }
    3450                 :             : 
    3451                 :        3542 : static int mptcp_init_sock(struct sock *sk)
    3452                 :             : {
    3453                 :        3542 :         struct net *net = sock_net(sk);
    3454                 :        3542 :         int ret;
    3455                 :             : 
    3456                 :        3542 :         __mptcp_init_sock(sk);
    3457                 :             : 
    3458       [ + ][ + ]:        3542 :         if (!mptcp_is_enabled(net))
    3459                 :             :                 return -ENOPROTOOPT;
    3460                 :             : 
    3461 [ +  - ][ +  - ]:        3532 :         if (unlikely(!net->mib.mptcp_statistics) && !mptcp_mib_alloc(net))
    3462                 :             :                 return -ENOMEM;
    3463                 :             : 
    3464                 :        3532 :         rcu_read_lock();
    3465       [ + ][ + ]:        3532 :         ret = mptcp_init_sched(mptcp_sk(sk),
    3466                 :             :                                mptcp_sched_find(mptcp_get_scheduler(net)));
    3467                 :        3532 :         rcu_read_unlock();
    3468       [ - ][ - ]:        3532 :         if (ret)
    3469                 :             :                 return ret;
    3470                 :             : 
    3471                 :        3532 :         set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags);
    3472                 :             : 
    3473                 :             :         /* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will
    3474                 :             :          * propagate the correct value
    3475                 :             :          */
    3476                 :        3532 :         mptcp_ca_reset(sk);
    3477                 :             : 
    3478                 :        3532 :         sk_sockets_allocated_inc(sk);
    3479                 :        3532 :         sk->sk_rcvbuf = READ_ONCE(net->ipv4.sysctl_tcp_rmem[1]);
    3480                 :        3532 :         sk->sk_sndbuf = READ_ONCE(net->ipv4.sysctl_tcp_wmem[1]);
    3481                 :        3532 :         sk->sk_write_space = sk_stream_write_space;
    3482                 :             : 
    3483                 :        3532 :         return 0;
    3484                 :             : }
    3485                 :             : 
    3486                 :        5255 : static void __mptcp_clear_xmit(struct sock *sk)
    3487                 :             : {
    3488            [ + ]:        5255 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3489                 :        5255 :         struct mptcp_data_frag *dtmp, *dfrag;
    3490                 :             : 
    3491                 :        5255 :         msk->first_pending = NULL;
    3492            [ + ]:        5407 :         list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list)
    3493                 :         152 :                 dfrag_clear(sk, dfrag);
    3494                 :        5255 : }
    3495                 :             : 
    3496                 :        3759 : void mptcp_cancel_work(struct sock *sk)
    3497                 :             : {
    3498            [ + ]:        3759 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3499                 :             : 
    3500            [ + ]:        3759 :         if (cancel_work_sync(&msk->work))
    3501                 :          45 :                 __sock_put(sk);
    3502                 :        3759 : }
    3503                 :             : 
    3504                 :        4103 : void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how)
    3505                 :             : {
    3506                 :        4103 :         lock_sock(ssk);
    3507                 :             : 
    3508      [ -  +  + ]:        4103 :         switch (ssk->sk_state) {
    3509                 :           0 :         case TCP_LISTEN:
    3510            [ # ]:           0 :                 if (!(how & RCV_SHUTDOWN))
    3511                 :             :                         break;
    3512                 :          18 :                 fallthrough;
    3513                 :             :         case TCP_SYN_SENT:
    3514            [ + ]:          18 :                 WARN_ON_ONCE(tcp_disconnect(ssk, O_NONBLOCK));
    3515                 :             :                 break;
    3516                 :        4085 :         default:
    3517         [ +  + ]:        4085 :                 if (__mptcp_check_fallback(mptcp_sk(sk))) {
    3518         [ -  - ]:         183 :                         pr_debug("Fallback\n");
    3519                 :         183 :                         ssk->sk_shutdown |= how;
    3520                 :         183 :                         tcp_shutdown(ssk, how);
    3521                 :             : 
    3522                 :             :                         /* simulate the data_fin ack reception to let the state
    3523                 :             :                          * machine move forward
    3524                 :             :                          */
    3525         [ +  + ]:         183 :                         WRITE_ONCE(mptcp_sk(sk)->snd_una, mptcp_sk(sk)->snd_nxt);
    3526                 :         183 :                         mptcp_schedule_work(sk);
    3527                 :             :                 } else {
    3528         [ -  - ]:        3902 :                         pr_debug("Sending DATA_FIN on subflow %p\n", ssk);
    3529                 :        3902 :                         tcp_send_ack(ssk);
    3530            [ + ]:        3902 :                         if (!mptcp_rtx_timer_pending(sk))
    3531                 :        1913 :                                 mptcp_reset_rtx_timer(sk);
    3532                 :             :                 }
    3533                 :             :                 break;
    3534                 :             :         }
    3535                 :             : 
    3536                 :        4103 :         release_sock(ssk);
    3537                 :        4103 : }
    3538                 :             : 
    3539                 :       24194 : void mptcp_set_state(struct sock *sk, int state)
    3540                 :             : {
    3541                 :       25241 :         int oldstate = sk->sk_state;
    3542                 :             : 
    3543   [ +  +  +  - ]:       24168 :         switch (state) {
           [ +  +  +  - ]
    3544                 :        3324 :         case TCP_ESTABLISHED:
    3545       [ - ][ - ]:        3324 :                 if (oldstate != TCP_ESTABLISHED)
    3546       [ - ][ - ]:        3324 :                         MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
    3547                 :             :                 break;
    3548                 :             :         case TCP_CLOSE_WAIT:
    3549                 :             :                 /* Unlike TCP, MPTCP sk would not have the TCP_SYN_RECV state:
    3550                 :             :                  * MPTCP "accepted" sockets will be created later on. So no
    3551                 :             :                  * transition from TCP_SYN_RECV to TCP_CLOSE_WAIT.
    3552                 :             :                  */
    3553                 :             :                 break;
    3554                 :       10526 :         case TCP_CLOSE:
    3555       [ + ][ + ]:       10526 :                 clear_bit(MPTCP_RTX_ENABLED, &mptcp_sk(sk)->flags);
    3556                 :       20844 :                 fallthrough;
    3557                 :       20844 :         default:
    3558       [ + ][ + ]:       20844 :                 if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
    3559       [ - ][ - ]:        3324 :                         MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
    3560                 :             :         }
    3561                 :             : 
    3562                 :       25241 :         inet_sk_state_store(sk, state);
    3563                 :        1073 : }
    3564                 :             : 
    3565                 :             : static const unsigned char new_state[16] = {
    3566                 :             :         /* current state:     new state:      action:   */
    3567                 :             :         [0 /* (Invalid) */] = TCP_CLOSE,
    3568                 :             :         [TCP_ESTABLISHED]   = TCP_FIN_WAIT1 | TCP_ACTION_FIN,
    3569                 :             :         [TCP_SYN_SENT]      = TCP_CLOSE,
    3570                 :             :         [TCP_SYN_RECV]      = TCP_FIN_WAIT1 | TCP_ACTION_FIN,
    3571                 :             :         [TCP_FIN_WAIT1]     = TCP_FIN_WAIT1,
    3572                 :             :         [TCP_FIN_WAIT2]     = TCP_FIN_WAIT2,
    3573                 :             :         [TCP_TIME_WAIT]     = TCP_CLOSE,        /* should not happen ! */
    3574                 :             :         [TCP_CLOSE]         = TCP_CLOSE,
    3575                 :             :         [TCP_CLOSE_WAIT]    = TCP_LAST_ACK  | TCP_ACTION_FIN,
    3576                 :             :         [TCP_LAST_ACK]      = TCP_LAST_ACK,
    3577                 :             :         [TCP_LISTEN]        = TCP_CLOSE,
    3578                 :             :         [TCP_CLOSING]       = TCP_CLOSING,
    3579                 :             :         [TCP_NEW_SYN_RECV]  = TCP_CLOSE,        /* should not happen ! */
    3580                 :             : };
    3581                 :             : 
    3582                 :        3514 : static int mptcp_close_state(struct sock *sk)
    3583                 :             : {
    3584                 :        3514 :         int next = (int)new_state[sk->sk_state];
    3585                 :        3514 :         int ns = next & TCP_STATE_MASK;
    3586                 :             : 
    3587                 :        3514 :         mptcp_set_state(sk, ns);
    3588                 :             : 
    3589                 :        3514 :         return next & TCP_ACTION_FIN;
    3590                 :             : }
    3591                 :             : 
    3592                 :      294552 : static void mptcp_check_send_data_fin(struct sock *sk)
    3593                 :             : {
    3594                 :      294552 :         struct mptcp_subflow_context *subflow;
    3595            [ + ]:      294552 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3596                 :             : 
    3597         [ -  - ]:      294552 :         pr_debug("msk=%p snd_data_fin_enable=%d pending=%d snd_nxt=%llu write_seq=%llu\n",
              [ -  -  - ]
    3598                 :             :                  msk, msk->snd_data_fin_enable, !!mptcp_send_head(sk),
    3599                 :             :                  msk->snd_nxt, msk->write_seq);
    3600                 :             : 
    3601                 :             :         /* we still need to enqueue subflows or not really shutting down,
    3602                 :             :          * skip this
    3603                 :             :          */
    3604      [ +  +  + ]:      297571 :         if (!msk->snd_data_fin_enable || msk->snd_nxt + 1 != msk->write_seq ||
           [ +  +  +  + ]
    3605                 :        3019 :             mptcp_send_head(sk))
    3606                 :      291533 :                 return;
    3607                 :             : 
    3608                 :        3019 :         WRITE_ONCE(msk->snd_nxt, msk->write_seq);
    3609                 :             : 
    3610                 :             :         /* an orphan's close timeout is for the DATA_FIN exchange */
    3611       [ + ][ + ]:        3019 :         if (sock_flag(sk, SOCK_DEAD))
    3612                 :         170 :                 mptcp_start_tout_timer(sk);
    3613                 :             : 
    3614       [ + ][ + ]:        6924 :         mptcp_for_each_subflow(msk, subflow) {
    3615                 :        3905 :                 struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
    3616                 :             : 
    3617                 :        3905 :                 mptcp_subflow_shutdown(sk, tcp_sk, SEND_SHUTDOWN);
    3618                 :             :         }
    3619                 :             : }
    3620                 :             : 
    3621                 :        3025 : static void __mptcp_wr_shutdown(struct sock *sk)
    3622                 :             : {
    3623            [ + ]:        3025 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3624                 :             : 
    3625         [ -  - ]:        3025 :         pr_debug("msk=%p snd_data_fin_enable=%d shutdown=%x state=%d pending=%d\n",
              [ -  -  - ]
    3626                 :             :                  msk, msk->snd_data_fin_enable, sk->sk_shutdown, sk->sk_state,
    3627                 :             :                  !!mptcp_send_head(sk));
    3628                 :             : 
    3629                 :             :         /* will be ignored by fallback sockets */
    3630                 :        3025 :         WRITE_ONCE(msk->write_seq, msk->write_seq + 1);
    3631                 :        3025 :         WRITE_ONCE(msk->snd_data_fin_enable, 1);
    3632                 :             : 
    3633                 :        3025 :         mptcp_check_send_data_fin(sk);
    3634                 :        3025 : }
    3635                 :             : 
    3636                 :        5133 : static void __mptcp_destroy_sock(struct sock *sk)
    3637                 :             : {
    3638            [ + ]:        5133 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3639                 :             : 
    3640         [ -  - ]:        5133 :         pr_debug("msk=%p\n", msk);
    3641                 :             : 
    3642                 :        5133 :         might_sleep();
    3643                 :             : 
    3644                 :        5133 :         mptcp_stop_rtx_timer(sk);
    3645                 :        5133 :         sk_stop_timer(sk, &inet_csk(sk)->mptcp_tout_timer);
    3646                 :        5133 :         msk->pm.status = 0;
    3647                 :        5133 :         mptcp_release_sched(msk);
    3648                 :             : 
    3649                 :        5133 :         sk->sk_prot->destroy(sk);
    3650                 :             : 
    3651                 :        5133 :         sk_stream_kill_queues(sk);
    3652                 :        5133 :         xfrm_sk_free_policy(sk);
    3653                 :             : 
    3654       [ + ][ + ]:        7716 :         if (test_and_clear_bit(MPTCP_ORPHAN_COUNTED, &msk->flags))
    3655                 :        1374 :                 tcp_orphan_count_dec();
    3656                 :             : 
    3657                 :        5133 :         sock_put(sk);
    3658                 :        5133 : }
    3659                 :             : 
    3660                 :          42 : void __mptcp_unaccepted_force_close(struct sock *sk)
    3661                 :             : {
    3662                 :          42 :         sock_set_flag(sk, SOCK_DEAD);
    3663                 :          42 :         mptcp_do_fastclose(sk);
    3664                 :          42 :         __mptcp_destroy_sock(sk);
    3665                 :          42 : }
    3666                 :             : 
    3667                 :           0 : static __poll_t mptcp_check_readable(struct sock *sk)
    3668                 :             : {
    3669            [ + ]:     1012689 :         return mptcp_epollin_ready(sk) ? EPOLLIN | EPOLLRDNORM : 0;
    3670                 :             : }
    3671                 :             : 
    3672                 :        3479 : static void mptcp_check_listen_stop(struct sock *sk)
    3673                 :             : {
    3674                 :        3479 :         struct sock *ssk;
    3675                 :             : 
    3676       [ + ][ + ]:        3479 :         if (inet_sk_state_load(sk) != TCP_LISTEN)
    3677                 :             :                 return;
    3678                 :             : 
    3679                 :        1851 :         sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
    3680       [ + ][ + ]:        1851 :         ssk = mptcp_sk(sk)->first;
    3681 [ -  + ][ -  + ]:        3702 :         if (WARN_ON_ONCE(!ssk || inet_sk_state_load(ssk) != TCP_LISTEN))
    3682                 :           0 :                 return;
    3683                 :             : 
    3684                 :        1851 :         lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
    3685                 :        1851 :         tcp_set_state(ssk, TCP_CLOSE);
    3686                 :        1851 :         mptcp_subflow_queue_clean(sk, ssk);
    3687                 :        1851 :         inet_csk_listen_stop(ssk);
    3688                 :        1851 :         mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CLOSED);
    3689                 :        1851 :         release_sock(ssk);
    3690                 :             : }
    3691                 :             : 
    3692                 :        5150 : bool __mptcp_close(struct sock *sk, long timeout)
    3693                 :             : {
    3694                 :        5150 :         struct mptcp_subflow_context *subflow;
    3695            [ + ]:        5150 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3696                 :        5150 :         bool do_cancel_work = false;
    3697                 :        5150 :         int subflows_alive = 0;
    3698                 :             : 
    3699                 :        5150 :         WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
    3700                 :             : 
    3701    [ + ][ +  + ]:        5150 :         if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
    3702                 :        3367 :                 mptcp_check_listen_stop(sk);
    3703                 :        3367 :                 mptcp_set_state(sk, TCP_CLOSE);
    3704                 :        3367 :                 goto cleanup;
    3705                 :             :         }
    3706                 :             : 
    3707      [ +  -  + ]:        3301 :         if (mptcp_data_avail(msk) || timeout < 0 ||
              [ +  -  + ]
    3708       [ - ][ - ]:        1530 :             (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime)) {
    3709                 :             :                 /* If the msk has read data, or the caller explicitly ask it,
    3710                 :             :                  * do the MPTCP equivalent of TCP reset, aka MPTCP fastclose
    3711                 :             :                  */
    3712                 :         277 :                 mptcp_do_fastclose(sk);
    3713                 :         277 :                 timeout = 0;
    3714       [ + ][ + ]:        1506 :         } else if (mptcp_close_state(sk)) {
    3715                 :        1169 :                 __mptcp_wr_shutdown(sk);
    3716                 :             :         }
    3717                 :             : 
    3718                 :        1783 :         sk_stream_wait_close(sk, timeout);
    3719                 :             : 
    3720                 :        5150 : cleanup:
    3721                 :             :         /* orphan all the subflows */
    3722       [ + ][ + ]:       10835 :         mptcp_for_each_subflow(msk, subflow) {
    3723                 :        5685 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    3724                 :        5685 :                 bool slow = lock_sock_fast_nested(ssk);
    3725                 :             : 
    3726                 :        5685 :                 subflows_alive += ssk->sk_state != TCP_CLOSE;
    3727                 :             : 
    3728                 :             :                 /* since the close timeout takes precedence on the fail one,
    3729                 :             :                  * cancel the latter
    3730                 :             :                  */
    3731       [ + ][ + ]:        5685 :                 if (ssk == msk->first)
    3732                 :        5132 :                         subflow->fail_tout = 0;
    3733                 :             : 
    3734                 :             :                 /* detach from the parent socket, but allow data_ready to
    3735                 :             :                  * push incoming data into the mptcp stack, to properly ack it
    3736                 :             :                  */
    3737                 :        5685 :                 ssk->sk_socket = NULL;
    3738                 :        5685 :                 ssk->sk_wq = NULL;
    3739                 :        5685 :                 unlock_sock_fast(ssk, slow);
    3740                 :             :         }
    3741                 :        5150 :         sock_orphan(sk);
    3742                 :             : 
    3743                 :             :         /* all the subflows are closed, only timeout can change the msk
    3744                 :             :          * state, let's not keep resources busy for no reasons
    3745                 :             :          */
    3746       [ + ][ + ]:        5150 :         if (subflows_alive == 0) {
    3747                 :        2889 :                 mptcp_set_state(sk, TCP_CLOSE);
    3748       [ + ][ + ]:        2261 :         } else if (sk->sk_state != TCP_CLOSE) {
    3749                 :             :                 /* as TCP orphans: counted, and limited */
    3750                 :        1433 :                 tcp_orphan_count_inc();
    3751                 :        1433 :                 set_bit(MPTCP_ORPHAN_COUNTED, &msk->flags);
    3752       [ + ][ + ]:        1433 :                 if (mptcp_orphan_oom(sk))
    3753                 :           0 :                         mptcp_do_fastclose(sk);
    3754                 :             :         }
    3755                 :             : 
    3756                 :        5150 :         sock_hold(sk);
    3757 [ -  - ][ -  - ]:        5150 :         pr_debug("msk=%p state=%d\n", sk, sk->sk_state);
    3758                 :        5150 :         mptcp_pm_connection_closed(msk);
    3759                 :             : 
    3760       [ + ][ + ]:        5150 :         if (sk->sk_state == TCP_CLOSE) {
    3761                 :        3717 :                 __mptcp_destroy_sock(sk);
    3762                 :        3717 :                 do_cancel_work = true;
    3763                 :             :         } else {
    3764                 :        1433 :                 mptcp_start_tout_timer(sk);
    3765                 :             :         }
    3766                 :             : 
    3767                 :        5150 :         return do_cancel_work;
    3768                 :             : }
    3769                 :             : 
    3770                 :        5150 : static void mptcp_close(struct sock *sk, long timeout)
    3771                 :             : {
    3772                 :        5150 :         bool do_cancel_work;
    3773                 :             : 
    3774                 :        5150 :         lock_sock(sk);
    3775                 :             : 
    3776                 :        5150 :         do_cancel_work = __mptcp_close(sk, timeout);
    3777                 :        5150 :         release_sock(sk);
    3778            [ + ]:        5150 :         if (do_cancel_work)
    3779                 :        3717 :                 mptcp_cancel_work(sk);
    3780                 :             : 
    3781                 :        5150 :         sock_put(sk);
    3782                 :        5150 : }
    3783                 :             : 
    3784                 :        6988 : static void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)
    3785                 :             : {
    3786                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
    3787            [ - ]:        6988 :         const struct ipv6_pinfo *ssk6 = inet6_sk(ssk);
    3788            [ - ]:        6988 :         struct ipv6_pinfo *msk6 = inet6_sk(msk);
    3789                 :             : 
    3790                 :        6988 :         msk->sk_v6_daddr = ssk->sk_v6_daddr;
    3791                 :        6988 :         msk->sk_v6_rcv_saddr = ssk->sk_v6_rcv_saddr;
    3792                 :             : 
    3793       [ + ][ + ]:        6988 :         if (msk6 && ssk6) {
    3794                 :        3152 :                 msk6->saddr = ssk6->saddr;
    3795                 :        3152 :                 msk6->flow_label = ssk6->flow_label;
    3796                 :             :         }
    3797                 :             : #endif
    3798                 :             : 
    3799                 :        6988 :         inet_sk(msk)->inet_num = inet_sk(ssk)->inet_num;
    3800                 :        6988 :         inet_sk(msk)->inet_dport = inet_sk(ssk)->inet_dport;
    3801                 :        6988 :         inet_sk(msk)->inet_sport = inet_sk(ssk)->inet_sport;
    3802                 :        6988 :         inet_sk(msk)->inet_daddr = inet_sk(ssk)->inet_daddr;
    3803                 :        6988 :         inet_sk(msk)->inet_saddr = inet_sk(ssk)->inet_saddr;
    3804                 :        6988 :         inet_sk(msk)->inet_rcv_saddr = inet_sk(ssk)->inet_rcv_saddr;
    3805                 :        6988 : }
    3806                 :             : 
    3807                 :        5255 : static void mptcp_destroy_common(struct mptcp_sock *msk)
    3808                 :             : {
    3809                 :        5255 :         struct mptcp_subflow_context *subflow, *tmp;
    3810                 :        5255 :         struct sock *sk = (struct sock *)msk;
    3811                 :             : 
    3812                 :        5255 :         __mptcp_clear_xmit(sk);
    3813                 :        5255 :         mptcp_backlog_purge(sk);
    3814                 :             : 
    3815                 :             :         /* join list will be eventually flushed (with rst) at sock lock release time */
    3816            [ + ]:       10910 :         mptcp_for_each_subflow_safe(msk, subflow, tmp)
    3817                 :        5655 :                 __mptcp_close_ssk(sk, mptcp_subflow_tcp_sock(subflow), subflow, 0);
    3818                 :             : 
    3819                 :        5255 :         __skb_queue_purge(&sk->sk_receive_queue);
    3820                 :        5255 :         skb_rbtree_purge(&msk->out_of_order_queue);
    3821                 :             : 
    3822                 :             :         /* move all the rx fwd alloc into the sk_mem_reclaim_final in
    3823                 :             :          * inet_sock_destruct() will dispose it
    3824                 :             :          */
    3825                 :        5255 :         mptcp_token_destroy(msk);
    3826                 :        5255 :         mptcp_pm_destroy(msk);
    3827                 :        5255 : }
    3828                 :             : 
    3829                 :         112 : static int mptcp_disconnect(struct sock *sk, int flags)
    3830                 :             : {
    3831                 :         112 :         struct inet_connection_sock *icsk = inet_csk(sk);
    3832            [ + ]:         112 :         struct mptcp_sock *msk = mptcp_sk(sk);
    3833                 :             : 
    3834                 :             :         /* We are on the fastopen error path. We can't call straight into the
    3835                 :             :          * subflows cleanup code due to lock nesting (we are already under
    3836                 :             :          * msk->firstsocket lock).
    3837                 :             :          */
    3838       [ - ][ - ]:         112 :         if (msk->fastopening)
    3839                 :             :                 return -EBUSY;
    3840                 :             : 
    3841                 :         112 :         mptcp_check_listen_stop(sk);
    3842                 :         112 :         mptcp_set_state(sk, TCP_CLOSE);
    3843                 :         112 :         inet_clear_bit(DEFER_CONNECT, sk);
    3844                 :             : 
    3845                 :             :         /* The later subflow close can not kick again the tout timer,
    3846                 :             :          * as the msk is already in closed status.
    3847                 :             :          */
    3848                 :         112 :         msk->timer_ival = icsk->icsk_rto_min;
    3849                 :         112 :         sk_stop_timer_sync(sk, &sk->mptcp_retransmit_timer);
    3850                 :         112 :         icsk->icsk_mtup.probe_timestamp = 0;
    3851                 :         112 :         sk_stop_timer_sync(sk, &icsk->mptcp_tout_timer);
    3852                 :             : 
    3853                 :         112 :         mptcp_pm_connection_closed(msk);
    3854                 :             : 
    3855                 :             :         /* msk->subflow is still intact, the following will not free the first
    3856                 :             :          * subflow
    3857                 :             :          */
    3858                 :         112 :         mptcp_do_fastclose(sk);
    3859                 :         112 :         mptcp_destroy_common(msk);
    3860                 :             : 
    3861                 :             :         /* The first subflow is already in TCP_CLOSE status, the following
    3862                 :             :          * can't overlap with a fallback anymore
    3863                 :             :          */
    3864                 :         112 :         spin_lock_bh(&msk->fallback_lock);
    3865                 :         112 :         msk->allow_subflows = true;
    3866                 :         112 :         msk->allow_infinite_fallback = true;
    3867                 :         112 :         WRITE_ONCE(msk->flags, 0);
    3868                 :         112 :         spin_unlock_bh(&msk->fallback_lock);
    3869                 :             : 
    3870                 :         112 :         msk->cb_flags = 0;
    3871                 :         112 :         msk->recovery = false;
    3872                 :         112 :         WRITE_ONCE(msk->can_ack, false);
    3873                 :         112 :         WRITE_ONCE(msk->fully_established, false);
    3874                 :         112 :         WRITE_ONCE(msk->rcv_data_fin, false);
    3875                 :         112 :         WRITE_ONCE(msk->snd_data_fin_enable, false);
    3876                 :         112 :         WRITE_ONCE(msk->rcv_fastclose, false);
    3877                 :         112 :         WRITE_ONCE(msk->use_64bit_ack, false);
    3878                 :         112 :         WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk)));
    3879                 :         112 :         mptcp_pm_data_reset(msk);
    3880                 :         112 :         mptcp_ca_reset(sk);
    3881                 :         112 :         msk->bytes_consumed = 0;
    3882                 :         112 :         msk->bytes_acked = 0;
    3883                 :         112 :         msk->bytes_received = 0;
    3884                 :         112 :         msk->bytes_sent = 0;
    3885                 :         112 :         msk->bytes_retrans = 0;
    3886                 :         112 :         msk->rcvspace_init = 0;
    3887                 :         112 :         msk->fastclosing = 0;
    3888                 :         112 :         mptcp_init_rtt_est(msk);
    3889                 :             : 
    3890                 :             :         /* for fallback's sake */
    3891                 :         112 :         WRITE_ONCE(msk->ack_seq, 0);
    3892                 :         112 :         atomic64_set(&msk->rcv_wnd_sent, 0);
    3893                 :             : 
    3894                 :         112 :         WRITE_ONCE(sk->sk_shutdown, 0);
    3895                 :         112 :         sock_reset_flag(sk, SOCK_DONE);
    3896                 :         112 :         sk_error_report(sk);
    3897                 :         112 :         return 0;
    3898                 :             : }
    3899                 :             : 
    3900                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
    3901                 :         802 : static struct ipv6_pinfo *mptcp_inet6_sk(const struct sock *sk)
    3902                 :             : {
    3903            [ + ]:         802 :         struct mptcp6_sock *msk6 = container_of(mptcp_sk(sk), struct mptcp6_sock, msk);
    3904                 :             : 
    3905                 :         802 :         return &msk6->np;
    3906                 :             : }
    3907                 :             : 
    3908                 :         802 : static void mptcp_copy_ip6_options(struct sock *newsk, const struct sock *sk)
    3909                 :             : {
    3910            [ - ]:         802 :         const struct ipv6_pinfo *np = inet6_sk(sk);
    3911                 :         802 :         struct ipv6_txoptions *opt;
    3912                 :         802 :         struct ipv6_pinfo *newnp;
    3913                 :             : 
    3914            [ - ]:         802 :         newnp = inet6_sk(newsk);
    3915                 :             : 
    3916                 :             :         /* The IPv4 options belong to the listener, which frees them */
    3917                 :         802 :         RCU_INIT_POINTER(inet_sk(newsk)->inet_opt, NULL);
    3918                 :             : 
    3919                 :         802 :         rcu_read_lock();
    3920   [ -  +  -  -  :         802 :         opt = rcu_dereference(np->opt);
                      - ]
    3921       [ - ][ - ]:         802 :         if (opt) {
    3922                 :           0 :                 opt = ipv6_dup_options(newsk, opt);
    3923       [ # ][ # ]:           0 :                 if (!opt)
    3924       [ # ][ # ]:           0 :                         net_warn_ratelimited("%s: Failed to copy ip6 options\n", __func__);
    3925                 :             :         }
    3926                 :         802 :         RCU_INIT_POINTER(newnp->opt, opt);
    3927                 :         802 :         rcu_read_unlock();
    3928                 :         802 : }
    3929                 :             : #endif
    3930                 :             : 
    3931                 :         858 : static void mptcp_copy_ip_options(struct sock *newsk, const struct sock *sk)
    3932                 :             : {
    3933                 :         858 :         struct ip_options_rcu *inet_opt, *newopt = NULL;
    3934                 :         858 :         const struct inet_sock *inet = inet_sk(sk);
    3935                 :         858 :         struct inet_sock *newinet;
    3936                 :             : 
    3937                 :         858 :         newinet = inet_sk(newsk);
    3938                 :             : 
    3939                 :         858 :         rcu_read_lock();
    3940   [ -  +  -  -  :         858 :         inet_opt = rcu_dereference(inet->inet_opt);
                      - ]
    3941       [ - ][ - ]:         858 :         if (inet_opt) {
    3942                 :           0 :                 newopt = sock_kmemdup(newsk, inet_opt, sizeof(*inet_opt) +
    3943                 :           0 :                                       inet_opt->opt.optlen, GFP_ATOMIC);
    3944       [ # ][ # ]:           0 :                 if (!newopt)
    3945       [ # ][ # ]:           0 :                         net_warn_ratelimited("%s: Failed to copy ip options\n", __func__);
    3946                 :             :         }
    3947                 :         858 :         RCU_INIT_POINTER(newinet->inet_opt, newopt);
    3948                 :         858 :         rcu_read_unlock();
    3949                 :         858 : }
    3950                 :             : 
    3951                 :           0 : static void mptcp_sk_clone_destroy(struct sock *nsk)
    3952                 :             : {
    3953            [ # ]:           0 :         struct mptcp_sock *msk = mptcp_sk(nsk);
    3954                 :             : 
    3955                 :           0 :         mptcp_release_sched(msk);
    3956                 :           0 :         mptcp_set_state(nsk, TCP_CLOSE);
    3957                 :             :         /* inet_csk_prepare_forced_close() clears TCP sock_ops state via
    3958                 :             :          * tcp_sk(), but nsk is an MPTCP master socket; keep the inet-level
    3959                 :             :          * destroy preparation here.
    3960                 :             :          */
    3961                 :           0 :         bh_unlock_sock(nsk);
    3962                 :           0 :         sock_put(nsk);
    3963                 :           0 :         sock_set_flag(nsk, SOCK_DEAD);
    3964                 :           0 :         tcp_orphan_count_inc();
    3965                 :           0 :         inet_sk(nsk)->inet_num = 0;
    3966                 :           0 :         inet_csk_destroy_sock(nsk);
    3967                 :           0 : }
    3968                 :             : 
    3969                 :        1660 : struct sock *mptcp_sk_clone_init(const struct sock *sk,
    3970                 :             :                                  const struct mptcp_options_received *mp_opt,
    3971                 :             :                                  struct sock *ssk,
    3972                 :             :                                  struct request_sock *req)
    3973                 :             : {
    3974                 :        1660 :         struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
    3975                 :        1660 :         struct sock *nsk = sk_clone_lock(sk, GFP_ATOMIC);
    3976                 :        1660 :         struct mptcp_subflow_context *subflow;
    3977                 :        1660 :         struct mptcp_sock *msk;
    3978                 :             : 
    3979            [ + ]:        1660 :         if (!nsk)
    3980                 :             :                 return NULL;
    3981                 :             : 
    3982                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
    3983            [ + ]:        1660 :         if (nsk->sk_family == AF_INET6)
    3984                 :         802 :                 inet_sk(nsk)->pinet6 = mptcp_inet6_sk(nsk);
    3985                 :             : #endif
    3986                 :             : 
    3987                 :        1660 :         __mptcp_init_sock(nsk);
    3988                 :             : 
    3989                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
    3990            [ + ]:        1660 :         if (nsk->sk_family == AF_INET6)
    3991                 :         802 :                 mptcp_copy_ip6_options(nsk, sk);
    3992                 :             :         else
    3993                 :             : #endif
    3994                 :         858 :                 mptcp_copy_ip_options(nsk, sk);
    3995                 :             : 
    3996            [ + ]:        1660 :         msk = mptcp_sk(nsk);
    3997                 :        1660 :         WRITE_ONCE(msk->local_key, subflow_req->local_key);
    3998                 :        1660 :         WRITE_ONCE(msk->token, subflow_req->token);
    3999                 :        1660 :         msk->in_accept_queue = 1;
    4000                 :        1660 :         msk->fastopening = 0;
    4001                 :        1660 :         WRITE_ONCE(msk->fully_established, false);
    4002            [ + ]:        1660 :         if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD)
    4003                 :         118 :                 WRITE_ONCE(msk->csum_enabled, true);
    4004                 :             : 
    4005                 :        1660 :         WRITE_ONCE(msk->write_seq, subflow_req->idsn + 1);
    4006                 :        1660 :         WRITE_ONCE(msk->snd_nxt, msk->write_seq);
    4007                 :        1660 :         WRITE_ONCE(msk->snd_una, msk->write_seq);
    4008            [ + ]:        1660 :         WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd);
    4009            [ + ]:        1660 :         msk->setsockopt_seq = mptcp_sk(sk)->setsockopt_seq;
    4010            [ + ]:        1660 :         mptcp_init_sched(msk, mptcp_sk(sk)->sched);
    4011                 :             : 
    4012                 :             :         /* passive msk is created after the first/MPC subflow */
    4013                 :        1660 :         msk->subflow_id = 2;
    4014                 :             : 
    4015                 :        1660 :         sock_reset_flag(nsk, SOCK_RCU_FREE);
    4016                 :        1660 :         security_inet_csk_clone(nsk, req);
    4017                 :             : 
    4018                 :             :         /* this can't race with mptcp_close(), as the msk is
    4019                 :             :          * not yet exposted to user-space
    4020                 :             :          */
    4021                 :        1660 :         mptcp_set_state(nsk, TCP_ESTABLISHED);
    4022                 :             : 
    4023                 :             :         /* The msk maintain a ref to each subflow in the connections list */
    4024                 :        1660 :         WRITE_ONCE(msk->first, ssk);
    4025       [ - ][ - ]:        1660 :         subflow = mptcp_subflow_ctx(ssk);
    4026       [ - ][ - ]:        1660 :         list_add(&subflow->node, &msk->conn_list);
    4027                 :        1660 :         sock_hold(ssk);
    4028                 :             : 
    4029                 :             :         /* set msk addresses early to ensure mptcp_pm_get_local_id()
    4030                 :             :          * uses the correct data
    4031                 :             :          */
    4032                 :        1660 :         mptcp_copy_inaddrs(nsk, ssk);
    4033                 :             : 
    4034                 :        1660 :         mptcp_rcv_space_init(msk, ssk);
    4035                 :        1660 :         msk->rcvq_space.time = mptcp_stamp();
    4036                 :             : 
    4037  [ + ][ + ][ + ]:        1660 :         if (!mptcp_token_accept(subflow_req, msk)) {
                    [ + ]
    4038                 :           0 :                 list_del_init(&subflow->node);
    4039                 :           0 :                 WRITE_ONCE(msk->first, NULL);
    4040                 :           0 :                 sock_put(ssk);
    4041                 :           0 :                 mptcp_sk_clone_destroy(nsk);
    4042                 :           0 :                 return NULL;
    4043                 :             :         }
    4044                 :             : 
    4045  [ + ][ + ][ - ]:        1660 :         if (mp_opt->suboptions & OPTION_MPTCP_MPC_ACK)
                    [ - ]
    4046                 :        1604 :                 __mptcp_subflow_fully_established(msk, subflow, mp_opt);
    4047                 :        1660 :         bh_unlock_sock(nsk);
    4048                 :             : 
    4049                 :             :         /* note: the newly allocated socket refcount is 2 now */
    4050                 :        1660 :         return nsk;
    4051                 :             : }
    4052                 :             : 
    4053                 :        5143 : static void mptcp_destroy(struct sock *sk)
    4054                 :             : {
    4055            [ + ]:        5143 :         struct mptcp_sock *msk = mptcp_sk(sk);
    4056                 :             : 
    4057                 :             :         /* allow the following to close even the initial subflow */
    4058                 :        5143 :         msk->free_first = 1;
    4059                 :        5143 :         mptcp_destroy_common(msk);
    4060                 :        5143 :         sk_sockets_allocated_dec(sk);
    4061                 :        5143 : }
    4062                 :             : 
    4063                 :      508273 : void __mptcp_data_acked(struct sock *sk)
    4064                 :             : {
    4065       [ + ][ + ]:      508273 :         if (!sock_owned_by_user(sk))
    4066                 :      268704 :                 __mptcp_clean_una(sk);
    4067                 :             :         else
    4068       [ + ][ + ]:      239569 :                 __set_bit(MPTCP_CLEAN_UNA, &mptcp_sk(sk)->cb_flags);
    4069                 :      508273 : }
    4070                 :             : 
    4071                 :     1746614 : void __mptcp_check_push(struct sock *sk, struct sock *ssk)
    4072                 :             : {
    4073       [ + ][ + ]:     1746614 :         if (!sock_owned_by_user(sk))
    4074                 :     1290891 :                 __mptcp_subflow_push_pending(sk, ssk, false);
    4075                 :             :         else
    4076       [ + ][ + ]:      455723 :                 __set_bit(MPTCP_PUSH_PENDING, &mptcp_sk(sk)->cb_flags);
    4077                 :     1746614 : }
    4078                 :             : 
    4079                 :             : #define MPTCP_FLAGS_PROCESS_CTX_NEED (BIT(MPTCP_PUSH_PENDING) | \
    4080                 :             :                                       BIT(MPTCP_RETRANSMIT) | \
    4081                 :             :                                       BIT(MPTCP_FLUSH_JOIN_LIST))
    4082                 :             : 
    4083                 :             : /* processes deferred events and flush wmem */
    4084                 :     1638520 : static void mptcp_release_cb(struct sock *sk)
    4085                 :             :         __must_hold(&sk->sk_lock.slock)
    4086                 :             : {
    4087            [ + ]:     1638520 :         struct mptcp_sock *msk = mptcp_sk(sk);
    4088                 :     1638520 :         u32 moved = 0;
    4089                 :             : 
    4090                 :      268045 :         for (;;) {
    4091                 :     1905930 :                 unsigned long flags = (msk->cb_flags & MPTCP_FLAGS_PROCESS_CTX_NEED);
    4092                 :     1905930 :                 struct list_head join_list, skbs;
    4093                 :     1905930 :                 bool spool_bl;
    4094                 :             : 
    4095                 :     1905930 :                 spool_bl = mptcp_can_spool_backlog(sk, &skbs);
    4096       [ + ][ + ]:     1905930 :                 if (!flags && !spool_bl)
    4097                 :             :                         break;
    4098                 :             : 
    4099            [ + ]:      267410 :                 INIT_LIST_HEAD(&join_list);
    4100            [ + ]:      267410 :                 list_splice_init(&msk->join_list, &join_list);
    4101                 :             : 
    4102                 :             :                 /* the following actions acquire the subflow socket lock
    4103                 :             :                  *
    4104                 :             :                  * 1) can't be invoked in atomic scope
    4105                 :             :                  * 2) must avoid ABBA deadlock with msk socket spinlock: the RX
    4106                 :             :                  *    datapath acquires the msk socket spinlock while helding
    4107                 :             :                  *    the subflow socket lock
    4108                 :             :                  */
    4109                 :      267410 :                 msk->cb_flags &= ~flags;
    4110                 :      267410 :                 spin_unlock_bh(&sk->sk_lock.slock);
    4111                 :             : 
    4112            [ + ]:      267410 :                 if (flags & BIT(MPTCP_FLUSH_JOIN_LIST))
    4113                 :          27 :                         __mptcp_flush_join_list(sk, &join_list);
    4114            [ + ]:      267410 :                 if (flags & BIT(MPTCP_PUSH_PENDING))
    4115                 :      213617 :                         __mptcp_push_pending(sk, 0);
    4116            [ + ]:      267410 :                 if (flags & BIT(MPTCP_RETRANSMIT))
    4117                 :         474 :                         __mptcp_retrans(sk);
    4118         [ +  + ]:      267410 :                 if (spool_bl && __mptcp_move_skbs(sk, &skbs, &moved)) {
    4119                 :             :                         /* notify ack seq update */
    4120                 :      135922 :                         mptcp_cleanup_rbuf(msk, 0);
    4121                 :      135922 :                         sk->sk_data_ready(sk);
    4122                 :             :                 }
    4123                 :             : 
    4124                 :      267410 :                 cond_resched();
    4125                 :      267410 :                 spin_lock_bh(&sk->sk_lock.slock);
    4126                 :             :         }
    4127       [ + ][ + ]:     1638520 :         if (moved)
    4128                 :      130034 :                 WRITE_ONCE(msk->backlog_len, msk->backlog_len - moved);
    4129                 :             : 
    4130   [ +  -  -  + ]:     3276446 :         if (__test_and_clear_bit(MPTCP_CLEAN_UNA, &msk->cb_flags))
           [ +  -  -  + ]
    4131                 :      100401 :                 __mptcp_clean_una_wakeup(sk);
    4132       [ + ][ + ]:     1638520 :         if (unlikely(msk->cb_flags)) {
    4133                 :             :                 /* be sure to sync the msk state before taking actions
    4134                 :             :                  * depending on sk_state (MPTCP_ERROR_REPORT)
    4135                 :             :                  * On sk release avoid actions depending on the first subflow
    4136                 :             :                  */
    4137   [ +  -  -  +  :        8576 :                 if (__test_and_clear_bit(MPTCP_SYNC_STATE, &msk->cb_flags) && msk->first)
           - ][ +  -  -  
                   +  - ]
    4138                 :        1126 :                         __mptcp_sync_state(sk, msk->pending_state);
    4139   [ +  -  -  + ]:        8576 :                 if (__test_and_clear_bit(MPTCP_ERROR_REPORT, &msk->cb_flags))
           [ +  -  -  + ]
    4140                 :         612 :                         __mptcp_error_report(sk);
    4141   [ +  -  -  + ]:        8576 :                 if (__test_and_clear_bit(MPTCP_SYNC_SNDBUF, &msk->cb_flags))
           [ +  -  -  + ]
    4142                 :        2570 :                         __mptcp_sync_sndbuf(sk);
    4143                 :             :         }
    4144                 :     1638520 : }
    4145                 :             : 
    4146                 :             : /* MP_JOIN client subflow must wait for 4th ack before sending any data:
    4147                 :             :  * TCP can't schedule delack timer before the subflow is fully established.
    4148                 :             :  * MPTCP uses the delack timer to do 3rd ack retransmissions
    4149                 :             :  */
    4150                 :         606 : static void schedule_3rdack_retransmission(struct sock *ssk)
    4151                 :             : {
    4152                 :         606 :         struct inet_connection_sock *icsk = inet_csk(ssk);
    4153            [ + ]:         606 :         struct tcp_sock *tp = tcp_sk(ssk);
    4154                 :         606 :         unsigned long timeout;
    4155                 :             : 
    4156    [ + ][ +  + ]:         606 :         if (mptcp_subflow_ctx(ssk)->fully_established)
    4157                 :             :                 return;
    4158                 :             : 
    4159                 :             :         /* reschedule with a timeout above RTT, as we must look only for drop */
    4160       [ - ][ - ]:          98 :         if (tp->srtt_us)
    4161       [ + ][ + ]:          98 :                 timeout = usecs_to_jiffies(tp->srtt_us >> (3 - 1));
    4162                 :             :         else
    4163                 :             :                 timeout = TCP_TIMEOUT_INIT;
    4164                 :          98 :         timeout += jiffies;
    4165                 :             : 
    4166       [ + ][ + ]:          98 :         WARN_ON_ONCE(icsk->icsk_ack.pending & ICSK_ACK_TIMER);
    4167                 :          98 :         smp_store_release(&icsk->icsk_ack.pending,
    4168                 :             :                           icsk->icsk_ack.pending | ICSK_ACK_SCHED | ICSK_ACK_TIMER);
    4169                 :          98 :         sk_reset_timer(ssk, &icsk->icsk_delack_timer, timeout);
    4170                 :             : }
    4171                 :             : 
    4172                 :       26059 : void mptcp_subflow_process_delegated(struct sock *ssk, long status)
    4173                 :             : {
    4174       [ + ][ + ]:       26059 :         struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
    4175                 :       26059 :         struct sock *sk = subflow->conn;
    4176                 :             : 
    4177       [ + ][ + ]:       26059 :         if (status & BIT(MPTCP_DELEGATE_SEND)) {
    4178                 :        6268 :                 mptcp_data_lock(sk);
    4179       [ + ][ + ]:        6268 :                 if (!sock_owned_by_user(sk))
    4180                 :        5646 :                         __mptcp_subflow_push_pending(sk, ssk, true);
    4181                 :             :                 else
    4182       [ + ][ + ]:         622 :                         __set_bit(MPTCP_PUSH_PENDING, &mptcp_sk(sk)->cb_flags);
    4183                 :        6268 :                 mptcp_data_unlock(sk);
    4184                 :             :         }
    4185       [ + ][ + ]:       26059 :         if (status & BIT(MPTCP_DELEGATE_SNDBUF)) {
    4186                 :       17119 :                 mptcp_data_lock(sk);
    4187       [ + ][ + ]:       17119 :                 if (!sock_owned_by_user(sk))
    4188                 :       13854 :                         __mptcp_sync_sndbuf(sk);
    4189                 :             :                 else
    4190       [ + ][ + ]:        3265 :                         __set_bit(MPTCP_SYNC_SNDBUF, &mptcp_sk(sk)->cb_flags);
    4191                 :       17119 :                 mptcp_data_unlock(sk);
    4192                 :             :         }
    4193       [ + ][ + ]:       26059 :         if (status & BIT(MPTCP_DELEGATE_ACK))
    4194                 :         606 :                 schedule_3rdack_retransmission(ssk);
    4195                 :       26059 : }
    4196                 :             : 
    4197                 :           0 : static int mptcp_hash(struct sock *sk)
    4198                 :             : {
    4199                 :             :         /* should never be called,
    4200                 :             :          * we hash the TCP subflows not the MPTCP socket
    4201                 :             :          */
    4202                 :           0 :         WARN_ON_ONCE(1);
    4203                 :           0 :         return 0;
    4204                 :             : }
    4205                 :             : 
    4206                 :          10 : static void mptcp_unhash(struct sock *sk)
    4207                 :             : {
    4208                 :             :         /* called from sk_common_release(), but nothing to do here */
    4209                 :          10 : }
    4210                 :             : 
    4211                 :           0 : static int mptcp_get_port(struct sock *sk, unsigned short snum)
    4212                 :             : {
    4213            [ # ]:           0 :         struct mptcp_sock *msk = mptcp_sk(sk);
    4214                 :             : 
    4215         [ #  # ]:           0 :         pr_debug("msk=%p, ssk=%p\n", msk, msk->first);
    4216            [ # ]:           0 :         if (WARN_ON_ONCE(!msk->first))
    4217                 :           0 :                 return -EINVAL;
    4218                 :             : 
    4219                 :           0 :         return inet_csk_get_port(msk->first, snum);
    4220                 :             : }
    4221                 :             : 
    4222                 :        1484 : void mptcp_finish_connect(struct sock *ssk)
    4223                 :             : {
    4224                 :        1484 :         struct mptcp_subflow_context *subflow;
    4225                 :        1484 :         struct mptcp_sock *msk;
    4226                 :        1484 :         struct sock *sk;
    4227                 :             : 
    4228            [ + ]:        1484 :         subflow = mptcp_subflow_ctx(ssk);
    4229                 :        1484 :         sk = subflow->conn;
    4230            [ + ]:        1484 :         msk = mptcp_sk(sk);
    4231                 :             : 
    4232         [ -  - ]:        1484 :         pr_debug("msk=%p, token=%u\n", sk, subflow->token);
    4233                 :             : 
    4234                 :        1484 :         subflow->map_seq = subflow->iasn;
    4235                 :        1484 :         subflow->map_subflow_seq = 1;
    4236                 :             : 
    4237                 :             :         /* the socket is not connected yet, no msk/subflow ops can access/race
    4238                 :             :          * accessing the field below
    4239                 :             :          */
    4240                 :        1484 :         WRITE_ONCE(msk->local_key, subflow->local_key);
    4241                 :        1484 :         WRITE_ONCE(msk->rcvq_space.time, mptcp_stamp());
    4242                 :             : 
    4243                 :        1484 :         mptcp_pm_new_connection(msk, ssk, 0);
    4244                 :        1484 : }
    4245                 :             : 
    4246                 :        6394 : void mptcp_sock_graft(struct sock *sk, struct socket *parent)
    4247                 :             : {
    4248                 :        6394 :         write_lock_bh(&sk->sk_callback_lock);
    4249                 :        6394 :         rcu_assign_pointer(sk->sk_wq, &parent->wq);
    4250            [ - ]:        6394 :         sk_set_socket(sk, parent);
    4251                 :        6394 :         write_unlock_bh(&sk->sk_callback_lock);
    4252                 :        6394 : }
    4253                 :             : 
    4254                 :             : /* Can be called without holding the msk socket lock; use the callback lock
    4255                 :             :  * to avoid {READ_,WRITE_}ONCE annotations on sk_socket.
    4256                 :             :  */
    4257                 :         612 : static void mptcp_sock_check_graft(struct sock *sk, struct sock *ssk)
    4258                 :             : {
    4259                 :         612 :         struct socket *sock;
    4260                 :             : 
    4261                 :         612 :         write_lock_bh(&sk->sk_callback_lock);
    4262                 :         612 :         sock = sk->sk_socket;
    4263                 :         612 :         write_unlock_bh(&sk->sk_callback_lock);
    4264            [ + ]:         612 :         if (sock) {
    4265                 :         572 :                 mptcp_sock_graft(ssk, sock);
    4266                 :         572 :                 __mptcp_inherit_cgrp_data(sk, ssk);
    4267                 :         572 :                 __mptcp_inherit_memcg(sk, ssk, GFP_ATOMIC);
    4268                 :             :         }
    4269                 :         612 : }
    4270                 :             : 
    4271                 :        1206 : bool mptcp_finish_join(struct sock *ssk)
    4272                 :             : {
    4273            [ + ]:        1206 :         struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
    4274            [ + ]:        1206 :         struct mptcp_sock *msk = mptcp_sk(subflow->conn);
    4275                 :        1206 :         struct sock *parent = (void *)msk;
    4276                 :        1206 :         bool ret = true;
    4277                 :             : 
    4278         [ -  - ]:        1206 :         pr_debug("msk=%p, subflow=%p\n", msk, subflow);
    4279                 :             : 
    4280                 :             :         /* mptcp socket already closing? */
    4281       [ + ][ + ]:        1206 :         if (!mptcp_is_fully_established(parent)) {
    4282       [ # ][ # ]:           0 :                 MPTCP_INC_STATS(sock_net(parent), MPTCP_MIB_MPJOINNOTESTABLISHED);
    4283                 :           0 :                 subflow->reset_reason = MPTCP_RST_EMPTCP;
    4284                 :           0 :                 return false;
    4285                 :             :         }
    4286                 :             : 
    4287                 :             :         /* Active subflow, already present inside the conn_list; is grafted
    4288                 :             :          * either by __mptcp_subflow_connect() or accept.
    4289                 :             :          */
    4290       [ + ][ + ]:        1206 :         if (!list_empty(&subflow->node)) {
    4291                 :         594 :                 spin_lock_bh(&msk->fallback_lock);
    4292    [ + ][ +  + ]:         594 :                 if (!msk->allow_subflows) {
    4293                 :           0 :                         spin_unlock_bh(&msk->fallback_lock);
    4294                 :           0 :                         return false;
    4295                 :             :                 }
    4296                 :         594 :                 mptcp_subflow_joined(msk, ssk);
    4297                 :         594 :                 spin_unlock_bh(&msk->fallback_lock);
    4298                 :         594 :                 mptcp_propagate_sndbuf(parent, ssk);
    4299                 :         594 :                 return true;
    4300                 :             :         }
    4301                 :             : 
    4302       [ + ][ + ]:         612 :         if (!mptcp_pm_allow_new_subflow(msk)) {
    4303       [ # ][ # ]:           0 :                 MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_JOINREJECTED);
    4304                 :           0 :                 goto err_prohibited;
    4305                 :             :         }
    4306                 :             : 
    4307                 :             :         /* If we can't acquire msk socket lock here, let the release callback
    4308                 :             :          * handle it
    4309                 :             :          */
    4310                 :         612 :         mptcp_data_lock(parent);
    4311       [ + ][ + ]:         612 :         if (!sock_owned_by_user(parent)) {
    4312                 :         584 :                 ret = __mptcp_finish_join(msk, ssk);
    4313       [ - ][ - ]:         584 :                 if (ret) {
    4314                 :         584 :                         sock_hold(ssk);
    4315                 :         584 :                         list_add_tail(&subflow->node, &msk->conn_list);
    4316                 :         584 :                         mptcp_sock_check_graft(parent, ssk);
    4317                 :             :                 }
    4318                 :             :         } else {
    4319                 :          28 :                 sock_hold(ssk);
    4320            [ + ]:          28 :                 list_add_tail(&subflow->node, &msk->join_list);
    4321      [ +  -  - ]:          28 :                 __set_bit(MPTCP_FLUSH_JOIN_LIST, &msk->cb_flags);
              [ +  -  - ]
    4322                 :             : 
    4323                 :             :                 /* In case of later failures, __mptcp_flush_join_list() will
    4324                 :             :                  * properly orphan the ssk via mptcp_close_ssk().
    4325                 :             :                  */
    4326                 :          28 :                 mptcp_sock_check_graft(parent, ssk);
    4327                 :             :         }
    4328                 :         612 :         mptcp_data_unlock(parent);
    4329                 :             : 
    4330       [ + ][ + ]:         612 :         if (!ret) {
    4331                 :           0 :                 mptcp_pm_close_subflow(msk);
    4332                 :           0 : err_prohibited:
    4333                 :           0 :                 subflow->reset_reason = MPTCP_RST_EPROHIBIT;
    4334                 :           0 :                 return false;
    4335                 :             :         }
    4336                 :             : 
    4337                 :             :         return true;
    4338                 :             : }
    4339                 :             : 
    4340                 :        2008 : static void mptcp_shutdown(struct sock *sk, int how)
    4341                 :             : {
    4342         [ -  - ]:        2008 :         pr_debug("sk=%p, how=%d\n", sk, how);
    4343                 :             : 
    4344         [ -  + ]:        2008 :         if ((how & SEND_SHUTDOWN) && mptcp_close_state(sk))
    4345                 :        1856 :                 __mptcp_wr_shutdown(sk);
    4346                 :        2008 : }
    4347                 :             : 
    4348                 :          16 : static int mptcp_ioctl_outq(const struct mptcp_sock *msk, u64 v)
    4349                 :             : {
    4350                 :          16 :         const struct sock *sk = (void *)msk;
    4351                 :          16 :         u64 delta;
    4352                 :             : 
    4353       [ - ][ - ]:          16 :         if (sk->sk_state == TCP_LISTEN)
    4354                 :             :                 return -EINVAL;
    4355                 :             : 
    4356    [ - ][ +  - ]:          16 :         if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
    4357                 :             :                 return 0;
    4358                 :             : 
    4359                 :          16 :         delta = msk->write_seq - v;
    4360 [ -  - ][ +  - ]:          16 :         if (__mptcp_check_fallback(msk) && msk->first) {
    4361       [ + ][ + ]:          16 :                 struct tcp_sock *tp = tcp_sk(msk->first);
    4362                 :             : 
    4363                 :             :                 /* the first subflow is disconnected after close - see
    4364                 :             :                  * __mptcp_close_ssk(). tcp_disconnect() moves the write_seq
    4365                 :             :                  * so ignore that status, too.
    4366                 :             :                  */
    4367    [ - ][ +  - ]:          16 :                 if (!((1 << msk->first->sk_state) &
    4368                 :             :                       (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_CLOSE)))
    4369                 :          16 :                         delta += READ_ONCE(tp->write_seq) - tp->snd_una;
    4370                 :             :         }
    4371                 :          16 :         if (delta > INT_MAX)
    4372                 :             :                 delta = INT_MAX;
    4373                 :             : 
    4374                 :          16 :         return (int)delta;
    4375                 :             : }
    4376                 :             : 
    4377                 :          16 : static int mptcp_ioctl(struct sock *sk, int cmd, int *karg)
    4378                 :             : {
    4379            [ + ]:          16 :         struct mptcp_sock *msk = mptcp_sk(sk);
    4380                 :          16 :         bool slow;
    4381                 :             : 
    4382   [ -  +  +  - ]:          16 :         switch (cmd) {
    4383                 :           0 :         case SIOCINQ:
    4384            [ # ]:           0 :                 if (sk->sk_state == TCP_LISTEN)
    4385                 :             :                         return -EINVAL;
    4386                 :             : 
    4387                 :           0 :                 lock_sock(sk);
    4388            [ # ]:           0 :                 if (mptcp_move_skbs(sk))
    4389                 :           0 :                         mptcp_cleanup_rbuf(msk, 0);
    4390                 :           0 :                 *karg = mptcp_inq_hint(sk);
    4391                 :           0 :                 release_sock(sk);
    4392                 :           0 :                 break;
    4393                 :           4 :         case SIOCOUTQ:
    4394                 :           8 :                 slow = lock_sock_fast(sk);
    4395                 :           8 :                 *karg = mptcp_ioctl_outq(msk, READ_ONCE(msk->snd_una));
    4396                 :           8 :                 unlock_sock_fast(sk, slow);
    4397                 :           8 :                 break;
    4398                 :           4 :         case SIOCOUTQNSD:
    4399                 :           8 :                 slow = lock_sock_fast(sk);
    4400                 :           8 :                 *karg = mptcp_ioctl_outq(msk, msk->snd_nxt);
    4401                 :           8 :                 unlock_sock_fast(sk, slow);
    4402                 :           8 :                 break;
    4403                 :             :         default:
    4404                 :             :                 return -ENOIOCTLCMD;
    4405                 :             :         }
    4406                 :             : 
    4407                 :             :         return 0;
    4408                 :             : }
    4409                 :             : 
    4410                 :        1744 : static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
    4411                 :             :                          int addr_len)
    4412                 :             : {
    4413                 :        1744 :         struct mptcp_subflow_context *subflow;
    4414            [ + ]:        1744 :         struct mptcp_sock *msk = mptcp_sk(sk);
    4415                 :        1744 :         int err = -EINVAL;
    4416                 :        1744 :         struct sock *ssk;
    4417                 :             : 
    4418                 :        1744 :         ssk = __mptcp_nmpc_sk(msk);
    4419            [ + ]:        1744 :         if (IS_ERR(ssk))
    4420                 :           0 :                 return PTR_ERR(ssk);
    4421                 :             : 
    4422                 :        1744 :         set_bit(MPTCP_RTX_ENABLED, &msk->flags);
    4423                 :        1744 :         mptcp_set_state(sk, TCP_SYN_SENT);
    4424       [ - ][ - ]:        1744 :         subflow = mptcp_subflow_ctx(ssk);
    4425                 :             : #ifdef CONFIG_TCP_MD5SIG
    4426                 :             :         /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
    4427                 :             :          * TCP option space.
    4428                 :             :          */
    4429                 :             :         if (rcu_access_pointer(tcp_sk(ssk)->md5sig_info))
    4430                 :             :                 mptcp_early_fallback(msk, subflow, MPTCP_MIB_MD5SIGFALLBACK);
    4431                 :             : #endif
    4432       [ - ][ - ]:        1744 :         if (subflow->request_mptcp) {
    4433       [ + ][ + ]:        1744 :                 if (mptcp_active_should_disable(sk))
    4434                 :          12 :                         mptcp_early_fallback(msk, subflow,
    4435                 :             :                                              MPTCP_MIB_MPCAPABLEACTIVEDISABLED);
    4436       [ + ][ + ]:        1732 :                 else if (mptcp_token_new_connect(ssk) < 0)
    4437                 :           0 :                         mptcp_early_fallback(msk, subflow,
    4438                 :             :                                              MPTCP_MIB_TOKENFALLBACKINIT);
    4439                 :             :         }
    4440                 :             : 
    4441                 :        1744 :         WRITE_ONCE(msk->write_seq, subflow->idsn);
    4442                 :        1744 :         WRITE_ONCE(msk->snd_nxt, subflow->idsn);
    4443                 :        1744 :         WRITE_ONCE(msk->snd_una, subflow->idsn);
    4444       [ + ][ + ]:        1744 :         if (likely(!__mptcp_check_fallback(msk)))
    4445       [ - ][ - ]:        1732 :                 MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEACTIVE);
    4446                 :             : 
    4447                 :             :         /* if reaching here via the fastopen/sendmsg path, the caller already
    4448                 :             :          * acquired the subflow socket lock, too.
    4449                 :             :          */
    4450       [ + ][ + ]:        1744 :         if (!msk->fastopening)
    4451                 :        1674 :                 lock_sock(ssk);
    4452                 :             : 
    4453                 :             :         /* the following mirrors closely a very small chunk of code from
    4454                 :             :          * __inet_stream_connect()
    4455                 :             :          */
    4456       [ + ][ + ]:        1744 :         if (ssk->sk_state != TCP_CLOSE)
    4457                 :           0 :                 goto out;
    4458                 :             : 
    4459      [ -  -  - ]:        1744 :         if (BPF_CGROUP_PRE_CONNECT_ENABLED(ssk)) {
              [ -  -  - ]
    4460                 :           0 :                 err = ssk->sk_prot->pre_connect(ssk, uaddr, addr_len);
    4461       [ - ][ - ]:           0 :                 if (err)
    4462                 :           0 :                         goto out;
    4463                 :             :         }
    4464                 :             : 
    4465                 :        1744 :         err = ssk->sk_prot->connect(ssk, uaddr, addr_len);
    4466       [ + ][ + ]:        1744 :         if (err < 0)
    4467                 :           6 :                 goto out;
    4468                 :             : 
    4469                 :             :         /* as tcp_connect_init(): drop an error from a previous connection */
    4470                 :        1738 :         WRITE_ONCE(sk->sk_err, 0);
    4471   [ +  -  -  + ]:        3446 :         inet_assign_bit(DEFER_CONNECT, sk, inet_test_bit(DEFER_CONNECT, ssk));
           [ +  -  -  + ]
    4472                 :             : 
    4473                 :        1744 : out:
    4474       [ + ][ + ]:        1744 :         if (!msk->fastopening)
    4475                 :        1674 :                 release_sock(ssk);
    4476                 :             : 
    4477                 :             :         /* on successful connect, the msk state will be moved to established by
    4478                 :             :          * subflow_finish_connect()
    4479                 :             :          */
    4480       [ + ][ + ]:        1744 :         if (unlikely(err)) {
    4481                 :           6 :                 mptcp_token_destroy(msk);
    4482                 :           6 :                 mptcp_set_state(sk, TCP_CLOSE);
    4483                 :             : 
    4484                 :           6 :                 spin_lock_bh(&msk->fallback_lock);
    4485                 :           6 :                 msk->allow_subflows = true;
    4486                 :           6 :                 msk->allow_infinite_fallback = true;
    4487                 :           6 :                 clear_bit(MPTCP_FALLBACK_DONE, &msk->flags);
    4488                 :           6 :                 spin_unlock_bh(&msk->fallback_lock);
    4489                 :             : 
    4490                 :           6 :                 mptcp_subflow_ctx_reset(mptcp_subflow_ctx(ssk));
    4491                 :           6 :                 return err;
    4492                 :             :         }
    4493                 :             : 
    4494                 :        1738 :         mptcp_copy_inaddrs(sk, ssk);
    4495                 :        1738 :         return 0;
    4496                 :             : }
    4497                 :             : 
    4498                 :             : static struct proto mptcp_prot = {
    4499                 :             :         .name           = "MPTCP",
    4500                 :             :         .owner          = THIS_MODULE,
    4501                 :             :         .init           = mptcp_init_sock,
    4502                 :             :         .connect        = mptcp_connect,
    4503                 :             :         .disconnect     = mptcp_disconnect,
    4504                 :             :         .close          = mptcp_close,
    4505                 :             :         .setsockopt     = mptcp_setsockopt,
    4506                 :             :         .getsockopt     = mptcp_getsockopt,
    4507                 :             :         .shutdown       = mptcp_shutdown,
    4508                 :             :         .destroy        = mptcp_destroy,
    4509                 :             :         .sendmsg        = mptcp_sendmsg,
    4510                 :             :         .ioctl          = mptcp_ioctl,
    4511                 :             :         .recvmsg        = mptcp_recvmsg,
    4512                 :             :         .release_cb     = mptcp_release_cb,
    4513                 :             :         .hash           = mptcp_hash,
    4514                 :             :         .unhash         = mptcp_unhash,
    4515                 :             :         .get_port       = mptcp_get_port,
    4516                 :             :         .stream_memory_free     = mptcp_stream_memory_free,
    4517                 :             :         .sockets_allocated      = &mptcp_sockets_allocated,
    4518                 :             : 
    4519                 :             :         .memory_allocated       = &net_aligned_data.tcp_memory_allocated,
    4520                 :             :         .per_cpu_fw_alloc       = &tcp_memory_per_cpu_fw_alloc,
    4521                 :             : 
    4522                 :             :         .memory_pressure        = &tcp_memory_pressure,
    4523                 :             :         .sysctl_wmem_offset     = offsetof(struct net, ipv4.sysctl_tcp_wmem),
    4524                 :             :         .sysctl_rmem_offset     = offsetof(struct net, ipv4.sysctl_tcp_rmem),
    4525                 :             :         .sysctl_mem     = sysctl_tcp_mem,
    4526                 :             :         .obj_size       = sizeof(struct mptcp_sock),
    4527                 :             :         .slab_flags     = SLAB_TYPESAFE_BY_RCU,
    4528                 :             :         .no_autobind    = true,
    4529                 :             : };
    4530                 :             : 
    4531                 :        1800 : static int mptcp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int addr_len)
    4532                 :             : {
    4533            [ + ]:        1800 :         struct mptcp_sock *msk = mptcp_sk(sock->sk);
    4534                 :        1800 :         struct sock *ssk, *sk = sock->sk;
    4535                 :        1800 :         int err = -EINVAL;
    4536                 :             : 
    4537                 :        1800 :         lock_sock(sk);
    4538                 :        1800 :         ssk = __mptcp_nmpc_sk(msk);
    4539            [ + ]:        1800 :         if (IS_ERR(ssk)) {
    4540                 :           0 :                 err = PTR_ERR(ssk);
    4541                 :           0 :                 goto unlock;
    4542                 :             :         }
    4543                 :             : 
    4544            [ + ]:        1800 :         if (sk->sk_family == AF_INET)
    4545                 :         922 :                 err = inet_bind_sk(ssk, uaddr, addr_len);
    4546                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
    4547            [ - ]:         878 :         else if (sk->sk_family == AF_INET6)
    4548                 :         878 :                 err = inet6_bind_sk(ssk, uaddr, addr_len);
    4549                 :             : #endif
    4550            [ + ]:        1800 :         if (!err)
    4551                 :        1795 :                 mptcp_copy_inaddrs(sk, ssk);
    4552                 :             : 
    4553                 :           5 : unlock:
    4554                 :        1800 :         release_sock(sk);
    4555                 :        1800 :         return err;
    4556                 :             : }
    4557                 :             : 
    4558                 :        1795 : static int mptcp_listen(struct socket *sock, int backlog)
    4559                 :             : {
    4560            [ + ]:        1795 :         struct mptcp_sock *msk = mptcp_sk(sock->sk);
    4561                 :        1795 :         struct sock *sk = sock->sk;
    4562                 :        1795 :         struct sock *ssk;
    4563                 :        1795 :         bool listening;
    4564                 :        1795 :         int err;
    4565                 :             : 
    4566         [ -  - ]:        1795 :         pr_debug("msk=%p\n", msk);
    4567                 :             : 
    4568                 :        1795 :         lock_sock(sk);
    4569                 :             : 
    4570                 :        1795 :         err = -EINVAL;
    4571         [ -  + ]:        1795 :         if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM)
    4572                 :           0 :                 goto unlock;
    4573                 :             : 
    4574                 :        1795 :         ssk = __mptcp_nmpc_sk(msk);
    4575            [ + ]:        1795 :         if (IS_ERR(ssk)) {
    4576                 :           0 :                 err = PTR_ERR(ssk);
    4577                 :           0 :                 goto unlock;
    4578                 :             :         }
    4579                 :             : 
    4580                 :        1795 :         listening = sk->sk_state == TCP_LISTEN;
    4581                 :        1795 :         set_bit(MPTCP_RTX_ENABLED, &msk->flags);
    4582                 :        1795 :         mptcp_set_state(sk, TCP_LISTEN);
    4583                 :        1795 :         sock_set_flag(sk, SOCK_RCU_FREE);
    4584                 :             : 
    4585                 :        1795 :         lock_sock(ssk);
    4586                 :        1795 :         err = __inet_listen_sk(ssk, backlog);
    4587 [ +  - ][ +  - ]:        1795 :         if (err && ssk->sk_state == TCP_CLOSE) {
    4588                 :             :                 /* inet_csk_listen_start() leaves this drain to MPTCP */
    4589                 :           0 :                 mptcp_subflow_queue_clean(sk, ssk);
    4590                 :           0 :                 inet_csk_listen_stop(ssk);
    4591                 :             :         }
    4592                 :        1795 :         release_sock(ssk);
    4593                 :        1795 :         mptcp_set_state(sk, inet_sk_state_load(ssk));
    4594                 :             : 
    4595                 :             :         /* only the backlog changes when listening already */
    4596       [ + ][ + ]:        1795 :         if (!err && !listening) {
    4597                 :        1795 :                 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
    4598                 :        1795 :                 mptcp_copy_inaddrs(sk, ssk);
    4599                 :        1795 :                 mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED);
    4600                 :             :         }
    4601                 :             : 
    4602                 :           0 : unlock:
    4603                 :        1795 :         release_sock(sk);
    4604                 :        1795 :         return err;
    4605                 :             : }
    4606                 :             : 
    4607                 :             : /* Similar to __sk_charge(), but the msk and its subflows share pages */
    4608                 :           6 : static int mptcp_charge_subflow(struct sock *sk, struct sock *ssk, int mem)
    4609                 :             : {
    4610                 :           9 :         int new_mem = mem + ssk->sk_forward_alloc +
    4611                 :           6 :                       atomic_read(&ssk->sk_rmem_alloc);
    4612                 :           6 :         int amt = sk_mem_pages(new_mem) - sk_mem_pages(mem);
    4613                 :           6 :         gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
    4614                 :             : 
    4615                 :           6 :         mem_cgroup_sk_inherit(sk, ssk);
    4616       [ + ][ + ]:           6 :         if (amt > 0)
    4617                 :           0 :                 mem_cgroup_sk_charge(ssk, amt, gfp);
    4618                 :           6 :         kmem_cache_charge(ssk, gfp);
    4619                 :           6 :         return new_mem;
    4620                 :             : }
    4621                 :             : 
    4622                 :        1618 : static void mptcp_graft_subflows(struct sock *sk)
    4623                 :             : {
    4624                 :        1618 :         struct mptcp_subflow_context *subflow;
    4625            [ + ]:        1618 :         struct mptcp_sock *msk = mptcp_sk(sk);
    4626                 :        1618 :         int mem;
    4627                 :             : 
    4628            [ + ]:        1618 :         if (mem_cgroup_sockets_enabled) {
    4629                 :           6 :                 LIST_HEAD(join_list);
    4630                 :             : 
    4631                 :             :                 /* Subflows joining after __inet_accept() will get the
    4632                 :             :                  * mem CG properly initialized at mptcp_finish_join() time,
    4633                 :             :                  * even if pending in join_list. The ones that joined before
    4634                 :             :                  * need explicit initialization by the loop below.
    4635                 :             :                  */
    4636                 :           6 :                 mptcp_data_lock(sk);
    4637            [ + ]:           6 :                 list_splice_init(&msk->join_list, &join_list);
    4638                 :           6 :                 mptcp_data_unlock(sk);
    4639                 :             : 
    4640                 :           6 :                 __mptcp_flush_join_list(sk, &join_list);
    4641                 :             :         }
    4642                 :             : 
    4643                 :             :         /* What __inet_accept() just charged for the msk, before rounding up. */
    4644                 :        1618 :         mem = sk->sk_forward_alloc + atomic_read(&sk->sk_rmem_alloc);
    4645                 :             : 
    4646       [ + ][ + ]:        3270 :         mptcp_for_each_subflow(msk, subflow) {
    4647                 :        1652 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    4648                 :             : 
    4649                 :        1652 :                 lock_sock(ssk);
    4650                 :             : 
    4651                 :             :                 /* Set ssk->sk_socket of accept()ed flows to mptcp socket.
    4652                 :             :                  * This is needed so NOSPACE flag can be set from tcp stack.
    4653                 :             :                  */
    4654       [ - ][ - ]:        1652 :                 if (!ssk->sk_socket)
    4655                 :        1652 :                         mptcp_sock_graft(ssk, sk->sk_socket);
    4656                 :             : 
    4657                 :             :                 /* Got the memcg when joining: its memory is already charged */
    4658 [ +  + ][ +  + ]:        1652 :                 if (!mem_cgroup_sk_enabled(sk) || mem_cgroup_from_sk(ssk))
    4659                 :        1646 :                         goto unlock;
    4660                 :             : 
    4661                 :           6 :                 __mptcp_inherit_cgrp_data(sk, ssk);
    4662                 :           6 :                 mem = mptcp_charge_subflow(sk, ssk, mem);
    4663                 :             : 
    4664                 :        1652 : unlock:
    4665                 :        1652 :                 release_sock(ssk);
    4666                 :             :         }
    4667                 :        1618 : }
    4668                 :             : 
    4669                 :        1808 : static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
    4670                 :             :                                struct proto_accept_arg *arg)
    4671                 :             : {
    4672            [ + ]:        1808 :         struct mptcp_sock *msk = mptcp_sk(sock->sk);
    4673                 :        1808 :         struct sock *ssk, *newsk;
    4674                 :             : 
    4675         [ -  - ]:        1808 :         pr_debug("msk=%p\n", msk);
    4676                 :             : 
    4677                 :             :         /* Buggy applications can call accept on socket states other then LISTEN
    4678                 :             :          * but no need to allocate the first subflow just to error out.
    4679                 :             :          */
    4680                 :        1808 :         ssk = READ_ONCE(msk->first);
    4681       [ - ][ - ]:        1808 :         if (!ssk)
    4682                 :             :                 return -EINVAL;
    4683                 :             : 
    4684         [ -  - ]:        1808 :         pr_debug("ssk=%p, listener=%p\n", ssk, mptcp_subflow_ctx(ssk));
    4685                 :        1808 :         newsk = inet_csk_accept(ssk, arg);
    4686            [ + ]:        1808 :         if (!newsk)
    4687                 :          12 :                 return arg->err;
    4688                 :             : 
    4689         [ -  - ]:        1796 :         pr_debug("newsk=%p, subflow is mptcp=%d\n", newsk, sk_is_mptcp(newsk));
              [ -  -  - ]
    4690    [ + ][ +  + ]:        1796 :         if (sk_is_mptcp(newsk)) {
    4691                 :        1618 :                 struct mptcp_subflow_context *subflow;
    4692                 :        1618 :                 struct sock *new_mptcp_sock;
    4693                 :             : 
    4694       [ + ][ + ]:        1618 :                 subflow = mptcp_subflow_ctx(newsk);
    4695                 :        1618 :                 new_mptcp_sock = subflow->conn;
    4696                 :             : 
    4697                 :             :                 /* is_mptcp should be false if subflow->conn is missing, see
    4698                 :             :                  * subflow_syn_recv_sock()
    4699                 :             :                  */
    4700       [ + ][ + ]:        1618 :                 if (WARN_ON_ONCE(!new_mptcp_sock)) {
    4701       [ # ][ # ]:           0 :                         tcp_sk(newsk)->is_mptcp = 0;
    4702                 :           0 :                         goto tcpfallback;
    4703                 :             :                 }
    4704                 :             : 
    4705                 :        1618 :                 newsk = new_mptcp_sock;
    4706       [ - ][ - ]:        1618 :                 MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_MPCAPABLEPASSIVEACK);
    4707                 :             : 
    4708            [ + ]:        1618 :                 newsk->sk_kern_sock = arg->kern;
    4709                 :        1618 :                 lock_sock(newsk);
    4710                 :        1618 :                 __inet_accept(sock, newsock, newsk);
    4711                 :             : 
    4712                 :        1618 :                 set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags);
    4713       [ + ][ + ]:        1618 :                 msk = mptcp_sk(newsk);
    4714                 :        1618 :                 msk->in_accept_queue = 0;
    4715                 :             : 
    4716                 :        1618 :                 mptcp_graft_subflows(newsk);
    4717                 :        1618 :                 mptcp_rps_record_subflows(msk);
    4718       [ + ][ + ]:        1618 :                 __mptcp_propagate_sndbuf(newsk, mptcp_subflow_tcp_sock(subflow));
    4719                 :             : 
    4720                 :             :                 /* Do late cleanup for the first subflow as necessary. Also
    4721                 :             :                  * deal with bad peers not doing a complete shutdown.
    4722                 :             :                  */
    4723       [ + ][ + ]:        1618 :                 if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
    4724       [ - ][ - ]:           6 :                         if (unlikely(list_is_singular(&msk->conn_list))) {
    4725                 :           6 :                                 mptcp_check_rcv_close(newsk);
    4726                 :             :                                 /* not reported in the accept queue */
    4727                 :           6 :                                 __mptcp_error_report(newsk);
    4728                 :           6 :                                 mptcp_set_state(newsk, TCP_CLOSE);
    4729                 :             :                         }
    4730                 :           6 :                         mptcp_close_ssk(newsk, msk->first,
    4731                 :           6 :                                         mptcp_subflow_ctx(msk->first));
    4732                 :             :                 }
    4733                 :             :         } else {
    4734                 :         178 : tcpfallback:
    4735            [ + ]:         178 :                 newsk->sk_kern_sock = arg->kern;
    4736                 :         178 :                 lock_sock(newsk);
    4737                 :         178 :                 __inet_accept(sock, newsock, newsk);
    4738                 :             :                 /* we are being invoked after accepting a non-mp-capable
    4739                 :             :                  * flow: sk is a tcp_sk, not an mptcp one.
    4740                 :             :                  *
    4741                 :             :                  * Hand the socket over to tcp so all further socket ops
    4742                 :             :                  * bypass mptcp.
    4743                 :             :                  */
    4744                 :         178 :                 WRITE_ONCE(newsock->sk->sk_socket->ops,
    4745                 :             :                            mptcp_fallback_tcp_ops(newsock->sk));
    4746                 :             :         }
    4747                 :        1796 :         release_sock(newsk);
    4748                 :             : 
    4749                 :        1796 :         return 0;
    4750                 :             : }
    4751                 :             : 
    4752                 :      551789 : static __poll_t mptcp_check_writeable(struct mptcp_sock *msk)
    4753                 :             : {
    4754                 :      551789 :         struct sock *sk = (struct sock *)msk;
    4755                 :             : 
    4756            [ + ]:      551789 :         if (__mptcp_stream_is_writeable(sk, 1))
    4757                 :             :                 return EPOLLOUT | EPOLLWRNORM;
    4758                 :             : 
    4759                 :      158914 :         sk_set_nospace(sk);
    4760                 :      158914 :         smp_mb__after_atomic(); /* NOSPACE is changed by mptcp_write_space() */
    4761            [ + ]:      158914 :         if (__mptcp_stream_is_writeable(sk, 1))
    4762                 :             :                 return EPOLLOUT | EPOLLWRNORM;
    4763                 :             : 
    4764                 :             :         return 0;
    4765                 :             : }
    4766                 :             : 
    4767                 :     1015457 : static __poll_t mptcp_poll(struct file *file, struct socket *sock,
    4768                 :             :                            struct poll_table_struct *wait)
    4769                 :             : {
    4770                 :     1015457 :         struct sock *sk = sock->sk;
    4771                 :     1015457 :         struct mptcp_sock *msk;
    4772                 :     1015457 :         __poll_t mask = 0;
    4773                 :     1015457 :         u8 shutdown;
    4774                 :     1015457 :         int state;
    4775                 :             : 
    4776            [ + ]:     1015457 :         msk = mptcp_sk(sk);
    4777                 :     1015457 :         sock_poll_wait(file, sock, wait);
    4778                 :             : 
    4779                 :     1015457 :         state = inet_sk_state_load(sk);
    4780         [ -  - ]:     1015457 :         pr_debug("msk=%p state=%d flags=%lx\n", msk, state, msk->flags);
    4781            [ + ]:     1015457 :         if (state == TCP_LISTEN) {
    4782                 :        2768 :                 struct sock *ssk = READ_ONCE(msk->first);
    4783                 :             : 
    4784            [ + ]:        2768 :                 if (WARN_ON_ONCE(!ssk))
    4785                 :           0 :                         return 0;
    4786                 :             : 
    4787            [ + ]:        4160 :                 return inet_csk_listen_poll(ssk);
    4788                 :             :         }
    4789                 :             : 
    4790                 :     1012689 :         shutdown = READ_ONCE(sk->sk_shutdown);
    4791            [ + ]:     1012689 :         if (shutdown == SHUTDOWN_MASK || state == TCP_CLOSE)
    4792                 :        4674 :                 mask |= EPOLLHUP;
    4793            [ + ]:     1012689 :         if (shutdown & RCV_SHUTDOWN)
    4794                 :      181031 :                 mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
    4795                 :             : 
    4796            [ - ]:     1012689 :         if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
    4797                 :     1012689 :                 mask |= mptcp_check_readable(sk);
    4798            [ + ]:     1012689 :                 if (shutdown & SEND_SHUTDOWN)
    4799                 :      460900 :                         mask |= EPOLLOUT | EPOLLWRNORM;
    4800                 :             :                 else
    4801                 :      551789 :                         mask |= mptcp_check_writeable(msk);
    4802 [ #  # ][ #  # ]:           0 :         } else if (state == TCP_SYN_SENT &&
    4803      [ #  #  # ]:           0 :                    inet_test_bit(DEFER_CONNECT, sk)) {
              [ #  #  # ]
    4804                 :             :                 /* cf tcp_poll() note about TFO */
    4805                 :           0 :                 mask |= EPOLLOUT | EPOLLWRNORM;
    4806                 :             :         }
    4807                 :             : 
    4808                 :             :         /* This barrier is coupled with smp_wmb() in __mptcp_error_report() */
    4809                 :     1012689 :         smp_rmb();
    4810       [ + ][ + ]:     1012689 :         if (READ_ONCE(sk->sk_err))
    4811                 :          10 :                 mask |= EPOLLERR;
    4812                 :             : 
    4813                 :             :         return mask;
    4814                 :             : }
    4815                 :             : 
    4816                 :      193349 : static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
    4817                 :             : {
    4818            [ + ]:      193349 :         struct mptcp_sock *msk = mptcp_sk(sk);
    4819                 :      193349 :         struct sk_buff *skb;
    4820                 :      193349 :         u32 offset;
    4821                 :             : 
    4822            [ + ]:      193349 :         if (!list_empty(&msk->backlog_list))
    4823                 :        5236 :                 mptcp_move_skbs(sk);
    4824                 :             : 
    4825         [ +  + ]:      193349 :         while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) {
    4826                 :       67919 :                 offset = MPTCP_SKB_CB(skb)->offset;
    4827            [ - ]:       67919 :                 if (offset < skb->len) {
    4828                 :       67919 :                         *off = offset;
    4829                 :       67919 :                         return skb;
    4830                 :             :                 }
    4831                 :           0 :                 mptcp_eat_recv_skb(sk, skb);
    4832                 :             :         }
    4833                 :             :         return NULL;
    4834                 :             : }
    4835                 :             : 
    4836                 :             : /*
    4837                 :             :  * Note:
    4838                 :             :  *      - It is assumed that the socket was locked by the caller.
    4839                 :             :  */
    4840                 :       91449 : static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
    4841                 :             :                              sk_read_actor_t recv_actor, bool noack)
    4842                 :             : {
    4843            [ + ]:       91449 :         struct mptcp_sock *msk = mptcp_sk(sk);
    4844                 :       91449 :         struct sk_buff *skb;
    4845                 :       91449 :         int copied = 0;
    4846                 :       91449 :         u32 offset;
    4847                 :             : 
    4848                 :       91449 :         msk_owned_by_me(msk);
    4849                 :             : 
    4850 [ +  - ][ +  - ]:       91449 :         if (sk->sk_state == TCP_LISTEN)
    4851                 :             :                 return -ENOTCONN;
    4852       [ + ][ + ]:      145089 :         while ((skb = mptcp_recv_skb(sk, &offset)) != NULL) {
    4853                 :       61945 :                 u32 data_len = skb->len - offset;
    4854                 :       61945 :                 int count;
    4855                 :       61945 :                 u32 size;
    4856                 :             : 
    4857                 :       61945 :                 size = min_t(size_t, data_len, INT_MAX);
    4858                 :       61945 :                 count = recv_actor(desc, skb, offset, size);
    4859       [ + ][ + ]:       61945 :                 if (count <= 0) {
    4860       [ + ][ + ]:        1643 :                         if (!copied)
    4861                 :        1481 :                                 copied = count;
    4862                 :             :                         break;
    4863                 :             :                 }
    4864                 :             : 
    4865                 :       60302 :                 copied += count;
    4866                 :             : 
    4867                 :       60302 :                 msk->bytes_consumed += count;
    4868       [ + ][ + ]:       60302 :                 if (count < data_len) {
    4869                 :        4108 :                         MPTCP_SKB_CB(skb)->offset += count;
    4870                 :        4108 :                         MPTCP_SKB_CB(skb)->map_seq += count;
    4871                 :        4108 :                         break;
    4872                 :             :                 }
    4873                 :             : 
    4874                 :       56194 :                 mptcp_eat_recv_skb(sk, skb);
    4875       [ + ][ + ]:       56194 :                 if (!desc->count)
    4876                 :             :                         break;
    4877                 :             :         }
    4878                 :             : 
    4879       [ + ][ + ]:       91449 :         if (noack)
    4880                 :           0 :                 goto out;
    4881                 :             : 
    4882                 :       91449 :         mptcp_rcv_space_adjust(msk, copied);
    4883                 :             : 
    4884       [ + ][ + ]:       91449 :         if (copied > 0) {
    4885                 :       48260 :                 mptcp_recv_skb(sk, &offset);
    4886                 :       48260 :                 mptcp_cleanup_rbuf(msk, copied);
    4887                 :             :         }
    4888                 :       43189 : out:
    4889                 :             :         return copied;
    4890                 :             : }
    4891                 :             : 
    4892                 :           0 : static int mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
    4893                 :             :                            sk_read_actor_t recv_actor)
    4894                 :             : {
    4895                 :           0 :         return __mptcp_read_sock(sk, desc, recv_actor, false);
    4896                 :             : }
    4897                 :             : 
    4898                 :       91449 : static int __mptcp_splice_read(struct sock *sk, struct tcp_splice_state *tss)
    4899                 :             : {
    4900                 :             :         /* Store TCP splice context information in read_descriptor_t. */
    4901                 :       91449 :         read_descriptor_t rd_desc = {
    4902                 :             :                 .arg.data = tss,
    4903                 :       91449 :                 .count    = tss->len,
    4904                 :             :         };
    4905                 :             : 
    4906                 :       91449 :         return mptcp_read_sock(sk, &rd_desc, tcp_splice_data_recv);
    4907                 :             : }
    4908                 :             : 
    4909                 :             : /**
    4910                 :             :  *  mptcp_splice_read - splice data from MPTCP socket to a pipe
    4911                 :             :  * @sock:       socket to splice from
    4912                 :             :  * @ppos:       position (not valid)
    4913                 :             :  * @pipe:       pipe to splice to
    4914                 :             :  * @len:        number of bytes to splice
    4915                 :             :  * @flags:      splice modifier flags
    4916                 :             :  *
    4917                 :             :  * Description:
    4918                 :             :  *    Will read pages from given socket and fill them into a pipe.
    4919                 :             :  *
    4920                 :             :  * Return:
    4921                 :             :  *    Amount of bytes that have been spliced.
    4922                 :             :  *
    4923                 :             :  **/
    4924                 :       33276 : static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos,
    4925                 :             :                                  struct pipe_inode_info *pipe, size_t len,
    4926                 :             :                                  unsigned int flags)
    4927                 :             : {
    4928                 :       33276 :         struct tcp_splice_state tss = {
    4929                 :             :                 .pipe   = pipe,
    4930                 :             :                 .len    = len,
    4931                 :             :                 .flags  = flags,
    4932                 :             :         };
    4933                 :       33276 :         struct sock *sk = sock->sk;
    4934                 :       33276 :         ssize_t spliced = 0;
    4935                 :       33276 :         int ret = 0;
    4936                 :       33276 :         long timeo;
    4937                 :             : 
    4938                 :             :         /*
    4939                 :             :          * We can't seek on a socket input
    4940                 :             :          */
    4941       [ - ][ - ]:       33276 :         if (unlikely(*ppos))
    4942                 :             :                 return -ESPIPE;
    4943                 :             : 
    4944                 :       33276 :         lock_sock(sk);
    4945                 :             : 
    4946            [ + ]:       33276 :         mptcp_rps_record_subflows(mptcp_sk(sk));
    4947                 :             : 
    4948            [ - ]:       33276 :         timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK);
    4949       [ + ][ + ]:       91449 :         while (tss.len) {
    4950                 :       91449 :                 ret = __mptcp_splice_read(sk, &tss);
    4951       [ + ][ + ]:       91449 :                 if (ret < 0) {
    4952                 :             :                         break;
    4953       [ + ][ + ]:       89968 :                 } else if (!ret) {
    4954       [ + ][ + ]:       41708 :                         if (spliced)
    4955                 :             :                                 break;
    4956       [ + ][ + ]:       16226 :                         if (sock_flag(sk, SOCK_DONE))
    4957                 :             :                                 break;
    4958            [ + ]:       15986 :                         ret = sock_error(sk);
    4959       [ # ][ - ]:       10275 :                         if (ret)
    4960                 :             :                                 break;
    4961       [ - ][ - ]:       15986 :                         if (sk->sk_shutdown & RCV_SHUTDOWN)
    4962                 :             :                                 break;
    4963       [ - ][ - ]:       15986 :                         if (sk->sk_state == TCP_CLOSE) {
    4964                 :             :                                 /*
    4965                 :             :                                  * This occurs when user tries to read
    4966                 :             :                                  * from never connected socket.
    4967                 :             :                                  */
    4968                 :             :                                 ret = -ENOTCONN;
    4969                 :             :                                 break;
    4970                 :             :                         }
    4971       [ - ][ - ]:       15986 :                         if (!timeo) {
    4972                 :             :                                 ret = -EAGAIN;
    4973                 :             :                                 break;
    4974                 :             :                         }
    4975                 :             :                         /* if __mptcp_splice_read() got nothing while we have
    4976                 :             :                          * an skb in receive queue, we do not want to loop.
    4977                 :             :                          * This might happen with URG data.
    4978                 :             :                          */
    4979       [ - ][ - ]:       15986 :                         if (!skb_queue_empty(&sk->sk_receive_queue))
    4980                 :             :                                 break;
    4981                 :       15986 :                         ret = sk_wait_data(sk, &timeo, NULL);
    4982       [ - ][ - ]:       15986 :                         if (ret < 0)
    4983                 :             :                                 break;
    4984       [ + ][ + ]:       15986 :                         if (signal_pending(current)) {
    4985       [ # ][ # ]:           0 :                                 ret = sock_intr_errno(timeo);
    4986                 :             :                                 break;
    4987                 :             :                         }
    4988                 :       15986 :                         continue;
    4989                 :             :                 }
    4990                 :       48260 :                 tss.len -= ret;
    4991                 :       48260 :                 spliced += ret;
    4992                 :             : 
    4993 [ +  - ][ +  - ]:       48260 :                 if (!tss.len || !timeo)
    4994                 :             :                         break;
    4995                 :       42438 :                 release_sock(sk);
    4996                 :       42438 :                 lock_sock(sk);
    4997                 :             : 
    4998       [ + ][ + ]:       42438 :                 if (tcp_recv_should_stop(sk))
    4999                 :             :                         break;
    5000                 :             :         }
    5001                 :             : 
    5002                 :       33276 :         release_sock(sk);
    5003                 :             : 
    5004       [ + ][ + ]:       33276 :         if (spliced)
    5005                 :             :                 return spliced;
    5006                 :             : 
    5007                 :         240 :         return ret;
    5008                 :             : }
    5009                 :             : 
    5010                 :             : static const struct proto_ops mptcp_stream_ops = {
    5011                 :             :         .family            = PF_INET,
    5012                 :             :         .owner             = THIS_MODULE,
    5013                 :             :         .release           = inet_release,
    5014                 :             :         .bind              = mptcp_bind,
    5015                 :             :         .connect           = inet_stream_connect,
    5016                 :             :         .socketpair        = sock_no_socketpair,
    5017                 :             :         .accept            = mptcp_stream_accept,
    5018                 :             :         .getname           = inet_getname,
    5019                 :             :         .poll              = mptcp_poll,
    5020                 :             :         .ioctl             = inet_ioctl,
    5021                 :             :         .gettstamp         = sock_gettstamp,
    5022                 :             :         .listen            = mptcp_listen,
    5023                 :             :         .shutdown          = inet_shutdown,
    5024                 :             :         .setsockopt        = sock_common_setsockopt,
    5025                 :             :         .getsockopt        = sock_common_getsockopt,
    5026                 :             :         .sendmsg           = inet_sendmsg,
    5027                 :             :         .recvmsg           = inet_recvmsg,
    5028                 :             :         .mmap              = sock_no_mmap,
    5029                 :             :         .set_rcvlowat      = mptcp_set_rcvlowat,
    5030                 :             :         .read_sock         = mptcp_read_sock,
    5031                 :             :         .splice_read       = mptcp_splice_read,
    5032                 :             : };
    5033                 :             : 
    5034                 :             : static struct inet_protosw mptcp_protosw = {
    5035                 :             :         .type           = SOCK_STREAM,
    5036                 :             :         .protocol       = IPPROTO_MPTCP,
    5037                 :             :         .prot           = &mptcp_prot,
    5038                 :             :         .ops            = &mptcp_stream_ops,
    5039                 :             :         .flags          = INET_PROTOSW_ICSK,
    5040                 :             : };
    5041                 :             : 
    5042                 :       57145 : static int mptcp_napi_poll(struct napi_struct *napi, int budget)
    5043                 :             : {
    5044                 :       57145 :         struct mptcp_delegated_action *delegated;
    5045                 :       57145 :         struct mptcp_subflow_context *subflow;
    5046                 :       57145 :         int work_done = 0;
    5047                 :             : 
    5048                 :       57145 :         delegated = container_of(napi, struct mptcp_delegated_action, napi);
    5049       [ + ][ + ]:      115449 :         while ((subflow = mptcp_subflow_delegated_next(delegated)) != NULL) {
    5050                 :       58304 :                 struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
    5051                 :       58304 :                 long status;
    5052                 :             : 
    5053                 :       58304 :                 bh_lock_sock_nested(ssk);
    5054       [ + ][ + ]:       58304 :                 if (!sock_owned_by_user(ssk)) {
    5055                 :       20504 :                         status = xchg(&subflow->delegated_status, 0);
    5056       [ - ][ - ]:       20504 :                         if (!(status & BIT(MPTCP_DELEGATE_DEAD)))
    5057                 :       20504 :                                 mptcp_subflow_process_delegated(ssk, status);
    5058                 :             :                 } else {
    5059                 :             :                         /* tcp_release_cb_override already processed
    5060                 :             :                          * the action or will do at next release_sock().
    5061                 :             :                          * In both case must dequeue the subflow here - on the same
    5062                 :             :                          * CPU that scheduled it.
    5063                 :             :                          */
    5064                 :       37800 :                         smp_wmb();
    5065      [ +  -  + ]:       37800 :                         status = set_mask_bits(&subflow->delegated_status,
                 [ +  - ]
    5066                 :             :                                                BIT(MPTCP_DELEGATE_SCHEDULED), 0);
    5067                 :             :                 }
    5068                 :       58304 :                 bh_unlock_sock(ssk);
    5069                 :       58304 :                 sock_put(ssk);
    5070                 :             : 
    5071       [ + ][ + ]:       58304 :                 if (status & BIT(MPTCP_DELEGATE_DEAD))
    5072                 :           0 :                         kfree_rcu(subflow, rcu);
    5073                 :             : 
    5074       [ - ][ - ]:       58304 :                 if (++work_done == budget)
    5075                 :             :                         return budget;
    5076                 :             :         }
    5077                 :             : 
    5078                 :             :         /* always provide a 0 'work_done' argument, so that napi_complete_done
    5079                 :             :          * will not try accessing the NULL napi->dev ptr
    5080                 :             :          */
    5081                 :       57145 :         napi_complete_done(napi, 0);
    5082                 :       57145 :         return work_done;
    5083                 :             : }
    5084                 :             : 
    5085                 :           6 : void __init mptcp_proto_init(void)
    5086                 :             : {
    5087                 :           6 :         struct mptcp_delegated_action *delegated;
    5088                 :           6 :         int cpu;
    5089                 :             : 
    5090                 :           6 :         mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo;
    5091                 :             : 
    5092            [ + ]:           6 :         if (percpu_counter_init(&mptcp_sockets_allocated, 0, GFP_KERNEL))
    5093                 :           0 :                 panic("Failed to allocate MPTCP pcpu counter\n");
    5094                 :             : 
    5095                 :           6 :         mptcp_napi_dev = alloc_netdev_dummy(0);
    5096            [ + ]:           6 :         if (!mptcp_napi_dev)
    5097                 :           0 :                 panic("Failed to allocate MPTCP dummy netdev\n");
    5098         [ -  + ]:          54 :         for_each_possible_cpu(cpu) {
    5099                 :          24 :                 delegated = per_cpu_ptr(&mptcp_delegated_actions, cpu);
    5100                 :          24 :                 INIT_LIST_HEAD(&delegated->head);
    5101                 :          24 :                 netif_napi_add_tx(mptcp_napi_dev, &delegated->napi,
    5102                 :             :                                   mptcp_napi_poll);
    5103                 :          24 :                 napi_enable(&delegated->napi);
    5104                 :             :         }
    5105                 :             : 
    5106                 :           6 :         mptcp_subflow_init();
    5107                 :           6 :         mptcp_pm_init();
    5108                 :           6 :         mptcp_sched_init();
    5109                 :           6 :         mptcp_token_init();
    5110                 :             : 
    5111            [ + ]:           6 :         if (proto_register(&mptcp_prot, 1) != 0)
    5112                 :           0 :                 panic("Failed to register MPTCP proto.\n");
    5113                 :             : 
    5114                 :           6 :         inet_register_protosw(&mptcp_protosw);
    5115                 :             : 
    5116                 :           6 :         BUILD_BUG_ON(sizeof(struct mptcp_skb_cb) > sizeof_field(struct sk_buff, cb));
    5117                 :             : 
    5118                 :             :         /* struct mptcp_data_frag: 'overhead' corresponds to the alignment
    5119                 :             :          * (ALIGN(1, sizeof(long)) - 1, so 8-1) + the struct's size
    5120                 :             :          */
    5121                 :           6 :         BUILD_BUG_ON(ALIGN(1, sizeof(long)) - 1 + sizeof(struct mptcp_data_frag)
    5122                 :             :                      > U8_MAX);
    5123                 :           6 : }
    5124                 :             : 
    5125                 :             : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
    5126                 :             : static const struct proto_ops mptcp_v6_stream_ops = {
    5127                 :             :         .family            = PF_INET6,
    5128                 :             :         .owner             = THIS_MODULE,
    5129                 :             :         .release           = inet6_release,
    5130                 :             :         .bind              = mptcp_bind,
    5131                 :             :         .connect           = inet_stream_connect,
    5132                 :             :         .socketpair        = sock_no_socketpair,
    5133                 :             :         .accept            = mptcp_stream_accept,
    5134                 :             :         .getname           = inet6_getname,
    5135                 :             :         .poll              = mptcp_poll,
    5136                 :             :         .ioctl             = inet6_ioctl,
    5137                 :             :         .gettstamp         = sock_gettstamp,
    5138                 :             :         .listen            = mptcp_listen,
    5139                 :             :         .shutdown          = inet_shutdown,
    5140                 :             :         .setsockopt        = sock_common_setsockopt,
    5141                 :             :         .getsockopt        = sock_common_getsockopt,
    5142                 :             :         .sendmsg           = inet6_sendmsg,
    5143                 :             :         .recvmsg           = inet6_recvmsg,
    5144                 :             :         .mmap              = sock_no_mmap,
    5145                 :             : #ifdef CONFIG_COMPAT
    5146                 :             :         .compat_ioctl      = inet6_compat_ioctl,
    5147                 :             : #endif
    5148                 :             :         .set_rcvlowat      = mptcp_set_rcvlowat,
    5149                 :             :         .read_sock         = mptcp_read_sock,
    5150                 :             :         .splice_read       = mptcp_splice_read,
    5151                 :             : };
    5152                 :             : 
    5153                 :             : static struct proto mptcp_v6_prot;
    5154                 :             : 
    5155                 :             : static struct inet_protosw mptcp_v6_protosw = {
    5156                 :             :         .type           = SOCK_STREAM,
    5157                 :             :         .protocol       = IPPROTO_MPTCP,
    5158                 :             :         .prot           = &mptcp_v6_prot,
    5159                 :             :         .ops            = &mptcp_v6_stream_ops,
    5160                 :             :         .flags          = INET_PROTOSW_ICSK,
    5161                 :             : };
    5162                 :             : 
    5163                 :           6 : int __init mptcp_proto_v6_init(void)
    5164                 :             : {
    5165                 :           6 :         int err;
    5166                 :             : 
    5167                 :           6 :         mptcp_subflow_v6_init();
    5168                 :             : 
    5169                 :           6 :         mptcp_v6_prot = mptcp_prot;
    5170                 :           6 :         strscpy(mptcp_v6_prot.name, "MPTCPv6", sizeof(mptcp_v6_prot.name));
    5171                 :           6 :         mptcp_v6_prot.slab = NULL;
    5172                 :           6 :         mptcp_v6_prot.obj_size = sizeof(struct mptcp6_sock);
    5173                 :           6 :         mptcp_v6_prot.ipv6_pinfo_offset = offsetof(struct mptcp6_sock, np);
    5174                 :             : 
    5175                 :           6 :         err = proto_register(&mptcp_v6_prot, 1);
    5176            [ - ]:           6 :         if (err)
    5177                 :             :                 return err;
    5178                 :             : 
    5179                 :           6 :         err = inet6_register_protosw(&mptcp_v6_protosw);
    5180            [ + ]:           6 :         if (err)
    5181                 :           0 :                 proto_unregister(&mptcp_v6_prot);
    5182                 :             : 
    5183                 :             :         return err;
    5184                 :             : }
    5185                 :             : #endif
        

Generated by: LCOV version 2.3.1-1