Skip to contentSkip to conversation

BPF packet scheduler updates part 2

PATCH In review Geliang Tang 4 participants 22 messages Jul 18, 2023 – Jul 28, 2023

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

v2 cover BPF packet scheduler updates part 2

v2:
- Init nr to -1 for bpf_bkup and bpf_stale.
- Update has_bytes_sent() to make sure only one item showed in 'ss -it', this needs to start server with PORT_1.
- Rename to bpf_mptcp_subflow_memory_free() and bpf_mptcp_subflow_queues_empty().
- Simplify div_u64().
- Move mptcp_subflow_set_stale() to kernel space. stale is a bit filed, I haven't found a way to set a bit filed in BPF context yet, so set it in kernel space.
- Sync with new bpf_tcp_ca.c.

Geliang Tang (13):
Squash to "bpf: Add bpf_mptcp_sched_ops" Squash to "selftests/bpf: Add bpf scheduler test" Squash to "selftests/bpf: Add bpf_first test" Squash to "selftests/bpf: Add bpf_bkup scheduler" Squash to "selftests/bpf: Add bpf_bkup test" Squash to "selftests/bpf: Add bpf_rr test" Squash to "selftests/bpf: Add bpf_red test"
mptcp: add subflow_set_stale helper selftests/bpf: Add bpf_stale scheduler selftests/bpf: Add bpf_stale test
bpf: Export more bpf_burst related functions selftests/bpf: Add bpf_burst scheduler selftests/bpf: Add bpf_burst test

 net/mptcp/bpf.c                               |  44 ++--
 net/mptcp/protocol.c                          |   4 +-
 net/mptcp/protocol.h                          |   6 +
 net/mptcp/sched.c                             |   6 +
 tools/testing/selftests/bpf/bpf_tcp_helpers.h |   7 +-
 .../testing/selftests/bpf/prog_tests/mptcp.c  |  91 +++++++-
 .../selftests/bpf/progs/mptcp_bpf_bkup.c      |   5 +-
 .../selftests/bpf/progs/mptcp_bpf_burst.c     | 197 ++++++++++++++++++
 .../selftests/bpf/progs/mptcp_bpf_stale.c     |  63 ++++++
 9 files changed, 384 insertions(+), 39 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_stale.c
Signature · 1 line
2.35.3
#1 lore raw

PATCH v2 1/13 Squash to "bpf: Add bpf_mptcp_sched_ops"

Some code in net/ipv4/bpf_tcp_ca.c is removed by the commit 9f0265e921de ("bpf: Require only one of cong_avoid() and cong_control() from a TCP CC"), sync this into net/mptcp/bpf.c.

---
 net/mptcp/bpf.c | 27 ---------------------------
 1 file changed, 27 deletions(-)
net/mptcp/bpf.c +0 -27
index c580add9c7f1..f388baf08d49 100644
@@ -18,15 +18,9 @@
 
 #ifdef CONFIG_BPF_JIT
 extern struct bpf_struct_ops bpf_mptcp_sched_ops;
-extern struct btf *btf_vmlinux;
 static const struct btf_type *mptcp_sched_type __read_mostly;
 static u32 mptcp_sched_id;
 
-static u32 optional_sched_ops[] = {
-	offsetof(struct mptcp_sched_ops, init),
-	offsetof(struct mptcp_sched_ops, release),
-};
-
 static const struct bpf_func_proto *
 bpf_mptcp_sched_get_func_proto(enum bpf_func_id func_id,
 			       const struct bpf_prog *prog)
@@ -101,25 +95,12 @@ static int bpf_mptcp_sched_check_member(const struct btf_type *t,
 	return 0;
 }
 
-static bool is_optional_sched(u32 member_offset)
-{
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(optional_sched_ops); i++) {
-		if (member_offset == optional_sched_ops[i])
-			return true;
-	}
-
-	return false;
-}
-
 static int bpf_mptcp_sched_init_member(const struct btf_type *t,
 				       const struct btf_member *member,
 				       void *kdata, const void *udata)
 {
 	const struct mptcp_sched_ops *usched;
 	struct mptcp_sched_ops *sched;
-	int prog_fd;
 	u32 moff;
 
 	usched = (const struct mptcp_sched_ops *)udata;
@@ -136,14 +117,6 @@ static int bpf_mptcp_sched_init_member(const struct btf_type *t,
 		return 1;
 	}
 
-	if (!btf_type_resolve_func_ptr(btf_vmlinux, member->type, NULL))
-		return 0;
-
-	/* Ensure bpf_prog is provided for compulsory func ptr */
-	prog_fd = (int)(*(unsigned long *)(udata + moff));
-	if (!prog_fd && !is_optional_sched(moff))
-		return -EINVAL;
-
 	return 0;
 }
 
Signature · 1 line
2.35.3
#2 lore raw

PATCH v2 2/13 Squash to "selftests/bpf: Add bpf scheduler test"

In reply to Geliang Tang

Start server with PORT_1 and update has_bytes_sent.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +4 -3
index 3279ff50ff69..f648e5d49f12 100644
@@ -296,6 +296,7 @@ static void send_data(int lfd, int fd, char *msg)
 
 #define ADDR_1	"10.0.1.1"
 #define ADDR_2	"10.0.1.2"
+#define PORT_1	10001
 
 static struct nstoken *sched_init(char *flags, char *sched)
 {
@@ -322,8 +323,8 @@ static int has_bytes_sent(char *addr)
 {
 	char cmd[128];
 
-	snprintf(cmd, sizeof(cmd), "ip netns exec %s ss -it dst %s | grep -q bytes_sent:",
-		 NS_TEST, addr);
+	snprintf(cmd, sizeof(cmd), "ip netns exec %s ss -it src %s sport %d dst %s | %s",
+		 NS_TEST, ADDR_1, PORT_1, addr, "grep -q bytes_sent:");
 	return system(cmd);
 }
 
@@ -335,7 +336,7 @@ static void test_default(void)
 	nstoken = sched_init("subflow", "default");
 	if (!ASSERT_OK_PTR(nstoken, "sched_init:default"))
 		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
+	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
 	send_data(server_fd, client_fd, "default");
Signature · 1 line
2.35.3
#3 lore raw

PATCH v2 3/13 Squash to "selftests/bpf: Add bpf_first test"

In reply to Geliang Tang

Start server with PORT_1.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -1
index f648e5d49f12..f09aafdff43c 100644
@@ -369,7 +369,7 @@ static void test_first(void)
 	nstoken = sched_init("subflow", "bpf_first");
 	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_first"))
 		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
+	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
 	send_data(server_fd, client_fd, "bpf_first");
Signature · 1 line
2.35.3
#4 lore raw

PATCH v2 4/13 Squash to "selftests/bpf: Add bpf_bkup scheduler"

In reply to Geliang Tang

Init nr to -1.

---
 tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c +3 -2
index e5ba97390e17..21493a3affdb 100644
@@ -25,7 +25,7 @@ void BPF_STRUCT_OPS(bpf_bkup_data_init, struct mptcp_sock *msk,
 int BPF_STRUCT_OPS(bpf_bkup_get_subflow, struct mptcp_sock *msk,
 		   const struct mptcp_sched_data *data)
 {
-	int nr = 0;
+	int nr = -1;
 
 	for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) {
 		struct mptcp_subflow_context *subflow;
@@ -40,7 +40,8 @@ int BPF_STRUCT_OPS(bpf_bkup_get_subflow, struct mptcp_sock *msk,
 		}
 	}
 
-	mptcp_subflow_set_scheduled(mptcp_subflow_ctx_by_pos(data, nr), true);
+	if (nr != -1)
+		mptcp_subflow_set_scheduled(mptcp_subflow_ctx_by_pos(data, nr), true);
 	return 0;
 }
 
Signature · 1 line
2.35.3
#5 lore raw

PATCH v2 5/13 Squash to "selftests/bpf: Add bpf_bkup test"

In reply to Geliang Tang

Start server with PORT_1.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -1
index f09aafdff43c..f5443c3d2d97 100644
@@ -404,7 +404,7 @@ static void test_bkup(void)
 	nstoken = sched_init("subflow backup", "bpf_bkup");
 	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_bkup"))
 		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
+	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
 	send_data(server_fd, client_fd, "bpf_bkup");
Signature · 1 line
2.35.3
#6 lore raw

PATCH v2 6/13 Squash to "selftests/bpf: Add bpf_rr test"

In reply to Geliang Tang

Start server with PORT_1.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -1
index f5443c3d2d97..5e2f6504cc68 100644
@@ -439,7 +439,7 @@ static void test_rr(void)
 	nstoken = sched_init("subflow", "bpf_rr");
 	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_rr"))
 		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
+	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
 	send_data(server_fd, client_fd, "bpf_rr");
Signature · 1 line
2.35.3
#7 lore raw

PATCH v2 7/13 Squash to "selftests/bpf: Add bpf_red test"

In reply to Geliang Tang

Start server with PORT_1.

---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -1
index 5e2f6504cc68..30fcc82b10ed 100644
@@ -474,7 +474,7 @@ static void test_red(void)
 	nstoken = sched_init("subflow", "bpf_red");
 	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_red"))
 		goto fail;
-	server_fd = start_mptcp_server(AF_INET, ADDR_1, 0, 0);
+	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	client_fd = connect_to_fd(server_fd, 0);
 
 	send_data(server_fd, client_fd, "bpf_red");
Signature · 1 line
2.35.3
#8 lore raw

PATCH v2 8/13 mptcp: add subflow_set_stale helper

In reply to Geliang Tang

Add mptcp_subflow_set_stale() helper.

---
 net/mptcp/bpf.c      | 1 +
 net/mptcp/protocol.h | 2 ++
 net/mptcp/sched.c    | 6 ++++++
 3 files changed, 9 insertions(+)
net/mptcp/bpf.c +1 -0
index f388baf08d49..e6f94d5e22fb 100644
@@ -146,6 +146,7 @@ struct bpf_struct_ops bpf_mptcp_sched_ops = {
 
 BTF_SET8_START(bpf_mptcp_sched_kfunc_ids)
 BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled)
+BTF_ID_FLAGS(func, mptcp_subflow_set_stale)
 BTF_ID_FLAGS(func, mptcp_sched_data_set_contexts)
 BTF_ID_FLAGS(func, mptcp_subflow_ctx_by_pos)
 BTF_SET8_END(bpf_mptcp_sched_kfunc_ids)
net/mptcp/protocol.h +2 -0
index 1b4457c44fe8..78b3beeb7d7a 100644
@@ -662,6 +662,8 @@ int mptcp_init_sched(struct mptcp_sock *msk,
 void mptcp_release_sched(struct mptcp_sock *msk);
 void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
 				 bool scheduled);
+void mptcp_subflow_set_stale(struct mptcp_subflow_context *subflow,
+			     int stale);
 void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk,
 				   struct mptcp_sched_data *data);
 struct mptcp_subflow_context *
net/mptcp/sched.c +6 -0
index a80cf0481edf..3f361e75e38c 100644
@@ -127,6 +127,12 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
 	WRITE_ONCE(subflow->scheduled, scheduled);
 }
 
+void mptcp_subflow_set_stale(struct mptcp_subflow_context *subflow,
+			     int stale)
+{
+	subflow->stale = stale;
+}
+
 void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk,
 				   struct mptcp_sched_data *data)
 {
Signature · 1 line
2.35.3
#12 lore raw

PATCH v2 9/13 selftests/bpf: Add bpf_stale scheduler

In reply to Geliang Tang

This patch implements the setting of stale flag in BPF MPTCP scheduler, named bpf_stale. The stale flag will be set in bpf_stale_data_init() and will be checked in bpf_stale_get_subflow().

---
 tools/testing/selftests/bpf/bpf_tcp_helpers.h |  3 +-
 .../selftests/bpf/progs/mptcp_bpf_stale.c     | 63 +++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_stale.c
tools/testing/selftests/bpf/bpf_tcp_helpers.h +2 -1
index 945dd46c98c0..c749940c9103 100644
@@ -234,7 +234,8 @@ extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym;
 #define MPTCP_SUBFLOWS_MAX	8
 
 struct mptcp_subflow_context {
-	__u32	backup : 1;
+	__u32	backup : 1,
+		stale : 1;
 	struct	sock *tcp_sock;	    /* tcp sk backpointer */
 } __attribute__((preserve_access_index));
 
tools/testing/selftests/bpf/progs/mptcp_bpf_stale.c new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.35.3
#13 lore raw

PATCH v2 10/13 selftests/bpf: Add bpf_stale test

In reply to Geliang Tang

This patch adds the bpf_stale scheduler test: test_stale(). Use sysctl to set net.mptcp.scheduler to use this sched. Add two veth net devices to simulate the multiple addresses case. Use 'ip mptcp endpoint' command to add the new endpoint ADDR_2 to PM netlink. Send data and check bytes_sent of 'ss' output after it to make sure the data has been only sent on ADDR_1 since ADDR_2 is set as stale.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +38 -0
index 30fcc82b10ed..c6aa34f3a0d7 100644
@@ -11,6 +11,7 @@
 #include "mptcp_bpf_bkup.skel.h"
 #include "mptcp_bpf_rr.skel.h"
 #include "mptcp_bpf_red.skel.h"
+#include "mptcp_bpf_stale.skel.h"
 
 char NS_TEST[32];
 
@@ -489,6 +490,41 @@ static void test_red(void)
 	mptcp_bpf_red__destroy(red_skel);
 }
 
+static void test_stale(void)
+{
+	struct mptcp_bpf_stale *stale_skel;
+	int server_fd, client_fd;
+	struct nstoken *nstoken;
+	struct bpf_link *link;
+
+	stale_skel = mptcp_bpf_stale__open_and_load();
+	if (!ASSERT_OK_PTR(stale_skel, "bpf_stale__open_and_load"))
+		return;
+
+	link = bpf_map__attach_struct_ops(stale_skel->maps.stale);
+	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
+		mptcp_bpf_stale__destroy(stale_skel);
+		return;
+	}
+
+	nstoken = sched_init("subflow", "bpf_stale");
+	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_stale"))
+		goto fail;
+	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
+	client_fd = connect_to_fd(server_fd, 0);
+
+	send_data(server_fd, client_fd, "bpf_stale");
+	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr_1");
+	ASSERT_GT(has_bytes_sent(ADDR_2), 0, "has_bytes_sent addr_2");
+
+	close(client_fd);
+	close(server_fd);
+fail:
+	cleanup_netns(nstoken);
+	bpf_link__destroy(link);
+	mptcp_bpf_stale__destroy(stale_skel);
+}
+
 void test_mptcp(void)
 {
 	if (test__start_subtest("base"))
@@ -503,4 +539,6 @@ void test_mptcp(void)
 		test_rr();
 	if (test__start_subtest("red"))
 		test_red();
+	if (test__start_subtest("stale"))
+		test_stale();
 }
Signature · 1 line
2.35.3
#14 lore raw

PATCH v2 11/13 bpf: Export more bpf_burst related functions

In reply to Geliang Tang

sk_stream_memory_free() and tcp_rtx_and_write_queues_empty() are needed to export into the BPF context for bpf_burst scheduler. But these two functions are inline ones. So this patch added two wrappers for them, and export the wrappers in the BPF context.

Add more bpf_burst related functions into bpf_mptcp_sched_kfunc_set to make sure these helpers can be accessed from the BPF context.

---
 net/mptcp/bpf.c      | 16 ++++++++++++++++
 net/mptcp/protocol.c |  4 ++--
 net/mptcp/protocol.h |  4 ++++
 3 files changed, 22 insertions(+), 2 deletions(-)
net/mptcp/bpf.c +16 -0
index e6f94d5e22fb..12b747813dee 100644
@@ -144,11 +144,27 @@ struct bpf_struct_ops bpf_mptcp_sched_ops = {
 	.name		= "mptcp_sched_ops",
 };
 
+bool bpf_mptcp_subflow_memory_free(const struct sock *sk)
+{
+	return sk_stream_memory_free(sk);
+}
+
+bool bpf_mptcp_subflow_queues_empty(const struct sock *sk)
+{
+	return tcp_rtx_and_write_queues_empty(sk);
+}
+
 BTF_SET8_START(bpf_mptcp_sched_kfunc_ids)
 BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled)
 BTF_ID_FLAGS(func, mptcp_subflow_set_stale)
 BTF_ID_FLAGS(func, mptcp_sched_data_set_contexts)
 BTF_ID_FLAGS(func, mptcp_subflow_ctx_by_pos)
+BTF_ID_FLAGS(func, mptcp_subflow_active)
+BTF_ID_FLAGS(func, mptcp_set_timeout)
+BTF_ID_FLAGS(func, mptcp_wnd_end)
+BTF_ID_FLAGS(func, bpf_mptcp_subflow_memory_free)
+BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty)
+BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale)
 BTF_SET8_END(bpf_mptcp_sched_kfunc_ids)
 
 static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = {
net/mptcp/protocol.c +2 -2
index 9f00a0288a0a..b4218108f17f 100644
@@ -50,7 +50,7 @@ DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);
 static struct net_device mptcp_napi_dev;
 
 /* Returns end sequence number of the receiver's advertised window */
-static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
+u64 mptcp_wnd_end(const struct mptcp_sock *msk)
 {
 	return READ_ONCE(msk->wnd_end);
 }
@@ -494,7 +494,7 @@ static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subfl
 	       inet_csk(ssk)->icsk_timeout - jiffies : 0;
 }
 
-static void mptcp_set_timeout(struct sock *sk)
+void mptcp_set_timeout(struct sock *sk)
 {
 	struct mptcp_subflow_context *subflow;
 	long tout = 0;
net/mptcp/protocol.h +4 -0
index 78b3beeb7d7a..cabda60f5f76 100644
@@ -635,6 +635,10 @@ void __mptcp_subflow_send_ack(struct sock *ssk);
 void mptcp_subflow_reset(struct sock *ssk);
 void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk);
 void mptcp_sock_graft(struct sock *sk, struct socket *parent);
+u64 mptcp_wnd_end(const struct mptcp_sock *msk);
+void mptcp_set_timeout(struct sock *sk);
+bool bpf_mptcp_subflow_memory_free(const struct sock *sk);
+bool bpf_mptcp_subflow_queues_empty(const struct sock *sk);
 struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk);
 bool __mptcp_close(struct sock *sk, long timeout);
 void mptcp_cancel_work(struct sock *sk);
Signature · 1 line
2.35.3
#16 lore raw

PATCH v2 12/13 selftests/bpf: Add bpf_burst scheduler

In reply to Geliang Tang

This patch implements the burst BPF MPTCP scheduler, named bpf_burst, which is the default scheduler in protocol.c. bpf_burst_get_send() uses the same logic as mptcp_subflow_get_send() and bpf_burst_get_retrans uses the same logic as mptcp_subflow_get_retrans().

---
 tools/testing/selftests/bpf/bpf_tcp_helpers.h |   4 +
 .../selftests/bpf/progs/mptcp_bpf_burst.c     | 197 ++++++++++++++++++
 2 files changed, 201 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c
tools/testing/selftests/bpf/bpf_tcp_helpers.h +4 -0
index c749940c9103..c1d7963c3bc8 100644
@@ -36,6 +36,7 @@ enum sk_pacing {
 struct sock {
 	struct sock_common	__sk_common;
 #define sk_state		__sk_common.skc_state
+	int			sk_wmem_queued;
 	unsigned long		sk_pacing_rate;
 	__u32			sk_pacing_status; /* see enum sk_pacing */
 } __attribute__((preserve_access_index));
@@ -234,8 +235,10 @@ extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym;
 #define MPTCP_SUBFLOWS_MAX	8
 
 struct mptcp_subflow_context {
+	unsigned long avg_pacing_rate;
 	__u32	backup : 1,
 		stale : 1;
+	__u8	stale_count;
 	struct	sock *tcp_sock;	    /* tcp sk backpointer */
 } __attribute__((preserve_access_index));
 
@@ -260,6 +263,7 @@ struct mptcp_sched_ops {
 struct mptcp_sock {
 	struct inet_connection_sock	sk;
 
+	__u64		snd_nxt;
 	__u32		token;
 	struct sock	*first;
 	char		ca_name[TCP_CA_NAME_MAX];
tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c new file +197 -0

197 lines not on this page · raw message

Signature · 1 line
2.35.3
#17 lore raw

PATCH v2 13/13 selftests/bpf: Add bpf_burst test

In reply to Geliang Tang

This patch adds the burst BPF MPTCP scheduler test: test_burst(). Use sysctl to set net.mptcp.scheduler to use this sched. Add two veth net devices to simulate the multiple addresses case. Use 'ip mptcp endpoint' command to add the new endpoint ADDR_2 to PM netlink. Send data and check bytes_sent of 'ss' output after it to make sure the data has been sent on both net devices.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +38 -0
index c6aa34f3a0d7..1be15973880e 100644
@@ -12,6 +12,7 @@
 #include "mptcp_bpf_rr.skel.h"
 #include "mptcp_bpf_red.skel.h"
 #include "mptcp_bpf_stale.skel.h"
+#include "mptcp_bpf_burst.skel.h"
 
 char NS_TEST[32];
 
@@ -525,6 +526,41 @@ static void test_stale(void)
 	mptcp_bpf_stale__destroy(stale_skel);
 }
 
+static void test_burst(void)
+{
+	struct mptcp_bpf_burst *burst_skel;
+	int server_fd, client_fd;
+	struct nstoken *nstoken;
+	struct bpf_link *link;
+
+	burst_skel = mptcp_bpf_burst__open_and_load();
+	if (!ASSERT_OK_PTR(burst_skel, "bpf_burst__open_and_load"))
+		return;
+
+	link = bpf_map__attach_struct_ops(burst_skel->maps.burst);
+	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
+		mptcp_bpf_burst__destroy(burst_skel);
+		return;
+	}
+
+	nstoken = sched_init("subflow", "bpf_burst");
+	if (!ASSERT_OK_PTR(nstoken, "sched_init:bpf_burst"))
+		goto fail;
+	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
+	client_fd = connect_to_fd(server_fd, 0);
+
+	send_data(server_fd, client_fd, "bpf_burst");
+	ASSERT_OK(has_bytes_sent(ADDR_1), "has_bytes_sent addr 1");
+	ASSERT_OK(has_bytes_sent(ADDR_2), "has_bytes_sent addr 2");
+
+	close(client_fd);
+	close(server_fd);
+fail:
+	cleanup_netns(nstoken);
+	bpf_link__destroy(link);
+	mptcp_bpf_burst__destroy(burst_skel);
+}
+
 void test_mptcp(void)
 {
 	if (test__start_subtest("base"))
@@ -541,4 +577,6 @@ void test_mptcp(void)
 		test_red();
 	if (test__start_subtest("stale"))
 		test_stale();
+	if (test__start_subtest("burst"))
+		test_burst();
 }
Signature · 1 line
2.35.3
#18 lore raw

Re: selftests/bpf: Add bpf_burst test: Tests Results

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6584199117799424
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6584199117799424/summary/summary.txt

- KVM Validation: debug (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/4843437464223744
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4843437464223744/summary/summary.txt

- KVM Validation: debug (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5494449095049216
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5494449095049216/summary/summary.txt

- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6134261296660480
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6134261296660480/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/64a0c9c1b0b4

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-debug

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)

maintainer
#20 lore raw
In reply to Geliang Tang
Quoted 12 lines · Geliang Tang

v2:
- Init nr to -1 for bpf_bkup and bpf_stale.
- Update has_bytes_sent() to make sure only one item showed in 'ss -it', this needs to start server with PORT_1.
- Rename to bpf_mptcp_subflow_memory_free() and bpf_mptcp_subflow_queues_empty().
- Simplify div_u64().
- Move mptcp_subflow_set_stale() to kernel space. stale is a bit filed, I haven't found a way to set a bit filed in BPF context yet, so set it in kernel space.
- Sync with new bpf_tcp_ca.c.

Quoted 1 line

Geliang Tang (13):

Thanks for the patches Geliang.

I think the first 7 patches are ok to squash on the export branch:

Quoted 7 lines

Squash to "bpf: Add bpf_mptcp_sched_ops" Squash to "selftests/bpf: Add bpf scheduler test" Squash to "selftests/bpf: Add bpf_first test" Squash to "selftests/bpf: Add bpf_bkup scheduler" Squash to "selftests/bpf: Add bpf_bkup test" Squash to "selftests/bpf: Add bpf_rr test" Squash to "selftests/bpf: Add bpf_red test"

I have questions for a few of the remaining patches, I will reply separately to those.

- Mat

Quoted 25 lines

mptcp: add subflow_set_stale helper
selftests/bpf: Add bpf_stale scheduler
selftests/bpf: Add bpf_stale test
bpf: Export more bpf_burst related functions
selftests/bpf: Add bpf_burst scheduler
selftests/bpf: Add bpf_burst test

net/mptcp/bpf.c                               |  44 ++--
net/mptcp/protocol.c                          |   4 +-
net/mptcp/protocol.h                          |   6 +
net/mptcp/sched.c                             |   6 +
tools/testing/selftests/bpf/bpf_tcp_helpers.h |   7 +-
.../testing/selftests/bpf/prog_tests/mptcp.c  |  91 +++++++-
.../selftests/bpf/progs/mptcp_bpf_bkup.c      |   5 +-
.../selftests/bpf/progs/mptcp_bpf_burst.c     | 197 ++++++++++++++++++
.../selftests/bpf/progs/mptcp_bpf_stale.c     |  63 ++++++
9 files changed, 384 insertions(+), 39 deletions(-)

create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_stale.c

Signature · 1 line
2.35.3
maintainer
#9 lore raw

Re: [PATCH mptcp-next v2 08/13] mptcp: add subflow_set_stale helper

In reply to Geliang Tang
Quoted 2 lines · Geliang Tang

Add mptcp_subflow_set_stale() helper.

I was trying to remember the use case for this. The closest thing I can find is this:

=> the scheduler should be able to interact with the "stale" logic
we have in the upstream kernel: mark a subflow as stale / back active.

from https://lore.kernel.org/mptcp/[email protected]/

I think that need is met by the change in patch 11 to export mptcp_pm_subflow_chk_stale - if a particular scheduler wants to track some stale-like metric, it can do so with its own sk_storage values. There's also the matter of coordinating the values of stale_count and stale_rcv_tstamp.

My suggestion is to drop patches 8, 9, and 10 unless there's a compelling reason to allow a BPF scheduler to control this bit. If there's a need for it please speak up!

- Mat

Quoted 54 lines

---

net/mptcp/bpf.c      | 1 +
net/mptcp/protocol.h | 2 ++
net/mptcp/sched.c    | 6 ++++++
3 files changed, 9 insertions(+)
net/mptcp/bpf.c +1 -0
index f388baf08d49..e6f94d5e22fb 100644
@@ -146,6 +146,7 @@ struct bpf_struct_ops bpf_mptcp_sched_ops = {
 
 BTF_SET8_START(bpf_mptcp_sched_kfunc_ids)
 BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled)
+BTF_ID_FLAGS(func, mptcp_subflow_set_stale)
 BTF_ID_FLAGS(func, mptcp_sched_data_set_contexts)
 BTF_ID_FLAGS(func, mptcp_subflow_ctx_by_pos)
 BTF_SET8_END(bpf_mptcp_sched_kfunc_ids)
net/mptcp/protocol.h +2 -0
index 1b4457c44fe8..78b3beeb7d7a 100644
@@ -662,6 +662,8 @@ int mptcp_init_sched(struct mptcp_sock *msk,
 void mptcp_release_sched(struct mptcp_sock *msk);
 void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
 				 bool scheduled);
+void mptcp_subflow_set_stale(struct mptcp_subflow_context *subflow,
+			     int stale);
 void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk,
 				   struct mptcp_sched_data *data);

struct mptcp_subflow_context *

net/mptcp/sched.c +6 -0
index a80cf0481edf..3f361e75e38c 100644
@@ -127,6 +127,12 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
 	WRITE_ONCE(subflow->scheduled, scheduled);
 }
 
+void mptcp_subflow_set_stale(struct mptcp_subflow_context *subflow,
+			     int stale)
+{
+	subflow->stale = stale;
+}
+
 void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk,
 				   struct mptcp_sched_data *data)
 {
Signature · 1 line
2.35.3
maintainer Reviewed-by on v2 11/13
#15 lore raw

Re: [PATCH mptcp-next v2 11/13] bpf: Export more bpf_burst related functions

In reply to Geliang Tang
Quoted 8 lines · Geliang Tang

sk_stream_memory_free() and tcp_rtx_and_write_queues_empty() are needed to export into the BPF context for bpf_burst scheduler. But these two functions are inline ones. So this patch added two wrappers for them, and export the wrappers in the BPF context.

Add more bpf_burst related functions into bpf_mptcp_sched_kfunc_set to make sure these helpers can be accessed from the BPF context.

Quoted 7 lines

---

net/mptcp/bpf.c      | 16 ++++++++++++++++
net/mptcp/protocol.c |  4 ++--
net/mptcp/protocol.h |  4 ++++
3 files changed, 22 insertions(+), 2 deletions(-)

Patches 11-13 look good to add to the "features other trees" section of the export branch for further testing:

Quoted 74 lines
net/mptcp/bpf.c +16 -0
index e6f94d5e22fb..12b747813dee 100644
@@ -144,11 +144,27 @@ struct bpf_struct_ops bpf_mptcp_sched_ops = {
 	.name		= "mptcp_sched_ops",
 };
 
+bool bpf_mptcp_subflow_memory_free(const struct sock *sk)
+{
+	return sk_stream_memory_free(sk);
+}
+
+bool bpf_mptcp_subflow_queues_empty(const struct sock *sk)
+{
+	return tcp_rtx_and_write_queues_empty(sk);
+}
+
 BTF_SET8_START(bpf_mptcp_sched_kfunc_ids)
 BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled)
 BTF_ID_FLAGS(func, mptcp_subflow_set_stale)
 BTF_ID_FLAGS(func, mptcp_sched_data_set_contexts)
 BTF_ID_FLAGS(func, mptcp_subflow_ctx_by_pos)
+BTF_ID_FLAGS(func, mptcp_subflow_active)
+BTF_ID_FLAGS(func, mptcp_set_timeout)
+BTF_ID_FLAGS(func, mptcp_wnd_end)
+BTF_ID_FLAGS(func, bpf_mptcp_subflow_memory_free)
+BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty)
+BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale)
 BTF_SET8_END(bpf_mptcp_sched_kfunc_ids)
 
 static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = {
net/mptcp/protocol.c +2 -2
index 9f00a0288a0a..b4218108f17f 100644
@@ -50,7 +50,7 @@ DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);
 static struct net_device mptcp_napi_dev;
 
 /* Returns end sequence number of the receiver's advertised window */
-static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
+u64 mptcp_wnd_end(const struct mptcp_sock *msk)
 {
 	return READ_ONCE(msk->wnd_end);
 }
@@ -494,7 +494,7 @@ static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subfl
 	       inet_csk(ssk)->icsk_timeout - jiffies : 0;
 }
 
-static void mptcp_set_timeout(struct sock *sk)
+void mptcp_set_timeout(struct sock *sk)
 {
 	struct mptcp_subflow_context *subflow;
 	long tout = 0;
net/mptcp/protocol.h +4 -0
index 78b3beeb7d7a..cabda60f5f76 100644
@@ -635,6 +635,10 @@ void __mptcp_subflow_send_ack(struct sock *ssk);
 void mptcp_subflow_reset(struct sock *ssk);
 void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk);
 void mptcp_sock_graft(struct sock *sk, struct socket *parent);
+u64 mptcp_wnd_end(const struct mptcp_sock *msk);
+void mptcp_set_timeout(struct sock *sk);
+bool bpf_mptcp_subflow_memory_free(const struct sock *sk);
+bool bpf_mptcp_subflow_queues_empty(const struct sock *sk);
 struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk);
 bool __mptcp_close(struct sock *sk, long timeout);
 void mptcp_cancel_work(struct sock *sk);
Signature · 1 line
2.35.3
#19 lore raw

Re: selftests/bpf: Add bpf_burst test: Tests Results

In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5024200105132032
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5024200105132032/summary/summary.txt

- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5619233783021568
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5619233783021568/summary/summary.txt

- KVM Validation: debug (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6713049965395968
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6713049965395968/summary/summary.txt

- KVM Validation: debug (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5587150058553344
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5587150058553344/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/8163a099bd40

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-debug

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)

#10 lore raw

Re: [PATCH mptcp-next v2 08/13] mptcp: add subflow_set_stale helper

In reply to Mat Martineau

Hi Mat,

Quoted 21 lines · Mat Martineau
Quoted 2 lines · Geliang Tang

Add mptcp_subflow_set_stale() helper.

I was trying to remember the use case for this. The closest thing I can find is this:

    => the scheduler should be able to interact with the "stale" logic we have in the upstream kernel: mark a subflow as stale / back active.

from
https://lore.kernel.org/mptcp/[email protected]/

I think that need is met by the change in patch 11 to export mptcp_pm_subflow_chk_stale - if a particular scheduler wants to track some stale-like metric, it can do so with its own sk_storage values. There's also the matter of coordinating the values of stale_count and stale_rcv_tstamp.

Quoted 3 lines

My suggestion is to drop patches 8, 9, and 10 unless there's a compelling reason to allow a BPF scheduler to control this bit. If there's a need for it please speak up!

If I'm not mistaken, the 'stale' logic is currently used by the core not to use a subflow (when calling mptcp_subflow_active()). A packet scheduler might want to proactively mark a subflow as stall, e.g. if the latency is too high, too many retransmissions, etc. and just set the subflow as stale.

But maybe we cannot do that because the core will reset stale in some conditions? Maybe we need something similar but not reusing "stale"?

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
#21 lore raw
In reply to Geliang Tang

Hi Geliang, Mat,

Quoted 12 lines · Geliang Tang

v2:
- Init nr to -1 for bpf_bkup and bpf_stale.
- Update has_bytes_sent() to make sure only one item showed in 'ss -it', this needs to start server with PORT_1.
- Rename to bpf_mptcp_subflow_memory_free() and bpf_mptcp_subflow_queues_empty().
- Simplify div_u64().
- Move mptcp_subflow_set_stale() to kernel space. stale is a bit filed, I haven't found a way to set a bit filed in BPF context yet, so set it in kernel space.
- Sync with new bpf_tcp_ca.c.

Quoted 14 lines

Geliang Tang (13):
Squash to "bpf: Add bpf_mptcp_sched_ops" Squash to "selftests/bpf: Add bpf scheduler test" Squash to "selftests/bpf: Add bpf_first test" Squash to "selftests/bpf: Add bpf_bkup scheduler" Squash to "selftests/bpf: Add bpf_bkup test" Squash to "selftests/bpf: Add bpf_rr test" Squash to "selftests/bpf: Add bpf_red test"
mptcp: add subflow_set_stale helper selftests/bpf: Add bpf_stale scheduler selftests/bpf: Add bpf_stale test
bpf: Export more bpf_burst related functions selftests/bpf: Add bpf_burst scheduler selftests/bpf: Add bpf_burst test

Thank you for the patches and the reviews!

Just applied in our tree (feat. for other trees) with Mat's RvB tag on patch 11-13:

New patches for t/upstream:
- 53ac64c3872b: "squashed" patch 1/13 in "bpf: Add bpf_mptcp_sched_ops"
- 0ab66f43ec70: "squashed" patch 2/13 in "selftests/bpf: Add bpf scheduler test"
- 2fc5650638c1: "squashed" patch 3/13 in "selftests/bpf: Add bpf_first test"
- e98afc8e2110: "squashed" patch 4/13 in "selftests/bpf: Add bpf_bkup scheduler"
- 0a920c696b80: "squashed" patch 5/13 in "selftests/bpf: Add bpf_bkup test"
- ca0924acae70: "squashed" patch 6/13 in "selftests/bpf: Add bpf_rr test"
- 4dfce80db661: "squashed" patch 7/13 in "selftests/bpf: Add bpf_red test"
- Results: b5ba626e6a54..59eafd2d73d8 (export)

- fd91a6aba636: bpf: Export more bpf_burst related functions
- ba9ff2266f7b: selftests/bpf: Add bpf_burst scheduler
- 558ed1c12d57: selftests/bpf: Add bpf_burst test
- Results: 59eafd2d73d8..e77fd85b3873 (export)

Tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20230728T160116

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
maintainer
#11 lore raw

Re: [PATCH mptcp-next v2 08/13] mptcp: add subflow_set_stale helper

In reply to Matthieu Baerts
Quoted 28 lines · Matthieu Baerts

Hi Mat,

Quoted 21 lines · Mat Martineau
Quoted 2 lines · Geliang Tang

Add mptcp_subflow_set_stale() helper.

I was trying to remember the use case for this. The closest thing I can find is this:

    => the scheduler should be able to interact with the "stale" logic we have in the upstream kernel: mark a subflow as stale / back active.

from
https://lore.kernel.org/mptcp/[email protected]/

I think that need is met by the change in patch 11 to export mptcp_pm_subflow_chk_stale - if a particular scheduler wants to track some stale-like metric, it can do so with its own sk_storage values. There's also the matter of coordinating the values of stale_count and stale_rcv_tstamp.

Quoted 3 lines

My suggestion is to drop patches 8, 9, and 10 unless there's a compelling reason to allow a BPF scheduler to control this bit. If there's a need for it please speak up!

Quoted 9 lines

If I'm not mistaken, the 'stale' logic is currently used by the core not to use a subflow (when calling mptcp_subflow_active()). A packet scheduler might want to proactively mark a subflow as stall, e.g. if the latency is too high, too many retransmissions, etc. and just set the subflow as stale.

But maybe we cannot do that because the core will reset stale in some conditions? Maybe we need something similar but not reusing "stale"?

That's what I'm thinking, yes. Individual BPF schedulers could create their own "skip this subflow if possible" variables in their custom sk_storage structs, and those would not have the complex interactions with stale_count and stale_rcv_tstamp.

- Mat