Skip to content

Commit 2673315

Browse files
Alexei Starovoitovborkmann
Alexei Starovoitov
authored andcommitted
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 5337ac4 commit 2673315

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,100 @@ int iter_limit_bug(struct __sk_buff *skb)
307307
return 0;
308308
}
309309

310+
SEC("socket")
311+
__success __retval(0)
312+
__naked void ja_and_may_goto(void)
313+
{
314+
asm volatile (" \
315+
l0_%=: .byte 0xe5; /* may_goto */ \
316+
.byte 0; /* regs */ \
317+
.short 1; /* off 1 */ \
318+
.long 0; /* imm */ \
319+
goto l0_%=; \
320+
r0 = 0; \
321+
exit; \
322+
" ::: __clobber_common);
323+
}
324+
325+
SEC("socket")
326+
__success __retval(0)
327+
__naked void ja_and_may_goto2(void)
328+
{
329+
asm volatile (" \
330+
l0_%=: r0 = 0; \
331+
.byte 0xe5; /* may_goto */ \
332+
.byte 0; /* regs */ \
333+
.short 1; /* off 1 */ \
334+
.long 0; /* imm */ \
335+
goto l0_%=; \
336+
r0 = 0; \
337+
exit; \
338+
" ::: __clobber_common);
339+
}
340+
341+
SEC("socket")
342+
__success __retval(0)
343+
__naked void jlt_and_may_goto(void)
344+
{
345+
asm volatile (" \
346+
l0_%=: call %[bpf_jiffies64]; \
347+
.byte 0xe5; /* may_goto */ \
348+
.byte 0; /* regs */ \
349+
.short 1; /* off 1 */ \
350+
.long 0; /* imm */ \
351+
if r0 < 10 goto l0_%=; \
352+
r0 = 0; \
353+
exit; \
354+
" :: __imm(bpf_jiffies64)
355+
: __clobber_all);
356+
}
357+
358+
#if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
359+
(defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
360+
defined(__TARGET_ARCH_arm) || defined(__TARGET_ARCH_s390) || \
361+
defined(__TARGET_ARCH_loongarch)) && \
362+
__clang_major__ >= 18
363+
SEC("socket")
364+
__success __retval(0)
365+
__naked void gotol_and_may_goto(void)
366+
{
367+
asm volatile (" \
368+
l0_%=: r0 = 0; \
369+
.byte 0xe5; /* may_goto */ \
370+
.byte 0; /* regs */ \
371+
.short 1; /* off 1 */ \
372+
.long 0; /* imm */ \
373+
gotol l0_%=; \
374+
r0 = 0; \
375+
exit; \
376+
" ::: __clobber_common);
377+
}
378+
#endif
379+
380+
SEC("socket")
381+
__success __retval(0)
382+
__naked void ja_and_may_goto_subprog(void)
383+
{
384+
asm volatile (" \
385+
call subprog_with_may_goto; \
386+
exit; \
387+
" ::: __clobber_all);
388+
}
389+
390+
static __naked __noinline __used
391+
void subprog_with_may_goto(void)
392+
{
393+
asm volatile (" \
394+
l0_%=: .byte 0xe5; /* may_goto */ \
395+
.byte 0; /* regs */ \
396+
.short 1; /* off 1 */ \
397+
.long 0; /* imm */ \
398+
goto l0_%=; \
399+
r0 = 0; \
400+
exit; \
401+
" ::: __clobber_all);
402+
}
403+
310404
#define ARR_SZ 1000000
311405
int zero;
312406
char arr[ARR_SZ];

0 commit comments

Comments
 (0)