Commit 95fdf6e3 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by Andrii Nakryiko

selftests/bpf: Add test for bpf_ksym_exists().

Add load and run time test for bpf_ksym_exists() and check that the verifier
performs dead code elimination for non-existing kfunc.
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Reviewed-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20230317201920.62030-5-alexei.starovoitov@gmail.com
parent 5cbd3fe3
......@@ -17,6 +17,10 @@ int err, pid;
* TP_PROTO(struct task_struct *p, u64 clone_flags)
*/
struct task_struct *bpf_task_acquire(struct task_struct *p) __ksym __weak;
void invalid_kfunc(void) __ksym __weak;
void bpf_testmod_test_mod_kfunc(int i) __ksym __weak;
static bool is_test_kfunc_task(void)
{
int cur_pid = bpf_get_current_pid_tgid() >> 32;
......@@ -26,7 +30,21 @@ static bool is_test_kfunc_task(void)
static int test_acquire_release(struct task_struct *task)
{
struct task_struct *acquired;
struct task_struct *acquired = NULL;
if (!bpf_ksym_exists(bpf_task_acquire)) {
err = 3;
return 0;
}
if (!bpf_ksym_exists(bpf_testmod_test_mod_kfunc)) {
err = 4;
return 0;
}
if (bpf_ksym_exists(invalid_kfunc)) {
/* the verifier's dead code elimination should remove this */
err = 5;
asm volatile ("goto -1"); /* for (;;); */
}
acquired = bpf_task_acquire(task);
bpf_task_release(acquired);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment