summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/verifier/jit.c
blob: c33adf344faeb3f70706358cbe782e29cd0acdf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
	"jit: lsh, rsh, arsh by 1",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_MOV64_IMM(BPF_REG_1, 0xff),
	BPF_ALU64_IMM(BPF_LSH, BPF_REG_1, 1),
	BPF_ALU32_IMM(BPF_LSH, BPF_REG_1, 1),
	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0x3fc, 1),
	BPF_EXIT_INSN(),
	BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 1),
	BPF_ALU32_IMM(BPF_RSH, BPF_REG_1, 1),
	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0xff, 1),
	BPF_EXIT_INSN(),
	BPF_ALU64_IMM(BPF_ARSH, BPF_REG_1, 1),
	BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0x7f, 1),
	BPF_EXIT_INSN(),
	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_EXIT_INSN(),
	},
	.result = ACCEPT,
	.retval = 2,
},
{
	"jit: mov32 for ldimm64, 1",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_LD_IMM64(BPF_REG_1, 0xfeffffffffffffffULL),
	BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 32),
	BPF_LD_IMM64(BPF_REG_2, 0xfeffffffULL),
	BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	},
	.result = ACCEPT,
	.retval = 2,
},
{
	"jit: mov32 for ldimm64, 2",
	.insns = {
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_LD_IMM64(BPF_REG_1, 0x1ffffffffULL),
	BPF_LD_IMM64(BPF_REG_2, 0xffffffffULL),
	BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_EXIT_INSN(),
	},
	.result = ACCEPT,
	.retval = 2,
},
{
	"jit: various mul tests",
	.insns = {
	BPF_LD_IMM64(BPF_REG_2, 0xeeff0d413122ULL),
	BPF_LD_IMM64(BPF_REG_0, 0xfefefeULL),
	BPF_LD_IMM64(BPF_REG_1, 0xefefefULL),
	BPF_ALU64_REG(BPF_MUL, BPF_REG_0, BPF_REG_1),
	BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 2),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	BPF_LD_IMM64(BPF_REG_3, 0xfefefeULL),
	BPF_ALU64_REG(BPF_MUL, BPF_REG_3, BPF_REG_1),
	BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	BPF_MOV32_REG(BPF_REG_2, BPF_REG_2),
	BPF_LD_IMM64(BPF_REG_0, 0xfefefeULL),
	BPF_ALU32_REG(BPF_MUL, BPF_REG_0, BPF_REG_1),
	BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 2),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	BPF_LD_IMM64(BPF_REG_3, 0xfefefeULL),
	BPF_ALU32_REG(BPF_MUL, BPF_REG_3, BPF_REG_1),
	BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	BPF_LD_IMM64(BPF_REG_0, 0x952a7bbcULL),
	BPF_LD_IMM64(BPF_REG_1, 0xfefefeULL),
	BPF_LD_IMM64(BPF_REG_2, 0xeeff0d413122ULL),
	BPF_ALU32_REG(BPF_MUL, BPF_REG_2, BPF_REG_1),
	BPF_JMP_REG(BPF_JEQ, BPF_REG_2, BPF_REG_0, 2),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),
	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_EXIT_INSN(),
	},
	.result = ACCEPT,
	.retval = 2,
},
{
	"jit: jsgt, jslt",
	.insns = {
	BPF_LD_IMM64(BPF_REG_1, 0x80000000ULL),
	BPF_LD_IMM64(BPF_REG_2, 0x0ULL),
	BPF_JMP_REG(BPF_JSGT, BPF_REG_1, BPF_REG_2, 2),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),

	BPF_JMP_REG(BPF_JSLT, BPF_REG_2, BPF_REG_1, 2),
	BPF_MOV64_IMM(BPF_REG_0, 1),
	BPF_EXIT_INSN(),

	BPF_MOV64_IMM(BPF_REG_0, 2),
	BPF_EXIT_INSN(),
	},
	.result = ACCEPT,
	.retval = 2,
},