[llvm] [BPF] Support Jump Table (PR #149715)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 2 08:43:45 PDT 2025
yonghong-song wrote:
@aspsk I just rebased on top of latest llvm-project main branch.
Based on discussion with @4ast, we will not introduce v5 at this moment. So jump table support will be in v4. The reason is that adding more and more versions are not scale.
With this llvm version, I tried with latest bpf-next with your current patch set
https://lore.kernel.org/bpf/20250816180631.952085-1-a.s.protopopov@gmail.com/T/#mbfb4fc7728228e74fd17c5147a64f21933b9987f
To build bpf selftest, I got the following libbpf warnings like
```
libbpf: elf: skipping unrecognized data section(6) .comment
libbpf: elf: skipping unrecognized data section(6) .comment
libbpf: elf: skipping section(7) .note.GNU-stack (size 0)
libbpf: elf: skipping section(7) .note.GNU-stack (size 0)
```
I did a hack like below
```
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 606d7d5a48a7..51e390eb7141 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -742,7 +742,7 @@ $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
# Define test_progs-cpuv4 test runner.
ifneq ($(CLANG_CPUV4),)
TRUNNER_BPF_BUILD_RULE := CLANG_CPUV4_BPF_BUILD_RULE
-TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
+TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS -mllvm -bpf-min-jump-table-entries=3
$(eval $(call DEFINE_TEST_RUNNER,test_progs,cpuv4))
endif
```
to allow jump table with switch cases 3 or above.
When running `test_progs-cpuv4 -j`, I got some failures like
```
libbpf: elf: skipping relo section(6) .rel.jumptables for section(5) .jumptables
libbpf: elf: skipping unrecognized data section(22) .comment
libbpf: elf: skipping section(23) .note.GNU-stack (size 0)
run_core_reloc_tests:PASS:obj_open 0 nsec
run_core_reloc_tests:PASS:find_probe 0 nsec
libbpf: prog 'test_core_bitfields_direct': BPF program load failed: -EINVAL
libbpf: prog 'test_core_bitfields_direct': -- BEGIN PROG LOAD LOG --
Failed to properly initialize insn array
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
-- END PROG LOAD LOG --
libbpf: prog 'test_core_bitfields_direct': failed to load: -EINVAL
libbpf: failed to load object 'test_core_reloc_bitfields_direct.bpf.o'
run_core_reloc_tests:FAIL:obj_load unexpected error: -22 (errno 22)
#84/50 core_reloc/direct:bitfields:FAIL
...
```
and a crash
```
[ 893.591003] BUG: kernel NULL pointer dereference, address: 0000000000000000
[ 893.591926] #PF: supervisor instruction fetch in kernel mode
[ 893.591926] #PF: error_code(0x0010) - not-present page
[ 893.591926] PGD 1084e8067 P4D 0
[ 893.591926] Oops: Oops: 0010 [#1] SMP KASAN NOPTI
[ 893.591926] CPU: 0 UID: 0 PID: 2014 Comm: test_progs-cpuv Tainted: G OE 6.17.0-rc1-g9fec31b21ada #55 PREEMP
[ 893.591926] Tainted: [O]=OOT_MODULE, [E]=UNSIGNED_MODULE
[ 893.591926] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/4
[ 893.591926] RIP: 0010:0x0
[ 893.591926] Code: Unable to access opcode bytes at 0xffffffffffffffd6.
[ 893.591926] RSP: 0018:ff1100011c54f9f0 EFLAGS: 00010286
[ 893.591926] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[ 893.591926] RDX: 0000000000000000 RSI: 0000000000000028 RDI: 0000000000000000
[ 893.591926] RBP: ff1100011c54fad0 R08: 0000000000000000 R09: ff1100011c54fc04
[ 893.591926] R10: dffffc0000000000 R11: ffffffffa000d44c R12: ffa000000026d030
[ 893.591926] R13: ff1100011c54fbc0 R14: ff1100011c54fc00 R15: ff110001086ae952
[ 893.591926] FS: 00007f40ab1730c0(0000) GS:ff11000238634000(0000) knlGS:0000000000000000
[ 893.591926] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 893.591926] CR2: ffffffffffffffd6 CR3: 000000011114f002 CR4: 0000000000371ef0
[ 893.591926] Call Trace:
[ 893.591926] <TASK>
[ 893.591926] ? __pfx___cant_migrate+0x10/0x10
[ 893.591926] ? __pfx___might_resched+0x10/0x10
[ 893.591926] ? srso_alias_return_thunk+0x5/0xfbef5
[ 893.591926] ? migrate_disable+0xd0/0x170
[ 893.591926] ? srso_alias_return_thunk+0x5/0xfbef5
[ 893.591926] ? bpf_flow_dissect+0x130/0x3d0
[ 893.591926] ? bpf_prog_test_run_flow_dissector+0x355/0x550
[ 893.591926] ? __pfx_bpf_prog_test_run_flow_dissector+0x10/0x10
[ 893.591926] ? __pfx__raw_spin_lock_irqsave+0x10/0x10
[ 893.591926] ? srso_alias_return_thunk+0x5/0xfbef5
[ 893.591926] ? __fget_files+0x205/0x260
[ 893.591926] ? bpf_prog_test_run+0x262/0x4d0
[ 893.591926] ? __pfx_bpf_prog_test_run+0x10/0x10
[ 893.591926] ? __sys_bpf+0x4ff/0x740
[ 893.591926] ? __pfx___sys_bpf+0x10/0x10
[ 893.591926] ? srso_alias_return_thunk+0x5/0xfbef5
[ 893.591926] ? xfd_validate_state+0x33/0x100
[ 893.591926] ? __x64_sys_bpf+0x7c/0x90
[ 893.591926] ? do_syscall_64+0x61/0x160
[ 893.591926] ? arch_exit_to_user_mode_prepare+0x9/0x50
[ 893.591926] ? srso_alias_return_thunk+0x5/0xfbef5
[ 893.591926] ? entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 893.591926] </TASK>
```
I think maybe it is time to send another revision?
https://github.com/llvm/llvm-project/pull/149715
More information about the llvm-commits
mailing list