Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: add bpf_modify_return_test_tp() kfunc triggering tracepoint

Add a simple bpf_modify_return_test_tp() kfunc, available to all program
types, that is useful for various testing and benchmarking scenarios, as
it allows to trigger most tracing BPF program types from BPF side,
allowing to do complex testing and benchmarking scenarios.

It is also attachable to for fmod_ret programs, making it a good and
simple way to trigger fmod_ret program under test/benchmark.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240326162151.3981687-6-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
3124591f b4ccf915

+26
+17
include/trace/events/bpf_test_run.h
··· 7 7 8 8 #include <linux/tracepoint.h> 9 9 10 + TRACE_EVENT(bpf_trigger_tp, 11 + 12 + TP_PROTO(int nonce), 13 + 14 + TP_ARGS(nonce), 15 + 16 + TP_STRUCT__entry( 17 + __field(int, nonce) 18 + ), 19 + 20 + TP_fast_assign( 21 + __entry->nonce = nonce; 22 + ), 23 + 24 + TP_printk("nonce %d", __entry->nonce) 25 + ); 26 + 10 27 DECLARE_EVENT_CLASS(bpf_test_finish, 11 28 12 29 TP_PROTO(int *err),
+1
kernel/bpf/helpers.c
··· 2625 2625 BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly) 2626 2626 BTF_ID_FLAGS(func, bpf_dynptr_size) 2627 2627 BTF_ID_FLAGS(func, bpf_dynptr_clone) 2628 + BTF_ID_FLAGS(func, bpf_modify_return_test_tp) 2628 2629 BTF_KFUNCS_END(common_btf_ids) 2629 2630 2630 2631 static const struct btf_kfunc_id_set common_kfunc_set = {
+8
net/bpf/test_run.c
··· 575 575 return a + *b + c + d + (long)e + f + g; 576 576 } 577 577 578 + __bpf_kfunc int bpf_modify_return_test_tp(int nonce) 579 + { 580 + trace_bpf_trigger_tp(nonce); 581 + 582 + return nonce; 583 + } 584 + 578 585 int noinline bpf_fentry_shadow_test(int a) 579 586 { 580 587 return a + 1; ··· 629 622 BTF_KFUNCS_START(bpf_test_modify_return_ids) 630 623 BTF_ID_FLAGS(func, bpf_modify_return_test) 631 624 BTF_ID_FLAGS(func, bpf_modify_return_test2) 625 + BTF_ID_FLAGS(func, bpf_modify_return_test_tp) 632 626 BTF_ID_FLAGS(func, bpf_fentry_test1, KF_SLEEPABLE) 633 627 BTF_KFUNCS_END(bpf_test_modify_return_ids) 634 628