export send_recv_data
Subsystems (4)
Geliang Tang
reviewerv4 cover export send_recv_data
From: Geliang Tang <[email protected]>
v4:
- fix a bug in v3, it should be 'if (err)', not 'if (!err)'.
- move "selftests/bpf: Use log_err in network_helpers" out of this series.
v3:
- add two more patches.
- use log_err instead of ASSERT in v3.
- let send_recv_data return int as Martin suggested.
v2:
Address Martin's comments for v1 (thanks.)
- drop patch 1, "export send_byte helper".
- drop "WRITE_ONCE(arg.stop, 0)".
- rebased.
send_recv_data will be re-used in MPTCP bpf tests, but not included in this set because it depends on other patches that have not been in the bpf-next yet. It will be sent as another set soon.
Geliang Tang (3):
selftests/bpf: Add struct send_recv_arg selftests/bpf: Export send_recv_data helper selftests/bpf: Support nonblock for send_recv_data
tools/testing/selftests/bpf/network_helpers.c | 103 ++++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 71 +----------- 3 files changed, 105 insertions(+), 70 deletions(-)
Signature · 1 line
2.40.1
Geliang Tang
reviewerPATCH v4 1/3 selftests/bpf: Add struct send_recv_arg
From: Geliang Tang <[email protected]>
Avoid setting total_bytes and stop as global variables, this patch adds a new struct named send_recv_arg to pass arguments between threads. Put these two variables together with fd into this struct and pass it to server thread, so that server thread can access these two variables without setting them as global ones.
--- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +22 -12
@@ -21,7 +21,6 @@static const unsigned int total_bytes =10 *1024 *1024 ;static int expected_stg =0xeB9F ; -static int stop;static int settcpca (int fd,const char *tcp_ca) {
@@ -34,13 +33,20 @@ static int settcpca(int fd, const char *tcp_ca)return 0 ; } +struct send_recv_arg { +int fd; +uint32_t bytes; +int stop; +}; +static void *server (void *arg) { -int lfd = (int )(long )arg, err =0 , fd; +struct send_recv_arg *a = (struct send_recv_arg *)arg;ssize_t nr_sent =0 , bytes =0 ;char batch[1500 ]; +int err =0 , fd; - fd =accept (lfd,NULL ,NULL ); + fd =accept (a->fd,NULL ,NULL );while (fd ==-1 ) {if (errno ==EINTR )continue ;
@@ -53,9 +59,9 @@ static void *server(void *arg) goto done; } -while (bytes < total_bytes && !READ_ONCE (stop)) { +while (bytes < a->bytes && !READ_ONCE (a->stop)) { nr_sent =send (fd, &batch, -MIN (total_bytes - bytes,sizeof (batch)),0 ); +MIN (a->bytes - bytes,sizeof (batch)),0 );if (nr_sent ==-1 && errno ==EINTR )continue ;if (nr_sent ==-1 ) {
@@ -65,13 +71,13 @@ static void *server(void *arg) bytes += nr_sent; } -ASSERT_EQ (bytes, total_bytes,"send" ); +ASSERT_EQ (bytes, a->bytes,"send" ); done:if (fd >=0 )close (fd);if (err) { -WRITE_ONCE (stop,1 ); +WRITE_ONCE (a->stop,1 );return ERR_PTR (err); }return NULL ;
@@ -80,18 +86,22 @@ static void *server(void *arg)static void do_test (const char *tcp_ca,const struct bpf_map *sk_stg_map) {ssize_t nr_recv =0 , bytes =0 ; +struct send_recv_arg arg = { + .bytes = total_bytes, + .stop =0 , + };int lfd =-1 , fd =-1 ;pthread_t srv_thread;void *thread_ret;char batch[1500 ];int err; -WRITE_ONCE (stop,0 ); - lfd =start_server (AF_INET6 ,SOCK_STREAM ,NULL ,0 ,0 );if (!ASSERT_NEQ (lfd,-1 ,"socket" ))return ; + arg.fd = lfd; + fd =socket (AF_INET6 ,SOCK_STREAM ,0 );if (!ASSERT_NEQ (fd,-1 ,"socket" )) {close (lfd);
@@ -123,12 +133,12 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) goto done; } - err =pthread_create (&srv_thread,NULL , server, (void *)(long )lfd); + err =pthread_create (&srv_thread,NULL , server, (void *)&arg);if (!ASSERT_OK (err,"pthread_create" )) goto done;/* recv total_bytes */ -while (bytes < total_bytes && !READ_ONCE (stop)) { +while (bytes < total_bytes && !READ_ONCE (arg.stop)) { nr_recv =recv (fd, &batch,MIN (total_bytes - bytes,sizeof (batch)),0 );if (nr_recv ==-1 && errno ==EINTR )
@@ -140,7 +150,7 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)ASSERT_EQ (bytes, total_bytes,"recv" ); -WRITE_ONCE (stop,1 ); +WRITE_ONCE (arg.stop,1 );pthread_join (srv_thread, &thread_ret);ASSERT_OK (IS_ERR (thread_ret),"thread_ret" );
Signature · 1 line
2.40.1
Geliang Tang
reviewerPATCH v4 2/3 selftests/bpf: Export send_recv_data helper
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch extracts the code to send and receive data into a new helper named send_recv_data() in network_helpers.c and export it in network_helpers.h.
This helper will be used for MPTCP BPF selftests.
--- tools/testing/selftests/bpf/network_helpers.c | 96 +++++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 1 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 81 +--------------- 3 files changed, 98 insertions(+), 80 deletions(-)
tools/testing/selftests/bpf/network_helpers.c +96 -0
@@ -545,3 +545,99 @@ int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)close (sockfd);return 0 ; } + +struct send_recv_arg { +int fd; +uint32_t bytes; +int stop; +}; + +static void *send_recv_server (void *arg) +{ +struct send_recv_arg *a = (struct send_recv_arg *)arg; +ssize_t nr_sent =0 , bytes =0 ; +char batch[1500 ]; +int err =0 , fd; + + fd =accept (a->fd,NULL ,NULL ); +while (fd ==-1 ) { +if (errno ==EINTR ) +continue ; + err = -errno; + goto done; + } + +if (settimeo (fd,0 )) { + err = -errno; + goto done; + } + +while (bytes < a->bytes && !READ_ONCE (a->stop)) { + nr_sent =send (fd, &batch, +MIN (a->bytes - bytes,sizeof (batch)),0 ); +if (nr_sent ==-1 && errno ==EINTR ) +continue ; +if (nr_sent ==-1 ) { + err = -errno; +break ; + } + bytes += nr_sent; + } + +if (bytes != a->bytes) +log_err ("send" ); + +done: +if (fd >=0 ) +close (fd); +if (err) { +WRITE_ONCE (a->stop,1 ); +return ERR_PTR (err); + } +return NULL ; +} + +int send_recv_data (int lfd,int fd,uint32_t total_bytes) +{ +ssize_t nr_recv =0 , bytes =0 ; +struct send_recv_arg arg = { + .fd = lfd, + .bytes = total_bytes, + .stop =0 , + }; +pthread_t srv_thread; +void *thread_ret; +char batch[1500 ]; +int err; + + err =pthread_create (&srv_thread,NULL , send_recv_server, (void *)&arg); +if (err) { +log_err ("pthread_create" ); +return err; + } + +/* recv total_bytes */ +while (bytes < total_bytes && !READ_ONCE (arg.stop)) { + nr_recv =recv (fd, &batch, +MIN (total_bytes - bytes,sizeof (batch)),0 ); +if (nr_recv ==-1 && errno ==EINTR ) +continue ; +if (nr_recv ==-1 ) +break ; + bytes += nr_recv; + } + +if (bytes != total_bytes) { +log_err ("recv" ); +return -1 ; + } + +WRITE_ONCE (arg.stop,1 ); +pthread_join (srv_thread, &thread_ret); +if (IS_ERR (thread_ret)) { +log_err ("thread_ret" ); +return -1 ; + } + +return 0 ; +}
tools/testing/selftests/bpf/network_helpers.h +1 -0
@@ -76,6 +76,7 @@ struct nstoken;*/ struct nstoken *open_netns (const char *name);void close_netns (struct nstoken *token); +int send_recv_data (int lfd,int fd,uint32_t total_bytes);static __u16 csum_fold (__u32 csum) {
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +1 -80
102 lines not on this page · raw message
Signature · 1 line
2.40.1
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v4 2/3] selftests/bpf: Export send_recv_data helper
Quoted 23 lines · Geliang Tang
tools/testing/selftests/bpf/network_helpers.c +23
-0+int send_recv_data (int lfd,int fd,uint32_t total_bytes) +{ +ssize_t nr_recv =0 , bytes =0 ; +struct send_recv_arg arg = { + .fd = lfd, + .bytes = total_bytes, + .stop =0 , + }; +pthread_t srv_thread; +void *thread_ret; +char batch[1500 ]; +int err; + + err =pthread_create (&srv_thread,NULL , send_recv_server, (void *)&arg); +if (err) { +log_err ("pthread_create" ); +return err; + } + +/* recv total_bytes */ +while (bytes < total_bytes && !READ_ONCE (arg.stop)) { + nr_recv =recv (fd, &batch, +MIN (total_bytes - bytes,sizeof (batch)),0 );
tools/testing/selftests/bpf/network_helpers.c int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param) · line 632
Quoted 10 lines
tools/testing/selftests/bpf/network_helpers.c +10
-0+if (nr_recv ==-1 && errno ==EINTR ) +continue ; +if (nr_recv ==-1 ) +break ; + bytes += nr_recv; + } + +if (bytes != total_bytes) { +log_err ("recv" ); +return -1 ;
This is still not right. It needs to write arg.stop and do pthread_join().
pw-bot: cr
Quoted 11 lines
tools/testing/selftests/bpf/network_helpers.c +11
-0+ } + +WRITE_ONCE (arg.stop,1 ); +pthread_join (srv_thread, &thread_ret); +if (IS_ERR (thread_ret)) { +log_err ("thread_ret" ); +return -1 ; + } + +return 0 ; +}
Geliang Tang
reviewerPATCH v4 3/3 selftests/bpf: Support nonblock for send_recv_data
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Some tests, such as the MPTCP bpf tests, require send_recv_data helper to run in nonblock mode.
This patch adds nonblock support for send_recv_data(). Check if it is currently in nonblock mode, and if so, ignore EWOULDBLOCK to continue sending and receiving.
--- tools/testing/selftests/bpf/network_helpers.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/network_helpers.c +8 -1
@@ -555,6 +555,7 @@ struct send_recv_arg {static void *send_recv_server (void *arg) {struct send_recv_arg *a = (struct send_recv_arg *)arg; +int flags =fcntl (a->fd,F_GETFL );ssize_t nr_sent =0 , bytes =0 ;char batch[1500 ];int err =0 , fd;
@@ -578,6 +579,8 @@ static void *send_recv_server(void *arg)if (nr_sent ==-1 && errno ==EINTR )continue ;if (nr_sent ==-1 ) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK ) +continue ; err = -errno;break ; }
@@ -599,6 +602,7 @@ static void *send_recv_server(void *arg)int send_recv_data (int lfd,int fd,uint32_t total_bytes) { +int flags =fcntl (lfd,F_GETFL );ssize_t nr_recv =0 , bytes =0 ;struct send_recv_arg arg = { .fd = lfd,
@@ -622,8 +626,11 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes) MIN(total_bytes - bytes, sizeof(batch)), 0);if (nr_recv ==-1 && errno ==EINTR )continue ; -if (nr_recv ==-1 ) +if (nr_recv ==-1 ) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK ) +continue ;break ; + } bytes += nr_recv; }
Signature · 1 line
2.40.1
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
Quoted 27 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Some tests, such as the MPTCP bpf tests, require
send_recv_datahelper to run in nonblock mode.This patch adds nonblock support for
send_recv_data(). Check if it is currently in nonblock mode, and if so, ignore EWOULDBLOCK to continue sending and receiving.Signed-off-by Geliang Tang <[email protected]>--- tools/testing/selftests/bpf/network_helpers.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -555,6 +555,7 @@ struct send_recv_arg {static void *send_recv_server (void *arg) {struct send_recv_arg *a = (struct send_recv_arg *)arg; +int flags =fcntl (a->fd,F_GETFL );ssize_t nr_sent =0 , bytes =0 ;char batch[1500 ];int err =0 , fd;
tools/testing/selftests/bpf/network_helpers.c static void *send_recv_server(void *arg) · line 582
Quoted 4 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -578,6 +579,8 @@ static void *send_recv_server(void *arg)if (nr_sent ==-1 && errno ==EINTR )continue ;if (nr_sent ==-1 ) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK )
I still don't see why it needs to be a non blocking IO. mptcp should work with blocking IO also, no? Does it really need non blocking IO to make mptcp test work? I would rather stay with blocking IO in selftest as much as possible for simplicity reason.
I am afraid the root cause of the EAGAIN thread has not been figured out yet:
https://lore.kernel.org/all/[email protected]/
Lets drop patch 3 until it is understood why mptcp needs EAGAIN or non-blocking IO. It feels like there is some flakiness and it should be understood and avoided.
Other than the comment in patch 2, the first two patches lgtm. Please respin with the first two patches.
Quoted 25 lines
tools/testing/selftests/bpf/network_helpers.c +6
-1+continue ; err = -errno;break ; }@@ -599,6 +602,7 @@ static void *send_recv_server(void *arg)int send_recv_data (int lfd,int fd,uint32_t total_bytes) { +int flags =fcntl (lfd,F_GETFL );ssize_t nr_recv =0 , bytes =0 ;struct send_recv_arg arg = { .fd = lfd,@@ -622,8 +626,11 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes) MIN(total_bytes - bytes, sizeof(batch)), 0);if (nr_recv ==-1 && errno ==EINTR )continue ; -if (nr_recv ==-1 ) +if (nr_recv ==-1 ) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK ) +continue ;break ; + } bytes += nr_recv; }
Geliang Tang
reviewerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
mptcp-only
Hi Matt & Mat,
Quoted 38 lines · Martin KaFai Lau
Quoted 31 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Some tests, such as the MPTCP bpf tests, require
send_recv_datahelper
to run in nonblock mode.This patch adds nonblock support for
send_recv_data(). Check if it is
currently in nonblock mode, and if so, ignore EWOULDBLOCK to continue
sending and receiving.Signed-off-by Geliang Tang <[email protected]>---
tools/testing/selftests/bpf/network_helpers.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -555,6 +555,7 @@ struct send_recv_arg { static void *send_recv_server(void *arg) { struct send_recv_arg *a = (struct send_recv_arg *)arg; +int flags =fcntl (a->fd,F_GETFL ); ssize_t nr_sent = 0, bytes = 0; char batch[1500]; int err = 0, fd;tools/testing/selftests/bpf/network_helpers.c static void *send_recv_server(void *arg) · line 583
Quoted 5 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -578,6 +579,8 @@ static void *send_recv_server(void *arg) if (nr_sent == -1 && errno == EINTR) continue; if (nr_sent == -1) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK )
Quoted 7 lines
I still don't see why it needs to be a non blocking IO. mptcp should work
with blocking IO also, no? Does it really need non blocking IO to make
mptcp test work? I would rather stay with blocking IO in selftest as much as
possible for simplicity reason.
I need some help here.
This issue is reported by Matt in "CI: MPTCP BPF tests are now validated", and my fixes ([1] and this patch) aren't accepted by Martin. Is it normal to get EAGAINs in this case? Please give some suggestions.
Thanks,
-Geliang
Quoted 44 lines
I am afraid the root cause of the EAGAIN thread has not been figured out yet:
https://lore.kernel.org/all/[email protected]/Lets drop patch 3 until it is understood why mptcp needs EAGAIN or non-blocking IO.
It feels like there is some flakiness and it should be understood and avoided.Other than the comment in patch 2, the first two patches lgtm. Please respin with
the first two patches.Quoted 28 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0+continue ; err = -errno; break;}
tools/testing/selftests/bpf/network_helpers.c +0
-0@@ -599,6 +602,7 @@ static void *send_recv_server(void *arg)
intsend_recv_data(int lfd, int fd, uint32_t total_bytes){tools/testing/selftests/bpf/network_helpers.c +1
-0+int flags =fcntl (lfd,F_GETFL );
ssize_tnr_recv= 0, bytes = 0;
structsend_recv_argarg = {
.fd = lfd,tools/testing/selftests/bpf/network_helpers.c +4
-1@@ -622,8 +626,11 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes) MIN(total_bytes - bytes, sizeof(batch)), 0); if (nr_recv == -1 && errno == EINTR) continue; -if (nr_recv ==-1 ) +if (nr_recv ==-1 ) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK ) +continue ; break; + }bytes +=
nr_recv;
}
Geliang Tang
reviewerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
Quoted 54 lines · Geliang Tang
mptcp-only
Hi Matt & Mat,
Quoted 40 lines · Martin KaFai Lau
Quoted 32 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Some tests, such as the MPTCP bpf tests, require
send_recv_datahelper
to run in nonblock mode.This patch adds nonblock support for
send_recv_data(). Check if it
is
currently in nonblock mode, and if so, ignore EWOULDBLOCK to continue
sending and receiving.Signed-off-by Geliang Tang <[email protected]>---
tools/testing/selftests/bpf/network_helpers.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -555,6 +555,7 @@ struct send_recv_arg { static void *send_recv_server(void *arg) { struct send_recv_arg *a = (struct send_recv_arg *)arg; +int flags =fcntl (a->fd,F_GETFL ); ssize_t nr_sent = 0, bytes = 0; char batch[1500]; int err = 0, fd;tools/testing/selftests/bpf/network_helpers.c static void *send_recv_server(void *arg) · line 583
Quoted 5 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -578,6 +579,8 @@ static void *send_recv_server(void *arg) if (nr_sent == -1 && errno == EINTR) continue; if (nr_sent == -1) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK )I still don't see why it needs to be a non blocking IO. mptcp
Quoted 8 lines
should
work
with blocking IO also, no? Does it really need non blocking IO to make
mptcp test work? I would rather stay with blocking IO in selftest as
much as
possible for simplicity reason.
Quoted 6 lines
I need some help here.
This issue is reported by Matt in "CI: MPTCP BPF tests are now validated", and my fixes ([1] and this patch) aren't accepted by Martin. Is it normal to get EAGAINs in this case? Please give some suggestions.
It fails in mptcp_sendmsg()
1898 wait_for_memory:
1899 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); 1900 __mptcp_push_pending(sk, msg->msg_flags); 1901 ret = sk_stream_wait_memory(sk, &timeo); 1902 if (ret)
1903 goto do_error;
1904 }
sk_stream_wait_memory() fails in the case, andtcp_rtx_and_write_queues_empty(sk) is true.
I added a issue #487 to trace this issue.
Thanks,
-Geliang
Quoted 55 lines
Thanks,
-GeliangQuoted 47 lines
I am afraid the root cause of the EAGAIN thread has not been figured
out yet:
https://lore.kernel.org/all/[email protected]/Lets drop patch 3 until it is understood why mptcp needs EAGAIN or non-blocking IO.
It feels like there is some flakiness and it should be understood and
avoided.Other than the comment in patch 2, the first two patches lgtm. Please
respin with
the first two patches.Quoted 28 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0+continue ; err = -errno; break;}
tools/testing/selftests/bpf/network_helpers.c +0
-0@@ -599,6 +602,7 @@ static void *send_recv_server(void *arg)
intsend_recv_data(int lfd, int fd, uint32_t total_bytes){tools/testing/selftests/bpf/network_helpers.c +1
-0+int flags =fcntl (lfd,F_GETFL );
ssize_tnr_recv= 0, bytes = 0;
structsend_recv_argarg = {
.fd = lfd,tools/testing/selftests/bpf/network_helpers.c +4
-1@@ -622,8 +626,11 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes) MIN(total_bytes - bytes, sizeof(batch)), 0); if (nr_recv == -1 && errno == EINTR) continue; -if (nr_recv ==-1 ) +if (nr_recv ==-1 ) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK ) +continue ; break; + }bytes +=
nr_recv;
}
Matthieu Baerts
maintainerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
Hi Geliang,
Quoted 55 lines · Geliang Tang
Quoted 54 lines · Geliang Tang
mptcp-only
Hi Matt & Mat,
Quoted 48 lines · Martin KaFai Lau
Quoted 32 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Some tests, such as the MPTCP bpf tests, require
send_recv_datahelper
to run in nonblock mode.This patch adds nonblock support for
send_recv_data(). Check if it
is
currently in nonblock mode, and if so, ignore EWOULDBLOCK to continue
sending and receiving.Signed-off-by Geliang Tang <[email protected]>---
tools/testing/selftests/bpf/network_helpers.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -555,6 +555,7 @@ struct send_recv_arg { static void *send_recv_server(void *arg) { struct send_recv_arg *a = (struct send_recv_arg *)arg; +int flags =fcntl (a->fd,F_GETFL ); ssize_t nr_sent = 0, bytes = 0; char batch[1500]; int err = 0, fd;tools/testing/selftests/bpf/network_helpers.c static void *send_recv_server(void *arg) · line 583
Quoted 5 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -578,6 +579,8 @@ static void *send_recv_server(void *arg) if (nr_sent == -1 && errno == EINTR) continue; if (nr_sent == -1) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK )I still don't see why it needs to be a non blocking IO. mptcp should
work
with blocking IO also, no? Does it really need non blocking IO to make
mptcp test work? I would rather stay with blocking IO in selftest as
much as
possible for simplicity reason.
Quoted 6 lines
Quoted 6 lines
I need some help here.
This issue is reported by Matt in "CI: MPTCP BPF tests are now validated", and my fixes ([1] and this patch) aren't accepted by Martin. Is it normal to get EAGAINs in this case? Please give some suggestions.
Thank you for the notification, I missed your previous question.
Regarding Martin's comment about O_NONBLOCK, I understand that with the current BPF selftests -- so excluding the ones linked to the MPTCP schedulers -- it is not needed to support O_NONBLOCK.
It looks like it is too early to do such modifications (patch 3), and probably better to do MPTCP specific modifications only in our tree for the moment. When upstreaming the new MPTCP BPF selftests, it will be clearer for BPF maintainers what are our requirements, and such modifications would make more sense, no?
Quoted 7 lines
It fails in
mptcp_sendmsg()1898
wait_for_memory:1899 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); 1900 __mptcp_push_pending(sk, msg->msg_flags); 1901 ret = sk_stream_wait_memory(sk, &timeo); 1902 if (ret)
Quoted 5 lines
1903 goto
do_error;
1904 }
sk_stream_wait_memory()fails in the case, andtcp_rtx_and_write_queues_empty(sk)is true.
My understanding is that with the current BPF selftests -- so excluding the ones linked to the MPTCP schedulers here as well -- it looks unlikely to have a EAGAIN errno, because only blocking IO is being used, right?
I might be wrong, but with MPTCP schedulers, it is different: with non-blocking IO, EAGAIN can be seen, and this case needs to be handled. Actively waiting by retrying directly in the loop in case of EAGAIN is not recommended, but probably OK for the tests (still, might be good to add a comment to recommend polling instead). So here as well, such modifications can stay in our tree for the moment.
Also, what is not clear to me is where we set the socket as the non-blocking one. Is it only done for MPTCP servers/clients?
Quoted 1 line
I added a issue #487 to trace this issue.
Thanks!
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
Hi Matt,
Quoted 115 lines · Matthieu Baerts
Hi Geliang,
Quoted 60 lines · Geliang Tang
Quoted 59 lines · Geliang Tang
mptcp-only
Hi Matt & Mat,
Quoted 53 lines · Martin KaFai Lau
Quoted 35 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Some tests, such as the MPTCP bpf tests, require
send_recv_data
helper
to run in nonblock mode.This patch adds nonblock support for
send_recv_data(). Check if
it
is
currently in nonblock mode, and if so, ignore EWOULDBLOCK to continue
sending and receiving.Signed-off-by Geliang Tang <[email protected]>---
tools/testing/selftests/bpf/network_helpers.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/network_helpers.c +0
-0@@ -555,6 +555,7 @@ struct send_recv_arg { static void *send_recv_server(void *arg) {struct
send_recv_arg*a = (structsend_recv_arg*)arg;tools/testing/selftests/bpf/network_helpers.c +1
-0+int flags =fcntl (a->fd,F_GETFL );
ssize_tnr_sent= 0, bytes = 0;
char batch[1500];
int err = 0, fd;tools/testing/selftests/bpf/network_helpers.c static void *send_recv_server(void *arg) · line 583
Quoted 5 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -578,6 +579,8 @@ static void *send_recv_server(void *arg) if (nr_sent == -1 && errno == EINTR) continue; if (nr_sent == -1) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK )I still don't see why it needs to be a non blocking IO. mptcp should
work
with blocking IO also, no? Does it really need non blocking IO to
make
mptcp test work? I would rather stay with blocking IO in selftest
as
much as
possible for simplicity reason.Quoted 7 lines
Quoted 7 lines
I need some help here.
This issue is reported by Matt in "CI: MPTCP BPF tests are now validated", and my fixes ([1] and this patch) aren't accepted by Martin. Is it normal to get EAGAINs in this case? Please give some
suggestions.Thank you for the notification, I missed your previous question.
Regarding Martin's comment about
O_NONBLOCK, I understand that with the
current BPF selftests -- so excluding the ones linked to the MPTCP schedulers -- it is not needed to supportO_NONBLOCK.It looks like it is too early to do such modifications (patch 3), and probably better to do MPTCP specific modifications only in our tree for
the moment. When upstreaming the new MPTCP BPF selftests, it will be clearer for BPF maintainers what are our requirements, and such modifications would make more sense, no?Quoted 10 lines
It fails in
mptcp_sendmsg()1898
wait_for_memory:
1899set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); 1900__mptcp_push_pending(sk, msg->msg_flags); 1901 ret =sk_stream_wait_memory(sk, &timeo); 1902 if (ret)
1903 gotodo_error;
1904 }Quoted 2 lines
sk_stream_wait_memory()fails in the case, andtcp_rtx_and_write_queues_empty(sk)is true.My understanding is that with the current BPF selftests -- so excluding
the ones linked to the MPTCP schedulers here as well -- it looks unlikely to have a EAGAIN errno, because only blocking IO is being used,
right?I might be wrong, but with MPTCP schedulers, it is different: with non-blocking IO, EAGAIN can be seen, and this case needs to be handled.
Actively waiting by retrying directly in the loop in case of EAGAIN is
not recommended, but probably OK for the tests (still, might be good to
add a comment to recommend polling instead). So here as well, such modifications can stay in our tree for the moment.
Quoted 2 lines
Also, what is not clear to me is where we set the socket as the non-blocking one. Is it only done for MPTCP servers/clients?
I didn't set the socket as non-block in the end.
EAGAIN will be got no matter non-block flag is set or not.
In old version like "[mptcp-next,v7,0/5] setsockopt per subflow: BPF":
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
"set_nonblock" is added in patch 2, and invoked in run_subflow() in patch 3.
Thanks,
-Geliang
Quoted 7 lines
Quoted 2 lines
I added a issue #487 to trace this issue.
Thanks!
Cheers,
Matt
Matthieu Baerts
maintainerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
On 22/04/2024 12:04, Geliang Tang wrote:> On Mon, 2024-04-22 at 11:45 +0200, Matthieu Baerts wrote:
(...)
Quoted 10 lines
Quoted 10 lines
I might be wrong, but with MPTCP schedulers, it is different: with non-blocking IO, EAGAIN can be seen, and this case needs to be handled.
Actively waiting by retrying directly in the loop in case of EAGAIN is
not recommended, but probably OK for the tests (still, might be good to
add a comment to recommend polling instead). So here as well, such modifications can stay in our tree for the moment.
Quoted 6 lines
Quoted 2 lines
Also, what is not clear to me is where we set the socket as the non-blocking one. Is it only done for MPTCP servers/clients?
I didn't set the socket as non-block in the end.
EAGAIN will be got no matter non-block flag is set or not.
That's strange, no? When the userspace sends data with a blocking IO socket, it should not get EAGAIN, no?
Quoted 6 lines
In old version like "[mptcp-next,v7,0/5] setsockopt per subflow: BPF":
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
"
set_nonblock" is added in patch 2, and invoked inrun_subflow()in patch 3.
I see, but the commit message of patch 2 doesn't explain why set_nonblock() is needed for MPTCP. I see it is used in patch 3, but is it really necessary? Maybe it was added for other reasons, that are no longer valid today?
Quoted 1 line
Quoted 1 line
Quoted 1 line
I added a issue #487 to trace this issue.
Please also note that we didn't have this issue for a while. When we had it, it is when KVM was not supported on the CI:
$ /opt/virtme/virtme-run (...) Could not access KVM kernel module: No such file or directory qemu-system-x86_64: failed to initialize kvm: No such file or directory qemu-system-x86_64: falling back to tcg
Maybe we had this issue because the VM was abnormally too slow, and we reached the 3 seconds timeout described by Martin in a previous message? If this is due to the "abnormally slow setup", maybe we don't need to do anything?
In other words, can you (easily) reproduce the issue on your side? With or without KVM support?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
Quoted 65 lines · Matthieu Baerts
On 22/04/2024 12:04, Geliang Tang wrote:> On Mon, 2024-04-22 at 11:45 +0200, Matthieu Baerts wrote:
(...)
Quoted 14 lines
Quoted 14 lines
I might be wrong, but with MPTCP schedulers, it is different:
with
non-blocking IO, EAGAIN can be seen, and this case needs to be handled.
Actively waiting by retrying directly in the loop in case of EAGAIN
is
not recommended, but probably OK for the tests (still, might be good
to
add a comment to recommend polling instead). So here as well, such
modifications can stay in our tree for the moment.Quoted 6 lines
Quoted 2 lines
Also, what is not clear to me is where we set the socket as the non-blocking one. Is it only done for MPTCP servers/clients?
I didn't set the socket as non-block in the end.
EAGAIN will be got no matter non-block flag is set or not.
That's strange, no? When the userspace sends data with a blocking IO socket, it should not get EAGAIN, no?
Quoted 7 lines
In old version like "[mptcp-next,v7,0/5] setsockopt per subflow:
BPF":https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
"
set_nonblock" is added in patch 2, and invoked inrun_subflow()in patch 3.I see, but the commit message of patch 2 doesn't explain why
set_nonblock()is needed for MPTCP. I see it is used in patch 3, but is
it really necessary? Maybe it was added for other reasons, that are no
longer valid today?Quoted 1 line
Quoted 1 line
Quoted 1 line
I added a issue #487 to trace this issue.
Please also note that we didn't have this issue for a while. When we had
it, it is when KVM was not supported on the CI:$ /opt/virtme/virtme-run (...) Could not access KVM kernel module: No such file or directory qemu-system-x86_64: failed to initialize kvm: No such file or directory qemu-system-x86_64: falling back to tcgMaybe we had this issue because the VM was abnormally too slow, and we
reached the 3 seconds timeout described by Martin in a previous message?
If this is due to the "abnormally slow setup", maybe we don't need to do
anything?
Quoted 3 lines
In other words, can you (easily) reproduce the issue on your side? With
or without KVM support?
It's easy to reproduce by increasing total_bytes:
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -46,7 +46,7 @@
#endif
#define MPTCP_SCHED_NAME_MAX 16
-static const unsigned int total_bytes = 10 * 1024 * 1024; +static const unsigned int total_bytes = 200 * 1024 * 1024;
Geliang
Quoted 3 lines
Cheers,
Matt
Matthieu Baerts
maintainerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
Quoted 66 lines · Geliang Tang
Quoted 65 lines · Matthieu Baerts
On 22/04/2024 12:04, Geliang Tang wrote:> On Mon, 2024-04-22 at 11:45 +0200, Matthieu Baerts wrote:
(...)
Quoted 14 lines
Quoted 14 lines
I might be wrong, but with MPTCP schedulers, it is different:
with
non-blocking IO, EAGAIN can be seen, and this case needs to be handled.
Actively waiting by retrying directly in the loop in case of EAGAIN
is
not recommended, but probably OK for the tests (still, might be good
to
add a comment to recommend polling instead). So here as well, such
modifications can stay in our tree for the moment.Quoted 6 lines
Quoted 2 lines
Also, what is not clear to me is where we set the socket as the non-blocking one. Is it only done for MPTCP servers/clients?
I didn't set the socket as non-block in the end.
EAGAIN will be got no matter non-block flag is set or not.
That's strange, no? When the userspace sends data with a blocking IO socket, it should not get EAGAIN, no?
Quoted 7 lines
In old version like "[mptcp-next,v7,0/5] setsockopt per subflow:
BPF":https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
"
set_nonblock" is added in patch 2, and invoked inrun_subflow()in patch 3.I see, but the commit message of patch 2 doesn't explain why
set_nonblock()is needed for MPTCP. I see it is used in patch 3, but is
it really necessary? Maybe it was added for other reasons, that are no
longer valid today?Quoted 1 line
Quoted 1 line
Quoted 1 line
I added a issue #487 to trace this issue.
Please also note that we didn't have this issue for a while. When we had
it, it is when KVM was not supported on the CI:$ /opt/virtme/virtme-run (...) Could not access KVM kernel module: No such file or directory qemu-system-x86_64: failed to initialize kvm: No such file or directory qemu-system-x86_64: falling back to tcgMaybe we had this issue because the VM was abnormally too slow, and we
reached the 3 seconds timeout described by Martin in a previous message?
If this is due to the "abnormally slow setup", maybe we don't need to do
anything?
Quoted 5 lines
Quoted 3 lines
In other words, can you (easily) reproduce the issue on your side? With
or without KVM support?It's easy to reproduce by increasing
total_bytes:
Even without "set_nonblock()"? With what is in our tree, we don't do that.
As I mentioned above, if 'send()' stops before the end with -1 and errno set to EAGAIN while the socket is supposed to wait for the transfer to be over (blocking IO), I guess there is a bug somewhere, but not in the tests, no?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
Quoted 79 lines · Matthieu Baerts
Quoted 78 lines · Geliang Tang
Quoted 77 lines · Matthieu Baerts
On 22/04/2024 12:04, Geliang Tang wrote:> On Mon, 2024-04-22 at 11:45
+0200, Matthieu Baerts wrote:(...)
Quoted 16 lines
Quoted 16 lines
I might be wrong, but with MPTCP schedulers, it is different:
with
non-blocking IO, EAGAIN can be seen, and this case needs to be
handled.
Actively waiting by retrying directly in the loop in case of EAGAIN
is
not recommended, but probably OK for the tests (still, might be
good
to
add a comment to recommend polling instead). So here as well, such
modifications can stay in our tree for the moment.Quoted 7 lines
Quoted 3 lines
Also, what is not clear to me is where we set the socket as the
non-blocking one. Is it only done for MPTCP servers/clients?I didn't set the socket as non-block in the end.
EAGAIN will be got no matter non-block flag is set or not.
That's strange, no? When the userspace sends data with a blocking IO
socket, it should not get EAGAIN, no?Quoted 9 lines
In old version like "[mptcp-next,v7,0/5] setsockopt per subflow:
BPF":https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
"
set_nonblock" is added in patch 2, and invoked inrun_subflow()in
patch 3.I see, but the commit message of patch 2 doesn't explain why
set_nonblock()is needed for MPTCP. I see it is used in patch 3, but
is
it really necessary? Maybe it was added for other reasons, that are
no
longer valid today?Quoted 1 line
Quoted 1 line
Quoted 1 line
I added a issue #487 to trace this issue.
Please also note that we didn't have this issue for a while. When we
had
it, it is when KVM was not supported on the CI:$ /opt/virtme/virtme-run (...) Could not access KVM kernel module: No such file or directory qemu-system-x86_64: failed to initialize kvm: No such file or directory qemu-system-x86_64: falling back to tcgMaybe we had this issue because the VM was abnormally too slow, and
we
reached the 3 seconds timeout described by Martin in a previous message?
If this is due to the "abnormally slow setup", maybe we don't need to
do
anything?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
In other words, can you (easily) reproduce the issue on your side?
With
or without KVM support?It's easy to reproduce by increasing
total_bytes:Even without "
set_nonblock()"? With what is in our tree, we don't do that.
Yes, without "set_nonblock". Without making any modifications, it can be reproduced in our tree. Increasing totol_bytes can make reproduction easier.
Quoted 8 lines
As I mentioned above, if '
send()' stops before the end with -1 and errno
set to EAGAIN while the socket is supposed to wait for the transfer to
be over (blocking IO), I guess there is a bug somewhere, but not in the
tests, no?
Yes, I think it's a bug in kernel space in wait_for_memory in mptcp_sendmsg().
Thanks,
-Geliang
Quoted 3 lines
Cheers,
Matt
Geliang Tang
reviewerRe: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data
In reply to Martin KaFai LauQuoted 46 lines · Martin KaFai Lau
Quoted 31 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Some tests, such as the MPTCP bpf tests, require
send_recv_datahelper
to run in nonblock mode.This patch adds nonblock support for
send_recv_data(). Check if it is
currently in nonblock mode, and if so, ignore EWOULDBLOCK to continue
sending and receiving.Signed-off-by Geliang Tang <[email protected]>---
tools/testing/selftests/bpf/network_helpers.c| 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -555,6 +555,7 @@ struct send_recv_arg { static void *send_recv_server(void *arg) { struct send_recv_arg *a = (struct send_recv_arg *)arg; +int flags =fcntl (a->fd,F_GETFL ); ssize_t nr_sent = 0, bytes = 0; char batch[1500]; int err = 0, fd;tools/testing/selftests/bpf/network_helpers.c static void *send_recv_server(void *arg) · line 583
Quoted 5 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0@@ -578,6 +579,8 @@ static void *send_recv_server(void *arg) if (nr_sent == -1 && errno == EINTR) continue; if (nr_sent == -1) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK )I still don't see why it needs to be a non blocking IO. mptcp should work
with blocking IO also, no? Does it really need non blocking IO to make
mptcp test work? I would rather stay with blocking IO in selftest as much as
possible for simplicity reason.
Quoted 8 lines
I am afraid the root cause of the EAGAIN thread has not been figured out yet:
https://lore.kernel.org/all/[email protected]/Lets drop patch 3 until it is understood why mptcp needs EAGAIN or non-blocking IO.
It feels like there is some flakiness and it should be understood and avoided.
Hi Martin,
I finally found the root cause of this issue. It is indeed an MPTCP bug. It took me a long time to debug, and the fix is here:
Thank you for insisting on not accepting these work around patches from me in the user space, almost hiding a kernel bug.
-Geliang
Quoted 35 lines
Other than the comment in patch 2, the first two patches lgtm. Please respin with
the first two patches.Quoted 28 lines
tools/testing/selftests/bpf/network_helpers.c +1
-0+continue ; err = -errno; break;}
tools/testing/selftests/bpf/network_helpers.c +0
-0@@ -599,6 +602,7 @@ static void *send_recv_server(void *arg)
intsend_recv_data(int lfd, int fd, uint32_t total_bytes){tools/testing/selftests/bpf/network_helpers.c +1
-0+int flags =fcntl (lfd,F_GETFL );
ssize_tnr_recv= 0, bytes = 0;
structsend_recv_argarg = {
.fd = lfd,tools/testing/selftests/bpf/network_helpers.c +4
-1@@ -622,8 +626,11 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes) MIN(total_bytes - bytes, sizeof(batch)), 0); if (nr_recv == -1 && errno == EINTR) continue; -if (nr_recv ==-1 ) +if (nr_recv ==-1 ) { +if (flags &O_NONBLOCK && errno ==EWOULDBLOCK ) +continue ; break; + }bytes +=
nr_recv;
}
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: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8635152681
Initiator: Matthieu Baerts (NGI0)
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/544eee7fd63f
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=843088
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-normalFor 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)