diff mbox series

[bpf-next] bpf: Allow to use kfunc XDP hints and frags together

Message ID 20230914083716.57443-1-larysa.zaremba@intel.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] bpf: Allow to use kfunc XDP hints and frags together | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1342 this patch: 1342
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 1364 this patch: 1364
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1365 this patch: 1365
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-0 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-1 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on s390x with gcc

Commit Message

Larysa Zaremba Sept. 14, 2023, 8:37 a.m. UTC
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(-)

Comments

Stanislav Fomichev Sept. 14, 2023, 4:29 p.m. UTC | #1
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.
Fijalkowski, Maciej Sept. 14, 2023, 4:38 p.m. UTC | #2
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
> 
>
Larysa Zaremba Sept. 14, 2023, 4:49 p.m. UTC | #3
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?
Larysa Zaremba Sept. 14, 2023, 4:53 p.m. UTC | #4
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
> > 
> >
Larysa Zaremba Sept. 14, 2023, 5:04 p.m. UTC | #5
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.
Stanislav Fomichev Sept. 14, 2023, 5:05 p.m. UTC | #6
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?
diff mbox series

Patch

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 &&