Skip to content

Commit 6e62702

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf-next 2024-05-13 We've added 119 non-merge commits during the last 14 day(s) which contain a total of 134 files changed, 9462 insertions(+), 4742 deletions(-). The main changes are: 1) Add BPF JIT support for 32-bit ARCv2 processors, from Shahab Vahedi. 2) Add BPF range computation improvements to the verifier in particular around XOR and OR operators, refactoring of checks for range computation and relaxing MUL range computation so that src_reg can also be an unknown scalar, from Cupertino Miranda. 3) Add support to attach kprobe BPF programs through kprobe_multi link in a session mode, meaning, a BPF program is attached to both function entry and return, the entry program can decide if the return program gets executed and the entry program can share u64 cookie value with return program. Session mode is a common use-case for tetragon and bpftrace, from Jiri Olsa. 4) Fix a potential overflow in libbpf's ring__consume_n() and improve libbpf as well as BPF selftest's struct_ops handling, from Andrii Nakryiko. 5) Improvements to BPF selftests in context of BPF gcc backend, from Jose E. Marchesi & David Faust. 6) Migrate remaining BPF selftest tests from test_sock_addr.c to prog_test- -style in order to retire the old test, run it in BPF CI and additionally expand test coverage, from Jordan Rife. 7) Big batch for BPF selftest refactoring in order to remove duplicate code around common network helpers, from Geliang Tang. 8) Another batch of improvements to BPF selftests to retire obsolete bpf_tcp_helpers.h as everything is available vmlinux.h, from Martin KaFai Lau. 9) Fix BPF map tear-down to not walk the map twice on free when both timer and wq is used, from Benjamin Tissoires. 10) Fix BPF verifier assumptions about socket->sk that it can be non-NULL, from Alexei Starovoitov. 11) Change BTF build scripts to using --btf_features for pahole v1.26+, from Alan Maguire. 12) Small improvements to BPF reusing struct_size() and krealloc_array(), from Andy Shevchenko. 13) Fix s390 JIT to emit a barrier for BPF_FETCH instructions, from Ilya Leoshkevich. 14) Extend TCP ->cong_control() callback in order to feed in ack and flag parameters and allow write-access to tp->snd_cwnd_stamp from BPF program, from Miao Xu. 15) Add support for internal-only per-CPU instructions to inline bpf_get_smp_processor_id() helper call for arm64 and riscv64 BPF JITs, from Puranjay Mohan. 16) Follow-up to remove the redundant ethtool.h from tooling infrastructure, from Tushar Vyavahare. 17) Extend libbpf to support "module:<function>" syntax for tracing programs, from Viktor Malik. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (119 commits) bpf: make list_for_each_entry portable bpf: ignore expected GCC warning in test_global_func10.c bpf: disable strict aliasing in test_global_func9.c selftests/bpf: Free strdup memory in xdp_hw_metadata selftests/bpf: Fix a few tests for GCC related warnings. bpf: avoid gcc overflow warning in test_xdp_vlan.c tools: remove redundant ethtool.h from tooling infra selftests/bpf: Expand ATTACH_REJECT tests selftests/bpf: Expand getsockname and getpeername tests sefltests/bpf: Expand sockaddr hook deny tests selftests/bpf: Expand sockaddr program return value tests selftests/bpf: Retire test_sock_addr.(c|sh) selftests/bpf: Remove redundant sendmsg test cases selftests/bpf: Migrate ATTACH_REJECT test cases selftests/bpf: Migrate expected_attach_type tests selftests/bpf: Migrate wildcard destination rewrite test selftests/bpf: Migrate sendmsg6 v4 mapped address tests selftests/bpf: Migrate sendmsg deny test cases selftests/bpf: Migrate WILDCARD_IP test selftests/bpf: Handle SYSCALL_EPERM and SYSCALL_ENOTSUPP test cases ... ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents afd29f3 + ba39486 commit 6e62702

File tree

134 files changed

+9462
-4742
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+9462
-4742
lines changed

Documentation/admin-guide/sysctl/net.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ two flavors of JITs, the newer eBPF JIT currently supported on:
7272
- riscv64
7373
- riscv32
7474
- loongarch64
75+
- arc
7576

7677
And the older cBPF JIT supported on the following archs:
7778

Documentation/networking/filter.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ JIT compiler
513513
------------
514514

515515
The Linux kernel has a built-in BPF JIT compiler for x86_64, SPARC,
516-
PowerPC, ARM, ARM64, MIPS, RISC-V and s390 and can be enabled through
516+
PowerPC, ARM, ARM64, MIPS, RISC-V, s390, and ARC and can be enabled through
517517
CONFIG_BPF_JIT. The JIT compiler is transparently invoked for each
518518
attached filter from user space or for internal kernel users if it has
519519
been previously enabled by root::
@@ -650,7 +650,7 @@ before a conversion to the new layout is being done behind the scenes!
650650

651651
Currently, the classic BPF format is being used for JITing on most
652652
32-bit architectures, whereas x86-64, aarch64, s390x, powerpc64,
653-
sparc64, arm32, riscv64, riscv32, loongarch64 perform JIT compilation
653+
sparc64, arm32, riscv64, riscv32, loongarch64, arc perform JIT compilation
654654
from eBPF instruction set.
655655

656656
Testing

MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,6 +3712,12 @@ S: Maintained
37123712
F: Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
37133713
F: drivers/iio/imu/bmi323/
37143714

3715+
BPF JIT for ARC
3716+
M: Shahab Vahedi <[email protected]>
3717+
3718+
S: Maintained
3719+
F: arch/arc/net/
3720+
37153721
BPF JIT for ARM
37163722
M: Russell King <[email protected]>
37173723
M: Puranjay Mohan <[email protected]>

arch/arc/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-y += kernel/
33
obj-y += mm/
4+
obj-y += net/
45

56
# for cleaning
67
subdir- += boot

arch/arc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ config ARC
5151
select PCI_SYSCALL if PCI
5252
select HAVE_ARCH_JUMP_LABEL if ISA_ARCV2 && !CPU_ENDIAN_BE32
5353
select TRACE_IRQFLAGS_SUPPORT
54+
select HAVE_EBPF_JIT if ISA_ARCV2
5455

5556
config LOCKDEP_SUPPORT
5657
def_bool y

arch/arc/net/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
ifeq ($(CONFIG_ISA_ARCV2),y)
4+
obj-$(CONFIG_BPF_JIT) += bpf_jit_core.o
5+
obj-$(CONFIG_BPF_JIT) += bpf_jit_arcv2.o
6+
endif

arch/arc/net/bpf_jit.h

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* The interface that a back-end should provide to bpf_jit_core.c.
4+
*
5+
* Copyright (c) 2024 Synopsys Inc.
6+
* Author: Shahab Vahedi <[email protected]>
7+
*/
8+
9+
#ifndef _ARC_BPF_JIT_H
10+
#define _ARC_BPF_JIT_H
11+
12+
#include <linux/bpf.h>
13+
#include <linux/filter.h>
14+
15+
/* Print debug info and assert. */
16+
//#define ARC_BPF_JIT_DEBUG
17+
18+
/* Determine the address type of the target. */
19+
#ifdef CONFIG_ISA_ARCV2
20+
#define ARC_ADDR u32
21+
#endif
22+
23+
/*
24+
* For the translation of some BPF instructions, a temporary register
25+
* might be needed for some interim data.
26+
*/
27+
#define JIT_REG_TMP MAX_BPF_JIT_REG
28+
29+
/*
30+
* Buffer access: If buffer "b" is not NULL, advance by "n" bytes.
31+
*
32+
* This macro must be used in any place that potentially requires a
33+
* "buf + len". This way, we make sure that the "buf" argument for
34+
* the underlying "arc_*(buf, ...)" ends up as NULL instead of something
35+
* like "0+4" or "0+8", etc. Those "arc_*()" functions check their "buf"
36+
* value to decide if instructions should be emitted or not.
37+
*/
38+
#define BUF(b, n) (((b) != NULL) ? ((b) + (n)) : (b))
39+
40+
/************** Functions that the back-end must provide **************/
41+
/* Extension for 32-bit operations. */
42+
inline u8 zext(u8 *buf, u8 rd);
43+
/***** Moves *****/
44+
u8 mov_r32(u8 *buf, u8 rd, u8 rs, u8 sign_ext);
45+
u8 mov_r32_i32(u8 *buf, u8 reg, s32 imm);
46+
u8 mov_r64(u8 *buf, u8 rd, u8 rs, u8 sign_ext);
47+
u8 mov_r64_i32(u8 *buf, u8 reg, s32 imm);
48+
u8 mov_r64_i64(u8 *buf, u8 reg, u32 lo, u32 hi);
49+
/***** Loads and stores *****/
50+
u8 load_r(u8 *buf, u8 rd, u8 rs, s16 off, u8 size, bool sign_ext);
51+
u8 store_r(u8 *buf, u8 rd, u8 rs, s16 off, u8 size);
52+
u8 store_i(u8 *buf, s32 imm, u8 rd, s16 off, u8 size);
53+
/***** Addition *****/
54+
u8 add_r32(u8 *buf, u8 rd, u8 rs);
55+
u8 add_r32_i32(u8 *buf, u8 rd, s32 imm);
56+
u8 add_r64(u8 *buf, u8 rd, u8 rs);
57+
u8 add_r64_i32(u8 *buf, u8 rd, s32 imm);
58+
/***** Subtraction *****/
59+
u8 sub_r32(u8 *buf, u8 rd, u8 rs);
60+
u8 sub_r32_i32(u8 *buf, u8 rd, s32 imm);
61+
u8 sub_r64(u8 *buf, u8 rd, u8 rs);
62+
u8 sub_r64_i32(u8 *buf, u8 rd, s32 imm);
63+
/***** Multiplication *****/
64+
u8 mul_r32(u8 *buf, u8 rd, u8 rs);
65+
u8 mul_r32_i32(u8 *buf, u8 rd, s32 imm);
66+
u8 mul_r64(u8 *buf, u8 rd, u8 rs);
67+
u8 mul_r64_i32(u8 *buf, u8 rd, s32 imm);
68+
/***** Division *****/
69+
u8 div_r32(u8 *buf, u8 rd, u8 rs, bool sign_ext);
70+
u8 div_r32_i32(u8 *buf, u8 rd, s32 imm, bool sign_ext);
71+
/***** Remainder *****/
72+
u8 mod_r32(u8 *buf, u8 rd, u8 rs, bool sign_ext);
73+
u8 mod_r32_i32(u8 *buf, u8 rd, s32 imm, bool sign_ext);
74+
/***** Bitwise AND *****/
75+
u8 and_r32(u8 *buf, u8 rd, u8 rs);
76+
u8 and_r32_i32(u8 *buf, u8 rd, s32 imm);
77+
u8 and_r64(u8 *buf, u8 rd, u8 rs);
78+
u8 and_r64_i32(u8 *buf, u8 rd, s32 imm);
79+
/***** Bitwise OR *****/
80+
u8 or_r32(u8 *buf, u8 rd, u8 rs);
81+
u8 or_r32_i32(u8 *buf, u8 rd, s32 imm);
82+
u8 or_r64(u8 *buf, u8 rd, u8 rs);
83+
u8 or_r64_i32(u8 *buf, u8 rd, s32 imm);
84+
/***** Bitwise XOR *****/
85+
u8 xor_r32(u8 *buf, u8 rd, u8 rs);
86+
u8 xor_r32_i32(u8 *buf, u8 rd, s32 imm);
87+
u8 xor_r64(u8 *buf, u8 rd, u8 rs);
88+
u8 xor_r64_i32(u8 *buf, u8 rd, s32 imm);
89+
/***** Bitwise Negate *****/
90+
u8 neg_r32(u8 *buf, u8 r);
91+
u8 neg_r64(u8 *buf, u8 r);
92+
/***** Bitwise left shift *****/
93+
u8 lsh_r32(u8 *buf, u8 rd, u8 rs);
94+
u8 lsh_r32_i32(u8 *buf, u8 rd, u8 imm);
95+
u8 lsh_r64(u8 *buf, u8 rd, u8 rs);
96+
u8 lsh_r64_i32(u8 *buf, u8 rd, s32 imm);
97+
/***** Bitwise right shift (logical) *****/
98+
u8 rsh_r32(u8 *buf, u8 rd, u8 rs);
99+
u8 rsh_r32_i32(u8 *buf, u8 rd, u8 imm);
100+
u8 rsh_r64(u8 *buf, u8 rd, u8 rs);
101+
u8 rsh_r64_i32(u8 *buf, u8 rd, s32 imm);
102+
/***** Bitwise right shift (arithmetic) *****/
103+
u8 arsh_r32(u8 *buf, u8 rd, u8 rs);
104+
u8 arsh_r32_i32(u8 *buf, u8 rd, u8 imm);
105+
u8 arsh_r64(u8 *buf, u8 rd, u8 rs);
106+
u8 arsh_r64_i32(u8 *buf, u8 rd, s32 imm);
107+
/***** Frame related *****/
108+
u32 mask_for_used_regs(u8 bpf_reg, bool is_call);
109+
u8 arc_prologue(u8 *buf, u32 usage, u16 frame_size);
110+
u8 arc_epilogue(u8 *buf, u32 usage, u16 frame_size);
111+
/***** Jumps *****/
112+
/*
113+
* Different sorts of conditions (ARC enum as opposed to BPF_*).
114+
*
115+
* Do not change the order of enums here. ARC_CC_SLE+1 is used
116+
* to determine the number of JCCs.
117+
*/
118+
enum ARC_CC {
119+
ARC_CC_UGT = 0, /* unsigned > */
120+
ARC_CC_UGE, /* unsigned >= */
121+
ARC_CC_ULT, /* unsigned < */
122+
ARC_CC_ULE, /* unsigned <= */
123+
ARC_CC_SGT, /* signed > */
124+
ARC_CC_SGE, /* signed >= */
125+
ARC_CC_SLT, /* signed < */
126+
ARC_CC_SLE, /* signed <= */
127+
ARC_CC_AL, /* always */
128+
ARC_CC_EQ, /* == */
129+
ARC_CC_NE, /* != */
130+
ARC_CC_SET, /* test */
131+
ARC_CC_LAST
132+
};
133+
134+
/*
135+
* A few notes:
136+
*
137+
* - check_jmp_*() are prerequisites before calling the gen_jmp_*().
138+
* They return "true" if the jump is possible and "false" otherwise.
139+
*
140+
* - The notion of "*_off" is to emphasize that these parameters are
141+
* merely offsets in the JIT stream and not absolute addresses. One
142+
* can look at them as addresses if the JIT code would start from
143+
* address 0x0000_0000. Nonetheless, since the buffer address for the
144+
* JIT is on a word-aligned address, this works and actually makes
145+
* things simpler (offsets are in the range of u32 which is more than
146+
* enough).
147+
*/
148+
bool check_jmp_32(u32 curr_off, u32 targ_off, u8 cond);
149+
bool check_jmp_64(u32 curr_off, u32 targ_off, u8 cond);
150+
u8 gen_jmp_32(u8 *buf, u8 rd, u8 rs, u8 cond, u32 c_off, u32 t_off);
151+
u8 gen_jmp_64(u8 *buf, u8 rd, u8 rs, u8 cond, u32 c_off, u32 t_off);
152+
/***** Miscellaneous *****/
153+
u8 gen_func_call(u8 *buf, ARC_ADDR func_addr, bool external_func);
154+
u8 arc_to_bpf_return(u8 *buf);
155+
/*
156+
* - Perform byte swaps on "rd" based on the "size".
157+
* - If "force" is set, do it unconditionally. Otherwise, consider the
158+
* desired "endian"ness and the host endianness.
159+
* - For data "size"s up to 32 bits, perform a zero-extension if asked
160+
* by the "do_zext" boolean.
161+
*/
162+
u8 gen_swap(u8 *buf, u8 rd, u8 size, u8 endian, bool force, bool do_zext);
163+
164+
#endif /* _ARC_BPF_JIT_H */

0 commit comments

Comments
 (0)