From: Tao Chen <chen.dylane@linux.dev>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
eddyz87@gmail.com, haoluo@google.com, jolsa@kernel.org,
qmo@kernel.org
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
chen.dylane@gmail.com, Tao Chen <chen.dylane@linux.dev>,
Tao Chen <dylane.chen@didiglobal.com>
Subject: [PATCH bpf-next v8 1/4] libbpf: Extract prog load type check from libbpf_probe_bpf_helper
Date: Sat, 22 Feb 2025 00:33:32 +0800 [thread overview]
Message-ID: <20250221163335.262143-2-chen.dylane@linux.dev> (raw)
In-Reply-To: <20250221163335.262143-1-chen.dylane@linux.dev>
Extract prog load type check part from libbpf_probe_bpf_helper
suggested by Andrii, which will be used in both
libbpf_probe_bpf_{helper, kfunc}.
Cc: Tao Chen <dylane.chen@didiglobal.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
tools/lib/bpf/libbpf_probes.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/tools/lib/bpf/libbpf_probes.c b/tools/lib/bpf/libbpf_probes.c
index 9dfbe7750f56..a48a557314f6 100644
--- a/tools/lib/bpf/libbpf_probes.c
+++ b/tools/lib/bpf/libbpf_probes.c
@@ -413,6 +413,23 @@ int libbpf_probe_bpf_map_type(enum bpf_map_type map_type, const void *opts)
return libbpf_err(ret);
}
+static bool can_probe_prog_type(enum bpf_prog_type prog_type)
+{
+ /* we can't successfully load all prog types to check for BPF helper
+ * and kfunc support.
+ */
+ switch (prog_type) {
+ case BPF_PROG_TYPE_TRACING:
+ case BPF_PROG_TYPE_EXT:
+ case BPF_PROG_TYPE_LSM:
+ case BPF_PROG_TYPE_STRUCT_OPS:
+ return false;
+ default:
+ break;
+ }
+ return true;
+}
+
int libbpf_probe_bpf_helper(enum bpf_prog_type prog_type, enum bpf_func_id helper_id,
const void *opts)
{
@@ -427,18 +444,8 @@ int libbpf_probe_bpf_helper(enum bpf_prog_type prog_type, enum bpf_func_id helpe
if (opts)
return libbpf_err(-EINVAL);
- /* we can't successfully load all prog types to check for BPF helper
- * support, so bail out with -EOPNOTSUPP error
- */
- switch (prog_type) {
- case BPF_PROG_TYPE_TRACING:
- case BPF_PROG_TYPE_EXT:
- case BPF_PROG_TYPE_LSM:
- case BPF_PROG_TYPE_STRUCT_OPS:
- return -EOPNOTSUPP;
- default:
- break;
- }
+ if (!can_probe_prog_type(prog_type))
+ return libbpf_err(-EOPNOTSUPP);
buf[0] = '\0';
ret = probe_prog_load(prog_type, insns, insn_cnt, buf, sizeof(buf));
--
2.43.0
next prev parent reply other threads:[~2025-02-21 16:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-21 16:33 [PATCH bpf-next v8 0/4] Add prog_kfunc feature probe Tao Chen
2025-02-21 16:33 ` Tao Chen [this message]
2025-02-21 16:33 ` [PATCH bpf-next v8 2/4] libbpf: Init fd_array when prog probe load Tao Chen
2025-02-21 16:33 ` [PATCH bpf-next v8 3/4] libbpf: Add libbpf_probe_bpf_kfunc API Tao Chen
2025-02-21 16:33 ` [PATCH bpf-next v8 4/4] selftests/bpf: Add libbpf_probe_bpf_kfunc API selftests Tao Chen
2025-02-21 18:19 ` Eduard Zingerman
2025-02-22 3:00 ` Tao Chen
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=20250221163335.262143-2-chen.dylane@linux.dev \
--to=chen.dylane@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chen.dylane@gmail.com \
--cc=daniel@iogearbox.net \
--cc=dylane.chen@didiglobal.com \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qmo@kernel.org \
/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.