bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Christy Lee <christylee@fb.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>,
	Christy Lee <christyc.y.lee@gmail.com>, bpf <bpf@vger.kernel.org>,
	"linux-perf-use." <linux-perf-users@vger.kernel.org>,
	Kernel Team <kernel-team@fb.com>, Wang Nan <wangnan0@huawei.com>,
	Wang ShaoBo <bobo.shaobowang@huawei.com>,
	YueHaibing <yuehaibing@huawei.com>
Subject: Re: [PATCH bpf-next v4 1/2] perf: stop using deprecated bpf_load_program() API
Date: Wed, 19 Jan 2022 15:25:43 -0800	[thread overview]
Message-ID: <CAEf4BzZHqBUt6hWN8isjdteO3MSHDMAsQpwn+19pTQEX1w_y=g@mail.gmail.com> (raw)
In-Reply-To: <20220119230636.1752684-2-christylee@fb.com>

On Wed, Jan 19, 2022 at 3:09 PM Christy Lee <christylee@fb.com> wrote:
>
> 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>
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>  tools/perf/tests/bpf.c      | 14 ++++----------
>  tools/perf/util/bpf-event.c | 16 ++++++++++++++++
>  2 files changed, 20 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..48872276c0b7 100644
> --- a/tools/perf/util/bpf-event.c
> +++ b/tools/perf/util/bpf-event.c
> @@ -33,6 +33,22 @@ struct btf * __weak btf__load_from_kernel_by_id(__u32 id)
>         return err ? ERR_PTR(err) : btf;
>  }
>
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wunused-parameter"

perf is using __maybe_unused to mark unused args, it's cleaner than pragma

> +int __weak
> +bpf_prog_load(enum bpf_prog_type prog_type,
> +               const char *prog_name, 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
> +}
> +#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-01-19 23:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19 23:06 [PATCH bpf-next v4 0/2] perf: stop using deprecated bpf APIs Christy Lee
2022-01-19 23:06 ` [PATCH bpf-next v4 1/2] perf: stop using deprecated bpf_load_program() API Christy Lee
2022-01-19 23:25   ` Andrii Nakryiko [this message]
     [not found]   ` <C02B00A0-5760-44CE-B727-90CF601A8437@fb.com>
2022-01-19 23:26     ` Andrii Nakryiko
     [not found]       ` <D753C41C-A70A-4316-8201-9F8369D1E627@fb.com>
2022-01-20  1:01         ` Andrii Nakryiko
2022-01-19 23:06 ` [PATCH bpf-next v4 2/2] perf: stop using deprecated bpf_object__next() API Christy Lee
2022-01-19 23:23   ` Song Liu
2022-01-23 17:06   ` Jiri Olsa
2022-02-02 17:00     ` Jiri Olsa
2022-02-02 17:24       ` Christy Lee
2022-02-09 16:11         ` Andrii Nakryiko
2022-02-12  7:31     ` Andrii Nakryiko
2022-01-20 22:58 ` [PATCH bpf-next v4 0/2] perf: stop using deprecated bpf APIs Andrii Nakryiko
2022-01-22 20:01   ` Arnaldo Carvalho de Melo
2022-01-22 20:38     ` Arnaldo Carvalho de Melo
2022-01-22 21:07       ` 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='CAEf4BzZHqBUt6hWN8isjdteO3MSHDMAsQpwn+19pTQEX1w_y=g@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=acme@kernel.org \
    --cc=andrii@kernel.org \
    --cc=bobo.shaobowang@huawei.com \
    --cc=bpf@vger.kernel.org \
    --cc=christyc.y.lee@gmail.com \
    --cc=christylee@fb.com \
    --cc=jolsa@redhat.com \
    --cc=kernel-team@fb.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=wangnan0@huawei.com \
    --cc=yuehaibing@huawei.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;
as well as URLs for NNTP newsgroup(s).