* [PATCH bpf-next] selftests/bpf: Make linked_list failure test more robust
@ 2023-10-20 14:48 Kumar Kartikeya Dwivedi
2023-10-20 16:30 ` Andrii Nakryiko
2023-10-20 17:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2023-10-20 14:48 UTC (permalink / raw)
To: bpf; +Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau
The linked list failure test 'pop_front_off' and 'pop_back_off'
currently rely on matching exact instruction and register values. The
purpose of the test is to ensure the offset is correctly incremented for
the returned pointers from list pop helpers, which can then be used with
container_of to obtain the real object. Hence, somehow obtaining the
information that the offset is 48 will work for us. Make the test more
robust by relying on verifier error string of bpf_spin_lock and remove
dependence on fragile instruction index or register number, which can be
affected by different clang versions used to build the selftests.
Fixes: 300f19dcdb99 ("selftests/bpf: Add BPF linked list API tests")
Reported-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
tools/testing/selftests/bpf/prog_tests/linked_list.c | 10 ++--------
tools/testing/selftests/bpf/progs/linked_list_fail.c | 4 +++-
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/linked_list.c b/tools/testing/selftests/bpf/prog_tests/linked_list.c
index 69dc31383b78..2fb89de63bd2 100644
--- a/tools/testing/selftests/bpf/prog_tests/linked_list.c
+++ b/tools/testing/selftests/bpf/prog_tests/linked_list.c
@@ -94,14 +94,8 @@ static struct {
{ "incorrect_head_var_off2", "variable ptr_ access var_off=(0x0; 0xffffffff) disallowed" },
{ "incorrect_head_off1", "bpf_list_head not found at offset=25" },
{ "incorrect_head_off2", "bpf_list_head not found at offset=1" },
- { "pop_front_off",
- "15: (bf) r1 = r6 ; R1_w=ptr_or_null_foo(id=4,ref_obj_id=4,off=48,imm=0) "
- "R6_w=ptr_or_null_foo(id=4,ref_obj_id=4,off=48,imm=0) refs=2,4\n"
- "16: (85) call bpf_this_cpu_ptr#154\nR1 type=ptr_or_null_ expected=percpu_ptr_" },
- { "pop_back_off",
- "15: (bf) r1 = r6 ; R1_w=ptr_or_null_foo(id=4,ref_obj_id=4,off=48,imm=0) "
- "R6_w=ptr_or_null_foo(id=4,ref_obj_id=4,off=48,imm=0) refs=2,4\n"
- "16: (85) call bpf_this_cpu_ptr#154\nR1 type=ptr_or_null_ expected=percpu_ptr_" },
+ { "pop_front_off", "off 48 doesn't point to 'struct bpf_spin_lock' that is at 40" },
+ { "pop_back_off", "off 48 doesn't point to 'struct bpf_spin_lock' that is at 40" },
};
static void test_linked_list_fail_prog(const char *prog_name, const char *err_msg)
diff --git a/tools/testing/selftests/bpf/progs/linked_list_fail.c b/tools/testing/selftests/bpf/progs/linked_list_fail.c
index f4c63daba229..6438982b928b 100644
--- a/tools/testing/selftests/bpf/progs/linked_list_fail.c
+++ b/tools/testing/selftests/bpf/progs/linked_list_fail.c
@@ -591,7 +591,9 @@ int pop_ptr_off(void *(*op)(void *head))
n = op(&p->head);
bpf_spin_unlock(&p->lock);
- bpf_this_cpu_ptr(n);
+ if (!n)
+ return 0;
+ bpf_spin_lock((void *)n);
return 0;
}
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Make linked_list failure test more robust
2023-10-20 14:48 [PATCH bpf-next] selftests/bpf: Make linked_list failure test more robust Kumar Kartikeya Dwivedi
@ 2023-10-20 16:30 ` Andrii Nakryiko
2023-10-20 17:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2023-10-20 16:30 UTC (permalink / raw)
To: Kumar Kartikeya Dwivedi
Cc: bpf, Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau
On Fri, Oct 20, 2023 at 7:48 AM Kumar Kartikeya Dwivedi
<memxor@gmail.com> wrote:
>
> The linked list failure test 'pop_front_off' and 'pop_back_off'
> currently rely on matching exact instruction and register values. The
> purpose of the test is to ensure the offset is correctly incremented for
> the returned pointers from list pop helpers, which can then be used with
> container_of to obtain the real object. Hence, somehow obtaining the
> information that the offset is 48 will work for us. Make the test more
> robust by relying on verifier error string of bpf_spin_lock and remove
> dependence on fragile instruction index or register number, which can be
> affected by different clang versions used to build the selftests.
>
> Fixes: 300f19dcdb99 ("selftests/bpf: Add BPF linked list API tests")
> Reported-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---
> tools/testing/selftests/bpf/prog_tests/linked_list.c | 10 ++--------
> tools/testing/selftests/bpf/progs/linked_list_fail.c | 4 +++-
> 2 files changed, 5 insertions(+), 9 deletions(-)
>
Thanks for the fix! Applied to bpf-next.
> diff --git a/tools/testing/selftests/bpf/prog_tests/linked_list.c b/tools/testing/selftests/bpf/prog_tests/linked_list.c
> index 69dc31383b78..2fb89de63bd2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/linked_list.c
> +++ b/tools/testing/selftests/bpf/prog_tests/linked_list.c
> @@ -94,14 +94,8 @@ static struct {
> { "incorrect_head_var_off2", "variable ptr_ access var_off=(0x0; 0xffffffff) disallowed" },
> { "incorrect_head_off1", "bpf_list_head not found at offset=25" },
> { "incorrect_head_off2", "bpf_list_head not found at offset=1" },
> - { "pop_front_off",
> - "15: (bf) r1 = r6 ; R1_w=ptr_or_null_foo(id=4,ref_obj_id=4,off=48,imm=0) "
> - "R6_w=ptr_or_null_foo(id=4,ref_obj_id=4,off=48,imm=0) refs=2,4\n"
> - "16: (85) call bpf_this_cpu_ptr#154\nR1 type=ptr_or_null_ expected=percpu_ptr_" },
> - { "pop_back_off",
> - "15: (bf) r1 = r6 ; R1_w=ptr_or_null_foo(id=4,ref_obj_id=4,off=48,imm=0) "
> - "R6_w=ptr_or_null_foo(id=4,ref_obj_id=4,off=48,imm=0) refs=2,4\n"
> - "16: (85) call bpf_this_cpu_ptr#154\nR1 type=ptr_or_null_ expected=percpu_ptr_" },
> + { "pop_front_off", "off 48 doesn't point to 'struct bpf_spin_lock' that is at 40" },
> + { "pop_back_off", "off 48 doesn't point to 'struct bpf_spin_lock' that is at 40" },
> };
>
> static void test_linked_list_fail_prog(const char *prog_name, const char *err_msg)
> diff --git a/tools/testing/selftests/bpf/progs/linked_list_fail.c b/tools/testing/selftests/bpf/progs/linked_list_fail.c
> index f4c63daba229..6438982b928b 100644
> --- a/tools/testing/selftests/bpf/progs/linked_list_fail.c
> +++ b/tools/testing/selftests/bpf/progs/linked_list_fail.c
> @@ -591,7 +591,9 @@ int pop_ptr_off(void *(*op)(void *head))
> n = op(&p->head);
> bpf_spin_unlock(&p->lock);
>
> - bpf_this_cpu_ptr(n);
> + if (!n)
> + return 0;
> + bpf_spin_lock((void *)n);
> return 0;
> }
>
> --
> 2.40.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Make linked_list failure test more robust
2023-10-20 14:48 [PATCH bpf-next] selftests/bpf: Make linked_list failure test more robust Kumar Kartikeya Dwivedi
2023-10-20 16:30 ` Andrii Nakryiko
@ 2023-10-20 17:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-20 17:10 UTC (permalink / raw)
To: Kumar Kartikeya Dwivedi; +Cc: bpf, andrii, ast, daniel, martin.lau
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Fri, 20 Oct 2023 14:48:39 +0000 you wrote:
> The linked list failure test 'pop_front_off' and 'pop_back_off'
> currently rely on matching exact instruction and register values. The
> purpose of the test is to ensure the offset is correctly incremented for
> the returned pointers from list pop helpers, which can then be used with
> container_of to obtain the real object. Hence, somehow obtaining the
> information that the offset is 48 will work for us. Make the test more
> robust by relying on verifier error string of bpf_spin_lock and remove
> dependence on fragile instruction index or register number, which can be
> affected by different clang versions used to build the selftests.
>
> [...]
Here is the summary with links:
- [bpf-next] selftests/bpf: Make linked_list failure test more robust
https://git.kernel.org/bpf/bpf-next/c/da1055b673f3
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-20 17:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-20 14:48 [PATCH bpf-next] selftests/bpf: Make linked_list failure test more robust Kumar Kartikeya Dwivedi
2023-10-20 16:30 ` Andrii Nakryiko
2023-10-20 17:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox