xref: /openbmc/linux/tools/testing/selftests/bpf/verifier/precise.c (revision e8c13c4d9b36065903a025f163db87a7afff7307)
1*e8c13c4dSAlexei Starovoitov {
2*e8c13c4dSAlexei Starovoitov 	"precise: test 1",
3*e8c13c4dSAlexei Starovoitov 	.insns = {
4*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_0, 1),
5*e8c13c4dSAlexei Starovoitov 	BPF_LD_MAP_FD(BPF_REG_6, 0),
6*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
7*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_FP),
8*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
9*e8c13c4dSAlexei Starovoitov 	BPF_ST_MEM(BPF_DW, BPF_REG_FP, -8, 0),
10*e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
11*e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
12*e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
13*e8c13c4dSAlexei Starovoitov 
14*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_9, BPF_REG_0),
15*e8c13c4dSAlexei Starovoitov 
16*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
17*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_FP),
18*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
19*e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
20*e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
21*e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
22*e8c13c4dSAlexei Starovoitov 
23*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_8, BPF_REG_0),
24*e8c13c4dSAlexei Starovoitov 
25*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_REG(BPF_SUB, BPF_REG_9, BPF_REG_8), /* map_value_ptr -= map_value_ptr */
26*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_9),
27*e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JLT, BPF_REG_2, 8, 1),
28*e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
29*e8c13c4dSAlexei Starovoitov 
30*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1), /* R2=inv(umin=1, umax=8) */
31*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_FP),
32*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
33*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_3, 0),
34*e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_probe_read),
35*e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
36*e8c13c4dSAlexei Starovoitov 	},
37*e8c13c4dSAlexei Starovoitov 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
38*e8c13c4dSAlexei Starovoitov 	.fixup_map_array_48b = { 1 },
39*e8c13c4dSAlexei Starovoitov 	.result = VERBOSE_ACCEPT,
40*e8c13c4dSAlexei Starovoitov 	.errstr =
41*e8c13c4dSAlexei Starovoitov 	"26: (85) call bpf_probe_read#4\
42*e8c13c4dSAlexei Starovoitov 	last_idx 26 first_idx 20\
43*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 25\
44*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 24\
45*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 23\
46*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 22\
47*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 20\
48*e8c13c4dSAlexei Starovoitov 	parent didn't have regs=4 stack=0 marks\
49*e8c13c4dSAlexei Starovoitov 	last_idx 19 first_idx 10\
50*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 19\
51*e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 18\
52*e8c13c4dSAlexei Starovoitov 	regs=300 stack=0 before 17\
53*e8c13c4dSAlexei Starovoitov 	regs=201 stack=0 before 15\
54*e8c13c4dSAlexei Starovoitov 	regs=201 stack=0 before 14\
55*e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 13\
56*e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 12\
57*e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 11\
58*e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 10\
59*e8c13c4dSAlexei Starovoitov 	parent already had regs=0 stack=0 marks",
60*e8c13c4dSAlexei Starovoitov },
61*e8c13c4dSAlexei Starovoitov {
62*e8c13c4dSAlexei Starovoitov 	"precise: test 2",
63*e8c13c4dSAlexei Starovoitov 	.insns = {
64*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_0, 1),
65*e8c13c4dSAlexei Starovoitov 	BPF_LD_MAP_FD(BPF_REG_6, 0),
66*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
67*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_FP),
68*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
69*e8c13c4dSAlexei Starovoitov 	BPF_ST_MEM(BPF_DW, BPF_REG_FP, -8, 0),
70*e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
71*e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
72*e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
73*e8c13c4dSAlexei Starovoitov 
74*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_9, BPF_REG_0),
75*e8c13c4dSAlexei Starovoitov 
76*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
77*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_FP),
78*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
79*e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
80*e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
81*e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
82*e8c13c4dSAlexei Starovoitov 
83*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_8, BPF_REG_0),
84*e8c13c4dSAlexei Starovoitov 
85*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_REG(BPF_SUB, BPF_REG_9, BPF_REG_8), /* map_value_ptr -= map_value_ptr */
86*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_2, BPF_REG_9),
87*e8c13c4dSAlexei Starovoitov 	BPF_JMP_IMM(BPF_JLT, BPF_REG_2, 8, 1),
88*e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
89*e8c13c4dSAlexei Starovoitov 
90*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1), /* R2=inv(umin=1, umax=8) */
91*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_REG(BPF_REG_1, BPF_REG_FP),
92*e8c13c4dSAlexei Starovoitov 	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
93*e8c13c4dSAlexei Starovoitov 	BPF_MOV64_IMM(BPF_REG_3, 0),
94*e8c13c4dSAlexei Starovoitov 	BPF_EMIT_CALL(BPF_FUNC_probe_read),
95*e8c13c4dSAlexei Starovoitov 	BPF_EXIT_INSN(),
96*e8c13c4dSAlexei Starovoitov 	},
97*e8c13c4dSAlexei Starovoitov 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
98*e8c13c4dSAlexei Starovoitov 	.fixup_map_array_48b = { 1 },
99*e8c13c4dSAlexei Starovoitov 	.result = VERBOSE_ACCEPT,
100*e8c13c4dSAlexei Starovoitov 	.flags = BPF_F_TEST_STATE_FREQ,
101*e8c13c4dSAlexei Starovoitov 	.errstr =
102*e8c13c4dSAlexei Starovoitov 	"26: (85) call bpf_probe_read#4\
103*e8c13c4dSAlexei Starovoitov 	last_idx 26 first_idx 22\
104*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 25\
105*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 24\
106*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 23\
107*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 22\
108*e8c13c4dSAlexei Starovoitov 	parent didn't have regs=4 stack=0 marks\
109*e8c13c4dSAlexei Starovoitov 	last_idx 20 first_idx 20\
110*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 20\
111*e8c13c4dSAlexei Starovoitov 	parent didn't have regs=4 stack=0 marks\
112*e8c13c4dSAlexei Starovoitov 	last_idx 19 first_idx 17\
113*e8c13c4dSAlexei Starovoitov 	regs=4 stack=0 before 19\
114*e8c13c4dSAlexei Starovoitov 	regs=200 stack=0 before 18\
115*e8c13c4dSAlexei Starovoitov 	regs=300 stack=0 before 17\
116*e8c13c4dSAlexei Starovoitov 	parent already had regs=0 stack=0 marks",
117*e8c13c4dSAlexei Starovoitov },
118