Skip to content

Commit 354259f

Browse files
edumazetkuba-moo
authored andcommitted
net: remove skb->vlan_present
skb->vlan_present seems redundant. We can instead derive it from this boolean expression: vlan_present = skb->vlan_proto != 0 || skb->vlan_tci != 0 Add a new union, to access both fields in a single load/store when possible. union { u32 vlan_all; struct { __be16 vlan_proto; __u16 vlan_tci; }; }; This allows following patch to remove a conditional test in GRO stack. Note: We move remcsum_offload to keep TC_AT_INGRESS_MASK and SKB_MONO_DELIVERY_TIME_MASK unchanged. Signed-off-by: Eric Dumazet <[email protected]> Acked-by: Yonghong Song <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2cf7e87 commit 354259f

File tree

6 files changed

+29
-33
lines changed

6 files changed

+29
-33
lines changed

arch/sparc/net/bpf_jit_comp_32.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,11 @@ void bpf_jit_compile(struct bpf_prog *fp)
555555
emit_skb_load16(vlan_tci, r_A);
556556
break;
557557
case BPF_ANC | SKF_AD_VLAN_TAG_PRESENT:
558-
__emit_skb_load8(__pkt_vlan_present_offset, r_A);
559-
if (PKT_VLAN_PRESENT_BIT)
560-
emit_alu_K(SRL, PKT_VLAN_PRESENT_BIT);
561-
if (PKT_VLAN_PRESENT_BIT < 7)
562-
emit_andi(r_A, 1, r_A);
558+
emit_skb_load32(vlan_all, r_A);
559+
emit_cmpi(r_A, 0);
560+
emit_branch_off(BE, 12);
561+
emit_nop();
562+
emit_loadimm(1, r_A);
563563
break;
564564
case BPF_LD | BPF_W | BPF_LEN:
565565
emit_skb_load32(len, r_A);

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,7 @@ static u16 otx2_select_queue(struct net_device *netdev, struct sk_buff *skb,
19731973
#endif
19741974

19751975
#ifdef CONFIG_DCB
1976-
if (!skb->vlan_present)
1976+
if (!skb_vlan_tag_present(skb))
19771977
goto pick_tx;
19781978

19791979
vlan_prio = skb->vlan_tci >> 13;

include/linux/if_vlan.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static inline bool is_vlan_dev(const struct net_device *dev)
7676
return dev->priv_flags & IFF_802_1Q_VLAN;
7777
}
7878

79-
#define skb_vlan_tag_present(__skb) ((__skb)->vlan_present)
79+
#define skb_vlan_tag_present(__skb) (!!(__skb)->vlan_all)
8080
#define skb_vlan_tag_get(__skb) ((__skb)->vlan_tci)
8181
#define skb_vlan_tag_get_id(__skb) ((__skb)->vlan_tci & VLAN_VID_MASK)
8282
#define skb_vlan_tag_get_cfi(__skb) (!!((__skb)->vlan_tci & VLAN_CFI_MASK))
@@ -471,7 +471,7 @@ static inline struct sk_buff *vlan_insert_tag_set_proto(struct sk_buff *skb,
471471
*/
472472
static inline void __vlan_hwaccel_clear_tag(struct sk_buff *skb)
473473
{
474-
skb->vlan_present = 0;
474+
skb->vlan_all = 0;
475475
}
476476

477477
/**
@@ -483,9 +483,7 @@ static inline void __vlan_hwaccel_clear_tag(struct sk_buff *skb)
483483
*/
484484
static inline void __vlan_hwaccel_copy_tag(struct sk_buff *dst, const struct sk_buff *src)
485485
{
486-
dst->vlan_present = src->vlan_present;
487-
dst->vlan_proto = src->vlan_proto;
488-
dst->vlan_tci = src->vlan_tci;
486+
dst->vlan_all = src->vlan_all;
489487
}
490488

491489
/*
@@ -519,7 +517,6 @@ static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb,
519517
{
520518
skb->vlan_proto = vlan_proto;
521519
skb->vlan_tci = vlan_tci;
522-
skb->vlan_present = 1;
523520
}
524521

525522
/**

include/linux/skbuff.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ typedef unsigned char *sk_buff_data_t;
818818
* @mark: Generic packet mark
819819
* @reserved_tailroom: (aka @mark) number of bytes of free space available
820820
* at the tail of an sk_buff
821-
* @vlan_present: VLAN tag is present
821+
* @vlan_all: vlan fields (proto & tci)
822822
* @vlan_proto: vlan encapsulation protocol
823823
* @vlan_tci: vlan tag control information
824824
* @inner_protocol: Protocol (encapsulation)
@@ -951,7 +951,7 @@ struct sk_buff {
951951
/* private: */
952952
__u8 __pkt_vlan_present_offset[0];
953953
/* public: */
954-
__u8 vlan_present:1; /* See PKT_VLAN_PRESENT_BIT */
954+
__u8 remcsum_offload:1;
955955
__u8 csum_complete_sw:1;
956956
__u8 csum_level:2;
957957
__u8 dst_pending_confirm:1;
@@ -966,7 +966,6 @@ struct sk_buff {
966966

967967
__u8 ipvs_property:1;
968968
__u8 inner_protocol_type:1;
969-
__u8 remcsum_offload:1;
970969
#ifdef CONFIG_NET_SWITCHDEV
971970
__u8 offload_fwd_mark:1;
972971
__u8 offload_l3_fwd_mark:1;
@@ -999,8 +998,13 @@ struct sk_buff {
999998
__u32 priority;
1000999
int skb_iif;
10011000
__u32 hash;
1002-
__be16 vlan_proto;
1003-
__u16 vlan_tci;
1001+
union {
1002+
u32 vlan_all;
1003+
struct {
1004+
__be16 vlan_proto;
1005+
__u16 vlan_tci;
1006+
};
1007+
};
10041008
#if defined(CONFIG_NET_RX_BUSY_POLL) || defined(CONFIG_XPS)
10051009
union {
10061010
unsigned int napi_id;
@@ -1059,15 +1063,13 @@ struct sk_buff {
10591063
#endif
10601064
#define PKT_TYPE_OFFSET offsetof(struct sk_buff, __pkt_type_offset)
10611065

1062-
/* if you move pkt_vlan_present, tc_at_ingress, or mono_delivery_time
1066+
/* if you move tc_at_ingress or mono_delivery_time
10631067
* around, you also must adapt these constants.
10641068
*/
10651069
#ifdef __BIG_ENDIAN_BITFIELD
1066-
#define PKT_VLAN_PRESENT_BIT 7
10671070
#define TC_AT_INGRESS_MASK (1 << 0)
10681071
#define SKB_MONO_DELIVERY_TIME_MASK (1 << 2)
10691072
#else
1070-
#define PKT_VLAN_PRESENT_BIT 0
10711073
#define TC_AT_INGRESS_MASK (1 << 7)
10721074
#define SKB_MONO_DELIVERY_TIME_MASK (1 << 5)
10731075
#endif

lib/test_bpf.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14346,7 +14346,6 @@ static struct sk_buff *populate_skb(char *buf, int size)
1434614346
skb->hash = SKB_HASH;
1434714347
skb->queue_mapping = SKB_QUEUE_MAP;
1434814348
skb->vlan_tci = SKB_VLAN_TCI;
14349-
skb->vlan_present = SKB_VLAN_PRESENT;
1435014349
skb->vlan_proto = htons(ETH_P_IP);
1435114350
dev_net_set(&dev, &init_net);
1435214351
skb->dev = &dev;

net/core/filter.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg,
325325
offsetof(struct sk_buff, vlan_tci));
326326
break;
327327
case SKF_AD_VLAN_TAG_PRESENT:
328-
*insn++ = BPF_LDX_MEM(BPF_B, dst_reg, src_reg, PKT_VLAN_PRESENT_OFFSET);
329-
if (PKT_VLAN_PRESENT_BIT)
330-
*insn++ = BPF_ALU32_IMM(BPF_RSH, dst_reg, PKT_VLAN_PRESENT_BIT);
331-
if (PKT_VLAN_PRESENT_BIT < 7)
332-
*insn++ = BPF_ALU32_IMM(BPF_AND, dst_reg, 1);
328+
BUILD_BUG_ON(sizeof_field(struct sk_buff, vlan_all) != 4);
329+
*insn++ = BPF_LDX_MEM(BPF_W, dst_reg, src_reg,
330+
offsetof(struct sk_buff, vlan_all));
331+
*insn++ = BPF_JMP_IMM(BPF_JEQ, dst_reg, 0, 1);
332+
*insn++ = BPF_ALU32_IMM(BPF_MOV, dst_reg, 1);
333333
break;
334334
}
335335

@@ -9290,13 +9290,11 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
92909290
break;
92919291

92929292
case offsetof(struct __sk_buff, vlan_present):
9293-
*target_size = 1;
9294-
*insn++ = BPF_LDX_MEM(BPF_B, si->dst_reg, si->src_reg,
9295-
PKT_VLAN_PRESENT_OFFSET);
9296-
if (PKT_VLAN_PRESENT_BIT)
9297-
*insn++ = BPF_ALU32_IMM(BPF_RSH, si->dst_reg, PKT_VLAN_PRESENT_BIT);
9298-
if (PKT_VLAN_PRESENT_BIT < 7)
9299-
*insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg, 1);
9293+
*insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->src_reg,
9294+
bpf_target_off(struct sk_buff,
9295+
vlan_all, 4, target_size));
9296+
*insn++ = BPF_JMP_IMM(BPF_JEQ, si->dst_reg, 0, 1);
9297+
*insn++ = BPF_ALU32_IMM(BPF_MOV, si->dst_reg, 1);
93009298
break;
93019299

93029300
case offsetof(struct __sk_buff, vlan_tci):

0 commit comments

Comments
 (0)