Skip to content

Commit

Permalink
tetragon: Load tail calls directly in genericuprobe program
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Aug 30, 2024
1 parent 3e72eed commit 4da5bc4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
32 changes: 24 additions & 8 deletions bpf/process/bpf_generic_uprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,28 @@ struct {
__type(value, struct msg_generic_kprobe);
} process_call_heap SEC(".maps");

int generic_uprobe_setup_event(void *ctx);
int generic_uprobe_process_event(void *ctx);
int generic_uprobe_process_filter(void *ctx);
int generic_uprobe_filter_arg(void *ctx);
int generic_uprobe_actions(void *ctx);
int generic_uprobe_output(void *ctx);

struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__uint(max_entries, 13);
__uint(key_size, sizeof(__u32));
__uint(value_size, sizeof(__u32));
} uprobe_calls SEC(".maps");
__array(values, int(void *));
} uprobe_calls SEC(".maps") = {
.values = {
[0] = (void *)&generic_uprobe_setup_event,
[1] = (void *)&generic_uprobe_process_event,
[2] = (void *)&generic_uprobe_process_filter,
[3] = (void *)&generic_uprobe_filter_arg,
[4] = (void *)&generic_uprobe_actions,
[5] = (void *)&generic_uprobe_output,
},
};

struct filter_map_value {
unsigned char buf[FILTER_SIZE];
Expand Down Expand Up @@ -69,7 +85,7 @@ generic_uprobe_event(struct pt_regs *ctx)
return generic_start_process_filter(ctx, &maps);
}

__attribute__((section("uprobe/0"), used)) int
__attribute__((section("uprobe"), used)) int
generic_uprobe_setup_event(void *ctx)
{
return generic_process_event_and_setup(
Expand All @@ -78,7 +94,7 @@ generic_uprobe_setup_event(void *ctx)
(struct bpf_map_def *)&config_map, 0);
}

__attribute__((section("uprobe/1"), used)) int
__attribute__((section("uprobe"), used)) int
generic_uprobe_process_event(void *ctx)
{
return generic_process_event(ctx,
Expand All @@ -87,7 +103,7 @@ generic_uprobe_process_event(void *ctx)
(struct bpf_map_def *)&config_map, 0);
}

__attribute__((section("uprobe/2"), used)) int
__attribute__((section("uprobe"), used)) int
generic_uprobe_process_filter(void *ctx)
{
int ret;
Expand All @@ -104,7 +120,7 @@ generic_uprobe_process_filter(void *ctx)
return PFILTER_REJECT;
}

__attribute__((section("uprobe/3"), used)) int
__attribute__((section("uprobe"), used)) int
generic_uprobe_filter_arg(void *ctx)
{
return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap,
Expand All @@ -114,13 +130,13 @@ generic_uprobe_filter_arg(void *ctx)
true);
}

__attribute__((section("uprobe/4"), used)) int
__attribute__((section("uprobe"), used)) int
generic_uprobe_actions(void *ctx)
{
return generic_actions(ctx, &maps);
}

__attribute__((section("uprobe/5"), used)) int
__attribute__((section("uprobe"), used)) int
generic_uprobe_output(void *ctx)
{
return generic_output(ctx, (struct bpf_map_def *)&process_call_heap, MSG_OP_GENERIC_UPROBE);
Expand Down
3 changes: 0 additions & 3 deletions pkg/sensors/tracing/genericuprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ func createMultiUprobeSensor(sensorPath string, multiIDs []idtable.EntryID) ([]*

maps = append(maps, configMap, tailCalls, filterMap)

load.SetTailCall("uprobe", tailCalls)

filterMap.SetMaxEntries(len(multiIDs))
configMap.SetMaxEntries(len(multiIDs))
return progs, maps, nil
Expand Down Expand Up @@ -475,7 +473,6 @@ func createUprobeSensorFromEntry(uprobeEntry *genericUprobe,
filterMap := program.MapBuilderProgram("filter_map", load)
selMatchBinariesMap := program.MapBuilderProgram("tg_mb_sel_opts", load)
maps = append(maps, configMap, tailCalls, filterMap, selMatchBinariesMap)
load.SetTailCall("uprobe", tailCalls)
return progs, maps
}

Expand Down

0 comments on commit 4da5bc4

Please sign in to comment.