File perf-augmented_raw_syscalls-add-handler-for-openat.patch of Package perf
67
1
From: Arnaldo Carvalho de Melo <acme@redhat.com>
2
Date: Tue, 16 Jul 2019 12:31:10 -0300
3
Subject: perf augmented_raw_syscalls: Add handler for "openat"
4
MIME-Version: 1.0
5
Content-Type: text/plain; charset=UTF-8
6
Content-Transfer-Encoding: 8bit
7
Git-commit: 236dd5838871024d58d354ff8d0dab00ee59a867
8
Patch-mainline: v5.4-rc1
9
References: jsc#SLE-13661
10
11
I.e. for a syscall that has its second argument being a string, its
12
difficult these days to find 'open' being used in the wild :-)
13
14
Cc: Adrian Hunter <adrian.hunter@intel.com>
15
Cc: Jiri Olsa <jolsa@kernel.org>
16
Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
17
Cc: Namhyung Kim <namhyung@kernel.org>
18
Link: https://lkml.kernel.org/n/tip-yf3kbzirqrukd3fb2sp5qx4p@git.kernel.org
19
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
20
Signed-off-by: Tony Jones <tonyj@suse.de>
21
---
22
tools/perf/builtin-trace.c | 1 +
23
tools/perf/examples/bpf/augmented_raw_syscalls.c | 17 +++++++++++++++++
24
2 files changed, 18 insertions(+)
25
26
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
27
index 872c9cc982a5..a681b8c2ee4e 100644
28
--- a/tools/perf/builtin-trace.c
29
+++ b/tools/perf/builtin-trace.c
30
31
.arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ },
32
[2] = { .scnprintf = SCA_OPEN_FLAGS, /* flags */ }, }, },
33
{ .name = "openat",
34
+ .bpf_prog_name = { .sys_enter = "!syscalls:sys_enter_openat", },
35
.arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ },
36
[2] = { .scnprintf = SCA_OPEN_FLAGS, /* flags */ }, }, },
37
{ .name = "perf_event_open",
38
diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
39
index c66474a6ccf4..661936f90fe0 100644
40
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
41
+++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
42
43
return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len);
44
}
45
46
+SEC("!syscalls:sys_enter_openat")
47
+int sys_enter_openat(struct syscall_enter_args *args)
48
+{
49
+ int key = 0;
50
+ struct augmented_args_filename *augmented_args = bpf_map_lookup_elem(&augmented_filename_map, &key);
51
+ const void *filename_arg = (const void *)args->args[1];
52
+ unsigned int len = sizeof(augmented_args->args);
53
+
54
+ if (augmented_args == NULL)
55
+ return 1; /* Failure: don't filter */
56
+
57
+ len += augmented_filename__read(&augmented_args->filename, filename_arg, sizeof(augmented_args->filename.value));
58
+
59
+ /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */
60
+ return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len);
61
+}
62
+
63
SEC("raw_syscalls:sys_enter")
64
int sys_enter(struct syscall_enter_args *args)
65
{
66
67