From nobody Mon Feb 9 07:54:46 2026 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (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 71A3712E64 for ; Fri, 8 Dec 2023 10:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="sPf2IpbV" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702030050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/or5oUWmDpXENm1x0X3HSQlL3UyP6fkZnnkAVM7KcHo=; b=sPf2IpbVNxE/Vf4FGMEoVky2VrsjR0l72VuzZgoR3/2MtJ2OJnfHkc5McGyXMxAB3xqOVq /JzegMnpnh5nekPVMoFUtGSqqBhJ84mt3O1ILEbaqnGhZzwysG9yMb4Brlq5V5ln/czVnP c/uDhauS06xzRgj5FNbD9qKTZ/lQ1s4= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Geliang Tang Subject: [PATCH mptcp-next v14 24/25] mptcp: add userspace pm addr entry refcount Date: Fri, 8 Dec 2023 18:07:37 +0800 Message-Id: <08ee5448fc4ecb8f77a79f5fd0919f3c18f66e02.1702029539.git.geliang.tang@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch adds the refcount of addree entry in userspace PM. Add a new counter 'refcnt' in struct mptcp_pm_addr_entry, initiated to 1. Increase this counter when an address is announced or a subflow is created in mptcp_pm_nl_announce_doit() and mptcp_pm_nl_subflow_create_doit(). And decrease it when an address is removed or a subflow is closed in mptcp_pm_nl_remove_doit() and mptcp_userspace_pm_delete_local_addr(). If the counter reaches to 1, free this entry. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/403 Fixes: 24430f8bf516 ("mptcp: add address into userspace pm list") Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 33 +++++++++++++++++++++++---------- net/mptcp/protocol.h | 2 ++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index eed1b351e307..eba78968e5b3 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -82,6 +82,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struc= t mptcp_sock *msk, __set_bit(e->addr.id, pernet->id_bitmap); list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); msk->pm.local_addr_used++; + refcount_set(&e->refcnt, 1); ret =3D e->addr.id; goto append_err; } @@ -107,12 +108,11 @@ static int mptcp_userspace_pm_delete_local_addr(struc= t mptcp_sock *msk, =20 entry =3D mptcp_userspace_pm_get_entry(msk, &addr->addr, false, false); if (entry) { - /* TODO: a refcount is needed because the entry can - * be used multiple times (e.g. fullmesh mode). - */ - list_del_rcu(&entry->list); - kfree(entry); - msk->pm.local_addr_used--; + if (!refcount_dec_not_one(&entry->refcnt)) { + list_del_rcu(&entry->list); + kfree(entry); + msk->pm.local_addr_used--; + } return 0; } =20 @@ -213,6 +213,11 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, str= uct genl_info *info) spin_lock_bh(&msk->pm.lock); =20 if (mptcp_pm_alloc_anno_list(msk, &addr_val.addr)) { + struct mptcp_pm_addr_entry *entry; + + entry =3D mptcp_userspace_pm_get_entry(msk, &addr_val.addr, false, false= ); + if (entry && !refcount_inc_not_zero(&entry->refcnt)) + pr_debug("userspace pm uninitialized entry"); msk->pm.add_addr_signaled++; mptcp_pm_announce_addr(msk, &addr_val.addr, false); mptcp_pm_nl_addr_send_ack(msk); @@ -318,8 +323,10 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struc= t genl_info *info) =20 mptcp_pm_remove_addrs(msk, &free_list); =20 - list_del_rcu(&match->list); - kfree(match); + if (!refcount_dec_not_one(&match->refcnt)) { + list_del_rcu(&match->list); + kfree(match); + } =20 release_sock(sk); =20 @@ -405,10 +412,16 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *s= kb, struct genl_info *info) release_sock(sk); =20 spin_lock_bh(&msk->pm.lock); - if (err) + if (err) { mptcp_userspace_pm_delete_local_addr(msk, &local); - else + } else { + struct mptcp_pm_addr_entry *entry; + + entry =3D mptcp_userspace_pm_get_entry(msk, &addr_l, false, false); + if (entry && !refcount_inc_not_zero(&entry->refcnt)) + pr_debug("userspace pm uninitialized entry"); msk->pm.subflows++; + } spin_unlock_bh(&msk->pm.lock); =20 create_err: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 493ee1871eed..5b33d7279654 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -8,6 +8,7 @@ #define __MPTCP_PROTOCOL_H =20 #include +#include #include #include #include @@ -244,6 +245,7 @@ struct mptcp_pm_addr_entry { u8 flags; int ifindex; struct socket *lsk; + refcount_t refcnt; }; =20 struct mptcp_data_frag { --=20 2.35.3