Skip to content

Commit

Permalink
tetragon: Use data_heap in generic functions
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Dec 19, 2024
1 parent 4635028 commit 1b24022
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
9 changes: 2 additions & 7 deletions bpf/process/bpf_generic_kprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,13 @@ generic_kprobe_event(struct pt_regs *ctx)
__attribute__((section("kprobe"), used)) int
generic_kprobe_setup_event(void *ctx)
{
return generic_process_event_and_setup(
ctx,
(struct bpf_map_def *)&kprobe_calls,
(struct bpf_map_def *)data_heap_ptr);
return generic_process_event_and_setup(ctx, (struct bpf_map_def *)&kprobe_calls);
}

__attribute__((section("kprobe"), used)) int
generic_kprobe_process_event(void *ctx)
{
return generic_process_event(ctx,
(struct bpf_map_def *)&kprobe_calls,
(struct bpf_map_def *)data_heap_ptr);
return generic_process_event(ctx, (struct bpf_map_def *)&kprobe_calls);
}

__attribute__((section("kprobe"), used)) int
Expand Down
9 changes: 2 additions & 7 deletions bpf/process/bpf_generic_lsm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,13 @@ generic_lsm_event(struct pt_regs *ctx)
__attribute__((section("lsm"), used)) int
generic_lsm_setup_event(void *ctx)
{
return generic_process_event_and_setup(
ctx,
(struct bpf_map_def *)&lsm_calls,
(struct bpf_map_def *)data_heap_ptr);
return generic_process_event_and_setup(ctx, (struct bpf_map_def *)&lsm_calls);
}

__attribute__((section("lsm"), used)) int
generic_lsm_process_event(void *ctx)
{
return generic_process_event(ctx,
(struct bpf_map_def *)&lsm_calls,
(struct bpf_map_def *)data_heap_ptr);
return generic_process_event(ctx, (struct bpf_map_def *)&lsm_calls);
}

__attribute__((section("lsm"), used)) int
Expand Down
3 changes: 1 addition & 2 deletions bpf/process/bpf_generic_tracepoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ generic_tracepoint_event(struct generic_tracepoint_event_arg *ctx)
__attribute__((section("tracepoint"), used)) int
generic_tracepoint_process_event(void *ctx)
{
return generic_process_event(ctx,
(struct bpf_map_def *)&tp_calls, 0);
return generic_process_event(ctx, (struct bpf_map_def *)&tp_calls);
}

__attribute__((section("tracepoint"), used)) int
Expand Down
7 changes: 2 additions & 5 deletions bpf/process/bpf_generic_uprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,13 @@ generic_uprobe_event(struct pt_regs *ctx)
__attribute__((section("uprobe"), used)) int
generic_uprobe_setup_event(void *ctx)
{
return generic_process_event_and_setup(
ctx,
(struct bpf_map_def *)&uprobe_calls, 0);
return generic_process_event_and_setup(ctx, (struct bpf_map_def *)&uprobe_calls);
}

__attribute__((section("uprobe"), used)) int
generic_uprobe_process_event(void *ctx)
{
return generic_process_event(ctx,
(struct bpf_map_def *)&uprobe_calls, 0);
return generic_process_event(ctx, (struct bpf_map_def *)&uprobe_calls);
}

__attribute__((section("uprobe"), used)) int
Expand Down
11 changes: 4 additions & 7 deletions bpf/process/generic_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ generic_start_process_filter(void *ctx, struct generic_maps *maps)
}

FUNC_INLINE int
generic_process_event(void *ctx, struct bpf_map_def *tailcals,
struct bpf_map_def *data_heap)
generic_process_event(void *ctx, struct bpf_map_def *tailcals)
{
struct msg_generic_kprobe *e;
struct event_config *config;
Expand Down Expand Up @@ -98,7 +97,7 @@ generic_process_event(void *ctx, struct bpf_map_def *tailcals,
asm volatile("%[am] &= 0xffff;\n"
: [am] "+r"(am));

errv = read_call_arg(ctx, e, index, ty, total, a, am, data_heap);
errv = read_call_arg(ctx, e, index, ty, total, a, am, data_heap_ptr);
if (errv > 0)
total += errv;
/* Follow filter lookup failed so lets abort the event.
Expand Down Expand Up @@ -148,9 +147,7 @@ generic_process_init(struct msg_generic_kprobe *e, u8 op, struct event_config *c
}

FUNC_INLINE int
generic_process_event_and_setup(struct pt_regs *ctx,
struct bpf_map_def *tailcals,
struct bpf_map_def *data_heap)
generic_process_event_and_setup(struct pt_regs *ctx, struct bpf_map_def *tailcals)
{
struct msg_generic_kprobe *e;
struct event_config *config;
Expand Down Expand Up @@ -216,7 +213,7 @@ generic_process_event_and_setup(struct pt_regs *ctx,
generic_process_init(e, MSG_OP_GENERIC_UPROBE, config);
#endif

return generic_process_event(ctx, tailcals, data_heap);
return generic_process_event(ctx, tailcals);
}

#endif /* __GENERIC_CALLS_H__ */
6 changes: 5 additions & 1 deletion bpf/process/generic_maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ struct {
} override_tasks SEC(".maps");

#ifdef __LARGE_BPF_PROG
#if defined(GENERIC_TRACEPOINT) || defined(GENERIC_UPROBE)
#define data_heap_ptr 0
#else
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, 1);
__type(key, __u32);
__type(value, struct msg_data);
} data_heap SEC(".maps");
#define data_heap_ptr &data_heap
#define data_heap_ptr (struct bpf_map_def *)&data_heap
#endif
#else
#define data_heap_ptr 0
#endif
Expand Down

0 comments on commit 1b24022

Please sign in to comment.