mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-17 20:54:10 +00:00
selftests/bpf: Add selftest for calling global functions from freplace
commit 2cf7b7ffda
upstream.
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>
[ backport: fix conflict because tests were not serialised ]
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
2d1e2881bd
commit
bfad0f77b3
2 changed files with 32 additions and 0 deletions
|
@ -371,6 +371,18 @@ static void test_func_map_prog_compatibility(void)
|
|||
"./test_attach_probe.o");
|
||||
}
|
||||
|
||||
static void test_func_replace_global_func(void)
|
||||
{
|
||||
const char *prog_name[] = {
|
||||
"freplace/test_pkt_access",
|
||||
};
|
||||
|
||||
test_fexit_bpf2bpf_common("./freplace_global_func.o",
|
||||
"./test_pkt_access.o",
|
||||
ARRAY_SIZE(prog_name),
|
||||
prog_name, false, NULL);
|
||||
}
|
||||
|
||||
void test_fexit_bpf2bpf(void)
|
||||
{
|
||||
if (test__start_subtest("target_no_callees"))
|
||||
|
@ -391,4 +403,6 @@ void test_fexit_bpf2bpf(void)
|
|||
test_func_replace_multi();
|
||||
if (test__start_subtest("fmod_ret_freplace"))
|
||||
test_fmod_ret_freplace();
|
||||
if (test__start_subtest("func_replace_global_func"))
|
||||
test_func_replace_global_func();
|
||||
}
|
||||
|
|
18
tools/testing/selftests/bpf/progs/freplace_global_func.c
Normal file
18
tools/testing/selftests/bpf/progs/freplace_global_func.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
|
||||
__noinline
|
||||
int test_ctx_global_func(struct __sk_buff *skb)
|
||||
{
|
||||
volatile int retval = 1;
|
||||
return retval;
|
||||
}
|
||||
|
||||
SEC("freplace/test_pkt_access")
|
||||
int new_test_pkt_access(struct __sk_buff *skb)
|
||||
{
|
||||
return test_ctx_global_func(skb);
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
Loading…
Add table
Reference in a new issue