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 <[email protected]>
  • Loading branch information
olsajiri committed Aug 19, 2024
1 parent 2537c68 commit b8f9d69
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 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
7 changes: 2 additions & 5 deletions pkg/sensors/tracing/genericuprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,8 @@ func createMultiUprobeSensor(sensorPath string, multiIDs []idtable.EntryID) ([]*
progs = append(progs, load)

configMap := program.MapBuilderPin("config_map", sensors.PathJoin(pinPath, "config_map"), load)
tailCalls := program.MapBuilderPin("uprobe_calls", sensors.PathJoin(pinPath, "up_calls"), load)
filterMap := program.MapBuilderPin("filter_map", sensors.PathJoin(pinPath, "filter_map"), load)

load.SetTailCall("uprobe", tailCalls)
program.MapBuilderPin("uprobe_calls", sensors.PathJoin(pinPath, "up_calls"), load)

filterMap.SetMaxEntries(len(multiIDs))
configMap.SetMaxEntries(len(multiIDs))
Expand Down Expand Up @@ -470,8 +468,7 @@ func createUprobeSensorFromEntry(uprobeEntry *genericUprobe,
_ = program.MapBuilderPin("filter_map", sensors.PathJoin(pinPath, "filter_map"), load)
_ = program.MapBuilderPin("tg_mb_sel_opts", sensors.PathJoin(pinPath, "tg_mb_sel_opts"), load)

tailCalls := program.MapBuilderPin("uprobe_calls", sensors.PathJoin(pinPath, "up_calls"), load)
load.SetTailCall("uprobe", tailCalls)
program.MapBuilderPin("uprobe_calls", sensors.PathJoin(pinPath, "up_calls"), load)
return progs
}

Expand Down

0 comments on commit b8f9d69

Please sign in to comment.