From 7685a7fa81a26ee4d35b31ef376ab5cd5c83c7e0 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Tue, 10 Dec 2024 23:08:07 +0000 Subject: [PATCH] tetragon: Use struct generic_maps in filter_read_arg Signed-off-by: Jiri Olsa --- bpf/process/bpf_generic_kprobe.c | 6 +----- bpf/process/bpf_generic_lsm_core.c | 6 +----- bpf/process/bpf_generic_retkprobe.c | 6 +----- bpf/process/bpf_generic_tracepoint.c | 6 +----- bpf/process/bpf_generic_uprobe.c | 6 +----- bpf/process/types/basic.h | 14 ++++++-------- 6 files changed, 11 insertions(+), 33 deletions(-) diff --git a/bpf/process/bpf_generic_kprobe.c b/bpf/process/bpf_generic_kprobe.c index a545724d09f..471a35f782e 100644 --- a/bpf/process/bpf_generic_kprobe.c +++ b/bpf/process/bpf_generic_kprobe.c @@ -164,11 +164,7 @@ generic_kprobe_process_filter(void *ctx) __attribute__((section("kprobe"), used)) int generic_kprobe_filter_arg(void *ctx) { - return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap, - (struct bpf_map_def *)&filter_map, - (struct bpf_map_def *)&kprobe_calls, - (struct bpf_map_def *)&config_map, - true); + return filter_read_arg(ctx, &maps, true); } __attribute__((section("kprobe"), used)) int diff --git a/bpf/process/bpf_generic_lsm_core.c b/bpf/process/bpf_generic_lsm_core.c index 48bd373f024..db402aeaa44 100644 --- a/bpf/process/bpf_generic_lsm_core.c +++ b/bpf/process/bpf_generic_lsm_core.c @@ -130,11 +130,7 @@ generic_lsm_process_filter(void *ctx) __attribute__((section("lsm"), used)) int generic_lsm_filter_arg(void *ctx) { - return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap, - (struct bpf_map_def *)&filter_map, - (struct bpf_map_def *)&lsm_calls, - (struct bpf_map_def *)&config_map, - true); + return filter_read_arg(ctx, &maps, true); } __attribute__((section("lsm"), used)) int diff --git a/bpf/process/bpf_generic_retkprobe.c b/bpf/process/bpf_generic_retkprobe.c index 82780605d33..db3321f361a 100644 --- a/bpf/process/bpf_generic_retkprobe.c +++ b/bpf/process/bpf_generic_retkprobe.c @@ -97,11 +97,7 @@ BPF_KRETPROBE(generic_retkprobe_event, unsigned long ret) __attribute__((section("kprobe"), used)) int BPF_KRETPROBE(generic_retkprobe_filter_arg) { - return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap, - (struct bpf_map_def *)&filter_map, - (struct bpf_map_def *)&retkprobe_calls, - (struct bpf_map_def *)&config_map, - false); + return filter_read_arg(ctx, &maps, false); } __attribute__((section("kprobe"), used)) int diff --git a/bpf/process/bpf_generic_tracepoint.c b/bpf/process/bpf_generic_tracepoint.c index 02f95f8e630..21165c51930 100644 --- a/bpf/process/bpf_generic_tracepoint.c +++ b/bpf/process/bpf_generic_tracepoint.c @@ -274,11 +274,7 @@ generic_tracepoint_filter(void *ctx) __attribute__((section("tracepoint"), used)) int generic_tracepoint_arg(void *ctx) { - return filter_read_arg(ctx, (struct bpf_map_def *)&tp_heap, - (struct bpf_map_def *)&filter_map, - (struct bpf_map_def *)&tp_calls, - (struct bpf_map_def *)&config_map, - true); + return filter_read_arg(ctx, &maps, true); } __attribute__((section("tracepoint"), used)) int diff --git a/bpf/process/bpf_generic_uprobe.c b/bpf/process/bpf_generic_uprobe.c index 6442d5c5420..ca7ba42494b 100644 --- a/bpf/process/bpf_generic_uprobe.c +++ b/bpf/process/bpf_generic_uprobe.c @@ -117,11 +117,7 @@ generic_uprobe_process_filter(void *ctx) __attribute__((section("uprobe"), used)) int generic_uprobe_filter_arg(void *ctx) { - return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap, - (struct bpf_map_def *)&filter_map, - (struct bpf_map_def *)&uprobe_calls, - (struct bpf_map_def *)&config_map, - true); + return filter_read_arg(ctx, &maps, true); } __attribute__((section("uprobe"), used)) int diff --git a/bpf/process/types/basic.h b/bpf/process/types/basic.h index 41ebf56e573..640ef82968e 100644 --- a/bpf/process/types/basic.h +++ b/bpf/process/types/basic.h @@ -2323,23 +2323,21 @@ do_actions(void *ctx, struct selector_action *actions, struct generic_maps *maps } FUNC_INLINE long -filter_read_arg(void *ctx, struct bpf_map_def *heap, - struct bpf_map_def *filter, struct bpf_map_def *tailcalls, - struct bpf_map_def *config_map, bool is_entry) +filter_read_arg(void *ctx, struct generic_maps *maps, bool is_entry) { struct msg_generic_kprobe *e; int selidx, pass, zero = 0; - e = map_lookup_elem(heap, &zero); + e = map_lookup_elem(maps->heap, &zero); if (!e) return 0; selidx = e->tailcall_index_selector; - pass = filter_args(e, selidx & MAX_SELECTORS_MASK, filter, is_entry); + pass = filter_args(e, selidx & MAX_SELECTORS_MASK, maps->filter, is_entry); if (!pass) { selidx++; if (selidx <= MAX_SELECTORS && e->sel.active[selidx & MAX_SELECTORS_MASK]) { e->tailcall_index_selector = selidx; - tail_call(ctx, tailcalls, TAIL_CALL_ARGS); + tail_call(ctx, maps->calls, TAIL_CALL_ARGS); } // reject if we did not attempt to tailcall, or if tailcall failed. return filter_args_reject(e->func_id); @@ -2349,10 +2347,10 @@ filter_read_arg(void *ctx, struct bpf_map_def *heap, // otherwise pass==1 indicates using default action. if (pass > 1) { e->pass = pass; - tail_call(ctx, tailcalls, TAIL_CALL_ACTIONS); + tail_call(ctx, maps->calls, TAIL_CALL_ACTIONS); } - tail_call(ctx, tailcalls, TAIL_CALL_SEND); + tail_call(ctx, maps->calls, TAIL_CALL_SEND); return 0; }