selftests/bpf: Rewrite two infinite loops in bound check cases

The two infinite loops in bound check cases added by commit
1a3148fc17 ("selftests/bpf: Check when bounds are not in the 32-bit range")
increased the execution time of test_verifier from about 6 seconds to
about 9 seconds. Rewrite these two infinite loops to finite loops to get
rid of this extra time cost.

Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/r/20230329011048.1721937-1-xukuohai@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Xu Kuohai 2023-03-28 21:10:48 -04:00 committed by Alexei Starovoitov
parent 8a9abe0293
commit 4ca13d1002

View File

@ -784,22 +784,26 @@
BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data_end)),
BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 1),
BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 8),
BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 13),
BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_2, 0),
BPF_LD_IMM64(BPF_REG_0, 0x7fffffffffffff10),
BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
BPF_LD_IMM64(BPF_REG_2, 0x8000000000000fff),
BPF_LD_IMM64(BPF_REG_0, 0x8000000000000000),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
BPF_JMP_REG(BPF_JSGT, BPF_REG_0, BPF_REG_2, 3),
/* r1 signed range is [S64_MIN, S64_MAX] */
BPF_JMP_REG(BPF_JSLT, BPF_REG_0, BPF_REG_1, -2),
BPF_JMP_REG(BPF_JSLT, BPF_REG_0, BPF_REG_1, -3),
BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
},
.errstr = "BPF program is too large",
.result = REJECT,
.result = ACCEPT,
.prog_type = BPF_PROG_TYPE_XDP,
},
{
@ -856,21 +860,25 @@
BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_1, offsetof(struct xdp_md, data_end)),
BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 1),
BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 6),
BPF_JMP_REG(BPF_JGT, BPF_REG_1, BPF_REG_3, 10),
BPF_LDX_MEM(BPF_B, BPF_REG_1, BPF_REG_2, 0),
BPF_MOV32_IMM(BPF_REG_0, 0x7fffff10),
BPF_ALU32_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
BPF_MOV32_IMM(BPF_REG_2, 0x80000fff),
BPF_MOV32_IMM(BPF_REG_0, 0x80000000),
BPF_ALU32_IMM(BPF_ADD, BPF_REG_0, 1),
BPF_JMP32_REG(BPF_JSGT, BPF_REG_0, BPF_REG_2, 3),
/* r1 signed range is [S32_MIN, S32_MAX] */
BPF_JMP32_REG(BPF_JSLT, BPF_REG_0, BPF_REG_1, -2),
BPF_JMP32_REG(BPF_JSLT, BPF_REG_0, BPF_REG_1, -3),
BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(),
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
},
.errstr = "BPF program is too large",
.result = REJECT,
.result = ACCEPT,
.prog_type = BPF_PROG_TYPE_XDP,
},