From nobody Thu Dec 26 15:02:04 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 026E21CEAA0 for ; Tue, 5 Nov 2024 09:41:08 +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=1730799669; cv=none; b=lhNcChvbZKjobPzy/lN/yosY8uPgTd1RpQAqXtb+A4IvoJzsGchzvtVw25zwjARma38ePv7LI6yIs5NmPnlf/Wtb+C/+PrRlWuy3HokpyvCaJb3zD4CumQn8gkIqX7cZgzuHCOmlvryUrkODuOX21zSAt3mh4Gcih2+VloXSStE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730799669; c=relaxed/simple; bh=p/FeQrTsBy9DjbSUQ6s1Th6P0uqVNuaVD+pj4E6Jnv8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fzTFDApuAACb6eI3tJYwA/GUCDrKa8BsrbSaWTPFAxYUDQdBFaIlZ7cjauF1k2mgO8ohhKn3dh3M2w68GDI7POU8UthwjuEZdmB4i/KuIRVt/hqQhqxXpQRZBbuwM+gBgL5YY61ieAUWs+rDO8N5b8bIZG2b7yF/NWdbHYIHhU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X05MCt5Z; 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="X05MCt5Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CE57C4CED0; Tue, 5 Nov 2024 09:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730799668; bh=p/FeQrTsBy9DjbSUQ6s1Th6P0uqVNuaVD+pj4E6Jnv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X05MCt5ZHi5XXbwlmm4AQLLGeU/Dvu6bhw/Z79ZPvy06HPke/dXQk6f+AcniZCMed Jp9C3I7fL3MDF818x4IpMMG3FlIlzBvJMEtG1q13doQKeef0hZvcax8k/vd6oXKQpQ ETPqvSxz26s5aPGl7JY0D2SNh4W+vdCDLoP4pNMy5Hj0e8HUU8LcTMzwztu4WAj84H p2+fZGikYiOFngbm+fTUgDqZsrHE9xahMl/U0FuAJUpuKGddfSfMq/JmberFmFVRuS igUSqoUdAzh7tL3h6TQ8mLpf4Wg2IlkwEid1G0IxHg94CsCfOfSgbxl+eQYKaXDH0R +xKwFWbVafVpQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-net 1/3] mptcp: add lookup_addr for userspace pm Date: Tue, 5 Nov 2024 17:40:58 +0800 Message-ID: <9ef5e8b9d589488850f31cb6dbd1da0f39e21210.1730799589.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Like __lookup_addr() helper in pm_netlink.c, a new helper mptcp_userspace_pm_lookup_addr() is also defined in pm_userspace.c. It looks up the corresponding mptcp_pm_addr_entry address in userspace_pm_local_addr_list through the passed "addr" parameter and returns it. This helper can be used in mptcp_userspace_pm_delete_local_addr(), mptcp_userspace_pm_get_local_id() and mptcp_userspace_pm_is_backup() to simplify the code. Please note that with this change now list_for_each_entry() is used in mptcp_userspace_pm_append_new_local_addr(), not list_for_each_entry_safe(), but that's OK to do so because mptcp_userspace_pm_lookup_addr() only returns an entry from the list, the list hasn't been modified here. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 58 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 56dfea9862b7..9c622b0e3e6e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -26,6 +26,19 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk) } } =20 +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (mptcp_addresses_equal(&entry->addr, addr, false)) + return entry; + } + return NULL; +} + static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) @@ -90,22 +103,20 @@ static int mptcp_userspace_pm_append_new_local_addr(st= ruct mptcp_sock *msk, static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *addr) { - struct mptcp_pm_addr_entry *entry, *tmp; struct sock *sk =3D (struct sock *)msk; + struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_lis= t, list) { - if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { - /* TODO: a refcount is needed because the entry can - * be used multiple times (e.g. fullmesh mode). - */ - list_del_rcu(&entry->list); - sock_kfree_s(sk, entry, sizeof(*entry)); - msk->pm.local_addr_used--; - return 0; - } - } - - return -EINVAL; + entry =3D mptcp_userspace_pm_lookup_addr(msk, &addr->addr); + if (!entry) + return -EINVAL; + + /* TODO: a refcount is needed because the entry can + * be used multiple times (e.g. fullmesh mode). + */ + list_del_rcu(&entry->list); + sock_kfree_s(sk, entry, sizeof(*entry)); + msk->pm.local_addr_used--; + return 0; } =20 static struct mptcp_pm_addr_entry * @@ -123,17 +134,12 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_soc= k *msk, unsigned int id) int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - struct mptcp_pm_addr_entry *entry =3D NULL, *e, new_entry; + struct mptcp_pm_addr_entry *entry =3D NULL, new_entry; __be16 msk_sport =3D ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; =20 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 =3D e; - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; @@ -153,15 +159,11 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *= msk, struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; - bool backup =3D false; + bool backup; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, false)) { - backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); + backup =3D entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); spin_unlock_bh(&msk->pm.lock); =20 return backup; --=20 2.45.2 From nobody Thu Dec 26 15:02:04 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 971011CEAA0 for ; Tue, 5 Nov 2024 09:41:10 +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=1730799670; cv=none; b=AvUGn8jWUqyctakWi4eHfOV8vfl8d7Za5qeiNP1v2qYwnInBMlAJ6u8ItRpJAPBHy222t0XMDpuDTRSNwy2fAlkU/vWWLU2QVLXfCmBVumCp5c61UGp2Id8wpf8LNnIGGlzgnR7YDQ9Rfl5Sig2n0sKZU2XlH7bU/i5cqgmoHXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730799670; c=relaxed/simple; bh=KPtlrGtxYJONQVEUACfPSIQJ7R6y/qNOjZKwIW4cMgU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cIJmHyjL+uZl1wQGiqB/GABXLF3MfaYdIpVmrjcMVAyy2LVhIGOIe6PX+vQ/oayNDTASMDktYm4jyroZZEoeVt33YqpTi6EwEdYL6LWdZbRA9LqbJRKwGTnCDH3HEbDlw7aCsVjEi/T/YN0+fE3eWw/FUjhkSAtINQS3RTG0+qU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kSj4Hz/2; 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="kSj4Hz/2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46611C4CECF; Tue, 5 Nov 2024 09:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730799670; bh=KPtlrGtxYJONQVEUACfPSIQJ7R6y/qNOjZKwIW4cMgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kSj4Hz/25Kog65n9XpkY8fPge2eDnewDcTudNfwWS+hM/pzxpivyakFTCfP8aTBkv Id3whAYeS1l00Fqk/EwxGslG4uLfggmUOfGOXK8HY/eIqBNZzzlFA3nMOlMFlUz7Zv AFMB0m3ULZB6NxSYJJEiseOKVGAy6xmowLVDUpWxWcqQYQLSCCai5eCxAwp3/WJMeE QHLJIMaUXFWODpATOLKN87WnAZmyiUbyaf858Yfg5ZOJ3BA6bPv+U11gZYUJ2aiVc1 q8nLwabtmEuAEAjwOHVZJnySPe7cVx7hqLX+m44cJC7cvlFmsNuoTXGe1P/ClGTpl2 wRPLHId20eKdw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-net 2/3] mptcp: update local address flags when setting it Date: Tue, 5 Nov 2024 17:40:59 +0800 Message-ID: <72998c181b94560b3d1e1e5843250ee2815869ac.1730799589.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Just like in-kernel pm, when userspace pm does set_flags, it needs to send out MP_PRIO signal, and also modify the flags of the corresponding address entry in the local address list. This patch implements the missing logic. Use mptcp_userspace_pm_lookup_addr() helper to find the address entry on userspace_pm_local_addr_list, if bkup is true, set the flags of the address entry with FLAG_BACKUP, otherwise, clear FLAG_BACKUP. Fixes: 892f396c8e68 ("mptcp: netlink: issue MP_PRIO signals from userspace = PMs") Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 9c622b0e3e6e..0c0f6f65accb 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -562,6 +562,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, s= truct genl_info *info) struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct net *net =3D sock_net(skb->sk); + struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret =3D -EINVAL; struct sock *sk; @@ -603,6 +604,16 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, = struct genl_info *info) if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup =3D 1; =20 + spin_lock_bh(&msk->pm.lock); + entry =3D mptcp_userspace_pm_lookup_addr(msk, &loc.addr); + if (entry) { + if (bkup) + entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; + else + entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; + } + spin_unlock_bh(&msk->pm.lock); + lock_sock(sk); ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); release_sock(sk); --=20 2.45.2 From nobody Thu Dec 26 15:02:04 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 C5FC11CEAA0 for ; Tue, 5 Nov 2024 09:41:12 +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=1730799672; cv=none; b=h7cbmuvQVREQA4EvNH6PKkc7qg6NAbsBG1aAO9yA9pK2vSAq567WV56vJs3G9yyzu9GwtNSBTPHajUM/K9OHldCfOJE6emQ64RgIzDI6/+RhBxxs2hZGrTSLvJN1NO2TqC2Nt5AcHWxApTDwQGi0tFqpR9FoGZP00lXQrEjYPkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730799672; c=relaxed/simple; bh=TdwHDStTHz0ZtxdE65IPfp02PyLZIKupedSDnKUIAzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bQZqeIvmnuQO304/NaZAmNGMbodk5RFpReUzvZnT9bzqxgdF4gEI3IsyyHCKmGuCc82etevlrEp9vsqwow/gov5UnATv6cHNBTbH/Cp2XJzUObBfUmvqif8OYW7TAvTA7wZ4YeyF4/Vk8H16FVBQ5ipNLNRUyLwrTIYM9QcWKxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UH/Wwnta; 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="UH/Wwnta" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 209ECC4CED0; Tue, 5 Nov 2024 09:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730799672; bh=TdwHDStTHz0ZtxdE65IPfp02PyLZIKupedSDnKUIAzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UH/WwntaI1zE6V8wI2CZ2cC3P1v9pENkWKdbTHC36OQr/4XeJN9yMTz94AcDcjKSS 0XdCBCp7B2Ov6qWZECc5aploRvQq/4zH7yVLIEtJxtO1PuKES82cHexPMJQ+U4aY8/ J40xNc4RdHMAipRWY+5+qTU476cKZiKcH0msTsEHeMMrQ/4GTeKl1JpAZb4zwLHkYa jfGDvvTBKuJzn2MiUVOdN5Y+T0BHEP5xDiesojRcM3T2u8uB+etPpalT6QSnfHg6GS KDoOtPYvA/5s3xZLewPU1xY9oOpsQY6XWquXWlqEMSfTjkWP4us03bHC2x1jfPObxM hX06BWKPjteCg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-net 3/3] mptcp: hold pm lock when deleting entry Date: Tue, 5 Nov 2024 17:41:00 +0800 Message-ID: <49c522bf883b5720c41d614885405f0deb38f518.1730799589.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang When traversing userspace_pm_local_addr_list and deleting an entry from it in mptcp_pm_nl_remove_doit(), msk->pm.lock should be held. This patch holds the lock in mptcp_pm_nl_remove_doit(). Fixes: d9a4594edabf ("mptcp: netlink: Add MPTCP_PM_CMD_REMOVE") Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 0c0f6f65accb..3664f3c1572e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -310,14 +310,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) =20 lock_sock(sk); =20 + spin_lock_bh(&msk->pm.lock); match =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); + spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; } =20 list_move(&match->list, &free_list); + spin_unlock_bh(&msk->pm.lock); =20 mptcp_pm_remove_addrs(msk, &free_list); =20 --=20 2.45.2