summaryrefslogtreecommitdiff
path: root/samples/bpf/tracex5.bpf.c
diff options
context:
space:
mode:
authorDaniel T. Lee <danieltimlee@gmail.com>2023-08-18 18:01:15 +0900
committerAlexei Starovoitov <ast@kernel.org>2023-08-21 15:39:09 -0700
commit11430421b440427e10dfb4bd2bdc418fab0ff166 (patch)
treef156649f07571863b44b63965dc80f318ef4cff5 /samples/bpf/tracex5.bpf.c
parent02dabc247ad68b41758bf39f11e2d682b8b32dd7 (diff)
downloadlinux-11430421b440427e10dfb4bd2bdc418fab0ff166.tar.gz
linux-11430421b440427e10dfb4bd2bdc418fab0ff166.tar.bz2
linux-11430421b440427e10dfb4bd2bdc418fab0ff166.zip
samples/bpf: make tracing programs to be more CO-RE centric
The existing tracing programs have been developed for a considerable period of time and, as a result, do not properly incorporate the features of the current libbpf, such as CO-RE. This is evident in frequent usage of functions like PT_REGS* and the persistence of "hack" methods using underscore-style bpf_probe_read_kernel from the past. These programs are far behind the current level of libbpf and can potentially confuse users. Therefore, this commit aims to convert the outdated BPF programs to be more CO-RE centric. Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com> Link: https://lore.kernel.org/r/20230818090119.477441-6-danieltimlee@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples/bpf/tracex5.bpf.c')
-rw-r--r--samples/bpf/tracex5.bpf.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/samples/bpf/tracex5.bpf.c b/samples/bpf/tracex5.bpf.c
index 8cd697ee7047..4d3d6c9b25fa 100644
--- a/samples/bpf/tracex5.bpf.c
+++ b/samples/bpf/tracex5.bpf.c
@@ -10,6 +10,7 @@
#include <uapi/linux/unistd.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
#define __stringify(x) #x
#define PROG(F) SEC("kprobe/"__stringify(F)) int bpf_func_##F
@@ -46,7 +47,7 @@ PROG(SYS__NR_write)(struct pt_regs *ctx)
{
struct seccomp_data sd;
- bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
+ bpf_core_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
if (sd.args[2] == 512) {
char fmt[] = "write(fd=%d, buf=%p, size=%d)\n";
bpf_trace_printk(fmt, sizeof(fmt),
@@ -59,7 +60,7 @@ PROG(SYS__NR_read)(struct pt_regs *ctx)
{
struct seccomp_data sd;
- bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
+ bpf_core_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx));
if (sd.args[2] > 128 && sd.args[2] <= 1024) {
char fmt[] = "read(fd=%d, buf=%p, size=%d)\n";
bpf_trace_printk(fmt, sizeof(fmt),