mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-20 16:52:28 +00:00
This patch adds a gen_epilogue test to test a main prog
using a bpf_tail_call.
A non test_loader test is used. The tailcall target program,
"test_epilogue_subprog", needs to be used in a struct_ops map
before it can be loaded. Another struct_ops map is also needed
to host the actual "test_epilogue_tailcall" struct_ops program
that does the bpf_tail_call. The earlier test_loader patch
will attach all struct_ops maps but the bpf_testmod.c does
not support >1 attached struct_ops.
The earlier patch used the test_loader which has already covered
checking for the patched pro/epilogue instructions. This is done
by the __xlated tag.
This patch goes for the regular skel load and syscall test to do
the tailcall test that can also allow to directly pass the
the "struct st_ops_args *args" as ctx_in to the
SEC("syscall") program.
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20240829210833.388152-8-martin.lau@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
59 lines
1.3 KiB
C
59 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
|
|
|
|
#include <vmlinux.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
#include "bpf_misc.h"
|
|
#include "../bpf_testmod/bpf_testmod.h"
|
|
#include "../bpf_testmod/bpf_testmod_kfunc.h"
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
static __noinline __used int subprog(struct st_ops_args *args)
|
|
{
|
|
args->a += 1;
|
|
return args->a;
|
|
}
|
|
|
|
SEC("struct_ops/test_epilogue_subprog")
|
|
int BPF_PROG(test_epilogue_subprog, struct st_ops_args *args)
|
|
{
|
|
subprog(args);
|
|
return args->a;
|
|
}
|
|
|
|
struct {
|
|
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
|
|
__uint(max_entries, 1);
|
|
__uint(key_size, sizeof(__u32));
|
|
__uint(value_size, sizeof(__u32));
|
|
__array(values, void (void));
|
|
} epilogue_map SEC(".maps") = {
|
|
.values = {
|
|
[0] = (void *)&test_epilogue_subprog,
|
|
}
|
|
};
|
|
|
|
SEC("struct_ops/test_epilogue_tailcall")
|
|
int test_epilogue_tailcall(unsigned long long *ctx)
|
|
{
|
|
bpf_tail_call(ctx, &epilogue_map, 0);
|
|
return 0;
|
|
}
|
|
|
|
SEC(".struct_ops.link")
|
|
struct bpf_testmod_st_ops epilogue_tailcall = {
|
|
.test_epilogue = (void *)test_epilogue_tailcall,
|
|
};
|
|
|
|
SEC(".struct_ops.link")
|
|
struct bpf_testmod_st_ops epilogue_subprog = {
|
|
.test_epilogue = (void *)test_epilogue_subprog,
|
|
};
|
|
|
|
SEC("syscall")
|
|
int syscall_epilogue_tailcall(struct st_ops_args *args)
|
|
{
|
|
return bpf_kfunc_st_ops_test_epilogue(args);
|
|
}
|