From: Alexei Starovoitov Add tests for special arithmetic shift right. Signed-off-by: Alexei Starovoitov --- .../selftests/bpf/progs/verifier_subreg.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/verifier_subreg.c b/tools/testing/selftests/bpf/progs/verifier_subreg.c index 8613ea160dcd..b18b75c532bc 100644 --- a/tools/testing/selftests/bpf/progs/verifier_subreg.c +++ b/tools/testing/selftests/bpf/progs/verifier_subreg.c @@ -670,4 +670,45 @@ __naked void ldx_w_zero_extend_check(void) : __clobber_all); } +SEC("socket") +__description("s>>=31") +__success __success_unpriv __retval(0) +__naked void arsh_31(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + w2 = w0; \ + w2 s>>= 31; \ + w2 &= -134; \ + if w2 s> -1 goto +2; \ + if w2 != 0xffffff78 goto +1; \ + w0 /= 0; \ + w0 = 0; \ + exit; \ +" : + : __imm(bpf_get_prandom_u32) + : __clobber_all); +} + +SEC("socket") +__description("s>>=63") +__success __success_unpriv __retval(0) +__naked void arsh_63(void) +{ + asm volatile (" \ + call %[bpf_get_prandom_u32]; \ + r2 = r0; \ + r2 <<= 32; \ + r2 s>>= 63; \ + r2 &= -134; \ + if r2 s> -1 goto +2; \ + if r2 != 0xffffff78 goto +1; \ + r0 /= 0; \ + r0 = 0; \ + exit; \ +" : + : __imm(bpf_get_prandom_u32) + : __clobber_all); +} + char _license[] SEC("license") = "GPL"; -- 2.47.3