Skip to contentSkip to conversation

bpf: correct use/def for may_goto instruction

PATCH Applied Eduard Zingerman 2 participants 2 messages Mar 5, 2025

Subsystems (4)
lore
Share & tools
lore

Eduard Zingerman

author maintainer
#0 lore raw

PATCH 1/1 bpf: correct use/def for may_goto instruction

may_goto instruction does not use any registers, but in compute_insn_live_regs() it was treated as a regular conditional jump of kind BPF_K with r0 as source register. Thus unnecessarily marking r0 as used.

Fixes 7dad03653567 ("bpf: simple DFA-based live registers analysis")
---
 kernel/bpf/verifier.c                                      | 1 +
 tools/testing/selftests/bpf/progs/compute_live_registers.c | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +1 -0
index 4edb2db0f889..3303a3605ee8 100644
@@ -23567,6 +23567,7 @@ static void compute_insn_live_regs(struct bpf_verifier_env *env,
 	case BPF_JMP32:
 		switch (code) {
 		case BPF_JA:
+		case BPF_JCOND:
 			def = 0;
 			use = 0;
 			break;
tools/testing/selftests/bpf/progs/compute_live_registers.c +3 -3
index 14df92949e81..f3d79aecbf93 100644
@@ -294,9 +294,9 @@ __naked void gotol(void)
 
 SEC("socket")
 __log_level(2)
-__msg("0: 0......... (b7) r1 = 1")
-__msg("1: 01........ (e5) may_goto pc+1")
-__msg("2: 0......... (05) goto pc-3")
+__msg("0: .......... (b7) r1 = 1")
+__msg("1: .1........ (e5) may_goto pc+1")
+__msg("2: .......... (05) goto pc-3")
 __msg("3: .1........ (bf) r0 = r1")
 __msg("4: 0......... (95) exit")
 __naked void may_goto(void)
Signature · 1 line
2.48.1
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 9 lines · On Wed, 5 Mar 2025 00:54:36 -0800 you wrote:

may_goto instruction does not use any registers, but in compute_insn_live_regs() it was treated as a regular conditional jump of kind BPF_K with r0 as source register. Thus unnecessarily marking r0 as used.

Fixes 7dad03653567 ("bpf: simple DFA-based live registers analysis")

[...]

Here is the summary with links:
- [bpf-next,v1] bpf: correct use/def for may_goto instruction

    https://git.kernel.org/bpf/bpf-next/c/aae1add9053e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html