Skip to contentSkip to conversation

add gso_size to __sk_buff

PATCH Applied Willem de Bruijn 3 participants 6 messages Mar 3, 2020 – Mar 4, 2020

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover add gso_size to __sk_buff

From: Willem de Bruijn <[email protected]>

See first patch for details.

Patch split across three parts { kernel feature, uapi header, tools } following the custom for such __sk_buff changes.

Willem de Bruijn (3):
bpf: add gso_size to __sk_buff
bpf: Sync uapi bpf.h to tools/ selftests/bpf: test new __sk_buff field gso_size

 include/uapi/linux/bpf.h                      |  1 +
 net/bpf/test_run.c                            |  7 +++
 net/core/filter.c                             | 44 +++++++++++------
 tools/include/uapi/linux/bpf.h                |  1 +
 .../selftests/bpf/prog_tests/skb_ctx.c        |  1 +
 .../selftests/bpf/progs/test_skb_ctx.c        |  2 +
 .../testing/selftests/bpf/verifier/ctx_skb.c  | 47 +++++++++++++++++++
 7 files changed, 89 insertions(+), 14 deletions(-)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
#1 lore raw

PATCH 1/3 bpf: add gso_size to __sk_buff

From: Willem de Bruijn <[email protected]>

BPF programs may want to know whether an skb is gso. The canonical answer is skb_is_gso(skb), which tests that gso_size != 0.

Expose this field in the same manner as gso_segs. That field itself is not a sufficient signal, as the comment in skb_shared_info makes
clear: gso_segs may be zero, e.g., from dodgy sources.

Also prepare net/bpf/test_run for upcoming BPF_PROG_TEST_RUN tests of the feature.

---
 include/uapi/linux/bpf.h |  1 +
 net/bpf/test_run.c       |  7 +++++++
 net/core/filter.c        | 44 +++++++++++++++++++++++++++-------------
 3 files changed, 38 insertions(+), 14 deletions(-)
include/uapi/linux/bpf.h +1 -0
index 8e98ced0963b..180337fae97e 100644
@@ -3176,6 +3176,7 @@ struct __sk_buff {
 	__u32 wire_len;
 	__u32 gso_segs;
 	__bpf_md_ptr(struct bpf_sock *, sk);
+	__u32 gso_size;
 };
 
 struct bpf_tunnel_key {
net/bpf/test_run.c +7 -0
index 562443f94133..1cd7a1c2f8b2 100644
@@ -277,6 +277,12 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
 	/* gso_segs is allowed */
 
 	if (!range_is_zero(__skb, offsetofend(struct __sk_buff, gso_segs),
+			   offsetof(struct __sk_buff, gso_size)))
+		return -EINVAL;
+
+	/* gso_size is allowed */
+
+	if (!range_is_zero(__skb, offsetofend(struct __sk_buff, gso_size),
 			   sizeof(struct __sk_buff)))
 		return -EINVAL;
 
@@ -297,6 +303,7 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
 	if (__skb->gso_segs > GSO_MAX_SEGS)
 		return -EINVAL;
 	skb_shinfo(skb)->gso_segs = __skb->gso_segs;
+	skb_shinfo(skb)->gso_size = __skb->gso_size;
 
 	return 0;
 }
net/core/filter.c +30 -14

62 lines not on this page · raw message

Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
#2 lore raw

PATCH 2/3 bpf: Sync uapi bpf.h to tools/

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

sync tools/include/uapi/linux/bpf.h to match include/uapi/linux/bpf.h

---
 tools/include/uapi/linux/bpf.h | 1 +
 1 file changed, 1 insertion(+)
tools/include/uapi/linux/bpf.h +1 -0
index 906e9f2752db..7c689f4552dd 100644
@@ -3176,6 +3176,7 @@ struct __sk_buff {
 	__u32 wire_len;
 	__u32 gso_segs;
 	__bpf_md_ptr(struct bpf_sock *, sk);
+	__u32 gso_size;
 };
 
 struct bpf_tunnel_key {
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
#3 lore raw

PATCH 3/3 selftests/bpf: test new __sk_buff field gso_size

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Analogous to the gso_segs selftests introduced in commit d9ff286a0f59 ("bpf: allow BPF programs access skb_shared_info->gso_segs field").

---
 .../selftests/bpf/prog_tests/skb_ctx.c        |  1 +
 .../selftests/bpf/progs/test_skb_ctx.c        |  2 +
 .../testing/selftests/bpf/verifier/ctx_skb.c  | 47 +++++++++++++++++++
 3 files changed, 50 insertions(+)
tools/testing/selftests/bpf/prog_tests/skb_ctx.c +1 -0
index c6d6b685a946..4538bd08203f 100644
@@ -14,6 +14,7 @@ void test_skb_ctx(void)
 		.wire_len = 100,
 		.gso_segs = 8,
 		.mark = 9,
+		.gso_size = 10,
 	};
 	struct bpf_prog_test_run_attr tattr = {
 		.data_in = &pkt_v4,
tools/testing/selftests/bpf/progs/test_skb_ctx.c +2 -0
index 202de3938494..b02ea589ce7e 100644
@@ -23,6 +23,8 @@ int process(struct __sk_buff *skb)
 		return 1;
 	if (skb->gso_segs != 8)
 		return 1;
+	if (skb->gso_size != 10)
+		return 1;
 
 	return 0;
 }
tools/testing/selftests/bpf/verifier/ctx_skb.c +47 -0

53 lines not on this page · raw message

Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
#4 lore raw
In reply to Willem de Bruijn

For the series: Acked-by: Petar Penkov <[email protected]>

Quoted 25 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

See first patch for details.

Patch split across three parts { kernel feature, uapi header, tools } following the custom for such __sk_buff changes.

Willem de Bruijn (3):
bpf: add gso_size to __sk_buff
bpf: Sync uapi bpf.h to tools/ selftests/bpf: test new __sk_buff field gso_size

 include/uapi/linux/bpf.h                      |  1 +
 net/bpf/test_run.c                            |  7 +++
 net/core/filter.c                             | 44 +++++++++++------
 tools/include/uapi/linux/bpf.h                |  1 +
 .../selftests/bpf/prog_tests/skb_ctx.c        |  1 +
 .../selftests/bpf/progs/test_skb_ctx.c        |  2 +
 .../testing/selftests/bpf/verifier/ctx_skb.c  | 47 +++++++++++++++++++
 7 files changed, 89 insertions(+), 14 deletions(-)

--
2.25.0.265.gbab2e86ba0-goog

#5 lore raw
Quoted 2 lines · Petar Penkov

For the series: Acked-by: Petar Penkov <[email protected]>

please don't top post.

Quoted 9 lines
Quoted 7 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

See first patch for details.

Patch split across three parts { kernel feature, uapi header, tools } following the custom for such __sk_buff changes.

Applied. Thanks