diff options
author | Jordan Rome <linux@jordanrome.com> | 2023-11-11 18:30:10 -0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-01-25 15:35:41 -0800 |
commit | 3db79d21cf9cd1f52b4e0b2497e47b2967495a25 (patch) | |
tree | dac64e310f18bd168793aa8a6e27bc6d3b051aad | |
parent | 5f93225dc925c43bb95c0a8a1e24f1a28d5370da (diff) | |
download | linux-stable-3db79d21cf9cd1f52b4e0b2497e47b2967495a25.tar.gz linux-stable-3db79d21cf9cd1f52b4e0b2497e47b2967495a25.tar.bz2 linux-stable-3db79d21cf9cd1f52b4e0b2497e47b2967495a25.zip |
selftests/bpf: Add assert for user stacks in test_task_stack
commit 727a92d62fd6a382b4c5972008e45667e707b0e4 upstream.
This is a follow up to:
commit b8e3a87a627b ("bpf: Add crosstask check to __bpf_get_stack").
This test ensures that the task iterator only gets a single
user stack (for the current task).
Signed-off-by: Jordan Rome <linux@jordanrome.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20231112023010.144675-1-linux@jordanrome.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 2 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c | 5 |
2 files changed, 7 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c index 1f02168103dd..f141e278b16f 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c @@ -334,6 +334,8 @@ static void test_task_stack(void) do_dummy_read(skel->progs.dump_task_stack); do_dummy_read(skel->progs.get_task_user_stacks); + ASSERT_EQ(skel->bss->num_user_stacks, 1, "num_user_stacks"); + bpf_iter_task_stack__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c b/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c index f2b8167b72a8..442f4ca39fd7 100644 --- a/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c +++ b/tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c @@ -35,6 +35,8 @@ int dump_task_stack(struct bpf_iter__task *ctx) return 0; } +int num_user_stacks = 0; + SEC("iter/task") int get_task_user_stacks(struct bpf_iter__task *ctx) { @@ -51,6 +53,9 @@ int get_task_user_stacks(struct bpf_iter__task *ctx) if (res <= 0) return 0; + /* Only one task, the current one, should succeed */ + ++num_user_stacks; + buf_sz += res; /* If the verifier doesn't refine bpf_get_task_stack res, and instead |