aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kirjanov <kda@linux-powerpc.org>2014-10-30 02:12:15 -0400
committerDavid S. Miller <davem@davemloft.net>2014-11-03 15:29:42 -0500
commit4e2357611323d562fe255d9d71309b3ece30b8cd (patch)
tree26db9651c4e5adc1c2bfb1dfcd1b28c46fd47a6b
parent547f2735c20023d7b50a791b1b17cacb652e9237 (diff)
PPC: bpf_jit_comp: add SKF_AD_PKTTYPE instruction
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>
-rw-r--r--arch/powerpc/include/asm/ppc-opcode.h1
-rw-r--r--arch/powerpc/net/bpf_jit.h7
-rw-r--r--arch/powerpc/net/bpf_jit_comp.c5
3 files changed, 13 insertions, 0 deletions
diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
index 6f8536208049..1a5287759fc8 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -204,6 +204,7 @@
204#define PPC_INST_ERATSX_DOT 0x7c000127 204#define PPC_INST_ERATSX_DOT 0x7c000127
205 205
206/* Misc instructions for BPF compiler */ 206/* Misc instructions for BPF compiler */
207#define PPC_INST_LBZ 0x88000000
207#define PPC_INST_LD 0xe8000000 208#define PPC_INST_LD 0xe8000000
208#define PPC_INST_LHZ 0xa0000000 209#define PPC_INST_LHZ 0xa0000000
209#define PPC_INST_LHBRX 0x7c00062c 210#define PPC_INST_LHBRX 0x7c00062c
diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
index 9aee27c582dc..c406aa95b2bc 100644
--- a/arch/powerpc/net/bpf_jit.h
+++ b/arch/powerpc/net/bpf_jit.h
@@ -87,6 +87,9 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
87#define PPC_STD(r, base, i) EMIT(PPC_INST_STD | ___PPC_RS(r) | \ 87#define PPC_STD(r, base, i) EMIT(PPC_INST_STD | ___PPC_RS(r) | \
88 ___PPC_RA(base) | ((i) & 0xfffc)) 88 ___PPC_RA(base) | ((i) & 0xfffc))
89 89
90
91#define PPC_LBZ(r, base, i) EMIT(PPC_INST_LBZ | ___PPC_RT(r) | \
92 ___PPC_RA(base) | IMM_L(i))
90#define PPC_LD(r, base, i) EMIT(PPC_INST_LD | ___PPC_RT(r) | \ 93#define PPC_LD(r, base, i) EMIT(PPC_INST_LD | ___PPC_RT(r) | \
91 ___PPC_RA(base) | IMM_L(i)) 94 ___PPC_RA(base) | IMM_L(i))
92#define PPC_LWZ(r, base, i) EMIT(PPC_INST_LWZ | ___PPC_RT(r) | \ 95#define PPC_LWZ(r, base, i) EMIT(PPC_INST_LWZ | ___PPC_RT(r) | \
@@ -96,6 +99,10 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
96#define PPC_LHBRX(r, base, b) EMIT(PPC_INST_LHBRX | ___PPC_RT(r) | \ 99#define PPC_LHBRX(r, base, b) EMIT(PPC_INST_LHBRX | ___PPC_RT(r) | \
97 ___PPC_RA(base) | ___PPC_RB(b)) 100 ___PPC_RA(base) | ___PPC_RB(b))
98/* Convenience helpers for the above with 'far' offsets: */ 101/* Convenience helpers for the above with 'far' offsets: */
102#define PPC_LBZ_OFFS(r, base, i) do { if ((i) < 32768) PPC_LBZ(r, base, i); \
103 else { PPC_ADDIS(r, base, IMM_HA(i)); \
104 PPC_LBZ(r, r, IMM_L(i)); } } while(0)
105
99#define PPC_LD_OFFS(r, base, i) do { if ((i) < 32768) PPC_LD(r, base, i); \ 106#define PPC_LD_OFFS(r, base, i) do { if ((i) < 32768) PPC_LD(r, base, i); \
100 else { PPC_ADDIS(r, base, IMM_HA(i)); \ 107 else { PPC_ADDIS(r, base, IMM_HA(i)); \
101 PPC_LD(r, r, IMM_L(i)); } } while(0) 108 PPC_LD(r, r, IMM_L(i)); } } while(0)
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index cbae2dfd053c..d110e288d7ac 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -407,6 +407,11 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
407 PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff, 407 PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
408 queue_mapping)); 408 queue_mapping));
409 break; 409 break;
410 case BPF_ANC | SKF_AD_PKTTYPE:
411 PPC_LBZ_OFFS(r_A, r_skb, PKT_TYPE_OFFSET());
412 PPC_ANDI(r_A, r_A, PKT_TYPE_MAX);
413 PPC_SRWI(r_A, r_A, 5);
414 break;
410 case BPF_ANC | SKF_AD_CPU: 415 case BPF_ANC | SKF_AD_CPU:
411#ifdef CONFIG_SMP 416#ifdef CONFIG_SMP
412 /* 417 /*