diff mbox series

[bpf-next] selftests/bpf: add assert for user stacks in test_task_stack

Message ID 20231112023010.144675-1-linux@jordanrome.com (mailing list archive)
State Accepted
Commit 727a92d62fd6a382b4c5972008e45667e707b0e4
Headers show
Series [bpf-next] selftests/bpf: add assert for user stacks in test_task_stack | expand

Commit Message

Jordan Rome Nov. 12, 2023, 2:30 a.m. UTC
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>
---
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c       | 2 ++
 tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c | 5 +++++
 2 files changed, 7 insertions(+)

Comments

Stanislav Fomichev Nov. 12, 2023, 7:03 p.m. UTC | #1
On 11/11, Jordan Rome wrote:
> 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>

Acked-by: Stanislav Fomichev <sdf@google.com>

(based on the tests passing)
patchwork-bot+netdevbpf@kernel.org Nov. 14, 2023, 2:50 a.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Sat, 11 Nov 2023 18:30:10 -0800 you wrote:
> 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>
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: add assert for user stacks in test_task_stack
    https://git.kernel.org/bpf/bpf-next/c/727a92d62fd6

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
index 4e02093c2cbe..618af9dfae9b 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
@@ -332,6 +332,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