Skip to content

Commit 0b42c28

Browse files
committed
Merge branch 'arm-bpf-next'
Nicolas Schichan says: ==================== ARM BPF JIT features This series adds support for more instructions to the ARM BPF JIT namely skb netdevice type retrieval, skb payload offset retrieval, and skb packet type retrieval. This allows 35 tests to use the JIT instead of 29 before. This series depends on the "BPF JIT fixes for ARM" serie sent earlier. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents e11f40b + 5bf705b commit 0b42c28

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

arch/arm/net/bpf_jit_32.c

Lines changed: 39 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;
@@ -895,6 +913,17 @@ static int build_body(struct jit_ctx *ctx)
895913
OP_IMM3(ARM_AND, r_A, r_A, 0x1, ctx);
896914
}
897915
break;
916+
case BPF_ANC | SKF_AD_PKTTYPE:
917+
ctx->seen |= SEEN_SKB;
918+
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
919+
__pkt_type_offset[0]) != 1);
920+
off = PKT_TYPE_OFFSET();
921+
emit(ARM_LDRB_I(r_A, r_skb, off), ctx);
922+
emit(ARM_AND_I(r_A, r_A, PKT_TYPE_MAX), ctx);
923+
#ifdef __BIG_ENDIAN_BITFIELD
924+
emit(ARM_LSR_I(r_A, r_A, 5), ctx);
925+
#endif
926+
break;
898927
case BPF_ANC | SKF_AD_QUEUE:
899928
ctx->seen |= SEEN_SKB;
900929
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
@@ -904,6 +933,14 @@ static int build_body(struct jit_ctx *ctx)
904933
off = offsetof(struct sk_buff, queue_mapping);
905934
emit(ARM_LDRH_I(r_A, r_skb, off), ctx);
906935
break;
936+
case BPF_ANC | SKF_AD_PAY_OFFSET:
937+
ctx->seen |= SEEN_SKB | SEEN_CALL;
938+
939+
emit(ARM_MOV_R(ARM_R0, r_skb), ctx);
940+
emit_mov_i(ARM_R3, (unsigned int)skb_get_poff, ctx);
941+
emit_blx_r(ARM_R3, ctx);
942+
emit(ARM_MOV_R(r_A, ARM_R0), ctx);
943+
break;
907944
case BPF_LDX | BPF_W | BPF_ABS:
908945
/*
909946
* load a 32bit word from struct seccomp_data.

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)