Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp441632rdb; Thu, 8 Feb 2024 10:06:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiI9iijgCLIZ/3MZHlO3xhIeM0qbn8IfHdJhT9a4CLaSwi4EPPq/Y4mtgpjdyzUl4wfi64 X-Received: by 2002:a05:6358:79c:b0:176:a2d7:850 with SMTP id n28-20020a056358079c00b00176a2d70850mr7604190rwj.16.1707415611352; Thu, 08 Feb 2024 10:06:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707415611; cv=pass; d=google.com; s=arc-20160816; b=QRmO1t2dl/T4BAWE2f3GwSDaYJHhatKfBzYusUAM/ZBtxGW2LObu+gCUCeMB0pN3N8 1zmiDp/KF3qY8yCnU/ajntFPZdxQpn6ryG7+1WmUWIIp4SSbkyxVNCnGVBviDq1cxlfU r6GooebuwdRUlujuzKJImzHSw3GXyWxlGjBm5rKBM6+lzEQ1cJNfbC9gj6Xm4mgcL6ts VVoPsdcjYMQOGG53Q1Yuob3r5F2MK4grVT+//jjC5jRhbLXUnS/w4rcdKPdEbo1mEo5v aMVtCCC1yX2AY6+pF3CfLZt80/OTki769yy0wXm+DlXVXayiKOhSlhKjG/K/5FNq+H7h nMpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=65AOkE2JGl02u97LcBqLl6whVDIzHfcqaQjPNgbmPzw=; fh=nyao59JhfYv8agTmzbSMd7W0CCHEqBDkdCLgs2fHaTg=; b=tMXfcIELNYPWn3oDYjyLFcKwiQEs9wyTYC0J1/my6Sxxuju4qjmzJt5dR7pms+Z++x t4bwUReXrLcUqLANWnMrY6VbVM6szpNIQbQ4THGY9nRRDwaGXE/boxvgMdusX6uwAu+j eL2qGE1g2S6oJ/AGN5I+MDH4XYzBYCFFbhxF3Gwqiga4QOJtLMNOD8giBPae296DXqrN bDTT2u5aSqrM09bxsQ6HGVRbaZ+xlO1LxvgIll0jxL4Rq3H8ZgCmT03rjLts5EMwxX/I Vo7cYwz9Qm1kmrCOaGzDvF2ctlm326UllNxqinqMnI6J6VCrm3Sg/lMAvpyDiyeVk1r5 u9OA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AfsCf+hv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-58510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUlrWtMAuxt8eOX2NX0HtxZmxk7Wdd5Q8Sp9q5W3JeE1j7qXq6fsx0PgmIGqGtg7nKk2XubyPURF9mICJHmuI2RFgf5uuWwz4T84SsPEg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gw6-20020a056102668600b0046b203c19ccsi66457vsb.665.2024.02.08.10.06.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 10:06:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AfsCf+hv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-58510-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 91D9B1C22ADC for ; Thu, 8 Feb 2024 18:06:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5815A1292DC; Thu, 8 Feb 2024 18:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AfsCf+hv" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 71CB8128833; Thu, 8 Feb 2024 18:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707415481; cv=none; b=DfVtkaixQaDa376Kx0opBnP67T7vJm6rV6HpUY8lPdfhQ+66lb0m5NIpguKweNYUiqUYbhol75fVBX+tSHsPAWyDS7r4nYmqCVjByLSml77tHmnuHlqQGjVGZUIaug09okOIQNMrgIFDDMjcd5jm+ZaCMRa7ZGdpjBkjAyKQCtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707415481; c=relaxed/simple; bh=NvTXRnuON6qPQNYuNjtmkLBaOdT6vLsUQt2KlMjwaRg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Hlalu6oY95u57LnyPAVQQI+KUD6pPjhcGV1cXSPXtCyIQAO0h5Dlr90L5uEo/nern3R9bSxtwsHLQFgZAtQ5ceKp/iB02/S4vr4ABMQhXf9M+0Nt+TwSxPdHqrV7S5mJZ1VAcvAMVpQ21Vf0GZ9lDk8MVGXUj3Rz26/ZCoAFB+g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AfsCf+hv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F90FC43399; Thu, 8 Feb 2024 18:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707415480; bh=NvTXRnuON6qPQNYuNjtmkLBaOdT6vLsUQt2KlMjwaRg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AfsCf+hvzcWGGLz8s8ueraM6xG333BQf/2BM1uSkw3s2DmRiP758Un8yRR76tvNaO w71OU7ffxu4lw41dLeeHBMWf1pzT/kUQUgDeKyoh3A2dAfU1ucqfxx2qXU9fOrIBkR OfhwynHiDhDgUjRAW6d4dmj8rpotTmGZJurv/p1QJ6wQUBSrN7k5qOprNFoc3V9uly synif8g6FoxJ4TEQ8EgVm4cPsnjaJGVUNv8Hcjn8fZMvEfWbekKqwLn86fTTKITxZa BOfan8bj8G+SJ9+hyDak8Hs1Yq5uJAtVaLI8zBt3oSfS/LA+ZdAB2ECHjeb/2KBoEr UmElN3vqcGwRg== From: "Matthieu Baerts (NGI0)" Date: Thu, 08 Feb 2024 19:03:53 +0100 Subject: [PATCH net 5/7] mptcp: check addrs list in userspace_pm_get_local_id Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240208-upstream-net-20240202-locking-cleanup-misc-v1-5-f75cc5b97e5a@kernel.org> References: <20240208-upstream-net-20240202-locking-cleanup-misc-v1-0-f75cc5b97e5a@kernel.org> In-Reply-To: <20240208-upstream-net-20240202-locking-cleanup-misc-v1-0-f75cc5b97e5a@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kishen Maloor , Florian Westphal , Peter Krystad , Dmytro Shytyi , Benjamin Hesmans Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Paasch , "Matthieu Baerts (NGI0)" , stable@vger.kernel.org, Geliang Tang X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1624; i=matttbe@kernel.org; h=from:subject:message-id; bh=8aCCu0yid68+GRgZ0xl8ByhW49kl62JqasxySjE1hiQ=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlxRehMiBc0n4f5gHnwPOyMOq49tP8zHm2lFVkT cE0jZcZVGWJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZcUXoQAKCRD2t4JPQmmg cxntEADURwJIyiZOlgRgmGk5605OerW8KhB2LAduQSzURfaFwUvTMpY0gAlP1jNEPHikGDBNPiF uOL+nPGidIDA/aoBUA18uSMVjP3lW6Fo/f5eAwPyMnPQzp8zVGkvOWDf7mi5Z5W+3dufYQfggYk U9Buxrb/uZ5Qq1Mnlu1Q0WwFrHTUjfUWZRMvOw5K/8fY2kN7qg1JxHDLpspfHM+qqdhsyi+73nF VITEEcn0tF2QxUxwP72FP/RhxO3e/dXoz7nmwmqLO4BUzO7smxueGgWJtYJNROjKC+g739r5VQX zAtfaGgm+MwHw4ZTMhRDJ/TqHGjJ5qxVQD+LkjfXj4aTY61N9onisctTHJ+HvhgIMaPW8bJ/GM3 5ymw4/GaknE8KN9ZmHjDvECOyFjfCoRYr8R2KnG4sN7TjMbMmrbfPLaXlocEwxjqUh9pLKkbLkQ l9lOr96uMF9YAU3HhgrpYZDjQLPGQ1R4F6Pi8U6IxQm7nzrFpcFgUFb705muBu4J1Lfe1vICjEX Y04hObPoIAElQd8fHfgLLRwyOqrCvvOsMWEpUaRLs17bVgYOR7Og5NFPurVFn4zB77d4qImkjYy a4b7uGx1pV7rx5xwie7qk+buNeYwnnQ1P1C+F5/xyGdnDOOQtyxS8ttuea2UY08zLE/Y90Zo7dd SqFfspoFmeCNIJQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang Before adding a new entry in mptcp_userspace_pm_get_local_id(), it's better to check whether this address is already in userspace pm local address list. If it's in the list, no need to add a new entry, just return it's address ID and use this address. Fixes: 8b20137012d9 ("mptcp: read attributes of addr entries managed by userspace PMs") Cc: stable@vger.kernel.org Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index efecbe3cf415..4f3901d5b8ef 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -130,10 +130,21 @@ int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - struct mptcp_pm_addr_entry new_entry; + struct mptcp_pm_addr_entry *entry = NULL, *e, new_entry; __be16 msk_sport = ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; + spin_lock_bh(&msk->pm.lock); + list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { + if (mptcp_addresses_equal(&e->addr, skc, false)) { + entry = e; + break; + } + } + spin_unlock_bh(&msk->pm.lock); + if (entry) + return entry->addr.id; + memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); new_entry.addr = *skc; new_entry.addr.id = 0; -- 2.43.0