diff mbox series

[bpf,09/12] selftests/bpf: test widening for iterating callbacks

Message ID 20231116021803.9982-10-eddyz87@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series verify callbacks as if they are called unknown number of times | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf, async
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 9 maintainers not CCed: haoluo@google.com song@kernel.org kpsingh@kernel.org jolsa@kernel.org john.fastabend@gmail.com linux-kselftest@vger.kernel.org shuah@kernel.org sdf@google.com mykolal@fb.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-2 success Logs for Validate matrix.py
bpf/vmtest-bpf-VM_Test-3 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-7 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-8 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-VM_Test-4 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-6 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-VM_Test-14 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-VM_Test-15 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-16 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-18 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-19 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-21 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-22 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for x86_64-llvm-16 / build / build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-25 success Logs for x86_64-llvm-16 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-26 success Logs for x86_64-llvm-16 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-27 success Logs for x86_64-llvm-16 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-28 success Logs for x86_64-llvm-16 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-29 success Logs for x86_64-llvm-16 / veristat
bpf/vmtest-bpf-VM_Test-13 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-11 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-10 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc

Commit Message

Eduard Zingerman Nov. 16, 2023, 2:18 a.m. UTC
A test case to verify that imprecise scalars widening is applied to
callback bodies on repetative iteration.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
 .../bpf/progs/verifier_iterating_callbacks.c  | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Andrii Nakryiko Nov. 17, 2023, 4:47 p.m. UTC | #1
On Wed, Nov 15, 2023 at 9:18 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
>
> A test case to verify that imprecise scalars widening is applied to
> callback bodies on repetative iteration.

typo: repetitive? repeating? successive? subsequent?

>
> Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
> ---
>  .../bpf/progs/verifier_iterating_callbacks.c  | 20 +++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c
> index fa9429f77a81..598c1e984b26 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c
> @@ -25,6 +25,7 @@ struct buf_context {
>
>  struct num_context {
>         __u64 i;
> +       __u64 j;
>  };
>
>  __u8 choice_arr[2] = { 0, 1 };
> @@ -69,6 +70,25 @@ int unsafe_on_zero_iter(void *unused)
>         return choice_arr[loop_ctx.i];
>  }
>
> +static int widening_cb(__u32 idx, struct num_context *ctx)
> +{
> +       ++ctx->i;
> +       return 0;
> +}
> +
> +SEC("?raw_tp")
> +__success
> +int widening(void *unused)
> +{
> +       struct num_context loop_ctx = { .i = 0, .j = 1 };
> +
> +       bpf_loop(100, widening_cb, &loop_ctx, 0);
> +       /* loop_ctx.j is not changed during callback iteration,
> +        * verifier should not apply widening to it.
> +        */
> +       return choice_arr[loop_ctx.j];

would the test be a bit more interesting if you use loop_ctx.i here?
`return choice_arr[loop_ctx.i & 1];` ?



> +}
> +
>  static int loop_detection_cb(__u32 idx, struct num_context *ctx)
>  {
>         for (;;) {}
> --
> 2.42.0
>
Eduard Zingerman Nov. 17, 2023, 6:53 p.m. UTC | #2
On Fri, 2023-11-17 at 11:47 -0500, Andrii Nakryiko wrote:
> On Wed, Nov 15, 2023 at 9:18 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > 
> > A test case to verify that imprecise scalars widening is applied to
> > callback bodies on repetative iteration.
> 
> typo: repetitive? repeating? successive? subsequent?

I'll configure spell-checking, I promise.

[...]
> > +static int widening_cb(__u32 idx, struct num_context *ctx)
> > +{
> > +       ++ctx->i;
> > +       return 0;
> > +}
> > +
> > +SEC("?raw_tp")
> > +__success
> > +int widening(void *unused)
> > +{
> > +       struct num_context loop_ctx = { .i = 0, .j = 1 };
> > +
> > +       bpf_loop(100, widening_cb, &loop_ctx, 0);
> > +       /* loop_ctx.j is not changed during callback iteration,
> > +        * verifier should not apply widening to it.
> > +        */
> > +       return choice_arr[loop_ctx.j];
> 
> would the test be a bit more interesting if you use loop_ctx.i here?
> `return choice_arr[loop_ctx.i & 1];` ? 

It would force precision for 'loop_ctx.i', precise values are not widened.

> 
> > +}
> > +
Andrii Nakryiko Nov. 17, 2023, 8:28 p.m. UTC | #3
On Fri, Nov 17, 2023 at 1:53 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
>
> On Fri, 2023-11-17 at 11:47 -0500, Andrii Nakryiko wrote:
> > On Wed, Nov 15, 2023 at 9:18 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > >
> > > A test case to verify that imprecise scalars widening is applied to
> > > callback bodies on repetative iteration.
> >
> > typo: repetitive? repeating? successive? subsequent?
>
> I'll configure spell-checking, I promise.

no worries, I only notice it because gmail highlights it. I was rather
wondering if "repetitive iteration" is the right way to explain this.

>
> [...]
> > > +static int widening_cb(__u32 idx, struct num_context *ctx)
> > > +{
> > > +       ++ctx->i;
> > > +       return 0;
> > > +}
> > > +
> > > +SEC("?raw_tp")
> > > +__success
> > > +int widening(void *unused)
> > > +{
> > > +       struct num_context loop_ctx = { .i = 0, .j = 1 };
> > > +
> > > +       bpf_loop(100, widening_cb, &loop_ctx, 0);
> > > +       /* loop_ctx.j is not changed during callback iteration,
> > > +        * verifier should not apply widening to it.
> > > +        */
> > > +       return choice_arr[loop_ctx.j];
> >
> > would the test be a bit more interesting if you use loop_ctx.i here?
> > `return choice_arr[loop_ctx.i & 1];` ?
>
> It would force precision for 'loop_ctx.i', precise values are not widened.

ah, right, ok

>
> >
> > > +}
> > > +
>
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c
index fa9429f77a81..598c1e984b26 100644
--- a/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c
+++ b/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c
@@ -25,6 +25,7 @@  struct buf_context {
 
 struct num_context {
 	__u64 i;
+	__u64 j;
 };
 
 __u8 choice_arr[2] = { 0, 1 };
@@ -69,6 +70,25 @@  int unsafe_on_zero_iter(void *unused)
 	return choice_arr[loop_ctx.i];
 }
 
+static int widening_cb(__u32 idx, struct num_context *ctx)
+{
+	++ctx->i;
+	return 0;
+}
+
+SEC("?raw_tp")
+__success
+int widening(void *unused)
+{
+	struct num_context loop_ctx = { .i = 0, .j = 1 };
+
+	bpf_loop(100, widening_cb, &loop_ctx, 0);
+	/* loop_ctx.j is not changed during callback iteration,
+	 * verifier should not apply widening to it.
+	 */
+	return choice_arr[loop_ctx.j];
+}
+
 static int loop_detection_cb(__u32 idx, struct num_context *ctx)
 {
 	for (;;) {}