Skip to contentSkip to conversation

fixes for "new MPTCP subflow subtest v4"

PATCH Superseded Geliang Tang 3 participants 8 messages Aug 22, 2024 – Aug 23, 2024

Subsystems (4)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v3 cover fixes for "new MPTCP subflow subtest v4"

From: Geliang Tang <[email protected]>

v3:
- drop "ss_search" from subflow subtest
- fix mptcp_for_each_subflow_safe
- add cond_break in list_for_each_entry/_safe

Two fixes address Martin's comments in "new MPTCP subflow subtest" v4. Patch 2 will conflict with "selftests/bpf: Add bpf_first scheduler & test".

Geliang Tang (2):
Squash to "selftests/bpf: Add mptcp subflow subtest" selftests/bpf: Add getsockopt to inspect mptcp subflow

 .../testing/selftests/bpf/prog_tests/mptcp.c  | 53 ++++++++++--------
 tools/testing/selftests/bpf/progs/mptcp_bpf.h | 35 ++++++++++++
 .../selftests/bpf/progs/mptcp_subflow.c       | 55 +++++++++++++++++++
 3 files changed, 119 insertions(+), 24 deletions(-)
Signature · 1 line
2.43.0
author reviewer
#1 lore raw

PATCH v3 1/2 Squash to "selftests/bpf: Add mptcp subflow subtest"

From: Geliang Tang <[email protected]>

Drop ss_search() from run_subflow().

Now ss_search() are only used by bpf_sched tests. It will be dropped in next step.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 38 +++++--------------
 1 file changed, 10 insertions(+), 28 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +10 -28
index 73adc58cd776..d4c5209fbfaf 100644
@@ -368,22 +368,9 @@ static int endpoint_init(char *flags)
 	return -1;
 }
 
-static int _ss_search(char *src, char *dst, char *port, char *keyword)
+static void run_subflow(void)
 {
-	return SYS_NOFAIL("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'",
-			  NS_TEST, src, dst, port, PORT_1, keyword);
-}
-
-static int ss_search(char *src, char *keyword)
-{
-	return _ss_search(src, ADDR_1, "dport", keyword);
-}
-
-static void run_subflow(char *new)
-{
-	int server_fd, client_fd, err;
-	char cc[TCP_CA_NAME_MAX];
-	socklen_t len;
+	int server_fd, client_fd;
 
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))
@@ -393,19 +380,8 @@ static void run_subflow(char *new)
 	if (!ASSERT_GE(client_fd, 0, "connect to fd"))
 		goto close_server;
 
-	len = sizeof(cc);
-	err = getsockopt(server_fd, SOL_TCP, TCP_CONGESTION, cc, &len);
-	if (!ASSERT_OK(err, "getsockopt(server_fd, TCP_CONGESTION)"))
-		goto close_client;
-
 	send_byte(client_fd);
 
-	ASSERT_OK(ss_search(ADDR_1, "fwmark:0x1"), "ss_search fwmark:0x1");
-	ASSERT_OK(ss_search(ADDR_2, "fwmark:0x2"), "ss_search fwmark:0x2");
-	ASSERT_OK(ss_search(ADDR_1, new), "ss_search new cc");
-	ASSERT_OK(ss_search(ADDR_2, cc), "ss_search default cc");
-
-close_client:
 	close(client_fd);
 close_server:
 	close(server_fd);
@@ -441,7 +417,7 @@ static void test_subflow(void)
 	if (endpoint_init("subflow") < 0)
 		goto close_netns;
 
-	run_subflow(skel->data->cc);
+	run_subflow();
 
 close_netns:
 	cleanup_netns(nstoken);
@@ -470,9 +446,15 @@ static struct nstoken *sched_init(char *flags, char *sched)
 	return NULL;
 }
 
+static int ss_search(char *src, char *dst, char *port, char *keyword)
+{
+	return SYS_NOFAIL("ip netns exec %s ss -enita src %s dst %s %s %d | grep -q '%s'",
+			  NS_TEST, src, dst, port, PORT_1, keyword);
+}
+
 static int has_bytes_sent(char *dst)
 {
-	return _ss_search(ADDR_1, dst, "sport", "bytes_sent:");
+	return ss_search(ADDR_1, dst, "sport", "bytes_sent:");
 }
 
 static void send_data_and_verify(char *sched, bool addr1, bool addr2)
Signature · 1 line
2.43.0
author reviewer
#2 lore raw

PATCH v3 2/2 selftests/bpf: Add getsockopt to inspect mptcp subflow

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch adds a "cgroup/getsockopt" way to inspect the subflows of a mptcp socket.

mptcp_for_each_stubflow() and other helpers related to list_dentry are added into progs/mptcp_bpf.h.

Add an extra "cgroup/getsockopt" prog to walk the msk->conn_list and use bpf_core_cast to cast a pointer to tcp_sock for readonly. It will allow to inspect all the fields in a tcp_sock.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 23 ++++++++
 tools/testing/selftests/bpf/progs/mptcp_bpf.h | 35 ++++++++++++
 .../selftests/bpf/progs/mptcp_subflow.c       | 55 +++++++++++++++++++
 3 files changed, 113 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +23 -0
index d4c5209fbfaf..143ed1c756e1 100644
@@ -371,6 +371,10 @@ static int endpoint_init(char *flags)
 static void run_subflow(void)
 {
 	int server_fd, client_fd;
+	char cc[TCP_CA_NAME_MAX];
+	unsigned int mark;
+	socklen_t len;
+	int err;
 
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))
@@ -382,6 +386,18 @@ static void run_subflow(void)
 
 	send_byte(client_fd);
 
+	sleep(0.1);
+
+	len = sizeof(mark);
+	err = getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len);
+	if (!ASSERT_OK(err, "getsockopt(client_fd, SO_MARK)"))
+		goto close_client;
+
+	len = sizeof(cc);
+	err = getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len);
+	ASSERT_OK(err, "getsockopt(client_fd, TCP_CONGESTION)");
+
+close_client:
 	close(client_fd);
 close_server:
 	close(server_fd);
@@ -392,6 +408,7 @@ static void test_subflow(void)
 	int cgroup_fd, prog_fd, err;
 	struct mptcp_subflow *skel;
 	struct nstoken *nstoken;
+	struct bpf_link *link;
 
 	cgroup_fd = test__join_cgroup("/mptcp_subflow");
 	if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup: mptcp_subflow"))
@@ -417,6 +434,11 @@ static void test_subflow(void)
 	if (endpoint_init("subflow") < 0)
 		goto close_netns;
 
+	link = bpf_program__attach_cgroup(skel->progs._getsockopt_subflow,
+					  cgroup_fd);
+	if (!ASSERT_OK_PTR(link, "getsockopt prog"))
+		goto close_netns;
+
 	run_subflow();
 
 close_netns:
@@ -425,6 +447,7 @@ static void test_subflow(void)
 	mptcp_subflow__destroy(skel);
 close_cgroup:
 	close(cgroup_fd);
+	bpf_link__destroy(link);
 }
 
 static struct nstoken *sched_init(char *flags, char *sched)
tools/testing/selftests/bpf/progs/mptcp_bpf.h +35 -0
index 782f36ed027e..70d9f5888976 100644
@@ -4,9 +4,44 @@
 
 #include <vmlinux.h>
 #include <bpf/bpf_core_read.h>
+#include "bpf_experimental.h"
 
 #define MPTCP_SUBFLOWS_MAX 8
 
+static inline int list_is_head(const struct list_head *list,
+			       const struct list_head *head)
+{
+	return list == head;
+}
+
+#define list_entry(ptr, type, member)					\
+	container_of(ptr, type, member)
+
+#define list_first_entry(ptr, type, member)				\
+	list_entry((ptr)->next, type, member)
+
+#define list_next_entry(pos, member)					\
+	list_entry((pos)->member.next, typeof(*(pos)), member)
+
+#define list_entry_is_head(pos, head, member)				\
+	list_is_head(&pos->member, (head))
+
+#define list_for_each_entry(pos, head, member)				\
+	for (pos = list_first_entry(head, typeof(*pos), member);	\
+	     !list_entry_is_head(pos, head, member);			\
+	     cond_break, pos = list_next_entry(pos, member))
+
+#define list_for_each_entry_safe(pos, n, head, member)			\
+	for (pos = list_first_entry(head, typeof(*pos), member),	\
+		n = list_next_entry(pos, member);			\
+	     !list_entry_is_head(pos, head, member);			\
+	     cond_break, pos = n, n = list_next_entry(n, member))
+
+#define mptcp_for_each_subflow(__msk, __subflow)			\
+	list_for_each_entry(__subflow, &((__msk)->conn_list), node)
+#define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp)		\
+	list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node)
+
 extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
 					bool scheduled) __ksym;
 
tools/testing/selftests/bpf/progs/mptcp_subflow.c +55 -0

64 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH mptcp-next v3 2/2] selftests/bpf: Add getsockopt to inspect mptcp subflow

Hi Geliang,

Thank you for the update!

Quoted 11 lines · Geliang Tang

From: Geliang Tang <[email protected]>

This patch adds a "cgroup/getsockopt" way to inspect the subflows of a mptcp socket.

mptcp_for_each_stubflow() and other helpers related to list_dentry are added into progs/mptcp_bpf.h.

Add an extra "cgroup/getsockopt" prog to walk the msk->conn_list and use bpf_core_cast to cast a pointer to tcp_sock for readonly. It will allow to inspect all the fields in a tcp_sock.

Should this not be squashed in "selftests/bpf: Add mptcp subflow subtest" as well?

Quoted 25 lines
---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 23 ++++++++
 tools/testing/selftests/bpf/progs/mptcp_bpf.h | 35 ++++++++++++
 .../selftests/bpf/progs/mptcp_subflow.c       | 55 +++++++++++++++++++
 3 files changed, 113 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +4 -0
index d4c5209fbfaf..143ed1c756e1 100644
@@ -371,6 +371,10 @@ static int endpoint_init(char *flags)
 static void run_subflow(void)
 {
 	int server_fd, client_fd;
+	char cc[TCP_CA_NAME_MAX];
+	unsigned int mark;
+	socklen_t len;
+	int err;
 
 	server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
 	if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))

tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(void) · line 389

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
@@ -382,6 +386,18 @@ static void run_subflow(void)
 
 	send_byte(client_fd);
 
+	sleep(0.1);

Why do you need a sleep here? To make sure the extra subflow has been created? It sounds safer to wait for an event here, no? Maybe simply with:

  #ifndef SOL_MPTCP
  #define SOL_MPTCP 284
  #endif

  #ifndef MPTCP_INFO
  #define MPTCP_INFO 1
  #endif

(...)

u8 subflows;
int i;

(...)

  len = sizeof(subflows);

  /* Wait max 1 sec for new subflows to be created */
  for (i = 0; i < 10; i++) {
      err = getsockopt(fd, SOL_MPTCP, MPTCP_INFO, &subflows, &len);
      if (!err && subflows > 0)
          break;

      sleep(0.1);

}

WDYT? It might make sense to add this in a new helper:

  wait_for_new_subflows(client_fd);

Also, just to be sure, when does the BPF program set the socket options per subflow? When the subflows are created? Just to be sure it is always done before this call to 'getsockopt()', and only once.

tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(void) · line 393

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +4 -0
+
+	len = sizeof(mark);
+	err = getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len);
+	if (!ASSERT_OK(err, "getsockopt(client_fd, SO_MARK)"))

Should we also check the value of 'mark' here?

tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(void) · line 394

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+		goto close_client;

Maybe it is not needed to stop earlier here, we can also check the value of the TCP CC and have info about the two checks? But maybe we need to return an error if this getsockopt() fails, but not the next one.

  err = getsockopt(TCP_CONGESTION) || err;

tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(void) · line 398

Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +3 -0
+	len = sizeof(cc);
+	err = getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len);
+	ASSERT_OK(err, "getsockopt(client_fd, TCP_CONGESTION)");

Here as well, we could check that 'cc' is the same as 'skel->data->cc', because MPTCP will return the value from the first subflow.

Or, we change the BPF test to set a different TCP CC only on the second subflow, then we compare this getsockopt() with the default value from there:

/proc/sys/net/ipv4/tcp_congestion_control

The validation in BPF will then check the value of the second subflow and it should be 'reno'.

Quoted 56 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +9 -0
+
+close_client:
 	close(client_fd);
 close_server:
 	close(server_fd);
@@ -392,6 +408,7 @@ static void test_subflow(void)
 	int cgroup_fd, prog_fd, err;
 	struct mptcp_subflow *skel;
 	struct nstoken *nstoken;
+	struct bpf_link *link;
 
 	cgroup_fd = test__join_cgroup("/mptcp_subflow");
 	if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup: mptcp_subflow"))
@@ -417,6 +434,11 @@ static void test_subflow(void)
 	if (endpoint_init("subflow") < 0)
 		goto close_netns;
 
+	link = bpf_program__attach_cgroup(skel->progs._getsockopt_subflow,
+					  cgroup_fd);
+	if (!ASSERT_OK_PTR(link, "getsockopt prog"))
+		goto close_netns;
+
 	run_subflow();
 
 close_netns:
@@ -425,6 +447,7 @@ static void test_subflow(void)
 	mptcp_subflow__destroy(skel);
 close_cgroup:
 	close(cgroup_fd);
+	bpf_link__destroy(link);
 }
 
 static struct nstoken *sched_init(char *flags, char *sched)
tools/testing/selftests/bpf/progs/mptcp_bpf.h +12 -0
index 782f36ed027e..70d9f5888976 100644
@@ -4,9 +4,44 @@
 
 #include <vmlinux.h>
 #include <bpf/bpf_core_read.h>
+#include "bpf_experimental.h"
 
 #define MPTCP_SUBFLOWS_MAX 8
 
+static inline int list_is_head(const struct list_head *list,
+			       const struct list_head *head)
+{
+	return list == head;
+}
+
+#define list_entry(ptr, type, member)					\
+	container_of(ptr, type, member)
+
+#define list_first_entry(ptr, type, member)				\
+	list_entry((ptr)->next, type, member)

tools/testing/selftests/bpf/progs/mptcp_bpf.h line 31

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +10 -0
+
+#define list_next_entry(pos, member)					\
+	list_entry((pos)->member.next, typeof(*(pos)), member)
+
+#define list_entry_is_head(pos, head, member)				\
+	list_is_head(&pos->member, (head))
+
+#define list_for_each_entry(pos, head, member)				\
+	for (pos = list_first_entry(head, typeof(*pos), member);	\
+	     !list_entry_is_head(pos, head, member);			\

I guess you cannot add 'cond_break' in the condition, because that's the equivalent of 'break', right?

Also, just to be sure: can this 'cond_break' be used on all architectures? If not, maybe best to have a "list_for_each_entry" version that is specific to MPTCP subflows, with a "i < MPTCP_SUBFLOWS_MAX".

tools/testing/selftests/bpf/progs/mptcp_bpf.h line 37

Quoted 6 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +6 -0
+	     cond_break, pos = list_next_entry(pos, member))
+
+#define list_for_each_entry_safe(pos, n, head, member)			\
+	for (pos = list_first_entry(head, typeof(*pos), member),	\
+		n = list_next_entry(pos, member);			\
+	     !list_entry_is_head(pos, head, member);			\

Same here for 'cond_break'.

Quoted 31 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +7 -0
+	     cond_break, pos = n, n = list_next_entry(n, member))
+
+#define mptcp_for_each_subflow(__msk, __subflow)			\
+	list_for_each_entry(__subflow, &((__msk)->conn_list), node)
+#define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp)		\
+	list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node)
+
 extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
 					bool scheduled) __ksym;
 
tools/testing/selftests/bpf/progs/mptcp_subflow.c +6 -0
index bc572e1d6df8..e8cc157278d2 100644
@@ -4,6 +4,7 @@
 
 /* vmlinux.h, bpf_helpers.h and other 'define' */
 #include "bpf_tracing_net.h"
+#include "mptcp_bpf.h"
 
 char _license[] SEC("license") = "GPL";
 
@@ -57,3 +58,57 @@ int mptcp_subflow(struct bpf_sock_ops *skops)
 
 	return 1;
 }
+
+static int _check_getsockopt_subflows_mark(struct mptcp_sock *msk, struct bpf_sockopt *ctx)
+{
+	struct mptcp_subflow_context *subflow;
+	int i = 0;

tools/testing/selftests/bpf/progs/mptcp_subflow.c int mptcp_subflow(struct bpf_sock_ops *skops) · line 75

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +10 -0
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct sock *ssk;
+
+		ssk = mptcp_subflow_tcp_sock(bpf_core_cast(subflow,
+							   struct mptcp_subflow_context));
+
+		if (ssk->sk_mark != ++i)
+			ctx->retval = -1;
+	}

I think you should check here that 'i == 2', otherwise we are not checking all the expected subflows.

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +10 -0
+
+	return 1;
+}
+
+static int _check_getsockopt_subflow_cc(struct mptcp_sock *msk, struct bpf_sockopt *ctx)
+{
+	struct mptcp_subflow_context *subflow, *tmp;
+
+	mptcp_for_each_subflow_safe(msk, subflow, tmp) {
+		struct inet_connection_sock *icsk;

tools/testing/selftests/bpf/progs/mptcp_subflow.c int mptcp_subflow(struct bpf_sock_ops *skops) · line 95

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +10 -0
+		struct sock *ssk;
+
+		ssk = mptcp_subflow_tcp_sock(bpf_core_cast(subflow,
+							   struct mptcp_subflow_context));
+		icsk = bpf_core_cast(ssk, struct inet_connection_sock);
+
+		if (ssk->sk_mark == 1 &&
+		    __builtin_memcmp(icsk->icsk_ca_ops->name, cc, TCP_CA_NAME_MAX))
+			ctx->retval = -1;
+	}

Same here, you should check the number of subflows that have been looked at (2), otherwise the check might succeed, while not doing any or half of the validation.

I think here it is better if the CC is modified on the second subflow, so we iterate at least 2 times, and expect to find the modified CC. WDYT?

tools/testing/selftests/bpf/progs/mptcp_subflow.c int mptcp_subflow(struct bpf_sock_ops *skops) · line 105

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +10 -0
+
+	return 1;
+}
+
+SEC("cgroup/getsockopt")
+int _getsockopt_subflow(struct bpf_sockopt *ctx)
+{
+	struct mptcp_sock *msk = bpf_core_cast(ctx->sk, struct mptcp_sock);
+
+	if (!msk || !msk->token)

Instead of checking the token, should you not check that

sk->sk_protocol == IPPROTO_MPTCP

no?

Just checking if there is something written at "*msk + token offset" looks a bit random to me, and not safe.

tools/testing/selftests/bpf/progs/mptcp_subflow.c int mptcp_subflow(struct bpf_sock_ops *skops) · line 114

Quoted 9 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +9 -0
+		return 1;
+
+	if (ctx->level == SOL_SOCKET && ctx->optname == SO_MARK)
+		return _check_getsockopt_subflows_mark(msk, ctx);
+	if (ctx->level == SOL_TCP && ctx->optname == TCP_CONGESTION)
+		return _check_getsockopt_subflow_cc(msk, ctx);
+
+	return 1;
+}

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#4 lore raw

Re: [PATCH mptcp-next v3 2/2] selftests/bpf: Add getsockopt to inspect mptcp subflow

Quoted 209 lines · Matthieu Baerts

Hi Geliang,

Thank you for the update!

Quoted 10 lines · Geliang Tang

From: Geliang Tang <[email protected]>

This patch adds a "cgroup/getsockopt" way to inspect the subflows of a
mptcp socket.

mptcp_for_each_stubflow() and other helpers related to list_dentry are
added into progs/mptcp_bpf.h.

Quoted 5 lines

Add an extra "cgroup/getsockopt" prog to walk the msk->conn_list and use
bpf_core_cast to cast a pointer to tcp_sock for readonly. It will allow
to inspect all the fields in a tcp_sock.

Should this not be squashed in "selftests/bpf: Add mptcp subflow subtest" as well?

Quoted 31 lines

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 23 ++++++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 35 ++++++++++++ .../selftests/bpf/progs/mptcp_subflow.c       | 55
+++++++++++++++++++

 3 files changed, 113 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +4 -0
index d4c5209fbfaf..143ed1c756e1 100644
@@ -371,6 +371,10 @@ static int endpoint_init(char *flags)
  static void run_subflow(void)
  {
  	int server_fd, client_fd;
+	char cc[TCP_CA_NAME_MAX];
+	unsigned int mark;
+	socklen_t len;
+	int err;


  server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
  if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))

tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -0
@@ -382,6 +386,18 @@ static void run_subflow(void)


  send_byte(client_fd);

tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(void) · line 389

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+	sleep(0.1);

Why do you need a sleep here? To make sure the extra subflow has been created? It sounds safer to wait for an event here, no? Maybe simply with:

  #ifndef SOL_MPTCP
  #define SOL_MPTCP 284
  #endif

  #ifndef MPTCP_INFO
  #define MPTCP_INFO 1
  #endif

  (...)

  u8 subflows;
  int i;

  (...)

  len = sizeof(subflows);

  /* Wait max 1 sec for new subflows to be created */ for (i = 0; i < 10; i++) {
      err = getsockopt(fd, SOL_MPTCP, MPTCP_INFO, &subflows, &len);

      if (!err && subflows > 0)
          break;

      sleep(0.1);
  }

WDYT? It might make sense to add this in a new helper:

  wait_for_new_subflows(client_fd);

Also, just to be sure, when does the BPF program set the socket options
per subflow? When the subflows are created? Just to be sure it is always
done before this call to 'getsockopt()', and only once.

tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(void) · line 393

Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +3 -0
+
+	len = sizeof(mark);
+	err = getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark,

&len);

tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+	if (!ASSERT_OK(err, "getsockopt(client_fd, SO_MARK)"))

Should we also check the value of 'mark' here?

tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(void) · line 394

Quoted 1 line
tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+		goto close_client;

Maybe it is not needed to stop earlier here, we can also check the value
of the TCP CC and have info about the two checks? But maybe we need to
return an error if this getsockopt() fails, but not the next one.

  err = getsockopt(TCP_CONGESTION) || err;

tools/testing/selftests/bpf/prog_tests/mptcp.c static void run_subflow(void) · line 398

Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -0
+	len = sizeof(cc);
+	err = getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc,

&len);

tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+	ASSERT_OK(err, "getsockopt(client_fd, TCP_CONGESTION)");

Here as well, we could check that 'cc' is the same as 'skel->data-

Quoted 1 line

cc',

because MPTCP will return the value from the first subflow.

Or, we change the BPF test to set a different TCP CC only on the second
subflow, then we compare this getsockopt() with the default value from
there:

  /proc/sys/net/ipv4/tcp_congestion_control

The validation in BPF will then check the value of the second subflow and it should be 'reno'.

Quoted 72 lines
tools/testing/selftests/bpf/prog_tests/mptcp.c +2 -0
+
+close_client:

  close(client_fd);
 close_server:
  close(server_fd);

tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
@@ -392,6 +408,7 @@ static void test_subflow(void)
  	int cgroup_fd, prog_fd, err;
  	struct mptcp_subflow *skel;
  	struct nstoken *nstoken;
+	struct bpf_link *link;


  cgroup_fd = test__join_cgroup("/mptcp_subflow"); if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup:
mptcp_subflow"))

tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -0
@@ -417,6 +434,11 @@ static void test_subflow(void)
  	if (endpoint_init("subflow") < 0)
  		goto close_netns;

tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+	link = bpf_program__attach_cgroup(skel-
Quoted 1 line

progs._getsockopt_subflow,

tools/testing/selftests/bpf/prog_tests/mptcp.c +4 -0
+					  cgroup_fd);
+	if (!ASSERT_OK_PTR(link, "getsockopt prog"))
+		goto close_netns;
+

  run_subflow();

 close_netns:

tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -0
@@ -425,6 +447,7 @@ static void test_subflow(void)
  	mptcp_subflow__destroy(skel);

 close_cgroup:
  close(cgroup_fd);

tools/testing/selftests/bpf/prog_tests/mptcp.c +1 -0
+	bpf_link__destroy(link);

 }

 static struct nstoken *sched_init(char *flags, char *sched)

tools/testing/selftests/bpf/progs/mptcp_bpf.h +0 -0
index 782f36ed027e..70d9f5888976 100644
@@ -4,9 +4,44 @@


 #include <vmlinux.h>
 #include <bpf/bpf_core_read.h>
+#include "bpf_experimental.h"

 #define MPTCP_SUBFLOWS_MAX 8

tools/testing/selftests/bpf/progs/mptcp_bpf.h +7 -0
+static inline int list_is_head(const struct list_head *list,
+			       const struct list_head *head)
+{
+	return list == head;
+}
+
+#define list_entry(ptr, type,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	container_of(ptr, type, member)
+
+#define list_first_entry(ptr, type,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_entry((ptr)->next, type, member)
+
+#define list_next_entry(pos,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_entry((pos)->member.next, typeof(*(pos)), member)
+
+#define list_entry_is_head(pos, head,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_is_head(&pos->member, (head))
+
+#define list_for_each_entry(pos, head,

member) \

Quoted 8 lines
Quoted 4 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	for (pos = list_first_entry(head, typeof(*pos),

member); \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	     !list_entry_is_head(pos, head,

member); \

I guess you cannot add 'cond_break' in the condition, because that's the
equivalent of 'break', right?

Hi Matt,

This confuses me.

I used this in v2:

	mptcp_for_each_subflow(msk, subflow) {
		... ...

		cond_break;
	}

And you suggested to add "cond_break" into list_for_each_entry().

Do you mean that I should go back to v2?

Regards,
-Geliang

Quoted 144 lines

Also, just to be sure: can this 'cond_break' be used on all architectures? If not, maybe best to have a "list_for_each_entry" version that is specific to MPTCP subflows, with a "i < MPTCP_SUBFLOWS_MAX".

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	     cond_break, pos = list_next_entry(pos, member))
+
+#define list_for_each_entry_safe(pos, n, head,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	for (pos = list_first_entry(head, typeof(*pos),

member), \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+		n = list_next_entry(pos,

member); \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	     !list_entry_is_head(pos, head,

member); \

Same here for 'cond_break'.

Quoted 46 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	     cond_break, pos = n, n = list_next_entry(n, member))
+
+#define mptcp_for_each_subflow(__msk,

__subflow) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	list_for_each_entry(__subflow, &((__msk)->conn_list),

node)
+#define mptcp_for_each_subflow_safe(__msk, __subflow,
__tmp) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	list_for_each_entry_safe(__subflow, __tmp, &((__msk)-
Quoted 1 line

conn_list), node)

+
 extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
  bool scheduled) __ksym;

tools/testing/selftests/bpf/progs/mptcp_subflow.c +0 -0
index bc572e1d6df8..e8cc157278d2 100644
@@ -4,6 +4,7 @@


 /* vmlinux.h, bpf_helpers.h and other 'define' */ #include "bpf_tracing_net.h"
+#include "mptcp_bpf.h"

 char _license[] SEC("license") = "GPL";

tools/testing/selftests/bpf/progs/mptcp_subflow.c +0 -0
@@ -57,3 +58,57 @@ int mptcp_subflow(struct bpf_sock_ops *skops)


  return 1;
 }

tools/testing/selftests/bpf/progs/mptcp_subflow.c +2 -0
+
+static int _check_getsockopt_subflows_mark(struct mptcp_sock *msk,

struct bpf_sockopt *ctx)

tools/testing/selftests/bpf/progs/mptcp_subflow.c +8 -0
+{
+	struct mptcp_subflow_context *subflow;
+	int i = 0;
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct sock *ssk;
+
+		ssk =

mptcp_subflow_tcp_sock(bpf_core_cast(subflow,

tools/testing/selftests/bpf/progs/mptcp_subflow.c +1 -0
+							   struct

mptcp_subflow_context));

tools/testing/selftests/bpf/progs/mptcp_subflow.c int mptcp_subflow(struct bpf_sock_ops *skops) · line 75

Quoted 4 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +4 -0
+
+		if (ssk->sk_mark != ++i)
+			ctx->retval = -1;
+	}

I think you should check here that 'i == 2', otherwise we are not checking all the expected subflows.

Quoted 23 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +5 -0
+
+	return 1;
+}
+
+static int _check_getsockopt_subflow_cc(struct mptcp_sock *msk,

struct bpf_sockopt *ctx)

tools/testing/selftests/bpf/progs/mptcp_subflow.c +8 -0
+{
+	struct mptcp_subflow_context *subflow, *tmp;
+
+	mptcp_for_each_subflow_safe(msk, subflow, tmp) {
+		struct inet_connection_sock *icsk;
+		struct sock *ssk;
+
+		ssk =

mptcp_subflow_tcp_sock(bpf_core_cast(subflow,

tools/testing/selftests/bpf/progs/mptcp_subflow.c +1 -0
+							   struct

mptcp_subflow_context));

tools/testing/selftests/bpf/progs/mptcp_subflow.c +1 -0
+		icsk = bpf_core_cast(ssk, struct

inet_connection_sock);

tools/testing/selftests/bpf/progs/mptcp_subflow.c +3 -0
+
+		if (ssk->sk_mark == 1 &&
+		    __builtin_memcmp(icsk->icsk_ca_ops->name, cc,

TCP_CA_NAME_MAX))

tools/testing/selftests/bpf/progs/mptcp_subflow.c

Quoted 2 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +2 -0
+			ctx->retval = -1;
+	}

Same here, you should check the number of subflows that have been looked
at (2), otherwise the check might succeed, while not doing any or half
of the validation.

I think here it is better if the CC is modified on the second subflow,
so we iterate at least 2 times, and expect to find the modified CC. WDYT?

tools/testing/selftests/bpf/progs/mptcp_subflow.c

Quoted 11 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +8 -0
+
+	return 1;
+}
+
+SEC("cgroup/getsockopt")
+int _getsockopt_subflow(struct bpf_sockopt *ctx)
+{
+	struct mptcp_sock *msk = bpf_core_cast(ctx->sk, struct

mptcp_sock);

tools/testing/selftests/bpf/progs/mptcp_subflow.c +2 -0
+
+	if (!msk || !msk->token)

Instead of checking the token, should you not check that

  sk->sk_protocol == IPPROTO_MPTCP

no?

Just checking if there is something written at "*msk + token offset" looks a bit random to me, and not safe.

tools/testing/selftests/bpf/progs/mptcp_subflow.c int mptcp_subflow(struct bpf_sock_ops *skops) · line 114

Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_subflow.c +5 -0
+		return 1;
+
+	if (ctx->level == SOL_SOCKET && ctx->optname == SO_MARK)
+		return _check_getsockopt_subflows_mark(msk, ctx);
+	if (ctx->level == SOL_TCP && ctx->optname ==

TCP_CONGESTION)

tools/testing/selftests/bpf/progs/mptcp_subflow.c +4 -0
+		return _check_getsockopt_subflow_cc(msk, ctx);
+
+	return 1;
+}

Cheers,
Matt

maintainer
#5 lore raw

Re: [PATCH mptcp-next v3 2/2] selftests/bpf: Add getsockopt to inspect mptcp subflow

Quoted 3 lines · Geliang Tang
Quoted 2 lines · Matthieu Baerts
Quoted 1 line · Geliang Tang

From: Geliang Tang <[email protected]>

(...)

Quoted 58 lines
Quoted 37 lines
Quoted 37 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +0 -0
index 782f36ed027e..70d9f5888976 100644
@@ -4,9 +4,44 @@


 #include <vmlinux.h>
 #include <bpf/bpf_core_read.h>
+#include "bpf_experimental.h"

 #define MPTCP_SUBFLOWS_MAX 8

tools/testing/selftests/bpf/progs/mptcp_bpf.h +7 -0
+static inline int list_is_head(const struct list_head *list,
+			       const struct list_head *head)
+{
+	return list == head;
+}
+
+#define list_entry(ptr, type,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	container_of(ptr, type, member)
+
+#define list_first_entry(ptr, type,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_entry((ptr)->next, type, member)
+
+#define list_next_entry(pos,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_entry((pos)->member.next, typeof(*(pos)), member)
+
+#define list_entry_is_head(pos, head,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_is_head(&pos->member, (head))
+
+#define list_for_each_entry(pos, head,

member) \

Quoted 8 lines
Quoted 4 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	for (pos = list_first_entry(head, typeof(*pos),

member); \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	     !list_entry_is_head(pos, head,

member); \

I guess you cannot add 'cond_break' in the condition, because that's the
equivalent of 'break', right?

Hi Matt,

This confuses me.

I used this in v2:

	mptcp_for_each_subflow(msk, subflow) {
		... ...

		cond_break;
	}
Quoted 3 lines

And you suggested to add "cond_break" into list_for_each_entry().

Do you mean that I should go back to v2?

No, sorry, I was just initially surprised to see 'cond_break' in the last part of the 'for', not in second part: the condition to stop the loop. But I then saw that 'cond_break' is a cryptic define, doing the equivalent of a "break", not just a simple condition, it has be where you added it.

I'm personally a bit annoy to see a copy of all these "define" for the list here in mptcp_bpf.h, but maybe it is normal, and accepted by BPF maintainers. Thanks to the 'cond_break' you added there, they look quite generic, and not specific to MPTCP. They could go elsewhere, but maybe nobody else needs to iterate a list in the BPF selftests. And they can always be moved later on I suppose. So no need to change that in the v4.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#6 lore raw

Re: [PATCH mptcp-next v3 2/2] selftests/bpf: Add getsockopt to inspect mptcp subflow

Hi Matt,

Quoted 66 lines · Matthieu Baerts
Quoted 3 lines · Geliang Tang
Quoted 2 lines · Matthieu Baerts
Quoted 1 line · Geliang Tang

From: Geliang Tang <[email protected]>

(...)

Quoted 59 lines
Quoted 38 lines
Quoted 38 lines
tools/testing/selftests/bpf/progs/mptcp_bpf.h +0 -0
index 782f36ed027e..70d9f5888976 100644
@@ -4,9 +4,44 @@


 #include <vmlinux.h>
 #include <bpf/bpf_core_read.h>
+#include "bpf_experimental.h"

 #define MPTCP_SUBFLOWS_MAX 8

tools/testing/selftests/bpf/progs/mptcp_bpf.h +7 -0
+static inline int list_is_head(const struct list_head *list,
+			       const struct list_head *head)
+{
+	return list == head;
+}
+
+#define list_entry(ptr, type,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	container_of(ptr, type, member)
+
+#define list_first_entry(ptr, type,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_entry((ptr)->next, type, member)
+
+#define list_next_entry(pos,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_entry((pos)->member.next, typeof(*(pos)), member)
+
+#define list_entry_is_head(pos, head,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
+	list_is_head(&pos->member, (head))
+
+#define list_for_each_entry(pos, head,

member) \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	for (pos = list_first_entry(head, typeof(*pos),
Quoted 8 lines
Quoted 3 lines

member); \

tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
+	     !list_entry_is_head(pos, head,

member); \

I guess you cannot add 'cond_break' in the condition, because that's
the
equivalent of 'break', right?

Hi Matt,

This confuses me.

I used this in v2:

	mptcp_for_each_subflow(msk, subflow) {
		... ...

		cond_break;
	}
Quoted 6 lines
Quoted 3 lines

And you suggested to add "cond_break" into list_for_each_entry().

Do you mean that I should go back to v2?

No, sorry, I was just initially surprised to see 'cond_break' in the last part of the 'for', not in second part: the condition to stop the

Yes, you're right. It's better to add 'cond_break' in second part of 'for', not the last one. Updated this in v4. And v4 addresses your other comments in v3 too.

Thanks,
-Geliang

Quoted 18 lines

loop. But I then saw that 'cond_break' is a cryptic define, doing the equivalent of a "break", not just a simple condition, it has be where you added it.

I'm personally a bit annoy to see a copy of all these "define" for the
list here in mptcp_bpf.h, but maybe it is normal, and accepted by BPF maintainers. Thanks to the 'cond_break' you added there, they look quite
generic, and not specific to MPTCP. They could go elsewhere, but maybe
nobody else needs to iterate a list in the BPF selftests. And they can
always be moved later on I suppose. So no need to change that in the v4.

Cheers,
Matt

#7 lore raw
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: Success! ✅
- KVM Validation: debug: Unstable: 1 failed test(s): packetdrill_mp_join 🔴
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/10505702786

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/4dd5dad52fbd
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=882086

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-normal

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 (NGI0 Core)