MIPS: Implement eBPF JIT.
Subsystems (6)
v2 cover MIPS: Implement eBPF JIT.
Changes in v2:
- Squash a couple of the uasm cleanups.
- Make insn_table_MM const (suggested by Matt Redfearn)
- Put the eBPF in its own source file (should fix build warnings/errors on 32-bit kernel builds).
- Use bpf_jit_binary_alloc() (suggested by Daniel Borkmann)
- Implement tail calls.
- Fix system call tracing to extract arguments for kprobe/__seccomp_filter() tracing (perhaps not really part the the JIT, but necessary to have fun with the samples/bpf programs).
Most things in samples/bpf work, still working on the incantations to build tools/testing/selftests/bpf/ ...
Quoted 1 line
From v1:
The first three patches improve MIPS uasm in preparation for use by the JIT. Then the eBPF JIT implementation.
I am CCing netdev@ and the BPF maintainers for their comments, but would expect Ralf to merge via the MIPS tree if and when it all looks good.
David Daney (5):
MIPS: Optimize uasm insn lookup.
MIPS: Correctly define DBSHFL type instruction opcodes.
MIPS: Add some instructions to uasm.
MIPS: Add support for eBPF JIT.
MIPS: Give __secure_computing() access to syscall arguments.
arch/mips/Kconfig | 12 +- arch/mips/include/asm/uasm.h | 30 + arch/mips/include/uapi/asm/inst.h | 9 +- arch/mips/kernel/ptrace.c | 22 +- arch/mips/mm/uasm-micromips.c | 188 ++-- arch/mips/mm/uasm-mips.c | 238 ++--- arch/mips/mm/uasm.c | 61 +- arch/mips/net/Makefile | 3 +- arch/mips/net/ebpf_jit.c | 1949 +++++++++++++++++++++++++++++++++++++ 9 files changed, 2285 insertions(+), 227 deletions(-) create mode 100644 arch/mips/net/ebpf_jit.c
Signature · 1 line
2.9.4
PATCH v2 1/5 MIPS: Optimize uasm insn lookup.
Instead of doing a linear search through the insn_table for each instruction, use the opcode as direct index into the table. This will give constant time lookup performance as the number of supported opcodes increases. Make the tables const as they are only ever read. For uasm-mips.c sort the table alphabetically, and remove duplicate entries, uasm-micromips.c was already sorted and duplicate free. There is a small savings in object size as struct insn loses a field:
$ size arch/mips/mm/uasm-mips.o arch/mips/mm/uasm-mips.o.save text data bss dec hex filename 10040 0 0 10040 2738 arch/mips/mm/uasm-mips.o 9240 1120 0 10360 2878 arch/mips/mm/uasm-mips.o.save
--- arch/mips/mm/uasm-micromips.c | 188 ++++++++++++++++++------------------ arch/mips/mm/uasm-mips.c | 217 +++++++++++++++++++++--------------------- arch/mips/mm/uasm.c | 3 +- 3 files changed, 199 insertions(+), 209 deletions(-)
arch/mips/mm/uasm-micromips.c +92 -96
@@ -40,93 +40,92 @@#include "uasm.c" -static struct insn insn_table_MM[] = { - { insn_addu,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_addu32_op),RT |RS |RD }, - { insn_addiu,M (mm_addiu32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, - { insn_and,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_and_op),RT |RS |RD }, - { insn_andi,M (mm_andi32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |UIMM }, - { insn_beq,M (mm_beq32_op,0 ,0 ,0 ,0 ,0 ),RS |RT |BIMM }, - { insn_beql,0 ,0 }, - { insn_bgez,M (mm_pool32i_op, mm_bgez_op,0 ,0 ,0 ,0 ),RS |BIMM }, - { insn_bgezl,0 ,0 }, - { insn_bltz,M (mm_pool32i_op, mm_bltz_op,0 ,0 ,0 ,0 ),RS |BIMM }, - { insn_bltzl,0 ,0 }, - { insn_bne,M (mm_bne32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |BIMM }, - { insn_cache,M (mm_pool32b_op,0 ,0 , mm_cache_func,0 ,0 ),RT |RS |SIMM }, - { insn_cfc1,M (mm_pool32f_op,0 ,0 ,0 , mm_cfc1_op, mm_32f_73_op),RT |RS }, - { insn_cfcmsa,M (mm_pool32s_op,0 , msa_cfc_op,0 ,0 , mm_32s_elm_op),RD |RE }, - { insn_ctc1,M (mm_pool32f_op,0 ,0 ,0 , mm_ctc1_op, mm_32f_73_op),RT |RS }, - { insn_ctcmsa,M (mm_pool32s_op,0 , msa_ctc_op,0 ,0 , mm_32s_elm_op),RD |RE }, - { insn_daddu,0 ,0 }, - { insn_daddiu,0 ,0 }, - { insn_di,M (mm_pool32a_op,0 ,0 ,0 , mm_di_op, mm_pool32axf_op),RS }, - { insn_divu,M (mm_pool32a_op,0 ,0 ,0 , mm_divu_op, mm_pool32axf_op),RT |RS }, - { insn_dmfc0,0 ,0 }, - { insn_dmtc0,0 ,0 }, - { insn_dsll,0 ,0 }, - { insn_dsll32,0 ,0 }, - { insn_dsra,0 ,0 }, - { insn_dsrl,0 ,0 }, - { insn_dsrl32,0 ,0 }, - { insn_drotr,0 ,0 }, - { insn_drotr32,0 ,0 }, - { insn_dsubu,0 ,0 }, - { insn_eret,M (mm_pool32a_op,0 ,0 ,0 , mm_eret_op, mm_pool32axf_op),0 }, - { insn_ins,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_ins_op),RT |RS |RD |RE }, - { insn_ext,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_ext_op),RT |RS |RD |RE }, - { insn_j,M (mm_j32_op,0 ,0 ,0 ,0 ,0 ),JIMM }, - { insn_jal,M (mm_jal32_op,0 ,0 ,0 ,0 ,0 ),JIMM }, - { insn_jalr,M (mm_pool32a_op,0 ,0 ,0 , mm_jalr_op, mm_pool32axf_op),RT |RS }, - { insn_jr,M (mm_pool32a_op,0 ,0 ,0 , mm_jalr_op, mm_pool32axf_op),RS }, - { insn_lb,M (mm_lb32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, - { insn_ld,0 ,0 }, - { insn_lh,M (mm_lh32_op,0 ,0 ,0 ,0 ,0 ),RS |RS |SIMM }, - { insn_ll,M (mm_pool32c_op,0 ,0 , (mm_ll_func <<1 ),0 ,0 ),RS |RT |SIMM }, - { insn_lld,0 ,0 }, - { insn_lui,M (mm_pool32i_op, mm_lui_op,0 ,0 ,0 ,0 ),RS |SIMM }, - { insn_lw,M (mm_lw32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, - { insn_mfc0,M (mm_pool32a_op,0 ,0 ,0 , mm_mfc0_op, mm_pool32axf_op),RT |RS |RD }, - { insn_mfhi,M (mm_pool32a_op,0 ,0 ,0 , mm_mfhi32_op, mm_pool32axf_op),RS }, - { insn_mflo,M (mm_pool32a_op,0 ,0 ,0 , mm_mflo32_op, mm_pool32axf_op),RS }, - { insn_mtc0,M (mm_pool32a_op,0 ,0 ,0 , mm_mtc0_op, mm_pool32axf_op),RT |RS |RD }, - { insn_mthi,M (mm_pool32a_op,0 ,0 ,0 , mm_mthi32_op, mm_pool32axf_op),RS }, - { insn_mtlo,M (mm_pool32a_op,0 ,0 ,0 , mm_mtlo32_op, mm_pool32axf_op),RS }, - { insn_mul,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_mul_op),RT |RS |RD }, - { insn_or,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_or32_op),RT |RS |RD }, - { insn_ori,M (mm_ori32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |UIMM }, - { insn_pref,M (mm_pool32c_op,0 ,0 , (mm_pref_func <<1 ),0 ,0 ),RT |RS |SIMM }, - { insn_rfe,0 ,0 }, - { insn_sc,M (mm_pool32c_op,0 ,0 , (mm_sc_func <<1 ),0 ,0 ),RT |RS |SIMM }, - { insn_scd,0 ,0 }, - { insn_sd,0 ,0 }, - { insn_sll,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_sll32_op),RT |RS |RD }, - { insn_sllv,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_sllv32_op),RT |RS |RD }, - { insn_slt,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_slt_op),RT |RS |RD }, - { insn_sltiu,M (mm_sltiu32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, - { insn_sltu,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_sltu_op),RT |RS |RD }, - { insn_sra,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_sra_op),RT |RS |RD }, - { insn_srl,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_srl32_op),RT |RS |RD }, - { insn_srlv,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_srlv32_op),RT |RS |RD }, - { insn_rotr,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_rotr_op),RT |RS |RD }, - { insn_subu,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_subu32_op),RT |RS |RD }, - { insn_sw,M (mm_sw32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, - { insn_sync,M (mm_pool32a_op,0 ,0 ,0 , mm_sync_op, mm_pool32axf_op),RS }, - { insn_tlbp,M (mm_pool32a_op,0 ,0 ,0 , mm_tlbp_op, mm_pool32axf_op),0 }, - { insn_tlbr,M (mm_pool32a_op,0 ,0 ,0 , mm_tlbr_op, mm_pool32axf_op),0 }, - { insn_tlbwi,M (mm_pool32a_op,0 ,0 ,0 , mm_tlbwi_op, mm_pool32axf_op),0 }, - { insn_tlbwr,M (mm_pool32a_op,0 ,0 ,0 , mm_tlbwr_op, mm_pool32axf_op),0 }, - { insn_wait,M (mm_pool32a_op,0 ,0 ,0 , mm_wait_op, mm_pool32axf_op),SCIMM }, - { insn_wsbh,M (mm_pool32a_op,0 ,0 ,0 , mm_wsbh_op, mm_pool32axf_op),RT |RS }, - { insn_xor,M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_xor32_op),RT |RS |RD }, - { insn_xori,M (mm_xori32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |UIMM }, - { insn_dins,0 ,0 }, - { insn_dinsm,0 ,0 }, - { insn_syscall,M (mm_pool32a_op,0 ,0 ,0 , mm_syscall_op, mm_pool32axf_op),SCIMM }, - { insn_bbit0,0 ,0 }, - { insn_bbit1,0 ,0 }, - { insn_lwx,0 ,0 }, - { insn_ldx,0 ,0 }, - { insn_invalid,0 ,0 } +static const struct insn const insn_table_MM[insn_invalid] = { + [insn_addu] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_addu32_op),RT |RS |RD }, + [insn_addiu] = {M (mm_addiu32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, + [insn_and] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_and_op),RT |RS |RD }, + [insn_andi] = {M (mm_andi32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |UIMM }, + [insn_beq] = {M (mm_beq32_op,0 ,0 ,0 ,0 ,0 ),RS |RT |BIMM }, + [insn_beql] = {0 ,0 }, + [insn_bgez] = {M (mm_pool32i_op, mm_bgez_op,0 ,0 ,0 ,0 ),RS |BIMM }, + [insn_bgezl] = {0 ,0 }, + [insn_bltz] = {M (mm_pool32i_op, mm_bltz_op,0 ,0 ,0 ,0 ),RS |BIMM }, + [insn_bltzl] = {0 ,0 }, + [insn_bne] = {M (mm_bne32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |BIMM }, + [insn_cache] = {M (mm_pool32b_op,0 ,0 , mm_cache_func,0 ,0 ),RT |RS |SIMM }, + [insn_cfc1] = {M (mm_pool32f_op,0 ,0 ,0 , mm_cfc1_op, mm_32f_73_op),RT |RS }, + [insn_cfcmsa] = {M (mm_pool32s_op,0 , msa_cfc_op,0 ,0 , mm_32s_elm_op),RD |RE }, + [insn_ctc1] = {M (mm_pool32f_op,0 ,0 ,0 , mm_ctc1_op, mm_32f_73_op),RT |RS }, + [insn_ctcmsa] = {M (mm_pool32s_op,0 , msa_ctc_op,0 ,0 , mm_32s_elm_op),RD |RE }, + [insn_daddu] = {0 ,0 }, + [insn_daddiu] = {0 ,0 }, + [insn_di] = {M (mm_pool32a_op,0 ,0 ,0 , mm_di_op, mm_pool32axf_op),RS }, + [insn_divu] = {M (mm_pool32a_op,0 ,0 ,0 , mm_divu_op, mm_pool32axf_op),RT |RS }, + [insn_dmfc0] = {0 ,0 }, + [insn_dmtc0] = {0 ,0 }, + [insn_dsll] = {0 ,0 }, + [insn_dsll32] = {0 ,0 }, + [insn_dsra] = {0 ,0 }, + [insn_dsrl] = {0 ,0 }, + [insn_dsrl32] = {0 ,0 }, + [insn_drotr] = {0 ,0 }, + [insn_drotr32] = {0 ,0 }, + [insn_dsubu] = {0 ,0 }, + [insn_eret] = {M (mm_pool32a_op,0 ,0 ,0 , mm_eret_op, mm_pool32axf_op),0 }, + [insn_ins] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_ins_op),RT |RS |RD |RE }, + [insn_ext] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_ext_op),RT |RS |RD |RE }, + [insn_j] = {M (mm_j32_op,0 ,0 ,0 ,0 ,0 ),JIMM }, + [insn_jal] = {M (mm_jal32_op,0 ,0 ,0 ,0 ,0 ),JIMM }, + [insn_jalr] = {M (mm_pool32a_op,0 ,0 ,0 , mm_jalr_op, mm_pool32axf_op),RT |RS }, + [insn_jr] = {M (mm_pool32a_op,0 ,0 ,0 , mm_jalr_op, mm_pool32axf_op),RS }, + [insn_lb] = {M (mm_lb32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, + [insn_ld] = {0 ,0 }, + [insn_lh] = {M (mm_lh32_op,0 ,0 ,0 ,0 ,0 ),RS |RS |SIMM }, + [insn_ll] = {M (mm_pool32c_op,0 ,0 , (mm_ll_func <<1 ),0 ,0 ),RS |RT |SIMM }, + [insn_lld] = {0 ,0 }, + [insn_lui] = {M (mm_pool32i_op, mm_lui_op,0 ,0 ,0 ,0 ),RS |SIMM }, + [insn_lw] = {M (mm_lw32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, + [insn_mfc0] = {M (mm_pool32a_op,0 ,0 ,0 , mm_mfc0_op, mm_pool32axf_op),RT |RS |RD }, + [insn_mfhi] = {M (mm_pool32a_op,0 ,0 ,0 , mm_mfhi32_op, mm_pool32axf_op),RS }, + [insn_mflo] = {M (mm_pool32a_op,0 ,0 ,0 , mm_mflo32_op, mm_pool32axf_op),RS }, + [insn_mtc0] = {M (mm_pool32a_op,0 ,0 ,0 , mm_mtc0_op, mm_pool32axf_op),RT |RS |RD }, + [insn_mthi] = {M (mm_pool32a_op,0 ,0 ,0 , mm_mthi32_op, mm_pool32axf_op),RS }, + [insn_mtlo] = {M (mm_pool32a_op,0 ,0 ,0 , mm_mtlo32_op, mm_pool32axf_op),RS }, + [insn_mul] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_mul_op),RT |RS |RD }, + [insn_or] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_or32_op),RT |RS |RD }, + [insn_ori] = {M (mm_ori32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |UIMM }, + [insn_pref] = {M (mm_pool32c_op,0 ,0 , (mm_pref_func <<1 ),0 ,0 ),RT |RS |SIMM }, + [insn_rfe] = {0 ,0 }, + [insn_sc] = {M (mm_pool32c_op,0 ,0 , (mm_sc_func <<1 ),0 ,0 ),RT |RS |SIMM }, + [insn_scd] = {0 ,0 }, + [insn_sd] = {0 ,0 }, + [insn_sll] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_sll32_op),RT |RS |RD }, + [insn_sllv] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_sllv32_op),RT |RS |RD }, + [insn_slt] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_slt_op),RT |RS |RD }, + [insn_sltiu] = {M (mm_sltiu32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, + [insn_sltu] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_sltu_op),RT |RS |RD }, + [insn_sra] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_sra_op),RT |RS |RD }, + [insn_srl] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_srl32_op),RT |RS |RD }, + [insn_srlv] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_srlv32_op),RT |RS |RD }, + [insn_rotr] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_rotr_op),RT |RS |RD }, + [insn_subu] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_subu32_op),RT |RS |RD }, + [insn_sw] = {M (mm_sw32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |SIMM }, + [insn_sync] = {M (mm_pool32a_op,0 ,0 ,0 , mm_sync_op, mm_pool32axf_op),RS }, + [insn_tlbp] = {M (mm_pool32a_op,0 ,0 ,0 , mm_tlbp_op, mm_pool32axf_op),0 }, + [insn_tlbr] = {M (mm_pool32a_op,0 ,0 ,0 , mm_tlbr_op, mm_pool32axf_op),0 }, + [insn_tlbwi] = {M (mm_pool32a_op,0 ,0 ,0 , mm_tlbwi_op, mm_pool32axf_op),0 }, + [insn_tlbwr] = {M (mm_pool32a_op,0 ,0 ,0 , mm_tlbwr_op, mm_pool32axf_op),0 }, + [insn_wait] = {M (mm_pool32a_op,0 ,0 ,0 , mm_wait_op, mm_pool32axf_op),SCIMM }, + [insn_wsbh] = {M (mm_pool32a_op,0 ,0 ,0 , mm_wsbh_op, mm_pool32axf_op),RT |RS }, + [insn_xor] = {M (mm_pool32a_op,0 ,0 ,0 ,0 , mm_xor32_op),RT |RS |RD }, + [insn_xori] = {M (mm_xori32_op,0 ,0 ,0 ,0 ,0 ),RT |RS |UIMM }, + [insn_dins] = {0 ,0 }, + [insn_dinsm] = {0 ,0 }, + [insn_syscall] = {M (mm_pool32a_op,0 ,0 ,0 , mm_syscall_op, mm_pool32axf_op),SCIMM }, + [insn_bbit0] = {0 ,0 }, + [insn_bbit1] = {0 ,0 }, + [insn_lwx] = {0 ,0 }, + [insn_ldx] = {0 ,0 }, };#undef M
@@ -156,20 +155,17 @@ static inline u32 build_jimm(u32 arg)*/ static void build_insn (u32 **buf,enum opcode opc, ...) { -struct insn *ip =NULL ; -unsigned int i; +const struct insn *ip;va_list ap;u32 op; -for (i =0 ; insn_table_MM[i].opcode != insn_invalid; i++) -if (insn_table_MM[i].opcode == opc) { - ip = &insn_table_MM[i]; -break ; - } - -if (!ip || (opc == insn_daddiu &&r4k_daddiu_bug ())) +if (opc <0 || opc >= insn_invalid || + (opc == insn_daddiu &&r4k_daddiu_bug ()) || + (insn_table_MM[opc].match ==0 && insn_table_MM[opc].fields ==0 ))panic ("Unsupported Micro-assembler instruction %d" , opc); + ip = &insn_table_MM[opc]; + op = ip->match;va_start (ap, opc);if (ip->fields &RS ) {
arch/mips/mm/uasm-mips.c +106 -111
252 lines not on this page · raw message
arch/mips/mm/uasm.c +1 -2
@@ -46,7 +46,6 @@ enum fields {#define SIMM9_MASK 0x1ffenum opcode { - insn_invalid, insn_addiu, insn_addu, insn_and, insn_andi, insn_bbit0, insn_bbit1, insn_beq, insn_beql, insn_bgez, insn_bgezl, insn_bltz, insn_bltzl, insn_bne, insn_cache, insn_cfc1, insn_cfcmsa, insn_ctc1, insn_ctcmsa,
@@ -62,10 +61,10 @@ enum opcode { insn_srlv, insn_subu, insn_sw, insn_sync, insn_syscall, insn_tlbp, insn_tlbr, insn_tlbwi, insn_tlbwr, insn_wait, insn_wsbh, insn_xor, insn_xori, insn_yield, insn_lddir, insn_ldpte, insn_lhu, + insn_invalid/* insn_invalid must be last */ };struct insn { -enum opcode opcode;u32 match;enum fields fields; };
Signature · 1 line
2.9.4
PATCH v2 2/5 MIPS: Correctly define DBSHFL type instruction opcodes.
In reply to David DaneyDSHD was incorrectly classified as being BSHFL, and DSHD was missing altogether.
--- arch/mips/include/uapi/asm/inst.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/mips/include/uapi/asm/inst.h +8 -1
@@ -276,12 +276,19 @@ enum lx_func {*/ enum bshfl_func { wsbh_op =0x2 , - dshd_op =0x5 , seb_op =0x10 , seh_op =0x18 , };/* +* DBSHFL opcodes +*/ +enum dbshfl_func { + dsbh_op =0x2 , + dshd_op =0x5 , +}; + +/* * MSA minor opcodes. */ enum msa_func {
Signature · 1 line
2.9.4
PATCH v2 3/5 MIPS: Add some instructions to uasm.
In reply to David DaneyFollow on patches for eBPF JIT require these additional instructions:
insn_bgtz, insn_blez, insn_break, insn_ddivu, insn_dmultu, insn_dsbh, insn_dshd, insn_dsllv, insn_dsra32, insn_dsrav, insn_dsrlv, insn_lbu, insn_movn, insn_movz, insn_multu, insn_nor, insn_sb, insn_sh, insn_slti, insn_dinsu, insn_lwu
... so, add them.
Sort the insn_* enumeration values alphabetically.
--- arch/mips/include/asm/uasm.h | 30 +++++++++++++++++++++++ arch/mips/mm/uasm-mips.c | 21 ++++++++++++++++ arch/mips/mm/uasm.c | 58 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 96 insertions(+), 13 deletions(-)
arch/mips/include/asm/uasm.h +30 -0
@@ -72,9 +72,12 @@ Ip_u1u2s3(_beq);Ip_u1u2s3 (_beql);Ip_u1s2 (_bgez);Ip_u1s2 (_bgezl); +Ip_u1s2 (_bgtz); +Ip_u1s2 (_blez);Ip_u1s2 (_bltz);Ip_u1s2 (_bltzl);Ip_u1u2s3 (_bne); +Ip_u1 (_break);Ip_u2s3u1 (_cache);Ip_u1u2 (_cfc1);Ip_u2u1 (_cfcmsa);
@@ -82,19 +85,28 @@ Ip_u1u2(_ctc1);Ip_u2u1 (_ctcmsa);Ip_u2u1s3 (_daddiu);Ip_u3u1u2 (_daddu); +Ip_u1u2 (_ddivu);Ip_u1 (_di);Ip_u2u1msbu3 (_dins);Ip_u2u1msbu3 (_dinsm); +Ip_u2u1msbu3 (_dinsu);Ip_u1u2 (_divu);Ip_u1u2u3 (_dmfc0);Ip_u1u2u3 (_dmtc0); +Ip_u1u2 (_dmultu);Ip_u2u1u3 (_drotr);Ip_u2u1u3 (_drotr32); +Ip_u2u1 (_dsbh); +Ip_u2u1 (_dshd);Ip_u2u1u3 (_dsll);Ip_u2u1u3 (_dsll32); +Ip_u3u2u1 (_dsllv);Ip_u2u1u3 (_dsra); +Ip_u2u1u3 (_dsra32); +Ip_u3u2u1 (_dsrav);Ip_u2u1u3 (_dsrl);Ip_u2u1u3 (_dsrl32); +Ip_u3u2u1 (_dsrlv);Ip_u3u1u2 (_dsubu);Ip_0 (_eret);Ip_u2u1msbu3 (_ext);
@@ -104,6 +116,7 @@ Ip_u1(_jal);Ip_u2u1 (_jalr);Ip_u1 (_jr);Ip_u2s3u1 (_lb); +Ip_u2s3u1 (_lbu);Ip_u2s3u1 (_ld);Ip_u3u1u2 (_ldx);Ip_u2s3u1 (_lh);
@@ -112,27 +125,35 @@ Ip_u2s3u1(_ll);Ip_u2s3u1 (_lld);Ip_u1s2 (_lui);Ip_u2s3u1 (_lw); +Ip_u2s3u1 (_lwu);Ip_u3u1u2 (_lwx);Ip_u1u2u3 (_mfc0);Ip_u1u2u3 (_mfhc0);Ip_u1 (_mfhi);Ip_u1 (_mflo); +Ip_u3u1u2 (_movn); +Ip_u3u1u2 (_movz);Ip_u1u2u3 (_mtc0);Ip_u1u2u3 (_mthc0);Ip_u1 (_mthi);Ip_u1 (_mtlo);Ip_u3u1u2 (_mul); +Ip_u1u2 (_multu); +Ip_u3u1u2 (_nor);Ip_u3u1u2 (_or);Ip_u2u1u3 (_ori);Ip_u2s3u1 (_pref);Ip_0 (_rfe);Ip_u2u1u3 (_rotr); +Ip_u2s3u1 (_sb);Ip_u2s3u1 (_sc);Ip_u2s3u1 (_scd);Ip_u2s3u1 (_sd); +Ip_u2s3u1 (_sh);Ip_u2u1u3 (_sll);Ip_u3u2u1 (_sllv);Ip_s3s1s2 (_slt); +Ip_u2u1s3 (_slti);Ip_u2u1s3 (_sltiu);Ip_u3u1u2 (_sltu);Ip_u2u1u3 (_sra);
@@ -248,6 +269,15 @@ static inline void uasm_i_dsrl_safe(u32 **p, unsigned int a1,uasm_i_dsrl32 (p, a1, a2, a3 -32 ); } +static inline void uasm_i_dsra_safe (u32 **p,unsigned int a1, +unsigned int a2,unsigned int a3) +{ +if (a3 <32 ) +uasm_i_dsra (p, a1, a2, a3); +else +uasm_i_dsra32 (p, a1, a2, a3 -32 ); +} +/* Handle relocations. */ struct uasm_reloc {u32 *addr;
arch/mips/mm/uasm-mips.c +21 -0
@@ -59,9 +59,12 @@ static const struct insn const insn_table[insn_invalid] = { [insn_beql] = {M(beql_op, 0, 0, 0, 0, 0), RS | RT | BIMM}, [insn_bgez] = {M(bcond_op, 0, bgez_op, 0, 0, 0), RS | BIMM}, [insn_bgezl] = {M(bcond_op, 0, bgezl_op, 0, 0, 0), RS | BIMM}, + [insn_bgtz] = {M(bgtz_op, 0, 0, 0, 0, 0), RS | BIMM}, + [insn_blez] = {M(blez_op, 0, 0, 0, 0, 0), RS | BIMM}, [insn_bltz] = {M(bcond_op, 0, bltz_op, 0, 0, 0), RS | BIMM}, [insn_bltzl] = {M(bcond_op, 0, bltzl_op, 0, 0, 0), RS | BIMM}, [insn_bne] = {M(bne_op, 0, 0, 0, 0, 0), RS | RT | BIMM}, + [insn_break] = {M (spec_op,0 ,0 ,0 ,0 , break_op),SCIMM }, #ifndef CONFIG_CPU_MIPSR6 [insn_cache] = {M(cache_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, #else
@@ -73,19 +76,28 @@ static const struct insn const insn_table[insn_invalid] = { [insn_ctcmsa] = {M(msa_op, 0, msa_ctc_op, 0, 0, msa_elm_op), RD | RE}, [insn_daddiu] = {M(daddiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_daddu] = {M(spec_op, 0, 0, 0, 0, daddu_op), RS | RT | RD}, + [insn_ddivu] = {M(spec_op, 0, 0, 0, 0, ddivu_op), RS | RT}, [insn_di] = {M(cop0_op, mfmc0_op, 0, 12, 0, 0), RT}, [insn_dins] = {M(spec3_op, 0, 0, 0, 0, dins_op), RS | RT | RD | RE}, [insn_dinsm] = {M(spec3_op, 0, 0, 0, 0, dinsm_op), RS | RT | RD | RE}, + [insn_dinsu] = {M(spec3_op, 0, 0, 0, 0, dinsu_op), RS | RT | RD | RE}, [insn_divu] = {M(spec_op, 0, 0, 0, 0, divu_op), RS | RT}, [insn_dmfc0] = {M(cop0_op, dmfc_op, 0, 0, 0, 0), RT | RD | SET}, [insn_dmtc0] = {M(cop0_op, dmtc_op, 0, 0, 0, 0), RT | RD | SET}, + [insn_dmultu] = {M(spec_op, 0, 0, 0, 0, dmultu_op), RS | RT}, [insn_drotr] = {M(spec_op, 1, 0, 0, 0, dsrl_op), RT | RD | RE}, [insn_drotr32] = {M(spec_op, 1, 0, 0, 0, dsrl32_op), RT | RD | RE}, + [insn_dsbh] = {M(spec3_op, 0, 0, 0, dsbh_op, dbshfl_op), RT | RD}, + [insn_dshd] = {M(spec3_op, 0, 0, 0, dshd_op, dbshfl_op), RT | RD}, [insn_dsll] = {M(spec_op, 0, 0, 0, 0, dsll_op), RT | RD | RE}, [insn_dsll32] = {M(spec_op, 0, 0, 0, 0, dsll32_op), RT | RD | RE}, + [insn_dsllv] = {M(spec_op, 0, 0, 0, 0, dsllv_op), RS | RT | RD}, [insn_dsra] = {M(spec_op, 0, 0, 0, 0, dsra_op), RT | RD | RE}, + [insn_dsra32] = {M(spec_op, 0, 0, 0, 0, dsra32_op), RT | RD | RE}, + [insn_dsrav] = {M(spec_op, 0, 0, 0, 0, dsrav_op), RS | RT | RD}, [insn_dsrl] = {M(spec_op, 0, 0, 0, 0, dsrl_op), RT | RD | RE}, [insn_dsrl32] = {M(spec_op, 0, 0, 0, 0, dsrl32_op), RT | RD | RE}, + [insn_dsrlv] = {M(spec_op, 0, 0, 0, 0, dsrlv_op), RS | RT | RD}, [insn_dsubu] = {M(spec_op, 0, 0, 0, 0, dsubu_op), RS | RT | RD}, [insn_eret] = {M(cop0_op, cop_op, 0, 0, 0, eret_op), 0}, [insn_ext] = {M(spec3_op, 0, 0, 0, 0, ext_op), RS | RT | RD | RE},
@@ -99,6 +111,7 @@ static const struct insn const insn_table[insn_invalid] = { [insn_jr] = {M(spec_op, 0, 0, 0, 0, jalr_op), RS}, #endif [insn_lb] = {M(lb_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, + [insn_lbu] = {M(lbu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_ld] = {M(ld_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_lddir] = {M(lwc2_op, 0, 0, 0, lddir_op, mult_op), RS | RT | RD}, [insn_ldpte] = {M(lwc2_op, 0, 0, 0, ldpte_op, mult_op), RS | RD},
@@ -114,11 +127,14 @@ static const struct insn const insn_table[insn_invalid] = { #endif [insn_lui] = {M(lui_op, 0, 0, 0, 0, 0), RT | SIMM}, [insn_lw] = {M(lw_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, + [insn_lwu] = {M(lwu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_lwx] = {M(spec3_op, 0, 0, 0, lwx_op, lx_op), RS | RT | RD}, [insn_mfc0] = {M(cop0_op, mfc_op, 0, 0, 0, 0), RT | RD | SET}, [insn_mfhc0] = {M(cop0_op, mfhc0_op, 0, 0, 0, 0), RT | RD | SET}, [insn_mfhi] = {M(spec_op, 0, 0, 0, 0, mfhi_op), RD}, [insn_mflo] = {M(spec_op, 0, 0, 0, 0, mflo_op), RD}, + [insn_movn] = {M(spec_op, 0, 0, 0, 0, movn_op), RS | RT | RD}, + [insn_movz] = {M(spec_op, 0, 0, 0, 0, movz_op), RS | RT | RD}, [insn_mtc0] = {M(cop0_op, mtc_op, 0, 0, 0, 0), RT | RD | SET}, [insn_mthc0] = {M(cop0_op, mthc0_op, 0, 0, 0, 0), RT | RD | SET}, [insn_mthi] = {M(spec_op, 0, 0, 0, 0, mthi_op), RS},
@@ -128,6 +144,8 @@ static const struct insn const insn_table[insn_invalid] = { #else [insn_mul] = {M(spec_op, 0, 0, 0, mult_mul_op, mult_op), RS | RT | RD}, #endif + [insn_multu] = {M(spec_op, 0, 0, 0, 0, multu_op), RS | RT}, + [insn_nor] = {M(spec_op, 0, 0, 0, 0, nor_op), RS | RT | RD}, [insn_or] = {M(spec_op, 0, 0, 0, 0, or_op), RS | RT | RD}, [insn_ori] = {M(ori_op, 0, 0, 0, 0, 0), RS | RT | UIMM}, #ifndef CONFIG_CPU_MIPSR6
@@ -137,6 +155,7 @@ static const struct insn const insn_table[insn_invalid] = { #endif [insn_rfe] = {M(cop0_op, cop_op, 0, 0, 0, rfe_op), 0}, [insn_rotr] = {M(spec_op, 1, 0, 0, 0, srl_op), RT | RD | RE}, + [insn_sb] = {M (sb_op,0 ,0 ,0 ,0 ,0 ),RS |RT |SIMM }, #ifndef CONFIG_CPU_MIPSR6 [insn_sc] = {M(sc_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_scd] = {M(scd_op, 0, 0, 0, 0, 0), RS | RT | SIMM},
@@ -145,9 +164,11 @@ static const struct insn const insn_table[insn_invalid] = { [insn_scd] = {M6(spec3_op, 0, 0, 0, scd6_op), RS | RT | SIMM9}, #endif [insn_sd] = {M(sd_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, + [insn_sh] = {M(sh_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_sll] = {M(spec_op, 0, 0, 0, 0, sll_op), RT | RD | RE}, [insn_sllv] = {M(spec_op, 0, 0, 0, 0, sllv_op), RS | RT | RD}, [insn_slt] = {M(spec_op, 0, 0, 0, 0, slt_op), RS | RT | RD}, + [insn_slti] = {M(slti_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_sltiu] = {M(sltiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, [insn_sltu] = {M(spec_op, 0, 0, 0, 0, sltu_op), RS | RT | RD}, [insn_sra] = {M(spec_op, 0, 0, 0, 0, sra_op), RT | RD | RE},
arch/mips/mm/uasm.c +45 -13
131 lines not on this page · raw message
Signature · 1 line
2.9.4
PATCH v2 4/5 MIPS: Add support for eBPF JIT.
In reply to David DaneySince the eBPF machine has 64-bit registers, we only support this in 64-bit kernels. As of the writing of this commit log test-bpf is showing:
test_bpf: Summary: 316 PASSED, 0 FAILED, [308/308 JIT'ed]
All current test cases are successfully compiled.
Many examples in samples/bpf are usable, specifically tracex5 which uses tail calls works.
--- arch/mips/Kconfig | 12 +- arch/mips/net/Makefile | 3 +- arch/mips/net/ebpf_jit.c | 1949 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1962 insertions(+), 2 deletions(-) create mode 100644 arch/mips/net/ebpf_jit.c
arch/mips/Kconfig +11 -1
@@ -18,7 +18,8 @@ config MIPS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_TRACEHOOK - select HAVE_CBPF_JIT if !CPU_MICROMIPS + select HAVE_CBPF_JIT if (!64BIT && !CPU_MICROMIPS) + select HAVE_EBPF_JIT if (64BIT && !CPU_MICROMIPS) select HAVE_FUNCTION_TRACER select HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD
@@ -1178,6 +1179,15 @@ config SYS_SUPPORTS_RELOCATABLE The platform must provide plat_get_fdt() if it selects CONFIG_USE_OF to allow access to command line and entropy sources. +config MIPS_CBPF_JIT + def_bool y + depends on BPF_JIT && HAVE_CBPF_JIT + +config MIPS_EBPF_JIT + def_bool y + depends on BPF_JIT && HAVE_EBPF_JIT + + # # Endianness selection. Sufficiently obscure so many users don't know what to # answer,so we try hard to limit the available choices. Also the use of a
arch/mips/net/Makefile +2 -1
@@ -1,3 +1,4 @@ # MIPS networking code -obj-$(CONFIG_BPF_JIT) += bpf_jit.o bpf_jit_asm.o +obj-$(CONFIG_MIPS_CBPF_JIT) += bpf_jit.o bpf_jit_asm.o +obj-$(CONFIG_MIPS_EBPF_JIT) += ebpf_jit.o
arch/mips/net/ebpf_jit.c new file +1949 -0
1,949 lines not on this page · raw message
Signature · 1 line
2.9.4
Daniel Borkmann
maintainerRe: [PATCH v2 4/5] MIPS: Add support for eBPF JIT.
Quoted 11 lines · David Daney
Since the eBPF machine has 64-bit registers, we only support this in 64-bit kernels. As of the writing of this commit log test-bpf is showing:
test_bpf: Summary: 316 PASSED, 0 FAILED, [308/308 JIT'ed]All current test cases are successfully compiled.
Many examples in
samples/bpfare usable, specifically tracex5 which uses tail calls works.Signed-off-by David Daney <[email protected]>
Awesome work, David! The bits interacting with core BPF look good to me.
Fyi, when Ralf merges this and it goes later on to Linus, there will be two minor (silent) merge conflicts with net-next tree (depending which one gets there first):
1) In bpf_int_jit_compile(), below the jited = 1 assignment, there needs to come a prog->jited_len = image_size.
2) The internal tail call opcode changed from BPF_JMP | BPF_CALL | BPF_X into BPF_JMP | BPF_TAIL_CALL.
Cheers,
Daniel
Re: [PATCH v2 4/5] MIPS: Add support for eBPF JIT.
In reply to David DaneyHi Ralf,
Quoted 11 lines · David Daney
Since the eBPF machine has 64-bit registers, we only support this in 64-bit kernels. As of the writing of this commit log test-bpf is showing:
test_bpf: Summary: 316 PASSED, 0 FAILED, [308/308 JIT'ed]All current test cases are successfully compiled.
Many examples in
samples/bpfare usable, specifically tracex5 which uses tail calls works.Signed-off-by David Daney <[email protected]>
I think you've misapplied this patch to upstream-sfr. I see the following commit, but it's missing the ebpf_jit.c file.
commit bb45edc82b3c1608026b5a7aeb0876ec31735359
Author: David Daney <[email protected]> Date: Tue Jun 13 15:28:46 2017 -0700
MIPS: Add support for eBPF JIT.
Since the eBPF machine has 64-bit registers, we only support this in 64-bit kernels. As of the writing of this commit log test-bpf is showing:
test_bpf: Summary: 316 PASSED, 0 FAILED, [308/308 JIT'ed]
All current test cases are successfully compiled.
Many examples in samples/bpf are usable, specifically tracex5 which uses tail calls works.
Patchwork: https://patchwork.linux-mips.org/patch/16369/
arch/mips/Kconfig | 12 +++++++++++- arch/mips/net/Makefile | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-)
This is causing my builds to fail with:
make[4]: *** No rule to make target 'arch/mips/net/ebpf_jit.o', needed by 'arch/mips/net/built-in.o'. Stop.
James
PATCH v2 5/5 MIPS: Give __secure_computing() access to syscall arguments.
In reply to David DaneyKProbes of __seccomp_filter() are not very useful without access to the syscall arguments.
Do what x86 does, and populate a struct seccomp_data to be passed to __secure_computing(). This allows samples/bpf/tracex5 to extract a sensible trace.
--- arch/mips/kernel/ptrace.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
arch/mips/kernel/ptrace.c +20 -2
@@ -868,8 +868,26 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall) tracehook_report_syscall_entry(regs))return -1 ; -if (secure_computing (NULL ) ==-1 ) -return -1 ; +#ifdef CONFIG_SECCOMP +if (unlikely (test_thread_flag (TIF_SECCOMP ))) { +int ret, i; +struct seccomp_data sd; + + sd.nr = syscall; + sd.arch =syscall_get_arch (); +for (i =0 ; i <6 ; i++) { +unsigned long v, r; + + r =mips_get_syscall_arg (&v, current, regs, i); + sd.args[i] = r ?0 : v; + } + sd.instruction_pointer =KSTK_EIP (current); + + ret =__secure_computing (&sd); +if (ret ==-1 ) +return ret; + } +#endif if (unlikely (test_thread_flag (TIF_SYSCALL_TRACEPOINT )))trace_sys_enter (regs, regs->regs[2 ]);
Signature · 1 line
2.9.4
Ralf Baechle
AppliedQuoted 21 lines · David Daney
Changes in v2:
- Squash a couple of the uasm cleanups.
- Make
insn_table_MMconst (suggested by Matt Redfearn)- Put the eBPF in its own source file (should fix build warnings/errors on 32-bit kernel builds).
- Use
bpf_jit_binary_alloc()(suggested by Daniel Borkmann)- Implement tail calls.
- Fix system call tracing to extract arguments for kprobe/__seccomp_filter() tracing (perhaps not really part the the JIT, but necessary to have fun with the
samples/bpfprograms).Most things in
samples/bpfwork, still working on the incantations to buildtools/testing/selftests/bpf/...
Quoted 8 lines
Quoted 1 line
From v1:
The first three patches improve MIPS uasm in preparation for use by the JIT. Then the eBPF JIT implementation.
I am CCing netdev@ and the BPF maintainers for their comments, but would expect Ralf to merge via the MIPS tree if and when it all looks good.
Thanks, applied after fixing a minor conflict in arch/mips/Kconfig.
Ralf