Skip to content

Commit a66c0a0

Browse files
Alexei StarovoitovKernel Patches Daemon
authored andcommitted
selftests/bpf: Add tests for s>>=31 and s>>=63
Add tests for special arithmetic shift right. Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 296d10e commit a66c0a0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,4 +670,45 @@ __naked void ldx_w_zero_extend_check(void)
670670
: __clobber_all);
671671
}
672672

673+
SEC("socket")
674+
__description("s>>=31")
675+
__success __success_unpriv __retval(0)
676+
__naked void arsh_31(void)
677+
{
678+
asm volatile (" \
679+
call %[bpf_get_prandom_u32]; \
680+
w2 = w0; \
681+
w2 s>>= 31; \
682+
w2 &= -134; \
683+
if w2 s> -1 goto +2; \
684+
if w2 != 0xffffff78 goto +1; \
685+
w0 /= 0; \
686+
w0 = 0; \
687+
exit; \
688+
" :
689+
: __imm(bpf_get_prandom_u32)
690+
: __clobber_all);
691+
}
692+
693+
SEC("socket")
694+
__description("s>>=63")
695+
__success __success_unpriv __retval(0)
696+
__naked void arsh_63(void)
697+
{
698+
asm volatile (" \
699+
call %[bpf_get_prandom_u32]; \
700+
r2 = r0; \
701+
r2 <<= 32; \
702+
r2 s>>= 63; \
703+
r2 &= -134; \
704+
if r2 s> -1 goto +2; \
705+
if r2 != 0xffffff78 goto +1; \
706+
r0 /= 0; \
707+
r0 = 0; \
708+
exit; \
709+
" :
710+
: __imm(bpf_get_prandom_u32)
711+
: __clobber_all);
712+
}
713+
673714
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)