lkml.org 
[lkml]   [2021]   [Nov]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH bpf-next] libbpf: Add ability to clear per-program load flags
On Thu, Nov 18, 2021 at 6:49 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Thu, Nov 18, 2021 at 2:33 AM Florent Revest <revest@chromium.org> wrote:
> >
> > We have a use-case where we construct a skeleton with a sleepable
> > program and if it fails to load then we want to make it non-sleepable by
> > clearing BPF_F_SLEEPABLE.
>
> I'd say the better way to do this is to have two programs (that share
> the logic, of course) and pick one or another at runtime:
>
> static int whatever_logic(bool sleepable) { ... }
>
> SEC("fentry.s/whatever")
> int BPF_PROG(whatever_sleepable, ...)
> {
> return whatever_logic(true);
> }
>
> SEC("fentry/whatever")
> int BPF_PROG(whatever_nonsleepable, ...)
> {
> return whatever_logic(false);
> }
>
>
> Then at runtime you can bpf_program__autoload(..., false) for a
> variant you don't want to load.

Ah cool, thanks! That's a good idea :) it will also look cleaner.

> This clear_flags business seems too low-level and too limited. Next
> thing we'll be adding a few more bit manipulation variants (e.g, reset
> flags). Let's see how far you can get with the use of existing
> features. I'd set_extra_flags() to be almost never used, btw. And they
> shouldn't, if can be avoided. So I'm hesitant to keep extending
> operations around prog_flags.

I agree

> But given we just added set_extra_flags() and it's already too
> limiting, let's change set_extra flags to just set_flags() that will
> override the flags with whatever user provides. Then with
> bpf_program__flags() and bpf_program__set_flags() you can express
> whatever you want without adding extra APIs. Care to fix that?

Sure, I'll send a patch for this! :)

\
 
 \ /
  Last update: 2021-11-18 21:30    [W:0.033 / U:1.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site