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

selftests/bpf: Add selftest for calling global functions from freplace

Add a selftest that calls a global function with a context object parameter
from an freplace function to check that the program context type is
correctly converted to the freplace target when fetching the context type
from the kernel BTF.

v2:
- Trim includes
- Get rid of global function
- Use __noinline

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/r/20220606075253.28422-2-toke@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Toke Høiland-Jørgensen and committed by
Alexei Starovoitov
2cf7b7ff f858c2b2

+32
+14
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
··· 395 395 "./test_attach_probe.o"); 396 396 } 397 397 398 + static void test_func_replace_global_func(void) 399 + { 400 + const char *prog_name[] = { 401 + "freplace/test_pkt_access", 402 + }; 403 + 404 + test_fexit_bpf2bpf_common("./freplace_global_func.o", 405 + "./test_pkt_access.o", 406 + ARRAY_SIZE(prog_name), 407 + prog_name, false, NULL); 408 + } 409 + 398 410 /* NOTE: affect other tests, must run in serial mode */ 399 411 void serial_test_fexit_bpf2bpf(void) 400 412 { ··· 428 416 test_func_replace_multi(); 429 417 if (test__start_subtest("fmod_ret_freplace")) 430 418 test_fmod_ret_freplace(); 419 + if (test__start_subtest("func_replace_global_func")) 420 + test_func_replace_global_func(); 431 421 }
+18
tools/testing/selftests/bpf/progs/freplace_global_func.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/bpf.h> 3 + #include <bpf/bpf_helpers.h> 4 + 5 + __noinline 6 + int test_ctx_global_func(struct __sk_buff *skb) 7 + { 8 + volatile int retval = 1; 9 + return retval; 10 + } 11 + 12 + SEC("freplace/test_pkt_access") 13 + int new_test_pkt_access(struct __sk_buff *skb) 14 + { 15 + return test_ctx_global_func(skb); 16 + } 17 + 18 + char _license[] SEC("license") = "GPL";