mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
In commit 22df776a9a
("tasks: Extract rcu_users out of union"), the
'refcount_t rcu_users' field was extracted out of a union with the
'struct rcu_head rcu' field. This allows us to safely perform a
refcount_inc_not_zero() on task->rcu_users when acquiring a reference on
a task struct. A prior patch leveraged this by making struct task_struct
an RCU-protected object in the verifier, and by bpf_task_acquire() to
use the task->rcu_users field for synchronization.
Now that we can use RCU to protect tasks, we no longer need
bpf_task_kptr_get(), or bpf_task_acquire_not_zero(). bpf_task_kptr_get()
is truly completely unnecessary, as we can just use RCU to get the
object. bpf_task_acquire_not_zero() is now equivalent to
bpf_task_acquire().
In addition to these changes, this patch also updates the associated
selftests to no longer use these kfuncs.
Signed-off-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/r/20230331195733.699708-3-void@manifault.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
96 lines
2.1 KiB
C
96 lines
2.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
|
|
|
|
#define _GNU_SOURCE
|
|
#include <sys/wait.h>
|
|
#include <test_progs.h>
|
|
#include <unistd.h>
|
|
|
|
#include "task_kfunc_failure.skel.h"
|
|
#include "task_kfunc_success.skel.h"
|
|
|
|
static struct task_kfunc_success *open_load_task_kfunc_skel(void)
|
|
{
|
|
struct task_kfunc_success *skel;
|
|
int err;
|
|
|
|
skel = task_kfunc_success__open();
|
|
if (!ASSERT_OK_PTR(skel, "skel_open"))
|
|
return NULL;
|
|
|
|
skel->bss->pid = getpid();
|
|
|
|
err = task_kfunc_success__load(skel);
|
|
if (!ASSERT_OK(err, "skel_load"))
|
|
goto cleanup;
|
|
|
|
return skel;
|
|
|
|
cleanup:
|
|
task_kfunc_success__destroy(skel);
|
|
return NULL;
|
|
}
|
|
|
|
static void run_success_test(const char *prog_name)
|
|
{
|
|
struct task_kfunc_success *skel;
|
|
int status;
|
|
pid_t child_pid;
|
|
struct bpf_program *prog;
|
|
struct bpf_link *link = NULL;
|
|
|
|
skel = open_load_task_kfunc_skel();
|
|
if (!ASSERT_OK_PTR(skel, "open_load_skel"))
|
|
return;
|
|
|
|
if (!ASSERT_OK(skel->bss->err, "pre_spawn_err"))
|
|
goto cleanup;
|
|
|
|
prog = bpf_object__find_program_by_name(skel->obj, prog_name);
|
|
if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
|
|
goto cleanup;
|
|
|
|
link = bpf_program__attach(prog);
|
|
if (!ASSERT_OK_PTR(link, "attached_link"))
|
|
goto cleanup;
|
|
|
|
child_pid = fork();
|
|
if (!ASSERT_GT(child_pid, -1, "child_pid"))
|
|
goto cleanup;
|
|
if (child_pid == 0)
|
|
_exit(0);
|
|
waitpid(child_pid, &status, 0);
|
|
|
|
ASSERT_OK(skel->bss->err, "post_wait_err");
|
|
|
|
cleanup:
|
|
bpf_link__destroy(link);
|
|
task_kfunc_success__destroy(skel);
|
|
}
|
|
|
|
static const char * const success_tests[] = {
|
|
"test_task_acquire_release_argument",
|
|
"test_task_acquire_release_current",
|
|
"test_task_acquire_leave_in_map",
|
|
"test_task_xchg_release",
|
|
"test_task_map_acquire_release",
|
|
"test_task_current_acquire_release",
|
|
"test_task_from_pid_arg",
|
|
"test_task_from_pid_current",
|
|
"test_task_from_pid_invalid",
|
|
"task_kfunc_acquire_trusted_walked",
|
|
};
|
|
|
|
void test_task_kfunc(void)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(success_tests); i++) {
|
|
if (!test__start_subtest(success_tests[i]))
|
|
continue;
|
|
|
|
run_success_test(success_tests[i]);
|
|
}
|
|
|
|
RUN_TESTS(task_kfunc_failure);
|
|
}
|