Skip to content

Commit

Permalink
cleanup: remove ctx
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 authored and poiana committed Nov 8, 2024
1 parent df962ed commit 1c4ee0e
Show file tree
Hide file tree
Showing 168 changed files with 321 additions and 352 deletions.
4 changes: 1 addition & 3 deletions driver/modern_bpf/helpers/store/auxmap_store_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ static __always_inline void auxmap__finalize_event_header(struct auxiliary_map *
* of events sent to userspace, otherwise we increment the dropped events.
*
* @param auxmap pointer to the auxmap in which we have already written the entire event.
* @param ctx BPF prog context
*/
// todo!: we need to remove the context because we don't perform any tail call
static __always_inline void auxmap__submit_event(struct auxiliary_map *auxmap, void *ctx) {
static __always_inline void auxmap__submit_event(struct auxiliary_map *auxmap) {
struct ringbuf_map *rb = maps__get_ringbuf_map();
if(!rb) {
// this should never happen because we check it in sys_enter/sys_exit
Expand Down
3 changes: 0 additions & 3 deletions driver/modern_bpf/helpers/store/ringbuf_store_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,10 @@ struct ringbuf_struct {
* to know the event dimension at compile time.
*
* @param ringbuf pointer to the `ringbuf_struct`
* @param ctx BPF prog context
* @param event_size exact size of the fixed-size event
* @return `1` in case of success, `0` in case of failure.
*/
// todo!: we need to remove the context because we don't perform any tail call
static __always_inline uint32_t ringbuf__reserve_space(struct ringbuf_struct *ringbuf,
void *ctx,
uint32_t event_size,
uint16_t event_type) {
struct ringbuf_map *rb = maps__get_ringbuf_map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int BPF_PROG(pf_kernel, unsigned long address, struct pt_regs *regs, unsigned lo
}

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, PAGE_FAULT_SIZE, PPME_PAGE_FAULT_E)) {
if(!ringbuf__reserve_space(&ringbuf, PAGE_FAULT_SIZE, PPME_PAGE_FAULT_E)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int BPF_PROG(pf_user, unsigned long address, struct pt_regs *regs, unsigned long
}

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, PAGE_FAULT_SIZE, PPME_PAGE_FAULT_E)) {
if(!ringbuf__reserve_space(&ringbuf, PAGE_FAULT_SIZE, PPME_PAGE_FAULT_E)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ int BPF_PROG(t2_sched_p_exec, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int BPF_PROG(sched_proc_exit, struct task_struct *task) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ int BPF_PROG(t2_sched_p_fork, struct task_struct *parent, struct task_struct *ch

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);
return 0;
}
#endif /* CAPTURE_SCHED_PROC_EXEC */
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int BPF_PROG(sched_switch, bool preempt, struct task_struct *prev, struct task_s
/// TODO: we could avoid switches from kernel threads to kernel threads (?).

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, SCHED_SWITCH_SIZE, PPME_SCHEDSWITCH_6_E)) {
if(!ringbuf__reserve_space(&ringbuf, SCHED_SWITCH_SIZE, PPME_SCHEDSWITCH_6_E)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int BPF_PROG(signal_deliver, int sig, struct kernel_siginfo *info, struct k_siga
}

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, SIGNAL_DELIVER_SIZE, PPME_SIGNALDELIVER_E)) {
if(!ringbuf__reserve_space(&ringbuf, SIGNAL_DELIVER_SIZE, PPME_SIGNALDELIVER_E)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(t1_drop_e) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, DROP_E_SIZE, PPME_DROP_E)) {
if(!ringbuf__reserve_space(&ringbuf, DROP_E_SIZE, PPME_DROP_E)) {
return 0;
}

Expand All @@ -36,7 +36,7 @@ int BPF_PROG(t1_drop_e) {
SEC("tp_btf/sys_exit")
int BPF_PROG(t1_drop_x) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, DROP_X_SIZE, PPME_DROP_X)) {
if(!ringbuf__reserve_space(&ringbuf, DROP_X_SIZE, PPME_DROP_X)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(accept_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, ACCEPT_E_SIZE, PPME_SOCKET_ACCEPT_5_E)) {
if(!ringbuf__reserve_space(&ringbuf, ACCEPT_E_SIZE, PPME_SOCKET_ACCEPT_5_E)) {
return 0;
}

Expand Down Expand Up @@ -105,7 +105,7 @@ int BPF_PROG(accept_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(accept4_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, ACCEPT4_E_SIZE, PPME_SOCKET_ACCEPT4_6_E)) {
if(!ringbuf__reserve_space(&ringbuf, ACCEPT4_E_SIZE, PPME_SOCKET_ACCEPT4_6_E)) {
return 0;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ int BPF_PROG(accept4_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(access_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, ACCESS_E_SIZE, PPME_SYSCALL_ACCESS_E)) {
if(!ringbuf__reserve_space(&ringbuf, ACCESS_E_SIZE, PPME_SYSCALL_ACCESS_E)) {
return 0;
}

Expand Down Expand Up @@ -59,7 +59,7 @@ int BPF_PROG(access_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int BPF_PROG(bind_e, struct pt_regs *regs, long id) {
extract__network_args(&socket_fd, 1, regs);

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, BIND_E_SIZE, PPME_SOCKET_BIND_E)) {
if(!ringbuf__reserve_space(&ringbuf, BIND_E_SIZE, PPME_SOCKET_BIND_E)) {
return 0;
}

Expand Down Expand Up @@ -70,7 +70,7 @@ int BPF_PROG(bind_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(bpf_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, BPF_E_SIZE, PPME_SYSCALL_BPF_2_E)) {
if(!ringbuf__reserve_space(&ringbuf, BPF_E_SIZE, PPME_SYSCALL_BPF_2_E)) {
return 0;
}

Expand All @@ -39,7 +39,7 @@ int BPF_PROG(bpf_e, struct pt_regs *regs, long id) {
SEC("tp_btf/sys_exit")
int BPF_PROG(bpf_x, struct pt_regs *regs, long ret) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, BPF_X_SIZE, PPME_SYSCALL_BPF_2_X)) {
if(!ringbuf__reserve_space(&ringbuf, BPF_X_SIZE, PPME_SYSCALL_BPF_2_X)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(brk_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, BRK_E_SIZE, PPME_SYSCALL_BRK_4_E)) {
if(!ringbuf__reserve_space(&ringbuf, BRK_E_SIZE, PPME_SYSCALL_BRK_4_E)) {
return 0;
}

Expand All @@ -39,7 +39,7 @@ int BPF_PROG(brk_e, struct pt_regs *regs, long id) {
SEC("tp_btf/sys_exit")
int BPF_PROG(brk_x, struct pt_regs *regs, long ret) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, BRK_X_SIZE, PPME_SYSCALL_BRK_4_X)) {
if(!ringbuf__reserve_space(&ringbuf, BRK_X_SIZE, PPME_SYSCALL_BRK_4_X)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(capset_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CAPSET_E_SIZE, PPME_SYSCALL_CAPSET_E)) {
if(!ringbuf__reserve_space(&ringbuf, CAPSET_E_SIZE, PPME_SYSCALL_CAPSET_E)) {
return 0;
}

Expand All @@ -37,7 +37,7 @@ int BPF_PROG(capset_e, struct pt_regs *regs, long id) {
SEC("tp_btf/sys_exit")
int BPF_PROG(capset_x, struct pt_regs *regs, long ret) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CAPSET_X_SIZE, PPME_SYSCALL_CAPSET_X)) {
if(!ringbuf__reserve_space(&ringbuf, CAPSET_X_SIZE, PPME_SYSCALL_CAPSET_X)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(chdir_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CHDIR_E_SIZE, PPME_SYSCALL_CHDIR_E)) {
if(!ringbuf__reserve_space(&ringbuf, CHDIR_E_SIZE, PPME_SYSCALL_CHDIR_E)) {
return 0;
}

Expand Down Expand Up @@ -57,7 +57,7 @@ int BPF_PROG(chdir_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(chmod_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CHMOD_E_SIZE, PPME_SYSCALL_CHMOD_E)) {
if(!ringbuf__reserve_space(&ringbuf, CHMOD_E_SIZE, PPME_SYSCALL_CHMOD_E)) {
return 0;
}

Expand Down Expand Up @@ -61,7 +61,7 @@ int BPF_PROG(chmod_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(chown_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CHOWN_E_SIZE, PPME_SYSCALL_CHOWN_E)) {
if(!ringbuf__reserve_space(&ringbuf, CHOWN_E_SIZE, PPME_SYSCALL_CHOWN_E)) {
return 0;
}

Expand Down Expand Up @@ -65,7 +65,7 @@ int BPF_PROG(chown_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(chroot_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CHROOT_E_SIZE, PPME_SYSCALL_CHROOT_E)) {
if(!ringbuf__reserve_space(&ringbuf, CHROOT_E_SIZE, PPME_SYSCALL_CHROOT_E)) {
return 0;
}

Expand Down Expand Up @@ -57,7 +57,7 @@ int BPF_PROG(chroot_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(clone_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CLONE_E_SIZE, PPME_SYSCALL_CLONE_20_E)) {
if(!ringbuf__reserve_space(&ringbuf, CLONE_E_SIZE, PPME_SYSCALL_CLONE_20_E)) {
return 0;
}

Expand Down Expand Up @@ -228,7 +228,7 @@ int BPF_PROG(t2_clone_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SEC("tp_btf/sys_enter")
int BPF_PROG(clone3_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CLONE3_E_SIZE, PPME_SYSCALL_CLONE3_E)) {
if(!ringbuf__reserve_space(&ringbuf, CLONE3_E_SIZE, PPME_SYSCALL_CLONE3_E)) {
return 0;
}

Expand Down Expand Up @@ -226,7 +226,7 @@ int BPF_PROG(t2_clone3_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int BPF_PROG(close_e, struct pt_regs *regs, long id) {
}

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CLOSE_E_SIZE, PPME_SYSCALL_CLOSE_E)) {
if(!ringbuf__reserve_space(&ringbuf, CLOSE_E_SIZE, PPME_SYSCALL_CLOSE_E)) {
return 0;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ int BPF_PROG(close_x, struct pt_regs *regs, long ret) {
}

struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf, ctx, CLOSE_X_SIZE, PPME_SYSCALL_CLOSE_X)) {
if(!ringbuf__reserve_space(&ringbuf, CLOSE_X_SIZE, PPME_SYSCALL_CLOSE_X)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int BPF_PROG(connect_e, struct pt_regs *regs, long id) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ int BPF_PROG(connect_x, struct pt_regs *regs, long ret) {

auxmap__finalize_event_header(auxmap);

auxmap__submit_event(auxmap, ctx);
auxmap__submit_event(auxmap);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SEC("tp_btf/sys_enter")
int BPF_PROG(copy_file_range_e, struct pt_regs *regs, long id) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf,
ctx,

COPY_FILE_RANGE_E_SIZE,
PPME_SYSCALL_COPY_FILE_RANGE_E)) {
return 0;
Expand Down Expand Up @@ -50,10 +50,7 @@ int BPF_PROG(copy_file_range_e, struct pt_regs *regs, long id) {
SEC("tp_btf/sys_exit")
int BPF_PROG(copy_file_range_x, struct pt_regs *regs, long ret) {
struct ringbuf_struct ringbuf;
if(!ringbuf__reserve_space(&ringbuf,
ctx,
COPY_FILE_RANGE_X_SIZE,
PPME_SYSCALL_COPY_FILE_RANGE_X)) {
if(!ringbuf__reserve_space(&ringbuf, COPY_FILE_RANGE_X_SIZE, PPME_SYSCALL_COPY_FILE_RANGE_X)) {
return 0;
}

Expand Down
Loading

0 comments on commit 1c4ee0e

Please sign in to comment.