bpf: allow BPF programs access skb_shared_info->gso_segs field
Subsystems (4)
PATCH 1/1 bpf: allow BPF programs access skb_shared_info->gso_segs field
This adds the ability to read gso_segs from a BPF program. This is useful for user space monitoring systems to get gso_segs statistics for each arbitrary group of flows defined by the BPF program.
--- include/uapi/linux/bpf.h | 1 + net/core/filter.c | 9 +++++++++ 2 files changed, 10 insertions(+)
include/uapi/linux/bpf.h +1 -0
@@ -2266,6 +2266,7 @@ struct __sk_buff {/* ... here. */ __u32 data_meta; +unsigned short gso_segs; };struct bpf_tunnel_key {
net/core/filter.c +9 -0
@@ -5820,6 +5820,15 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, bpf_target_off(struct sock_common, skc_num, 2, target_size));break ; + +case offsetof(struct __sk_buff , gso_segs): + BUILD_BUG_ON(FIELD_SIZEOF(struct skb_shared_info, gso_segs) != + sizeof(unsigned short)); + off = offsetof(struct sk_buff , end); + off += offsetof(struct skb_shared_info , gso_segs); + *insn++ = BPF_LDX_MEM(BPF_SIZEOF(unsigned short), si->dst_reg, + si->src_reg, off); +break ; }return insn - insn_buf;
Signature · 1 line
2.18.0.203.gfac676dfb9-goog
Sorry, forgot to annotate the subject line with bpf-next.
Quoted 46 lines · Eddie Hao
This adds the ability to read
gso_segsfrom a BPF program. This is useful for user space monitoring systems to getgso_segsstatistics for each arbitrary group of flows defined by the BPF program.Signed-off-by Eddie Hao <[email protected]>--- include/uapi/linux/bpf.h | 1 + net/core/filter.c | 9 +++++++++ 2 files changed, 10 insertions(+)include/uapi/linux/bpf.h +1
-0@@ -2266,6 +2266,7 @@ struct __sk_buff {/* ... here. */ __u32 data_meta; +unsigned short gso_segs; };struct bpf_tunnel_key {net/core/filter.c +9
-1@@ -5820,6 +5820,15 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, bpf_target_off(struct sock_common, skc_num, 2, target_size));break ; + +case offsetof(struct __sk_buff , gso_segs): + BUILD_BUG_ON(FIELD_SIZEOF(struct skb_shared_info, gso_segs) != + sizeof(unsigned short)); + off = offsetof(struct sk_buff , end); + off += offsetof(struct skb_shared_info , gso_segs); + *insn++ = BPF_LDX_MEM(BPF_SIZEOF(unsigned short), si->dst_reg, + si->src_reg, off); +break ; }return insn - insn_buf; --2.18.0.203.gfac676dfb9-goog
Quoted 15 lines · Eddie Hao
This adds the ability to read
gso_segsfrom a BPF program. This is useful for user space monitoring systems to getgso_segsstatistics for each arbitrary group of flows defined by the BPF program.Signed-off-by Eddie Hao <[email protected]>--- include/uapi/linux/bpf.h | 1 + net/core/filter.c | 9 +++++++++ 2 files changed, 10 insertions(+)include/uapi/linux/bpf.h +0
-0
include/uapi/linux/bpf.h struct __sk_buff { · line 2269
Quoted 4 lines
include/uapi/linux/bpf.h +1
-0@@ -2266,6 +2266,7 @@ struct __sk_buff {/* ... here. */ __u32 data_meta; +unsigned short gso_segs;
'short' will make it harder to extend due to struct hole. please use __u32 instead.
Quoted 8 lines
include/uapi/linux/bpf.h +0
-0};struct bpf_tunnel_key {net/core/filter.c +0
-0
net/core/filter.c static u32 bpf_convert_ctx_access(enum bpf_access_type type, · line 5828
Quoted 9 lines
net/core/filter.c +6
-0@@ -5820,6 +5820,15 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, bpf_target_off(struct sock_common, skc_num, 2, target_size));break ; + +case offsetof(struct __sk_buff , gso_segs): + BUILD_BUG_ON(FIELD_SIZEOF(struct skb_shared_info, gso_segs) != + sizeof(unsigned short)); + off = offsetof(struct sk_buff , end); + off += offsetof(struct skb_shared_info , gso_segs);
did you test this patch?
Above math doesn't look correct.NET_SKBUFF_DATA_USES_OFFSET is not handled. At least one more LDX is needed.
net/core/filter.c static u32 bpf_convert_ctx_access(enum bpf_access_type type, · line 5830
Quoted 2 lines
net/core/filter.c +2
-0+ *insn++ = BPF_LDX_MEM(BPF_SIZEOF(unsigned short), si->dst_reg, + si->src_reg, off);
I think BUILD_BUG_ON is a bit of overkill when BPF_LDX_MEM can use BPF_FIELD_SIZEOF(struct skb_shared_info, gso_segs) instead.