Merge branch 'allow-kfuncs-in-tracepoint-and-perf-event'

JP Kobryn says:

====================
allow kfuncs in tracepoint and perf event

It is possible to call a cpumask kfunc within a raw tp_btf program but not
possible within tracepoint or perf event programs. Currently, the verifier
receives -EACCESS from fetch_kfunc_meta() as a result of not finding any
kfunc hook associated with these program types.

This patch series associates tracepoint and perf event program types with
the tracing hook and includes test coverage.

Pre-submission CI run: https://github.com/kernel-patches/bpf/pull/7674

v3:
	- map tracepoint and perf event progs to tracing kfunc hook
	- expand existing verifier tests for kfuncs
	- remove explicit registrations from v2
	- no longer including kprobes
v2:
	- create new kfunc hooks for tracepoint and perf event
	- map tracepoint, and perf event prog types to kfunc hooks
	- register cpumask kfuncs with prog types in focus
	- expand existing verifier tests for cpumask kfuncs
v1:
	- map tracepoint type progs to tracing kfunc hook
	- new selftests for calling cpumask kfuncs in tracepoint prog
---
====================

Link: https://lore.kernel.org/r/20240905223812.141857-1-inwardvessel@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Alexei Starovoitov
2024-09-05 17:02:03 -07:00
2 changed files with 50 additions and 0 deletions

View File

@@ -8357,6 +8357,8 @@ static int bpf_prog_type_to_kfunc_hook(enum bpf_prog_type prog_type)
case BPF_PROG_TYPE_STRUCT_OPS:
return BTF_KFUNC_HOOK_STRUCT_OPS;
case BPF_PROG_TYPE_TRACING:
case BPF_PROG_TYPE_TRACEPOINT:
case BPF_PROG_TYPE_PERF_EVENT:
case BPF_PROG_TYPE_LSM:
return BTF_KFUNC_HOOK_TRACING;
case BPF_PROG_TYPE_SYSCALL:

View File

@@ -47,6 +47,22 @@ int BPF_PROG(task_kfunc_syscall)
return 0;
}
SEC("tracepoint")
__success
int BPF_PROG(task_kfunc_tracepoint)
{
task_kfunc_load_test();
return 0;
}
SEC("perf_event")
__success
int BPF_PROG(task_kfunc_perf_event)
{
task_kfunc_load_test();
return 0;
}
/*****************
* cgroup kfuncs *
*****************/
@@ -85,6 +101,22 @@ int BPF_PROG(cgrp_kfunc_syscall)
return 0;
}
SEC("tracepoint")
__success
int BPF_PROG(cgrp_kfunc_tracepoint)
{
cgrp_kfunc_load_test();
return 0;
}
SEC("perf_event")
__success
int BPF_PROG(cgrp_kfunc_perf_event)
{
cgrp_kfunc_load_test();
return 0;
}
/******************
* cpumask kfuncs *
******************/
@@ -120,3 +152,19 @@ int BPF_PROG(cpumask_kfunc_syscall)
cpumask_kfunc_load_test();
return 0;
}
SEC("tracepoint")
__success
int BPF_PROG(cpumask_kfunc_tracepoint)
{
cpumask_kfunc_load_test();
return 0;
}
SEC("perf_event")
__success
int BPF_PROG(cpumask_kfunc_perf_event)
{
cpumask_kfunc_load_test();
return 0;
}