From patchwork Fri Apr 14 14:08:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 83433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp417690vqo; Fri, 14 Apr 2023 07:18:14 -0700 (PDT) X-Google-Smtp-Source: AKy350aFD5xvl8cr/zpyLzBS3IoS/vkM8SlSXjAE2DuDH9ABuF+Yr6lSwY9TEs9kMFCreoA0n7KD X-Received: by 2002:a17:90a:1102:b0:247:180d:1a82 with SMTP id d2-20020a17090a110200b00247180d1a82mr6793425pja.15.1681481894157; Fri, 14 Apr 2023 07:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681481894; cv=none; d=google.com; s=arc-20160816; b=xTcSfaPsfMgzjwVGg4Eah2nXXMYTOQog/N3XqrN8GWPfuLWrapRqTWeCxVHQJq5hks 1QINbPj7ohxUjVdGGToRC7ua84Wr9BJ4FcJBXQfovtZ+zCIlUvINhKzsgO9Ifmt7T0Ff rkqJd0d0tzbAXz/eSHib7lGSV25Rr8J0mvA1ZcehJ3Fv8tYcf7kNEPAcMw4uxJn7kVm0 jprCJ0JsRgyYjqpRZaqzMytLkFy2LXD5UyYvkffe72wUPJUjnwAJE61sf/w8/K7a0CJ8 hZtEwD1dqG06IC4qpz4hEGNKzNVLVhGciqdRU8ehy0B67N4Ie17TP5IZkxAZ+fr6KBml 09IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=xZhYE929PeAd0ZLAU9yqicLsmxgzSrjpBPOp2nmL8n0=; b=hznqRixbAi6ff1b/2+Jq/aHywMPsiAu6XheRaK/8W/SR0hFb/dw4cqbqoEO5gRh+4n 5UjhQa18HBdFpR0vAwTAGu1qwTVZf8I39hDCzOSI1TKBkxEmLpDvwWoK/c/6pewNKum1 HapCQlWg/ThQhooCk6/h0hMr1kIek0C/rqeSXt+sLMpZj9VOnU5rvp/V/ijAuwVFKT49 u6lP0lC1dNJVDE619iLglLbVNsH8CCHF1q5l/V3VPNXO+O/iHZQuPUxQFX9u5h3+yuqE D8jyuwpYtY4421M3TpdXMp6qUd/7uKewic2NfjdVGhtXjbqOwf8dts3h3sqNSmMpxka5 CDFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares.net header.s=google header.b=aqtuhrKb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=tessares.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t21-20020a17090ad15500b00246abe40ca9si7522064pjw.9.2023.04.14.07.18.00; Fri, 14 Apr 2023 07:18:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@tessares.net header.s=google header.b=aqtuhrKb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=tessares.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbjDNOJb (ORCPT + 99 others); Fri, 14 Apr 2023 10:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230382AbjDNOJY (ORCPT ); Fri, 14 Apr 2023 10:09:24 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23BCEC14A for ; Fri, 14 Apr 2023 07:08:51 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id s2so14368871wra.7 for ; Fri, 14 Apr 2023 07:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1681481311; x=1684073311; 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=xZhYE929PeAd0ZLAU9yqicLsmxgzSrjpBPOp2nmL8n0=; b=aqtuhrKb79sOWSOu6w3w1lpzSVh3Aokv6l+YXXFIQk+r0U0XQFAQqKBQLM5r7wKuig OycDp8uWtXg5G+e0+tVn6uv1AGd5hFY+wzwFgha++3wfanjGcmK9aXvavN7Ok2OJNlVV DxdVfuipATJj0lHVqp0Z3LCDMu9qIyxNRc5hHYG43D5lcpzinDtK4roPAWvZkbqTX3Z4 8EdLMUw1qkgGCR9llXwHMpe1SKug/5WLudbCbnnR+36Yfn9vZUKUAMrvzUiOLqS+HKRC TEdFZ9CxNHMMhWXg/tTL3BdSAz3oEUbXDIDnbf62SuJj4LUdzUwzMNgJ3RxAiEq+B46K XAkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681481311; x=1684073311; 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=xZhYE929PeAd0ZLAU9yqicLsmxgzSrjpBPOp2nmL8n0=; b=QBhOBstnU8q7+pUa9C9jpPMpc0wV5sn7ulcJssGdg9QH69oiNMn22KmU2iXSNqCLx/ En4KTaqPz+YDa6Y1akNnBSmMwPzlS7MpAexTszWCbHhfMDkGn2ERwfLuE9r7hLDZmhN3 lJxm/NsDGv6ohFi/b0cL9uUYIOcYKaAr5hx0hhh0bxb3HfJrv0Qtraw/DBWrGDEbO27l FEZ2hwtcv49ATnK3oLFtszp5b++Pfxiv8viAhRnai7oxTr79JqMuro1EGwdkNxfvsqA4 S2oW4xRvwur6wrn5SM7dBll8QKbqqDkHX2Ngi2sodFkgGsUDzgMJ5UXToz2aQeJ3Fo8A kVhw== X-Gm-Message-State: AAQBX9cGulBOTzcm2B2k6sa4ePOvNEP8Tt7riZe0/RYVX4Deo8SObaj+ uewLdH8w+8CJcNklRS6TveQWbg== X-Received: by 2002:a5d:4e11:0:b0:2f4:fd50:9cb8 with SMTP id p17-20020a5d4e11000000b002f4fd509cb8mr4382629wrt.42.1681481310078; Fri, 14 Apr 2023 07:08:30 -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 o5-20020a5d58c5000000b002f47ae62fe0sm3648185wrf.115.2023.04.14.07.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 07:08:29 -0700 (PDT) From: Matthieu Baerts Date: Fri, 14 Apr 2023 16:08:02 +0200 Subject: [PATCH net-next 3/5] mptcp: move fastopen subflow check inside mptcp_sendmsg_fastopen() MIME-Version: 1.0 Message-Id: <20230414-upstream-net-next-20230414-mptcp-refactor-first-subflow-init-v1-3-04d177057eb9@tessares.net> References: <20230414-upstream-net-next-20230414-mptcp-refactor-first-subflow-init-v1-0-04d177057eb9@tessares.net> In-Reply-To: <20230414-upstream-net-next-20230414-mptcp-refactor-first-subflow-init-v1-0-04d177057eb9@tessares.net> To: mptcp@lists.linux.dev, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Ondrej Mosnacek , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthieu Baerts X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2817; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=P9n60YIe/mfn8CQZAad2UIBXi/vdPChGGnKW1QV+jTM=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBkOV5ZosafB8d9GNmNZ1meFhcnycRNpkZenoavp FVmCcOlLviJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZDleWQAKCRD2t4JPQmmg cxHQD/4z3riXqfAZUhX4rcRrvxKx561jC5T5Wn/xk9PLqTfmLJM/J+uDRno+meTIsy3Gt0zlws5 /zWj/eS3bIKsxwNffgmkKUDm59OH2DRnN6WN9mKXadPQ53+30TerpxmXB6GLGCxmMM2Fa22ZApE 8EbRWfppLAO37JDArFx46THJ3SHS0Fghm5DmFbL6X9gdOSNCZElMiRn1mxRheOEaFqAtn0Zl2+w JLV6h+h1kV6RGfN36zxDzMOZhZIQnTcSqAB73D2enOuvukL/LW9nse2sS1Su7Uvu7x7867reBRX NydxcCYUemkiiZVRjePSOKxtc5L3GNoK++uAv78Ey1RdMivWGHmd12tfsP5E4ZB0RaqISBLOuoA DRnwJYNuJU0i5qGgcHX+q21Bo9GoXbxJsllDlIFJ2bGwXk2HLpVMoK83qpq3Owp86/dgPqWqc2R t9qzQO7UCOWO21uRpiDwf3KYtvAMOFINATu8zszRrKngatOAxKlO1cnyn+e9jFXoxw1OTx93NAx +XCSwQwkZh9lfY9CM/9GmFH+hLE+av2heTVPGaw6HbOklRTwGQZc1pjE4DuZnop6+ukd1JGeK5K 6OUp9tsP2FShZcNXuOtG+EpEtUGXPEqRQTtPeK4tQ+MEitgxVJzwKFjW7cX7neAe0xevXESU/0m CsvfP0paDYtH01A== 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763161558566800880?= X-GMAIL-MSGID: =?utf-8?q?1763161558566800880?= From: Paolo Abeni So that we can avoid a bunch of check in fastpath. Additionally we can specialize such check according to the specific fastopen method - defer_connect vs MSG_FASTOPEN. The latter bits will simplify the next patches. Signed-off-by: Paolo Abeni Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 9cdcfdb44aee..22e073b373af 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1662,13 +1662,27 @@ static void mptcp_set_nospace(struct sock *sk) static int mptcp_disconnect(struct sock *sk, int flags); -static int mptcp_sendmsg_fastopen(struct sock *sk, struct sock *ssk, struct msghdr *msg, +static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, size_t len, int *copied_syn) { unsigned int saved_flags = msg->msg_flags; struct mptcp_sock *msk = mptcp_sk(sk); + struct sock *ssk; int ret; + /* on flags based fastopen the mptcp is supposed to create the + * first subflow right now. Otherwise we are in the defer_connect + * path, and the first subflow must be already present. + * Since the defer_connect flag is cleared after the first succsful + * fastopen attempt, no need to check for additional subflow status. + */ + if (msg->msg_flags & MSG_FASTOPEN && !__mptcp_nmpc_socket(msk)) + return -EINVAL; + if (!msk->first) + return -EINVAL; + + ssk = msk->first; + lock_sock(ssk); msg->msg_flags |= MSG_DONTWAIT; msk->connect_flags = O_NONBLOCK; @@ -1691,6 +1705,7 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct sock *ssk, struct msgh } else if (ret && ret != -EINPROGRESS) { mptcp_disconnect(sk, 0); } + inet_sk(sk)->defer_connect = 0; return ret; } @@ -1699,7 +1714,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) { struct mptcp_sock *msk = mptcp_sk(sk); struct page_frag *pfrag; - struct socket *ssock; size_t copied = 0; int ret = 0; long timeo; @@ -1709,12 +1723,10 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) lock_sock(sk); - ssock = __mptcp_nmpc_socket(msk); - if (unlikely(ssock && (inet_sk(ssock->sk)->defer_connect || - msg->msg_flags & MSG_FASTOPEN))) { + if (unlikely(inet_sk(sk)->defer_connect || msg->msg_flags & MSG_FASTOPEN)) { int copied_syn = 0; - ret = mptcp_sendmsg_fastopen(sk, ssock->sk, msg, len, &copied_syn); + ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn); copied += copied_syn; if (ret == -EINPROGRESS && copied_syn > 0) goto out;