On Thu, 2025-01-30 at 13:23 +0200, Dimitar Kanaliev wrote: > This commit adds a few more tests related to tnum_scast that explicitly > check cases with known / unknown sign bit, as well as values that cross > zero (going from negative to positive). > > Signed-off-by: Dimitar Kanaliev <dimitar.kanaliev@xxxxxxxxxxxxxx> > --- > .../selftests/bpf/progs/verifier_movsx.c | 73 +++++++++++++++++++ > 1 file changed, 73 insertions(+) > > diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c > index 994bbc346d25..20abeec09dee 100644 > --- a/tools/testing/selftests/bpf/progs/verifier_movsx.c > +++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c > @@ -327,6 +327,79 @@ label_%=: \ > : __clobber_all); > } > > +SEC("socket") > +__description("MOV64SX, S8, unknown value") > +__success __success_unpriv __retval(1) Note: __retval() annotation is needed when one wants to execute the test using libbpf's bpf_prog_test_run_opts(). The changes for register range tracking should not affect runtime behaviour (unless there is a bug in and some dead code elimination is done incorrectly). I suggest to add __log_level(2) annotation and check verifier log output using __msg() annotations to check what range is inferred for specific registers. As-is these new tests are passing on master as well, so the feature is effectively untested. > +__naked void mov64sx_s8_unknown(void) > +{ > + asm volatile (" \ > + call %[bpf_get_prandom_u32]; \ > + r1 = r0; \ > + r1 &= 0xFF; \ > + r1 = (s8)r1; \ > + if r1 s>= -128 goto l0_%=; \ > + r0 = 0; \ > + exit; \ > +l0_%=: \ > + if r1 s<= 127 goto l1_%=; \ > + r0 = 0; \ > + exit; \ > +l1_%=: \ > + r0 = 1; \ > + exit; \ > +" : > + : __imm(bpf_get_prandom_u32) > + : __clobber_all); > +} [...]