linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <acme@kernel.org>, <linux-perf-users@vger.kernel.org>
Cc: <bpf@vger.kernel.org>, <christylee@fb.com>, <jolsa@redhat.com>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH v6 perf/core 1/2] perf: Stop using deprecated bpf_load_program() API
Date: Sat, 12 Feb 2022 07:51:24 -0800	[thread overview]
Message-ID: <20220212155125.3406232-2-andrii@kernel.org> (raw)
In-Reply-To: <20220212155125.3406232-1-andrii@kernel.org>

From: Christy Lee <christylee@fb.com>

bpf_load_program() API is deprecated, remove perf's usage of the
deprecated function. Add a __weak function declaration for libbpf
version compatibility.

Signed-off-by: Christy Lee <christylee@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/perf/tests/bpf.c      | 14 ++++----------
 tools/perf/util/bpf-event.c | 13 +++++++++++++
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 573490530194..57b9591f7cbb 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -281,8 +281,8 @@ static int __test__bpf(int idx)
 
 static int check_env(void)
 {
+	LIBBPF_OPTS(bpf_prog_load_opts, opts);
 	int err;
-	unsigned int kver_int;
 	char license[] = "GPL";
 
 	struct bpf_insn insns[] = {
@@ -290,19 +290,13 @@ static int check_env(void)
 		BPF_EXIT_INSN(),
 	};
 
-	err = fetch_kernel_version(&kver_int, NULL, 0);
+	err = fetch_kernel_version(&opts.kern_version, NULL, 0);
 	if (err) {
 		pr_debug("Unable to get kernel version\n");
 		return err;
 	}
-
-/* temporarily disable libbpf deprecation warnings */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-	err = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns,
-			       ARRAY_SIZE(insns),
-			       license, kver_int, NULL, 0);
-#pragma GCC diagnostic pop
+	err = bpf_prog_load(BPF_PROG_TYPE_KPROBE, NULL, license, insns,
+			    ARRAY_SIZE(insns), &opts);
 	if (err < 0) {
 		pr_err("Missing basic BPF support, skip this test: %s\n",
 		       strerror(errno));
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index a517eaa51eb3..bd1bc3c86cac 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -33,6 +33,19 @@ struct btf * __weak btf__load_from_kernel_by_id(__u32 id)
        return err ? ERR_PTR(err) : btf;
 }
 
+int __weak bpf_prog_load(enum bpf_prog_type prog_type,
+			 const char *prog_name __maybe_unused,
+			 const char *license,
+			 const struct bpf_insn *insns, size_t insn_cnt,
+			 const struct bpf_prog_load_opts *opts)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+	return bpf_load_program(prog_type, insns, insn_cnt, license,
+				opts->kern_version, opts->log_buf, opts->log_size);
+#pragma GCC diagnostic pop
+}
+
 struct bpf_program * __weak
 bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prev)
 {
-- 
2.30.2


  reply	other threads:[~2022-02-12 15:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-12 15:51 [PATCH v6 perf/core 0/2] perf: stop using deprecated bpf APIs Andrii Nakryiko
2022-02-12 15:51 ` Andrii Nakryiko [this message]
2022-02-12 15:51 ` [PATCH v6 perf/core 2/2] perf: Stop using deprecated bpf_object__next() API Andrii Nakryiko
2022-02-12 18:18 ` [PATCH v6 perf/core 0/2] perf: stop using deprecated bpf APIs Jiri Olsa
2022-02-13  1:47   ` Andrii Nakryiko
2022-02-14 18:58     ` Arnaldo Carvalho de Melo

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=20220212155125.3406232-2-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=acme@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=christylee@fb.com \
    --cc=jolsa@redhat.com \
    --cc=linux-perf-users@vger.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 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).