From: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, kernel-team@meta.com, eddyz87@gmail.com,
memxor@gmail.com
Cc: Mykyta Yatsenko <yatsenko@meta.com>
Subject: [PATCH bpf-next v2 2/2] selftests/bpf: Test JIT jumps which change at a repeated image length
Date: Thu, 22 Oct 2026 05:04:56 -0700 [thread overview]
Message-ID: <20261022-jit_size_fix-v2-2-4bee6921b218@meta.com> (raw)
In-Reply-To: <20261022-jit_size_fix-v2-0-4bee6921b218@meta.com>
From: Mykyta Yatsenko <yatsenko@meta.com>
Cover the case where two JIT passes give the same image length while
jumps still change size, which used to fail with -ENOTSUPP on x86-64.
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
tools/testing/selftests/bpf/prog_tests/jit_insns.c | 59 ++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/jit_insns.c b/tools/testing/selftests/bpf/prog_tests/jit_insns.c
index dabefdb8a353..52bffe27199b 100644
--- a/tools/testing/selftests/bpf/prog_tests/jit_insns.c
+++ b/tools/testing/selftests/bpf/prog_tests/jit_insns.c
@@ -2881,6 +2881,63 @@ static void test_convergence(void)
}
}
+/*
+ * On x86-64 a backward jump sized from its own previous-pass address grew
+ * here while others shrank, so two passes gave the same image length with
+ * jumps still changing. The fillers are 7 and 2 bytes of native code, the
+ * conditional jumps are never taken.
+ */
+static void test_same_len_not_converged(void)
+{
+ struct bpf_insn insns[] = {
+ BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, IN0),
+ BPF_LDX_MEM(BPF_DW, BPF_REG_4, BPF_REG_1, IN1),
+ BPF_JMP_IMM(BPF_JA, 0, 0, 1),
+ BPF_JMP_IMM(BPF_JA, 0, 0, 29),
+ BPF_JMP32_REG(BPF_JEQ, BPF_REG_0, BPF_REG_4, 20),
+ BPF_JMP32_REG(BPF_JEQ, BPF_REG_0, BPF_REG_4, -3),
+ BPF_JMP32_REG(BPF_JEQ, BPF_REG_0, BPF_REG_4, 22),
+ BPF_JMP32_REG(BPF_JEQ, BPF_REG_0, BPF_REG_4, 2),
+ BPF_MOV32_IMM(BPF_REG_2, 0),
+ BPF_JMP32_REG(BPF_JEQ, BPF_REG_0, BPF_REG_4, 23),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV32_IMM(BPF_REG_2, 0),
+ BPF_JMP_IMM(BPF_JA, 0, 0, -22),
+ BPF_MOV64_IMM(BPF_REG_2, -1),
+ BPF_MOV32_IMM(BPF_REG_2, 0),
+ BPF_MOV32_IMM(BPF_REG_2, 0),
+ BPF_JMP32_REG(BPF_JEQ, BPF_REG_0, BPF_REG_4, 3),
+ BPF_MOV32_IMM(BPF_REG_2, 0),
+ BPF_JMP32_REG(BPF_JEQ, BPF_REG_0, BPF_REG_4, 2),
+ BPF_JMP_IMM(BPF_JA, 0, 0, -22),
+ BPF_MOV32_IMM(BPF_REG_2, 0),
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 10),
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, RES),
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_EXIT_INSN(),
+ };
+ int fd;
+
+ fd = load_prog(insns, ARRAY_SIZE(insns), "same len not converged");
+ if (fd < 0)
+ return;
+ ASSERT_GT(jited_len(fd), 0, "same len not converged jited");
+ prog_run(fd, 1, 2, 11, "same len not converged");
+ close(fd);
+}
+
/*
* Calls into a subprogram with all five arguments, which clobbers a subset
* of r6-r9 and uses the deepest stack slot the budget leaves, directly or
@@ -3087,6 +3144,8 @@ void test_jit_insns(void)
test_max_jmp();
if (test__start_subtest("convergence"))
test_convergence();
+ if (test__start_subtest("same_len_not_converged"))
+ test_same_len_not_converged();
if (test__start_subtest("calls"))
test_calls();
if (test__start_subtest("helper_calls"))
--
2.53.0-Meta
next prev parent reply other threads:[~2026-10-22 12:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 12:04 [PATCH bpf-next v2 0/2] bpf: Fix x86 JIT stopping before jumps converge Mykyta Yatsenko
2026-10-22 12:04 ` [PATCH bpf-next v2 1/2] bpf: Size backward jumps by the insns they jump over Mykyta Yatsenko
2026-10-22 13:18 ` Daniel Borkmann
2026-10-22 12:04 ` Mykyta Yatsenko [this message]
2026-10-22 12:44 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test JIT jumps which change at a repeated image length bot+bpf-ci
2026-10-22 13:05 ` Mykyta Yatsenko
2026-10-22 13:24 ` Daniel Borkmann
2026-10-22 13:21 ` Daniel Borkmann
2026-10-24 4:00 ` [PATCH bpf-next v2 0/2] bpf: Fix x86 JIT stopping before jumps converge patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022-jit_size_fix-v2-2-4bee6921b218@meta.com \
--to=mykyta.yatsenko5@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.com \
--cc=memxor@gmail.com \
--cc=yatsenko@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox