All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: avoid mark_all_scalars_precise() trigger in one of iter tests
@ 2023-04-24 23:51 Andrii Nakryiko
  2023-04-25  0:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2023-04-24 23:51 UTC (permalink / raw
  To: bpf, ast, daniel, martin.lau; +Cc: andrii, kernel-team

iter_pass_iter_ptr_to_subprog subtest is relying on actual array size
being passed as subprog parameter. This combined with recent fixes to
precision tracking in conditional jumps ([0]) is now causing verifier to
backtrack all the way to the point where sum() and fill() subprogs are
called, at which point precision backtrack bails out and forces all the
states to have precise SCALAR registers. This in turn causes each
possible value of i within fill() and sum() subprogs to cause
a different non-equivalent state, preventing iterator code to converge.

For now, change the test to assume fixed size of passed in array. Once
BPF verifier supports precision tracking across subprogram calls, these
changes will be reverted as unnecessary.

  [0] 71b547f56124 ("bpf: Fix incorrect verifier pruning due to missing register precision taints")

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/testing/selftests/bpf/progs/iters.c | 26 +++++++++++++----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/iters.c b/tools/testing/selftests/bpf/progs/iters.c
index 6b9b3c56f009..be16143ae292 100644
--- a/tools/testing/selftests/bpf/progs/iters.c
+++ b/tools/testing/selftests/bpf/progs/iters.c
@@ -651,25 +651,29 @@ int iter_stack_array_loop(const void *ctx)
 	return sum;
 }
 
-static __noinline void fill(struct bpf_iter_num *it, int *arr, __u32 n, int mul)
+#define ARR_SZ 16
+
+static __noinline void fill(struct bpf_iter_num *it, int *arr, int mul)
 {
-	int *t, i;
+	int *t;
+	__u64 i;
 
 	while ((t = bpf_iter_num_next(it))) {
 		i = *t;
-		if (i >= n)
+		if (i >= ARR_SZ)
 			break;
 		arr[i] =  i * mul;
 	}
 }
 
-static __noinline int sum(struct bpf_iter_num *it, int *arr, __u32 n)
+static __noinline int sum(struct bpf_iter_num *it, int *arr)
 {
-	int *t, i, sum = 0;;
+	int *t, sum = 0;;
+	__u64 i;
 
 	while ((t = bpf_iter_num_next(it))) {
 		i = *t;
-		if (i >= n)
+		if (i >= ARR_SZ)
 			break;
 		sum += arr[i];
 	}
@@ -681,7 +685,7 @@ SEC("raw_tp")
 __success
 int iter_pass_iter_ptr_to_subprog(const void *ctx)
 {
-	int arr1[16], arr2[32];
+	int arr1[ARR_SZ], arr2[ARR_SZ];
 	struct bpf_iter_num it;
 	int n, sum1, sum2;
 
@@ -690,25 +694,25 @@ int iter_pass_iter_ptr_to_subprog(const void *ctx)
 	/* fill arr1 */
 	n = ARRAY_SIZE(arr1);
 	bpf_iter_num_new(&it, 0, n);
-	fill(&it, arr1, n, 2);
+	fill(&it, arr1, 2);
 	bpf_iter_num_destroy(&it);
 
 	/* fill arr2 */
 	n = ARRAY_SIZE(arr2);
 	bpf_iter_num_new(&it, 0, n);
-	fill(&it, arr2, n, 10);
+	fill(&it, arr2, 10);
 	bpf_iter_num_destroy(&it);
 
 	/* sum arr1 */
 	n = ARRAY_SIZE(arr1);
 	bpf_iter_num_new(&it, 0, n);
-	sum1 = sum(&it, arr1, n);
+	sum1 = sum(&it, arr1);
 	bpf_iter_num_destroy(&it);
 
 	/* sum arr2 */
 	n = ARRAY_SIZE(arr2);
 	bpf_iter_num_new(&it, 0, n);
-	sum2 = sum(&it, arr2, n);
+	sum2 = sum(&it, arr2);
 	bpf_iter_num_destroy(&it);
 
 	bpf_printk("sum1=%d, sum2=%d", sum1, sum2);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: avoid mark_all_scalars_precise() trigger in one of iter tests
  2023-04-24 23:51 [PATCH bpf-next] selftests/bpf: avoid mark_all_scalars_precise() trigger in one of iter tests Andrii Nakryiko
@ 2023-04-25  0:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-04-25  0:50 UTC (permalink / raw
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, martin.lau, kernel-team

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Mon, 24 Apr 2023 16:51:28 -0700 you wrote:
> iter_pass_iter_ptr_to_subprog subtest is relying on actual array size
> being passed as subprog parameter. This combined with recent fixes to
> precision tracking in conditional jumps ([0]) is now causing verifier to
> backtrack all the way to the point where sum() and fill() subprogs are
> called, at which point precision backtrack bails out and forces all the
> states to have precise SCALAR registers. This in turn causes each
> possible value of i within fill() and sum() subprogs to cause
> a different non-equivalent state, preventing iterator code to converge.
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: avoid mark_all_scalars_precise() trigger in one of iter tests
    https://git.kernel.org/bpf/bpf-next/c/be7dbd275dc6

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] 2+ messages in thread

end of thread, other threads:[~2023-04-25  0:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-24 23:51 [PATCH bpf-next] selftests/bpf: avoid mark_all_scalars_precise() trigger in one of iter tests Andrii Nakryiko
2023-04-25  0:50 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.