Skip to content

Commit be7dbd2

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: avoid mark_all_scalars_precise() trigger in one of iter tests
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] 71b547f ("bpf: Fix incorrect verifier pruning due to missing register precision taints") Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent a0c109d commit be7dbd2

File tree

1 file changed

+15
-11
lines changed
  • tools/testing/selftests/bpf/progs

1 file changed

+15
-11
lines changed

tools/testing/selftests/bpf/progs/iters.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -651,25 +651,29 @@ int iter_stack_array_loop(const void *ctx)
651651
return sum;
652652
}
653653

654-
static __noinline void fill(struct bpf_iter_num *it, int *arr, __u32 n, int mul)
654+
#define ARR_SZ 16
655+
656+
static __noinline void fill(struct bpf_iter_num *it, int *arr, int mul)
655657
{
656-
int *t, i;
658+
int *t;
659+
__u64 i;
657660

658661
while ((t = bpf_iter_num_next(it))) {
659662
i = *t;
660-
if (i >= n)
663+
if (i >= ARR_SZ)
661664
break;
662665
arr[i] = i * mul;
663666
}
664667
}
665668

666-
static __noinline int sum(struct bpf_iter_num *it, int *arr, __u32 n)
669+
static __noinline int sum(struct bpf_iter_num *it, int *arr)
667670
{
668-
int *t, i, sum = 0;;
671+
int *t, sum = 0;;
672+
__u64 i;
669673

670674
while ((t = bpf_iter_num_next(it))) {
671675
i = *t;
672-
if (i >= n)
676+
if (i >= ARR_SZ)
673677
break;
674678
sum += arr[i];
675679
}
@@ -681,7 +685,7 @@ SEC("raw_tp")
681685
__success
682686
int iter_pass_iter_ptr_to_subprog(const void *ctx)
683687
{
684-
int arr1[16], arr2[32];
688+
int arr1[ARR_SZ], arr2[ARR_SZ];
685689
struct bpf_iter_num it;
686690
int n, sum1, sum2;
687691

@@ -690,25 +694,25 @@ int iter_pass_iter_ptr_to_subprog(const void *ctx)
690694
/* fill arr1 */
691695
n = ARRAY_SIZE(arr1);
692696
bpf_iter_num_new(&it, 0, n);
693-
fill(&it, arr1, n, 2);
697+
fill(&it, arr1, 2);
694698
bpf_iter_num_destroy(&it);
695699

696700
/* fill arr2 */
697701
n = ARRAY_SIZE(arr2);
698702
bpf_iter_num_new(&it, 0, n);
699-
fill(&it, arr2, n, 10);
703+
fill(&it, arr2, 10);
700704
bpf_iter_num_destroy(&it);
701705

702706
/* sum arr1 */
703707
n = ARRAY_SIZE(arr1);
704708
bpf_iter_num_new(&it, 0, n);
705-
sum1 = sum(&it, arr1, n);
709+
sum1 = sum(&it, arr1);
706710
bpf_iter_num_destroy(&it);
707711

708712
/* sum arr2 */
709713
n = ARRAY_SIZE(arr2);
710714
bpf_iter_num_new(&it, 0, n);
711-
sum2 = sum(&it, arr2, n);
715+
sum2 = sum(&it, arr2);
712716
bpf_iter_num_destroy(&it);
713717

714718
bpf_printk("sum1=%d, sum2=%d", sum1, sum2);

0 commit comments

Comments
 (0)