Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpftool: Probe for ISA v4 instruction set extension

This patch introduces a new probe to check whether the kernel supports
instruction set extensions v4. The v4 extension comprises several new
instructions: BPF_{SDIV,SMOD} (signed div and mod), BPF_{LD,LDX,ST,STX,MOV}
(sign-extended load/store/move), 32-bit BPF_JA (unconditional jump),
target-independent BPF_ALU64 BSWAP (byte-swapping 16/32/64).

These have been introduced in the following commits respectively:

* ec0e2da95f72 ("bpf: Support new signed div/mod instructions.")
* 1f9a1ea821ff ("bpf: Support new sign-extension load insns")
* 8100928c8814 ("bpf: Support new sign-extension mov insns")
* 4cd58e9af8b9 ("bpf: Support new 32bit offset jmp instruction")
* 0845c3db7bf5 ("bpf: Support new unconditional bswap instruction")

Support in bpftool for previous ISA extensions was added in commit
0fd800b2456c ("bpftool: Probe for instruction set extensions"). These
probes are useful for userspace BPF projects that want to use newer
instruction set extensions on newer kernels, to reduce the programs'
sizes or their complexity.

LLVM provides the mcpu=v4 option since LLVM commit 8f28e8069c4b ("[BPF]
support for BPF_ST instruction in codegen") [0].

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://github.com/llvm/llvm-project/commit/8f28e8069c4ba1110daee8bddc4d5049b6d4646e [0]
Link: https://lore.kernel.org/bpf/20241209145439.336362-1-simone.magnani@isovalent.com

authored by

Simone Magnani and committed by
Daniel Borkmann
b9fee10a 6e8ba494

+33
+23
tools/bpf/bpftool/feature.c
··· 885 885 "V3_ISA_EXTENSION"); 886 886 } 887 887 888 + /* 889 + * Probe for the v4 instruction set extension introduced in commit 1f9a1ea821ff 890 + * ("bpf: Support new sign-extension load insns"). 891 + */ 892 + static void 893 + probe_v4_isa_extension(const char *define_prefix, __u32 ifindex) 894 + { 895 + struct bpf_insn insns[5] = { 896 + BPF_MOV64_IMM(BPF_REG_0, 0), 897 + BPF_JMP32_IMM(BPF_JEQ, BPF_REG_0, 1, 1), 898 + BPF_JMP32_A(1), 899 + BPF_MOV64_IMM(BPF_REG_0, 1), 900 + BPF_EXIT_INSN() 901 + }; 902 + 903 + probe_misc_feature(insns, ARRAY_SIZE(insns), 904 + define_prefix, ifindex, 905 + "have_v4_isa_extension", 906 + "ISA extension v4", 907 + "V4_ISA_EXTENSION"); 908 + } 909 + 888 910 static void 889 911 section_system_config(enum probe_component target, const char *define_prefix) 890 912 { ··· 1051 1029 probe_bounded_loops(define_prefix, ifindex); 1052 1030 probe_v2_isa_extension(define_prefix, ifindex); 1053 1031 probe_v3_isa_extension(define_prefix, ifindex); 1032 + probe_v4_isa_extension(define_prefix, ifindex); 1054 1033 print_end_section(); 1055 1034 } 1056 1035
+10
tools/include/linux/filter.h
··· 273 273 .off = OFF, \ 274 274 .imm = 0 }) 275 275 276 + /* Unconditional jumps, gotol pc + imm32 */ 277 + 278 + #define BPF_JMP32_A(IMM) \ 279 + ((struct bpf_insn) { \ 280 + .code = BPF_JMP32 | BPF_JA, \ 281 + .dst_reg = 0, \ 282 + .src_reg = 0, \ 283 + .off = 0, \ 284 + .imm = IMM }) 285 + 276 286 /* Function call */ 277 287 278 288 #define BPF_EMIT_CALL(FUNC) \