Skip to content

Commit

Permalink
tetragon: Add TAIL_CALL_* enums for generic tail calls
Browse files Browse the repository at this point in the history
Adding TAIL_CALL_* enum values to identify tail calls for generic
probes and make it more human friendly.

Suggested-by: Djalal Harouni <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Nov 27, 2023
1 parent beaf407 commit 92e4c99
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
7 changes: 2 additions & 5 deletions bpf/process/bpf_generic_kprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ generic_kprobe_start_process_filter(void *ctx)
#endif

/* Tail call into filters. */
tail_call(ctx, &kprobe_calls, 2);
tail_call(ctx, &kprobe_calls, TAIL_CALL_FILTER);
return 0;
}

Expand Down Expand Up @@ -187,7 +187,7 @@ generic_kprobe_process_filter(void *ctx)
ret = generic_process_filter(&msg->sel, &msg->current, &msg->ns,
&msg->caps, &filter_map, msg->idx);
if (ret == PFILTER_CONTINUE)
tail_call(ctx, &kprobe_calls, 2);
tail_call(ctx, &kprobe_calls, TAIL_CALL_FILTER);
else if (ret == PFILTER_ACCEPT)
tail_call(ctx, &kprobe_calls, 0);
/* If filter does not accept drop it. Ideally we would
Expand All @@ -196,9 +196,6 @@ generic_kprobe_process_filter(void *ctx)
return PFILTER_REJECT;
}

// Filter tailcalls: kprobe/6...kprobe/10
// see also: MIN_FILTER_TAILCALL, MAX_FILTER_TAILCALL

__attribute__((section("kprobe/3"), used)) int
generic_kprobe_filter_arg(void *ctx)
{
Expand Down
9 changes: 3 additions & 6 deletions bpf/process/bpf_generic_tracepoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ generic_tracepoint_event(struct generic_tracepoint_event_arg *ctx)
#ifdef __CAP_CHANGES_FILTER
msg->sel.match_cap = 0;
#endif
tail_call(ctx, &tp_calls, 2);
tail_call(ctx, &tp_calls, TAIL_CALL_FILTER);
return 0;
}

Expand All @@ -221,18 +221,15 @@ generic_tracepoint_filter(void *ctx)
ret = generic_process_filter(&msg->sel, &msg->current, &msg->ns,
&msg->caps, &filter_map, msg->idx);
if (ret == PFILTER_CONTINUE)
tail_call(ctx, &tp_calls, 2);
tail_call(ctx, &tp_calls, TAIL_CALL_FILTER);
else if (ret == PFILTER_ACCEPT)
tail_call(ctx, &tp_calls, 1);
tail_call(ctx, &tp_calls, TAIL_CALL_PROCESS);
/* If filter does not accept drop it. Ideally we would
* log error codes for later review, TBD.
*/
return PFILTER_REJECT;
}

// Filter tailcalls: tracepoint/6...tracepoint/10
// see also: MIN_FILTER_TAILCALL, MAX_FILTER_TAILCALL

__attribute__((section("tracepoint/3"), used)) int
generic_tracepoint_arg(void *ctx)
{
Expand Down
4 changes: 2 additions & 2 deletions bpf/process/bpf_generic_uprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ generic_uprobe_start_process_filter(void *ctx)
if (!generic_process_filter_binary(config))
return 0;
/* Tail call into filters. */
tail_call(ctx, &uprobe_calls, 2);
tail_call(ctx, &uprobe_calls, TAIL_CALL_FILTER);
return 0;
}

Expand Down Expand Up @@ -130,7 +130,7 @@ generic_uprobe_process_filter(void *ctx)
ret = generic_process_filter(&msg->sel, &msg->current, &msg->ns,
&msg->caps, &filter_map, msg->idx);
if (ret == PFILTER_CONTINUE)
tail_call(ctx, &uprobe_calls, 2);
tail_call(ctx, &uprobe_calls, TAIL_CALL_FILTER);
else if (ret == PFILTER_ACCEPT)
tail_call(ctx, &uprobe_calls, 0);
/* If filter does not accept drop it. Ideally we would
Expand Down
4 changes: 2 additions & 2 deletions bpf/process/generic_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ generic_process_event(void *ctx, struct bpf_map_def *heap_map,
/* Continue to process other arguments. */
if (index < 4) {
e->filter_tailcall_index = index + 1;
tail_call(ctx, tailcals, 1);
tail_call(ctx, tailcals, TAIL_CALL_PROCESS);
}

/* Last argument, go send.. */
e->filter_tailcall_index = 0;
tail_call(ctx, tailcals, 3);
tail_call(ctx, tailcals, TAIL_CALL_ARGS);
return 0;
}

Expand Down
25 changes: 15 additions & 10 deletions bpf/process/types/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ enum {
FGS_SIGKILL = 9,
};

enum {
TAIL_CALL_PROCESS = 1,
TAIL_CALL_FILTER = 2,
TAIL_CALL_ARGS = 3,
TAIL_CALL_ACTIONS = 4,
TAIL_CALL_SEND = 5,
};

struct selector_action {
__u32 actionlen;
__u32 act[];
Expand Down Expand Up @@ -183,12 +191,9 @@ static inline __attribute__((always_inline)) __u32 get_index(void *ctx)
#define get_index(ctx) 0
#endif

// Filter tailcalls are {kprobe,tracepoint}/{6,7,8,9,10}
// We do one tail-call per selector, so we can have up to 5 selectors.
#define MIN_FILTER_TAILCALL 6
#define MAX_FILTER_TAILCALL 10
#define MAX_SELECTORS (MAX_FILTER_TAILCALL - MIN_FILTER_TAILCALL + 1)
#define MAX_SELECTORS_MASK 7
// We do one tail-call per selector, we can have up to 5 selectors.
#define MAX_SELECTORS 5
#define MAX_SELECTORS_MASK 7

static inline __attribute__((always_inline)) long
filter_32ty_map(struct selector_arg_filter *filter, char *args);
Expand Down Expand Up @@ -2182,7 +2187,7 @@ filter_read_arg(void *ctx, struct bpf_map_def *heap,
index++;
if (index <= MAX_SELECTORS && e->sel.active[index & MAX_SELECTORS_MASK]) {
e->filter_tailcall_index = index;
tail_call(ctx, tailcalls, 3);
tail_call(ctx, tailcalls, TAIL_CALL_ARGS);
}
// reject if we did not attempt to tailcall, or if tailcall failed.
return filter_args_reject(e->func_id);
Expand All @@ -2192,10 +2197,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, 4);
tail_call(ctx, tailcalls, TAIL_CALL_ACTIONS);
}

tail_call(ctx, tailcalls, 5);
tail_call(ctx, tailcalls, TAIL_CALL_SEND);
return 1;
}

Expand Down Expand Up @@ -2237,7 +2242,7 @@ generic_actions(void *ctx, struct bpf_map_def *heap,

postit = do_actions(ctx, e, actions, override_tasks);
if (postit)
tail_call(ctx, tailcalls, 5);
tail_call(ctx, tailcalls, TAIL_CALL_SEND);
return 1;
}

Expand Down

0 comments on commit 92e4c99

Please sign in to comment.