MPTCP Linux Development
 help / color / mirror / Atom feed
From: Matthieu Baerts <matttbe@kernel.org>
To: Geliang Tang <geliang.tang@suse.com>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v3 18/29] mptcp: add userspace pm addr entry refcount
Date: Sat, 7 Oct 2023 23:04:34 +0200	[thread overview]
Message-ID: <b3da54fb-37ba-4095-b10d-3fcb836212ed@kernel.org> (raw)
In-Reply-To: <f1389728746b0a44344a343dec208f31d7ed1986.1695631132.git.geliang.tang@suse.com>

Hi Geliang,

On 25/09/2023 10:41, Geliang Tang wrote:
> This patch adds userspace PM address entry refcount. Add a new filed
> 'refcont' in struct mptcp_pm_addr_entry, inited to 1.

Small nits: s/refcont/refcnt/  and s/inited/initiated/

(same comment for the next patch)

> Increase this counter in mptcp_nl_cmd_sf_create(), and decrease it in
> mptcp_userspace_pm_delete_local_addr() according the subflows value.

Please *always* explain why this commit is needed: why do we need a
refcount per address entry? Feel free to look at the ticket 403 for
inspirations.

(same comment for the next patch)

Also, please add the Closes tag:

Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/403

Another thing: should we consider this as a bug-fix? I think we can
because without this modification, we were not able to send a RM_ADDR if
another subflow using the same local address has been removed before. It
should not be a too annoying issue but if we consider it as an issue,
this should target 'mptcp-net' and have a Fixes tag:

Fixes: 24430f8bf516 ("mptcp: add address into userspace pm list")

One last thing: do you mind adding a new test to cover this case please?
e.g.

- the client creates an MPTCP connection: A <-> A
- it asks the userspace PM to add 2 subflows using the same source IP
address: B <-> B ; B <-> C
- it deletes one subflow: B <-> B
- it sends a RM_ADDR for B

Before the patch, it should fail: the kernel has removed the
corresponding entry for the local address from the list when removing
the subflow while another subflow was using the same local address.
After the patch, it should succeed.

Also, trying to send yet another RM_ADDR for B after the previous one
should result in an expected error. (it is possible we don't handle that
correctly)

> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> ---
>  net/mptcp/pm_userspace.c | 21 +++++++++++++++------
>  net/mptcp/protocol.h     |  2 ++
>  2 files changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index 30f4dd074a70..8efca1602e11 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
> @@ -70,6 +70,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
>  							1);
>  		list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list);
>  		msk->pm.local_addr_used++;
> +		refcount_set(&e->refcnt, 1);
>  		ret = e->addr.id;
>  	} else if (match) {
>  		ret = entry->addr.id;

Should you not increment the refcount here if there is a match?

> @@ -107,9 +108,12 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk,
>  	if (!entry)
>  		return -EINVAL;
>  
> -	/* TODO: a refcount is needed because the entry can
> -	 * be used multiple times (e.g. fullmesh mode).
> -	 */
> +	if (!refcount_dec_not_one(&entry->refcnt)) {
> +		pr_debug("userspace refcount error: refcnt=%d",
> +			 refcount_read(&entry->refcnt));
> +		return -EINVAL;

I'm not sure to understand why you treat that as an error.

Should you not simply use refcount_dec_and_test()? If after the
decrement, the counter is not 0, there is nothing to do: the entry is
still being used by another subflow, that's fine. You can keep a
pr_debug() but please do not mention 'error' and do not return a
negative value, no?

> +	}
> +
>  	list_del_rcu(&entry->list);
>  	kfree(entry);
>  	msk->pm.local_addr_used--;
> @@ -387,10 +391,15 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info)
>  	release_sock(sk);
>  
>  	spin_lock_bh(&msk->pm.lock);
> -	if (err)
> +	if (err) {
>  		mptcp_userspace_pm_delete_local_addr(msk, &local);
> -	else
> -		msk->pm.subflows++;
> +	} else {
> +		struct mptcp_pm_addr_entry *entry;
> +
> +		entry = mptcp_userspace_pm_get_entry(msk, &addr_l);
> +		if (entry && refcount_inc_not_zero(&entry->refcnt))

I don't think you need to change the code here: before creating the
subflow, 'mptcp_userspace_pm_append_new_local_addr()' has been called
which has initialised or incremented the refcount. Then it cannot be 0
and it doesn't need to be incremented, no?

> +			msk->pm.subflows++;
> +	}
>  	spin_unlock_bh(&msk->pm.lock);
>  
>   create_err:

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net

  reply	other threads:[~2023-10-07 21:04 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25  8:41 [PATCH mptcp-next v3 00/29] userspace pm enhancements Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 01/29] mptcp: drop useless ssk in pm_subflow_check_next Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 02/29] mptcp: use mptcp_check_fallback helper Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 03/29] mptcp: use mptcp_get_ext helper Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 04/29] mptcp: move sk assignment statement ahead Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 05/29] mptcp: define more local variables sk Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 06/29] selftests: mptcp: sockopt: drop mptcp_connect var Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 07/29] selftests: mptcp: display simult in extra_msg Geliang Tang
2023-09-28 20:54   ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 08/29] mptcp: add mptcpi_subflows_total counter Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 09/29] selftests: mptcp: add evts_get_info helper Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 10/29] selftests: mptcp: add chk_subflows_total helper Geliang Tang
2023-09-28 21:12   ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 11/29] selftests: mptcp: update userspace pm test helpers Geliang Tang
2023-09-28 20:56   ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 12/29] selftests: mptcp: userspace pm remove id 0 subflow Geliang Tang
2023-09-28 20:58   ` Matthieu Baerts
2023-10-05  8:32     ` Geliang Tang
2023-10-05  9:46       ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 13/29] mptcp: userspace pm allow creating " Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 14/29] selftests: mptcp: userspace pm create " Geliang Tang
2023-09-25  8:41 ` [PATCH mptcp-next v3 15/29] mptcp: userspace pm remove id 0 address Geliang Tang
2023-09-28 21:00   ` Matthieu Baerts
2023-10-05  8:35     ` Geliang Tang
2023-10-05  9:49       ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 16/29] selftests: " Geliang Tang
2023-09-28 21:01   ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 17/29] mptcp: add userspace_pm_get_entry helper Geliang Tang
2023-10-07 21:00   ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 18/29] mptcp: add userspace pm addr entry refcount Geliang Tang
2023-10-07 21:04   ` Matthieu Baerts [this message]
2023-10-07 21:09   ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 19/29] mptcp: add netlink " Geliang Tang
2023-10-07 21:05   ` Matthieu Baerts
2023-09-25  8:41 ` [PATCH mptcp-next v3 20/29] selftests: mptcp: add userspace pm fullmesh tests Geliang Tang
2023-10-07 21:06   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 21/29] selftests: mptcp: add mptcp_lib_kill_wait Geliang Tang
2023-10-08 10:49   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 22/29] selftests: mptcp: add mptcp_lib_evts_* Geliang Tang
2023-10-08 10:54   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 23/29] selftests: mptcp: userspace: print colored results Geliang Tang
2023-10-08 10:55   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 24/29] selftests: mptcp: add mptcp_lib_verify_listener_events Geliang Tang
2023-10-08 10:56   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 25/29] selftests: mptcp: add mptcp_lib_is_v6 Geliang Tang
2023-10-08 10:56   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 26/29] selftests: mptcp: add mptcp_lib_get_counter Geliang Tang
2023-10-08 10:56   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 27/29] selftests: mptcp: add mptcp_lib_make_file Geliang Tang
2023-10-08 10:58   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 28/29] selftests: mptcp: add mptcp_lib_check_transfer Geliang Tang
2023-10-08 10:59   ` Matthieu Baerts
2023-09-25  8:42 ` [PATCH mptcp-next v3 29/29] selftests: mptcp: add mptcp_lib_wait_local_port_listen Geliang Tang
2023-09-25  9:54   ` selftests: mptcp: add mptcp_lib_wait_local_port_listen: Tests Results MPTCP CI
2023-09-28 21:26   ` selftests: mptcp: add mptcp_lib_wait_local_port_listen: Build Failure MPTCP CI
2023-09-28 22:04   ` selftests: mptcp: add mptcp_lib_wait_local_port_listen: Tests Results MPTCP CI
2023-10-08 10:59   ` [PATCH mptcp-next v3 29/29] selftests: mptcp: add mptcp_lib_wait_local_port_listen Matthieu Baerts
2023-09-28 20:54 ` [PATCH mptcp-next v3 00/29] userspace pm enhancements Matthieu Baerts
2023-09-28 21:37   ` Matthieu Baerts
2023-10-05 15:53     ` Matthieu Baerts
2023-10-06 10:42       ` Geliang Tang
2023-10-31 17:40 ` Matthieu Baerts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3da54fb-37ba-4095-b10d-3fcb836212ed@kernel.org \
    --to=matttbe@kernel.org \
    --cc=geliang.tang@suse.com \
    --cc=mptcp@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox