bpf, ppc64: implement jiting of BPF_J{LT, LE, SLT, SLE}
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 9 Aug 2017 23:40:00 +0000 (01:40 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 9 Aug 2017 23:53:57 +0000 (16:53 -0700)
This work implements jiting of BPF_J{LT,LE,SLT,SLE} instructions
with BPF_X/BPF_K variants for the ppc64 eBPF JIT.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/powerpc/net/bpf_jit.h
arch/powerpc/net/bpf_jit_comp64.c

index 30cf03f534280b9c956f5c78aab02ae4223c1061..47fc6660845d3735545efc718ae013ee3c1609a8 100644 (file)
@@ -263,6 +263,7 @@ static inline bool is_nearbranch(int offset)
 #define COND_EQ                (CR0_EQ | COND_CMP_TRUE)
 #define COND_NE                (CR0_EQ | COND_CMP_FALSE)
 #define COND_LT                (CR0_LT | COND_CMP_TRUE)
+#define COND_LE                (CR0_GT | COND_CMP_FALSE)
 
 #endif
 
index 861c5af1c9c4bdd85dba552b2e41a9587162e3a7..faf20163bd4cd36c28d9ab60e7ca58f2b741798f 100644 (file)
@@ -795,12 +795,24 @@ emit_clear:
                case BPF_JMP | BPF_JSGT | BPF_X:
                        true_cond = COND_GT;
                        goto cond_branch;
+               case BPF_JMP | BPF_JLT | BPF_K:
+               case BPF_JMP | BPF_JLT | BPF_X:
+               case BPF_JMP | BPF_JSLT | BPF_K:
+               case BPF_JMP | BPF_JSLT | BPF_X:
+                       true_cond = COND_LT;
+                       goto cond_branch;
                case BPF_JMP | BPF_JGE | BPF_K:
                case BPF_JMP | BPF_JGE | BPF_X:
                case BPF_JMP | BPF_JSGE | BPF_K:
                case BPF_JMP | BPF_JSGE | BPF_X:
                        true_cond = COND_GE;
                        goto cond_branch;
+               case BPF_JMP | BPF_JLE | BPF_K:
+               case BPF_JMP | BPF_JLE | BPF_X:
+               case BPF_JMP | BPF_JSLE | BPF_K:
+               case BPF_JMP | BPF_JSLE | BPF_X:
+                       true_cond = COND_LE;
+                       goto cond_branch;
                case BPF_JMP | BPF_JEQ | BPF_K:
                case BPF_JMP | BPF_JEQ | BPF_X:
                        true_cond = COND_EQ;
@@ -817,14 +829,18 @@ emit_clear:
 cond_branch:
                        switch (code) {
                        case BPF_JMP | BPF_JGT | BPF_X:
+                       case BPF_JMP | BPF_JLT | BPF_X:
                        case BPF_JMP | BPF_JGE | BPF_X:
+                       case BPF_JMP | BPF_JLE | BPF_X:
                        case BPF_JMP | BPF_JEQ | BPF_X:
                        case BPF_JMP | BPF_JNE | BPF_X:
                                /* unsigned comparison */
                                PPC_CMPLD(dst_reg, src_reg);
                                break;
                        case BPF_JMP | BPF_JSGT | BPF_X:
+                       case BPF_JMP | BPF_JSLT | BPF_X:
                        case BPF_JMP | BPF_JSGE | BPF_X:
+                       case BPF_JMP | BPF_JSLE | BPF_X:
                                /* signed comparison */
                                PPC_CMPD(dst_reg, src_reg);
                                break;
@@ -834,7 +850,9 @@ cond_branch:
                        case BPF_JMP | BPF_JNE | BPF_K:
                        case BPF_JMP | BPF_JEQ | BPF_K:
                        case BPF_JMP | BPF_JGT | BPF_K:
+                       case BPF_JMP | BPF_JLT | BPF_K:
                        case BPF_JMP | BPF_JGE | BPF_K:
+                       case BPF_JMP | BPF_JLE | BPF_K:
                                /*
                                 * Need sign-extended load, so only positive
                                 * values can be used as imm in cmpldi
@@ -849,7 +867,9 @@ cond_branch:
                                }
                                break;
                        case BPF_JMP | BPF_JSGT | BPF_K:
+                       case BPF_JMP | BPF_JSLT | BPF_K:
                        case BPF_JMP | BPF_JSGE | BPF_K:
+                       case BPF_JMP | BPF_JSLE | BPF_K:
                                /*
                                 * signed comparison, so any 16-bit value
                                 * can be used in cmpdi