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

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Test access from RO map from xdp_store_bytes

This new test simply checks that helper bpf_xdp_store_bytes can
successfully read from a read-only map.

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Link: https://lore.kernel.org/r/4fdb934a713b2d7cf133288c77f6cfefe9856440.1769875479.git.paul.chaignon@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Paul Chaignon and committed by
Alexei Starovoitov
f0b5b3d6 6557f156

+35
+35
tools/testing/selftests/bpf/progs/verifier_xdp.c
··· 5 5 #include <bpf/bpf_helpers.h> 6 6 #include "bpf_misc.h" 7 7 8 + struct { 9 + __uint(type, BPF_MAP_TYPE_ARRAY); 10 + __uint(max_entries, 1); 11 + __type(key, int); 12 + __type(value, __u64); 13 + __uint(map_flags, BPF_F_RDONLY_PROG); 14 + } map_array_ro SEC(".maps"); 15 + 8 16 SEC("xdp") 9 17 __description("XDP, using ifindex from netdev") 10 18 __success __retval(1) ··· 26 18 l0_%=: exit; \ 27 19 " : 28 20 : __imm_const(xdp_md_ingress_ifindex, offsetof(struct xdp_md, ingress_ifindex)) 21 + : __clobber_all); 22 + } 23 + 24 + SEC("xdp") 25 + __description("XDP, using xdp_store_bytes from RO map") 26 + __success __retval(0) 27 + __naked void xdp_store_bytes_from_ro_map(void) 28 + { 29 + asm volatile (" \ 30 + r6 = r1; \ 31 + r1 = 0; \ 32 + *(u64*)(r10 - 8) = r1; \ 33 + r2 = r10; \ 34 + r2 += -8; \ 35 + r1 = %[map_array_ro] ll; \ 36 + call %[bpf_map_lookup_elem]; \ 37 + if r0 == 0 goto l0_%=; \ 38 + r1 = r6; \ 39 + r2 = 0; \ 40 + r3 = r0; \ 41 + r4 = 8; \ 42 + call %[bpf_xdp_store_bytes]; \ 43 + l0_%=: exit; \ 44 + " : 45 + : __imm(bpf_map_lookup_elem), 46 + __imm(bpf_xdp_store_bytes), 47 + __imm_addr(map_array_ro) 29 48 : __clobber_all); 30 49 } 31 50