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

selftests/bpf: verifier/xdp.c converted to inline assembly

Test verifier/xdp.c automatically converted to use inline assembly.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20230325025524.144043-43-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Eduard Zingerman and committed by
Alexei Starovoitov
ffb515c9 a8036aea

+26 -14
+2
tools/testing/selftests/bpf/prog_tests/verifier.c
··· 39 39 #include "verifier_value_or_null.skel.h" 40 40 #include "verifier_var_off.skel.h" 41 41 #include "verifier_xadd.skel.h" 42 + #include "verifier_xdp.skel.h" 42 43 43 44 __maybe_unused 44 45 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory) ··· 101 100 void test_verifier_value_or_null(void) { RUN(verifier_value_or_null); } 102 101 void test_verifier_var_off(void) { RUN(verifier_var_off); } 103 102 void test_verifier_xadd(void) { RUN(verifier_xadd); } 103 + void test_verifier_xdp(void) { RUN(verifier_xdp); }
+24
tools/testing/selftests/bpf/progs/verifier_xdp.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Converted from tools/testing/selftests/bpf/verifier/xdp.c */ 3 + 4 + #include <linux/bpf.h> 5 + #include <bpf/bpf_helpers.h> 6 + #include "bpf_misc.h" 7 + 8 + SEC("xdp") 9 + __description("XDP, using ifindex from netdev") 10 + __success __retval(1) 11 + __naked void xdp_using_ifindex_from_netdev(void) 12 + { 13 + asm volatile (" \ 14 + r0 = 0; \ 15 + r2 = *(u32*)(r1 + %[xdp_md_ingress_ifindex]); \ 16 + if r2 < 1 goto l0_%=; \ 17 + r0 = 1; \ 18 + l0_%=: exit; \ 19 + " : 20 + : __imm_const(xdp_md_ingress_ifindex, offsetof(struct xdp_md, ingress_ifindex)) 21 + : __clobber_all); 22 + } 23 + 24 + char _license[] SEC("license") = "GPL";
-14
tools/testing/selftests/bpf/verifier/xdp.c
··· 1 - { 2 - "XDP, using ifindex from netdev", 3 - .insns = { 4 - BPF_MOV64_IMM(BPF_REG_0, 0), 5 - BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 6 - offsetof(struct xdp_md, ingress_ifindex)), 7 - BPF_JMP_IMM(BPF_JLT, BPF_REG_2, 1, 1), 8 - BPF_MOV64_IMM(BPF_REG_0, 1), 9 - BPF_EXIT_INSN(), 10 - }, 11 - .result = ACCEPT, 12 - .prog_type = BPF_PROG_TYPE_XDP, 13 - .retval = 1, 14 - },