All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mat Martineau <martineau@kernel.org>
To: Geliang Tang <geliang@kernel.org>
Cc: mptcp@lists.linux.dev, Geliang Tang <tanggeliang@kylinos.cn>
Subject: Re: [PATCH mptcp-next v5 2/5] Squash to "bpf: Extend bpf_skc_to_mptcp_sock to MPTCP sock"
Date: Mon, 3 Mar 2025 17:37:04 -0800 (PST)	[thread overview]
Message-ID: <b45a0591-597a-46cf-7315-cf4dce7dbd7a@kernel.org> (raw)
In-Reply-To: <c43f5e1fe8da4db01749ede9d18af1a3a2134fd4.1740997925.git.tanggeliang@kylinos.cn>

On Mon, 3 Mar 2025, Geliang Tang wrote:

> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> Set msk->bpf_iter_task in bpf_mptcp_sock_from_sock() to allow
> mptcp_subflow bpt_iter can be used in cgroup/getsockopt,
> otherwise, the selftest in this set fails.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> net/mptcp/bpf.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
> index be222fa5f308..aff92f458e7f 100644
> --- a/net/mptcp/bpf.c
> +++ b/net/mptcp/bpf.c
> @@ -197,14 +197,22 @@ static struct bpf_struct_ops bpf_mptcp_sched_ops = {
>
> struct mptcp_sock *bpf_mptcp_sock_from_sock(struct sock *sk)
> {
> +	struct mptcp_sock *msk;
> +
> 	if (unlikely(!sk || !sk_fullsock(sk)))
> 		return NULL;
>
> -	if (sk->sk_protocol == IPPROTO_MPTCP)
> -		return mptcp_sk(sk);
> +	if (sk->sk_protocol == IPPROTO_MPTCP) {
> +		msk = mptcp_sk(sk);
> +		mptcp_set_bpf_iter_task(msk);

Hi Geliang -

The important part of the bpf_iter_task approach is to only set the 
task_struct pointer when the msk lock is already held, and to clear it 
before the msk lock is released. When used this way, the check ensures 
that the iterator code is both *running with the socket locked* and *in 
the same context where the lock is held*.

The code above will set msk->bpf_iter_task even when the lock is not held, 
and then it is never cleared.

To set/clear as expected for get/setsockopt I think the task pointer would 
have to be set in places where the locks are acquired and released, like 
these:

https://elixir.bootlin.com/linux/v6.14-rc5/source/kernel/bpf/cgroup.c#L1955
https://elixir.bootlin.com/linux/v6.14-rc5/source/kernel/bpf/cgroup.c#L1846


- Mat

> +		return msk;
> +	}
>
> -	if (sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
> -		return mptcp_sk(mptcp_subflow_ctx(sk)->conn);
> +	if (sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) {
> +		msk = mptcp_sk(mptcp_subflow_ctx(sk)->conn);
> +		mptcp_set_bpf_iter_task(msk);
> +		return msk;
> +	}
>
> 	return NULL;
> }
> -- 
> 2.43.0
>
>
>

  reply	other threads:[~2025-03-04  1:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 10:33 [PATCH mptcp-next v5 0/5] Squash to "Add mptcp_subflow bpf_iter support" Geliang Tang
2025-03-03 10:33 ` [PATCH mptcp-next v5 1/5] mptcp: add bpf_iter_task for mptcp_sock Geliang Tang
2025-03-03 10:33 ` [PATCH mptcp-next v5 2/5] Squash to "bpf: Extend bpf_skc_to_mptcp_sock to MPTCP sock" Geliang Tang
2025-03-04  1:37   ` Mat Martineau [this message]
2025-03-07  3:51     ` Geliang Tang
2025-03-07  3:54     ` Geliang Tang
2025-03-07  8:53       ` Matthieu Baerts
2025-03-03 10:33 ` [PATCH mptcp-next v5 3/5] Squash to "bpf: Add mptcp_subflow bpf_iter" Geliang Tang
2025-03-04  1:39   ` Mat Martineau
2025-03-07  3:54     ` Geliang Tang
2025-03-03 10:33 ` [PATCH mptcp-next v5 4/5] Revert "bpf: Acquire and release mptcp socket" Geliang Tang
2025-03-03 10:33 ` [PATCH mptcp-next v5 5/5] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Geliang Tang
2025-03-03 11:13 ` [PATCH mptcp-next v5 0/5] Squash to "Add mptcp_subflow bpf_iter support" Matthieu Baerts
2025-03-03 11:42 ` MPTCP CI

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=b45a0591-597a-46cf-7315-cf4dce7dbd7a@kernel.org \
    --to=martineau@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.