On Thu, Nov 18, 2021 at 6:49 PM Andrii Nakryiko <andrii.nakryiko@xxxxxxxxx> wrote: > > On Thu, Nov 18, 2021 at 2:33 AM Florent Revest <revest@xxxxxxxxxxxx> 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! :)