Commit 4ad70153 authored by David Daney's avatar David Daney Committed by Ralf Baechle

MIPS: BPF: Add JIT support for SKF_AD_HATYPE.

This let's us pass some additional "modprobe test-bpf" tests with JIT
enabled.

Reuse the code for SKF_AD_IFINDEX, but substitute the offset and size
of the "type" field.
Signed-off-by: default avatarDavid Daney <david.daney@cavium.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Steven J. Hill <steven.hill@cavium.com>
Cc: linux-mips@linux-mips.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/15744/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent bfbfa9d6
...@@ -365,6 +365,12 @@ static inline void emit_half_load(unsigned int reg, unsigned int base, ...@@ -365,6 +365,12 @@ static inline void emit_half_load(unsigned int reg, unsigned int base,
emit_instr(ctx, lh, reg, offset, base); emit_instr(ctx, lh, reg, offset, base);
} }
static inline void emit_half_load_unsigned(unsigned int reg, unsigned int base,
unsigned int offset, struct jit_ctx *ctx)
{
emit_instr(ctx, lhu, reg, offset, base);
}
static inline void emit_mul(unsigned int dst, unsigned int src1, static inline void emit_mul(unsigned int dst, unsigned int src1,
unsigned int src2, struct jit_ctx *ctx) unsigned int src2, struct jit_ctx *ctx)
{ {
...@@ -1112,6 +1118,8 @@ static int build_body(struct jit_ctx *ctx) ...@@ -1112,6 +1118,8 @@ static int build_body(struct jit_ctx *ctx)
break; break;
case BPF_ANC | SKF_AD_IFINDEX: case BPF_ANC | SKF_AD_IFINDEX:
/* A = skb->dev->ifindex */ /* A = skb->dev->ifindex */
case BPF_ANC | SKF_AD_HATYPE:
/* A = skb->dev->type */
ctx->flags |= SEEN_SKB | SEEN_A; ctx->flags |= SEEN_SKB | SEEN_A;
off = offsetof(struct sk_buff, dev); off = offsetof(struct sk_buff, dev);
/* Load *dev pointer */ /* Load *dev pointer */
...@@ -1120,10 +1128,15 @@ static int build_body(struct jit_ctx *ctx) ...@@ -1120,10 +1128,15 @@ static int build_body(struct jit_ctx *ctx)
emit_bcond(MIPS_COND_EQ, r_s0, r_zero, emit_bcond(MIPS_COND_EQ, r_s0, r_zero,
b_imm(prog->len, ctx), ctx); b_imm(prog->len, ctx), ctx);
emit_reg_move(r_ret, r_zero, ctx); emit_reg_move(r_ret, r_zero, ctx);
BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, if (code == (BPF_ANC | SKF_AD_IFINDEX)) {
ifindex) != 4); BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4);
off = offsetof(struct net_device, ifindex); off = offsetof(struct net_device, ifindex);
emit_load(r_A, r_s0, off, ctx); emit_load(r_A, r_s0, off, ctx);
} else { /* (code == (BPF_ANC | SKF_AD_HATYPE) */
BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, type) != 2);
off = offsetof(struct net_device, type);
emit_half_load_unsigned(r_A, r_s0, off, ctx);
}
break; break;
case BPF_ANC | SKF_AD_MARK: case BPF_ANC | SKF_AD_MARK:
ctx->flags |= SEEN_SKB | SEEN_A; ctx->flags |= SEEN_SKB | SEEN_A;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment