[v1,0/7] Fix perf trace libbpf 1.0+ compatibility

Message ID 20221103045437.163510-1-irogers@google.com
Headers
Series Fix perf trace libbpf 1.0+ compatibility |

Message

Ian Rogers Nov. 3, 2022, 4:54 a.m. UTC
  Perf trace can augment system calls with a BPF program passed as an
event. The BPF code for this lives in examples. This patch fixes the
example code to not used deprecated/removed APIs in libbpf. As libbpf
has similar header files to tools/perf/include/bpf the code is
transitioned to use the more standard libbpf code and the perf BPF
header files removed.

Ian Rogers (7):
  perf trace: Raw augmented syscalls fix libbpf 1.0+ compatibility
  perf trace: Etcsnoop fix libbpf 1.0+ compatibility
  perf trace: Augmented syscalls fix libbpf 1.0+ compatibility
  perf trace: hello fix libbpf 1.0+ compatibility
  perf trace: empty fix libbpf 1.0+ compatibility
  perf trace: 5sec fix libbpf 1.0+ compatibility
  perf bpf: Remove now unused BPF headers

 tools/perf/Makefile.perf                      |  5 --
 tools/perf/examples/bpf/5sec.c                |  8 +-
 .../examples/bpf/augmented_raw_syscalls.c     | 75 ++++++++++++++-----
 tools/perf/examples/bpf/augmented_syscalls.c  | 58 +++++++++-----
 tools/perf/examples/bpf/empty.c               | 13 +++-
 tools/perf/examples/bpf/etcsnoop.c            | 41 ++++++++--
 tools/perf/examples/bpf/hello.c               | 24 +++++-
 tools/perf/include/bpf/bpf.h                  | 70 -----------------
 tools/perf/include/bpf/linux/socket.h         | 24 ------
 tools/perf/include/bpf/pid_filter.h           | 21 ------
 tools/perf/include/bpf/stdio.h                | 16 ----
 tools/perf/include/bpf/unistd.h               | 10 ---
 12 files changed, 169 insertions(+), 196 deletions(-)
 delete mode 100644 tools/perf/include/bpf/bpf.h
 delete mode 100644 tools/perf/include/bpf/linux/socket.h
 delete mode 100644 tools/perf/include/bpf/pid_filter.h
 delete mode 100644 tools/perf/include/bpf/stdio.h
 delete mode 100644 tools/perf/include/bpf/unistd.h
  

Comments

Leo Yan Nov. 11, 2022, 12:09 p.m. UTC | #1
Hi Ian, Arnaldo,

On Wed, Nov 02, 2022 at 09:54:30PM -0700, Ian Rogers wrote:
> Perf trace can augment system calls with a BPF program passed as an
> event. The BPF code for this lives in examples. This patch fixes the
> example code to not used deprecated/removed APIs in libbpf. As libbpf
> has similar header files to tools/perf/include/bpf the code is
> transitioned to use the more standard libbpf code and the perf BPF
> header files removed.

I think you missed to update the code examples/bpf/sys_enter_openat.c,
either you could remove it (since it's duplicate with
augmented_raw_syscalls.c), or we should apply below fixing:

From f30af3b43060e482c54e113cbe90223173c69abd Mon Sep 17 00:00:00 2001
From: Leo Yan <leo.yan@linaro.org>
Date: Fri, 11 Nov 2022 12:02:24 +0000
Subject: [PATCH] perf trace: sys_enter_openat.c fix libbpf 1.0+ compatibility

Avoid use of tools/perf/include/bpf/bpf.h and use the more regular BPF
headers.

With fixing:

  # ./perf trace -e examples/bpf/sys_enter_openat.c
  0.000 irqbalance/1025 syscalls:sys_enter_openat(AT_FDCWD, "", O_RDONLY)
  1.596 irqbalance/1025 syscalls:sys_enter_openat(AT_FDCWD, "", O_RDONLY)
  1.832 irqbalance/1025 syscalls:sys_enter_openat(AT_FDCWD, "", O_RDONLY)
  1.864 irqbalance/1025 syscalls:sys_enter_openat(AT_FDCWD, "", O_RDONLY)

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/examples/bpf/sys_enter_openat.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/examples/bpf/sys_enter_openat.c b/tools/perf/examples/bpf/sys_enter_openat.c
index c4481c390d23..8edfa7c147d1 100644
--- a/tools/perf/examples/bpf/sys_enter_openat.c
+++ b/tools/perf/examples/bpf/sys_enter_openat.c
@@ -14,7 +14,9 @@
  * the return value.
  */
 
-#include <bpf/bpf.h>
+#include <linux/bpf.h>
+#include <linux/limits.h>
+#include <bpf/bpf_helpers.h>
 
 struct syscall_enter_openat_args {
 	unsigned long long unused;
@@ -25,9 +27,10 @@ struct syscall_enter_openat_args {
 	long		   mode;
 };
 
-int syscall_enter(openat)(struct syscall_enter_openat_args *args)
+SEC("syscalls:sys_enter_openat")
+int syscall_enter_openat(struct syscall_enter_openat_args *args)
 {
 	return 1;
 }
 
-license(GPL);
+char _license[] SEC("license") = "GPL";
  
Ian Rogers Nov. 15, 2022, 7:12 p.m. UTC | #2
On Fri, Nov 11, 2022 at 4:09 AM Leo Yan <leo.yan@linaro.org> wrote:
>
> Hi Ian, Arnaldo,
>
> On Wed, Nov 02, 2022 at 09:54:30PM -0700, Ian Rogers wrote:
> > Perf trace can augment system calls with a BPF program passed as an
> > event. The BPF code for this lives in examples. This patch fixes the
> > example code to not used deprecated/removed APIs in libbpf. As libbpf
> > has similar header files to tools/perf/include/bpf the code is
> > transitioned to use the more standard libbpf code and the perf BPF
> > header files removed.
>
> I think you missed to update the code examples/bpf/sys_enter_openat.c,
> either you could remove it (since it's duplicate with
> augmented_raw_syscalls.c), or we should apply below fixing:

Arnaldo, what do you think?

Thanks,
Ian

> From f30af3b43060e482c54e113cbe90223173c69abd Mon Sep 17 00:00:00 2001
> From: Leo Yan <leo.yan@linaro.org>
> Date: Fri, 11 Nov 2022 12:02:24 +0000
> Subject: [PATCH] perf trace: sys_enter_openat.c fix libbpf 1.0+ compatibility
>
> Avoid use of tools/perf/include/bpf/bpf.h and use the more regular BPF
> headers.
>
> With fixing:
>
>   # ./perf trace -e examples/bpf/sys_enter_openat.c
>   0.000 irqbalance/1025 syscalls:sys_enter_openat(AT_FDCWD, "", O_RDONLY)
>   1.596 irqbalance/1025 syscalls:sys_enter_openat(AT_FDCWD, "", O_RDONLY)
>   1.832 irqbalance/1025 syscalls:sys_enter_openat(AT_FDCWD, "", O_RDONLY)
>   1.864 irqbalance/1025 syscalls:sys_enter_openat(AT_FDCWD, "", O_RDONLY)
>
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
>  tools/perf/examples/bpf/sys_enter_openat.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/examples/bpf/sys_enter_openat.c b/tools/perf/examples/bpf/sys_enter_openat.c
> index c4481c390d23..8edfa7c147d1 100644
> --- a/tools/perf/examples/bpf/sys_enter_openat.c
> +++ b/tools/perf/examples/bpf/sys_enter_openat.c
> @@ -14,7 +14,9 @@
>   * the return value.
>   */
>
> -#include <bpf/bpf.h>
> +#include <linux/bpf.h>
> +#include <linux/limits.h>
> +#include <bpf/bpf_helpers.h>
>
>  struct syscall_enter_openat_args {
>         unsigned long long unused;
> @@ -25,9 +27,10 @@ struct syscall_enter_openat_args {
>         long               mode;
>  };
>
> -int syscall_enter(openat)(struct syscall_enter_openat_args *args)
> +SEC("syscalls:sys_enter_openat")
> +int syscall_enter_openat(struct syscall_enter_openat_args *args)
>  {
>         return 1;
>  }
>
> -license(GPL);
> +char _license[] SEC("license") = "GPL";