public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together
@ 2023-09-14  8:37 Larysa Zaremba
  2023-09-14 16:29 ` Stanislav Fomichev
  2023-09-14 16:38 ` Maciej Fijalkowski
  0 siblings, 2 replies; 7+ messages in thread
From: Larysa Zaremba @ 2023-09-14  8:37 UTC (permalink / raw)
  To: bpf
  Cc: Larysa Zaremba, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	linux-kernel

There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints
cannot coexist in a single program.

Allow those features to be used together by modifying the flags conditions.

Suggested-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/CAKH8qBuzgtJj=OKMdsxEkyML36VsAuZpcrsXcyqjdKXSJCBq=Q@mail.gmail.com/
Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
 kernel/bpf/offload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
index ee35f33a96d1..43aded96c79b 100644
--- a/kernel/bpf/offload.c
+++ b/kernel/bpf/offload.c
@@ -232,7 +232,11 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
 	    attr->prog_type != BPF_PROG_TYPE_XDP)
 		return -EINVAL;
 
-	if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
+	if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
+		return -EINVAL;
+
+	if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
+	    !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
 		return -EINVAL;
 
 	if (attr->prog_type == BPF_PROG_TYPE_SCHED_CLS &&
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together
  2023-09-14  8:37 [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together Larysa Zaremba
@ 2023-09-14 16:29 ` Stanislav Fomichev
  2023-09-14 16:49   ` Larysa Zaremba
  2023-09-14 16:38 ` Maciej Fijalkowski
  1 sibling, 1 reply; 7+ messages in thread
From: Stanislav Fomichev @ 2023-09-14 16:29 UTC (permalink / raw)
  To: Larysa Zaremba
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Hao Luo, Jiri Olsa, linux-kernel

On 09/14, Larysa Zaremba wrote:
> There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints
> cannot coexist in a single program.
> 
> Allow those features to be used together by modifying the flags conditions.
> 
> Suggested-by: Stanislav Fomichev <sdf@google.com>
> Link: https://lore.kernel.org/bpf/CAKH8qBuzgtJj=OKMdsxEkyML36VsAuZpcrsXcyqjdKXSJCBq=Q@mail.gmail.com/
> Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
> ---
>  kernel/bpf/offload.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
> index ee35f33a96d1..43aded96c79b 100644
> --- a/kernel/bpf/offload.c
> +++ b/kernel/bpf/offload.c
> @@ -232,7 +232,11 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
>  	    attr->prog_type != BPF_PROG_TYPE_XDP)
>  		return -EINVAL;
>  
> -	if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
> +	if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
> +		return -EINVAL;
> +

[..]

> +	if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
> +	    !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
>  		return -EINVAL;

Any reason we have 'attr->prog_flags & BPF_F_XDP_HAS_FRAGS' part here?
Seems like doing '!(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY)' should
be enough, right? We only want to bail out here when BPF_F_XDP_DEV_BOUND_ONLY
is not set and we don't really care whether BPF_F_XDP_HAS_FRAGS is set
or not at this point.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together
  2023-09-14  8:37 [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together Larysa Zaremba
  2023-09-14 16:29 ` Stanislav Fomichev
@ 2023-09-14 16:38 ` Maciej Fijalkowski
  2023-09-14 16:53   ` Larysa Zaremba
  1 sibling, 1 reply; 7+ messages in thread
From: Maciej Fijalkowski @ 2023-09-14 16:38 UTC (permalink / raw)
  To: Larysa Zaremba
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, linux-kernel

On Thu, Sep 14, 2023 at 10:37:11AM +0200, Larysa Zaremba wrote:
> There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints
> cannot coexist in a single program.
> 
> Allow those features to be used together by modifying the flags conditions.
> 
> Suggested-by: Stanislav Fomichev <sdf@google.com>
> Link: https://lore.kernel.org/bpf/CAKH8qBuzgtJj=OKMdsxEkyML36VsAuZpcrsXcyqjdKXSJCBq=Q@mail.gmail.com/
> Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>

Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>

Though it would be worth spelling out something in the commit msg about
additional check you're adding (frags flag can't go without dev bound)

> ---
>  kernel/bpf/offload.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
> index ee35f33a96d1..43aded96c79b 100644
> --- a/kernel/bpf/offload.c
> +++ b/kernel/bpf/offload.c
> @@ -232,7 +232,11 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
>  	    attr->prog_type != BPF_PROG_TYPE_XDP)
>  		return -EINVAL;
>  
> -	if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
> +	if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
> +		return -EINVAL;
> +
> +	if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
> +	    !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
>  		return -EINVAL;
>  
>  	if (attr->prog_type == BPF_PROG_TYPE_SCHED_CLS &&
> -- 
> 2.41.0
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together
  2023-09-14 16:29 ` Stanislav Fomichev
@ 2023-09-14 16:49   ` Larysa Zaremba
  2023-09-14 17:05     ` Stanislav Fomichev
  0 siblings, 1 reply; 7+ messages in thread
From: Larysa Zaremba @ 2023-09-14 16:49 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Hao Luo, Jiri Olsa, linux-kernel

On Thu, Sep 14, 2023 at 09:29:57AM -0700, Stanislav Fomichev wrote:
> On 09/14, Larysa Zaremba wrote:
> > There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints
> > cannot coexist in a single program.
> > 
> > Allow those features to be used together by modifying the flags conditions.
> > 
> > Suggested-by: Stanislav Fomichev <sdf@google.com>
> > Link: https://lore.kernel.org/bpf/CAKH8qBuzgtJj=OKMdsxEkyML36VsAuZpcrsXcyqjdKXSJCBq=Q@mail.gmail.com/
> > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
> > ---
> >  kernel/bpf/offload.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
> > index ee35f33a96d1..43aded96c79b 100644
> > --- a/kernel/bpf/offload.c
> > +++ b/kernel/bpf/offload.c
> > @@ -232,7 +232,11 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
> >  	    attr->prog_type != BPF_PROG_TYPE_XDP)
> >  		return -EINVAL;
> >  
> > -	if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
> > +	if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
> > +		return -EINVAL;
> > +
> 
> [..]
> 
> > +	if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
> > +	    !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
> >  		return -EINVAL;
> 
> Any reason we have 'attr->prog_flags & BPF_F_XDP_HAS_FRAGS' part here?
> Seems like doing '!(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY)' should
> be enough, right? We only want to bail out here when BPF_F_XDP_DEV_BOUND_ONLY
> is not set and we don't really care whether BPF_F_XDP_HAS_FRAGS is set
> or not at this point.

If !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY) at this point, program could 
be requesting offload.

Now I have thought about those conditions once more and they could be reduced to 
this:

if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY) &&
    attr->prog_flags != (BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
	return -EINVAL;

What do you think?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together
  2023-09-14 16:38 ` Maciej Fijalkowski
@ 2023-09-14 16:53   ` Larysa Zaremba
  0 siblings, 0 replies; 7+ messages in thread
From: Larysa Zaremba @ 2023-09-14 16:53 UTC (permalink / raw)
  To: Maciej Fijalkowski
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, linux-kernel

On Thu, Sep 14, 2023 at 06:38:15PM +0200, Maciej Fijalkowski wrote:
> On Thu, Sep 14, 2023 at 10:37:11AM +0200, Larysa Zaremba wrote:
> > There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints
> > cannot coexist in a single program.
> > 
> > Allow those features to be used together by modifying the flags conditions.
> > 
> > Suggested-by: Stanislav Fomichev <sdf@google.com>
> > Link: https://lore.kernel.org/bpf/CAKH8qBuzgtJj=OKMdsxEkyML36VsAuZpcrsXcyqjdKXSJCBq=Q@mail.gmail.com/
> > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
> 
> Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> 
> Though it would be worth spelling out something in the commit msg about
> additional check you're adding (frags flag can't go without dev bound)
>

Ok, I'll add to the commit message the below:

Frags are allowed only if program is dev-bound-only, but not if it is requesting 
bpf offload.

> > ---
> >  kernel/bpf/offload.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
> > index ee35f33a96d1..43aded96c79b 100644
> > --- a/kernel/bpf/offload.c
> > +++ b/kernel/bpf/offload.c
> > @@ -232,7 +232,11 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
> >  	    attr->prog_type != BPF_PROG_TYPE_XDP)
> >  		return -EINVAL;
> >  
> > -	if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
> > +	if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
> > +		return -EINVAL;
> > +
> > +	if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
> > +	    !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
> >  		return -EINVAL;
> >  
> >  	if (attr->prog_type == BPF_PROG_TYPE_SCHED_CLS &&
> > -- 
> > 2.41.0
> > 
> > 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together
  2023-09-14 17:05     ` Stanislav Fomichev
@ 2023-09-14 17:04       ` Larysa Zaremba
  0 siblings, 0 replies; 7+ messages in thread
From: Larysa Zaremba @ 2023-09-14 17:04 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Hao Luo, Jiri Olsa, linux-kernel

On Thu, Sep 14, 2023 at 10:05:47AM -0700, Stanislav Fomichev wrote:
> On Thu, Sep 14, 2023 at 9:55 AM Larysa Zaremba <larysa.zaremba@intel.com> wrote:
> >
> > On Thu, Sep 14, 2023 at 09:29:57AM -0700, Stanislav Fomichev wrote:
> > > On 09/14, Larysa Zaremba wrote:
> > > > There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints
> > > > cannot coexist in a single program.
> > > >
> > > > Allow those features to be used together by modifying the flags conditions.
> > > >
> > > > Suggested-by: Stanislav Fomichev <sdf@google.com>
> > > > Link: https://lore.kernel.org/bpf/CAKH8qBuzgtJj=OKMdsxEkyML36VsAuZpcrsXcyqjdKXSJCBq=Q@mail.gmail.com/
> > > > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
> > > > ---
> > > >  kernel/bpf/offload.c | 6 +++++-
> > > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
> > > > index ee35f33a96d1..43aded96c79b 100644
> > > > --- a/kernel/bpf/offload.c
> > > > +++ b/kernel/bpf/offload.c
> > > > @@ -232,7 +232,11 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
> > > >         attr->prog_type != BPF_PROG_TYPE_XDP)
> > > >             return -EINVAL;
> > > >
> > > > -   if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
> > > > +   if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
> > > > +           return -EINVAL;
> > > > +
> > >
> > > [..]
> > >
> > > > +   if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
> > > > +       !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
> > > >             return -EINVAL;
> > >
> > > Any reason we have 'attr->prog_flags & BPF_F_XDP_HAS_FRAGS' part here?
> > > Seems like doing '!(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY)' should
> > > be enough, right? We only want to bail out here when BPF_F_XDP_DEV_BOUND_ONLY
> > > is not set and we don't really care whether BPF_F_XDP_HAS_FRAGS is set
> > > or not at this point.
> >
> > If !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY) at this point, program could
> > be requesting offload.
> >
> > Now I have thought about those conditions once more and they could be reduced to
> > this:
> >
> > if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY) &&
> >     attr->prog_flags != (BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
> >         return -EINVAL;
> >
> > What do you think?
> 
> Ah, so this check is here to protect against the mbuf+offloaded
> combination? (looking at that other thread with Maciej)
> Let's keep your current way with two separate checks, but let's add
> your "/* Frags are allowed only if program is dev-bound-only, but not
> if it is requesting
> bpf offload. */" as a comment to the second check?

Ok, sound good to me.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together
  2023-09-14 16:49   ` Larysa Zaremba
@ 2023-09-14 17:05     ` Stanislav Fomichev
  2023-09-14 17:04       ` Larysa Zaremba
  0 siblings, 1 reply; 7+ messages in thread
From: Stanislav Fomichev @ 2023-09-14 17:05 UTC (permalink / raw)
  To: Larysa Zaremba
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Hao Luo, Jiri Olsa, linux-kernel

On Thu, Sep 14, 2023 at 9:55 AM Larysa Zaremba <larysa.zaremba@intel.com> wrote:
>
> On Thu, Sep 14, 2023 at 09:29:57AM -0700, Stanislav Fomichev wrote:
> > On 09/14, Larysa Zaremba wrote:
> > > There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints
> > > cannot coexist in a single program.
> > >
> > > Allow those features to be used together by modifying the flags conditions.
> > >
> > > Suggested-by: Stanislav Fomichev <sdf@google.com>
> > > Link: https://lore.kernel.org/bpf/CAKH8qBuzgtJj=OKMdsxEkyML36VsAuZpcrsXcyqjdKXSJCBq=Q@mail.gmail.com/
> > > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
> > > ---
> > >  kernel/bpf/offload.c | 6 +++++-
> > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
> > > index ee35f33a96d1..43aded96c79b 100644
> > > --- a/kernel/bpf/offload.c
> > > +++ b/kernel/bpf/offload.c
> > > @@ -232,7 +232,11 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
> > >         attr->prog_type != BPF_PROG_TYPE_XDP)
> > >             return -EINVAL;
> > >
> > > -   if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
> > > +   if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
> > > +           return -EINVAL;
> > > +
> >
> > [..]
> >
> > > +   if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
> > > +       !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
> > >             return -EINVAL;
> >
> > Any reason we have 'attr->prog_flags & BPF_F_XDP_HAS_FRAGS' part here?
> > Seems like doing '!(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY)' should
> > be enough, right? We only want to bail out here when BPF_F_XDP_DEV_BOUND_ONLY
> > is not set and we don't really care whether BPF_F_XDP_HAS_FRAGS is set
> > or not at this point.
>
> If !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY) at this point, program could
> be requesting offload.
>
> Now I have thought about those conditions once more and they could be reduced to
> this:
>
> if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY) &&
>     attr->prog_flags != (BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
>         return -EINVAL;
>
> What do you think?

Ah, so this check is here to protect against the mbuf+offloaded
combination? (looking at that other thread with Maciej)
Let's keep your current way with two separate checks, but let's add
your "/* Frags are allowed only if program is dev-bound-only, but not
if it is requesting
bpf offload. */" as a comment to the second check?

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-09-14 17:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-14  8:37 [PATCH bpf-next] bpf: Allow to use kfunc XDP hints and frags together Larysa Zaremba
2023-09-14 16:29 ` Stanislav Fomichev
2023-09-14 16:49   ` Larysa Zaremba
2023-09-14 17:05     ` Stanislav Fomichev
2023-09-14 17:04       ` Larysa Zaremba
2023-09-14 16:38 ` Maciej Fijalkowski
2023-09-14 16:53   ` Larysa Zaremba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox