[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87blpc4g14.fsf@toke.dk>
Date: Wed, 04 Mar 2020 10:37:27 +0100
From: Toke Høiland-Jørgensen <toke@...hat.com>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>,
Daniel Borkmann <daniel@...earbox.net>
Cc: Andrii Nakryiko <andriin@...com>, bpf <bpf@...r.kernel.org>,
Networking <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...com>,
Kernel Team <kernel-team@...com>, Yonghong Song <yhs@...com>
Subject: Re: [PATCH v3 bpf-next 1/3] bpf: switch BPF UAPI #define constants used from BPF program side to enums
Andrii Nakryiko <andrii.nakryiko@...il.com> writes:
> On Tue, Mar 3, 2020 at 3:01 PM Daniel Borkmann <daniel@...earbox.net> wrote:
>>
>> On 3/3/20 1:32 AM, Andrii Nakryiko wrote:
>> > Switch BPF UAPI constants, previously defined as #define macro, to anonymous
>> > enum values. This preserves constants values and behavior in expressions, but
>> > has added advantaged of being captured as part of DWARF and, subsequently, BTF
>> > type info. Which, in turn, greatly improves usefulness of generated vmlinux.h
>> > for BPF applications, as it will not require BPF users to copy/paste various
>> > flags and constants, which are frequently used with BPF helpers. Only those
>> > constants that are used/useful from BPF program side are converted.
>> >
>> > Signed-off-by: Andrii Nakryiko <andriin@...com>
>>
>> Just thinking out loud, is there some way this could be resolved generically
>> either from compiler side or via additional tooling where this ends up as BTF
>> data and thus inside vmlinux.h as anon enum eventually? bpf.h is one single
>> header and worst case libbpf could also ship a copy of it (?), but what about
>> all the other things one would need to redefine e.g. for tracing? Small example
>> that comes to mind are all these TASK_* defines in sched.h etc, and there's
>> probably dozens of other similar stuff needed too depending on the particular
>> case; would be nice to have some generic catch-all, hmm.
>
> Enum convertion seems to be the simplest and cleanest way,
> unfortunately (as far as I know). DWARF has some extensions capturing
> #defines, but values are strings (and need to be parsed, which is pain
> already for "1 << 1ULL"), and it's some obscure extension, not a
> standard thing. I agree would be nice not to have and change all UAPI
> headers for this, but I'm not aware of the solution like that.
Since this is a UAPI header, are we sure that no userspace programs are
using these defines in #ifdefs or something like that?
-Toke
Powered by blists - more mailing lists