Skip to contentSkip to conversation

selftests/bpf: add assert for user stacks in test_task_stack

PATCH Applied Jordan Rome 3 participants 3 messages Nov 12, 2023 – Nov 14, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: add assert for user stacks in test_task_stack

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).

---
 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(+)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +2 -0
index 4e02093c2cbe..618af9dfae9b 100644
@@ -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);
 }
 
tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c +5 -0
index f2b8167b72a8..442f4ca39fd7 100644
@@ -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
Signature · 1 line
2.39.3
#2 lore raw
In reply to Jordan Rome
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 9 lines · 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).

[...]

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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html