1 From: Johan Almbladh <johan.almbladh@anyfinetworks.com>
2 Date: Tue, 5 Oct 2021 18:54:08 +0200
3 Subject: [PATCH] mips: bpf: Remove old BPF JIT implementations
5 This patch removes the old 32-bit cBPF and 64-bit eBPF JIT implementations.
6 They are replaced by a new eBPF implementation that supports both 32-bit
9 Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
11 delete mode 100644 arch/mips/net/bpf_jit.c
12 delete mode 100644 arch/mips/net/bpf_jit.h
13 delete mode 100644 arch/mips/net/bpf_jit_asm.S
14 delete mode 100644 arch/mips/net/ebpf_jit.c
16 --- a/arch/mips/net/bpf_jit.h
19 -/* SPDX-License-Identifier: GPL-2.0-only */
21 - * Just-In-Time compiler for BPF filters on MIPS
23 - * Copyright (c) 2014 Imagination Technologies Ltd.
24 - * Author: Markos Chandras <markos.chandras@imgtec.com>
27 -#ifndef BPF_JIT_MIPS_OP_H
28 -#define BPF_JIT_MIPS_OP_H
30 -/* Registers used by JIT */
31 -#define MIPS_R_ZERO 0
50 -/* Conditional codes */
51 -#define MIPS_COND_EQ 0x1
52 -#define MIPS_COND_GE (0x1 << 1)
53 -#define MIPS_COND_GT (0x1 << 2)
54 -#define MIPS_COND_NE (0x1 << 3)
55 -#define MIPS_COND_ALL (0x1 << 4)
56 -/* Conditionals on X register or K immediate */
57 -#define MIPS_COND_X (0x1 << 5)
58 -#define MIPS_COND_K (0x1 << 6)
60 -#define r_ret MIPS_R_V0
63 - * Use 2 scratch registers to avoid pipeline interlocks.
64 - * There is no overhead during epilogue and prologue since
65 - * any of the $s0-$s6 registers will only be preserved if
66 - * they are going to actually be used.
68 -#define r_skb_hl MIPS_R_S0 /* skb header length */
69 -#define r_skb_data MIPS_R_S1 /* skb actual data */
70 -#define r_off MIPS_R_S2
71 -#define r_A MIPS_R_S3
72 -#define r_X MIPS_R_S4
73 -#define r_skb MIPS_R_S5
74 -#define r_M MIPS_R_S6
75 -#define r_skb_len MIPS_R_S7
76 -#define r_s0 MIPS_R_T4 /* scratch reg 1 */
77 -#define r_s1 MIPS_R_T5 /* scratch reg 2 */
78 -#define r_tmp_imm MIPS_R_T6 /* No need to preserve this */
79 -#define r_tmp MIPS_R_T7 /* No need to preserve this */
80 -#define r_zero MIPS_R_ZERO
81 -#define r_sp MIPS_R_SP
82 -#define r_ra MIPS_R_RA
86 -/* Declare ASM helpers */
88 -#define DECLARE_LOAD_FUNC(func) \
89 - extern u8 func(unsigned long *skb, int offset); \
90 - extern u8 func##_negative(unsigned long *skb, int offset); \
91 - extern u8 func##_positive(unsigned long *skb, int offset)
93 -DECLARE_LOAD_FUNC(sk_load_word);
94 -DECLARE_LOAD_FUNC(sk_load_half);
95 -DECLARE_LOAD_FUNC(sk_load_byte);
99 -#endif /* BPF_JIT_MIPS_OP_H */
100 --- a/arch/mips/net/bpf_jit_asm.S
104 - * bpf_jib_asm.S: Packet/header access helper functions for MIPS/MIPS64 BPF
107 - * Copyright (C) 2015 Imagination Technologies Ltd.
108 - * Author: Markos Chandras <markos.chandras@imgtec.com>
110 - * This program is free software; you can redistribute it and/or modify it
111 - * under the terms of the GNU General Public License as published by the
112 - * Free Software Foundation; version 2 of the License.
115 -#include <asm/asm.h>
116 -#include <asm/isa-rev.h>
117 -#include <asm/regdef.h>
118 -#include "bpf_jit.h"
122 - * r_skb_hl skb header length
123 - * r_skb_data skb data
124 - * r_off(a1) offset register
125 - * r_A BPF register A
126 - * r_X PF register X
128 - * r_M *scratch memory
129 - * r_skb_le skb length
130 - * r_s0 Scratch register 0
131 - * r_s1 Scratch register 1
135 - * a1: offset (imm or imm + X)
137 - * All non-BPF-ABI registers are free for use. On return, we only
138 - * care about r_ret. The BPF-ABI registers are assumed to remain
139 - * unmodified during the entire filter operation.
144 -#define SKF_LL_OFF (-0x200000) /* Can't include linux/filter.h in assembly */
146 - /* We know better :) so prevent assembler reordering etc */
149 -#define is_offset_negative(TYPE) \
150 - /* If offset is negative we have more work to do */ \
151 - slti t0, offset, 0; \
152 - bgtz t0, bpf_slow_path_##TYPE##_neg; \
153 - /* Be careful what follows in DS. */
155 -#define is_offset_in_header(SIZE, TYPE) \
156 - /* Reading from header? */ \
157 - addiu $r_s0, $r_skb_hl, -SIZE; \
158 - slt t0, $r_s0, offset; \
159 - bgtz t0, bpf_slow_path_##TYPE; \
162 - is_offset_negative(word)
163 -FEXPORT(sk_load_word_positive)
164 - is_offset_in_header(4, word)
165 - /* Offset within header boundaries */
166 - PTR_ADDU t1, $r_skb_data, offset
170 -#ifdef CONFIG_CPU_LITTLE_ENDIAN
171 -# if MIPS_ISA_REV >= 2
179 - andi t2, t2, 0xff00
180 - andi t1, $r_A, 0xff00
191 - is_offset_negative(half)
192 -FEXPORT(sk_load_half_positive)
193 - is_offset_in_header(2, half)
194 - /* Offset within header boundaries */
195 - PTR_ADDU t1, $r_skb_data, offset
197 -#ifdef CONFIG_CPU_LITTLE_ENDIAN
198 -# if MIPS_ISA_REV >= 2
203 - andi t0, t0, 0xff00
212 - is_offset_negative(byte)
213 -FEXPORT(sk_load_byte_positive)
214 - is_offset_in_header(1, byte)
215 - /* Offset within header boundaries */
216 - PTR_ADDU t1, $r_skb_data, offset
223 - * call skb_copy_bits:
224 - * (prototype in linux/skbuff.h)
226 - * int skb_copy_bits(sk_buff *skb, int offset, void *to, int len)
228 - * o32 mandates we leave 4 spaces for argument registers in case
229 - * the callee needs to use them. Even though we don't care about
230 - * the argument registers ourselves, we need to allocate that space
231 - * to remain ABI compliant since the callee may want to use that space.
232 - * We also allocate 2 more spaces for $r_ra and our return register (*to).
234 - * n64 is a bit different. The *caller* will allocate the space to preserve
235 - * the arguments. So in 64-bit kernels, we allocate the 4-arg space for no
236 - * good reason but it does not matter that much really.
238 - * (void *to) is returned in r_s0
241 -#ifdef CONFIG_CPU_LITTLE_ENDIAN
242 -#define DS_OFFSET(SIZE) (4 * SZREG)
244 -#define DS_OFFSET(SIZE) ((4 * SZREG) + (4 - SIZE))
246 -#define bpf_slow_path_common(SIZE) \
247 - /* Quick check. Are we within reasonable boundaries? */ \
248 - LONG_ADDIU $r_s1, $r_skb_len, -SIZE; \
249 - sltu $r_s0, offset, $r_s1; \
250 - beqz $r_s0, fault; \
251 - /* Load 4th argument in DS */ \
252 - LONG_ADDIU a3, zero, SIZE; \
253 - PTR_ADDIU $r_sp, $r_sp, -(6 * SZREG); \
254 - PTR_LA t0, skb_copy_bits; \
255 - PTR_S $r_ra, (5 * SZREG)($r_sp); \
256 - /* Assign low slot to a2 */ \
257 - PTR_ADDIU a2, $r_sp, DS_OFFSET(SIZE); \
259 - /* Reset our destination slot (DS but it's ok) */ \
260 - INT_S zero, (4 * SZREG)($r_sp); \
262 - * skb_copy_bits returns 0 on success and -EFAULT \
263 - * on error. Our data live in a2. Do not bother with \
264 - * our data if an error has been returned. \
266 - /* Restore our frame */ \
267 - PTR_L $r_ra, (5 * SZREG)($r_sp); \
268 - INT_L $r_s0, (4 * SZREG)($r_sp); \
270 - PTR_ADDIU $r_sp, $r_sp, 6 * SZREG; \
271 - move $r_ret, zero; \
273 -NESTED(bpf_slow_path_word, (6 * SZREG), $r_sp)
274 - bpf_slow_path_common(4)
275 -#ifdef CONFIG_CPU_LITTLE_ENDIAN
276 -# if MIPS_ISA_REV >= 2
285 - andi t2, t2, 0xff00
286 - andi t1, $r_s0, 0xff00
297 - END(bpf_slow_path_word)
299 -NESTED(bpf_slow_path_half, (6 * SZREG), $r_sp)
300 - bpf_slow_path_common(2)
301 -#ifdef CONFIG_CPU_LITTLE_ENDIAN
302 -# if MIPS_ISA_REV >= 2
307 - andi t1, $r_s0, 0xff00
308 - andi t0, t0, 0xff00
318 - END(bpf_slow_path_half)
320 -NESTED(bpf_slow_path_byte, (6 * SZREG), $r_sp)
321 - bpf_slow_path_common(1)
325 - END(bpf_slow_path_byte)
328 - * Negative entry points
330 - .macro bpf_is_end_of_data
332 - /* Reading link layer data? */
335 - /* Be careful what follows in DS. */
338 - * call skb_copy_bits:
339 - * (prototype in linux/filter.h)
341 - * void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb,
342 - * int k, unsigned int size)
344 - * see above (bpf_slow_path_common) for ABI restrictions
346 -#define bpf_negative_common(SIZE) \
347 - PTR_ADDIU $r_sp, $r_sp, -(6 * SZREG); \
348 - PTR_LA t0, bpf_internal_load_pointer_neg_helper; \
349 - PTR_S $r_ra, (5 * SZREG)($r_sp); \
352 - PTR_L $r_ra, (5 * SZREG)($r_sp); \
353 - /* Check return pointer */ \
355 - PTR_ADDIU $r_sp, $r_sp, 6 * SZREG; \
356 - /* Preserve our pointer */ \
358 - /* Set return value */ \
359 - move $r_ret, zero; \
361 -bpf_slow_path_word_neg:
363 -NESTED(sk_load_word_negative, (6 * SZREG), $r_sp)
364 - bpf_negative_common(4)
367 - END(sk_load_word_negative)
369 -bpf_slow_path_half_neg:
371 -NESTED(sk_load_half_negative, (6 * SZREG), $r_sp)
372 - bpf_negative_common(2)
375 - END(sk_load_half_negative)
377 -bpf_slow_path_byte_neg:
379 -NESTED(sk_load_byte_negative, (6 * SZREG), $r_sp)
380 - bpf_negative_common(1)
383 - END(sk_load_byte_negative)
387 - addiu $r_ret, zero, 1