All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/3] add gso_size to __sk_buff
@ 2020-03-03 20:05 Willem de Bruijn
  2020-03-03 20:05 ` [PATCH bpf-next 1/3] bpf: " Willem de Bruijn
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Willem de Bruijn @ 2020-03-03 20:05 UTC (permalink / raw)
  To: bpf; +Cc: netdev, daniel, ast, Willem de Bruijn

From: Willem de Bruijn <willemb@google.com>

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH bpf-next 1/3] bpf: add gso_size to __sk_buff
  2020-03-03 20:05 [PATCH bpf-next 0/3] add gso_size to __sk_buff Willem de Bruijn
@ 2020-03-03 20:05 ` Willem de Bruijn
  2020-03-03 20:05 ` [PATCH bpf-next 2/3] bpf: Sync uapi bpf.h to tools/ Willem de Bruijn
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Willem de Bruijn @ 2020-03-03 20:05 UTC (permalink / raw)
  To: bpf; +Cc: netdev, daniel, ast, Willem de Bruijn

From: Willem de Bruijn <willemb@google.com>

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.

Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 include/uapi/linux/bpf.h |  1 +
 net/bpf/test_run.c       |  7 +++++++
 net/core/filter.c        | 44 +++++++++++++++++++++++++++-------------
 3 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 8e98ced0963b..180337fae97e 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -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 {
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 562443f94133..1cd7a1c2f8b2 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -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;
 }
diff --git a/net/core/filter.c b/net/core/filter.c
index 4a08c9fb2be7..cd0a532db4e7 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -7139,6 +7139,27 @@ static u32 flow_dissector_convert_ctx_access(enum bpf_access_type type,
 	return insn - insn_buf;
 }
 
+static struct bpf_insn *bpf_convert_shinfo_access(const struct bpf_insn *si,
+						  struct bpf_insn *insn)
+{
+	/* si->dst_reg = skb_shinfo(SKB); */
+#ifdef NET_SKBUFF_DATA_USES_OFFSET
+	*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end),
+			      BPF_REG_AX, si->src_reg,
+			      offsetof(struct sk_buff, end));
+	*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, head),
+			      si->dst_reg, si->src_reg,
+			      offsetof(struct sk_buff, head));
+	*insn++ = BPF_ALU64_REG(BPF_ADD, si->dst_reg, BPF_REG_AX);
+#else
+	*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end),
+			      si->dst_reg, si->src_reg,
+			      offsetof(struct sk_buff, end));
+#endif
+
+	return insn;
+}
+
 static u32 bpf_convert_ctx_access(enum bpf_access_type type,
 				  const struct bpf_insn *si,
 				  struct bpf_insn *insn_buf,
@@ -7461,26 +7482,21 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
 		break;
 
 	case offsetof(struct __sk_buff, gso_segs):
-		/* si->dst_reg = skb_shinfo(SKB); */
-#ifdef NET_SKBUFF_DATA_USES_OFFSET
-		*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end),
-				      BPF_REG_AX, si->src_reg,
-				      offsetof(struct sk_buff, end));
-		*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, head),
-				      si->dst_reg, si->src_reg,
-				      offsetof(struct sk_buff, head));
-		*insn++ = BPF_ALU64_REG(BPF_ADD, si->dst_reg, BPF_REG_AX);
-#else
-		*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end),
-				      si->dst_reg, si->src_reg,
-				      offsetof(struct sk_buff, end));
-#endif
+		insn = bpf_convert_shinfo_access(si, insn);
 		*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct skb_shared_info, gso_segs),
 				      si->dst_reg, si->dst_reg,
 				      bpf_target_off(struct skb_shared_info,
 						     gso_segs, 2,
 						     target_size));
 		break;
+	case offsetof(struct __sk_buff, gso_size):
+		insn = bpf_convert_shinfo_access(si, insn);
+		*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct skb_shared_info, gso_size),
+				      si->dst_reg, si->dst_reg,
+				      bpf_target_off(struct skb_shared_info,
+						     gso_size, 2,
+						     target_size));
+		break;
 	case offsetof(struct __sk_buff, wire_len):
 		BUILD_BUG_ON(sizeof_field(struct qdisc_skb_cb, pkt_len) != 4);
 
-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf-next 2/3] bpf: Sync uapi bpf.h to tools/
  2020-03-03 20:05 [PATCH bpf-next 0/3] add gso_size to __sk_buff Willem de Bruijn
  2020-03-03 20:05 ` [PATCH bpf-next 1/3] bpf: " Willem de Bruijn
@ 2020-03-03 20:05 ` Willem de Bruijn
  2020-03-03 20:05 ` [PATCH bpf-next 3/3] selftests/bpf: test new __sk_buff field gso_size Willem de Bruijn
  2020-03-03 22:56 ` [PATCH bpf-next 0/3] add gso_size to __sk_buff Petar Penkov
  3 siblings, 0 replies; 6+ messages in thread
From: Willem de Bruijn @ 2020-03-03 20:05 UTC (permalink / raw)
  To: bpf; +Cc: netdev, daniel, ast, Willem de Bruijn

From: Willem de Bruijn <willemb@google.com>

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

Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 tools/include/uapi/linux/bpf.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 906e9f2752db..7c689f4552dd 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -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 {
-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf-next 3/3] selftests/bpf: test new __sk_buff field gso_size
  2020-03-03 20:05 [PATCH bpf-next 0/3] add gso_size to __sk_buff Willem de Bruijn
  2020-03-03 20:05 ` [PATCH bpf-next 1/3] bpf: " Willem de Bruijn
  2020-03-03 20:05 ` [PATCH bpf-next 2/3] bpf: Sync uapi bpf.h to tools/ Willem de Bruijn
@ 2020-03-03 20:05 ` Willem de Bruijn
  2020-03-03 22:56 ` [PATCH bpf-next 0/3] add gso_size to __sk_buff Petar Penkov
  3 siblings, 0 replies; 6+ messages in thread
From: Willem de Bruijn @ 2020-03-03 20:05 UTC (permalink / raw)
  To: bpf; +Cc: netdev, daniel, ast, Willem de Bruijn

From: Willem de Bruijn <willemb@google.com>

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

Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 .../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(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/skb_ctx.c b/tools/testing/selftests/bpf/prog_tests/skb_ctx.c
index c6d6b685a946..4538bd08203f 100644
--- a/tools/testing/selftests/bpf/prog_tests/skb_ctx.c
+++ b/tools/testing/selftests/bpf/prog_tests/skb_ctx.c
@@ -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,
diff --git a/tools/testing/selftests/bpf/progs/test_skb_ctx.c b/tools/testing/selftests/bpf/progs/test_skb_ctx.c
index 202de3938494..b02ea589ce7e 100644
--- a/tools/testing/selftests/bpf/progs/test_skb_ctx.c
+++ b/tools/testing/selftests/bpf/progs/test_skb_ctx.c
@@ -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;
 }
diff --git a/tools/testing/selftests/bpf/verifier/ctx_skb.c b/tools/testing/selftests/bpf/verifier/ctx_skb.c
index d438193804b2..2e16b8e268f2 100644
--- a/tools/testing/selftests/bpf/verifier/ctx_skb.c
+++ b/tools/testing/selftests/bpf/verifier/ctx_skb.c
@@ -1010,6 +1010,53 @@
 	.result = ACCEPT,
 	.prog_type = BPF_PROG_TYPE_SCHED_CLS,
 },
+{
+	"read gso_size from CGROUP_SKB",
+	.insns = {
+	BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+		    offsetof(struct __sk_buff, gso_size)),
+	BPF_MOV64_IMM(BPF_REG_0, 0),
+	BPF_EXIT_INSN(),
+	},
+	.result = ACCEPT,
+	.prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+},
+{
+	"read gso_size from CGROUP_SKB",
+	.insns = {
+	BPF_LDX_MEM(BPF_W, BPF_REG_1, BPF_REG_1,
+		    offsetof(struct __sk_buff, gso_size)),
+	BPF_MOV64_IMM(BPF_REG_0, 0),
+	BPF_EXIT_INSN(),
+	},
+	.result = ACCEPT,
+	.prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+},
+{
+	"write gso_size from CGROUP_SKB",
+	.insns = {
+	BPF_MOV64_IMM(BPF_REG_0, 0),
+	BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
+		    offsetof(struct __sk_buff, gso_size)),
+	BPF_MOV64_IMM(BPF_REG_0, 0),
+	BPF_EXIT_INSN(),
+	},
+	.result = REJECT,
+	.result_unpriv = REJECT,
+	.errstr = "invalid bpf_context access off=176 size=4",
+	.prog_type = BPF_PROG_TYPE_CGROUP_SKB,
+},
+{
+	"read gso_size from CLS",
+	.insns = {
+	BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
+		    offsetof(struct __sk_buff, gso_size)),
+	BPF_MOV64_IMM(BPF_REG_0, 0),
+	BPF_EXIT_INSN(),
+	},
+	.result = ACCEPT,
+	.prog_type = BPF_PROG_TYPE_SCHED_CLS,
+},
 {
 	"check wire_len is not readable by sockets",
 	.insns = {
-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf-next 0/3] add gso_size to __sk_buff
  2020-03-03 20:05 [PATCH bpf-next 0/3] add gso_size to __sk_buff Willem de Bruijn
                   ` (2 preceding siblings ...)
  2020-03-03 20:05 ` [PATCH bpf-next 3/3] selftests/bpf: test new __sk_buff field gso_size Willem de Bruijn
@ 2020-03-03 22:56 ` Petar Penkov
  2020-03-04  0:31   ` Alexei Starovoitov
  3 siblings, 1 reply; 6+ messages in thread
From: Petar Penkov @ 2020-03-03 22:56 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: bpf, Networking, Daniel Borkmann, Alexei Starovoitov, Willem de Bruijn

For the series: Acked-by: Petar Penkov <ppenkov@google.com>

On Tue, Mar 3, 2020 at 1:46 PM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> From: Willem de Bruijn <willemb@google.com>
>
> 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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf-next 0/3] add gso_size to __sk_buff
  2020-03-03 22:56 ` [PATCH bpf-next 0/3] add gso_size to __sk_buff Petar Penkov
@ 2020-03-04  0:31   ` Alexei Starovoitov
  0 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2020-03-04  0:31 UTC (permalink / raw)
  To: Petar Penkov
  Cc: Willem de Bruijn, bpf, Networking, Daniel Borkmann,
	Alexei Starovoitov, Willem de Bruijn

On Tue, Mar 3, 2020 at 2:56 PM Petar Penkov <ppenkov.kernel@gmail.com> wrote:
>
> For the series: Acked-by: Petar Penkov <ppenkov@google.com>

please don't top post.

> On Tue, Mar 3, 2020 at 1:46 PM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > From: Willem de Bruijn <willemb@google.com>
> >
> > 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-04  0:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03 20:05 [PATCH bpf-next 0/3] add gso_size to __sk_buff Willem de Bruijn
2020-03-03 20:05 ` [PATCH bpf-next 1/3] bpf: " Willem de Bruijn
2020-03-03 20:05 ` [PATCH bpf-next 2/3] bpf: Sync uapi bpf.h to tools/ Willem de Bruijn
2020-03-03 20:05 ` [PATCH bpf-next 3/3] selftests/bpf: test new __sk_buff field gso_size Willem de Bruijn
2020-03-03 22:56 ` [PATCH bpf-next 0/3] add gso_size to __sk_buff Petar Penkov
2020-03-04  0:31   ` Alexei Starovoitov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.