selftests/bpf: Tests with may_goto and jumps to the 1st insn
Add few tests with may_goto and jumps to the 1st insn. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20240619011859.79334-2-alexei.starovoitov@gmail.com
This commit is contained in:
parent
5337ac4c9b
commit
2673315947
@ -307,6 +307,100 @@ int iter_limit_bug(struct __sk_buff *skb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("socket")
|
||||
__success __retval(0)
|
||||
__naked void ja_and_may_goto(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
l0_%=: .byte 0xe5; /* may_goto */ \
|
||||
.byte 0; /* regs */ \
|
||||
.short 1; /* off 1 */ \
|
||||
.long 0; /* imm */ \
|
||||
goto l0_%=; \
|
||||
r0 = 0; \
|
||||
exit; \
|
||||
" ::: __clobber_common);
|
||||
}
|
||||
|
||||
SEC("socket")
|
||||
__success __retval(0)
|
||||
__naked void ja_and_may_goto2(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
l0_%=: r0 = 0; \
|
||||
.byte 0xe5; /* may_goto */ \
|
||||
.byte 0; /* regs */ \
|
||||
.short 1; /* off 1 */ \
|
||||
.long 0; /* imm */ \
|
||||
goto l0_%=; \
|
||||
r0 = 0; \
|
||||
exit; \
|
||||
" ::: __clobber_common);
|
||||
}
|
||||
|
||||
SEC("socket")
|
||||
__success __retval(0)
|
||||
__naked void jlt_and_may_goto(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
l0_%=: call %[bpf_jiffies64]; \
|
||||
.byte 0xe5; /* may_goto */ \
|
||||
.byte 0; /* regs */ \
|
||||
.short 1; /* off 1 */ \
|
||||
.long 0; /* imm */ \
|
||||
if r0 < 10 goto l0_%=; \
|
||||
r0 = 0; \
|
||||
exit; \
|
||||
" :: __imm(bpf_jiffies64)
|
||||
: __clobber_all);
|
||||
}
|
||||
|
||||
#if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
|
||||
(defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
|
||||
defined(__TARGET_ARCH_arm) || defined(__TARGET_ARCH_s390) || \
|
||||
defined(__TARGET_ARCH_loongarch)) && \
|
||||
__clang_major__ >= 18
|
||||
SEC("socket")
|
||||
__success __retval(0)
|
||||
__naked void gotol_and_may_goto(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
l0_%=: r0 = 0; \
|
||||
.byte 0xe5; /* may_goto */ \
|
||||
.byte 0; /* regs */ \
|
||||
.short 1; /* off 1 */ \
|
||||
.long 0; /* imm */ \
|
||||
gotol l0_%=; \
|
||||
r0 = 0; \
|
||||
exit; \
|
||||
" ::: __clobber_common);
|
||||
}
|
||||
#endif
|
||||
|
||||
SEC("socket")
|
||||
__success __retval(0)
|
||||
__naked void ja_and_may_goto_subprog(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
call subprog_with_may_goto; \
|
||||
exit; \
|
||||
" ::: __clobber_all);
|
||||
}
|
||||
|
||||
static __naked __noinline __used
|
||||
void subprog_with_may_goto(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
l0_%=: .byte 0xe5; /* may_goto */ \
|
||||
.byte 0; /* regs */ \
|
||||
.short 1; /* off 1 */ \
|
||||
.long 0; /* imm */ \
|
||||
goto l0_%=; \
|
||||
r0 = 0; \
|
||||
exit; \
|
||||
" ::: __clobber_all);
|
||||
}
|
||||
|
||||
#define ARR_SZ 1000000
|
||||
int zero;
|
||||
char arr[ARR_SZ];
|
||||
|
Loading…
x
Reference in New Issue
Block a user