Commit 6551971e authored by David S. Miller's avatar David S. Miller

Merge branch 'Remove-VLAN-CFI-overload'

Michał Mirosław says:

====================
Remove VLAN.CFI overload

Fix BPF code/JITs to allow for separate VLAN_PRESENT flag
storage and finally move the flag to separate storage in skbuff.

This is final step to make CLAN.CFI transparent to core Linux
networking stack.

An #ifdef is introduced temporarily to mark fragments masking
VLAN_TAG_PRESENT. This is removed altogether in the final patch.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 5aa25c05 0c4b2d37
...@@ -1159,19 +1159,19 @@ static int build_body(struct jit_ctx *ctx) ...@@ -1159,19 +1159,19 @@ static int build_body(struct jit_ctx *ctx)
emit_load(r_A, r_skb, off, ctx); emit_load(r_A, r_skb, off, ctx);
break; break;
case BPF_ANC | SKF_AD_VLAN_TAG: case BPF_ANC | SKF_AD_VLAN_TAG:
case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
ctx->flags |= SEEN_SKB | SEEN_A; ctx->flags |= SEEN_SKB | SEEN_A;
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
vlan_tci) != 2); vlan_tci) != 2);
off = offsetof(struct sk_buff, vlan_tci); off = offsetof(struct sk_buff, vlan_tci);
emit_half_load_unsigned(r_s0, r_skb, off, ctx); emit_half_load_unsigned(r_A, r_skb, off, ctx);
if (code == (BPF_ANC | SKF_AD_VLAN_TAG)) { break;
emit_andi(r_A, r_s0, (u16)~VLAN_TAG_PRESENT, ctx); case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
} else { ctx->flags |= SEEN_SKB | SEEN_A;
emit_andi(r_A, r_s0, VLAN_TAG_PRESENT, ctx); emit_load_byte(r_A, r_skb, PKT_VLAN_PRESENT_OFFSET(), ctx);
/* return 1 if present */ if (PKT_VLAN_PRESENT_BIT)
emit_sltu(r_A, r_zero, r_A, ctx); emit_srl(r_A, r_A, PKT_VLAN_PRESENT_BIT, ctx);
} if (PKT_VLAN_PRESENT_BIT < 7)
emit_andi(r_A, r_A, 1, ctx);
break; break;
case BPF_ANC | SKF_AD_PKTTYPE: case BPF_ANC | SKF_AD_PKTTYPE:
ctx->flags |= SEEN_SKB; ctx->flags |= SEEN_SKB;
......
...@@ -379,18 +379,17 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, ...@@ -379,18 +379,17 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
hash)); hash));
break; break;
case BPF_ANC | SKF_AD_VLAN_TAG: case BPF_ANC | SKF_AD_VLAN_TAG:
case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2); BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff, PPC_LHZ_OFFS(r_A, r_skb, offsetof(struct sk_buff,
vlan_tci)); vlan_tci));
if (code == (BPF_ANC | SKF_AD_VLAN_TAG)) { break;
PPC_ANDI(r_A, r_A, ~VLAN_TAG_PRESENT); case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
} else { PPC_LBZ_OFFS(r_A, r_skb, PKT_VLAN_PRESENT_OFFSET());
PPC_ANDI(r_A, r_A, VLAN_TAG_PRESENT); if (PKT_VLAN_PRESENT_BIT)
PPC_SRWI(r_A, r_A, 12); PPC_SRWI(r_A, r_A, PKT_VLAN_PRESENT_BIT);
} if (PKT_VLAN_PRESENT_BIT < 7)
PPC_ANDI(r_A, r_A, 1);
break; break;
case BPF_ANC | SKF_AD_QUEUE: case BPF_ANC | SKF_AD_QUEUE:
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff,
......
...@@ -552,15 +552,14 @@ void bpf_jit_compile(struct bpf_prog *fp) ...@@ -552,15 +552,14 @@ void bpf_jit_compile(struct bpf_prog *fp)
emit_skb_load32(hash, r_A); emit_skb_load32(hash, r_A);
break; break;
case BPF_ANC | SKF_AD_VLAN_TAG: case BPF_ANC | SKF_AD_VLAN_TAG:
case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
emit_skb_load16(vlan_tci, r_A); emit_skb_load16(vlan_tci, r_A);
if (code != (BPF_ANC | SKF_AD_VLAN_TAG)) { break;
emit_alu_K(SRL, 12); case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
__emit_skb_load8(__pkt_vlan_present_offset, r_A);
if (PKT_VLAN_PRESENT_BIT)
emit_alu_K(SRL, PKT_VLAN_PRESENT_BIT);
if (PKT_VLAN_PRESENT_BIT < 7)
emit_andi(r_A, 1, r_A); emit_andi(r_A, 1, r_A);
} else {
emit_loadimm(~VLAN_TAG_PRESENT, r_TMP);
emit_and(r_A, r_TMP, r_A);
}
break; break;
case BPF_LD | BPF_W | BPF_LEN: case BPF_LD | BPF_W | BPF_LEN:
emit_skb_load32(len, r_A); emit_skb_load32(len, r_A);
......
...@@ -66,7 +66,6 @@ static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb) ...@@ -66,7 +66,6 @@ static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */ #define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
#define VLAN_PRIO_SHIFT 13 #define VLAN_PRIO_SHIFT 13
#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */ #define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */
#define VLAN_TAG_PRESENT VLAN_CFI_MASK
#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */ #define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
#define VLAN_N_VID 4096 #define VLAN_N_VID 4096
...@@ -78,8 +77,8 @@ static inline bool is_vlan_dev(const struct net_device *dev) ...@@ -78,8 +77,8 @@ static inline bool is_vlan_dev(const struct net_device *dev)
return dev->priv_flags & IFF_802_1Q_VLAN; return dev->priv_flags & IFF_802_1Q_VLAN;
} }
#define skb_vlan_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT) #define skb_vlan_tag_present(__skb) ((__skb)->vlan_present)
#define skb_vlan_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT) #define skb_vlan_tag_get(__skb) ((__skb)->vlan_tci)
#define skb_vlan_tag_get_id(__skb) ((__skb)->vlan_tci & VLAN_VID_MASK) #define skb_vlan_tag_get_id(__skb) ((__skb)->vlan_tci & VLAN_VID_MASK)
#define skb_vlan_tag_get_prio(__skb) (((__skb)->vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT) #define skb_vlan_tag_get_prio(__skb) (((__skb)->vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT)
...@@ -480,7 +479,7 @@ static inline struct sk_buff *vlan_insert_tag_set_proto(struct sk_buff *skb, ...@@ -480,7 +479,7 @@ static inline struct sk_buff *vlan_insert_tag_set_proto(struct sk_buff *skb,
*/ */
static inline void __vlan_hwaccel_clear_tag(struct sk_buff *skb) static inline void __vlan_hwaccel_clear_tag(struct sk_buff *skb)
{ {
skb->vlan_tci = 0; skb->vlan_present = 0;
} }
/** /**
...@@ -492,6 +491,7 @@ static inline void __vlan_hwaccel_clear_tag(struct sk_buff *skb) ...@@ -492,6 +491,7 @@ static inline void __vlan_hwaccel_clear_tag(struct sk_buff *skb)
*/ */
static inline void __vlan_hwaccel_copy_tag(struct sk_buff *dst, const struct sk_buff *src) static inline void __vlan_hwaccel_copy_tag(struct sk_buff *dst, const struct sk_buff *src)
{ {
dst->vlan_present = src->vlan_present;
dst->vlan_proto = src->vlan_proto; dst->vlan_proto = src->vlan_proto;
dst->vlan_tci = src->vlan_tci; dst->vlan_tci = src->vlan_tci;
} }
...@@ -526,7 +526,8 @@ static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb, ...@@ -526,7 +526,8 @@ static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb,
__be16 vlan_proto, u16 vlan_tci) __be16 vlan_proto, u16 vlan_tci)
{ {
skb->vlan_proto = vlan_proto; skb->vlan_proto = vlan_proto;
skb->vlan_tci = VLAN_TAG_PRESENT | vlan_tci; skb->vlan_tci = vlan_tci;
skb->vlan_present = 1;
} }
/** /**
......
...@@ -777,6 +777,14 @@ struct sk_buff { ...@@ -777,6 +777,14 @@ struct sk_buff {
__u8 encap_hdr_csum:1; __u8 encap_hdr_csum:1;
__u8 csum_valid:1; __u8 csum_valid:1;
#ifdef __BIG_ENDIAN_BITFIELD
#define PKT_VLAN_PRESENT_BIT 7
#else
#define PKT_VLAN_PRESENT_BIT 0
#endif
#define PKT_VLAN_PRESENT_OFFSET() offsetof(struct sk_buff, __pkt_vlan_present_offset)
__u8 __pkt_vlan_present_offset[0];
__u8 vlan_present:1;
__u8 csum_complete_sw:1; __u8 csum_complete_sw:1;
__u8 csum_level:2; __u8 csum_level:2;
__u8 csum_not_inet:1; __u8 csum_not_inet:1;
...@@ -784,8 +792,8 @@ struct sk_buff { ...@@ -784,8 +792,8 @@ struct sk_buff {
#ifdef CONFIG_IPV6_NDISC_NODETYPE #ifdef CONFIG_IPV6_NDISC_NODETYPE
__u8 ndisc_nodetype:2; __u8 ndisc_nodetype:2;
#endif #endif
__u8 ipvs_property:1;
__u8 ipvs_property:1;
__u8 inner_protocol_type:1; __u8 inner_protocol_type:1;
__u8 remcsum_offload:1; __u8 remcsum_offload:1;
#ifdef CONFIG_NET_SWITCHDEV #ifdef CONFIG_NET_SWITCHDEV
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#define SKB_HASH 0x1234aaab #define SKB_HASH 0x1234aaab
#define SKB_QUEUE_MAP 123 #define SKB_QUEUE_MAP 123
#define SKB_VLAN_TCI 0xffff #define SKB_VLAN_TCI 0xffff
#define SKB_VLAN_PRESENT 1
#define SKB_DEV_IFINDEX 577 #define SKB_DEV_IFINDEX 577
#define SKB_DEV_TYPE 588 #define SKB_DEV_TYPE 588
...@@ -725,8 +726,8 @@ static struct bpf_test tests[] = { ...@@ -725,8 +726,8 @@ static struct bpf_test tests[] = {
CLASSIC, CLASSIC,
{ }, { },
{ {
{ 1, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT }, { 1, SKB_VLAN_TCI },
{ 10, SKB_VLAN_TCI & ~VLAN_TAG_PRESENT } { 10, SKB_VLAN_TCI }
}, },
}, },
{ {
...@@ -739,8 +740,8 @@ static struct bpf_test tests[] = { ...@@ -739,8 +740,8 @@ static struct bpf_test tests[] = {
CLASSIC, CLASSIC,
{ }, { },
{ {
{ 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }, { 1, SKB_VLAN_PRESENT },
{ 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) } { 10, SKB_VLAN_PRESENT }
}, },
}, },
{ {
...@@ -5289,8 +5290,8 @@ static struct bpf_test tests[] = { ...@@ -5289,8 +5290,8 @@ static struct bpf_test tests[] = {
#endif #endif
{ }, { },
{ {
{ 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }, { 1, SKB_VLAN_PRESENT },
{ 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) } { 10, SKB_VLAN_PRESENT }
}, },
.fill_helper = bpf_fill_maxinsns6, .fill_helper = bpf_fill_maxinsns6,
.expected_errcode = -ENOTSUPP, .expected_errcode = -ENOTSUPP,
...@@ -6493,6 +6494,7 @@ static struct sk_buff *populate_skb(char *buf, int size) ...@@ -6493,6 +6494,7 @@ static struct sk_buff *populate_skb(char *buf, int size)
skb->hash = SKB_HASH; skb->hash = SKB_HASH;
skb->queue_mapping = SKB_QUEUE_MAP; skb->queue_mapping = SKB_QUEUE_MAP;
skb->vlan_tci = SKB_VLAN_TCI; skb->vlan_tci = SKB_VLAN_TCI;
skb->vlan_present = SKB_VLAN_PRESENT;
skb->vlan_proto = htons(ETH_P_IP); skb->vlan_proto = htons(ETH_P_IP);
dev_net_set(&dev, &init_net); dev_net_set(&dev, &init_net);
skb->dev = &dev; skb->dev = &dev;
......
...@@ -296,22 +296,18 @@ static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg, ...@@ -296,22 +296,18 @@ static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg,
break; break;
case SKF_AD_VLAN_TAG: case SKF_AD_VLAN_TAG:
case SKF_AD_VLAN_TAG_PRESENT:
BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2); BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, vlan_tci) != 2);
BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000);
/* dst_reg = *(u16 *) (src_reg + offsetof(vlan_tci)) */ /* dst_reg = *(u16 *) (src_reg + offsetof(vlan_tci)) */
*insn++ = BPF_LDX_MEM(BPF_H, dst_reg, src_reg, *insn++ = BPF_LDX_MEM(BPF_H, dst_reg, src_reg,
offsetof(struct sk_buff, vlan_tci)); offsetof(struct sk_buff, vlan_tci));
if (skb_field == SKF_AD_VLAN_TAG) { break;
*insn++ = BPF_ALU32_IMM(BPF_AND, dst_reg, case SKF_AD_VLAN_TAG_PRESENT:
~VLAN_TAG_PRESENT); *insn++ = BPF_LDX_MEM(BPF_B, dst_reg, src_reg, PKT_VLAN_PRESENT_OFFSET());
} else { if (PKT_VLAN_PRESENT_BIT)
/* dst_reg >>= 12 */ *insn++ = BPF_ALU32_IMM(BPF_RSH, dst_reg, PKT_VLAN_PRESENT_BIT);
*insn++ = BPF_ALU32_IMM(BPF_RSH, dst_reg, 12); if (PKT_VLAN_PRESENT_BIT < 7)
/* dst_reg &= 1 */
*insn++ = BPF_ALU32_IMM(BPF_AND, dst_reg, 1); *insn++ = BPF_ALU32_IMM(BPF_AND, dst_reg, 1);
}
break; break;
} }
...@@ -6140,19 +6136,19 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, ...@@ -6140,19 +6136,19 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
break; break;
case offsetof(struct __sk_buff, vlan_present): case offsetof(struct __sk_buff, vlan_present):
case offsetof(struct __sk_buff, vlan_tci): *target_size = 1;
BUILD_BUG_ON(VLAN_TAG_PRESENT != 0x1000); *insn++ = BPF_LDX_MEM(BPF_B, si->dst_reg, si->src_reg,
PKT_VLAN_PRESENT_OFFSET());
if (PKT_VLAN_PRESENT_BIT)
*insn++ = BPF_ALU32_IMM(BPF_RSH, si->dst_reg, PKT_VLAN_PRESENT_BIT);
if (PKT_VLAN_PRESENT_BIT < 7)
*insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg, 1);
break;
case offsetof(struct __sk_buff, vlan_tci):
*insn++ = BPF_LDX_MEM(BPF_H, si->dst_reg, si->src_reg, *insn++ = BPF_LDX_MEM(BPF_H, si->dst_reg, si->src_reg,
bpf_target_off(struct sk_buff, vlan_tci, 2, bpf_target_off(struct sk_buff, vlan_tci, 2,
target_size)); target_size));
if (si->off == offsetof(struct __sk_buff, vlan_tci)) {
*insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg,
~VLAN_TAG_PRESENT);
} else {
*insn++ = BPF_ALU32_IMM(BPF_RSH, si->dst_reg, 12);
*insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg, 1);
}
break; break;
case offsetof(struct __sk_buff, cb[0]) ... case offsetof(struct __sk_buff, cb[0]) ...
......
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