]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Extend live regs tests with a test for gotox
authorAnton Protopopov <a.s.protopopov@gmail.com>
Wed, 14 Jan 2026 16:25:44 +0000 (16:25 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 15 Jan 2026 03:08:09 +0000 (19:08 -0800)
Add a test which checks that the destination register of a gotox
instruction is marked as used and that the union of jump targets
is considered as live.

Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
Link: https://lore.kernel.org/r/20260114162544.83253-3-a.s.protopopov@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/compute_live_registers.c

index 6884ab99a421b5f5f689ceacee998e8cf7b1324e..f05e120f345087844a57e1f53b67a54d746da75b 100644 (file)
@@ -431,6 +431,47 @@ __naked void subprog1(void)
                ::: __clobber_all);
 }
 
+#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)
+
+SEC("socket")
+__log_level(2)
+__msg("2: .1........ (07) r1 += 8")
+__msg("3: .1........ (79) r2 = *(u64 *)(r1 +0)")
+__msg("4: ..2....... (b7) r3 = 1")
+__msg("5: ..23...... (b7) r4 = 2")
+__msg("6: ..234..... (0d) gotox r2")
+__msg("7: ...3...... (bf) r0 = r3")
+__msg("8: 0......... (95) exit")
+__msg("9: ....4..... (bf) r0 = r4")
+__msg("10: 0......... (95) exit")
+__naked
+void gotox(void)
+{
+       asm volatile (
+       ".pushsection .jumptables,\"\",@progbits;"
+"jt0_%=: .quad l0_%= - socket;"
+       ".quad l1_%= - socket;"
+       ".size jt0_%=, 16;"
+       ".global jt0_%=;"
+       ".popsection;"
+
+       "r1 = jt0_%= ll;"
+       "r1 += 8;"
+       "r2 = *(u64 *)(r1 + 0);"
+       "r3 = 1;"
+       "r4 = 2;"
+       ".8byte %[gotox_r2];"
+"l0_%=:  r0 = r3;"
+       "exit;"
+"l1_%=:  r0 = r4;"
+       "exit;"
+       :
+       : __imm_insn(gotox_r2, BPF_RAW_INSN(BPF_JMP | BPF_JA | BPF_X, BPF_REG_2, BPF_REG_0, 0, 0))
+       : __clobber_all);
+}
+
+#endif /* __TARGET_ARCH_x86 || __TARGET_ARCH_arm64 */
+
 /* to retain debug info for BTF generation */
 void kfunc_root(void)
 {