Re: [PATCH v2 2/2] selftests/bpf: Add testcases for BPF_ADD and BPF_SUB
From: Eduard Zingerman
Date: Wed Jun 18 2025 - 17:23:07 EST
On Tue, 2025-06-17 at 19:17 -0400, Harishankar Vishwanathan wrote:
> The previous commit improves the precision in scalar(32)_min_max_add,
> and scalar(32)_min_max_sub. The improvement in precision occurs in
> cases when all outcomes overflow or underflow, respectively. This
> commit adds selftests that exercise those cases.
>
> Co-developed-by: Matan Shachnai <m.shachnai@xxxxxxxxxxx>
> Signed-off-by: Matan Shachnai <m.shachnai@xxxxxxxxxxx>
> Signed-off-by: Harishankar Vishwanathan <harishankar.vishwanathan@xxxxxxxxx>
> ---
Could you please also add test cases when one bound overflows while
another does not? Or these are covered by some other tests?
[...]
> +SEC("socket")
> +__description("64-bit addition overflow, all outcomes overflow")
> +__success __log_level(2)
> +__msg("7: (0f) r5 += r3 {{.*}} R5_w=scalar(smin=0x800003d67e960f7d,umin=0x551ee3d67e960f7d,umax=0xc0149fffffffffff,smin32=0xfe960f7d,umin32=0x7e960f7d,var_off=(0x3d67e960f7d; 0xfffffc298169f082))")
Would it be possible to pick some more "human readable" constants here?
As-is it is hard to make sense what verifier actually computes.
> +__retval(0)
> +__naked void add64_ovf(void)
> +{
> + asm volatile (
> + "call %[bpf_get_prandom_u32];"
> + "r3 = r0;"
> + "r4 = 0x950a43d67e960f7d ll;"
> + "r3 |= r4;"
> + "r5 = 0xc014a00000000000 ll;"
> + "r5 += r3;"
> + "r0 = 0;"
> + "exit"
> + :
> + : __imm(bpf_get_prandom_u32)
> + : __clobber_all);
> +}
[...]