From patchwork Fri Aug 11 15:57:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351060 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B42A92AB42 for ; Fri, 11 Aug 2023 15:58:45 +0000 (UTC) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DDAA30D5 for ; Fri, 11 Aug 2023 08:58:43 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-31771bb4869so1945122f8f.0 for ; Fri, 11 Aug 2023 08:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769522; x=1692374322; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=k5X9dCBbAfU6DjT+NDvr2dXxeO/cfwiJDXtpifKgXlA=; b=AfNHOQJ2nkB4iLHU0XVMtVVb1UTnxAlXjmudsfmcOaORZaxOvRzrr6koOLBpjL69QQ tt9xfEhLwbWEL3B7zOiiJ3zwChgyoycobsJf7svUsEVpCMgPOLnp3DPZtSoOnpVwxKDb 18FBd+zzEuVvYjyW1rujienvRQtSWWwKZMXGN6ZfK7/X3GRIsk4s6KKUq6Iiy26aWt6H gmoTwFWF9zbFCXa8wxuWHRN2D6xzLGJg8vmjzlFdVyvV9h2whRtMfhHnzPBSyY7yLkO4 6CnTY9+d+D8b4YjvYmH8zjFo2tLhlqIO41WsVPYxWAyBdtCH2il3OvT08DS2+ywhFiiG HYtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769522; x=1692374322; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k5X9dCBbAfU6DjT+NDvr2dXxeO/cfwiJDXtpifKgXlA=; b=idpsW4Jtb2HfevM6AYkxCKxDzL6ffx2oUbsXQqAxzbROQ2mhOdfBNJ52Km0vYcD4Ht d5zaODgqtefzGCrqYsspPiA5grnnE7ccMTSyHaLW0uFmMU4lDpvrt+ean4GsUPBK3p3+ tPsqf5vh/zAreHiQSS08H8P2gf9BJaILi8EJNJ/TBrO7AqEsX69pwius39crE1ziZker YMvP4PxZAz8l5W2Bdky2jggRMZzsQAyNn4O9tpkW8bnBm9jJ5Wc4b/V2CeF7h3AFodu/ TUwqf9g0VpxB9bDBI8oXLvFRqi4IHvGorxVyZMBb3ov0Q3vT0rRhn4bVPhitMtIO0CDE rQpw== X-Gm-Message-State: AOJu0Yx3Dj6QL7Tu+id/3hWT6ev1WrC8D7ArwJjTGdbmVKWPtheut8FK RYB6djDoiVyJ927B22AhUANUPg== X-Google-Smtp-Source: AGHT+IGSD4ePtHDWsMuK7XQNepQL96MNQFK7TtCmw2t1Syvy1CL8jN95/AgxPjnyyfqTQtK9EQ0vVw== X-Received: by 2002:adf:fc0f:0:b0:314:3a3d:5d1f with SMTP id i15-20020adffc0f000000b003143a3d5d1fmr1851910wrr.19.1691769521953; Fri, 11 Aug 2023 08:58:41 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:41 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:14 +0200 Subject: [PATCH net-next 01/14] mptcp: avoid unneeded mptcp_token_destroy() calls Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-1-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1720; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=gXoRie7DLKf3vWVejVmTZfC//Kg+jCDe1+Txjp6fEyI=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqv+r3KsHtF8v8Wo26pcmdkgVeFoZMKt2vnr HOE8E3VCBeJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c5hhD/0c8KK8DF9+DihPAJVsBCw7OJK4Qsqj2v1GgkbmoYkVV/vFyweuzcYBNmZTwHt0Su6nykO yTlwWPLLzZhhIAXBOXbC3XB7d2jkyS3h2pqF/9NcTWo8weFJ8uSMbNlAe7PnjeMAIpzPkJrEK8H 4YkzZK9+ntc2MMMzT73WfsF5iC+FruQYPx/OhwC6yAEVeJ23v5qxEJJojrDZJN+x51fFdQdJNF/ QvsWBAWSLqAXLxy+4Ds9b8q8FMkIXKXIaws85ymRXZ/94L20W9rPdHHljK1Ek1hYlHbD8LJNcxO No80OBKqkrAXLp3LEsaADiPDGyDQSMeaWkRjFZlSj7dybAooRafbK8PZ1Da3GUJsR3Iv8cbj+9O cjhYtxdA6xrGd7MsTFO2pwlVGHp3NCJQyIyqoQFgpjflevMdPrfX/1kA0i/dioxVacgWg8/5uLO 5S0HrjyyGNyngounFXMI4f4Lsouhe0X+DgUcSLMUqyEb+Dpt3XyyIh+nZDOFc9Ivvi1pzkGYovL fLLChmmsbzNCGm4exod+n3UvNvo6upaYtM9NJqaT8A7u8XfsWA9bbICQ2IVtU1htskbe1U0L1Bn Qyhhfb59KB54aTJX647M05snl4oFlidlaSmSjVcMZKw2963aE61PrSJtRdVXw2g/wzH2L6b4HFU 8k5iDsBxKuQShNg== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni The MPTCP protocol currently clears the msk token both at connect() and listen() time. That is needed to deal with failing connect() calls that can create a new token while leaving the sk in TCP_CLOSE,SS_UNCONNECTED status and thus allowing later connect() and/or listen() calls. Let's deal with such failures explicitly, cleaning the token in a timely manner and avoid the confusing early mptcp_token_destroy(). Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 48e649fe2360..abb310548c37 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3594,7 +3594,6 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) if (IS_ERR(ssock)) return PTR_ERR(ssock); - mptcp_token_destroy(msk); inet_sk_state_store(sk, TCP_SYN_SENT); subflow = mptcp_subflow_ctx(ssock->sk); #ifdef CONFIG_TCP_MD5SIG @@ -3624,6 +3623,8 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) * subflow_finish_connect() */ if (unlikely(err && err != -EINPROGRESS)) { + /* avoid leaving a dangling token in an unconnected socket */ + mptcp_token_destroy(msk); inet_sk_state_store(sk, inet_sk_state_load(ssock->sk)); return err; } @@ -3713,7 +3714,6 @@ static int mptcp_listen(struct socket *sock, int backlog) goto unlock; } - mptcp_token_destroy(msk); inet_sk_state_store(sk, TCP_LISTEN); sock_set_flag(sk, SOCK_RCU_FREE); From patchwork Fri Aug 11 15:57:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351061 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 352742AB42 for ; Fri, 11 Aug 2023 15:58:46 +0000 (UTC) Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E264430D7 for ; Fri, 11 Aug 2023 08:58:44 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4fe0eb0ca75so3286147e87.2 for ; Fri, 11 Aug 2023 08:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769523; x=1692374323; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lhePiwzsSx/PL85mddTkFwpXPwkG7Z75k06o+iuXV0A=; b=v1ebNHHM6M1mmtuZYCv9hRgIOkNvxHx2SBgalyfmwDZhrfEP9IFSEcEkc4TRnRuPDv Ao0uoh4HYY2as2H7y1J9ab6sbArcrdWg7SaIIeVQhpHhugrq2WkDi3Emdx/CbDhYrVBM D+lPAgyFcDqUpd2x8FeKuRbhvWnEgQaGpZCWhjB7Nwi+rIIhgoiueuPj5VE12UgA0dI0 h3oYYd9MkdE1qfpUX72Aat2uQTVWut57m3OIDEvheqy/KjoG3gPPP9gnWHvbvLTR5cDr N8aKLr3ik3cVQ/ZjSY56pHpzWz4ou7/3bqoVW9jSxs1angf6mLpdQeVnNoc+8EJP1btk NF2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769523; x=1692374323; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lhePiwzsSx/PL85mddTkFwpXPwkG7Z75k06o+iuXV0A=; b=YqN2FEhlLDdIeRhjxsVd+C2OUd4q0JHxOcN9NSIMiQ13Ud+wWCFPsqtHJ6Bd6QY2Wu xictxMBW9a3T4LVTcNYQAg0N0dBFtooJtZAb9vHavh5BQYkNsiJzdPsigjSM/Aw4I9Ez vH2vlfmsv1mlwtXHhGAdd31N0XdrC+6nSMYcLa6fBNeMl+Sh8MLneT7oJZFdLomITICJ YDWfNidgkJfcj1IPFvCs1I3PzFgwazqxGBct0gmfl3CFh/F8fu7DhmnxQMccIX7XUMdR /VAEQdJfVaZM5riPIWsnc9JYUW4YoCy7UEze9ji+uHoTsSaIhfmikyXaZd0qbUWv2ejD DZHA== X-Gm-Message-State: AOJu0YyX4GcEncmsZXZWJ9I6iSR6q5cV7NQ/o/kafGF2OL45jTFGTGw9 YnluceOvMkpYonc8timkR55qmA== X-Google-Smtp-Source: AGHT+IEujOlzrfqvXdCg0+L8AtbpF7nTqrrFN85u705jORmwlIy3xMjlO1zC1yyK/tf3s2Jwb6Ap3Q== X-Received: by 2002:a05:6512:308c:b0:4fe:8c1d:9e7b with SMTP id z12-20020a056512308c00b004fe8c1d9e7bmr2115985lfd.49.1691769522977; Fri, 11 Aug 2023 08:58:42 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:42 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:15 +0200 Subject: [PATCH net-next 02/14] mptcp: avoid additional __inet_stream_connect() call Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-2-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3783; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=9Qe781+27wzhv16vF50KO5HsGzkjYeuVU2/sb7jT8+c=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqv5fFsBgTBTnGPQG9RVKTvL3RVK7VoW1/dY tAt+/hU8biJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c4sGEADj8+wJ8gLXhu4xLA3eshwVHpAUMPU6fl5G1adbkUaHa4ymSWx/xIIWUFc+BgqfFa4bUHA JZSHhjd5Ui/PTvxdKjznOkZlfpJJrXAke5riO8m2bkSLlAHIyh6YfaeXIZ4BqylD8FjjQi8fu/J Mi7HshwB5pwlR6mPcviJi8hiUV6ha9Txs/2nJ4l0uVpNw9i37VyzWW7N7S6MipOFkCiwmQrpnLo 0Hf69GX16W8QNlyvUxNcBcZr2KilIWTIYAYN/LvyP0TmzCKSAaQqKPqXBRwcDxus7tn3BxmRHig aA4FJPpHoM5XRCz5EtPtH5NNKOWWcUrsTlhiWlfKwcGqdVZwM5yTeD2U/LvEcyC43MMhUsTsBk2 KmM8E+oeTleZtGwTWAuD/dJjtY+KrW86S1iheFW9obk9GQIJNTK8SUzzRBhmF3hdpAZKQlMcNGc KZfbu0kd7uPFy6vaAtDtURGiU1YWRx0GT8SNcl4BxqzalwVQaS3oF0VdQkAE3yE7XC7u3kmDsBG XjrvyAU9j8Au9o0OtUEbvr8FST8dYjQdG8z/il7pD4pHB5FALIw5jnDpXLIFWRf91KIIZZQAQh6 7XwvLCdlTkwdU3yeM4FvlDciFXTqzbUHmjQMzSh+n7cLweyaMLk6p0fdSDg138LeQLLqjXfAewy fztkK3c9TEI9XkQ== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni The mptcp protocol maintains an additional socket just to easily invoke a few stream operations on the first subflow. One of them is __inet_stream_connect(). We are going to remove the first subflow socket soon, so avoid the additional indirection via at connect time, calling directly into the sock-level connect() ops. The sk-level connect never return -EINPROGRESS, cleanup the error path accordingly. Additionally, the ssk status on error is always TCP_CLOSE. Avoid unneeded access to the subflow sk state. No functional change intended. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index abb310548c37..b888d6339c80 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3589,22 +3589,24 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) struct mptcp_sock *msk = mptcp_sk(sk); struct socket *ssock; int err = -EINVAL; + struct sock *ssk; ssock = __mptcp_nmpc_socket(msk); if (IS_ERR(ssock)) return PTR_ERR(ssock); inet_sk_state_store(sk, TCP_SYN_SENT); - subflow = mptcp_subflow_ctx(ssock->sk); + ssk = msk->first; + subflow = mptcp_subflow_ctx(ssk); #ifdef CONFIG_TCP_MD5SIG /* no MPTCP if MD5SIG is enabled on this socket or we may run out of * TCP option space. */ - if (rcu_access_pointer(tcp_sk(ssock->sk)->md5sig_info)) + if (rcu_access_pointer(tcp_sk(ssk)->md5sig_info)) mptcp_subflow_early_fallback(msk, subflow); #endif - if (subflow->request_mptcp && mptcp_token_new_connect(ssock->sk)) { - MPTCP_INC_STATS(sock_net(ssock->sk), MPTCP_MIB_TOKENFALLBACKINIT); + if (subflow->request_mptcp && mptcp_token_new_connect(ssk)) { + MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_TOKENFALLBACKINIT); mptcp_subflow_early_fallback(msk, subflow); } if (likely(!__mptcp_check_fallback(msk))) @@ -3613,27 +3615,42 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) /* if reaching here via the fastopen/sendmsg path, the caller already * acquired the subflow socket lock, too. */ - if (msk->fastopening) - err = __inet_stream_connect(ssock, uaddr, addr_len, O_NONBLOCK, 1); - else - err = inet_stream_connect(ssock, uaddr, addr_len, O_NONBLOCK); - inet_sk(sk)->defer_connect = inet_sk(ssock->sk)->defer_connect; + if (!msk->fastopening) + lock_sock(ssk); + + /* the following mirrors closely a very small chunk of code from + * __inet_stream_connect() + */ + if (ssk->sk_state != TCP_CLOSE) + goto out; + + if (BPF_CGROUP_PRE_CONNECT_ENABLED(ssk)) { + err = ssk->sk_prot->pre_connect(ssk, uaddr, addr_len); + if (err) + goto out; + } + + err = ssk->sk_prot->connect(ssk, uaddr, addr_len); + if (err < 0) + goto out; + + inet_sk(sk)->defer_connect = inet_sk(ssk)->defer_connect; + +out: + if (!msk->fastopening) + release_sock(ssk); /* on successful connect, the msk state will be moved to established by * subflow_finish_connect() */ - if (unlikely(err && err != -EINPROGRESS)) { + if (unlikely(err)) { /* avoid leaving a dangling token in an unconnected socket */ mptcp_token_destroy(msk); - inet_sk_state_store(sk, inet_sk_state_load(ssock->sk)); + inet_sk_state_store(sk, TCP_CLOSE); return err; } - mptcp_copy_inaddrs(sk, ssock->sk); - - /* silence EINPROGRESS and let the caller inet_stream_connect - * handle the connection in progress - */ + mptcp_copy_inaddrs(sk, ssk); return 0; } From patchwork Fri Aug 11 15:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351062 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F13E360C2 for ; Fri, 11 Aug 2023 15:58:46 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52B592723 for ; Fri, 11 Aug 2023 08:58:45 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fe5c0e57d2so18754685e9.0 for ; Fri, 11 Aug 2023 08:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769524; x=1692374324; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=v41qzMf6LvZ79BWScnJgfS1EiY59Q4nhSyLXYX9clC8=; b=dCpP57fWagMhSfkoq09ZTOyreAAn1Ol4VHCZxHRN1quTTKFwgC5E1TY/3szUZL+Nho bi4MwaKRbxx2jdBAnsIcMtJ/394azV8mlkBhG36GzSzQZ5lKHCYFHypiuKOD1yxm80ZZ hRvJVXtb9dGHvUk8u0sgnWydoFkJ4Y8Qn2NY5WDC4BPJitlQajjAYA9BaAffFNNTduFX dHRpKdIRCekz54EmvfTOlGwds3C06vC2AzPbvBEIwoc9VNypU2VpHoy4clF8101b3udq dOneavoGfDsaA9N8+0BoJSk6B4vRg+W5CKsNwoNmUWG5dCMcVX9ZAcroED7Jv6GVIs9S kZIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769524; x=1692374324; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v41qzMf6LvZ79BWScnJgfS1EiY59Q4nhSyLXYX9clC8=; b=evPuS5dBTDgokXZnwss1Hh30d8FpcTKrapbjizhnYx6PQnHfWbojgJ0HSnDtkdLePi 7VcpO1xQB1QVH6rak+dAR0fqGOiEzTI0wXjefLSXO/QBN47m7r1J38O7O/XaLI2fWZ9Z dZxWs1BRr5nlhCdvpE+8J4jImVgvSPKYH74wVn9/m9ukixPmGZjLofJg9JWpzyo4iY3Y TsSKKYBy7jlpwOClwzrjJRZPNFaEHW5jOGj0VvHGTd1s45qiDrVE5x3n2sCKRCoMjbzf 022ZRfhLtpTA0f9XMF13jcTuNmNvSXZLeDqtEPvFGES01NOk1GA1OhImxrJw2J0/E2pD DZsQ== X-Gm-Message-State: AOJu0YwkstuTR5ov4H4qoI0YonuSd62RNZOITDfklXcpKm19QNq5ju7j e00Ki6bLN0EGuKDoUssPLDvmlQ== X-Google-Smtp-Source: AGHT+IEkpl5SbnBobq9PFSDtqBQa20owAg6YgDzSe6V+rMq1bi6S/v8n951Yt0Kko0IVOqBq/E3ITQ== X-Received: by 2002:adf:efca:0:b0:314:34dd:aaec with SMTP id i10-20020adfefca000000b0031434ddaaecmr1889820wrp.8.1691769523941; Fri, 11 Aug 2023 08:58:43 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:43 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:16 +0200 Subject: [PATCH net-next 03/14] mptcp: avoid subflow socket usage in mptcp_get_port() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-3-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1135; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=qK4HL7ezTejvaB3TjS+CX/NlLTCXy1zfWJooZqvAatM=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvLUyKj/mYOz62URiB0KFWHJAuVmboKVIMR 4TcaDRhCOSJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c8LuD/9b7fcRKlNJsRt+MISnQc+hRMDgQiu+4c5P3Dbqv/qbP8THtVxf4LdUWcBeTeV3dqcJir/ z0fAK/4dEvm08l8ew1OHXViLxS77ybbKIrN4azBbEnDCDnOiJc+7Zetxuwv2Mc2+rthfG8V9uBZ 7tvB8ET48AjFga00QxJd3oH1PE2Rj1r+N22oyH/bFxc2ECrCJZUo+ZUfh9FBhED7UXEIT3yyQbG C3EJCT6WkPKj0ROz7tPh5Zk2iODubNydmNdiKcwmdGrspd5UC3k9b7tkPXngeOZ6mdMDv0Wu5+v ne3eNtzm6rufhdIt1yhMVWUu6QCK9ilhuCo7PPE5KOcvxMm159bpU/il2t9mCWzlj8B9kWW9yKk vcoINOl/nPOZd2SmlVlO+qDhp1fXg5T20Wc8h1E7iGvkKkOLwvQid6Q5ay6KwnMtN0EfoB/bUXO nSYeL5urXLDgrToWfdlL/HXbvdLt9w/0OR4DXeFHRLu98KVQo3x6ngDnXTxJwOEeQYBmJznF+zE 3J4t29u7nqHNjUF06rmss4nPN8o1YHUvMm6vilrRJRM8tqG06B//ajcFqXEYe+G98IOz9Ah3wgl cj6uShv8wlaSvj94mjIdtldrdZcN1/64wQsmS6ByshKqXFkwVv1W8JDXU2NdrlT9cORnrxOiCi2 4R/CJi0KXEXOtvg== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni We are going to remove the first subflow socket soon, so avoid accessing it in mptcp_get_port(). Instead, access directly the first subflow sock. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index b888d6339c80..891f49722263 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3405,14 +3405,12 @@ static void mptcp_unhash(struct sock *sk) static int mptcp_get_port(struct sock *sk, unsigned short snum) { struct mptcp_sock *msk = mptcp_sk(sk); - struct socket *ssock; - ssock = msk->subflow; - pr_debug("msk=%p, subflow=%p", msk, ssock); - if (WARN_ON_ONCE(!ssock)) + pr_debug("msk=%p, ssk=%p", msk, msk->first); + if (WARN_ON_ONCE(!msk->first)) return -EINVAL; - return inet_csk_get_port(ssock->sk, snum); + return inet_csk_get_port(msk->first, snum); } void mptcp_finish_connect(struct sock *ssk) From patchwork Fri Aug 11 15:57:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351063 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B32FC2AB55 for ; Fri, 11 Aug 2023 15:58:47 +0000 (UTC) Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F8CF30CB for ; Fri, 11 Aug 2023 08:58:46 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31765aee31bso1787345f8f.1 for ; Fri, 11 Aug 2023 08:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769525; x=1692374325; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EwluUaIaFp8xw9bbqeJza0dSEd7d6Y+8KVbDaj+RAU4=; b=RPmoWFEUY34CsBWB1T3YgIpK7QheQyy4afzp1jWMob8P8SIQRh71QllzXtbBnu5ypi 8hFjDnYvAwUeOjangHtczaddwuBagCWIlcyDbCax8XLaMVpJp1lNqfcGtxwBpJXY0lK3 x/bHsUOPFYsvmYLaZv/jhe5on7mnv2jPxhfHlWoO+fxC2jYt0v2XeQeXY+kFM68ChsRJ dCVBBTvuHcHF1dj0TGHrwyqkhkZmqmy16SCK1qseyFHU0T8LXOkR/m9oClhuK93fAde3 bTA348TQfYgGgX+cKiXtf1EF6CgXK/Q6HNB7BCuJCHCEHpLjNZPduLRaWcPWN/Mslx+0 TKtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769525; x=1692374325; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EwluUaIaFp8xw9bbqeJza0dSEd7d6Y+8KVbDaj+RAU4=; b=OKDYbliZiJoQ/7YtmuuW3osrKXEplP5xrhDDNWwClXUM0GQgfNGBehJOIZLuuyb7dH V0XtoMms8i8O6yC2jAxsXFeLKGgPopwYKPtG1Ef4uqtCvbheziiEBUZa1DqO5LQgir5d TPHVVUiSCkJnIgdEq7+0fx+2zaX+nXIAIaqSbfKV8jQ8f5XXPHr/HwoqpH/lgDV3HRrj Icft3G6ma2gXIcGauFXbz6wp2tRC3Hz44bZGbY12Dl42SXYnUBP0PPw17gHuPENtiLpp rV9FNlZ5Xe6J1Os/JT8tL6bIhO9RPEhRriFpxELVBdx+6hE2DU+TIbutsm8ce+sMWxCp C3wA== X-Gm-Message-State: AOJu0Ywn/Hd4ONv+RxkEsVqkJ2yOEqpNlItEQQ+XUVvurLAJb9YBsKMd P0+Kp56uc9ZuPAb+8sW3Maee4w== X-Google-Smtp-Source: AGHT+IHBz37I7lskQLuIvJ9UxsVV8epJemJB05nNf6IU/WnHy8VNp7xJ65qSymo4pOT8HF3AvfIVnA== X-Received: by 2002:adf:f042:0:b0:317:15f5:a1ca with SMTP id t2-20020adff042000000b0031715f5a1camr1780613wro.10.1691769524854; Fri, 11 Aug 2023 08:58:44 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:44 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:17 +0200 Subject: [PATCH net-next 04/14] net: factor out inet{,6}_bind_sk helpers Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-4-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3806; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=BsYDUl/DUbLVHU4Xpb77aTgJyY+cTGBHLN6ctIYlp+g=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvcGmbN1LPAIgSii681NHqkjqbG/PqT7qgh uX2O1Pdu8GJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c9kDD/9Rkt0oclO8gRzT4WMkWSflZ5DKPreOTVjGK2jDzc+Ey2XwhTDLf34/LzizqyAiyyReo9I RA4Kqa4wLste8hiIZmf69CR8WpBwgjmK4k8S9Awwi4g1Iy/21RbOtqxwcf4HprWrOJhQ/iC363F TKTDGI8YHuSd9TJFB8c1YEz3aNvuD67F4n1KJ8x9V7jRqnSUCUKAFShc0KC5I5dqi86QAvV7sud uPL7+fyUb70hhV3GJMrojHPgQROlTC8fQYTLV4bs2Yf52728rCx/zMS2MbvNxWkCYB310cAnDj+ 2hqxDhyHP6Y0pvsCs4zpXEfq1q9RW52HlM5WBA74Nru9OaLhSQsI7YIiWu09GSIJMFzV0U825vv 09F5P85g/Bo0Lp5lwmKHp20P98IHU5VYzxbd5uaQB1JU9iHX/CDD9w6lWZKScdgfhVk9NMto7S2 zeP15nQrGFzajLSffRNsofkuRKu9DUhvMRSdxdkbTGBHR4Q0qjlvEF4VYgTs1LeZq6+tXwnPT1r Z+Fynw1LmFa+TBv+KsTKA5SUcjPZ5pP3KsBAvVK0H1k7zSQiGM8v4UhTHrcjUxLYkzeIjM22I4Z OxTcbrUNPVKhAJ48mQcQlyx1tL9hONyS1Aiqtcwhm2lkNjEJ0qRLWu+aXtu2sJamxLPglVCaMZV p8BNC20K7enjzJg== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni The mptcp protocol maintains an additional socket just to easily invoke a few stream operations on the first subflow. One of them is bind(). Factor out the helpers operating directly on the struct sock, to allow get rid of the above dependency in the next patch without duplicating the existing code. No functional changes intended. Signed-off-by: Paolo Abeni Acked-by: Mat Martineau Signed-off-by: Matthieu Baerts --- include/net/inet_common.h | 1 + include/net/ipv6.h | 1 + net/ipv4/af_inet.c | 8 ++++++-- net/ipv6/af_inet6.c | 10 +++++++--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/net/inet_common.h b/include/net/inet_common.h index b86b8e21de7f..8e97de700991 100644 --- a/include/net/inet_common.h +++ b/include/net/inet_common.h @@ -42,6 +42,7 @@ int inet_shutdown(struct socket *sock, int how); int inet_listen(struct socket *sock, int backlog); void inet_sock_destruct(struct sock *sk); int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len); +int inet_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len); /* Don't allocate port at this moment, defer to connect. */ #define BIND_FORCE_ADDRESS_NO_PORT (1 << 0) /* Grab and release socket lock. */ diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 2acc4c808d45..22643ffc2df8 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -1216,6 +1216,7 @@ void inet6_cleanup_sock(struct sock *sk); void inet6_sock_destruct(struct sock *sk); int inet6_release(struct socket *sock); int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len); +int inet6_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len); int inet6_getname(struct socket *sock, struct sockaddr *uaddr, int peer); int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 9b2ca2fcc5a1..2fd23437c1d2 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -431,9 +431,8 @@ int inet_release(struct socket *sock) } EXPORT_SYMBOL(inet_release); -int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) +int inet_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len) { - struct sock *sk = sock->sk; u32 flags = BIND_WITH_LOCK; int err; @@ -454,6 +453,11 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) return __inet_bind(sk, uaddr, addr_len, flags); } + +int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) +{ + return inet_bind_sk(sock->sk, uaddr, addr_len); +} EXPORT_SYMBOL(inet_bind); int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len, diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 9f9c4b838664..3ec0359d5c1f 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -435,10 +435,8 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len, goto out; } -/* bind for INET6 API */ -int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) +int inet6_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len) { - struct sock *sk = sock->sk; u32 flags = BIND_WITH_LOCK; const struct proto *prot; int err = 0; @@ -462,6 +460,12 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) return __inet6_bind(sk, uaddr, addr_len, flags); } + +/* bind for INET6 API */ +int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) +{ + return inet6_bind_sk(sock->sk, uaddr, addr_len); +} EXPORT_SYMBOL(inet6_bind); int inet6_release(struct socket *sock) From patchwork Fri Aug 11 15:57:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351064 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9768A360E0 for ; Fri, 11 Aug 2023 15:58:48 +0000 (UTC) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67CE930D4 for ; Fri, 11 Aug 2023 08:58:47 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-31956020336so809880f8f.0 for ; Fri, 11 Aug 2023 08:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769526; x=1692374326; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=VXo0sd7SwYNHKnxVFphwOPuJHuje+rAleUnK3N6bXns=; b=13y5vALU9DW+JJ2uo9mfksvy1dk73siK5uzK8gc4SXHP1eziiEQAFRO1aTUrsZv0jW 6cakbID3ywLC+T/uZ0W+bymrKCy3C7WnFOOCVDNEMlTMc9m4fVIqgMGN4N38p2M3mtI3 SSO8Pdlnd3VH3/aZi5bjADFKUT3Q1HD8gZia2XkI5MVPr+qtBRnWyiGimYv7U6zTQeyW piuCFbEIP6A5yAvUzcm+r8DVdaQ+vvLRvJ6ayoZyKsTTmrqnjosjZ7tbJ9iZWZZ/TnTa NrY9Uz44enNrAfN++CU1qupQJDDrhLxlaB8gab1WaOlj7nVwStKdgpN43mrP/tK1PT6p UNjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769526; x=1692374326; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VXo0sd7SwYNHKnxVFphwOPuJHuje+rAleUnK3N6bXns=; b=XwUQtH1BknDFOZCaT+oVUWN3Ep8Pa7km4/+nlRVeUyyV5QafKeo2VRUzbACYmCpvqO yQtLMi4wN5m8Ynf4tSkWEkC0EdGZzpGzIFim5EzcKECLb7sStqMPyRlBmjKjYVqp4jn9 TBfTUUvKYuMOHRS7N4HJ58zQxMnfRQeAJTQzTrWxvjLUBunvj4aLNXUO/HdBxdCgc99y Kxi7IDeaOmjQiGSCHHmIqNP9N2k/YFqzTHPMwOw5Hy6CMi0YwltjCSx2SFYanMST6xMJ eV16ftzJEETVILylj/rpjqsXIpusoC6yHJgNciRgTSWpzC30WGIcZg1PbL63mYs2O0GC 6ozQ== X-Gm-Message-State: AOJu0Yzt/6f4y+tzOoF3CT+yyupHj2+k0aammc2iQhQlODSK/227boHj zfNT+oTe1WMvmWqL2s0arcsDoQ== X-Google-Smtp-Source: AGHT+IFJPySODNZASWJwgumOMgIlOK+JSgpHaW2lQlb/mSeShN4RnZANnmzMasJy+nIeIULx7YAy4Q== X-Received: by 2002:adf:d0d2:0:b0:316:fc03:3c66 with SMTP id z18-20020adfd0d2000000b00316fc033c66mr1971213wrh.3.1691769525729; Fri, 11 Aug 2023 08:58:45 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:45 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:18 +0200 Subject: [PATCH net-next 05/14] mptcp: mptcp: avoid additional indirection in mptcp_bind() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-5-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1547; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=cdwy4jZYJOHpcHNPu/Z9TpyfzeGedcmkSzxHG6aP0d4=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvp6igb6LLgMw0L0m3fOD5/XhmzXvqIteac rzBRElskEaJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c11KD/9UokU2haRftpKeotauDl76HX7tCqE3iw4xRk5XJvZkHuq1stH7gm4PN1Yb654o8nk0d4f vOd44O3is3+wImlJijpb/JC4XnDm7UIgPivo49Y/Ffa8oBeF8H3+mZE2jjhZkP46Ah0xNIFd5vK +0ho6WTK9/kxzznIugKjyHu9ILe0Kz40Nfwyu32EKdQrbjk7ho1/lMDxb0YcBADaOfx7KN1uU2j tn5+X2GH9SEk+zLdjmVB0lqeHERql3n4P/Xk6MJ8ajtc+A4PWWNZZ3gz/JJ9asaSWBD8yKzGcfg zN7Zev5BJmqRCb4QFh7RbkFBmFIqOQ5ROrkj/HkVlC5En4uA+g5g6LrbpC5adtjxiaoPKKdSuGN d8kHbKIVwn37lPm0TKU+8zMlqFKglgfCIunqehisK5DLANS5Ryk7XXzTQy36dI33h5pc5PluGbE h20VyHrAQ6wVRiFdkHwuR7rtijtfpxAr/TEn7A8ZnpOIVs6uM4Ia2Lv2P5ktwgO+O/v5mAoxAlj KBTmZ4Uorsbaj7FuTZF8xGHVfwcD9ft3oSlFiqN1ou5eJQkRXp3ZTel3Pq7oIQmFDHlegKTGPZL KXtkHRCYfIIUxz1pnWvZJvjrZ/xrEiU86VoSM2xkGvK2fYQuGPNKOfgXgAuaUxCbWJTTSyB7pR4 ltiVCyO+859qRgw== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni We are going to remove the first subflow socket soon, so avoid the additional indirection via at bind() time. Instead call directly the recently introduced helpers on the first subflow sock. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 891f49722263..5b4d6f0628a7 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3689,22 +3689,29 @@ static struct proto mptcp_prot = { static int mptcp_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) { struct mptcp_sock *msk = mptcp_sk(sock->sk); + struct sock *ssk, *sk = sock->sk; struct socket *ssock; - int err; + int err = -EINVAL; - lock_sock(sock->sk); + lock_sock(sk); ssock = __mptcp_nmpc_socket(msk); if (IS_ERR(ssock)) { err = PTR_ERR(ssock); goto unlock; } - err = READ_ONCE(ssock->ops)->bind(ssock, uaddr, addr_len); + ssk = msk->first; + if (sk->sk_family == AF_INET) + err = inet_bind_sk(ssk, uaddr, addr_len); +#if IS_ENABLED(CONFIG_MPTCP_IPV6) + else if (sk->sk_family == AF_INET6) + err = inet6_bind_sk(ssk, uaddr, addr_len); +#endif if (!err) - mptcp_copy_inaddrs(sock->sk, ssock->sk); + mptcp_copy_inaddrs(sk, ssk); unlock: - release_sock(sock->sk); + release_sock(sk); return err; } From patchwork Fri Aug 11 15:57:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351065 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48DCD360E0 for ; Fri, 11 Aug 2023 15:58:49 +0000 (UTC) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F60C30D5 for ; Fri, 11 Aug 2023 08:58:48 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3178dd771ceso1940264f8f.2 for ; Fri, 11 Aug 2023 08:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769526; x=1692374326; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Y1qLyx2LWnWiVDIicSTKWPLIL8cOkrsv9pt//BNBZb0=; b=5CwpXuyc3e6V3L5gpSouGk49Q1W6jcHqBw2n3JRh5rxeWROc6RP0WMlI3du/myOPmQ puaHwGDQzngqlZqsTSl1AJYZUARvyusyNSZDnqqD1G+WkC9kGhL8KS23G/vKMnSFqtwF F7MlilSG9CMyFf736o5zzpNvtmnNjorFEFiCknqz0CAvpOrI22/K2lxvHZ1CR6j+I2+t yBytN7X3CaMJrgOdnRU2O2C22RMQItsSHTeRNPSD0lvTGaiImWpKjiAnX20Hp52EsKSY 3DaEGNExNcg6Z7Vlnqz+wkuSz9nMG/BL4BntoOh1gFyKMzX2YJIMAH4O1xD/GWyWse9y j+Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769526; x=1692374326; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y1qLyx2LWnWiVDIicSTKWPLIL8cOkrsv9pt//BNBZb0=; b=ZqHivWtvkOeGKQRpnAeCvr/f2BUHm02xQj+tdFuUEKwCQg2rvwlxMmkaEci/eYsKTX X1qvgi0Kqs2BeXL5qk/uxinLirEXhlDOI455gLcjUoiVSoptt2e7rO8bFf1fbq6BNr6J TsyDfPtT460kynz/H+6VxjmMFsDjl9ESmx7vo3sSDPMMeCkoFIJtz3R87kx1edWifQhA Rmh402owaIi1YiqDY22ptlTCy0Ea4ygWUrFc5FFET0F6Rz7v1mRGtwajVqm+Eu5mchdM inyN0Exn2ZZ88OJGiSjwf4WT31qqzKn54JRsw4JY7hlAViNvZK95oNr4WhURo7qGvLv0 f3ug== X-Gm-Message-State: AOJu0YyHkkhZvhz19le71eQ2Iao49wox5sMf605+1NOEWIy0hvLcNrhi /RmCSX5OYIA/oH+sxCc2mkR2OA== X-Google-Smtp-Source: AGHT+IGO2ZGpfasS5e61DzCME3nhIJa+sQZctwadJVKZRETnlnDPmN8+cX+ArLQaMqp76/LqKTpriA== X-Received: by 2002:a5d:4ecf:0:b0:317:5f04:bc00 with SMTP id s15-20020a5d4ecf000000b003175f04bc00mr1863528wrv.27.1691769526605; Fri, 11 Aug 2023 08:58:46 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:46 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:19 +0200 Subject: [PATCH net-next 06/14] net: factor out __inet_listen_sk() helper Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-6-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2806; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=bTkRYVwJ7Bz5xqxHF7Zx1jU11iINDUJMHCOsJN7EE2Q=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvWJ+40gT5DCRm0wzA6GWW71En1AJiVIL0q cyGXtBLMdWJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c5E8EACO1BlTw3jWXRxMGk/AGNAJ7LKBgy2u6pKDc2BZIqqPhyn6pLcNgjgTXPkhX5zmfRAUkjf 2H2t2dQ7K2uYYZaCEbHDQgyD8CXdVZbJGXgt/oOY59A6QeBNd0ZMsp5PcFv0hhnGgHp5On4nume 7zQt1bR3lJBlXN2t6pFywGTU8LuMn+bakwUL8yv3rK0OfPRfhmjpkB2koU0MsvifsZt8a2JY1Fy vH6A6mQ8NVO6NOpcQhIFJHYODBvCOz9e7z5l7l7woFiZ7Yp7GTI5qY7CKvWk7pdexEC9M7Fph9M 2akdXXS50JCWa77DG5ox2ae+Ud/hASytOKywNgXRZm5vS/3IJxsOpDpFxRAq/9C0pf1hHmDPsrC Ip7l70RMDt9bXvYsKCESV7EZpL3Uv/CvIRH06FUjngzMLZ+/kWZVRDJtWUgUpVK6+pxMSg9dD8Z DVc+Id57OLi/QXArLKIVja84CNuwy5AK3IdL9im85QqqDNVXT3C4td4aaeS6KP7mUWxvTeCfRzR 5Mdv1YvILBTAqgV0kFvcisFNzZZ8QRHrxWx2FOm1X9Y8tJ0cLYROhjJprdMtz7lMWa1aytvSGo8 R0XhXB9M/Y31n9yFOzHHpCHNits6YehkcrYWjz9Q2Nuyem1eaYlP+9NfxNNS6rnw4XzLJbFNsEl uEXsD8ZExbvWA9Q== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni The mptcp protocol maintains an additional socket just to easily invoke a few stream operations on the first subflow. One of them is inet_listen(). Factor out an helper operating directly on the (locked) struct sock, to allow get rid of the above dependency in the next patch without duplicating the existing code. No functional changes intended. Signed-off-by: Paolo Abeni Acked-by: Mat Martineau Signed-off-by: Matthieu Baerts --- include/net/inet_common.h | 1 + net/ipv4/af_inet.c | 38 ++++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/net/inet_common.h b/include/net/inet_common.h index 8e97de700991..f50a644d87a9 100644 --- a/include/net/inet_common.h +++ b/include/net/inet_common.h @@ -40,6 +40,7 @@ int inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, int flags); int inet_shutdown(struct socket *sock, int how); int inet_listen(struct socket *sock, int backlog); +int __inet_listen_sk(struct sock *sk, int backlog); void inet_sock_destruct(struct sock *sk); int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len); int inet_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len); diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 2fd23437c1d2..c59da65f19d2 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -187,24 +187,13 @@ static int inet_autobind(struct sock *sk) return 0; } -/* - * Move a socket into listening state. - */ -int inet_listen(struct socket *sock, int backlog) +int __inet_listen_sk(struct sock *sk, int backlog) { - struct sock *sk = sock->sk; - unsigned char old_state; + unsigned char old_state = sk->sk_state; int err, tcp_fastopen; - lock_sock(sk); - - err = -EINVAL; - if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM) - goto out; - - old_state = sk->sk_state; if (!((1 << old_state) & (TCPF_CLOSE | TCPF_LISTEN))) - goto out; + return -EINVAL; WRITE_ONCE(sk->sk_max_ack_backlog, backlog); /* Really, if the socket is already in listen state @@ -227,10 +216,27 @@ int inet_listen(struct socket *sock, int backlog) err = inet_csk_listen_start(sk); if (err) - goto out; + return err; + tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB, 0, NULL); } - err = 0; + return 0; +} + +/* + * Move a socket into listening state. + */ +int inet_listen(struct socket *sock, int backlog) +{ + struct sock *sk = sock->sk; + int err = -EINVAL; + + lock_sock(sk); + + if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM) + goto out; + + err = __inet_listen_sk(sk, backlog); out: release_sock(sk); From patchwork Fri Aug 11 15:57:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351066 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F377F34CDD for ; Fri, 11 Aug 2023 15:58:49 +0000 (UTC) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07C5730DA for ; Fri, 11 Aug 2023 08:58:49 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-317798b359aso1884046f8f.1 for ; Fri, 11 Aug 2023 08:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769527; x=1692374327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EyRx/lqS+isYchr9XgPLMFHBFRIijA0curLoMvnrLXI=; b=A4x7JHBFtN/v8rQSnnmwXaQxQTM977zx8b5onDqAtC+l9kHCtn/C8+sQOS8LRmmfgR d1DCu1MVk4eeOTT9Q4gsBGPdbSEOvESuLPp0Q2NQJN/7Eg/EkPG87mrn4lFVIrN2q1qk vFxh+WcOIlgOVs2nkW24Y9a1Qg4/y6nr5isopIgjw74w5mQabIO1LHWXoDVqgAOraLlU lgbJos7nlJM4hpQXti3OzEvwtX+X+sE5V4gHyn5/wEB65e2jFrucBCuyVVZja7IVSEE2 oS0QSjgnoeOTfoL0+J23cW5hS+q0Q2WJmKFNMaYM42XWJ1UKxNDyU6UcaspQx/xWGQYp HmLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769527; x=1692374327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EyRx/lqS+isYchr9XgPLMFHBFRIijA0curLoMvnrLXI=; b=UXPsPP/O8KEJjmiEEgZgkWZQ43CxR5Hl58u0v0YL8xOsPKIALdKY6izBRuPEudEYHd VQiLTcLmTbd7FNfVXE/vwyCxgiJNy8dUasNWpDVfa2u17lWTB592eopgbu+MJ2QAiCZq boJC86yldHidfcxZNg55B9pRn00YaRbTHiMmMrQlBk5kcTOudFvJo+sYR4VcaJ4GlWsy LuShah33GZP++PIH0Ad4h/cwRCoJmGuJga+Ef0XVRKY2i0pwCT8CmYYhqxB2/wkrFQLB X37vxNBjiDu5oKnartpVBDi2ZiQtx8upGR+tKdT9vfoqUyImylIrHMbuJbn2X5TIfYZ6 a3cQ== X-Gm-Message-State: AOJu0YwNJnMUy8MKiWnx1zN+pe01DQ/WswaB/Pr+z3eXJwUDOZf7dOhe 8Gu6YiuMMPp3lCP67y7HGBL0iA== X-Google-Smtp-Source: AGHT+IFZ0atisWKPvBjtYJDx96JtPWXfkTzMHwNbYsicETFEqF/de2pxA3IOn8IiCi9B7L2N06u4ww== X-Received: by 2002:adf:fcce:0:b0:316:fc63:dfed with SMTP id f14-20020adffcce000000b00316fc63dfedmr1705179wrs.39.1691769527592; Fri, 11 Aug 2023 08:58:47 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:47 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:20 +0200 Subject: [PATCH net-next 07/14] mptcp: avoid additional indirection in mptcp_listen() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-7-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1668; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=uGv0GZryGFtqDT83EYsbNMTqvKrHGPnUvPWP7zmvWRc=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvJSlkomXuEhk3T8qOlOZZYYOSwumgYgTcj lJMdiQ9JlmJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c0SQD/9RvknM07vU2B7bycJBkHsghFJbpbcj/egc4zS2Q4FbOtFZ+n4uytsZjFaFu0fEXHdmwM4 fF75/DI2RsOcGg8d4Nu0RGM8yRu8gPBRZQIC+H45/7ld2tN6qZsSBd8ZAnxhlX2z4N0KuKaV5J7 u5EdlH5ubNE3tvGauOZzlaSDhugejcC9fSmjDz6sOxirfdGIrJKrftVKU3JekZJQMGW65B8kZYG gcM5+lUWNoNT/91bH7ti6qe4rcP8fxMTzX9OTflHVmM+DqWuZ/iO41mCrnVu6RgZBqhrnRiLveX CqP3x2VJBgzSHAfXaz9caEESzKNm+GKtJcXlfbMaPtqpYmB69rI+jU+eGrOe6fIozUw/3HN85pT Rrvp9jjK6CDlb1CRXIRgV3S7Pn7pwSnYayeRN0m2Eu7izBY4VCzI1GH3Rice8+oljgIp4tmxfYO EJ74fsybfqn7ARd7WSs0jIqJ/zNA74edhHrm5FUSMKGG1F9rUQimn3BN6DZpm9YMd46vwDXr43S bM/QR1Q1QxZB4rgdGoJbR460fXqhD36Yq8ldZH5P9edz8ze5ZgfcGxBxGei//TEUwKvZx2O6Q8Q QJiGDSkqYnJxlMvJMNJxkOizkDt7+zGPbtl4LAyqwzNVUt2IjMTBdbew5hj6ZhrenvBcqFf2tqd Q601hSoSt8x2g5Q== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni We are going to remove the first subflow socket soon, so avoid the additional indirection via at listen() time. Instead call directly the recently introduced helper on the first subflow sock. No functional changes intended. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 5b4d6f0628a7..d8b75fbc4f24 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3720,6 +3720,7 @@ static int mptcp_listen(struct socket *sock, int backlog) struct mptcp_sock *msk = mptcp_sk(sock->sk); struct sock *sk = sock->sk; struct socket *ssock; + struct sock *ssk; int err; pr_debug("msk=%p", msk); @@ -3736,15 +3737,19 @@ static int mptcp_listen(struct socket *sock, int backlog) goto unlock; } + ssk = msk->first; inet_sk_state_store(sk, TCP_LISTEN); sock_set_flag(sk, SOCK_RCU_FREE); - err = READ_ONCE(ssock->ops)->listen(ssock, backlog); - inet_sk_state_store(sk, inet_sk_state_load(ssock->sk)); + lock_sock(ssk); + err = __inet_listen_sk(ssk, backlog); + release_sock(ssk); + inet_sk_state_store(sk, inet_sk_state_load(ssk)); + if (!err) { sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); - mptcp_copy_inaddrs(sk, ssock->sk); - mptcp_event_pm_listener(ssock->sk, MPTCP_EVENT_LISTENER_CREATED); + mptcp_copy_inaddrs(sk, ssk); + mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED); } unlock: From patchwork Fri Aug 11 15:57:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351067 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 708AD329BA for ; Fri, 11 Aug 2023 15:58:51 +0000 (UTC) Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39D4C30DB for ; Fri, 11 Aug 2023 08:58:50 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fe4b45a336so18671445e9.1 for ; Fri, 11 Aug 2023 08:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769529; x=1692374329; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0e3CJJrqZ7ewmH2P5w0S/0zIFsn4QxREbiOM6aZrWvM=; b=lX+Ys8CLIATfx0LJtFzeLQ0ERTTrxPkesrFPMmBBNHN86jFrD5P1lfm+ZuIU+kAt7e BKBApd8RB4H0cU1jcFTrQziVbtFXdP1duoGwh18rf/io955LcWi7us/52WSQe7pFxdrN EJwVzpvtfkWkZnUNNLZTu/xoWO5mMB33a6uemnlGsaUvGomWxdXoxtP0zmFEhhokvjCV j/sqlOHXHII4646BvzRoTJ5hcYJbNMEgjwc+ULaarg5W/hYVGjbZHwIv/en9my3r/+zp yt5LVvVLIh5SJ7x/IeBaD3TVW7tdwEaGCfOtSkZAIktPoya9afYeSPdirqU9498B2Sl3 IoDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769529; x=1692374329; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0e3CJJrqZ7ewmH2P5w0S/0zIFsn4QxREbiOM6aZrWvM=; b=NrScw/NJYfYyrRWeqr10n5w0XZFq/U9a1HXswnaQ9gSJVPCXmlZJicsLUW/CSfOkRY um5FfmPcWh8UcYq54dFJsylGEsh1rK5ZOpD7okLHjlehY+ZP0seuPDYDMOcRtq2Lh9aX dOLgy5uXzI8io2wL+oUKHwg3noJi6WjqDu7OKypJiF1rOROYG36ZiitaB3CWLdbWUwMo n6CP6qgiNaHTWDwm3ScmZS3EtJN2BlqPlce7BKiVuXSiWODIUPq0Jcug5UBBWwxnkqVe WBGcbPcgPi72+KTiuwk5X8HncE1k59qaKfN5vcsQNS6ZPfL/Ot0F5UXVWEjD8tv8Pdxg xsTQ== X-Gm-Message-State: AOJu0YxfRL/rgpHl26NiXpXzKPWWStIT/S4eDBBDPTgYqgFTUNrHPCkB YIbDRk6Q3uVS8Xp+TR3xaxqMcA== X-Google-Smtp-Source: AGHT+IEMRuVR4UsvMsf8IVtrN3B7SqSXCFwDWFlUx5pvxeBUjQjokyhxcx8/ORvwhtNlUaLQ2ZSj+w== X-Received: by 2002:a5d:438a:0:b0:30f:c5b1:23ef with SMTP id i10-20020a5d438a000000b0030fc5b123efmr1642236wrq.41.1691769528840; Fri, 11 Aug 2023 08:58:48 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:48 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:21 +0200 Subject: [PATCH net-next 08/14] mptcp: avoid additional indirection in mptcp_poll() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-8-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1163; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=J9VNeffJDPfkoJa+eIaJ2TO+2VxqSncVcduqI3h44xQ=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvfhQYxdq5nUH4ZAoej7J8+p2L5Lmk3Y0Jp 4uaCRiefWOJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c8j2D/4z5s9NgjC9q7QH5Jp/JvDdZkfDO89mpDeftND2ALbI0xuUPpP/N2wmHEm9wtubG3ZWDPP 1YHwLOswxY4RhycdjJc8NMo3j/IqTpCtz/hTNXmOdReLcv1BiuIERObu7456c46NuhYZbG2fepu j1sOGlUnf6LxHPb4MLyWv5PtU90T+gL+MQFyQr4j+uumiM719nFQm+yB7j7ULl08oD/x1ZjRdy1 BD8Sci4RpOCJJYZ5JK3/Ms6H1NOPsULBbPGoaVJks9OsFpEMwky9aPPlpDsQOQAfKVlkLp1mMZz UH4zdwDsJIhMC1USzsgCLBM7TZIu3lckmH6QikfyD1nJ/6R7G4jE2u3zJC6uqLWx8EJo74mfqUu hakjOElfGBTXTXCBLIDoBFJTDBEFspHXFtzxztgMGB7mDZIUJ2RcUwn4K8r1t7zBK2GhLfxQrNL mUHr3pJ/m/h4UuJvc9cyK4DHp6gN7PF/bRO+Kg0ZCTEp2zdoi8UEi24lqRRVZfJhVd2QR+1ueuK JZhzQl2UjPNt+UW6kN0DcNIgcIaBi+1T4l1O1zyx8jGXfyHkfC1GQ0DZe8C42hOD9d5//IZqhV+ T9uAVSAVqZXlJ1unylAdRkJ1lgXkkuRnOri0iROXZx/wK//VK6iWZodcb2jhuj2NaYq/xZr2oAq Q0T1caiGXyTPi4g== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni We are going to remove the first subflow socket soon, so avoid the additional indirection at poll() time. Instead access directly the first subflow sock. No functional changes intended. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index d8b75fbc4f24..e89d1bf44f77 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3844,12 +3844,12 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock, state = inet_sk_state_load(sk); pr_debug("msk=%p state=%d flags=%lx", msk, state, msk->flags); if (state == TCP_LISTEN) { - struct socket *ssock = READ_ONCE(msk->subflow); + struct sock *ssk = READ_ONCE(msk->first); - if (WARN_ON_ONCE(!ssock || !ssock->sk)) + if (WARN_ON_ONCE(!ssk)) return 0; - return inet_csk_listen_poll(ssock->sk); + return inet_csk_listen_poll(ssk); } shutdown = READ_ONCE(sk->sk_shutdown); From patchwork Fri Aug 11 15:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351068 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C92E234CDD for ; Fri, 11 Aug 2023 15:58:52 +0000 (UTC) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BD9330DB for ; Fri, 11 Aug 2023 08:58:51 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3180fd48489so1648483f8f.3 for ; Fri, 11 Aug 2023 08:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769530; x=1692374330; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8p7hz56BvINY3bYnl+8763aXFv1bqlZKj1UXcfxTM+A=; b=a1cUMQYvxGodmKZuN0U3paq8749qJLSolfZfU9LZW7mhsN12u/vcKYlNfVEvpeKua/ RSmJgd1SNHQdt4lIQsjrfenFY/IX2BrdTWGD9BQ80j3g4WZXiX6YQj6gNAsjrvPGxjes Ufmxo0b5XJenWZ4KJy/ajW8xU1VBSu9ujiwUAnGHkMiQw1VKWzyrxvlPjAVgRhPZpQwB 7aI+LtZOe2SUU61zO8ayLhK9z8ypD6Dw92oKbTg3/Tz9zf0rPFFTAT3sSuyEhIrJ5yyj E9sVzAsk3NTtBt5FEUTwRnB+1Hv5aujTj6AcCwU2IQrpWI3xPO/BYBbDQhzvpFMouPB7 PtcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769530; x=1692374330; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8p7hz56BvINY3bYnl+8763aXFv1bqlZKj1UXcfxTM+A=; b=VryrjPF/4cDTmTmLG4tOYQdhPUS0x8RS1gEbsRu+hdA4Fuk8JCe7rHg9cEKKr2RIoG x350hm45yyEbDbREXM0a33Xsry7wjB3hV4i1DL4b4vnzGCsWkgXeSZv71+n5AIM7JdTh 37plVzM+f5e0aE7pLys4J4GFqQk5w/4u7Po0zaKdsp3xfI5aFovdY9FJoDzN9qWOh3dG qgGoC6XH7CAltPPk3JtIhGJYMCawOmp0RlsJWqLNoSGX4pW3lp/SE7Qtj1NEnL6teN1I 4X9LNN1xUfnEMBbAv93HBT4NqWtTJ5WUzc/LUL5wh4t9TpaYadabwg6ikdMduFDuQlrU amLw== X-Gm-Message-State: AOJu0YzWNS+U3y2CGrxwAIPA/QuSYSNXyekILa7uARM7u41nT8/liOyP /t1FFbZi06wNFFqL9Lc1r0Ze9Q== X-Google-Smtp-Source: AGHT+IHuN2kBxo5vJotiYC5W0zdFQwerKWvpkbHQuZiEAiyVgP6xmAYbwPwozJl7J+DOCN6OUJ7+mw== X-Received: by 2002:adf:db02:0:b0:317:6262:87af with SMTP id s2-20020adfdb02000000b00317626287afmr1780157wri.16.1691769530265; Fri, 11 Aug 2023 08:58:50 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:49 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:22 +0200 Subject: [PATCH net-next 09/14] mptcp: avoid unneeded indirection in mptcp_stream_accept() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-9-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3045; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=ezLN5rJDn0TKO1JLa8QX3XwohNG5LslqBliGtaEoxsw=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqv/lFxB/q1xOo6Csx0Xdq2xu9hotDvV06g3 sPqycFbHI6JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c282D/0YBufkFft2xSGrrVTQKpXzWqy831F4wJMr0YYiSFFjo6t89EoMlCfqAA6Hi7PhgT8zjre lZ7XLHyFEoqT0kcRbZkRecPf6ufbznmbi0DSXRLLtW1T5yZCx+MSgGL+nddqIr+j7d5p8JLYWIC Uj9v5uObKodFM3Zc9KlK/aqJ0Wlti5is16ableDYRk+6u7QzLJVt6UUOgiAgDs3mNA/VCHoysOU 78L2m/REztuWfSsDwmNcl4dEsNn6nLfxo6uUJALQOR6NEVtrrhy8zBiWjBWGGS4swP7++luhdhN mUpnMYiCzxyx4rACw7tho5c5ruF+IrFkDBgwrm5B6s9FrvsC+ZqX//AB2dIbKVOXJSdjBOqwrVO JDLQBk06QM8GZiZVzI5+UZCfgsZwI3TTlRZJk1LrrxYCnSpLtvBOp6srC1V33iqUFaaqmESfHgn PgPRj4tqPwo/n53/etr+/FGO3B3HvatVudlgHJffISYDreLC44waaztHUMOFs4JraTim70bq5UE 4qCXED30ysbD0zbBVYxnMFYFmmkH2Ig2niuukH761p5M86YFa9lrS8Ae0CwsSosY35YYfw3H9+1 wH2Z9UUn5XiW//D8W7VJVz0Y9ACfBHxuBioJy5pqdJluWqf5E5Lr1rvE09vbUjkSd1pmOgzOEOI pJJ2zxuw4QcPZhQ== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni We are going to remove the first subflow socket soon, so avoid the additional indirection at accept() time. Instead access directly the first subflow sock, and update mptcp_accept() to operate on it. This allows dropping a duplicated check in mptcp_accept(). No functional changes intended. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e89d1bf44f77..e5ebd170d316 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3174,25 +3174,17 @@ void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk) WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd); } -static struct sock *mptcp_accept(struct sock *sk, int flags, int *err, +static struct sock *mptcp_accept(struct sock *ssk, int flags, int *err, bool kern) { - struct mptcp_sock *msk = mptcp_sk(sk); - struct socket *listener; struct sock *newsk; - listener = READ_ONCE(msk->subflow); - if (WARN_ON_ONCE(!listener)) { - *err = -EINVAL; - return NULL; - } - - pr_debug("msk=%p, listener=%p", msk, mptcp_subflow_ctx(listener->sk)); - newsk = inet_csk_accept(listener->sk, flags, err, kern); + pr_debug("ssk=%p, listener=%p", ssk, mptcp_subflow_ctx(ssk)); + newsk = inet_csk_accept(ssk, flags, err, kern); if (!newsk) return NULL; - pr_debug("msk=%p, subflow is mptcp=%d", msk, sk_is_mptcp(newsk)); + pr_debug("newsk=%p, subflow is mptcp=%d", newsk, sk_is_mptcp(newsk)); if (sk_is_mptcp(newsk)) { struct mptcp_subflow_context *subflow; struct sock *new_mptcp_sock; @@ -3209,9 +3201,9 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err, } newsk = new_mptcp_sock; - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEPASSIVEACK); + MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_MPCAPABLEPASSIVEACK); } else { - MPTCP_INC_STATS(sock_net(sk), + MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK); } @@ -3761,8 +3753,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, int flags, bool kern) { struct mptcp_sock *msk = mptcp_sk(sock->sk); - struct socket *ssock; - struct sock *newsk; + struct sock *ssk, *newsk; int err; pr_debug("msk=%p", msk); @@ -3770,11 +3761,11 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, /* Buggy applications can call accept on socket states other then LISTEN * but no need to allocate the first subflow just to error out. */ - ssock = READ_ONCE(msk->subflow); - if (!ssock) + ssk = READ_ONCE(msk->first); + if (!ssk) return -EINVAL; - newsk = mptcp_accept(sock->sk, flags, &err, kern); + newsk = mptcp_accept(ssk, flags, &err, kern); if (!newsk) return err; From patchwork Fri Aug 11 15:57:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351069 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CDEE329BD for ; Fri, 11 Aug 2023 15:58:54 +0000 (UTC) Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A55530E5 for ; Fri, 11 Aug 2023 08:58:52 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fe4cdb724cso19585085e9.1 for ; Fri, 11 Aug 2023 08:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769531; x=1692374331; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JwrGlqlP8zy3xXA0Lb/3kVoPgUx6S4wahN68TVcAYEQ=; b=TkGxEa8dAStkiM49LVmgJ3jR4c3XDLmu00M5xmgIHyo6D7mpxSimlm3wTJ3CS7gxNu 61d6qt610XAioK9CRnwlPzJqGvTE8yWUs3SYRoqOjUYWPRhGMcgfHUD/J1C/UchyGLvF FPAPd3SVA6hrxFS3EYxo638MzgVoOFAv9mXW/vC81ZZqXdlrUqr9fv/4qzXOTIcP2yrP 2CMiPNNv/YR8xoyYET+pLGPCHvZNxbHGgoDorqTPL7I54Kk1OLkw/lj0mJ8D5HNTy25j N6J8M0M/cikW5nR0talBWo0QPmO3LrKnuru+oe+fLpner+KT9IYfIEItbvkAQriDq6cY Xzfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769531; x=1692374331; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JwrGlqlP8zy3xXA0Lb/3kVoPgUx6S4wahN68TVcAYEQ=; b=KHPjACHmYnRLB9Hb5+EJ64ZiE5F3fgisA3L6e8i0hRQNFXrk9zmr0A/lff+IGj2r4+ qSRRsDVvw6sZtU1T+MnX1paZk7RNSdRmpn4wGbppKsClHBMSDiihcn997nQzpZu1+B7e bgEowa7Sp/hKZAPaeN5oh1IN3QnRbMO4h1PUf4i1j0W73Lx3N8SM9yfk/v29NRwWavmR m688NCzCA3LF+5JRjuZmO4lxaK1TGouW/hRq3ZhE7rwwanR9kafk9oQatMlpO+u4ciKd IQdkECCJu09wtlRQ1D1DnivZ3vMMloFLn5VEsh8d8bLZ/iKsvZhxmEMpVD/Q069vw7Ub 3Zyg== X-Gm-Message-State: AOJu0Yywzh69x0GCrcrJp/7ah8yGtnWRQkFvl2CcUZbKlZ5bF+JKZkP+ aYVf1tjSUgvZPySsYKeflxcCRg== X-Google-Smtp-Source: AGHT+IFJvLhnrsMjucsD45KsPbAk74xTiu5ctAqDiqb2OIrHPfC/OoVCjzXmxl3NujWNQzzuaT+12Q== X-Received: by 2002:a5d:40ce:0:b0:317:4d79:1e45 with SMTP id b14-20020a5d40ce000000b003174d791e45mr1756196wrq.15.1691769531158; Fri, 11 Aug 2023 08:58:51 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:50 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:23 +0200 Subject: [PATCH net-next 10/14] mptcp: avoid additional indirection in sockopt Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-10-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3734; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=K7Cpw3bUrIQ1S7TwFyAgFflx+80UQhfgWAmuSbjF5r0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvQ4Qy9NxZorSk6UHkZ3Aip/F03UNbG6MtU BNDH6LXkDaJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg c11OD/90ZhRggDinf+VJ9ze2snCh8sxAHT3osOY0tSEOW5XL9QSsQfrygLx9LGDNMYMJ/evOU/v vxxmWM9J2RYCR66Ihi0Qqxtsulf/v2bMi9TtbGdvneTxyIfOlEtVAmmPmlZdBLw529/RiTI3wj0 wYQxytcKOMq2sVxBkL8VUXgXbvvwhgnzXX3ooTTiaAu4Rm/bqCXWxLecOnXfSN2vDc4+LrCBJz8 jPq4akOusmYqvBT0mc7zPw46AMyU3DYhLUmtCvcxQfyoykgPSe6F8RUxA8G/esE6Lldp5jlzGTa 084tnztrobEugEOhkChqxji7jUyUnJvx1G7Tx2KVbpKNiCACmX0XX2RcCMgexevqL2HN2o8DPAS /HiLpGk/91JQxkqOMwxvrrF6n6nCp6XJ+Scrrp6Uu9KS3W3jWu9qBAF3jspNrl6lkex3bvqfiLV CicghVwEs2ggnF7dhTENjjDJ23AsUcdiYN7dNT95i2qYkUfpWAfDMq69+hUeA+9c2zqv2+/idq8 Ynoxbz/5cKHVGueKv/XJSnqaVLCcc288UgYOElMnzcreyAijt8TFDzxPtJQO5KN+Ug9CfP6q76o gGZqDDwDC8B1dsf/cjnz4seJSSI/GjZ/Ws4DR92gkWDUBtU40O+KkjWC8WEkirYuNg0wMbN9MFZ DQsB9DrXeyUk87A== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni The mptcp sockopt infrastructure unneedly uses the first subflow socket struct in a few spots. We are going to remove such field soon, so use directly the first subflow sock instead. No functional changes intended. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/sockopt.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index a3f1fe810cc9..6661852f8d97 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -293,6 +293,7 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname, { struct sock *sk = (struct sock *)msk; struct socket *ssock; + struct sock *ssk; int ret; switch (optname) { @@ -307,16 +308,17 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname, return PTR_ERR(ssock); } - ret = sock_setsockopt(ssock, SOL_SOCKET, optname, optval, optlen); + ssk = msk->first; + ret = sk_setsockopt(ssk, SOL_SOCKET, optname, optval, optlen); if (ret == 0) { if (optname == SO_REUSEPORT) - sk->sk_reuseport = ssock->sk->sk_reuseport; + sk->sk_reuseport = ssk->sk_reuseport; else if (optname == SO_REUSEADDR) - sk->sk_reuse = ssock->sk->sk_reuse; + sk->sk_reuse = ssk->sk_reuse; else if (optname == SO_BINDTODEVICE) - sk->sk_bound_dev_if = ssock->sk->sk_bound_dev_if; + sk->sk_bound_dev_if = ssk->sk_bound_dev_if; else if (optname == SO_BINDTOIFINDEX) - sk->sk_bound_dev_if = ssock->sk->sk_bound_dev_if; + sk->sk_bound_dev_if = ssk->sk_bound_dev_if; } release_sock(sk); return ret; @@ -391,6 +393,7 @@ static int mptcp_setsockopt_v6(struct mptcp_sock *msk, int optname, struct sock *sk = (struct sock *)msk; int ret = -EOPNOTSUPP; struct socket *ssock; + struct sock *ssk; switch (optname) { case IPV6_V6ONLY: @@ -403,7 +406,8 @@ static int mptcp_setsockopt_v6(struct mptcp_sock *msk, int optname, return PTR_ERR(ssock); } - ret = tcp_setsockopt(ssock->sk, SOL_IPV6, optname, optval, optlen); + ssk = msk->first; + ret = tcp_setsockopt(ssk, SOL_IPV6, optname, optval, optlen); if (ret != 0) { release_sock(sk); return ret; @@ -413,13 +417,13 @@ static int mptcp_setsockopt_v6(struct mptcp_sock *msk, int optname, switch (optname) { case IPV6_V6ONLY: - sk->sk_ipv6only = ssock->sk->sk_ipv6only; + sk->sk_ipv6only = ssk->sk_ipv6only; break; case IPV6_TRANSPARENT: - inet_sk(sk)->transparent = inet_sk(ssock->sk)->transparent; + inet_sk(sk)->transparent = inet_sk(ssk)->transparent; break; case IPV6_FREEBIND: - inet_sk(sk)->freebind = inet_sk(ssock->sk)->freebind; + inet_sk(sk)->freebind = inet_sk(ssk)->freebind; break; } @@ -700,7 +704,7 @@ static int mptcp_setsockopt_sol_ip_set_transparent(struct mptcp_sock *msk, int o return PTR_ERR(ssock); } - issk = inet_sk(ssock->sk); + issk = inet_sk(msk->first); switch (optname) { case IP_FREEBIND: @@ -865,8 +869,8 @@ static int mptcp_getsockopt_first_sf_only(struct mptcp_sock *msk, int level, int { struct sock *sk = (struct sock *)msk; struct socket *ssock; - int ret; struct sock *ssk; + int ret; lock_sock(sk); ssk = msk->first; @@ -881,7 +885,7 @@ static int mptcp_getsockopt_first_sf_only(struct mptcp_sock *msk, int level, int goto out; } - ret = tcp_getsockopt(ssock->sk, level, optname, optval, optlen); + ret = tcp_getsockopt(ssk, level, optname, optval, optlen); out: release_sock(sk); From patchwork Fri Aug 11 15:57:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351070 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AEBF329BA for ; Fri, 11 Aug 2023 15:58:58 +0000 (UTC) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9843D30E8 for ; Fri, 11 Aug 2023 08:58:53 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-317f1c480eeso1904059f8f.2 for ; Fri, 11 Aug 2023 08:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769532; x=1692374332; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=st2NKZ9E1hXrfDL5Ot0q/FaTfuFvnM6rU0/aNjt+RGc=; b=TGFIIasqCurxVc8BEOtpb7f0OIiHFeMet4baqs+yRG+W1i1oVpnRM7RH/oRF2dGxHu C3yaSG936y/XFN8cFrb3PMr9yODT9g8P7U3CJvMLHGL72yTu++BvRLnXj8GK9c7yO4qq B90jn6CTED9DabWy5o4ivqlOkl+g/Wx9ue+bKmzH700b9rs9Fj5L51k/NsSviadPG9uo 5Srlly7ULuVfkVqVLWSMgTKirFez42x5hJmEga1Wfi8xh29VbL+TXjSR3kIfTeMlETqO pOP7LD/6pkfaQFEyYmILGr4/Trla2LyutlHlST2Rxpc4G/wGX8MS6hGcXOQSoP15krxv nHaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769532; x=1692374332; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=st2NKZ9E1hXrfDL5Ot0q/FaTfuFvnM6rU0/aNjt+RGc=; b=B13YSczrmpspEQ5BV3hrU1zKDbk+Q+H3NhQsB2XfrNBI6wjQLZAaOid2F+25y2k4BQ e7WZg0XH+ANcVSNGI2hgHBt3vCDAtC/Kdbe97yDRLFzMn8JyMhhMAjWrC3RnqBbTtZ1r MJFVyGLHPPdBnoerCwTtIgqXGa+fmtuc/49iurXUWNvZBmmb9sb9pd6XWT6xh0ydu3MC rYdQQfz4jOn6HywuB0L0vumf3FlkzlIn2r8IowfjLszmMO/wDh1OeNRbugPpbK6WSCIt VeVbl18BEwqmqDtKbrMoDK115+o7cRBa2kQ4XeCOV6J9E56QemnQqF1Yybu0hda8LV3U s2dg== X-Gm-Message-State: AOJu0Yxcyi/yKAGdbCNAh9/PvO3bI710tNGg/I5ifODEyML4Nn/Awvko FFOe6yRnFWY868/OKoXDlxUW2Q== X-Google-Smtp-Source: AGHT+IG6K+E9E28dAF2CoPZoZYVbMBVGSUSdw0piTwy+yuUln7CVT3T59uKh993Hsq2y/6zb/QQlTw== X-Received: by 2002:adf:fa8c:0:b0:317:7081:9a6a with SMTP id h12-20020adffa8c000000b0031770819a6amr1667780wrr.24.1691769532173; Fri, 11 Aug 2023 08:58:52 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:51 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:24 +0200 Subject: [PATCH net-next 11/14] mptcp: avoid ssock usage in mptcp_pm_nl_create_listen_socket() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-11-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2211; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=ryKEnhcU8jzGTw+8/ZGieSQgwwgsCHLHT0d+ugOOpQc=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvmajEXvtvTqt8lHzWQds82lCmd/Y2V7HCi Z01gYHwgqaJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg cwrJD/40dDF0EYxvn5MXmn3Z/EHHQzIE6RcDCAsJGNaSvTC/z0X5Qd57QL50ZkUasy7eWY/XL04 dVxdTQXld587lj44Hpu4qUxptiGHQcjviVPK8jhcH9QBJME4PL9apiurN28mna90GcUCuZfgTWU hn1pw0e2lY0nEY91BMsvdrbgPXYQljrn+kn2O6nIkNq0WWsfphkTWNMfeBCwFeVzto6Kecrf5bI LVPSdRtuy+fBfG2qAa+HUyf5wvyo4Lpu3PBlWvJJuj3gL7Qjpp/xfXWMRhsTRpe1iHl6CmhhguS Nkag1RM90+SzkkKWzMKEZEJkWAgM+5hMY2Kzzodm4V6raj7tof+dxZdii0Zike1tiV0FTQK0WLo o8xPMddT995MaoIDY3QCxbiViJDQpRRUPH6+NeMWq+AheVQJauH2eLA2DotoBZUCVjbWTWKfHfO /jm3l4X8Xam9FNNKeFMQ/lr+ZyydVpZ1bx5gye6iBVHRH06E0o+J9stqqlmqIV8hQo8J880Fhr2 eWvuLyMImbi0rKsspWbaphIL/iTrMjzaK+n4WkfcXtzcaQtn/9ROyHYtErQZh3A8wfdbMjJX1UX JkngATdTVyt+Kiy0BAHiirZrk1HjjgQkw+v5U+UJXvMBcrwFXQCIz8t/ECB9soCoeBK6MThJH5D Pr81hahvz6kdXcA== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni This is one of the few remaining spots actually manipulating the first subflow socket. We can leverage the recently introduced inet helpers to get rid of ssock there. No functional changes intended. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/pm_netlink.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 5692daf57a4d..ae36155ff128 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1005,8 +1006,8 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, bool is_ipv6 = sk->sk_family == AF_INET6; int addrlen = sizeof(struct sockaddr_in); struct sockaddr_storage addr; + struct sock *newsk, *ssk; struct socket *ssock; - struct sock *newsk; int backlog = 1024; int err; @@ -1042,18 +1043,23 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, if (entry->addr.family == AF_INET6) addrlen = sizeof(struct sockaddr_in6); #endif - err = kernel_bind(ssock, (struct sockaddr *)&addr, addrlen); + ssk = mptcp_sk(newsk)->first; + if (ssk->sk_family == AF_INET) + err = inet_bind_sk(ssk, (struct sockaddr *)&addr, addrlen); +#if IS_ENABLED(CONFIG_MPTCP_IPV6) + else if (ssk->sk_family == AF_INET6) + err = inet6_bind_sk(ssk, (struct sockaddr *)&addr, addrlen); +#endif if (err) return err; inet_sk_state_store(newsk, TCP_LISTEN); - err = kernel_listen(ssock, backlog); - if (err) - return err; - - mptcp_event_pm_listener(ssock->sk, MPTCP_EVENT_LISTENER_CREATED); - - return 0; + lock_sock(ssk); + err = __inet_listen_sk(ssk, backlog); + if (!err) + mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED); + release_sock(ssk); + return err; } int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) From patchwork Fri Aug 11 15:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351071 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1D29329BA for ; Fri, 11 Aug 2023 15:58:59 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2EBE30ED for ; Fri, 11 Aug 2023 08:58:54 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fe167d4a18so19658015e9.0 for ; Fri, 11 Aug 2023 08:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769533; x=1692374333; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LSGODcFr9OATSyqQxuKOktFKCDDLoEhYtD7jcorRxls=; b=Ns1lteFxpGDVHRr38JDPYc+60Nzl7xP/gf0ZKPsOMwq34jdrCKfZ/cwPk/wmPUz4sS 4B0ebU8RTUNR/NLt23mZ+jTb2pmqeRacpKRP1Bbver0Yy0LlTNvzg/13mW3x9NB5Wkq6 maFLwHCC9lVe6FM7zhXGEi4pxAuOOSmZri/uYjdvRjK2/0Aor+r0q4muwwnVHvqlhuRJ fCPYJtvJhrgsHNxhRA4r0ywV7MrSTxZTiV5vWC0kR1dP4RvW2VQmc3owz7jn42NyeCr8 ESM/YU2HagKdfe6mjsOx8oPYUL/LMLexoi0mib6FD+g3nWBb+fojKsCSSS16Gr3xYToU 8qMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769533; x=1692374333; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LSGODcFr9OATSyqQxuKOktFKCDDLoEhYtD7jcorRxls=; b=KRnyQdf9wQJWM6fjkfDDKSxWfHF8jqzjQ0of7daFUYbTDEb4wSKsBtp5hWuiuVlAjx TbMbTFehVMStPF1+StLjVAHKkmasPnei/yaPXpIAfO61S3bLbe9FC8/vgeDkGkZU5y7/ r/ncQtx8P0gnI2mf5mNy++PoiQePhPlkNRpBMx3A0dk6y/m1RwMc+2aLml6JSe3n8tWE lHykKjM0ppEbzol+WDIfPLgJAMflR5zygXnhgsVxhKbKuq/jT/+PyR3kKJClcnVfX9vr p67L+qolf76ZKXrZQ5TQUeZn8ICQsnJ8rppfu4kbcBSHER4v8WSzto3YZMkLg1G/2Jsw 2rzA== X-Gm-Message-State: AOJu0YxsckCqBSiR6p7pApkLv1yixcxh6P/4TCZtUin3ke7a6EmoHWIt buKV77P1hOlbclMwK43KFw5PhQ== X-Google-Smtp-Source: AGHT+IHSAIG9FO2b3p/44Qi1wGiiMXTS2x9PQYOlWgfnoC2epewlMwfPHnzUFVs635sk0DrPmdvg2Q== X-Received: by 2002:a5d:5742:0:b0:319:57c0:19f7 with SMTP id q2-20020a5d5742000000b0031957c019f7mr1881075wrw.7.1691769533171; Fri, 11 Aug 2023 08:58:53 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:52 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:25 +0200 Subject: [PATCH net-next 12/14] mptcp: change the mpc check helper to return a sk Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-12-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=10012; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=5FIAPyMt3vXexcaCp5hS8RO0kYDOfcIUe8e+GVkbMIM=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqvEIUdoYbsI/k9HD+UAvGip1BHaH0nZMrnK M38NGK6mkaJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg cxNXEACaIW71/uXxptgFXdcZuPe5B6cj2DPTZ7da9NeA1HhobPG9XGyFbJRt6lYh7CP+DoUxDrU kIB3bMZjZM/g3ljiPvnyGbNBOAg96iZKCvdh4XxkqvHKoIK5IApq/MD4FPK6G0Z2Jpmdv2rI4PB hzB14paKlxVV5aqiSiaQNhEoT5L8w1tg/6ZADRLfMkdv2az3ZnFDPrXZ1+AjlBTB6pVtvQXXhsF /JZQ0O0kzQZRBNVIKhF1jW6Qmp/oXP3w+TvfM9RFIYbJbdILcpt1cwV6KGdKnTWMni9h/6OOg1F eAg1hXQXZJ/wCU6B/Yoq+56E4qz+mL1ZXlxJuX8O0HiHNjakXvwlqp9CuHb4b1i71rTkhgQT44R /26+Ha9fXQV7qph/+O3Vcc+bpHJzsPd7GFzqkj2Cw0K1JHoCq7j+gNGtjO59T//MXJMig3dYmKH QPnnVV4Q0mhN/CYsfkCeQTzW51NrnkgeybU4gB91QfxhPQoF0jkUqszrU9rQ57Fno8z4CuVVGYs hh6YCjB3xnqIp/BzJoV7fe1Hl0JQugFHClZ/IizWAd5R6D60KVQCSkq/SXS2Y6dfT1XiGnHatH+ WDuEAQHv/bzgsanN6X9rUTXksrKtTYms66SKvK70PKM0gyVlu8MTPOiS+6k3gwEIW1Qs5h4KCnZ woES6Jm4M95XQ8g== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni After the previous patch the __mptcp_nmpc_socket helper is used only to ensure that the MPTCP socket is a suitable status - that is, the mptcp capable handshake is not started yet. Change the return value to the relevant subflow sock, to finally remove the last references to first subflow socket in the MPTCP stack. As a bonus, we can get rid of a few local variables in different functions. No functional change intended. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/pm_netlink.c | 8 +++----- net/mptcp/protocol.c | 40 +++++++++++++++------------------------- net/mptcp/protocol.h | 2 +- net/mptcp/sockopt.c | 43 +++++++++++++++++++------------------------ 4 files changed, 38 insertions(+), 55 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index ae36155ff128..c75d9d88a053 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1007,7 +1007,6 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, int addrlen = sizeof(struct sockaddr_in); struct sockaddr_storage addr; struct sock *newsk, *ssk; - struct socket *ssock; int backlog = 1024; int err; @@ -1033,17 +1032,16 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, &mptcp_keys[is_ipv6]); lock_sock(newsk); - ssock = __mptcp_nmpc_socket(mptcp_sk(newsk)); + ssk = __mptcp_nmpc_sk(mptcp_sk(newsk)); release_sock(newsk); - if (IS_ERR(ssock)) - return PTR_ERR(ssock); + if (IS_ERR(ssk)) + return PTR_ERR(ssk); mptcp_info2sockaddr(&entry->addr, &addr, entry->addr.family); #if IS_ENABLED(CONFIG_MPTCP_IPV6) if (entry->addr.family == AF_INET6) addrlen = sizeof(struct sockaddr_in6); #endif - ssk = mptcp_sk(newsk)->first; if (ssk->sk_family == AF_INET) err = inet_bind_sk(ssk, (struct sockaddr *)&addr, addrlen); #if IS_ENABLED(CONFIG_MPTCP_IPV6) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e5ebd170d316..fafa83ee4a72 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -109,7 +109,7 @@ static int __mptcp_socket_create(struct mptcp_sock *msk) /* If the MPC handshake is not started, returns the first subflow, * eventually allocating it. */ -struct socket *__mptcp_nmpc_socket(struct mptcp_sock *msk) +struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk) { struct sock *sk = (struct sock *)msk; int ret; @@ -117,10 +117,7 @@ struct socket *__mptcp_nmpc_socket(struct mptcp_sock *msk) if (!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) return ERR_PTR(-EINVAL); - if (!msk->subflow) { - if (msk->first) - return ERR_PTR(-EINVAL); - + if (!msk->first) { ret = __mptcp_socket_create(msk); if (ret) return ERR_PTR(ret); @@ -128,7 +125,7 @@ struct socket *__mptcp_nmpc_socket(struct mptcp_sock *msk) mptcp_sockopt_sync(msk, msk->first); } - return msk->subflow; + return msk->first; } static void mptcp_drop(struct sock *sk, struct sk_buff *skb) @@ -1643,7 +1640,6 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, { unsigned int saved_flags = msg->msg_flags; struct mptcp_sock *msk = mptcp_sk(sk); - struct socket *ssock; struct sock *ssk; int ret; @@ -1654,9 +1650,9 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, * fastopen attempt, no need to check for additional subflow status. */ if (msg->msg_flags & MSG_FASTOPEN) { - ssock = __mptcp_nmpc_socket(msk); - if (IS_ERR(ssock)) - return PTR_ERR(ssock); + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) + return PTR_ERR(ssk); } if (!msk->first) return -EINVAL; @@ -3577,16 +3573,14 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) { struct mptcp_subflow_context *subflow; struct mptcp_sock *msk = mptcp_sk(sk); - struct socket *ssock; int err = -EINVAL; struct sock *ssk; - ssock = __mptcp_nmpc_socket(msk); - if (IS_ERR(ssock)) - return PTR_ERR(ssock); + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) + return PTR_ERR(ssk); inet_sk_state_store(sk, TCP_SYN_SENT); - ssk = msk->first; subflow = mptcp_subflow_ctx(ssk); #ifdef CONFIG_TCP_MD5SIG /* no MPTCP if MD5SIG is enabled on this socket or we may run out of @@ -3682,17 +3676,15 @@ static int mptcp_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) { struct mptcp_sock *msk = mptcp_sk(sock->sk); struct sock *ssk, *sk = sock->sk; - struct socket *ssock; int err = -EINVAL; lock_sock(sk); - ssock = __mptcp_nmpc_socket(msk); - if (IS_ERR(ssock)) { - err = PTR_ERR(ssock); + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) { + err = PTR_ERR(ssk); goto unlock; } - ssk = msk->first; if (sk->sk_family == AF_INET) err = inet_bind_sk(ssk, uaddr, addr_len); #if IS_ENABLED(CONFIG_MPTCP_IPV6) @@ -3711,7 +3703,6 @@ static int mptcp_listen(struct socket *sock, int backlog) { struct mptcp_sock *msk = mptcp_sk(sock->sk); struct sock *sk = sock->sk; - struct socket *ssock; struct sock *ssk; int err; @@ -3723,13 +3714,12 @@ static int mptcp_listen(struct socket *sock, int backlog) if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM) goto unlock; - ssock = __mptcp_nmpc_socket(msk); - if (IS_ERR(ssock)) { - err = PTR_ERR(ssock); + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) { + err = PTR_ERR(ssk); goto unlock; } - ssk = msk->first; inet_sk_state_store(sk, TCP_LISTEN); sock_set_flag(sk, SOCK_RCU_FREE); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 79fc5cdb67bc..dccc96dc2d6b 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -640,7 +640,7 @@ void __mptcp_subflow_send_ack(struct sock *ssk); void mptcp_subflow_reset(struct sock *ssk); void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk); void mptcp_sock_graft(struct sock *sk, struct socket *parent); -struct socket *__mptcp_nmpc_socket(struct mptcp_sock *msk); +struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk); bool __mptcp_close(struct sock *sk, long timeout); void mptcp_cancel_work(struct sock *sk); void __mptcp_unaccepted_force_close(struct sock *sk); diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 6661852f8d97..21bc46acbe38 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -292,7 +292,6 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname, sockptr_t optval, unsigned int optlen) { struct sock *sk = (struct sock *)msk; - struct socket *ssock; struct sock *ssk; int ret; @@ -302,13 +301,12 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname, case SO_BINDTODEVICE: case SO_BINDTOIFINDEX: lock_sock(sk); - ssock = __mptcp_nmpc_socket(msk); - if (IS_ERR(ssock)) { + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) { release_sock(sk); - return PTR_ERR(ssock); + return PTR_ERR(ssk); } - ssk = msk->first; ret = sk_setsockopt(ssk, SOL_SOCKET, optname, optval, optlen); if (ret == 0) { if (optname == SO_REUSEPORT) @@ -392,7 +390,6 @@ static int mptcp_setsockopt_v6(struct mptcp_sock *msk, int optname, { struct sock *sk = (struct sock *)msk; int ret = -EOPNOTSUPP; - struct socket *ssock; struct sock *ssk; switch (optname) { @@ -400,13 +397,12 @@ static int mptcp_setsockopt_v6(struct mptcp_sock *msk, int optname, case IPV6_TRANSPARENT: case IPV6_FREEBIND: lock_sock(sk); - ssock = __mptcp_nmpc_socket(msk); - if (IS_ERR(ssock)) { + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) { release_sock(sk); - return PTR_ERR(ssock); + return PTR_ERR(ssk); } - ssk = msk->first; ret = tcp_setsockopt(ssk, SOL_IPV6, optname, optval, optlen); if (ret != 0) { release_sock(sk); @@ -689,7 +685,7 @@ static int mptcp_setsockopt_sol_ip_set_transparent(struct mptcp_sock *msk, int o { struct sock *sk = (struct sock *)msk; struct inet_sock *issk; - struct socket *ssock; + struct sock *ssk; int err; err = ip_setsockopt(sk, SOL_IP, optname, optval, optlen); @@ -698,13 +694,13 @@ static int mptcp_setsockopt_sol_ip_set_transparent(struct mptcp_sock *msk, int o lock_sock(sk); - ssock = __mptcp_nmpc_socket(msk); - if (IS_ERR(ssock)) { + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) { release_sock(sk); - return PTR_ERR(ssock); + return PTR_ERR(ssk); } - issk = inet_sk(msk->first); + issk = inet_sk(ssk); switch (optname) { case IP_FREEBIND: @@ -767,18 +763,18 @@ static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, int sockptr_t optval, unsigned int optlen) { struct sock *sk = (struct sock *)msk; - struct socket *sock; + struct sock *ssk; int ret; /* Limit to first subflow, before the connection establishment */ lock_sock(sk); - sock = __mptcp_nmpc_socket(msk); - if (IS_ERR(sock)) { - ret = PTR_ERR(sock); + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) { + ret = PTR_ERR(ssk); goto unlock; } - ret = tcp_setsockopt(sock->sk, level, optname, optval, optlen); + ret = tcp_setsockopt(ssk, level, optname, optval, optlen); unlock: release_sock(sk); @@ -868,7 +864,6 @@ static int mptcp_getsockopt_first_sf_only(struct mptcp_sock *msk, int level, int char __user *optval, int __user *optlen) { struct sock *sk = (struct sock *)msk; - struct socket *ssock; struct sock *ssk; int ret; @@ -879,9 +874,9 @@ static int mptcp_getsockopt_first_sf_only(struct mptcp_sock *msk, int level, int goto out; } - ssock = __mptcp_nmpc_socket(msk); - if (IS_ERR(ssock)) { - ret = PTR_ERR(ssock); + ssk = __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) { + ret = PTR_ERR(ssk); goto out; } From patchwork Fri Aug 11 15:57:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351072 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EF54329BA for ; Fri, 11 Aug 2023 15:59:00 +0000 (UTC) Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4957330D4 for ; Fri, 11 Aug 2023 08:58:56 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-31751d7d96eso1829127f8f.1 for ; Fri, 11 Aug 2023 08:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769535; x=1692374335; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cLaLRYF1JduC+QzJ6GmQvAFgWnOUNDuN5FR0KZ2xx0A=; b=noy0cHvA5nSTmWrJUz91yjHuTF/IaG5qP+BedmmnjvAivrJ7RDhS85BDCiPUg3NRFE XeVT+4W66rrFujkgK3Lyqjh77PF2/8XxVznsW/tvioTNi/g3DlaFBsxEHcyN/9awDzLc p1dfFs3XqBkbW6ETfcwakXFGLYb1nMthGv2b3/MiKQ3AYhG1PNbYfdNAkU3zmtO2z+uk +tMNEn9LJiAgyKyTJiWyB775hg29tXJ9Y1oN8OQTL2CeXRqF6po4G0Yar2tLTXb60o2H fWWd7inV6p7Tngvoc/hLcSWbeFGE0zgKeW9lT9gEuN2QC6SvRK/l7b7/YjjoXELTcY+W G0wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769535; x=1692374335; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cLaLRYF1JduC+QzJ6GmQvAFgWnOUNDuN5FR0KZ2xx0A=; b=ZsIp9LXOvRfxX0ui1uzB5XSbjBmpIIs29S3Vk/EG6yMxlWJ6LfkF8fakMUqbLG019B BQChbyColdBu5olRB5dFNYOPQTZeT+0bVW0oNjvWRwFG40+Aw9h+g9FpRUqmbQ+VFQlz t93mvi/DIErGDdTcXoszx/n5XlfL74OUAVV08XiQC7nQrFHzM5Jwod3jIZsLvNy/pkiJ dwS0GcOSs54W8HkAV9RCDy5P/kELYUSoXrVevrBvQGfznFS8VsThj7VA8Rm66c0bZLIB iEuomqICWTfHtnQ1QOcicwjPMRtUdRiNO3CZvevq+PsfxF87HbOaj/pC0afpplo7VdEU JoyA== X-Gm-Message-State: AOJu0Yxty0pcZgCQ5/faFizPeoqqwK8Y6k29eNNGjz3nLptxVyzL+Xh9 F1/0Mns2S0V2Byz9C9if+Z6M7w== X-Google-Smtp-Source: AGHT+IGOmd1+l7kOKJnbNq4g2j2InKaMpB7aiJxx5b1DAIVklrLR/bZOa2fdd2lhCnC+46zkWB11gQ== X-Received: by 2002:a05:6000:1086:b0:317:594a:dbde with SMTP id y6-20020a056000108600b00317594adbdemr1777929wrw.20.1691769534752; Fri, 11 Aug 2023 08:58:54 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:54 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:26 +0200 Subject: [PATCH net-next 13/14] mptcp: get rid of msk->subflow Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-13-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5387; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=JOoJwlBZFYBUmiOmWbe7z+i/oWAb6YdcTuPbi7SJfsk=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqv+QeEPuMBcjYRKmzxcRYgSkRQXDk9iGBun vM2a5KezHSJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZarwAKCRD2t4JPQmmg cyamD/wLack7Ml/PVH4WCAUD77D7IUrXDx2QwvmPDDPIrBy8extCVuY65SVGbf4MLGWc5VLR4Fh /+pyJCyslnWNGjIhYp5fzJMNKBO0XVCTaaa8g+TV1umSei3ZcF92+m08Jf1PgANT7J/70WzSQKM iJj0NboA+2HnINHXUrb460QdHWDd0VGtp8Qp2ttCHOq8mKBg4LrhLPQW7D/DU1eSTfll+2u1atP KwV5wWXWbSuKGJxOAiGKMJmBQ0EHjNOHxCYf5/AKJesmv5i2L75pOqRhvYGWB0uaQqj3OZh6BFF 34Q1AxWzJzcBLQRljg1MYlb6isWqZrRefJZ2prthzJKk+OQ9ujOfGSp3li06eJBQyVgrvL+x2qc 5dzwRrHSGl1z16xFqiUzfW8oR8CZ7n5aBrU4l+a35VSVmP060bBiBp/0R+dkzJndam3XT4eEBsF A2Pcmog4QLppbn4fwvFmgESMqtauV0CEYzYcML3xvVz0m3Aa8IIdZzFrDkXvY5N5m/C2xxBnwBX SXPwgxC4dzyrJH4J1bGTCzAWtY6YtH10XLApj0TwuWwKqEt5h31iPq0V+N0vSl734jfVZ3wAT5X xMUhV5OMqjBDl2D7YjyMHXWUNA5zPgkMsOo1IyJ0wVRCq2GP2kEt0xBwyDwBYmvZzIGZjUsCjtW mBvQOALx7hmZd0Q== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Paolo Abeni Such field is now unused just as a flag to control the first subflow deletion at close() time. Introduce a new bit flag for that and finally drop the mentioned field. As an intended side effect, now the first subflow sock is not freed before close() even for passive sockets. The msk has no open/active subflows if the first one is closed and the subflow list is singular, update accordingly the state check in mptcp_stream_accept(). Among other benefits, the subflow removal, reduces the amount of memory used on the client side for each mptcp connection, allows passive sockets to go through successful accept()/disconnect()/connect() and makes return error code consistent for failing both passive and active sockets. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/290 Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 25 ++++++------------------- net/mptcp/protocol.h | 13 ++++++------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index fafa83ee4a72..e715771ded7c 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -92,7 +92,6 @@ static int __mptcp_socket_create(struct mptcp_sock *msk) msk->scaling_ratio = tcp_sk(ssock->sk)->scaling_ratio; WRITE_ONCE(msk->first, ssock->sk); - WRITE_ONCE(msk->subflow, ssock); subflow = mptcp_subflow_ctx(ssock->sk); list_add(&subflow->node, &msk->conn_list); sock_hold(ssock->sk); @@ -102,6 +101,7 @@ static int __mptcp_socket_create(struct mptcp_sock *msk) /* This is the first subflow, always with id 0 */ subflow->local_id_valid = 1; mptcp_sock_graft(msk->first, sk->sk_socket); + iput(SOCK_INODE(ssock)); return 0; } @@ -2238,14 +2238,6 @@ static struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk) return min_stale_count > 1 ? backup : NULL; } -static void mptcp_dispose_initial_subflow(struct mptcp_sock *msk) -{ - if (msk->subflow) { - iput(SOCK_INODE(msk->subflow)); - WRITE_ONCE(msk->subflow, NULL); - } -} - bool __mptcp_retransmit_pending_data(struct sock *sk) { struct mptcp_data_frag *cur, *rtx_head; @@ -2324,7 +2316,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, goto out_release; } - dispose_it = !msk->subflow || ssk != msk->subflow->sk; + dispose_it = msk->free_first || ssk != msk->first; if (dispose_it) list_del(&subflow->node); @@ -2345,7 +2337,6 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, * disconnect should never fail */ WARN_ON_ONCE(tcp_disconnect(ssk, 0)); - msk->subflow->state = SS_UNCONNECTED; mptcp_subflow_ctx_reset(subflow); release_sock(ssk); @@ -3106,7 +3097,6 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, msk = mptcp_sk(nsk); msk->local_key = subflow_req->local_key; msk->token = subflow_req->token; - WRITE_ONCE(msk->subflow, NULL); msk->in_accept_queue = 1; WRITE_ONCE(msk->fully_established, false); if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD) @@ -3240,10 +3230,8 @@ static void mptcp_destroy(struct sock *sk) { struct mptcp_sock *msk = mptcp_sk(sk); - /* clears msk->subflow, allowing the following to close - * even the initial subflow - */ - mptcp_dispose_initial_subflow(msk); + /* allow the following to close even the initial subflow */ + msk->free_first = 1; mptcp_destroy_common(msk, 0); sk_sockets_allocated_dec(sk); } @@ -3782,11 +3770,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, /* Do late cleanup for the first subflow as necessary. Also * deal with bad peers not doing a complete shutdown. */ - if (msk->first && - unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) { + if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) { __mptcp_close_ssk(newsk, msk->first, mptcp_subflow_ctx(msk->first), 0); - if (unlikely(list_empty(&msk->conn_list))) + if (unlikely(list_is_singular(&msk->conn_list))) inet_sk_state_store(newsk, TCP_CLOSE); } } diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index dccc96dc2d6b..38c7ea013361 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -299,7 +299,8 @@ struct mptcp_sock { cork:1, nodelay:1, fastopening:1, - in_accept_queue:1; + in_accept_queue:1, + free_first:1; struct work_struct work; struct sk_buff *ooo_last_skb; struct rb_root out_of_order_queue; @@ -308,12 +309,10 @@ struct mptcp_sock { struct list_head rtx_queue; struct mptcp_data_frag *first_pending; struct list_head join_list; - struct socket *subflow; /* outgoing connect/listener/!mp_capable - * The mptcp ops can safely dereference, using suitable - * ONCE annotation, the subflow outside the socket - * lock as such sock is freed after close(). - */ - struct sock *first; + struct sock *first; /* The mptcp ops can safely dereference, using suitable + * ONCE annotation, the subflow outside the socket + * lock as such sock is freed after close(). + */ struct mptcp_pm_data pm; struct { u32 space; /* bytes copied in last measurement window */ From patchwork Fri Aug 11 15:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13351073 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1EFD11708 for ; Fri, 11 Aug 2023 15:59:01 +0000 (UTC) Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8565430E7 for ; Fri, 11 Aug 2023 08:58:57 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3090d3e9c92so1898082f8f.2 for ; Fri, 11 Aug 2023 08:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1691769536; x=1692374336; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=t+XgaLGpUVP+G9qnOB0ZNXJDWKPyu+7aNgrOOBV4CXs=; b=Wge3t0yMVuay4tm8zdBQ9VyeL6OLJAnYtN8V9iwiqU8TvRM5ND9ERv/8i2Y0FArvFQ tyG+3O1nerD6rcqBCbg2Yxi/GEjlgN0VeHNCzZWoK8KmI2UeXphNC4ct39rAWNHhOq6n g3MxOHl1F/R3iVZaFvULiNeXrTd5HPlV4+zO97TksYClBrDGyBmm4kRFzTQccpHZLLyG jXFYRE99H23TempgCoan3vs01e8+KRWka4tBP479RADB9zjrIIFJ64LnP/2iwPPymaWX OkJg6VAAsx3QO7crW4QlH020KhacJUh6CmeEv8xlivqVhmJYQ7RUE1o45BE134rD1wev Scgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691769536; x=1692374336; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t+XgaLGpUVP+G9qnOB0ZNXJDWKPyu+7aNgrOOBV4CXs=; b=FeoDVyJ5mxRhRxWWXa5+OrUuU4eYnEFYxsvhq8+qQwEs/vWvB41b0HsffSWK+zDQZy FOH9S3aD2GBuLSCV+r7i4XdCcHySQ5ZD8GxFIUxV51dI3O4/9by/1hmpxi8QPrTF0WsW 0ufjRpp8JtoGzzkcnV4A0sVbqC57SIyQDKnv0wo4FNAnibpwLE2kKqOIbCEPn0ZYwPMh L+GTub7pFocidnwtU2yDlrSXRkKK85/K4omGZDkYkg2OMFHChbDt5ZXQWTKvFvCdTWRD k/gsNJHhXgwmRDnnT35XprsEtcCmxc6mNu6Au3E+vL25HCKLaCtOQ1Fwts5H4bTfVLjM 8cNg== X-Gm-Message-State: AOJu0Ywao3+EwHgUC+bu3r99dShUr9zWBB/qQJ/nrgi9I8wsFktT1SKI ZuQ2352l2DBMpQev47bfHJZSFA== X-Google-Smtp-Source: AGHT+IH+uijgDdhfb4MCBOghDLHl+5AuYsKXMZMFSQo58jr8ReplmmJKvjmkcb9cb2D4E1oZaQweCQ== X-Received: by 2002:adf:dccd:0:b0:317:5a9b:fcec with SMTP id x13-20020adfdccd000000b003175a9bfcecmr1553679wrm.14.1691769536025; Fri, 11 Aug 2023 08:58:56 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id m12-20020a5d4a0c000000b00317e9c05d35sm5834308wrq.85.2023.08.11.08.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:58:55 -0700 (PDT) From: Matthieu Baerts Date: Fri, 11 Aug 2023 17:57:27 +0200 Subject: [PATCH net-next 14/14] mptcp: Remove unnecessary test for __mptcp_init_sock() Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-14-36183269ade8@tessares.net> References: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> In-Reply-To: <20230811-upstream-net-next-20230811-mptcp-get-rid-of-msk-subflow-v1-0-36183269ade8@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts , Kuniyuki Iwashima X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1657; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=9eUzQsTH9C4lw0Wrk8AIKRJ6c0bqe3QPvYFbn9S2V3Q=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBk1lqwU7yF3k2xiGkkBmwynf1c4Z1lknA9Khwon buB7uDg15eJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZNZasAAKCRD2t4JPQmmg c53oD/9Cm0tzdEzZtSh2bD4u/FrbdFha+H7oI7jW05zlpsFeQAA3EQLy5H58wxt8lTY6tbB3ENZ MHZa6zrGYtWnVl3BEO8/JPEa1wSXa2BT+Ke/fk2NRWhHV8w/7w426oiEurwvMZgpU2U/l6rlpFi 3vRvAO8KgA1CDraah31q+rj0LD40A//lSUC5rcG/XtrqIduqvyo/Mb0+sqQ66guhuzAPYRGj1Qk 3A0OAwr9kMd6ie34lrH4wle2YQnZku78y5+KjTPgKR3/m+tdn4AtwdqvsGHZsxjwRf9GwgUeXsU jkwWJSEN5bHVOChix6B/qGM8ziHaGa+Icc23/wR1ZMBRfhzD6i5NuljgtALxngwomGPkaMHZUCy 7pgM497BTMGffB7C7NPkHSuYmykvz+xAlJgcTLgLL83dweYf6NoFvRgie/vjHwBc4m+MooOJhZy jdGsO7K8gEB94e6a34UTYdtZAtiyUABk/qr2KYHzdU4zdOT05/7V14EJZRXdR8ZT8CakcEBP7XG fJdRjfUt7lnMcpGT5hKYMGqP8ZSmkTY4SN+j7kE0/8jNzYkifmuiSgp773MGvtbrDf0ONREBNBL Hr6lp1QGjLPxsdtKiHaEbI4NW5pl3ZmwlvQ5wKs80e9cM2+PJFX6+1Dn20Xdx8e3wrDIPF8dXbk eqm6CsASm8so4Og== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Kuniyuki Iwashima __mptcp_init_sock() always returns 0 because mptcp_init_sock() used to return the value directly. But after commit 18b683bff89d ("mptcp: queue data for mptcp level retransmission"), __mptcp_init_sock() need not return value anymore. Let's remove the unnecessary test for __mptcp_init_sock() and make it return void. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e715771ded7c..6ea0a1da8068 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2649,7 +2649,7 @@ static void mptcp_worker(struct work_struct *work) sock_put(sk); } -static int __mptcp_init_sock(struct sock *sk) +static void __mptcp_init_sock(struct sock *sk) { struct mptcp_sock *msk = mptcp_sk(sk); @@ -2676,8 +2676,6 @@ static int __mptcp_init_sock(struct sock *sk) /* re-use the csk retrans timer for MPTCP-level retrans */ timer_setup(&msk->sk.icsk_retransmit_timer, mptcp_retransmit_timer, 0); timer_setup(&sk->sk_timer, mptcp_timeout_timer, 0); - - return 0; } static void mptcp_ca_reset(struct sock *sk) @@ -2695,11 +2693,8 @@ static void mptcp_ca_reset(struct sock *sk) static int mptcp_init_sock(struct sock *sk) { struct net *net = sock_net(sk); - int ret; - ret = __mptcp_init_sock(sk); - if (ret) - return ret; + __mptcp_init_sock(sk); if (!mptcp_is_enabled(net)) return -ENOPROTOOPT;