Skip to content

Commit 02ea80b

Browse files
borkmanndavem330
authored andcommitted
bpf: add various verifier test cases for self-tests
Add a couple of test cases, for example, probing for xadd on a spilled pointer to packet and map_value_adj register, various other map_value_adj tests including the unaligned load/store, and trying out pointer arithmetic on map_value_adj register itself. For the unaligned load/store, we need to figure out whether the architecture has efficient unaligned access and need to mark affected tests accordingly. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 79adffc commit 02ea80b

3 files changed

Lines changed: 283 additions & 6 deletions

File tree

‎tools/include/linux/filter.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@
168168
.off = OFF, \
169169
.imm = 0 })
170170

171+
/* Atomic memory add, *(uint *)(dst_reg + off16) += src_reg */
172+
173+
#define BPF_STX_XADD(SIZE, DST, SRC, OFF) \
174+
((struct bpf_insn) { \
175+
.code = BPF_STX | BPF_SIZE(SIZE) | BPF_XADD, \
176+
.dst_reg = DST, \
177+
.src_reg = SRC, \
178+
.off = OFF, \
179+
.imm = 0 })
180+
171181
/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
172182

173183
#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \

‎tools/testing/selftests/bpf/Makefile‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
LIBDIR := ../../../lib
22
BPFDIR := $(LIBDIR)/bpf
3+
APIDIR := ../../../include/uapi
4+
GENDIR := ../../../../include/generated
5+
GENHDR := $(GENDIR)/autoconf.h
36

4-
CFLAGS += -Wall -O2 -I../../../include/uapi -I$(LIBDIR)
7+
ifneq ($(wildcard $(GENHDR)),)
8+
GENFLAGS := -DHAVE_GENHDR
9+
endif
10+
11+
CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS)
512
LDLIBS += -lcap
613

714
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map

0 commit comments

Comments
 (0)