libbpf: fix AF_XDP helper program to support kernels without the JMP32 eBPF instruction class
Subsystems (4)
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.
--- tools/lib/bpf/xsk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/xsk.c +1 -1
@@ -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
Quoted 2 lines · Alex Forster
Kernel 5.1 introduced support for the JMP32 eBPF instruction class, and commit d7d962a modified the libbpf
AF_XDPhelper program to use theBPF_JMP32_IMMinstruction. 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 ofBPF_JMP32_IMMwithBPF_JMP_IMMfor compatibility with pre-5.1 kernels.
I though af_xdp landed after jmp32 ?
Quoted 1 line
I though
af_xdplanded 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
Björn Töpel
Acked-byQuoted 6 lines · Alex Forster
Quoted 1 line
I though
af_xdplanded after jmp32 ?They were indeed pretty close together, but
AF_XDPbecame 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
Daniel Borkmann
maintainerQuoted 9 lines · Björn Töpel
Quoted 5 lines · Alex Forster
Quoted 1 line
I though
af_xdplanded after jmp32 ?They were indeed pretty close together, but
AF_XDPbecame 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_XDPpre-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_XDPprograms 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