From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: 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
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@kernel.org,
andrii@kernel.org, daniel@iogearbox.net, martin.lau@kernel.org,
eddyz87@gmail.com, yonghong.song@linux.dev, clm@meta.com,
ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next 1/2] libbpf: Move XDP frags flag to prog_flags
Date: Thu, 27 Aug 2026 15:27:41 +0200 [thread overview]
Message-ID: <87cxv34rsi.fsf@toke.dk> (raw)
In-Reply-To: <f8413c983b5bbf569125bfa9d12a81f2293adc9905f89d746cc51276c21459ea@mail.kernel.org>
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?
-Toke
next prev parent reply other threads:[~2026-08-27 13:29 UTC|newest]
Thread overview: 5+ 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 [this message]
2026-08-28 0:20 ` Andrii Nakryiko
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=87cxv34rsi.fsf@toke.dk \
--to=toke@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox