All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthieu Baerts <matttbe@kernel.org>
To: Geliang Tang <geliang@kernel.org>, mptcp@lists.linux.dev
Cc: Geliang Tang <tanggeliang@kylinos.cn>
Subject: Re: [PATCH mptcp-next v8 08/12] mptcp: pm: initialize and release mptcp_pm_ops
Date: Wed, 5 Mar 2025 12:57:51 +0100	[thread overview]
Message-ID: <385de26e-26ba-4227-a815-19e3edbb585c@kernel.org> (raw)
In-Reply-To: <0fd4e42c04c60d63c11463c792084b751c4e2e48.1741088339.git.tanggeliang@kylinos.cn>

Hi Geliang,

On 04/03/2025 12:40, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Add a struct mptcp_pm_ops pointer "ops" in struct mptcp_pm_data, and two
> functions mptcp_pm_initialize() and mptcp_pm_release(), to set and release
> this pointer. mptcp_pm_initialize() is invoked in mptcp_pm_data_reset(),
> while mptcp_pm_release() is invoked in mptcp_pm_destroy().
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  net/mptcp/pm.c       | 57 +++++++++++++++++++++++++++-----------------
>  net/mptcp/protocol.h |  1 +
>  2 files changed, 36 insertions(+), 22 deletions(-)
> 
> diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
> index 5018ed3c575f..e4d84aad3795 100644
> --- a/net/mptcp/pm.c
> +++ b/net/mptcp/pm.c
> @@ -970,16 +970,45 @@ void mptcp_pm_worker(struct mptcp_sock *msk)
>  	spin_unlock_bh(&msk->pm.lock);
>  }
>  
> +static void mptcp_pm_initialize(struct mptcp_sock *msk,
> +				struct mptcp_pm_ops *pm)

To avoid confusions, probably best to use "pm_ops" for "mptcp_pm_ops"
structures, and keep "pm" for "mptcp_pm_data" ones.

> +{
> +	if (!pm || !bpf_try_module_get(pm, pm->owner)) {
> +		pr_warn_once("pm %s fails, fallback to default pm",
> +			     pm->name);
> +		pm = &mptcp_pm_kernel;
> +	}
> +
> +	msk->pm.ops = pm;
> +	if (msk->pm.ops->init)

Note: this should be kept like that if 'init' is no longer mandatory
(see my comment on patch 7 -- but if it was mandatory because of what is
done in mptcp_pm_validate(), no need to check if it is set then)

> +		msk->pm.ops->init(msk);
> +
> +	pr_debug("pm %s initialized\n", pm->name);
> +}
> +
> +static void mptcp_pm_release(struct mptcp_sock *msk)
> +{
> +	struct mptcp_pm_ops *pm = msk->pm.ops;

Same here: pm_ops?

> +
> +	if (!pm)
When can we have this case? If we can have this case, that means each
time we will want to use "pm->ops", we will need to check if it is not
NULL. That feels wrong. The PM should be released only once.

We could add a WARN_ON_ONCE() here, but still, that feels wrong: why
adding a check only there? And if it is not needed, why adding it?

> +		return;
> +
> +	msk->pm.ops = NULL;
> +	if (pm->release)
> +		pm->release(msk);
> +
> +	bpf_module_put(pm, pm->owner);
Probably good to add this after:

  pr_debug("pm %s released\n", pm->name);

(...)

> @@ -991,25 +1020,9 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk)
>  	pm->rm_list_rx.nr = 0;
>  	WRITE_ONCE(pm->pm_type, pm_type);
>  
> -	if (pm_type == MPTCP_PM_TYPE_KERNEL) {
> -		bool subflows_allowed = !!mptcp_pm_get_subflows_max(msk);
> -
> -		/* pm->work_pending must be only be set to 'true' when
> -		 * pm->pm_type is set to MPTCP_PM_TYPE_KERNEL
> -		 */
> -		WRITE_ONCE(pm->work_pending,
> -			   (!!mptcp_pm_get_local_addr_max(msk) &&
> -			    subflows_allowed) ||
> -			   !!mptcp_pm_get_add_addr_signal_max(msk));
> -		WRITE_ONCE(pm->accept_addr,
> -			   !!mptcp_pm_get_add_addr_accept_max(msk) &&
> -			   subflows_allowed);
> -		WRITE_ONCE(pm->accept_subflow, subflows_allowed);
> -	} else {
> -		WRITE_ONCE(pm->work_pending, 0);
> -		WRITE_ONCE(pm->accept_addr, 0);
> -		WRITE_ONCE(pm->accept_subflow, 0);
This should be kept here, for all PM, then calling pm->ops->init(), see
my comment in patch 7.


Also, not directly related to this patch, it feels like we should add a
"struct_group(reset, ...)" in struct mptcp_pm_data to simplify the
reset, and make sure we don't miss any. This should be done in a
dedicated patch, and can be done later.
Note that mptcp_pm_data_reset() is called when the msk is created, and
after a disconnect, to be able to re-use the socket again after. We
should make sure everything has been reset, that's not something we
heavily test. In fact, maybe we already missed the reset of some fields
that could cause some issues? Can you check that please?

> -	}
> +	rcu_read_lock();
> +	mptcp_pm_initialize(msk, mptcp_pm_find(path_manager));
> +	rcu_read_unlock();
>  
>  	WRITE_ONCE(pm->addr_signal, 0);
>  	WRITE_ONCE(pm->remote_deny_join_id0, false);
Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


  reply	other threads:[~2025-03-05 11:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 11:40 [PATCH mptcp-next v8 00/12] BPF path manager, part 5 Geliang Tang
2025-03-04 11:40 ` [PATCH mptcp-next v8 01/12] mptcp: pm: define struct mptcp_pm_ops Geliang Tang
2025-03-05 11:42   ` Matthieu Baerts
2025-03-04 11:40 ` [PATCH mptcp-next v8 02/12] mptcp: sysctl: new sysctl to set path manager by name Geliang Tang
2025-03-04 11:40 ` [PATCH mptcp-next v8 03/12] mptcp: sysctl: map pm_type to path_manager Geliang Tang
2025-03-05 11:45   ` Matthieu Baerts
2025-03-04 11:40 ` [PATCH mptcp-next v8 04/12] mptcp: sysctl: map path_manager to pm_type Geliang Tang
2025-03-05 11:48   ` Matthieu Baerts
2025-03-04 11:40 ` [PATCH mptcp-next v8 05/12] mptcp: sysctl: add available_path_managers Geliang Tang
2025-03-04 11:40 ` [PATCH mptcp-next v8 06/12] mptcp: pm: in-kernel: register mptcp_pm_kernel Geliang Tang
2025-03-05  1:35   ` Geliang Tang
2025-03-05  9:11     ` Matthieu Baerts
2025-03-05  9:14       ` Geliang Tang
2025-03-05  9:22         ` Matthieu Baerts
2025-03-05  9:29           ` Geliang Tang
2025-03-05 11:51   ` Matthieu Baerts
2025-03-06 11:09     ` Geliang Tang
2025-03-06 11:27       ` Matthieu Baerts
2025-03-04 11:40 ` [PATCH mptcp-next v8 07/12] mptcp: pm: userspace: register mptcp_pm_userspace Geliang Tang
2025-03-05 11:53   ` Matthieu Baerts
2025-03-04 11:40 ` [PATCH mptcp-next v8 08/12] mptcp: pm: initialize and release mptcp_pm_ops Geliang Tang
2025-03-05 11:57   ` Matthieu Baerts [this message]
2025-03-04 11:40 ` [PATCH mptcp-next v8 09/12] mptcp: pm: add get_local_id() interface Geliang Tang
2025-03-04 11:40 ` [PATCH mptcp-next v8 10/12] mptcp: pm: add get_priority() interface Geliang Tang
2025-03-04 11:40 ` [PATCH mptcp-next v8 11/12] selftests: mptcp: add pm_type mapping tests Geliang Tang
2025-03-05 11:58   ` Matthieu Baerts
2025-03-04 11:40 ` [PATCH mptcp-next v8 12/12] selftests: mptcp: add path_manager sysctl test Geliang Tang
2025-03-05 11:59   ` Matthieu Baerts
2025-03-05 11:41 ` [PATCH mptcp-next v8 00/12] BPF path manager, part 5 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=385de26e-26ba-4227-a815-19e3edbb585c@kernel.org \
    --to=matttbe@kernel.org \
    --cc=geliang@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=tanggeliang@kylinos.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.