Skip to content

Commit 6a9f5cd

Browse files
author
Martin KaFai Lau
committed
Merge branch 'net: skbuff: skb bitfield compaction - bpf'
Jakub Kicinski says: ==================== I'm trying to make more of the sk_buff bits optional. Move the BPF-accessed bits a little - because they must be at coding-time-constant offsets they must precede any optional bit. While at it clean up the naming a bit. v1: https://lore.kernel.org/all/[email protected]/ ==================== Signed-off-by: Martin KaFai Lau <[email protected]>
2 parents 01dc26c + c0ba861 commit 6a9f5cd

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

include/linux/skbuff.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,19 @@ struct sk_buff {
944944
__u8 ip_summed:2;
945945
__u8 ooo_okay:1;
946946

947+
/* private: */
948+
__u8 __mono_tc_offset[0];
949+
/* public: */
950+
__u8 mono_delivery_time:1; /* See SKB_MONO_DELIVERY_TIME_MASK */
951+
#ifdef CONFIG_NET_CLS_ACT
952+
__u8 tc_at_ingress:1; /* See TC_AT_INGRESS_MASK */
953+
__u8 tc_skip_classify:1;
954+
#endif
955+
__u8 remcsum_offload:1;
956+
__u8 csum_complete_sw:1;
957+
__u8 csum_level:2;
958+
__u8 dst_pending_confirm:1;
959+
947960
__u8 l4_hash:1;
948961
__u8 sw_hash:1;
949962
__u8 wifi_acked_valid:1;
@@ -953,19 +966,6 @@ struct sk_buff {
953966
__u8 encapsulation:1;
954967
__u8 encap_hdr_csum:1;
955968
__u8 csum_valid:1;
956-
957-
/* private: */
958-
__u8 __pkt_vlan_present_offset[0];
959-
/* public: */
960-
__u8 remcsum_offload:1;
961-
__u8 csum_complete_sw:1;
962-
__u8 csum_level:2;
963-
__u8 dst_pending_confirm:1;
964-
__u8 mono_delivery_time:1; /* See SKB_MONO_DELIVERY_TIME_MASK */
965-
#ifdef CONFIG_NET_CLS_ACT
966-
__u8 tc_skip_classify:1;
967-
__u8 tc_at_ingress:1; /* See TC_AT_INGRESS_MASK */
968-
#endif
969969
#ifdef CONFIG_IPV6_NDISC_NODETYPE
970970
__u8 ndisc_nodetype:2;
971971
#endif
@@ -1072,13 +1072,13 @@ struct sk_buff {
10721072
* around, you also must adapt these constants.
10731073
*/
10741074
#ifdef __BIG_ENDIAN_BITFIELD
1075-
#define TC_AT_INGRESS_MASK (1 << 0)
1076-
#define SKB_MONO_DELIVERY_TIME_MASK (1 << 2)
1075+
#define SKB_MONO_DELIVERY_TIME_MASK (1 << 7)
1076+
#define TC_AT_INGRESS_MASK (1 << 6)
10771077
#else
1078-
#define TC_AT_INGRESS_MASK (1 << 7)
1079-
#define SKB_MONO_DELIVERY_TIME_MASK (1 << 5)
1078+
#define SKB_MONO_DELIVERY_TIME_MASK (1 << 0)
1079+
#define TC_AT_INGRESS_MASK (1 << 1)
10801080
#endif
1081-
#define PKT_VLAN_PRESENT_OFFSET offsetof(struct sk_buff, __pkt_vlan_present_offset)
1081+
#define SKB_BF_MONO_TC_OFFSET offsetof(struct sk_buff, __mono_tc_offset)
10821082

10831083
#ifdef __KERNEL__
10841084
/*

net/core/filter.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9185,7 +9185,7 @@ static struct bpf_insn *bpf_convert_tstamp_type_read(const struct bpf_insn *si,
91859185
__u8 tmp_reg = BPF_REG_AX;
91869186

91879187
*insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg,
9188-
PKT_VLAN_PRESENT_OFFSET);
9188+
SKB_BF_MONO_TC_OFFSET);
91899189
*insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg,
91909190
SKB_MONO_DELIVERY_TIME_MASK, 2);
91919191
*insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_TSTAMP_UNSPEC);
@@ -9232,7 +9232,7 @@ static struct bpf_insn *bpf_convert_tstamp_read(const struct bpf_prog *prog,
92329232
/* AX is needed because src_reg and dst_reg could be the same */
92339233
__u8 tmp_reg = BPF_REG_AX;
92349234

9235-
*insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, PKT_VLAN_PRESENT_OFFSET);
9235+
*insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, SKB_BF_MONO_TC_OFFSET);
92369236
*insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg,
92379237
TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK);
92389238
*insn++ = BPF_JMP32_IMM(BPF_JNE, tmp_reg,
@@ -9267,14 +9267,14 @@ static struct bpf_insn *bpf_convert_tstamp_write(const struct bpf_prog *prog,
92679267
if (!prog->tstamp_type_access) {
92689268
__u8 tmp_reg = BPF_REG_AX;
92699269

9270-
*insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, PKT_VLAN_PRESENT_OFFSET);
9270+
*insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, SKB_BF_MONO_TC_OFFSET);
92719271
/* Writing __sk_buff->tstamp as ingress, goto <clear> */
92729272
*insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, TC_AT_INGRESS_MASK, 1);
92739273
/* goto <store> */
92749274
*insn++ = BPF_JMP_A(2);
92759275
/* <clear>: mono_delivery_time */
92769276
*insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, ~SKB_MONO_DELIVERY_TIME_MASK);
9277-
*insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, PKT_VLAN_PRESENT_OFFSET);
9277+
*insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, SKB_BF_MONO_TC_OFFSET);
92789278
}
92799279
#endif
92809280

tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ static struct test_case test_cases[] = {
6868
#if defined(__x86_64__) || defined(__aarch64__)
6969
{
7070
N(SCHED_CLS, struct __sk_buff, tstamp),
71-
.read = "r11 = *(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset);"
72-
"w11 &= 160;"
73-
"if w11 != 0xa0 goto pc+2;"
71+
.read = "r11 = *(u8 *)($ctx + sk_buff::__mono_tc_offset);"
72+
"w11 &= 3;"
73+
"if w11 != 0x3 goto pc+2;"
7474
"$dst = 0;"
7575
"goto pc+1;"
7676
"$dst = *(u64 *)($ctx + sk_buff::tstamp);",
77-
.write = "r11 = *(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset);"
78-
"if w11 & 0x80 goto pc+1;"
77+
.write = "r11 = *(u8 *)($ctx + sk_buff::__mono_tc_offset);"
78+
"if w11 & 0x2 goto pc+1;"
7979
"goto pc+2;"
80-
"w11 &= -33;"
81-
"*(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset) = r11;"
80+
"w11 &= -2;"
81+
"*(u8 *)($ctx + sk_buff::__mono_tc_offset) = r11;"
8282
"*(u64 *)($ctx + sk_buff::tstamp) = $src;",
8383
},
8484
#endif

0 commit comments

Comments
 (0)