diff mbox series

[bpf-next,v2,1/2] bpf: Allow usage of BPF ringbuffer in sleepable programs

Message ID 20210204193622.3367275-2-kpsingh@kernel.org (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series BPF Ringbuffer + Sleepable Programs | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 5 maintainers not CCed: netdev@vger.kernel.org songliubraving@fb.com john.fastabend@gmail.com kafai@fb.com yhs@fb.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 17 this patch: 17
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 17 this patch: 17
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

KP Singh Feb. 4, 2021, 7:36 p.m. UTC
The BPF ringbuffer map is pre-allocated and the implementation logic
does not rely on disabling preemption or per-cpu data structures. Using
the BPF ringbuffer sleepable LSM and tracing programs does not trigger
any warnings with DEBUG_ATOMIC_SLEEP, DEBUG_PREEMPT,
PROVE_RCU and PROVE_LOCKING and LOCKDEP enabled.

This allows helpers like bpf_copy_from_user and bpf_ima_inode_hash to
write to the BPF ring buffer from sleepable BPF programs.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: KP Singh <kpsingh@kernel.org>
---
 kernel/bpf/verifier.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Song Liu Feb. 4, 2021, 8:57 p.m. UTC | #1
On Thu, Feb 4, 2021 at 11:39 AM KP Singh <kpsingh@kernel.org> wrote:
>
> The BPF ringbuffer map is pre-allocated and the implementation logic
> does not rely on disabling preemption or per-cpu data structures. Using
> the BPF ringbuffer sleepable LSM and tracing programs does not trigger
> any warnings with DEBUG_ATOMIC_SLEEP, DEBUG_PREEMPT,
> PROVE_RCU and PROVE_LOCKING and LOCKDEP enabled.
>
> This allows helpers like bpf_copy_from_user and bpf_ima_inode_hash to
> write to the BPF ring buffer from sleepable BPF programs.
>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: KP Singh <kpsingh@kernel.org>
> ---
>  kernel/bpf/verifier.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 5e09632efddb..4c33b4840438 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -10024,6 +10024,8 @@ static int check_map_prog_compatibility(struct bpf_verifier_env *env,
>                                 return -EINVAL;
>                         }
>                         break;
> +               case BPF_MAP_TYPE_RINGBUF:
> +                       break;
>                 default:
>                         verbose(env,
>                                 "Sleepable programs can only use array and hash maps\n");

Shall we update this message?

Thanks,
Song

> --
> 2.30.0.365.g02bc693789-goog
>
Andrii Nakryiko Feb. 5, 2021, 1:15 a.m. UTC | #2
On Thu, Feb 4, 2021 at 12:57 PM Song Liu <song@kernel.org> wrote:
>
> On Thu, Feb 4, 2021 at 11:39 AM KP Singh <kpsingh@kernel.org> wrote:
> >
> > The BPF ringbuffer map is pre-allocated and the implementation logic
> > does not rely on disabling preemption or per-cpu data structures. Using
> > the BPF ringbuffer sleepable LSM and tracing programs does not trigger
> > any warnings with DEBUG_ATOMIC_SLEEP, DEBUG_PREEMPT,
> > PROVE_RCU and PROVE_LOCKING and LOCKDEP enabled.
> >
> > This allows helpers like bpf_copy_from_user and bpf_ima_inode_hash to
> > write to the BPF ring buffer from sleepable BPF programs.
> >
> > Acked-by: Andrii Nakryiko <andrii@kernel.org>
> > Signed-off-by: KP Singh <kpsingh@kernel.org>
> > ---
> >  kernel/bpf/verifier.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 5e09632efddb..4c33b4840438 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -10024,6 +10024,8 @@ static int check_map_prog_compatibility(struct bpf_verifier_env *env,
> >                                 return -EINVAL;
> >                         }
> >                         break;
> > +               case BPF_MAP_TYPE_RINGBUF:
> > +                       break;
> >                 default:
> >                         verbose(env,
> >                                 "Sleepable programs can only use array and hash maps\n");
>
> Shall we update this message?
>

I fixed it up while applying. Thanks for staying alert!

> Thanks,
> Song
>
> > --
> > 2.30.0.365.g02bc693789-goog
> >
diff mbox series

Patch

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5e09632efddb..4c33b4840438 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -10024,6 +10024,8 @@  static int check_map_prog_compatibility(struct bpf_verifier_env *env,
 				return -EINVAL;
 			}
 			break;
+		case BPF_MAP_TYPE_RINGBUF:
+			break;
 		default:
 			verbose(env,
 				"Sleepable programs can only use array and hash maps\n");