Skip to content

Commit 9fd82b6

Browse files
4astdavem330
authored andcommitted
bpf: register BPF_PROG_TYPE_TRACEPOINT program type
register tracepoint bpf program type and let it call the same set of helper functions as BPF_PROG_TYPE_KPROBE Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 98b5c2c commit 9fd82b6

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

kernel/trace/bpf_trace.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static const struct bpf_func_proto bpf_perf_event_output_proto = {
268268
.arg5_type = ARG_CONST_STACK_SIZE,
269269
};
270270

271-
static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func_id)
271+
static const struct bpf_func_proto *tracing_func_proto(enum bpf_func_id func_id)
272272
{
273273
switch (func_id) {
274274
case BPF_FUNC_map_lookup_elem:
@@ -295,12 +295,20 @@ static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func
295295
return &bpf_get_smp_processor_id_proto;
296296
case BPF_FUNC_perf_event_read:
297297
return &bpf_perf_event_read_proto;
298+
default:
299+
return NULL;
300+
}
301+
}
302+
303+
static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func_id)
304+
{
305+
switch (func_id) {
298306
case BPF_FUNC_perf_event_output:
299307
return &bpf_perf_event_output_proto;
300308
case BPF_FUNC_get_stackid:
301309
return &bpf_get_stackid_proto;
302310
default:
303-
return NULL;
311+
return tracing_func_proto(func_id);
304312
}
305313
}
306314

@@ -332,9 +340,42 @@ static struct bpf_prog_type_list kprobe_tl = {
332340
.type = BPF_PROG_TYPE_KPROBE,
333341
};
334342

343+
static const struct bpf_func_proto *tp_prog_func_proto(enum bpf_func_id func_id)
344+
{
345+
switch (func_id) {
346+
case BPF_FUNC_perf_event_output:
347+
case BPF_FUNC_get_stackid:
348+
return NULL;
349+
default:
350+
return tracing_func_proto(func_id);
351+
}
352+
}
353+
354+
static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type)
355+
{
356+
if (off < sizeof(void *) || off >= PERF_MAX_TRACE_SIZE)
357+
return false;
358+
if (type != BPF_READ)
359+
return false;
360+
if (off % size != 0)
361+
return false;
362+
return true;
363+
}
364+
365+
static const struct bpf_verifier_ops tracepoint_prog_ops = {
366+
.get_func_proto = tp_prog_func_proto,
367+
.is_valid_access = tp_prog_is_valid_access,
368+
};
369+
370+
static struct bpf_prog_type_list tracepoint_tl = {
371+
.ops = &tracepoint_prog_ops,
372+
.type = BPF_PROG_TYPE_TRACEPOINT,
373+
};
374+
335375
static int __init register_kprobe_prog_ops(void)
336376
{
337377
bpf_register_prog_type(&kprobe_tl);
378+
bpf_register_prog_type(&tracepoint_tl);
338379
return 0;
339380
}
340381
late_initcall(register_kprobe_prog_ops);

0 commit comments

Comments
 (0)