* [PATCH bpf-next v2] selftests/bpf: Rewrite two infinite loops in bound check cases
@ 2023-03-29 1:10 Xu Kuohai
2023-03-30 0:28 ` Alexei Starovoitov
2023-03-30 0:30 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Xu Kuohai @ 2023-03-29 1:10 UTC (permalink / raw)
To: bpf, linux-kselftest; +Cc: Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann
From: Xu Kuohai <xukuohai@huawei.com>
The two infinite loops in bound check cases added by commit
1a3148fc171f ("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>
---
v2:
- rewrite the infinite loops to finite loops instead of removing the
test cases
v1: https://lore.kernel.org/bpf/20230327153538.850440-1-xukuohai@huaweicloud.com/
---
tools/testing/selftests/bpf/verifier/bounds.c | 24 ++++++++++++-------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/bpf/verifier/bounds.c b/tools/testing/selftests/bpf/verifier/bounds.c
index 74b1917d4208..43942ce8cf15 100644
--- a/tools/testing/selftests/bpf/verifier/bounds.c
+++ b/tools/testing/selftests/bpf/verifier/bounds.c
@@ -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,
},
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] selftests/bpf: Rewrite two infinite loops in bound check cases
2023-03-29 1:10 [PATCH bpf-next v2] selftests/bpf: Rewrite two infinite loops in bound check cases Xu Kuohai
@ 2023-03-30 0:28 ` Alexei Starovoitov
2023-03-30 0:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2023-03-30 0:28 UTC (permalink / raw)
To: Xu Kuohai
Cc: bpf, open list:KERNEL SELFTEST FRAMEWORK, Andrii Nakryiko,
Alexei Starovoitov, Daniel Borkmann
On Tue, Mar 28, 2023 at 5:11 AM Xu Kuohai <xukuohai@huaweicloud.com> wrote:
>
> From: Xu Kuohai <xukuohai@huawei.com>
>
> The two infinite loops in bound check cases added by commit
> 1a3148fc171f ("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>
> ---
> v2:
> - rewrite the infinite loops to finite loops instead of removing the
> test cases
>
> v1: https://lore.kernel.org/bpf/20230327153538.850440-1-xukuohai@huaweicloud.com/
Thanks.
On my VM with debug kernel it went
from:
real 0m37.508s
user 0m0.382s
sys 0m36.555s
to:
real 0m14.547s
user 0m0.378s
sys 0m13.661s
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] selftests/bpf: Rewrite two infinite loops in bound check cases
2023-03-29 1:10 [PATCH bpf-next v2] selftests/bpf: Rewrite two infinite loops in bound check cases Xu Kuohai
2023-03-30 0:28 ` Alexei Starovoitov
@ 2023-03-30 0:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-30 0:30 UTC (permalink / raw)
To: Xu Kuohai; +Cc: bpf, linux-kselftest, andrii, ast, daniel
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Tue, 28 Mar 2023 21:10:48 -0400 you wrote:
> From: Xu Kuohai <xukuohai@huawei.com>
>
> The two infinite loops in bound check cases added by commit
> 1a3148fc171f ("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.
>
> [...]
Here is the summary with links:
- [bpf-next,v2] selftests/bpf: Rewrite two infinite loops in bound check cases
https://git.kernel.org/bpf/bpf-next/c/4ca13d1002f3
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-30 0:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 1:10 [PATCH bpf-next v2] selftests/bpf: Rewrite two infinite loops in bound check cases Xu Kuohai
2023-03-30 0:28 ` Alexei Starovoitov
2023-03-30 0:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).