BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/2] bpf: Fix x86 JIT stopping before jumps converge
@ 2026-10-22 12:04 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
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Mykyta Yatsenko @ 2026-10-22 12:04 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kernel-team, eddyz87, memxor; +Cc: Mykyta Yatsenko

The x86 JIT stops its sizing passes once two passes give the same image
length. A backward jump can grow while other jumps shrink, so the length
may repeat with jump sizes still changing. The final pass then emits code
of a different size than was sized, hits "bpf_jit: fatal error" and the
program fails to load with -ENOTSUPP.

Patch 1 sizes backward jumps by the insns they jump over, so no insn
grows between passes and a repeated length means nothing moved.
Patch 2 adds a selftest which fails to load without the fix.

This was hit in CI by cgroup_tcp_skb with the unpublished branch
inversion series, whose layout change happened to trigger it.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
Changes in v2:
- Size backward jumps by the insns they jump over instead of checking
  for moved insns, drop the ja -1 special case and the imm8 limit of 123
  (Alexei)
- Start every insn at BPF_MAX_INSN_SIZE, so none grows in the first pass
- Check that the selftest program is JITed
- Link to v1: https://patch.msgid.link/20261021-jit_size_fix-v1-0-b89fd32cafd6@meta.com

---
Mykyta Yatsenko (2):
      bpf: Size backward jumps by the insns they jump over
      selftests/bpf: Test JIT jumps which change at a repeated image length

 arch/x86/net/bpf_jit_comp.c                        | 109 ++++++---------------
 tools/testing/selftests/bpf/prog_tests/jit_insns.c |  59 +++++++++++
 2 files changed, 90 insertions(+), 78 deletions(-)
---
base-commit: 65953903cd7bce4c4392ad6ab629cba78f24644e
change-id: 20261021-jit_size_fix-da316b8d492c

Best regards,
--  
Mykyta Yatsenko <yatsenko@meta.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-10-24  4:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test JIT jumps which change at a repeated image length Mykyta Yatsenko
2026-10-22 12:44   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox