samples: bpf: fix broken behavior of tracex2 write_size count
Subsystems (3)
PATCH 1/1 samples: bpf: fix broken behavior of tracex2 write_size count
Currently, there is a problem with tracex2, as it doesn't print the histogram properly and the results are misleading. (all results report as 0)
The problem is caused by a change in arguments of the function to which the kprobe connects. This tracex2 bpf program uses kprobe (attached to __x64_sys_write) to figure out the size of the write system call. In order to achieve this, the third argument 'count' must be intact.
The following is a prototype of the sys_write variant. (checked with pfunct)
~/git/linux$ pfunct -P fs/read_write.o | grep sys_write
ssize_t ksys_write(unsigned int fd, const char * buf, size_t count);
long int __x64_sys_write(const struct pt_regs * regs);
... cross compile with s390x ...
long int __s390_sys_write(struct pt_regs * regs);Since the __x64_sys_write (or s390x also) doesn't have the proper argument, changing the kprobe event to ksys_write will fix the problem.
--- samples/bpf/tracex2_kern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
samples/bpf/tracex2_kern.c +1 -1
@@ -78,7 +78,7 @@ struct {__uint (max_entries,1024 ); } my_hist_map SEC(".maps"); -SEC("kprobe/" SYSCALL(sys_write)) +SEC("kprobe/ksys_write")int bpf_prog3 (struct pt_regs *ctx) {long write_size =PT_REGS_PARM3 (ctx);
Signature · 1 line
2.34.1
Quoted 32 lines · Daniel T. Lee
Currently, there is a problem with tracex2, as it doesn't print the histogram properly and the results are misleading. (all results report as 0)
The problem is caused by a change in arguments of the function to which the kprobe connects. This tracex2 bpf program uses kprobe (attached to
__x64_sys_write) to figure out the size of the write system call. In order to achieve this, the third argument 'count' must be intact.The following is a prototype of the
sys_writevariant. (checked with pfunct)~/git/linux$ pfunct -P fs/read_write.o | grep sys_write ssize_t ksys_write(unsigned int fd, const char * buf, size_t count); long int __x64_sys_write(const struct pt_regs * regs); ... cross compile with s390x ... long int __s390_sys_write(struct pt_regs * regs);Since the
__x64_sys_write(or s390x also) doesn't have the proper argument, changing the kprobe event toksys_writewill fix the problem.Signed-off-by Daniel T. Lee <[email protected]>--- samples/bpf/tracex2_kern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)samples/bpf/tracex2_kern.c +0
-0
samples/bpf/tracex2_kern.c struct { · line 84
Quoted 8 lines
samples/bpf/tracex2_kern.c +1
-1@@ -78,7 +78,7 @@ struct {__uint (max_entries,1024 ); } my_hist_map SEC(".maps"); -SEC("kprobe/" SYSCALL(sys_write)) +SEC("kprobe/ksys_write")int bpf_prog3 (struct pt_regs *ctx) {long write_size =PT_REGS_PARM3 (ctx);
use
SEC("ksyscall/write")
int BPF_KSYSCALL(bpf_prog3, unsigned int fd, const char *buf, size_t count)
instead?
And maybe let's update other samples to use SEC("ksyscall") and BPF_KSYSCALL() macro as well?
Quoted 3 lines
--
2.34.1
Quoted 46 lines · Andrii Nakryiko
Quoted 32 lines · Daniel T. Lee
Currently, there is a problem with tracex2, as it doesn't print the histogram properly and the results are misleading. (all results report as 0)
The problem is caused by a change in arguments of the function to which the kprobe connects. This tracex2 bpf program uses kprobe (attached to
__x64_sys_write) to figure out the size of the write system call. In order to achieve this, the third argument 'count' must be intact.The following is a prototype of the
sys_writevariant. (checked with pfunct)~/git/linux$ pfunct -P fs/read_write.o | grep sys_write ssize_t ksys_write(unsigned int fd, const char * buf, size_t count); long int __x64_sys_write(const struct pt_regs * regs); ... cross compile with s390x ... long int __s390_sys_write(struct pt_regs * regs);Since the
__x64_sys_write(or s390x also) doesn't have the proper argument, changing the kprobe event toksys_writewill fix the problem.Signed-off-by Daniel T. Lee <[email protected]>--- samples/bpf/tracex2_kern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)samples/bpf/tracex2_kern.c +0
-0samples/bpf/tracex2_kern.c struct { · line 84
Quoted 8 lines
samples/bpf/tracex2_kern.c +1
-1@@ -78,7 +78,7 @@ struct {__uint (max_entries,1024 ); } my_hist_map SEC(".maps"); -SEC("kprobe/" SYSCALL(sys_write)) +SEC("kprobe/ksys_write")int bpf_prog3 (struct pt_regs *ctx) {long write_size =PT_REGS_PARM3 (ctx);use
Quoted 9 lines
SEC("ksyscall/write")
intBPF_KSYSCALL(bpf_prog3, unsigned int fd, const char *buf, size_t count)instead?
And maybe let's update other samples to use
SEC("ksyscall")andBPF_KSYSCALL()macro as well?
Thanks for the review!
I'll check with the new BPF_KSYSCALL and try to fix others as well!
Quoted 3 lines
Quoted 3 lines
--
2.34.1
Signature · 2 lines
Best, Daniel T. Lee