From patchwork Fri Apr 14 14:08:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 83429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp413462vqo; Fri, 14 Apr 2023 07:12:30 -0700 (PDT) X-Google-Smtp-Source: AKy350YQvkzK8UDkHr4ARM+ipqMpAIlwXCBsOdER6jJavacGGQ5bt/4wAL29yIcBE+mqeXSlAfZ8 X-Received: by 2002:a05:6a00:240a:b0:5a8:8535:18b with SMTP id z10-20020a056a00240a00b005a88535018bmr8380475pfh.11.1681481550505; Fri, 14 Apr 2023 07:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681481550; cv=none; d=google.com; s=arc-20160816; b=hymAawD7N8Y2VYMicDt9OAKBeGWst+jv4xCu1xDWbxaufMSrrYX7kYteANxZTGtdU7 Gr5OtUQC8kIuuVE1t0V+1iehXY4vYIsUSYkfdFahdeAYZ/SSzOXiMsnFy6BJlYVZSV4F empYpLclXVRJ7Tj99pydpSMmN3ZvuPpeumZINnE7oZVqrTPhPd6IQra1+fm0LGoH8rFd qOi4uusCfqnGS2jZtIcw0RDtwlzRi3f8jUIgfEQryOTsfv1xAXYJRTAamzVAItI8Yh3V HtLPWXJPSlhXciNp/m/xJctsTdKK026K/UtdJBHmxt/gkU6th125b+gP6m8PG68qi+3W DkZg== 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=m66cRDfB61TtjfV8yD54rvNQYmtYBLMGnE8NSc4/AeM=; b=Lx5iqx3EFXboGKUTQljlR+dhY2Jwum3DaYb98xiGcgs12lotstr3/7fqYH4ABgfyvi 4NcSR2fG7bGbcMKvinlPSWYKrBm5h1yu8j/V92/Kc4YDot3SLWGtMEQgqoxf6ZH9xoKa Q78By3aAj5d4RMjuvR0WfMBgfiKX8ZuGnrMyVKLEejL+6kygFC8pnO7mp8G0sp3mP8v8 RiAT8otJshu1DBEHt2AqgjzW7xGXlM9dvkXwgzPlDP75fa1ySBpC3Wi91mDOlLQ9lWoC BJ181Rs/t6l4iTZG2UAz663/g9LuSwv6/X+rwB3UNZs9aF+PLgBv6tN4tIGvzfYWH/0A o2WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares.net header.s=google header.b=fY6FXzLy; 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 p185-20020a6229c2000000b0063b54679d0dsi3719929pfp.44.2023.04.14.07.12.17; Fri, 14 Apr 2023 07:12:30 -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=fY6FXzLy; 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 S230413AbjDNOJY (ORCPT + 99 others); Fri, 14 Apr 2023 10:09:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230167AbjDNOJT (ORCPT ); Fri, 14 Apr 2023 10:09:19 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A04ABB8D for ; Fri, 14 Apr 2023 07:08:44 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id q6so6171473wrc.3 for ; Fri, 14 Apr 2023 07:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1681481309; x=1684073309; 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=m66cRDfB61TtjfV8yD54rvNQYmtYBLMGnE8NSc4/AeM=; b=fY6FXzLykolJ+i9Za1CV4ll8jWr69FyB35y2mOLGOihNwAFCEZQOp8fOjHcwtyL02I u5vd0ml7sD3Fr4Qtnbfyc5QH5cfa43RpmK1NozI/0c0gdHT7ZwNSc8qluqcpm7795JpG xqtP6e/1jo172fq3SmjUOzkZRVIJAJ76/GgZ6JE5HTIU0wKD/Oz/SMwO5RJ5L4CPVmuJ 4p7BCaZ1DPzd4Eec0cxV2PeqngvlIZgZ5jfshNLHoIWa+GPsjezIkLKixGvFyJKfUgRy r+mLB4xBUezdkFjGOvXayAqFaXyqYmd8Ts7Njzc3JVGvoUxVYYPgjcGnB74F/Y1bCadg 413w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681481309; x=1684073309; 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=m66cRDfB61TtjfV8yD54rvNQYmtYBLMGnE8NSc4/AeM=; b=AkOUCQjRNohQfGEfYxxJupP3cH8XaHT7J8YrTcc7YFWVnk/9ldQGOXW9ZTvrELoif1 JsObuF7k4P5EJSO/wHn6uNyxz8fcFgAdDk6rStFfSQ0TOBYgbfz0t//NaHmgysxVYI/7 FNE9ZmqnsAQDa1t9lPpKUu4vSSxCb4EFDqOj7Tk9Fx0sZ34uVygSdRJUBs1aBK2vg3QF bsJ8vMUWEUnfNrDQOEPJUBuZ8JGjFHongUwcpX3vp9GD3xC/ej+pYpTymGMbnpYl1jYg tnGYN3jgnBc14MK09B6ZPSMJ9YIn9DCJJoG8Ez0bcCYLzd3CfA8wo96Wcuu7Wa0F8vAE 5jPA== X-Gm-Message-State: AAQBX9daVhzKhp3xw5L7GpD5kzu0I8Kzu+mpHE52pYn+Vu7wCj+UoApq GySwnC6bRXZ8DDap5GahLXiTOw== X-Received: by 2002:adf:ebc7:0:b0:2f6:6f0c:a2ba with SMTP id v7-20020adfebc7000000b002f66f0ca2bamr3318268wrn.63.1681481309191; Fri, 14 Apr 2023 07:08:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 07:08:28 -0700 (PDT) From: Matthieu Baerts Date: Fri, 14 Apr 2023 16:08:01 +0200 Subject: [PATCH net-next 2/5] mptcp: avoid unneeded __mptcp_nmpc_socket() usage MIME-Version: 1.0 Message-Id: <20230414-upstream-net-next-20230414-mptcp-refactor-first-subflow-init-v1-2-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=1864; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=v3ERWSmGTwhX1zfSOFHxV4yLOCVx2TIDjGL56UvMCw0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBkOV5Zyl/LCHrWjit6z8vyaL4Okf2RFmEt3FnMi GJI4vpLCoiJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZDleWQAKCRD2t4JPQmmg cxroEACJ0K+liYP3kEeK1Y3OyVkmSgD4Y+GGfKtR0SOc9aYpBCMnVKufnipdwiV2iJ4j4hfwbt7 6Q5g3VcDB7g/210e3iBTx0pjawiePuwz7YknZA1hHl3l5nWcuTLQG1yAESzwTTom7WJNTTJFJLu VpaNJFTtU1twEV9JmF+qBVReTZ+sa0A2cpgznnnOXii8zLtUzTsAWUXSrSWxJT1Y8c5mgjhbGmu Z8m+d3/Tm8izeLQtZfhnnyCV/ZG3950G7+te/gzIjeY5SAD4+ByZyz2F7Z9+O8sOKLTMwXFBGxv IRtATjxXwHzmW+tzijxnL4mODecfX7KRfD+P6soi4dj/hQHGzbfcNgj5n+SBT/3NEPZljm9CSw1 zK9iUKr6Te4lW2Ewzd6uA+wzpfb3ibluVyV21Q5TLiqu3vTC2ZRoyzl2U0HGKbyuWufsRfeJ2jR eTWOSL7ZuAH+q6a6Hf1gJZ8IHXI0KhymFlKiMsvTY/kCBmvQkLeg04q7FRXuk5Cs9Laekn0nGQi jtd29DF6maOOO5NLdMAlf1puJ+zIybKP9kUjg/PtkKK6G+pWswf8W99JHjnQSlKn/78jWLUJtbj 0wy2DQD86waQ+ded1+8otDps+5fSarm7qr/c8XEkbLZkD54ZiT197PngORD7nCpmr4JCOtzE5ho g/llVsoT5mxWjjg== 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?1763161198521576181?= X-GMAIL-MSGID: =?utf-8?q?1763161198521576181?= From: Paolo Abeni In a few spots, the mptcp code invokes the __mptcp_nmpc_socket() helper multiple times under the same socket lock scope. Additionally, in such places, the socket status ensures that there is no MP capable handshake running. Under the above condition we can replace the later __mptcp_nmpc_socket() helper invocation with direct access to the msk->subflow pointer and better document such access is not supposed to fail with WARN(). Signed-off-by: Paolo Abeni Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts --- net/mptcp/protocol.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e6cb36784a68..9cdcfdb44aee 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3143,7 +3143,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err, struct socket *listener; struct sock *newsk; - listener = __mptcp_nmpc_socket(msk); + listener = msk->subflow; if (WARN_ON_ONCE(!listener)) { *err = -EINVAL; return NULL; @@ -3363,7 +3363,7 @@ static int mptcp_get_port(struct sock *sk, unsigned short snum) struct mptcp_sock *msk = mptcp_sk(sk); struct socket *ssock; - ssock = __mptcp_nmpc_socket(msk); + ssock = msk->subflow; pr_debug("msk=%p, subflow=%p", msk, ssock); if (WARN_ON_ONCE(!ssock)) return -EINVAL; @@ -3709,7 +3709,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, pr_debug("msk=%p", msk); - ssock = __mptcp_nmpc_socket(msk); + /* buggy applications can call accept on socket states other then LISTEN + * but no need to allocate the first subflow just to error out. + */ + ssock = msk->subflow; if (!ssock) return -EINVAL;