PPC: bpf_jit_comp: add SKF_AD_PKTTYPE instruction
authorDenis Kirjanov <kda@linux-powerpc.org>
Thu, 30 Oct 2014 06:12:15 +0000 (09:12 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Nov 2014 20:29:42 +0000 (15:29 -0500)
Add BPF extension SKF_AD_PKTTYPE to ppc JIT to load
skb->pkt_type field.

Before:
[   88.262622] test_bpf: #11 LD_IND_NET 86 97 99 PASS
[   88.265740] test_bpf: #12 LD_PKTTYPE 109 107 PASS

After:
[   80.605964] test_bpf: #11 LD_IND_NET 44 40 39 PASS
[   80.607370] test_bpf: #12 LD_PKTTYPE 9 9 PASS

CC: Alexei Starovoitov<alexei.starovoitov@gmail.com>
CC: Michael Ellerman<mpe@ellerman.id.au>
Cc: Matt Evans <matt@ozlabs.org>
Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>
v2: Added test rusults
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/powerpc/include/asm/ppc-opcode.h
arch/powerpc/net/bpf_jit.h
arch/powerpc/net/bpf_jit_comp.c

index 6f8536208049f4c8f46708e45b4153927c36658a..1a5287759fc86cdd1918abfcf7b2645031ac77c6 100644 (file)
 #define PPC_INST_ERATSX_DOT            0x7c000127
 
 /* Misc instructions for BPF compiler */
+#define PPC_INST_LBZ                   0x88000000
 #define PPC_INST_LD                    0xe8000000
 #define PPC_INST_LHZ                   0xa0000000
 #define PPC_INST_LHBRX                 0x7c00062c
index 9aee27c582dcbcbd34a7f9acd2f0aabe6ffb3445..c406aa95b2bc5970b1aa7d3033cc8518faa93089 100644 (file)
@@ -87,6 +87,9 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
 #define PPC_STD(r, base, i)    EMIT(PPC_INST_STD | ___PPC_RS(r) |            \
                                     ___PPC_RA(base) | ((i) & 0xfffc))
 
+
+#define PPC_LBZ(r, base, i)    EMIT(PPC_INST_LBZ | ___PPC_RT(r) |            \
+                                    ___PPC_RA(base) | IMM_L(i))
 #define PPC_LD(r, base, i)     EMIT(PPC_INST_LD | ___PPC_RT(r) |             \
                                     ___PPC_RA(base) | IMM_L(i))
 #define PPC_LWZ(r, base, i)    EMIT(PPC_INST_LWZ | ___PPC_RT(r) |            \
@@ -96,6 +99,10 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
 #define PPC_LHBRX(r, base, b)  EMIT(PPC_INST_LHBRX | ___PPC_RT(r) |          \
                                     ___PPC_RA(base) | ___PPC_RB(b))
 /* Convenience helpers for the above with 'far' offsets: */
+#define PPC_LBZ_OFFS(r, base, i) do { if ((i) < 32768) PPC_LBZ(r, base, i);   \
+               else {  PPC_ADDIS(r, base, IMM_HA(i));                        \
+                       PPC_LBZ(r, r, IMM_L(i)); } } while(0)
+
 #define PPC_LD_OFFS(r, base, i) do { if ((i) < 32768) PPC_LD(r, base, i);     \
                else {  PPC_ADDIS(r, base, IMM_HA(i));                        \
                        PPC_LD(r, r, IMM_L(i)); } } while(0)
index cbae2dfd053cafc22540572652528d4dbedc91fe..d110e288d7ac6fe3fb77a9c4416b915a609e2dd0 100644 (file)
@@ -407,6 +407,11 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
                        PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
                                                          queue_mapping));
                        break;
+               case BPF_ANC | SKF_AD_PKTTYPE:
+                       PPC_LBZ_OFFS(r_A, r_skb, PKT_TYPE_OFFSET());
+                       PPC_ANDI(r_A, r_A, PKT_TYPE_MAX);
+                       PPC_SRWI(r_A, r_A, 5);
+                       break;
                case BPF_ANC | SKF_AD_CPU:
 #ifdef CONFIG_SMP
                        /*