From nobody Sat Nov 23 09:47:32 2024 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 2E69019CC36 for ; Thu, 7 Nov 2024 09:09:58 +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=1730970599; cv=none; b=QAsCJ4mQgB+I8etrdKafokuAdf6xylRUnk5BC55pVmDALsH8qJ+qWI3oWFQ25N4gusPpKwnDmCBjomkDPFERfztT1QnnqwBXVfl/rYQj5mE2R2e/FfjsIjd1Ib+s0tJ1b0/y1B4LX+20QoRrID5TpEPZPfz8zOdjT796Bi2h4b0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730970599; c=relaxed/simple; bh=/VF77SAF39byCwbOD5hNvJqh/yxw5otX1wXH/nRl954=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gbht1+Z3GBsg3imAlOEOhPKFxxJRWBBPxwgb6NqagL7mTZ+FQZrTQBsCcOqGuK1D0ZESM/NFYOWCxvixQbyzV7L8dZ2/pqJsSeyov0SOMW5QCTfSOollMeM5lHUzRbXHVab/05dYaevMfRLv5YqPbLm56vGeae3vX2MhHlqN0b4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Eub9zIQD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Eub9zIQD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F418BC4CED0; Thu, 7 Nov 2024 09:09:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730970598; bh=/VF77SAF39byCwbOD5hNvJqh/yxw5otX1wXH/nRl954=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Eub9zIQDtlt1xjTNouymtHr3N5e0hkyz6V3Zlz6XgcrvT18RYcuotBD8OZWBxsDBg R4fL6WjEe0H/bynFQeOQShh0B8CeKQqkVOqFwqeS4UCeFebgNa3s2mcLXEUded7xdV oTRyxIrMEZssmPRJZ1Y5pk0GVnbmn99cbt8t4QIJgZGjJebRsd1/3WKhQwynSWv4Cl b+7+qQOQks7eI+uo0W+YD/Ya0b/mtlNwZAzkHr7cTprUkZ+pMgFq0r9c5ElqBIJezo uMsAcA/qQpZvFjH0zRwPFeIW9KHc6EyrUbGmPeAQq6J7KLXFdIsF0izTBi2BgBBcqc khgfYF9jyxNAg== From: "Matthieu Baerts (NGI0)" Date: Thu, 07 Nov 2024 10:04:14 +0100 Subject: [PATCH mptcp-net v3 1/3] mptcp: pm: use _rcu variant under rcu_read_lock Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241107-mptcp-pm-lookup_addr_rcu-v3-1-3c458d025de4@kernel.org> References: <20241107-mptcp-pm-lookup_addr_rcu-v3-0-3c458d025de4@kernel.org> In-Reply-To: <20241107-mptcp-pm-lookup_addr_rcu-v3-0-3c458d025de4@kernel.org> To: mptcp@lists.linux.dev Cc: Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1594; i=matttbe@kernel.org; h=from:subject:message-id; bh=/VF77SAF39byCwbOD5hNvJqh/yxw5otX1wXH/nRl954=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnLIPj4R8dmCaKkOYhqMeiwxhhEAcGZ1nn4E8nV pnDR0Szb2KJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZyyD4wAKCRD2t4JPQmmg cyJKD/4jam6LCrRBbVJSDg5DCnzaHvFUrozDN2wOHUDtZmWAaSrkwoouCibXKd/NuRqooQU++sa 4vYeMdVXhVzfvBnycQwLi+Ldu3WEMO+5MwgGhsd7ibtT1GrDubLxb4GQX5C432evjnMikxm2D4U Vg21I339jib2jlMESNZrkcLIvZBxgjR8WKgVC9ssBMCGViFmOyMEh+EXko8u24gfkhkBCI8EHSK JWDdhX4YDJ0e2t1zBBgCun+Rngmi1YT6JGsii8pAzRPJ8lS+0PKuDY5e7x0EeSbraCSzSY/SbxJ 7Par8z4xhR1kVYxCqwI9HWe5+TmJgoCvmK0C4n6ZmafnSi2iVQGJMt/QnrbypkNu3kMVbdpb9jX e+OdCdliMZAlnw/YfgUkNR4MQKcTpUHiHrQ88/HREfb+WQfsMs8YfQHvADBi6Jyidy4z7pKdt9c O57b1UD7oy/RuN3EgziqbALdQ6BTWzoAnW1NvEpG3MfamnwU/idZQenYlRkB+G/FAUQ+TTqhAZR REF+bBGoNApyE+MrGncN6/CNQMwt4YfRfC/VmGlxAtGT9SlD6Aa5OXIW+UWR5k9NQx4CQtveGBe O5LEUxvkx5LMdpsE+fWg/E8QRtv/Ze/pdK5cwv0Le8NOUUYmeGgy3zUM4O1BgSOhu4tYEFTDN+X BAZE1gn+qvpfUZw== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 In mptcp_pm_create_subflow_or_signal_addr(), rcu_read_(un)lock() are used as expected to iterate over the list of local addresses, but list_for_each_entry() was used instead of list_for_each_entry_rcu() in __lookup_addr(). It is important to use this variant which adds the required READ_ONCE() (and diagnostic checks if enabled). Because __lookup_addr() is also used in mptcp_pm_nl_set_flags() where it is called under the pernet->lock and not rcu_read_lock(), an extra condition is then passed to help the diagnostic checks making sure either the associated spin lock or the RCU lock is held. Fixes: 86e39e04482b ("mptcp: keep track of local endpoint still available f= or each msk") Signed-off-by: Matthieu Baerts (NGI0) --- v3: - Use list_for_each_entry_rcu() with lockdep_is_held(). - Update commit message accordingly. --- net/mptcp/pm_netlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 618289aac0ab7f558d55d8b2ebb00dc62fc72f88..758a0dbfcf78e545d840c0b580c= 0b12bd042d7a4 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -524,7 +524,8 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct= mptcp_addr_info *info) { struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry(entry, &pernet->local_addr_list, list) { + list_for_each_entry_rcu(entry, &pernet->local_addr_list, list, + lockdep_is_held(&pernet->lock)) { if (mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) return entry; } --=20 2.45.2 From nobody Sat Nov 23 09:47:32 2024 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 4FFBF19CC36 for ; Thu, 7 Nov 2024 09:10:00 +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=1730970600; cv=none; b=gtDEk18YfnFG0dOkEpZAXHnctS2WM+loNeLFvAQim+m98xNo9bKB17oSJ6egBmQIhDWDKdS9rhL3mq4CBXZ86ArAksm+9aBrBszS7F3kBwxwgGKYZ9xNEqW57KnAGQFhrYqRqGwQY3zJW1z0NtBbMERV8dPP+REh4HxpymHz6NQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730970600; c=relaxed/simple; bh=LR8paxrpA9rV64owzMgemXMb9bMluQXMg0iVcTNDwds=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cinu7J9JrJI4QZlusFOIQyqsSJ6JMLhmY8me07Nk2bkigJTU4576oBSG9NZA9QcIYec8FYgI6is2gSLmm3qygCUPIbRW2NE1n2Ypkl7l+pwEX77gLDhW2poFgcEBP/lUqTJ01CLtiID96nhnK9H5f0/iNLL8bU9A2GYF8oyRHq8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NpK6S3jj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NpK6S3jj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CBE5C4CECC; Thu, 7 Nov 2024 09:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730970599; bh=LR8paxrpA9rV64owzMgemXMb9bMluQXMg0iVcTNDwds=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NpK6S3jjqPfEyV23x8ibJa5iz7Chet6ws3l7LRfpzb2X7vlmbdLmhxU4hkVYUYPwK 3P5aKHW0SQxUBYzrOOR2QcxKdyvBdbdIDlZZK1LFXu3e5Amlub2VjXNJO45ME6GOX6 RbCBo0CBofsunNZXwbcb0yLNKcsJ4V0NjUudHC6kLDiGKimcb14hHosu7RJzVdKUbk OIKeN0KDxKCV02nYMmqzJDNfn5DNYzWvEB5YKnBoKUOrKa4HPvxRie53JRhgtcp31F FhU0w23+24SdO1QligREAL8PicPLAsMlhf553gFE6baETiLOIoR+92tdZNfb8UJFis SZwKeFa7vTN2g== From: "Matthieu Baerts (NGI0)" Date: Thu, 07 Nov 2024 10:04:15 +0100 Subject: [PATCH mptcp-net v3 2/3] mptcp: pm: lockless list traversal to dump endpoints Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241107-mptcp-pm-lookup_addr_rcu-v3-2-3c458d025de4@kernel.org> References: <20241107-mptcp-pm-lookup_addr_rcu-v3-0-3c458d025de4@kernel.org> In-Reply-To: <20241107-mptcp-pm-lookup_addr_rcu-v3-0-3c458d025de4@kernel.org> To: mptcp@lists.linux.dev Cc: Paolo Abeni , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2798; i=matttbe@kernel.org; h=from:subject:message-id; bh=LR8paxrpA9rV64owzMgemXMb9bMluQXMg0iVcTNDwds=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnLIPjmQXhtUkcjXpNDY7FbBNOdRI4aN/2NxXh4 Ir/xLHBAbmJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZyyD4wAKCRD2t4JPQmmg cyXhD/9jIU0QtYQQFKthACNVGdJnCdtr+in6lkcJeNcPD2wPtClbRAKF4kol09KuKPlg7fZ1Wbw 3PCagyUThQAg/ID7dReWP8DiaIf43gNM+9ygPra8gcsYaMgGg479NavhU8YtGQwMRWQ1FSOzF67 1eOUhMLADyOcBYYUgS+pDExEVvl+0RxhPk320lSGamexNWyuwZdB4Dy6gRER7gMjYHCxnu6ETrM gmtawUF9iqp2RmQA3gGn8Ofs1FADN00bXJzkPy9kiUHO2zGhhvRagoytww41NVWNZaLe9RCMwet e/nWsK56CCo+CMcl/Gjqc3a+lINz+Ecyarg9BcYA2ETs3J+yFJUru6gWjE3Zqxl6yhag7aHB6R1 6qRqClRPI/KZfpbDoijIYQQvXo4imPIMNFNT6KcxANMnw54M4oiUumd6LLId/ubEVvO5vAsozQt +sW1GLVmqbQ+OFczSuHUdM+aFBzUZn10u5epTX6lBVurg7fRo0kItYGOBrqMJkWO5uF4r/FShzl U0f5bNmIFkSWQbCryMDokWWwhsKfMIbCW46uFvqft/5B+25rwACK176D+I+TNzUlnNd/aPIgEQ1 TuoJSp1UKCkq1mk9APr6+XnmtWBLdbum3g8KziUxN7KRHJbRENPBOtZNl5upnyDheeqv2ND6Vi8 XkWkc88n0w3FJ+Q== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 To return an endpoint to the userspace via Netlink, and to dump all of them, the endpoint list was iterated while holding the pernet->lock, but only to read the content of the list. In these cases, the spin locks can be replaced by RCU read ones, and use the _rcu variants to iterate over the entries list in a lockless way. Note that the __lookup_addr_by_id() helper has been modified to use the _rcu variants of list_for_each_entry(), but with an extra conditions, so it can be called either while the RCU read lock is held, or when the associated pernet->lock is held. Signed-off-by: Matthieu Baerts (NGI0) --- Notes: - This is not a fix, a small improvement for -next. - v3: - Use list_for_each_entry_rcu() with lockdep_is_held() instead of duplicating the helper. So no need to rename the helper with _rcu suffix. - No copy of the bitmap in dump_addr() (Mat) - No need to modify set flags. (Paolo) --- net/mptcp/pm_netlink.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 758a0dbfcf78e545d840c0b580c0b12bd042d7a4..2b005ddfd2d365b66abf4206528= 9d74630e604f6 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -512,7 +512,8 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsign= ed int id) { struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry(entry, &pernet->local_addr_list, list) { + list_for_each_entry_rcu(entry, &pernet->local_addr_list, list, + lockdep_is_held(&pernet->lock)) { if (entry->addr.id =3D=3D id) return entry; } @@ -1824,7 +1825,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct = genl_info *info) goto fail; } =20 - spin_lock_bh(&pernet->lock); + rcu_read_lock(); entry =3D __lookup_addr_by_id(pernet, addr.addr.id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); @@ -1838,11 +1839,11 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struc= t genl_info *info) =20 genlmsg_end(msg, reply); ret =3D genlmsg_reply(msg, info); - spin_unlock_bh(&pernet->lock); + rcu_read_unlock(); return ret; =20 unlock_fail: - spin_unlock_bh(&pernet->lock); + rcu_read_unlock(); =20 fail: nlmsg_free(msg); @@ -1866,7 +1867,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, =20 pernet =3D pm_nl_get_pernet(net); =20 - spin_lock_bh(&pernet->lock); + rcu_read_lock(); for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, pernet->id_bitmap)) { entry =3D __lookup_addr_by_id(pernet, i); @@ -1891,7 +1892,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, genlmsg_end(msg, hdr); } } - spin_unlock_bh(&pernet->lock); + rcu_read_unlock(); =20 cb->args[0] =3D id; return msg->len; --=20 2.45.2 From nobody Sat Nov 23 09:47:32 2024 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 A926F19CC36 for ; Thu, 7 Nov 2024 09:10:01 +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=1730970601; cv=none; b=Gi9w9533SaJxquEUO/xcr0b6gyc8FDcIMaO8RwjzGoEmUb73LWpEdfW8rMDw/5f0wGBnw0F6O7yJs6JczbBxmDJxkRmJCJraPeAR58Ne1Y/oOTkRH4GO0K242qppzrsNf6VDBvSl2eXSieF9sRdJnHdBn0GVp7sWkHphV6UN068= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730970601; c=relaxed/simple; bh=UeCsZxEfG4t+jeWSbmbPJW11g9vScyiLjAaeOnPjkNI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Oie1bGIZRy8Ziatk2uOn3xashctQa0Dwy0y9ediI6PqGFthdnEw0L7YDJyg8BZSCm+sw0Ghau8xzNcaLYc4risv3Iy2dZ+1J67Mf7MnMgoSOVkJQX8ctQcnZuLcfMB/Cgnuu+PamHe8D5yuW4xZ+1y5tghBEcZTOCCtO3El7+YI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nL074tdr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nL074tdr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B105C4CED2; Thu, 7 Nov 2024 09:10:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730970601; bh=UeCsZxEfG4t+jeWSbmbPJW11g9vScyiLjAaeOnPjkNI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nL074tdr7jBFTtbUbDqzjTPqFEu0rkj+fYjcvZ2Nz0efNhl3j8CXghhPOaYHRb9OK ScbpezfGDw7zCY849JgdKq9VgcYo+LJhCRijwMQWkfgSpMnW/U8toive5CR/lvea8X 0BGbVpz2EaGpjRIL9yhNnEqWvyT3NwdoQvCk9yiP7ZisCwS9a6Ca3ZEgom8KdTfP2l vjKtPn2dO4VNO/b8ACvQdYZ9fb1agZRsK0Wmc+ByGxx+TEEV1hQIApUZrZpniSYUXJ FqFm9l2iZ8gYa/XXidu+gJRW8NUROwEXzZwTrw3he9DI7CKoACAYYrhIgyDUEOhnyj 3g3T7cDFwUr/Q== From: "Matthieu Baerts (NGI0)" Date: Thu, 07 Nov 2024 10:04:16 +0100 Subject: [PATCH mptcp-net v3 3/3] mptcp: pm: avoid code duplication to lookup endp Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241107-mptcp-pm-lookup_addr_rcu-v3-3-3c458d025de4@kernel.org> References: <20241107-mptcp-pm-lookup_addr_rcu-v3-0-3c458d025de4@kernel.org> In-Reply-To: <20241107-mptcp-pm-lookup_addr_rcu-v3-0-3c458d025de4@kernel.org> To: mptcp@lists.linux.dev Cc: Paolo Abeni , "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2056; i=matttbe@kernel.org; h=from:subject:message-id; bh=YUL4CGqIzhlMPln+WT5oVHu4NWvc7lGKFG/f9fL/Src=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnLIPjXFnhfiUc0gnlVc4vtIcjZoyoryUl7JsGp v44pVw/+VCJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZyyD4wAKCRD2t4JPQmmg c0rdEACsuEEz4EXequBL1f5SnGTndmGTApab40O2pX5mJlusVcKGzpXWGq228ikqqChI6J42r9K FGKyBJtGqZGz42me0lyXacDy4O+ZYA36OXMO6+NZMOQkEY+8jCA3eydf1cYe0usgO2XJSXCsdGR rnCs9l2ivgYMRVXSdhC+ZHIUtFfdcOQIFamrIJbYlTSJFJ0AeTt8QVpe9Y9c4bxpCergFy7BN/4 qu1brpXLgF/0ov9cefJpgCo9CawW4PiNums89l+JRhr1vPfT5J2erg4GD5Rfn5GgHj/h7Q0WNtZ OiSwf1U/DEVlR5gCAOJO/OHr/JvqnZU7hSn/ilhkjn3sRHRwMxpAXsRLk4gQkXqXGZYgSXGEvtK 1AhNCoy7GPWpbPXcZyq6RcJ50K+d0IgBaa8OHld6GdCyXmuiJkmOJRypZ+mTcwdmX5CH0cj8cjt 238wlEOqUvYhcVDRAP+e+x7DaCBSHOddHtSDRvaO0YJVOXaj6dsf3C8LKThsPeOkr/OS5tCeVvz /R/HxttnCCr5VKzI1+CZVTkgB1V7XI3ZZPruLg8qxL17RaKVlRsiH0ysfjb4jmyuxUgXicKBRRV RqAXic172y0Ee5DFkTVTe4bwqdoeQ++0Pv1kkHsV5KH4IHw1Ho4vlVVTR+8WltddV+0soqtZc6d 5n7jStUg0wYRYng== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang The helper __lookup_addr() can be used in mptcp_pm_nl_get_local_id() and mptcp_pm_nl_is_backup() to simplify the code, and avoid code duplication. Co-developed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Signed-off-by: Geliang Tang --- Notes: - This is also for -next. - v3: - use __lookup_addr() instead of __lookup_addr_rcu() that has been removed in v3. --- net/mptcp/pm_netlink.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 2b005ddfd2d365b66abf42065289d74630e604f6..7a0f7998376a5bb73a37829f9a6= b3cdb9a3236a2 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1143,17 +1143,13 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk= , struct mptcp_addr_info *skc { struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; - int ret =3D -1; + int ret; =20 pernet =3D pm_nl_get_pernet_from_msk(msk); =20 rcu_read_lock(); - list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) { - ret =3D entry->addr.id; - break; - } - } + entry =3D __lookup_addr(pernet, skc); + ret =3D entry ? entry->addr.id : -1; rcu_read_unlock(); if (ret >=3D 0) return ret; @@ -1180,15 +1176,11 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, = struct mptcp_addr_info *skc) { struct pm_nl_pernet *pernet =3D pm_nl_get_pernet_from_msk(msk); struct mptcp_pm_addr_entry *entry; - bool backup =3D false; + bool backup; =20 rcu_read_lock(); - list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) { - backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry =3D __lookup_addr(pernet, skc); + backup =3D entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); rcu_read_unlock(); =20 return backup; --=20 2.45.2