aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/core.c
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2018-12-07 16:30:49 -0500
committerAlexei Starovoitov <ast@kernel.org>2018-12-07 16:30:49 -0500
commit6baefa1aa46f0e90aefbd13b8c926e89068fabba (patch)
tree376ae3306dbeee7a83d76f705159e7de1d61b464 /kernel/bpf/core.c
parent17f6c83fb5ebf7db4fcc94a5be4c22d5a7bfe428 (diff)
parentc099f3f413f354ecdd518e4be6a232592e91d5b9 (diff)
Merge branch 'support-alu32_arsh'
Jiong Wang says: ==================== BPF_ALU | BPF_ARSH | BPF_* were rejected by commit: 7891a87efc71 ("bpf: arsh is not supported in 32 bit alu thus reject it"). As explained in the commit message, this is due to there is no complete support for them on interpreter and various JIT compilation back-ends. This patch set is a follow-up which completes the missing bits. This also pave the way for running bpf program compiled with ALU32 instruction enabled by specifing -mattr=+alu32 to LLVM for which case there is likely to have more BPF_ALU | BPF_ARSH insns that will trigger the rejection code. test_verifier.c is updated accordingly. I have tested this patch set on x86-64 and NFP, I need help of review and test on the arch changes (mips/ppc/s390). Note, there might be merge confict on mips change which is better to be applied on top of: commit: 20b880a05f06 ("mips: bpf: fix encoding bug for mm_srlv32_op"), which is on mips-fixes branch at the moment. Thanks. v1->v2: - Fix ppc implementation bug. Should zero high bits explicitly. ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/core.c')
-rw-r--r--kernel/bpf/core.c52
1 files changed, 30 insertions, 22 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 628b3970a49b..a5b223ef7131 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -933,32 +933,34 @@ EXPORT_SYMBOL_GPL(__bpf_call_base);
933#define BPF_INSN_MAP(INSN_2, INSN_3) \ 933#define BPF_INSN_MAP(INSN_2, INSN_3) \
934 /* 32 bit ALU operations. */ \ 934 /* 32 bit ALU operations. */ \
935 /* Register based. */ \ 935 /* Register based. */ \
936 INSN_3(ALU, ADD, X), \ 936 INSN_3(ALU, ADD, X), \
937 INSN_3(ALU, SUB, X), \ 937 INSN_3(ALU, SUB, X), \
938 INSN_3(ALU, AND, X), \ 938 INSN_3(ALU, AND, X), \
939 INSN_3(ALU, OR, X), \ 939 INSN_3(ALU, OR, X), \
940 INSN_3(ALU, LSH, X), \ 940 INSN_3(ALU, LSH, X), \
941 INSN_3(ALU, RSH, X), \ 941 INSN_3(ALU, RSH, X), \
942 INSN_3(ALU, XOR, X), \ 942 INSN_3(ALU, XOR, X), \
943 INSN_3(ALU, MUL, X), \ 943 INSN_3(ALU, MUL, X), \
944 INSN_3(ALU, MOV, X), \ 944 INSN_3(ALU, MOV, X), \
945 INSN_3(ALU, DIV, X), \ 945 INSN_3(ALU, ARSH, X), \
946 INSN_3(ALU, MOD, X), \ 946 INSN_3(ALU, DIV, X), \
947 INSN_3(ALU, MOD, X), \
947 INSN_2(ALU, NEG), \ 948 INSN_2(ALU, NEG), \
948 INSN_3(ALU, END, TO_BE), \ 949 INSN_3(ALU, END, TO_BE), \
949 INSN_3(ALU, END, TO_LE), \ 950 INSN_3(ALU, END, TO_LE), \
950 /* Immediate based. */ \ 951 /* Immediate based. */ \
951 INSN_3(ALU, ADD, K), \ 952 INSN_3(ALU, ADD, K), \
952 INSN_3(ALU, SUB, K), \ 953 INSN_3(ALU, SUB, K), \
953 INSN_3(ALU, AND, K), \ 954 INSN_3(ALU, AND, K), \
954 INSN_3(ALU, OR, K), \ 955 INSN_3(ALU, OR, K), \
955 INSN_3(ALU, LSH, K), \ 956 INSN_3(ALU, LSH, K), \
956 INSN_3(ALU, RSH, K), \ 957 INSN_3(ALU, RSH, K), \
957 INSN_3(ALU, XOR, K), \ 958 INSN_3(ALU, XOR, K), \
958 INSN_3(ALU, MUL, K), \ 959 INSN_3(ALU, MUL, K), \
959 INSN_3(ALU, MOV, K), \ 960 INSN_3(ALU, MOV, K), \
960 INSN_3(ALU, DIV, K), \ 961 INSN_3(ALU, ARSH, K), \
961 INSN_3(ALU, MOD, K), \ 962 INSN_3(ALU, DIV, K), \
963 INSN_3(ALU, MOD, K), \
962 /* 64 bit ALU operations. */ \ 964 /* 64 bit ALU operations. */ \
963 /* Register based. */ \ 965 /* Register based. */ \
964 INSN_3(ALU64, ADD, X), \ 966 INSN_3(ALU64, ADD, X), \
@@ -1137,6 +1139,12 @@ select_insn:
1137 DST = (u64) (u32) insn[0].imm | ((u64) (u32) insn[1].imm) << 32; 1139 DST = (u64) (u32) insn[0].imm | ((u64) (u32) insn[1].imm) << 32;
1138 insn++; 1140 insn++;
1139 CONT; 1141 CONT;
1142 ALU_ARSH_X:
1143 DST = (u64) (u32) ((*(s32 *) &DST) >> SRC);
1144 CONT;
1145 ALU_ARSH_K:
1146 DST = (u64) (u32) ((*(s32 *) &DST) >> IMM);
1147 CONT;
1140 ALU64_ARSH_X: 1148 ALU64_ARSH_X:
1141 (*(s64 *) &DST) >>= SRC; 1149 (*(s64 *) &DST) >>= SRC;
1142 CONT; 1150 CONT;