Skip to content

Commit 5bf705b

Browse files
nschichandavem330
authored andcommitted
ARM: net: add support for BPF_ANC | SKF_AD_HATYPE in ARM JIT.
Signed-off-by: Nicolas Schichan <nschichan@freebox.fr> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 303249a commit 5bf705b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

arch/arm/net/bpf_jit_32.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,9 @@ static int build_body(struct jit_ctx *ctx)
857857
emit(ARM_LDR_I(r_A, r_scratch, off), ctx);
858858
break;
859859
case BPF_ANC | SKF_AD_IFINDEX:
860+
case BPF_ANC | SKF_AD_HATYPE:
860861
/* A = skb->dev->ifindex */
862+
/* A = skb->dev->type */
861863
ctx->seen |= SEEN_SKB;
862864
off = offsetof(struct sk_buff, dev);
863865
emit(ARM_LDR_I(r_scratch, r_skb, off), ctx);
@@ -867,8 +869,24 @@ static int build_body(struct jit_ctx *ctx)
867869

868870
BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
869871
ifindex) != 4);
870-
off = offsetof(struct net_device, ifindex);
871-
emit(ARM_LDR_I(r_A, r_scratch, off), ctx);
872+
BUILD_BUG_ON(FIELD_SIZEOF(struct net_device,
873+
type) != 2);
874+
875+
if (code == (BPF_ANC | SKF_AD_IFINDEX)) {
876+
off = offsetof(struct net_device, ifindex);
877+
emit(ARM_LDR_I(r_A, r_scratch, off), ctx);
878+
} else {
879+
/*
880+
* offset of field "type" in "struct
881+
* net_device" is above what can be
882+
* used in the ldrh rd, [rn, #imm]
883+
* instruction, so load the offset in
884+
* a register and use ldrh rd, [rn, rm]
885+
*/
886+
off = offsetof(struct net_device, type);
887+
emit_mov_i(ARM_R3, off, ctx);
888+
emit(ARM_LDRH_R(r_A, r_scratch, ARM_R3), ctx);
889+
}
872890
break;
873891
case BPF_ANC | SKF_AD_MARK:
874892
ctx->seen |= SEEN_SKB;

arch/arm/net/bpf_jit_32.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#define ARM_INST_LDRB_I 0x05d00000
7575
#define ARM_INST_LDRB_R 0x07d00000
7676
#define ARM_INST_LDRH_I 0x01d000b0
77+
#define ARM_INST_LDRH_R 0x019000b0
7778
#define ARM_INST_LDR_I 0x05900000
7879

7980
#define ARM_INST_LDM 0x08900000
@@ -160,6 +161,8 @@
160161
| (rm))
161162
#define ARM_LDRH_I(rt, rn, off) (ARM_INST_LDRH_I | (rt) << 12 | (rn) << 16 \
162163
| (((off) & 0xf0) << 4) | ((off) & 0xf))
164+
#define ARM_LDRH_R(rt, rn, rm) (ARM_INST_LDRH_R | (rt) << 12 | (rn) << 16 \
165+
| (rm))
163166

164167
#define ARM_LDM(rn, regs) (ARM_INST_LDM | (rn) << 16 | (regs))
165168

0 commit comments

Comments
 (0)