From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Andrii Nakryiko <andrii@kernel.org>
Cc: bpf <bpf@vger.kernel.org>,
Network Development <netdev@vger.kernel.org>,
Paul Moore <paul@paul-moore.com>,
Christian Brauner <brauner@kernel.org>,
Linux-Fsdevel <linux-fsdevel@vger.kernel.org>,
LSM List <linux-security-module@vger.kernel.org>,
Kees Cook <keescook@chromium.org>,
Kernel Team <kernel-team@meta.com>,
Sargun Dhillon <sargun@sargun.me>
Subject: Re: [PATCH RFC bpf-next 1/3] bpf: add mapper macro for bpf_cmd enum
Date: Mon, 11 Dec 2023 18:40:12 -0800 [thread overview]
Message-ID: <CAADnVQK6WWcgKtPNQrGe9dM7x1iMOyL943PVrJjT6ueBDFRyQw@mail.gmail.com> (raw)
In-Reply-To: <20231207222755.3920286-2-andrii@kernel.org>
On Thu, Dec 7, 2023 at 2:28 PM Andrii Nakryiko <andrii@kernel.org> wrote:
>
> +#define __BPF_CMD_MAPPER(FN, ctx...) \
> + FN(BPF_MAP_CREATE, 0) \
> + FN(BPF_MAP_LOOKUP_ELEM, 1) \
> + FN(BPF_MAP_UPDATE_ELEM, 2) \
> + FN(BPF_MAP_DELETE_ELEM, 3) \
> + FN(BPF_MAP_GET_NEXT_KEY, 4) \
So macro conversion across 4 main enums in uapi/bpf.h
is just to do:
+static const struct constant_table cmd_kvs[] = {
+ __BPF_CMD_MAPPER(__BPF_KV_FN)
+ {}
+};
on the kernel side,
right?
While in libbpf we already hard code name to value in arrays:
prog_type_name[], map_type_name[]
which probably will remain as-is, since libbpf needs to be
built independently from the kernel.
(unless we will say that tools/uapi/bpf.h is part of libbpf,
which probably not a good way).
There are more pros than cons in this enum uglification,
but cons are definitely staring in the face.
Have you considered other options?
Like using vmlinix BTF for parsing bpffs delegation?
[14083] ENUM 'bpf_cmd' encoding=UNSIGNED size=4 vlen=39
'BPF_MAP_CREATE' val=0
'BPF_MAP_LOOKUP_ELEM' val=1
'BPF_MAP_UPDATE_ELEM' val=2
'BPF_MAP_DELETE_ELEM' val=3
'BPF_MAP_GET_NEXT_KEY' val=4
'BPF_PROG_LOAD' val=5
Names and values are available.
btf_find_by_name_kind(vmlinux_btf, "bpd_cmd", BTF_KIND_ENUM);
is fast enough.
I suspect you'll argue that you don't want to tie in
bpffs delegation parsing with BTF ;)
While I can preemptively answer that in the case vmlinux BTF
is not available it's fine not to parse names and rely on hex.
next prev parent reply other threads:[~2023-12-12 2:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-07 22:27 [PATCH RFC bpf-next 0/3] BPF FS mount options parsing follow ups Andrii Nakryiko
2023-12-07 22:27 ` [PATCH RFC bpf-next 1/3] bpf: add mapper macro for bpf_cmd enum Andrii Nakryiko
2023-12-12 2:40 ` Alexei Starovoitov [this message]
2023-12-12 4:01 ` Andrii Nakryiko
2023-12-12 4:06 ` Alexei Starovoitov
2023-12-13 1:37 ` Martin KaFai Lau
2023-12-13 17:26 ` Andrii Nakryiko
2023-12-07 22:27 ` [PATCH RFC bpf-next 2/3] bpf: extend parsing logic for BPF FS delegate_cmds mount option Andrii Nakryiko
2023-12-07 22:27 ` [PATCH RFC bpf-next 3/3] selftests/bpf: utilize string values for delegate_xxx mount options 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=CAADnVQK6WWcgKtPNQrGe9dM7x1iMOyL943PVrJjT6ueBDFRyQw@mail.gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=keescook@chromium.org \
--cc=kernel-team@meta.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=sargun@sargun.me \
/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;
as well as URLs for NNTP newsgroup(s).