* [PATCH bpf-next 0/3] net: skbuff: skb bitfield compaction - bpf
@ 2023-03-08 0:31 Jakub Kicinski
2023-03-08 0:31 ` [PATCH bpf-next 1/3] net: skbuff: rename __pkt_vlan_present_offset to __mono_tc_offset Jakub Kicinski
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jakub Kicinski @ 2023-03-08 0:31 UTC (permalink / raw)
To: bpf; +Cc: davem, netdev, edumazet, pabeni, Jakub Kicinski
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.
Jakub Kicinski (3):
net: skbuff: rename __pkt_vlan_present_offset to __mono_tc_offset
net: skbuff: reorder bytes 2 and 3 of the bitfield
net: skbuff: move the fields BPF cares about directly next to the
offset marker
include/linux/skbuff.h | 36 +++++++++----------
net/core/filter.c | 8 ++---
.../selftests/bpf/prog_tests/ctx_rewrite.c | 6 ++--
3 files changed, 25 insertions(+), 25 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH bpf-next 1/3] net: skbuff: rename __pkt_vlan_present_offset to __mono_tc_offset 2023-03-08 0:31 [PATCH bpf-next 0/3] net: skbuff: skb bitfield compaction - bpf Jakub Kicinski @ 2023-03-08 0:31 ` Jakub Kicinski 2023-03-09 1:16 ` Martin KaFai Lau 2023-03-08 0:31 ` [PATCH bpf-next 2/3] net: skbuff: reorder bytes 2 and 3 of the bitfield Jakub Kicinski 2023-03-08 0:31 ` [PATCH bpf-next 3/3] net: skbuff: move the fields BPF cares about directly next to the offset marker Jakub Kicinski 2 siblings, 1 reply; 5+ messages in thread From: Jakub Kicinski @ 2023-03-08 0:31 UTC (permalink / raw) To: bpf; +Cc: davem, netdev, edumazet, pabeni, Jakub Kicinski vlan_present is gone since commit 354259fa73e2 ("net: remove skb->vlan_present") rename the offset field to what BPF is currently looking for in this byte - mono_delivery_time and tc_at_ingress. Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- include/linux/skbuff.h | 4 ++-- net/core/filter.c | 8 ++++---- tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index ff7ad331fb82..004009b3930f 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -956,7 +956,7 @@ struct sk_buff { __u8 csum_valid:1; /* private: */ - __u8 __pkt_vlan_present_offset[0]; + __u8 __mono_tc_offset[0]; /* public: */ __u8 remcsum_offload:1; __u8 csum_complete_sw:1; @@ -1080,7 +1080,7 @@ struct sk_buff { #define TC_AT_INGRESS_MASK (1 << 7) #define SKB_MONO_DELIVERY_TIME_MASK (1 << 5) #endif -#define PKT_VLAN_PRESENT_OFFSET offsetof(struct sk_buff, __pkt_vlan_present_offset) +#define SKB_BF_MONO_TC_OFFSET offsetof(struct sk_buff, __mono_tc_offset) #ifdef __KERNEL__ /* diff --git a/net/core/filter.c b/net/core/filter.c index 50f649f1b4a9..3370efad1dda 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -9185,7 +9185,7 @@ static struct bpf_insn *bpf_convert_tstamp_type_read(const struct bpf_insn *si, __u8 tmp_reg = BPF_REG_AX; *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, - PKT_VLAN_PRESENT_OFFSET); + SKB_BF_MONO_TC_OFFSET); *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, SKB_MONO_DELIVERY_TIME_MASK, 2); *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, /* AX is needed because src_reg and dst_reg could be the same */ __u8 tmp_reg = BPF_REG_AX; - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, PKT_VLAN_PRESENT_OFFSET); + *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, SKB_BF_MONO_TC_OFFSET); *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK); *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, if (!prog->tstamp_type_access) { __u8 tmp_reg = BPF_REG_AX; - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, PKT_VLAN_PRESENT_OFFSET); + *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, SKB_BF_MONO_TC_OFFSET); /* Writing __sk_buff->tstamp as ingress, goto <clear> */ *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, TC_AT_INGRESS_MASK, 1); /* goto <store> */ *insn++ = BPF_JMP_A(2); /* <clear>: mono_delivery_time */ *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, ~SKB_MONO_DELIVERY_TIME_MASK); - *insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, PKT_VLAN_PRESENT_OFFSET); + *insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, SKB_BF_MONO_TC_OFFSET); } #endif diff --git a/tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c b/tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c index d5fe3d4b936c..ae7b6e50e405 100644 --- a/tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c +++ b/tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c @@ -68,17 +68,17 @@ static struct test_case test_cases[] = { #if defined(__x86_64__) || defined(__aarch64__) { N(SCHED_CLS, struct __sk_buff, tstamp), - .read = "r11 = *(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset);" + .read = "r11 = *(u8 *)($ctx + sk_buff::__mono_tc_offset);" "w11 &= 160;" "if w11 != 0xa0 goto pc+2;" "$dst = 0;" "goto pc+1;" "$dst = *(u64 *)($ctx + sk_buff::tstamp);", - .write = "r11 = *(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset);" + .write = "r11 = *(u8 *)($ctx + sk_buff::__mono_tc_offset);" "if w11 & 0x80 goto pc+1;" "goto pc+2;" "w11 &= -33;" - "*(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset) = r11;" + "*(u8 *)($ctx + sk_buff::__mono_tc_offset) = r11;" "*(u64 *)($ctx + sk_buff::tstamp) = $src;", }, #endif -- 2.39.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next 1/3] net: skbuff: rename __pkt_vlan_present_offset to __mono_tc_offset 2023-03-08 0:31 ` [PATCH bpf-next 1/3] net: skbuff: rename __pkt_vlan_present_offset to __mono_tc_offset Jakub Kicinski @ 2023-03-09 1:16 ` Martin KaFai Lau 0 siblings, 0 replies; 5+ messages in thread From: Martin KaFai Lau @ 2023-03-09 1:16 UTC (permalink / raw) To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, bpf On 3/7/23 4:31 PM, Jakub Kicinski wrote: > vlan_present is gone since > commit 354259fa73e2 ("net: remove skb->vlan_present") > rename the offset field to what BPF is currently looking > for in this byte - mono_delivery_time and tc_at_ingress. > > Signed-off-by: Jakub Kicinski <kuba@kernel.org> > --- > include/linux/skbuff.h | 4 ++-- > net/core/filter.c | 8 ++++---- > tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c | 6 +++--- > 3 files changed, 9 insertions(+), 9 deletions(-) > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > index ff7ad331fb82..004009b3930f 100644 > --- a/include/linux/skbuff.h > +++ b/include/linux/skbuff.h > @@ -956,7 +956,7 @@ struct sk_buff { > __u8 csum_valid:1; > > /* private: */ > - __u8 __pkt_vlan_present_offset[0]; > + __u8 __mono_tc_offset[0]; > /* public: */ > __u8 remcsum_offload:1; > __u8 csum_complete_sw:1; > @@ -1080,7 +1080,7 @@ struct sk_buff { > #define TC_AT_INGRESS_MASK (1 << 7) > #define SKB_MONO_DELIVERY_TIME_MASK (1 << 5) > #endif > -#define PKT_VLAN_PRESENT_OFFSET offsetof(struct sk_buff, __pkt_vlan_present_offset) > +#define SKB_BF_MONO_TC_OFFSET offsetof(struct sk_buff, __mono_tc_offset) > > #ifdef __KERNEL__ > /* > diff --git a/net/core/filter.c b/net/core/filter.c > index 50f649f1b4a9..3370efad1dda 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -9185,7 +9185,7 @@ static struct bpf_insn *bpf_convert_tstamp_type_read(const struct bpf_insn *si, > __u8 tmp_reg = BPF_REG_AX; > > *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, > - PKT_VLAN_PRESENT_OFFSET); > + SKB_BF_MONO_TC_OFFSET); > *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, > SKB_MONO_DELIVERY_TIME_MASK, 2); > *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, > /* AX is needed because src_reg and dst_reg could be the same */ > __u8 tmp_reg = BPF_REG_AX; > > - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, PKT_VLAN_PRESENT_OFFSET); > + *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, SKB_BF_MONO_TC_OFFSET); > *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, > TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK); > *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, > if (!prog->tstamp_type_access) { > __u8 tmp_reg = BPF_REG_AX; > > - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, PKT_VLAN_PRESENT_OFFSET); > + *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, SKB_BF_MONO_TC_OFFSET); > /* Writing __sk_buff->tstamp as ingress, goto <clear> */ > *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, TC_AT_INGRESS_MASK, 1); > /* goto <store> */ > *insn++ = BPF_JMP_A(2); > /* <clear>: mono_delivery_time */ > *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, ~SKB_MONO_DELIVERY_TIME_MASK); > - *insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, PKT_VLAN_PRESENT_OFFSET); > + *insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, SKB_BF_MONO_TC_OFFSET); > } > #endif > > diff --git a/tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c b/tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c > index d5fe3d4b936c..ae7b6e50e405 100644 > --- a/tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c > +++ b/tools/testing/selftests/bpf/prog_tests/ctx_rewrite.c > @@ -68,17 +68,17 @@ static struct test_case test_cases[] = { > #if defined(__x86_64__) || defined(__aarch64__) > { > N(SCHED_CLS, struct __sk_buff, tstamp), > - .read = "r11 = *(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset);" > + .read = "r11 = *(u8 *)($ctx + sk_buff::__mono_tc_offset);" > "w11 &= 160;" The mask needs to be adjusted also after patch 3. This selftest is failing: https://github.com/kernel-patches/bpf/actions/runs/4369844423/jobs/7644281598 > "if w11 != 0xa0 goto pc+2;" > "$dst = 0;" > "goto pc+1;" > "$dst = *(u64 *)($ctx + sk_buff::tstamp);", > - .write = "r11 = *(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset);" > + .write = "r11 = *(u8 *)($ctx + sk_buff::__mono_tc_offset);" > "if w11 & 0x80 goto pc+1;" It probably needs to adjust here also > "goto pc+2;" > "w11 &= -33;" and here. > - "*(u8 *)($ctx + sk_buff::__pkt_vlan_present_offset) = r11;" > + "*(u8 *)($ctx + sk_buff::__mono_tc_offset) = r11;" > "*(u64 *)($ctx + sk_buff::tstamp) = $src;", > }, > #endif ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH bpf-next 2/3] net: skbuff: reorder bytes 2 and 3 of the bitfield 2023-03-08 0:31 [PATCH bpf-next 0/3] net: skbuff: skb bitfield compaction - bpf Jakub Kicinski 2023-03-08 0:31 ` [PATCH bpf-next 1/3] net: skbuff: rename __pkt_vlan_present_offset to __mono_tc_offset Jakub Kicinski @ 2023-03-08 0:31 ` Jakub Kicinski 2023-03-08 0:31 ` [PATCH bpf-next 3/3] net: skbuff: move the fields BPF cares about directly next to the offset marker Jakub Kicinski 2 siblings, 0 replies; 5+ messages in thread From: Jakub Kicinski @ 2023-03-08 0:31 UTC (permalink / raw) To: bpf; +Cc: davem, netdev, edumazet, pabeni, Jakub Kicinski BPF needs to know the offsets of fields it tries to access. Zero-length fields are added to make offsetof() work. This unfortunately partitions the bitfield (fields across the zero-length members can't be coalesced). Reorder bytes 2 and 3, BPF needs to know the offset of fields previously in byte 3 and some fields in byte 2 should really be optional. The two bytes are always in the same cacheline so it should not matter. Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- include/linux/skbuff.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 004009b3930f..c4122797d465 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -945,16 +945,6 @@ struct sk_buff { __u8 ip_summed:2; __u8 ooo_okay:1; - __u8 l4_hash:1; - __u8 sw_hash:1; - __u8 wifi_acked_valid:1; - __u8 wifi_acked:1; - __u8 no_fcs:1; - /* Indicates the inner headers are valid in the skbuff. */ - __u8 encapsulation:1; - __u8 encap_hdr_csum:1; - __u8 csum_valid:1; - /* private: */ __u8 __mono_tc_offset[0]; /* public: */ @@ -967,6 +957,16 @@ struct sk_buff { __u8 tc_skip_classify:1; __u8 tc_at_ingress:1; /* See TC_AT_INGRESS_MASK */ #endif + + __u8 l4_hash:1; + __u8 sw_hash:1; + __u8 wifi_acked_valid:1; + __u8 wifi_acked:1; + __u8 no_fcs:1; + /* Indicates the inner headers are valid in the skbuff. */ + __u8 encapsulation:1; + __u8 encap_hdr_csum:1; + __u8 csum_valid:1; #ifdef CONFIG_IPV6_NDISC_NODETYPE __u8 ndisc_nodetype:2; #endif -- 2.39.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next 3/3] net: skbuff: move the fields BPF cares about directly next to the offset marker 2023-03-08 0:31 [PATCH bpf-next 0/3] net: skbuff: skb bitfield compaction - bpf Jakub Kicinski 2023-03-08 0:31 ` [PATCH bpf-next 1/3] net: skbuff: rename __pkt_vlan_present_offset to __mono_tc_offset Jakub Kicinski 2023-03-08 0:31 ` [PATCH bpf-next 2/3] net: skbuff: reorder bytes 2 and 3 of the bitfield Jakub Kicinski @ 2023-03-08 0:31 ` Jakub Kicinski 2 siblings, 0 replies; 5+ messages in thread From: Jakub Kicinski @ 2023-03-08 0:31 UTC (permalink / raw) To: bpf; +Cc: davem, netdev, edumazet, pabeni, Jakub Kicinski To avoid more possible BPF dependencies with moving bitfields around keep the fields BPF cares about right next to the offset marker. Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- include/linux/skbuff.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index c4122797d465..3716818b804d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -948,15 +948,15 @@ struct sk_buff { /* private: */ __u8 __mono_tc_offset[0]; /* public: */ - __u8 remcsum_offload:1; - __u8 csum_complete_sw:1; - __u8 csum_level:2; - __u8 dst_pending_confirm:1; __u8 mono_delivery_time:1; /* See SKB_MONO_DELIVERY_TIME_MASK */ #ifdef CONFIG_NET_CLS_ACT - __u8 tc_skip_classify:1; __u8 tc_at_ingress:1; /* See TC_AT_INGRESS_MASK */ + __u8 tc_skip_classify:1; #endif + __u8 remcsum_offload:1; + __u8 csum_complete_sw:1; + __u8 csum_level:2; + __u8 dst_pending_confirm:1; __u8 l4_hash:1; __u8 sw_hash:1; @@ -1074,11 +1074,11 @@ struct sk_buff { * around, you also must adapt these constants. */ #ifdef __BIG_ENDIAN_BITFIELD -#define TC_AT_INGRESS_MASK (1 << 0) -#define SKB_MONO_DELIVERY_TIME_MASK (1 << 2) +#define SKB_MONO_DELIVERY_TIME_MASK (1 << 7) +#define TC_AT_INGRESS_MASK (1 << 6) #else -#define TC_AT_INGRESS_MASK (1 << 7) -#define SKB_MONO_DELIVERY_TIME_MASK (1 << 5) +#define SKB_MONO_DELIVERY_TIME_MASK (1 << 0) +#define TC_AT_INGRESS_MASK (1 << 1) #endif #define SKB_BF_MONO_TC_OFFSET offsetof(struct sk_buff, __mono_tc_offset) -- 2.39.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-09 1:16 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-03-08 0:31 [PATCH bpf-next 0/3] net: skbuff: skb bitfield compaction - bpf Jakub Kicinski 2023-03-08 0:31 ` [PATCH bpf-next 1/3] net: skbuff: rename __pkt_vlan_present_offset to __mono_tc_offset Jakub Kicinski 2023-03-09 1:16 ` Martin KaFai Lau 2023-03-08 0:31 ` [PATCH bpf-next 2/3] net: skbuff: reorder bytes 2 and 3 of the bitfield Jakub Kicinski 2023-03-08 0:31 ` [PATCH bpf-next 3/3] net: skbuff: move the fields BPF cares about directly next to the offset marker Jakub Kicinski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox