From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
<paul@paul-moore.com>, <brauner@kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>,
<linux-security-module@vger.kernel.org>, <keescook@chromium.org>,
<kernel-team@meta.com>, <sargun@sargun.me>
Subject: [PATCH RFC bpf-next 1/3] bpf: add mapper macro for bpf_cmd enum
Date: Thu, 7 Dec 2023 14:27:53 -0800 [thread overview]
Message-ID: <20231207222755.3920286-2-andrii@kernel.org> (raw)
In-Reply-To: <20231207222755.3920286-1-andrii@kernel.org>
Use similar approach to enum bpf_func_id and generate enumerators using
a macro with macro callback. This approach allows to generate derivative
tables for string-based lookups and whatnot. In this particular case,
this mapper macro will be used for parsing BPF FS delegate_cmds mount
option and their human-readable output format in mount info.
Validated no regressions using before/after BTF through
`bpftool btf dump <file> format c` command.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
include/uapi/linux/bpf.h | 81 ++++++++++++++++++----------------
tools/include/uapi/linux/bpf.h | 81 ++++++++++++++++++----------------
2 files changed, 86 insertions(+), 76 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index e0545201b55f..d05ea24ace3f 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -893,47 +893,52 @@ union bpf_iter_link_info {
* to the object have been closed and no references remain pinned to the
* filesystem or attached (for example, bound to a program or device).
*/
+#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) \
+ FN(BPF_PROG_LOAD, 5) \
+ FN(BPF_OBJ_PIN, 6) \
+ FN(BPF_OBJ_GET, 7) \
+ FN(BPF_PROG_ATTACH, 8) \
+ FN(BPF_PROG_DETACH, 9) \
+ FN(BPF_PROG_TEST_RUN, 10) \
+ FN(BPF_PROG_RUN, 10) /* alias for BPF_PROG_TEST_RUN */ \
+ FN(BPF_PROG_GET_NEXT_ID, 11) \
+ FN(BPF_MAP_GET_NEXT_ID, 12) \
+ FN(BPF_PROG_GET_FD_BY_ID, 13) \
+ FN(BPF_MAP_GET_FD_BY_ID, 14) \
+ FN(BPF_OBJ_GET_INFO_BY_FD, 15) \
+ FN(BPF_PROG_QUERY, 16) \
+ FN(BPF_RAW_TRACEPOINT_OPEN, 17) \
+ FN(BPF_BTF_LOAD, 18) \
+ FN(BPF_BTF_GET_FD_BY_ID, 19) \
+ FN(BPF_TASK_FD_QUERY, 20) \
+ FN(BPF_MAP_LOOKUP_AND_DELETE_ELEM, 21) \
+ FN(BPF_MAP_FREEZE, 22) \
+ FN(BPF_BTF_GET_NEXT_ID, 23) \
+ FN(BPF_MAP_LOOKUP_BATCH, 24) \
+ FN(BPF_MAP_LOOKUP_AND_DELETE_BATCH, 25) \
+ FN(BPF_MAP_UPDATE_BATCH, 26) \
+ FN(BPF_MAP_DELETE_BATCH, 27) \
+ FN(BPF_LINK_CREATE, 28) \
+ FN(BPF_LINK_UPDATE, 29) \
+ FN(BPF_LINK_GET_FD_BY_ID, 30) \
+ FN(BPF_LINK_GET_NEXT_ID, 31) \
+ FN(BPF_ENABLE_STATS, 32) \
+ FN(BPF_ITER_CREATE, 33) \
+ FN(BPF_LINK_DETACH, 34) \
+ FN(BPF_PROG_BIND_MAP, 35) \
+ FN(BPF_TOKEN_CREATE, 36) \
+ /* */
+#define __BPF_CMD_FN(x, y) x = y,
enum bpf_cmd {
- BPF_MAP_CREATE,
- BPF_MAP_LOOKUP_ELEM,
- BPF_MAP_UPDATE_ELEM,
- BPF_MAP_DELETE_ELEM,
- BPF_MAP_GET_NEXT_KEY,
- BPF_PROG_LOAD,
- BPF_OBJ_PIN,
- BPF_OBJ_GET,
- BPF_PROG_ATTACH,
- BPF_PROG_DETACH,
- BPF_PROG_TEST_RUN,
- BPF_PROG_RUN = BPF_PROG_TEST_RUN,
- BPF_PROG_GET_NEXT_ID,
- BPF_MAP_GET_NEXT_ID,
- BPF_PROG_GET_FD_BY_ID,
- BPF_MAP_GET_FD_BY_ID,
- BPF_OBJ_GET_INFO_BY_FD,
- BPF_PROG_QUERY,
- BPF_RAW_TRACEPOINT_OPEN,
- BPF_BTF_LOAD,
- BPF_BTF_GET_FD_BY_ID,
- BPF_TASK_FD_QUERY,
- BPF_MAP_LOOKUP_AND_DELETE_ELEM,
- BPF_MAP_FREEZE,
- BPF_BTF_GET_NEXT_ID,
- BPF_MAP_LOOKUP_BATCH,
- BPF_MAP_LOOKUP_AND_DELETE_BATCH,
- BPF_MAP_UPDATE_BATCH,
- BPF_MAP_DELETE_BATCH,
- BPF_LINK_CREATE,
- BPF_LINK_UPDATE,
- BPF_LINK_GET_FD_BY_ID,
- BPF_LINK_GET_NEXT_ID,
- BPF_ENABLE_STATS,
- BPF_ITER_CREATE,
- BPF_LINK_DETACH,
- BPF_PROG_BIND_MAP,
- BPF_TOKEN_CREATE,
+ __BPF_CMD_MAPPER(__BPF_CMD_FN)
__MAX_BPF_CMD,
};
+#undef __BPF_CMD_FN
enum bpf_map_type {
BPF_MAP_TYPE_UNSPEC,
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index e0545201b55f..d05ea24ace3f 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -893,47 +893,52 @@ union bpf_iter_link_info {
* to the object have been closed and no references remain pinned to the
* filesystem or attached (for example, bound to a program or device).
*/
+#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) \
+ FN(BPF_PROG_LOAD, 5) \
+ FN(BPF_OBJ_PIN, 6) \
+ FN(BPF_OBJ_GET, 7) \
+ FN(BPF_PROG_ATTACH, 8) \
+ FN(BPF_PROG_DETACH, 9) \
+ FN(BPF_PROG_TEST_RUN, 10) \
+ FN(BPF_PROG_RUN, 10) /* alias for BPF_PROG_TEST_RUN */ \
+ FN(BPF_PROG_GET_NEXT_ID, 11) \
+ FN(BPF_MAP_GET_NEXT_ID, 12) \
+ FN(BPF_PROG_GET_FD_BY_ID, 13) \
+ FN(BPF_MAP_GET_FD_BY_ID, 14) \
+ FN(BPF_OBJ_GET_INFO_BY_FD, 15) \
+ FN(BPF_PROG_QUERY, 16) \
+ FN(BPF_RAW_TRACEPOINT_OPEN, 17) \
+ FN(BPF_BTF_LOAD, 18) \
+ FN(BPF_BTF_GET_FD_BY_ID, 19) \
+ FN(BPF_TASK_FD_QUERY, 20) \
+ FN(BPF_MAP_LOOKUP_AND_DELETE_ELEM, 21) \
+ FN(BPF_MAP_FREEZE, 22) \
+ FN(BPF_BTF_GET_NEXT_ID, 23) \
+ FN(BPF_MAP_LOOKUP_BATCH, 24) \
+ FN(BPF_MAP_LOOKUP_AND_DELETE_BATCH, 25) \
+ FN(BPF_MAP_UPDATE_BATCH, 26) \
+ FN(BPF_MAP_DELETE_BATCH, 27) \
+ FN(BPF_LINK_CREATE, 28) \
+ FN(BPF_LINK_UPDATE, 29) \
+ FN(BPF_LINK_GET_FD_BY_ID, 30) \
+ FN(BPF_LINK_GET_NEXT_ID, 31) \
+ FN(BPF_ENABLE_STATS, 32) \
+ FN(BPF_ITER_CREATE, 33) \
+ FN(BPF_LINK_DETACH, 34) \
+ FN(BPF_PROG_BIND_MAP, 35) \
+ FN(BPF_TOKEN_CREATE, 36) \
+ /* */
+#define __BPF_CMD_FN(x, y) x = y,
enum bpf_cmd {
- BPF_MAP_CREATE,
- BPF_MAP_LOOKUP_ELEM,
- BPF_MAP_UPDATE_ELEM,
- BPF_MAP_DELETE_ELEM,
- BPF_MAP_GET_NEXT_KEY,
- BPF_PROG_LOAD,
- BPF_OBJ_PIN,
- BPF_OBJ_GET,
- BPF_PROG_ATTACH,
- BPF_PROG_DETACH,
- BPF_PROG_TEST_RUN,
- BPF_PROG_RUN = BPF_PROG_TEST_RUN,
- BPF_PROG_GET_NEXT_ID,
- BPF_MAP_GET_NEXT_ID,
- BPF_PROG_GET_FD_BY_ID,
- BPF_MAP_GET_FD_BY_ID,
- BPF_OBJ_GET_INFO_BY_FD,
- BPF_PROG_QUERY,
- BPF_RAW_TRACEPOINT_OPEN,
- BPF_BTF_LOAD,
- BPF_BTF_GET_FD_BY_ID,
- BPF_TASK_FD_QUERY,
- BPF_MAP_LOOKUP_AND_DELETE_ELEM,
- BPF_MAP_FREEZE,
- BPF_BTF_GET_NEXT_ID,
- BPF_MAP_LOOKUP_BATCH,
- BPF_MAP_LOOKUP_AND_DELETE_BATCH,
- BPF_MAP_UPDATE_BATCH,
- BPF_MAP_DELETE_BATCH,
- BPF_LINK_CREATE,
- BPF_LINK_UPDATE,
- BPF_LINK_GET_FD_BY_ID,
- BPF_LINK_GET_NEXT_ID,
- BPF_ENABLE_STATS,
- BPF_ITER_CREATE,
- BPF_LINK_DETACH,
- BPF_PROG_BIND_MAP,
- BPF_TOKEN_CREATE,
+ __BPF_CMD_MAPPER(__BPF_CMD_FN)
__MAX_BPF_CMD,
};
+#undef __BPF_CMD_FN
enum bpf_map_type {
BPF_MAP_TYPE_UNSPEC,
--
2.34.1
next prev parent reply other threads:[~2023-12-07 22:28 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 ` Andrii Nakryiko [this message]
2023-12-12 2:40 ` [PATCH RFC bpf-next 1/3] bpf: add mapper macro for bpf_cmd enum Alexei Starovoitov
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=20231207222755.3920286-2-andrii@kernel.org \
--to=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 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.