bpf: Live registers computation with gotox
Subsystems (4)
v2 cover bpf: Live registers computation with gotox
While adding a selftest for live registers computation with gotox, I've noticed that the code is actually incomplete. Namely, the destination register rX in gotox rX wasn't actually considered as used. Fix this and add a selftest.
v1 -> v2:
* only enable the new selftest on x86 and arm64
v1: https://lore.kernel.org/bpf/[email protected]/T/#t
Anton Protopopov (2):
bpf: Properly mark live registers for indirect jumps selftests/bpf: Extend live regs tests with a test for gotox
kernel/bpf/verifier.c | 6 +++ .../bpf/progs/compute_live_registers.c | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+)
Signature · 1 line
2.34.1
PATCH v2 1/2 bpf: Properly mark live registers for indirect jumps
For a gotox rX instruction the rX register should be marked as used in the compute_insn_live_regs() function. Fix this.
--- kernel/bpf/verifier.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/bpf/verifier.c +6 -0
@@ -24843,6 +24843,12 @@ static void compute_insn_live_regs(struct bpf_verifier_env *env,case BPF_JMP32 :switch (code) {case BPF_JA : + def =0 ; +if (BPF_SRC (insn->code) ==BPF_X ) + use = dst; +else + use =0 ; +break ;case BPF_JCOND : def =0 ; use =0 ;
Signature · 1 line
2.34.1
PATCH v2 2/2 selftests/bpf: Extend live regs tests with a test for gotox
In reply to Anton ProtopopovAdd 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.
--- .../bpf/progs/compute_live_registers.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+)
tools/testing/selftests/bpf/progs/compute_live_registers.c +41 -0
@@ -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 ) +{ + asmvolatile ( +".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 ) {
Signature · 1 line
2.34.1
Quoted 10 lines · Anton Protopopov
While adding a selftest for live registers computation with gotox, I've noticed that the code is actually incomplete. Namely, the destination register rX in
gotox rXwasn't actually considered as used. Fix this and add a selftest.v1 -> v2:
* only enable the new selftest on x86 and arm64
Quoted 7 lines
Anton Protopopov (2):
bpf: Properly mark live registers for indirect jumps selftests/bpf: Extend live regs tests with a test for gotoxkernel/bpf/verifier.c | 6 +++ .../bpf/progs/compute_live_registers.c | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+)
Huh, how did we miss this one?
Thank you for the patches.
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Wed, 14 Jan 2026 16:25:42 +0000 you wrote:
While adding a selftest for live registers computation with gotox, I've noticed that the code is actually incomplete. Namely, the destination register rX in
gotox rXwasn't actually considered as used. Fix this and add a selftest.v1 -> v2:
* only enable the new selftest on x86 and arm64[...]
Here is the summary with links:
- [v2,bpf-next,1/2] bpf: Properly mark live registers for indirect jumps
https://git.kernel.org/bpf/bpf-next/c/d1aab1ca576c - [v2,bpf-next,2/2] selftests/bpf: Extend live regs tests with a test for gotox https://git.kernel.org/bpf/bpf-next/c/7c8e817e443c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html