From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bot+bpf-ci@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
davem@davemloft.net, kuba@kernel.org, hawk@kernel.org,
john.fastabend@gmail.com, sdf@fomichev.me, lorenzo@kernel.org,
bpf@vger.kernel.org, netdev@vger.kernel.org,
martin.lau@kernel.org, clm@meta.com
Subject: Re: [PATCH bpf-next 1/2] libbpf: Move XDP frags flag to prog_flags
Date: Mon, 31 Aug 2026 12:22:26 +0200 [thread overview]
Message-ID: <874igawpwd.fsf@toke.dk> (raw)
In-Reply-To: <CAEf4BzaupNE1_svo_zjOB+ccfZWUrAm7s5kJDCMOnMKaZ4Odww@mail.gmail.com>
Andrii Nakryiko <andrii.nakryiko@gmail.com> writes:
> On Thu, Aug 27, 2026 at 6:27 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>>
>> bot+bpf-ci@kernel.org writes:
>>
>> >> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> >> index b749c01742ee0..7d6f0fe518d99 100644
>> >> --- a/tools/lib/bpf/libbpf.c
>> >> +++ b/tools/lib/bpf/libbpf.c
>> >
>> > [ ... ]
>> >
>> >> @@ -7879,6 +7877,12 @@ static int tracing_multi_mod_fd(struct bpf_program *prog, int *btf_obj_fd)
>> >> return 0;
>> >> }
>> >>
>> >> +static int setup_xdp_frags(struct bpf_program *prog, long cookie)
>> >> +{
>> >> + prog->prog_flags |= BPF_F_XDP_HAS_FRAGS;
>> >> + return 0;
>> >> +}
>> >
>> > Does storing BPF_F_XDP_HAS_FRAGS in prog->prog_flags here break callers
>> > that use bpf_program__set_flags()?
>> >
>> > bpf_program__set_flags() overwrites rather than OR-ing:
>> >
>> > int bpf_program__set_flags(struct bpf_program *prog, __u32 flags)
>> > {
>> > ...
>> > prog->prog_flags = flags;
>> > }
>> >
>> > Previously the flag was OR'd into the load-time opts by
>> > libbpf_prepare_prog_load(), so it survived any user manipulation of
>> > prog_flags between open and load. The new code latches it into
>> > prog->prog_flags at open time, so it's lost whenever a caller assigns
>> > prog_flags instead of OR-ing.
>>
>> Making it possible to manipulate the flag after loading is the whole
>> point of the patch, so this is expected. As for users like:
>>
>> > bpf_object_load_prog() passes prog->prog_flags straight to the kernel:
>> >
>> > load_attr.prog_flags = prog->prog_flags;
>> >
>> > Two in-tree callers do exactly that on SEC("xdp.frags") programs.
>> >
>> > bpftool (tools/bpf/bpftool/prog.c), i.e. 'bpftool prog load FILE PIN
>> > xdpmeta_dev DEV':
>> >
>> > if (prog_type == BPF_PROG_TYPE_XDP && xdpmeta_ifindex) {
>> > bpf_program__set_flags(pos, BPF_F_XDP_DEV_BOUND_ONLY);
>> > bpf_program__set_ifindex(pos, xdpmeta_ifindex);
>>
>> ...doing a set_flags without preserving the existing flags will lead to
>> clobbering, that's what's implied by the API? So any users doing that
>> are buggy, I'd argue.
>>
>> > Keeping the load-time 'opts->prog_flags
>> > |= BPF_F_XDP_HAS_FRAGS' in addition to the new prog_flags initialisation,
>> > or having bpf_program__set_flags() preserve section-implied bits, would give
>> > visibility without breaking existing callers.
>>
>> Both of these options will still make it impossible to turn off the
>> frags bit after loading the object. I guess we could do the "preserve
>> section-implied bits" part and add an explicit
>> bpf_program__clear_flags() to remove everything. What do others think?
>>
>> >> /* this is called as prog->sec_def->prog_prepare_load_fn for libbpf-supported sec_defs */
>> >> static int libbpf_prepare_prog_load(struct bpf_program *prog,
>> >> struct bpf_prog_load_opts *opts, long cookie)
>> >> @@ -7892,9 +7896,6 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
>> >> if (def & SEC_SLEEPABLE)
>> >> opts->prog_flags |= BPF_F_SLEEPABLE;
>> >>
>> >> - if (prog->type == BPF_PROG_TYPE_XDP && (def & SEC_XDP_FRAGS))
>> >> - opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
>> >> -
>> >
>> > Should setup_xdp_frags() keep a program type guard?
>>
>> No, the setup callback callback is called too early for this to make
>> sense. However:
>>
>> > The trigger requires a deliberate retype, but the guard removal is a
>> > behaviour change that the changelog does not mention. If the flag is meant
>> > to be XDP-only, should setup_xdp_frags() keep the type test or should
>> > bpf_program__set_type() drop the bit when moving away from
>> > BPF_PROG_TYPE_XDP?
>>
>> Clearing the type-specific flags on type change could make sense. I can
>> add that in v2 if others agree?
>
> no, let's not.
>
> But instead of making this XDP-specific custom callback, let's have a
> generic default libbpf setup callback that will do the same for
> BPF_F_SLEEPABLE, seems a fair game (and technically will allow to
> dynamically downgrade sleepable to non-sleepable, if there is ever any
> good reason to do that)
Alright, will do. I'll also fix up the destructive use of
bpf_program__set_flags() in the selftests, then :)
-Toke
prev parent reply other threads:[~2026-08-31 10:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 10:02 [PATCH bpf-next 1/2] libbpf: Move XDP frags flag to prog_flags Toke Høiland-Jørgensen
2026-08-27 10:02 ` [PATCH bpf-next 2/2] bpf: selftests: Check for XDP frags flag in bpf_program__flags() Toke Høiland-Jørgensen
2026-08-27 11:10 ` [PATCH bpf-next 1/2] libbpf: Move XDP frags flag to prog_flags bot+bpf-ci
2026-08-27 13:27 ` Toke Høiland-Jørgensen
2026-08-28 0:20 ` Andrii Nakryiko
2026-08-31 10:22 ` Toke Høiland-Jørgensen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874igawpwd.fsf@toke.dk \
--to=toke@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hawk@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=lorenzo@kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.