Skip to contentSkip to conversation

libbpf: fix AF_XDP helper program to support kernels without the JMP32 eBPF instruction class

PATCH In review Alex Forster 4 participants 5 messages Dec 19, 2019 – Dec 20, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: fix AF_XDP helper program to support kernels without the JMP32 eBPF instruction class

Kernel 5.1 introduced support for the JMP32 eBPF instruction class, and commit d7d962a modified the libbpf AF_XDP helper program to use the BPF_JMP32_IMM instruction. For those on earlier kernels, attempting to load the helper program now results in the verifier failing with "unknown opcode 66". This change replaces the usage of BPF_JMP32_IMM with BPF_JMP_IMM for compatibility with pre-5.1 kernels.

Cc Alexei Starovoitov <[email protected]>
Cc Björn Töpel <[email protected]>
---
 tools/lib/bpf/xsk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/xsk.c +1 -1
index 8e0ffa800a71..761f8485b80e 100644
@@ -366,7 +366,7 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
 		/* call bpf_redirect_map */
 		BPF_EMIT_CALL(BPF_FUNC_redirect_map),
 		/* if w0 != 0 goto pc+13 */
-		BPF_JMP32_IMM(BPF_JSGT, BPF_REG_0, 0, 13),
+		BPF_JMP_IMM(BPF_JSGT, BPF_REG_0, 0, 13),
 		/* r2 = r10 */
 		BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
 		/* r2 += -4 */
Signature · 1 line
2.23.0
#1 lore raw
Quoted 2 lines · Alex Forster

Kernel 5.1 introduced support for the JMP32 eBPF instruction class, and commit d7d962a modified the libbpf AF_XDP helper program to use the BPF_JMP32_IMM instruction. For those on earlier kernels, attempting to load the helper program now results in the verifier failing with "unknown opcode 66". This change replaces the usage of BPF_JMP32_IMM with BPF_JMP_IMM for compatibility with pre-5.1 kernels.

I though af_xdp landed after jmp32 ?

#2 lore raw
Quoted 1 line

I though af_xdp landed after jmp32 ?

They were indeed pretty close together, but AF_XDP became usable in late 2018 with either 4.18 or 4.19. JMP32 landed in early 2019 with 5.1.

Alex Forster

Acked-by
#3 lore raw
Quoted 6 lines · Alex Forster
Quoted 1 line

I though af_xdp landed after jmp32 ?

They were indeed pretty close together, but AF_XDP became usable in late 2018 with either 4.18 or 4.19. JMP32 landed in early 2019 with 5.1.

Correct, but is anyone really using AF_XDP pre-5.1?

The rationale for doing JMP32:
https://lore.kernel.org/bpf/[email protected]/

I think going forward, a route where different AF_XDP programs is loaded based on what currently running kernel supports. "Every s^Hcycle is sacred", and we're actually paying for the extra checks.

Then again, failing to load is still pretty bad. :-) Thanks for fixing this.

Quoted 2 lines

Alex Forster

maintainer
#4 lore raw
Quoted 9 lines · Björn Töpel
Quoted 5 lines · Alex Forster
Quoted 1 line

I though af_xdp landed after jmp32 ?

They were indeed pretty close together, but AF_XDP became usable in late 2018 with either 4.18 or 4.19. JMP32 landed in early 2019 with 5.1.

Correct, but is anyone really using AF_XDP pre-5.1?

Quoted 8 lines

The rationale for doing JMP32:
https://lore.kernel.org/bpf/[email protected]/

I think going forward, a route where different AF_XDP programs is loaded based on what currently running kernel supports. "Every s^Hcycle is sacred", and we're actually paying for the extra checks.

Then again, failing to load is still pretty bad. :-) Thanks for fixing this.

Could we simply just test availability of JMP32 in underlying kernel and use it if available, if not, fall back to regular JMP. libbpf already has infra for this, so xsk code could make use of it.

Thanks,
Daniel