Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Enable timed may_goto tests for arm64

As arm64 JIT now supports timed may_goto instruction, make sure all
relevant tests run on this architecture. Some tests were enabled and
other required modifications to work properly on arm64.

$ ./test_progs -a "stream*","*may_goto*",verifier_bpf_fastcall

#404 stream_errors:OK
[...]
#406/2 stream_success/stream_cond_break:OK
[...]
#494/23 verifier_bpf_fastcall/may_goto_interaction_x86_64:SKIP
#494/24 verifier_bpf_fastcall/may_goto_interaction_arm64:OK
[...]
#539/1 verifier_may_goto_1/may_goto 0:OK
#539/2 verifier_may_goto_1/batch 2 of may_goto 0:OK
#539/3 verifier_may_goto_1/may_goto batch with offsets 2/1/0:OK
#539/4 verifier_may_goto_1/may_goto batch with offsets 2/0:OK
#539 verifier_may_goto_1:OK
#540/1 verifier_may_goto_2/C code with may_goto 0:OK
#540 verifier_may_goto_2:OK
Summary: 7/16 PASSED, 25 SKIPPED, 0 FAILED

Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Acked-by: Xu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/r/20250827113245.52629-3-puranjay@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Puranjay Mohan and committed by
Alexei Starovoitov
22b22bf9 16175375

+23 -40
+1 -1
tools/testing/selftests/bpf/prog_tests/stream.c
··· 77 77 ASSERT_OK(ret, "ret"); 78 78 ASSERT_OK(opts.retval, "retval"); 79 79 80 - #if !defined(__x86_64__) && !defined(__s390x__) 80 + #if !defined(__x86_64__) && !defined(__s390x__) && !defined(__aarch64__) 81 81 ASSERT_TRUE(1, "Timed may_goto unsupported, skip."); 82 82 if (i == 0) { 83 83 ret = bpf_prog_stream_read(prog_fd, 2, buf, sizeof(buf), &ropts);
+16 -11
tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
··· 660 660 661 661 SEC("raw_tp") 662 662 __arch_arm64 663 - __log_level(4) __msg("stack depth 16") 664 - /* may_goto counter at -16 */ 665 - __xlated("0: *(u64 *)(r10 -16) =") 666 - __xlated("1: r1 = 1") 667 - __xlated("2: call bpf_get_smp_processor_id") 663 + __log_level(4) __msg("stack depth 24") 664 + /* may_goto counter at -24 */ 665 + __xlated("0: *(u64 *)(r10 -24) =") 666 + /* may_goto timestamp at -16 */ 667 + __xlated("1: *(u64 *)(r10 -16) =") 668 + __xlated("2: r1 = 1") 669 + __xlated("3: call bpf_get_smp_processor_id") 668 670 /* may_goto expansion starts */ 669 - __xlated("3: r11 = *(u64 *)(r10 -16)") 670 - __xlated("4: if r11 == 0x0 goto pc+3") 671 - __xlated("5: r11 -= 1") 672 - __xlated("6: *(u64 *)(r10 -16) = r11") 671 + __xlated("4: r11 = *(u64 *)(r10 -24)") 672 + __xlated("5: if r11 == 0x0 goto pc+6") 673 + __xlated("6: r11 -= 1") 674 + __xlated("7: if r11 != 0x0 goto pc+2") 675 + __xlated("8: r11 = -24") 676 + __xlated("9: call unknown") 677 + __xlated("10: *(u64 *)(r10 -24) = r11") 673 678 /* may_goto expansion ends */ 674 - __xlated("7: *(u64 *)(r10 -8) = r1") 675 - __xlated("8: exit") 679 + __xlated("11: *(u64 *)(r10 -8) = r1") 680 + __xlated("12: exit") 676 681 __success 677 682 __naked void may_goto_interaction_arm64(void) 678 683 {
+6 -28
tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
··· 10 10 __description("may_goto 0") 11 11 __arch_x86_64 12 12 __arch_s390x 13 + __arch_arm64 13 14 __xlated("0: r0 = 1") 14 15 __xlated("1: exit") 15 16 __success ··· 30 29 __description("batch 2 of may_goto 0") 31 30 __arch_x86_64 32 31 __arch_s390x 32 + __arch_arm64 33 33 __xlated("0: r0 = 1") 34 34 __xlated("1: exit") 35 35 __success ··· 52 50 __description("may_goto batch with offsets 2/1/0") 53 51 __arch_x86_64 54 52 __arch_s390x 53 + __arch_arm64 55 54 __xlated("0: r0 = 1") 56 55 __xlated("1: exit") 57 56 __success ··· 75 72 } 76 73 77 74 SEC("raw_tp") 78 - __description("may_goto batch with offsets 2/0 - x86_64 and s390x") 75 + __description("may_goto batch with offsets 2/0") 79 76 __arch_x86_64 80 77 __arch_s390x 78 + __arch_arm64 81 79 __xlated("0: *(u64 *)(r10 -16) = 65535") 82 80 __xlated("1: *(u64 *)(r10 -8) = 0") 83 81 __xlated("2: r11 = *(u64 *)(r10 -16)") ··· 92 88 __xlated("10: r0 = 2") 93 89 __xlated("11: exit") 94 90 __success 95 - __naked void may_goto_batch_2_x86_64_s390x(void) 96 - { 97 - asm volatile ( 98 - ".8byte %[may_goto1];" 99 - ".8byte %[may_goto3];" 100 - "r0 = 1;" 101 - "r0 = 2;" 102 - "exit;" 103 - : 104 - : __imm_insn(may_goto1, BPF_RAW_INSN(BPF_JMP | BPF_JCOND, 0, 0, 2 /* offset */, 0)), 105 - __imm_insn(may_goto3, BPF_RAW_INSN(BPF_JMP | BPF_JCOND, 0, 0, 0 /* offset */, 0)) 106 - : __clobber_all); 107 - } 108 - 109 - SEC("raw_tp") 110 - __description("may_goto batch with offsets 2/0 - arm64") 111 - __arch_arm64 112 - __xlated("0: *(u64 *)(r10 -8) = 8388608") 113 - __xlated("1: r11 = *(u64 *)(r10 -8)") 114 - __xlated("2: if r11 == 0x0 goto pc+3") 115 - __xlated("3: r11 -= 1") 116 - __xlated("4: *(u64 *)(r10 -8) = r11") 117 - __xlated("5: r0 = 1") 118 - __xlated("6: r0 = 2") 119 - __xlated("7: exit") 120 - __success 121 - __naked void may_goto_batch_2_arm64(void) 91 + __naked void may_goto_batch_2(void) 122 92 { 123 93 asm volatile ( 124 94 ".8byte %[may_goto1];"