From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Jiri Olsa <jolsa@kernel.org>, Stanislav Fomichev <sdf@google.com>,
Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH RFC bpf-next v2 1/4] bpf: Introduce BPF_HELPER_CALL
Date: Thu, 16 Feb 2023 00:59:28 +0100 [thread overview]
Message-ID: <20230215235931.380197-2-iii@linux.ibm.com> (raw)
In-Reply-To: <20230215235931.380197-1-iii@linux.ibm.com>
Make the code more readable by introducing a symbolic constant
instead of using 0.
Suggested-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
include/uapi/linux/bpf.h | 4 ++++
kernel/bpf/disasm.c | 2 +-
kernel/bpf/verifier.c | 12 +++++++-----
tools/include/linux/filter.h | 2 +-
tools/include/uapi/linux/bpf.h | 4 ++++
5 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 1503f61336b6..37f7588d5b2f 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1211,6 +1211,10 @@ enum bpf_link_type {
*/
#define BPF_PSEUDO_FUNC 4
+/* when bpf_call->src_reg == BPF_HELPER_CALL, bpf_call->imm == index of a bpf
+ * helper function (see ___BPF_FUNC_MAPPER below for a full list)
+ */
+#define BPF_HELPER_CALL 0
/* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
* offset to another bpf function
*/
diff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c
index 7b4afb7d96db..c11d9b5a45a9 100644
--- a/kernel/bpf/disasm.c
+++ b/kernel/bpf/disasm.c
@@ -19,7 +19,7 @@ static const char *__func_get_name(const struct bpf_insn_cbs *cbs,
{
BUILD_BUG_ON(ARRAY_SIZE(func_id_str) != __BPF_FUNC_MAX_ID);
- if (!insn->src_reg &&
+ if (insn->src_reg == BPF_HELPER_CALL &&
insn->imm >= 0 && insn->imm < __BPF_FUNC_MAX_ID &&
func_id_str[insn->imm])
return func_id_str[insn->imm];
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 272563a0b770..427525fc3791 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2947,7 +2947,8 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx,
/* BPF helpers that invoke callback subprogs are
* equivalent to BPF_PSEUDO_CALL above
*/
- if (insn->src_reg == 0 && is_callback_calling_function(insn->imm))
+ if (insn->src_reg == BPF_HELPER_CALL &&
+ is_callback_calling_function(insn->imm))
return -ENOTSUPP;
/* kfunc with imm==0 is invalid and fixup_kfunc_call will
* catch this error later. Make backtracking conservative
@@ -7522,7 +7523,7 @@ static int __check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn
}
if (insn->code == (BPF_JMP | BPF_CALL) &&
- insn->src_reg == 0 &&
+ insn->src_reg == BPF_HELPER_CALL &&
insn->imm == BPF_FUNC_timer_set_callback) {
struct bpf_verifier_state *async_cb;
@@ -14730,7 +14731,7 @@ static int do_check(struct bpf_verifier_env *env)
if (BPF_SRC(insn->code) != BPF_K ||
(insn->src_reg != BPF_PSEUDO_KFUNC_CALL
&& insn->off != 0) ||
- (insn->src_reg != BPF_REG_0 &&
+ (insn->src_reg != BPF_HELPER_CALL &&
insn->src_reg != BPF_PSEUDO_CALL &&
insn->src_reg != BPF_PSEUDO_KFUNC_CALL) ||
insn->dst_reg != BPF_REG_0 ||
@@ -14740,7 +14741,8 @@ static int do_check(struct bpf_verifier_env *env)
}
if (env->cur_state->active_lock.ptr) {
- if ((insn->src_reg == BPF_REG_0 && insn->imm != BPF_FUNC_spin_unlock) ||
+ if ((insn->src_reg == BPF_HELPER_CALL &&
+ insn->imm != BPF_FUNC_spin_unlock) ||
(insn->src_reg == BPF_PSEUDO_CALL) ||
(insn->src_reg == BPF_PSEUDO_KFUNC_CALL &&
(insn->off != 0 || !is_bpf_graph_api_kfunc(insn->imm)))) {
@@ -16933,7 +16935,7 @@ static struct bpf_prog *inline_bpf_loop(struct bpf_verifier_env *env,
static bool is_bpf_loop_call(struct bpf_insn *insn)
{
return insn->code == (BPF_JMP | BPF_CALL) &&
- insn->src_reg == 0 &&
+ insn->src_reg == BPF_HELPER_CALL &&
insn->imm == BPF_FUNC_loop;
}
diff --git a/tools/include/linux/filter.h b/tools/include/linux/filter.h
index 736bdeccdfe4..78dc208c8d88 100644
--- a/tools/include/linux/filter.h
+++ b/tools/include/linux/filter.h
@@ -261,7 +261,7 @@
((struct bpf_insn) { \
.code = BPF_JMP | BPF_CALL, \
.dst_reg = 0, \
- .src_reg = 0, \
+ .src_reg = BPF_HELPER_CALL, \
.off = 0, \
.imm = ((FUNC) - BPF_FUNC_unspec) })
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 1503f61336b6..37f7588d5b2f 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1211,6 +1211,10 @@ enum bpf_link_type {
*/
#define BPF_PSEUDO_FUNC 4
+/* when bpf_call->src_reg == BPF_HELPER_CALL, bpf_call->imm == index of a bpf
+ * helper function (see ___BPF_FUNC_MAPPER below for a full list)
+ */
+#define BPF_HELPER_CALL 0
/* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
* offset to another bpf function
*/
--
2.39.1
next prev parent reply other threads:[~2023-02-15 23:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-15 23:59 [PATCH RFC bpf-next v2 0/4] bpf: Support 64-bit pointers to kfuncs Ilya Leoshkevich
2023-02-15 23:59 ` Ilya Leoshkevich [this message]
2023-02-16 16:37 ` [PATCH RFC bpf-next v2 1/4] bpf: Introduce BPF_HELPER_CALL Alexei Starovoitov
2023-02-16 17:25 ` Stanislav Fomichev
2023-02-16 17:33 ` Alexei Starovoitov
2023-02-16 18:03 ` Stanislav Fomichev
2023-02-17 10:57 ` Ilya Leoshkevich
2023-02-17 16:19 ` Alexei Starovoitov
2023-02-17 17:08 ` Stanislav Fomichev
2023-02-15 23:59 ` [PATCH RFC bpf-next v2 2/4] bpf: Use BPF_HELPER_CALL in check_subprogs() Ilya Leoshkevich
2023-02-15 23:59 ` [PATCH RFC bpf-next v2 3/4] bpf, x86: Use bpf_jit_get_func_addr() Ilya Leoshkevich
2023-02-15 23:59 ` [PATCH RFC bpf-next v2 4/4] bpf: Support 64-bit pointers to kfuncs Ilya Leoshkevich
2023-02-17 9:40 ` Jiri Olsa
2023-02-17 10:53 ` Ilya Leoshkevich
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=20230215235931.380197-2-iii@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=jolsa@kernel.org \
--cc=sdf@google.com \
/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