LoongArch: BPF: Fix jump offset calculation in tailcall
authorHaoran Jiang <jianghaoran@kylinos.cn>
Tue, 5 Aug 2025 11:00:22 +0000 (19:00 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Tue, 5 Aug 2025 11:00:22 +0000 (19:00 +0800)
commitcd39d9e6b7e4c58fa77783e7aedf7ada51d02ea3
tree2071534f4bc1a5fb63b985632586508b7b4eb56c
parent6abf17d690d83d25f6d00a1a2cd3553c7d20c2d8
LoongArch: BPF: Fix jump offset calculation in tailcall

The extra pass of bpf_int_jit_compile() skips JIT context initialization
which essentially skips offset calculation leaving out_offset = -1, so
the jmp_offset in emit_bpf_tail_call is calculated by

"#define jmp_offset (out_offset - (cur_offset))"

is a negative number, which is wrong. The final generated assembly are
as follow.

54: bgeu         $a2, $t1, -8     # 0x0000004c
58: addi.d       $a6, $s5, -1
5c: bltz         $a6, -16     # 0x0000004c
60: alsl.d       $t2, $a2, $a1, 0x3
64: ld.d         $t2, $t2, 264
68: beq          $t2, $zero, -28     # 0x0000004c

Before apply this patch, the follow test case will reveal soft lock issues.

cd tools/testing/selftests/bpf/
./test_progs --allow=tailcalls/tailcall_bpf2bpf_1

dmesg:
watchdog: BUG: soft lockup - CPU#2 stuck for 26s! [test_progs:25056]

Cc: stable@vger.kernel.org
Fixes: 5dc615520c4d ("LoongArch: Add BPF JIT support")
Reviewed-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Haoran Jiang <jianghaoran@kylinos.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/net/bpf_jit.c