sys_enter tracepoint ctx structure
Hi!
Should perf_call_bpf_enter/exit (kernel/trace/trace_syscalls.c) use struct trace_event_raw_sys_enter/exit instead of locally crafted struct syscall_tp_t nowadays? test_progs's vmlinux test expects it as the context.
Or at least use struct trace_entry instead of struct pt_regs?
I have a problem with one RT patch with extends trace_entry.
Signature · 2 lines
WBR, Yauheni Kaliuta
Quoted 6 lines · Yauheni Kaliuta
Hi!
Should perf_call_bpf_enter/exit (
kernel/trace/trace_syscalls.c) use struct trace_event_raw_sys_enter/exit instead of locally crafted structsyscall_tp_tnowadays?
No. It needs syscall_tp_t.
Quoted 2 lines
test_progs's vmlinux test
expects it as the context.
what do you mean? Pls share a code pointer?
Quoted 3 lines
Or at least use struct
trace_entryinstead of structpt_regs?
no. It needs a pointer to pt_regs.
See all of the pe_* flavor of helpers.
Quoted 3 lines
I have a problem with one RT patch with extends
trace_entry.
Just extend it. It shouldn't matter.
I'm likely missing something.
Hi, Alexei!
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 5 lines · Yauheni Kaliuta
Hi!
Should perf_call_bpf_enter/exit (
kernel/trace/trace_syscalls.c) use struct trace_event_raw_sys_enter/exit instead of locally crafted structsyscall_tp_tnowadays?
Quoted 7 lines
No. It needs
syscall_tp_t.test_progs's vmlinux test
Quoted 2 lines
expects it as the context.
what do you mean? Pls share a code pointer?
https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/test_vmlinux.c#L19
SEC("tp/syscalls/sys_enter_nanosleep")
int handle__tp(struct trace_event_raw_sys_enter *args)
So, should it use different structure then? syscall_tp_t to be declared publicly?
Quoted 9 lines
Quoted 3 lines
Or at least use struct
trace_entryinstead of structpt_regs?no. It needs a pointer to
pt_regs.
See all of the pe_* flavor of helpers.Quoted 1 line
Quoted 5 lines
Quoted 2 lines
I have a problem with one RT patch with extends
trace_entry.Just extend it. It shouldn't matter.
I'm likely missing something.
Or me. Let's figure out :)
Signature · 2 lines
WBR, Yauheni Kaliuta
Quoted 19 lines · Yauheni Kaliuta
Hi, Alexei!
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 5 lines · Yauheni Kaliuta
Hi!
Should perf_call_bpf_enter/exit (
kernel/trace/trace_syscalls.c) use struct trace_event_raw_sys_enter/exit instead of locally crafted structsyscall_tp_tnowadays?No. It needs
syscall_tp_t.test_progs's vmlinux test
Quoted 2 lines
expects it as the context.
Quoted 6 lines
Quoted 1 line
what do you mean? Pls share a code pointer?
https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/test_vmlinux.c#L19
SEC("tp/syscalls/sys_enter_nanosleep")
inthandle__tp(struct trace_event_raw_sys_enter *args)
I see. That bit is correct and that's what bpftrace is doing when attaching to syscalls.
What do you see in your patched RT kernel when you do:
cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format ?
Depending on the answer we might need to fix
the kernel side that has to use struct trace_entry
in syscall_tp_t instead of plain long long.
Hi, Alexei!
Quoted 22 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 13 lines · Yauheni Kaliuta
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Should perf_call_bpf_enter/exit (
kernel/trace/trace_syscalls.c) use struct trace_event_raw_sys_enter/exit instead of locally crafted structsyscall_tp_tnowadays?No. It needs
syscall_tp_t.test_progs's vmlinux test
Quoted 2 lines
expects it as the context.
Quoted 6 lines
Quoted 1 line
what do you mean? Pls share a code pointer?
https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/test_vmlinux.c#L19
SEC("tp/syscalls/sys_enter_nanosleep")
inthandle__tp(struct trace_event_raw_sys_enter *args)
Quoted 8 lines
I see. That bit is correct and that's what bpftrace is doing when attaching to syscalls.
What do you see in your patched RT kernel when you do:
cat/sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format?
Depending on the answer we might need to fix
the kernel side that has to use structtrace_entry
insyscall_tp_tinstead of plain long long.
# cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format
name: sys_enter_nanosleep
ID: 374
format:
field:unsigned short common_type; offset:0; size:2; signed:0;
field:unsigned char common_flags; offset:2; size:1; signed:0;
field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
field:int common_pid; offset:4; size:4; signed:1;
field:unsigned char common_preempt_lazy_count; offset:8; size:1; signed:0; field:int __syscall_nr; offset:12; size:4; signed:1;
field:struct __kernel_timespec * rqtp; offset:16; size:8; signed:0;
field:struct __kernel_timespec * rmtp; offset:24; size:8; signed:0;print fmt: "rqtp: 0x%08lx, rmtp: 0x%08lx", ((unsigned long)(REC->rqtp)), ((unsigned long)(REC->rmtp))
Signature · 2 lines
WBR, Yauheni Kaliuta
Quoted 44 lines · Yauheni Kaliuta
Hi, Alexei!
Quoted 22 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 13 lines · Yauheni Kaliuta
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Should perf_call_bpf_enter/exit (
kernel/trace/trace_syscalls.c) use struct trace_event_raw_sys_enter/exit instead of locally crafted structsyscall_tp_tnowadays?No. It needs
syscall_tp_t.test_progs's vmlinux test
Quoted 2 lines
expects it as the context.
Quoted 6 lines
Quoted 1 line
what do you mean? Pls share a code pointer?
https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/test_vmlinux.c#L19
SEC("tp/syscalls/sys_enter_nanosleep")
inthandle__tp(struct trace_event_raw_sys_enter *args)Quoted 8 lines
I see. That bit is correct and that's what bpftrace is doing when attaching to syscalls.
What do you see in your patched RT kernel when you do:
cat/sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format?
Depending on the answer we might need to fix
the kernel side that has to use structtrace_entry
insyscall_tp_tinstead of plain long long.# cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format name: sys_enter_nanosleep ID: 374 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:unsigned char common_preempt_lazy_count; offset:8; size:1; signed:0;
Quoted 5 lines
field:int __syscall_nr; offset:12; size:4; signed:1; field:struct __kernel_timespec * rqtp; offset:16; size:8; signed:0; field:struct __kernel_timespec * rmtp; offset:24; size:8; signed:0;print fmt: "rqtp: 0x%08lx, rmtp: 0x%08lx", ((unsigned long)(REC->rqtp)), ((unsigned long)(REC->rmtp))
Lol.
Jiri even fixed the issue with this format in bpftrace 3 years ago:
https://github.com/iovisor/bpftrace/commit/a2e3d5dbc03ceb49b776cf5602d31896158844a7
Let's fix the kernel side too. Something like this should do it:
kernel/trace/trace_syscalls.c +0 -0
@@ -555,7 +555,7 @@ static int perf_call_bpf_enter(struct
trace_event_call *call, struct pt_regs *re
struct syscall_trace_enter *rec)
{
struct syscall_tp_t {
- unsigned long long regs;
+ struct trace_entry ent;
unsigned long syscall_nr;
unsigned long args[SYSCALL_DEFINE_MAXARGS];
} param;
@@ -657,7 +657,7 @@ static int perf_call_bpf_exit(struct
trace_event_call *call, struct pt_regs *reg
struct syscall_trace_exit *rec)
{
struct syscall_tp_t {- unsigned long long regs;
+ struct trace_entry ent;
pls add build_bug_on that sizeof(ent) >= sizeof(void*).
Hi, Alexei!
Quoted 47 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 45 lines · Yauheni Kaliuta
Quoted 22 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 13 lines · Yauheni Kaliuta
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Should perf_call_bpf_enter/exit (
kernel/trace/trace_syscalls.c) use struct trace_event_raw_sys_enter/exit instead of locally crafted structsyscall_tp_tnowadays?No. It needs
syscall_tp_t.test_progs's vmlinux test
Quoted 2 lines
expects it as the context.
Quoted 6 lines
Quoted 1 line
what do you mean? Pls share a code pointer?
https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/test_vmlinux.c#L19
SEC("tp/syscalls/sys_enter_nanosleep")
inthandle__tp(struct trace_event_raw_sys_enter *args)Quoted 8 lines
I see. That bit is correct and that's what bpftrace is doing when attaching to syscalls.
What do you see in your patched RT kernel when you do:
cat/sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format?
Depending on the answer we might need to fix
the kernel side that has to use structtrace_entry
insyscall_tp_tinstead of plain long long.# cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format name: sys_enter_nanosleep ID: 374 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:unsigned char common_preempt_lazy_count; offset:8; size:1; signed:0;field:int __syscall_nr; offset:12; size:4; signed:1; field:struct __kernel_timespec * rqtp; offset:16; size:8; signed:0; field:struct __kernel_timespec * rmtp; offset:24; size:8; signed:0;
Quoted 6 lines
Quoted 1 line
print fmt: "rqtp: 0x%08lx, rmtp: 0x%08lx", ((unsigned long)(REC->rqtp)), ((unsigned long)(REC->rmtp))
Lol.
Jiri even fixed the issue with this format in bpftrace 3 years ago:
https://github.com/iovisor/bpftrace/commit/a2e3d5dbc03ceb49b776cf5602d31896158844a7
Hehe :)
Quoted 25 lines
Let's fix the kernel side too. Something like this should do it:
kernel/trace/trace_syscalls.c +0
-0@@ -555,7 +555,7 @@ static int perf_call_bpf_enter(struct
trace_event_call*call, structpt_regs*re
structsyscall_trace_enter*rec){ struct syscall_tp_t {kernel/trace/trace_syscalls.c +1
-1-unsigned long long regs; +struct trace_entry ent;unsigned long syscall_nr;unsigned long args[SYSCALL_DEFINE_MAXARGS ]; } param;@@ -657,7 +657,7 @@ static int perf_call_bpf_exit(struct
trace_event_call*call, structpt_regs*reg
structsyscall_trace_exit*rec){ struct syscall_tp_t {kernel/trace/trace_syscalls.c +1
-1-unsigned long long regs; +struct trace_entry ent;
Quoted 1 line
pls add
build_bug_onthat sizeof(ent) >=sizeof(void*).
Ok. Should the line *(struct pt_regs **)¶m = regs; be commented somehow?
Signature · 2 lines
WBR, Yauheni Kaliuta
Quoted 84 lines · Yauheni Kaliuta
Hi, Alexei!
Quoted 47 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 45 lines · Yauheni Kaliuta
Quoted 22 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 13 lines · Yauheni Kaliuta
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Should perf_call_bpf_enter/exit (
kernel/trace/trace_syscalls.c) use struct trace_event_raw_sys_enter/exit instead of locally crafted structsyscall_tp_tnowadays?No. It needs
syscall_tp_t.test_progs's vmlinux test
Quoted 2 lines
expects it as the context.
Quoted 6 lines
Quoted 1 line
what do you mean? Pls share a code pointer?
https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/progs/test_vmlinux.c#L19
SEC("tp/syscalls/sys_enter_nanosleep")
inthandle__tp(struct trace_event_raw_sys_enter *args)Quoted 8 lines
I see. That bit is correct and that's what bpftrace is doing when attaching to syscalls.
What do you see in your patched RT kernel when you do:
cat/sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format?
Depending on the answer we might need to fix
the kernel side that has to use structtrace_entry
insyscall_tp_tinstead of plain long long.# cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/format name: sys_enter_nanosleep ID: 374 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:unsigned char common_preempt_lazy_count; offset:8; size:1; signed:0;field:int __syscall_nr; offset:12; size:4; signed:1; field:struct __kernel_timespec * rqtp; offset:16; size:8; signed:0; field:struct __kernel_timespec * rmtp; offset:24; size:8; signed:0;Quoted 6 lines
Quoted 1 line
print fmt: "rqtp: 0x%08lx, rmtp: 0x%08lx", ((unsigned long)(REC->rqtp)), ((unsigned long)(REC->rmtp))
Lol.
Jiri even fixed the issue with this format in bpftrace 3 years ago:
https://github.com/iovisor/bpftrace/commit/a2e3d5dbc03ceb49b776cf5602d31896158844a7Hehe :)
Quoted 23 lines
Let's fix the kernel side too. Something like this should do it:
kernel/trace/trace_syscalls.c +0
-0@@ -555,7 +555,7 @@ static int perf_call_bpf_enter(struct
trace_event_call*call, structpt_regs*re
structsyscall_trace_enter*rec){ struct syscall_tp_t {kernel/trace/trace_syscalls.c +1
-1-unsigned long long regs; +struct trace_entry ent;unsigned long syscall_nr;unsigned long args[SYSCALL_DEFINE_MAXARGS ]; } param;@@ -657,7 +657,7 @@ static int perf_call_bpf_exit(struct
trace_event_call*call, structpt_regs*reg
structsyscall_trace_exit*rec){ struct syscall_tp_t {kernel/trace/trace_syscalls.c +1
-1-unsigned long long regs; +struct trace_entry ent;
Quoted 3 lines
Quoted 1 line
pls add
build_bug_onthat sizeof(ent) >=sizeof(void*).Ok. Should the line *(struct
pt_regs**)¶m = regs; be commented somehow?
commented out? No. It's mandatory.
And the reason for build_bug_on existence... to make sure that there is enough space there.
Hi, Alexei!
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 5 lines · Yauheni Kaliuta
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 3 lines · Yauheni Kaliuta
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 1 line · Yauheni Kaliuta
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
[...]
Quoted 25 lines
Quoted 25 lines
Quoted 23 lines
Let's fix the kernel side too. Something like this should do it:
kernel/trace/trace_syscalls.c +0
-0@@ -555,7 +555,7 @@ static int perf_call_bpf_enter(struct
trace_event_call*call, structpt_regs*re
structsyscall_trace_enter*rec){ struct syscall_tp_t {kernel/trace/trace_syscalls.c +1
-1-unsigned long long regs; +struct trace_entry ent;unsigned long syscall_nr;unsigned long args[SYSCALL_DEFINE_MAXARGS ]; } param;@@ -657,7 +657,7 @@ static int perf_call_bpf_exit(struct
trace_event_call*call, structpt_regs*reg
structsyscall_trace_exit*rec){ struct syscall_tp_t {kernel/trace/trace_syscalls.c +1
-1-unsigned long long regs; +struct trace_entry ent;
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
pls add
build_bug_onthat sizeof(ent) >=sizeof(void*).Ok. Should the line *(struct
pt_regs**)¶m = regs; be commented somehow?commented out?
No, no :)
Quoted 3 lines
No. It's mandatory.
And the reason forbuild_bug_onexistence... to make sure that there is enough space there.
Yes, it's clear for sure.
It can be not obvious why basically 'ent' is inited with 'regs'. Before it was called 'regs' at least.
Signature · 2 lines
WBR, Yauheni Kaliuta
Quoted 46 lines · Yauheni Kaliuta
Hi, Alexei!
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 5 lines · Yauheni Kaliuta
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 3 lines · Yauheni Kaliuta
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
Quoted 1 line · Yauheni Kaliuta
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Alexei Starovoitov
[...]
Quoted 25 lines
Quoted 25 lines
Quoted 23 lines
Let's fix the kernel side too. Something like this should do it:
kernel/trace/trace_syscalls.c +0
-0@@ -555,7 +555,7 @@ static int perf_call_bpf_enter(struct
trace_event_call*call, structpt_regs*re
structsyscall_trace_enter*rec){ struct syscall_tp_t {kernel/trace/trace_syscalls.c +1
-1-unsigned long long regs; +struct trace_entry ent;unsigned long syscall_nr;unsigned long args[SYSCALL_DEFINE_MAXARGS ]; } param;@@ -657,7 +657,7 @@ static int perf_call_bpf_exit(struct
trace_event_call*call, structpt_regs*reg
structsyscall_trace_exit*rec){ struct syscall_tp_t {kernel/trace/trace_syscalls.c +1
-1-unsigned long long regs; +struct trace_entry ent;Quoted 5 lines
Quoted 3 lines
Quoted 1 line
pls add
build_bug_onthat sizeof(ent) >=sizeof(void*).Ok. Should the line *(struct
pt_regs**)¶m = regs; be commented somehow?commented out?
No, no :)
Quoted 8 lines
Quoted 3 lines
No. It's mandatory.
And the reason forbuild_bug_onexistence... to make sure that there is enough space there.Yes, it's clear for sure.
It can be not obvious why basically 'ent' is inited with 'regs'. Before it was called 'regs' at least.
Got it :) Yeah. A comment describing the intent would be nice.