All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geliang Tang <geliang.tang@suse.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v11 10/11] Squash to "selftests/bpf: Add bpf_rr scheduler"
Date: Tue, 4 Jul 2023 10:06:54 +0800	[thread overview]
Message-ID: <20230704020654.GA27381@localhost> (raw)
In-Reply-To: <d005f0e6692d6fdb175b5366c1b7afe253f7930e.camel@redhat.com>

On Mon, Jul 03, 2023 at 05:38:39PM +0200, Paolo Abeni wrote:
> On Tue, 2023-06-27 at 09:06 +0800, Geliang Tang wrote:
> > Use sk_storage to store last_snd, instead of using msk->last_snd.
> > 
> > Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> > ---
> >  tools/testing/selftests/bpf/bpf_tcp_helpers.h |  6 ++-
> >  .../selftests/bpf/progs/mptcp_bpf_rr.c        | 44 ++++++++++++++-----
> >  2 files changed, 39 insertions(+), 11 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/bpf_tcp_helpers.h b/tools/testing/selftests/bpf/bpf_tcp_helpers.h
> > index b4b766c7a68f..945dd46c98c0 100644
> > --- a/tools/testing/selftests/bpf/bpf_tcp_helpers.h
> > +++ b/tools/testing/selftests/bpf/bpf_tcp_helpers.h
> > @@ -259,7 +259,6 @@ struct mptcp_sched_ops {
> >  struct mptcp_sock {
> >  	struct inet_connection_sock	sk;
> >  
> > -	struct sock	*last_snd;
> >  	__u32		token;
> >  	struct sock	*first;
> >  	char		ca_name[TCP_CA_NAME_MAX];
> > @@ -271,5 +270,10 @@ extern void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk,
> >  					  struct mptcp_sched_data *data) __ksym;
> >  extern struct mptcp_subflow_context *
> >  mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) __ksym;
> > +static inline struct sock *
> > +mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
> > +{
> > +	return subflow->tcp_sock;
> > +}
> >  
> >  #endif
> > diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
> > index e101428e5906..21144e96ba56 100644
> > --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
> > +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
> > @@ -6,33 +6,49 @@
> >  
> >  char _license[] SEC("license") = "GPL";
> >  
> > +struct mptcp_rr_storage {
> > +	struct sock *last_snd;
> > +};
> > +struct sock *last_snd;
> > +
> > +struct {
> > +	__uint(type, BPF_MAP_TYPE_SK_STORAGE);
> > +	__uint(map_flags, BPF_F_NO_PREALLOC);
> > +	__type(key, int);
> > +	__type(value, struct mptcp_rr_storage);
> > +} mptcp_rr_map SEC(".maps");
> > +
> >  SEC("struct_ops/mptcp_sched_rr_init")
> > -void BPF_PROG(mptcp_sched_rr_init, const struct mptcp_sock *msk)
> > +void BPF_PROG(mptcp_sched_rr_init, struct mptcp_sock *msk)
> >  {
> >  }
> >  
> >  SEC("struct_ops/mptcp_sched_rr_release")
> > -void BPF_PROG(mptcp_sched_rr_release, const struct mptcp_sock *msk)
> > +void BPF_PROG(mptcp_sched_rr_release, struct mptcp_sock *msk)
> >  {
> > +	bpf_sk_storage_delete(&mptcp_rr_map, msk);
> >  }
> >  
> > -void BPF_STRUCT_OPS(bpf_rr_data_init, const struct mptcp_sock *msk,
> > +void BPF_STRUCT_OPS(bpf_rr_data_init, struct mptcp_sock *msk,
> >  		    struct mptcp_sched_data *data)
> >  {
> >  	mptcp_sched_data_set_contexts(msk, data);
> >  }
> >  
> > -int BPF_STRUCT_OPS(bpf_rr_get_subflow, const struct mptcp_sock *msk,
> > -		   struct mptcp_sched_data *data)
> > +int BPF_STRUCT_OPS(bpf_rr_get_subflow, struct mptcp_sock *msk,
> > +		   const struct mptcp_sched_data *data)
> >  {
> > +	struct mptcp_subflow_context *subflow;
> > +	struct mptcp_rr_storage *ptr;
> >  	int nr = 0;
> >  
> > -	for (int i = 0; i < MPTCP_SUBFLOWS_MAX; i++) {
> > -		if (!msk->last_snd || !data->contexts[i])
> > +	for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) {
> > +		subflow = mptcp_subflow_ctx_by_pos(data, i);
> > +		if (!last_snd || !subflow)
> 
> It looks like this is accessing a global variable ('last_snd'), which
> is probably not very safe.

Yes, it's should be a local variable. I just sent a patch to ML to fix
this:

https://patchwork.kernel.org/project/mptcp/patch/0b57bf87dc30e15782ba1fe2e925a7ce6ef0fc90.1688434547.git.geliang.tang@suse.com/

> 
> I think you could instead use inet_csk(msk)->icsk_ca_priv - currently
> unused.
> 
> As this is the only comment I have, no need to send a whole v12. I
> think we can merge the series as-is and then squash the needed change
> to replace the global variable and map used here with inet_csk(msk)-
> >icsk_ca_priv.

One of the purposes of this test is to demonstrate an example of using a
bpf map to store persistent schedulers data, so I prefer to use the bpf
map to implement it here.

Using inet_csk(msk)->icsk_ca_priv is much more complex. We need to add
the special write accesses for icsk_ca_priv.

Thanks,
-Geliang

> 
> Thanks!
> 
> Paolo
> 

  reply	other threads:[~2023-07-04  2:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27  1:06 [PATCH mptcp-next v11 00/11] BPF packet scheduler updates part 1 Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 01/11] Squash to "mptcp: drop last_snd and MPTCP_RESET_SCHEDULER" Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 02/11] Squash to "mptcp: add struct mptcp_sched_ops" Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 03/11] Squash to "mptcp: add sched_data_set_contexts helper" Geliang Tang
2023-07-13  7:15   ` Geliang Tang
2023-07-13  8:50     ` Matthieu Baerts
2023-06-27  1:06 ` [PATCH mptcp-next v11 04/11] mptcp: register default scheduler Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 05/11] Squash to "bpf: Add bpf_mptcp_sched_ops" Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 06/11] Squash to "bpf: Add bpf_mptcp_sched_kfunc_set" Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 07/11] Squash to "selftests/bpf: Add mptcp sched structs" Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 08/11] Squash to "selftests/bpf: Add bpf_first scheduler" Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 09/11] Squash to "selftests/bpf: Add bpf_bkup scheduler" Geliang Tang
2023-06-27  1:06 ` [PATCH mptcp-next v11 10/11] Squash to "selftests/bpf: Add bpf_rr scheduler" Geliang Tang
2023-07-03 15:38   ` Paolo Abeni
2023-07-04  2:06     ` Geliang Tang [this message]
2023-06-27  1:06 ` [PATCH mptcp-next v11 11/11] Squash to "selftests/bpf: Add bpf_red scheduler" Geliang Tang
2023-06-27  1:29   ` Squash to "selftests/bpf: Add bpf_red scheduler": Tests Results MPTCP CI
2023-06-27  9:13   ` MPTCP CI
2023-07-05  9:11 ` [PATCH mptcp-next v11 00/11] BPF packet scheduler updates part 1 Matthieu Baerts
2023-07-05 17:53   ` Mat Martineau
2023-07-06  8:49   ` Geliang Tang

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=20230704020654.GA27381@localhost \
    --to=geliang.tang@suse.com \
    --cc=mptcp@lists.linux.dev \
    --cc=pabeni@redhat.com \
    /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.