mptcp: wmem accounting and nonblocking io support
Subsystems (3)
Florian Westphal
PATCH v2 1/1 mptcp: wmem accounting and nonblocking io support
This is the second iteration of the mptcp poll rework.
Most patches have no changes, the ones with changes have these highlighted in the changelog (6/9/10).
This addresses comments from Paolo. I've also axed the 'empty send' part as per comments from Paolo and Mat.
There were doubts as to the repeated invocations of mptcp_send_frag() (RFC patch 13/14, "sendmsg: don't restart mptcp_sendmsg_frag"), I have dropped it from this iteration -- mptcp_sendmsg_frag needs rework which isn't related to this patch series.
Old covert letter:
The first patch extends the test suite with a mmap-based mode to check large, blocking writes. This uncovered a minor problem with the earlier v2 wmem accounting patch series -- we would happily take a lot more data than sndbuf allowed, as we only limited based on what the subflow could accept. So with a 4k sndbuf we could easily accept 256kb or even more.
This patch doesn't change anything in the test suite behaviour however, you need to use "-b 4096" and/or "-m mmap" to enable this mode.
Second patch changes test suite to move to nonblocking io, this breaks mptcp because mptcp_poll can signal EPOLLIN when it shouldn't, so userspace gets -EAGAIN even though poll told it otherwise.
Patches 3/4/5/6 are an update vs. last wmem accounting series. Remaining patches fix the nonblocking io behaviour.
mptcp_poll is made to be stand-alone, i.e. it no longer calls __tcp_poll on the subflow sockets and only considers mptcp_sk state.
After this series the selftest works again and mptcp sk rtx queue is limited by msk wmem.
The patches can't easily be rebased/merged so I propose that I would squash this myself and send a pull request when done.
The following changes since commit c925affd3fa9dd18e6c326cff510bd30087f0ac8:
subflow: wake parent mptcp socket on subflow state change (2019-11-18 02:44:11 +0000)
are available in the Git repository at:
git://git.breakpoint.cc/fw/mptcp-next.git tcp_poll_removal_08
for you to fetch changes up to 2bbcfcd464c6ff1626800cc2e7c02085e02f35e8:
sendmsg: truncate source buffer if mptcp sndbuf size was set from userspace (2019-11-18 17:45:44 +0100)
----------------------------------------------------------------
Florian Westphal (13):
selftest: add mmap-write support
selftests: make sockets non-blocking for default poll mode
mptcp: add wmem_queued accounting
mptcp: allow partial cleaning of rtx head dfrag
mptcp: add and use mptcp RTX flag
sendmsg: block until mptcp sk is writeable
subflow: sk_data_ready: make wakeup on tcp sock conditional
mptcp: add and use mptcp_subflow_get_retrans
mptcp: sendmsg: transmit on backup if other subflows have been closed
recv: make DATA_READY reflect ssk in-sequence state
sendmsg: clear SEND_SPACE if write caused wmem to grow too large
mptcp_poll: don't consider subflow socket state anymore
sendmsg: truncate source buffer if mptcp sndbuf size was set from userspace
net/mptcp/options.c | 2 +- net/mptcp/protocol.c | 249 ++++++++++++++++--- net/mptcp/protocol.h | 4 +- net/mptcp/subflow.c | 12 +- tools/testing/selftests/net/mptcp/mptcp_connect.c | 268 ++++++++++++++++++++- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 36 ++- 6 files changed, 518 insertions(+), 53 deletions(-)
Florian Westphal
PATCH v2 1/13 selftest: add mmap-write support
No changes on default options. New option -b allows to set a lower send buffer size.
New option "-m mmap" allows to use a mode where the sender transmits the entire file in very large chunks (using mmap + write) instead of the default poll+read/write.
This is mainly useful to make sure we cope with large writes. I also added sendfile() support (as its easy), but it won't work yet for mptcp sockets.
should be squashed into mptcp: add basic kselftest for mptcp
--- .../selftests/net/mptcp/mptcp_connect.c | 257 +++++++++++++++++- .../selftests/net/mptcp/mptcp_connect.sh | 36 ++- 2 files changed, 284 insertions(+), 9 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +251 -6
@@ -3,6 +3,7 @@#define _GNU_SOURCE#include <errno.h> +#include <limits.h> #include <fcntl.h> #include <string.h> #include <stdbool.h>
@@ -13,8 +14,11 @@#include <unistd.h> #include <sys/poll.h> +#include <sys/sendfile.h> +#include <sys/stat.h> #include <sys/socket.h> #include <sys/types.h> +#include <sys/mman.h> #include <netdb.h> #include <netinet/in.h>
@@ -33,15 +37,23 @@ extern int optind;static bool listen_mode;static int poll_timeout; +enum cfg_mode { +CFG_MODE_POLL , +CFG_MODE_MMAP , +CFG_MODE_SENDFILE , +}; + +static enum cfg_mode cfg_mode =CFG_MODE_POLL ;static const char *cfg_host;static const char *cfg_port ="12000" ;static int cfg_sock_proto =IPPROTO_MPTCP ;static bool tcpulp_audit;static int pf =AF_INET ; +static int cfg_sndbuf;static void die_usage (void ) { -fprintf (stderr,"Usage: mptcp_connect [-6] [-u] [-s MPTCP|TCP] [-p port] " +fprintf (stderr,"Usage: mptcp_connect [-6] [-u] [-s MPTCP|TCP] [-p port] -m mode]" "[ -l ] [ -t timeout ] connect_address\n" );exit (1 ); }
@@ -84,6 +96,17 @@ static void xgetaddrinfo(const char *node, const char *service, } } +static void set_sndbuf (int fd,unsigned int size) +{ +int err; + + err =setsockopt (fd,SOL_SOCKET ,SO_SNDBUF , &size,sizeof (size)); +if (err) { +perror ("set SO_SNDBUF" ); +exit (1 ); + } +} +static int sock_listen_mptcp (const char *const listenaddr,const char *const port) {
@@ -256,7 +279,7 @@ static ssize_t do_rnd_read(const int fd, char *buf, const size_t len)return read (fd, buf, cap); } -static int copyfd_io (int infd,int peerfd,int outfd) +static int copyfd_io_poll (int infd,int peerfd,int outfd) {struct pollfd fds = { .fd = peerfd,
@@ -352,6 +375,168 @@ static int copyfd_io(int infd, int peerfd, int outfd)return 0 ; } +static int do_recvfile (int infd,int outfd) +{ +ssize_t r; + +do { +char buf[16536 ]; + + r =do_rnd_read (infd, buf,sizeof (buf)); +if (r >0 ) { +if (write (outfd, buf, r) != r) +break ; + }else if (r <0 ) { +perror ("read" ); + } + }while (r >0 ); + +return (int )r; +} + +static int do_mmap (int infd,int outfd,unsigned int size) +{ +char *inbuf =mmap (NULL , size,PROT_READ ,MAP_SHARED , infd,0 ); +ssize_t ret =0 , off =0 ; +size_t rem; + +if (inbuf ==MAP_FAILED ) { +perror ("mmap" ); +return 1 ; + } + + rem = size; + +while (rem >0 ) { + ret =write (outfd, inbuf + off, rem); + +if (ret <0 ) { +perror ("write" ); +break ; + } + + off += ret; + rem -= ret; + } + +munmap (inbuf, size); +return rem; +} + +static int get_infd_size (int fd) +{ +struct stat sb; +ssize_t count; +int err; + + err =fstat (fd, &sb); +if (err <0 ) { +perror ("fstat" ); +return -1 ; + } + +if ((sb.st_mode &S_IFMT ) !=S_IFREG ) { +fprintf (stderr,"%s: stdin is not a regular file\n" , __func__); +return -2 ; + } + + count = sb.st_size; +if (count >INT_MAX ) { +fprintf (stderr,"File too large: %zu\n" , count); +return -3 ; + } + +return (int )count; +} + +static int do_sendfile (int infd,int outfd,unsigned int count) +{ +while (count >0 ) { +ssize_t r; + + r =sendfile (outfd, infd,NULL , count); +if (r <0 ) { +perror ("sendfile" ); +return 3 ; + } + + count -= r; + } + +return 0 ; +} + +static int copyfd_io_mmap (int infd,int peerfd,int outfd, +unsigned int size) +{ +int err; + +if (listen_mode) { + err =do_recvfile (peerfd, outfd); +if (err) +return err; + + err =do_mmap (infd, peerfd, size); + }else { + err =do_mmap (infd, peerfd, size); +if (err) +return err; + +shutdown (peerfd,SHUT_WR ); + + err =do_recvfile (peerfd, outfd); + } + +return err; +} + + +static int copyfd_io_sendfile (int infd,int peerfd,int outfd, +unsigned int size) +{ +int err; + +if (listen_mode) { + err =do_recvfile (peerfd, outfd); +if (err) +return err; + + err =do_sendfile (infd, peerfd, size); + }else { + err =do_sendfile (infd, peerfd, size); +if (err) +return err; + err =do_recvfile (peerfd, outfd); + } + +return err; +} + +static int copyfd_io (int infd,int peerfd,int outfd) +{ +int file_size; + +switch (cfg_mode) { +case CFG_MODE_POLL : +return copyfd_io_poll (infd, peerfd, outfd); +case CFG_MODE_MMAP : + file_size =get_infd_size (infd); +if (file_size <0 ) +return file_size; +return copyfd_io_mmap (infd, peerfd, outfd, file_size); +case CFG_MODE_SENDFILE : + file_size =get_infd_size (infd); +if (file_size <0 ) +return file_size; +return copyfd_io_sendfile (infd, peerfd, outfd, file_size); + } + +fprintf (stderr,"Invalid mode %d\n" , cfg_mode); + +die_usage (); +return 1 ; +} +static void check_sockaddr (int pf,struct sockaddr_storage *ss,socklen_t salen) {
@@ -464,8 +649,7 @@ int main_loop_s(int listensock)check_sockaddr (pf, &ss, salen);check_getpeername (remotesock, &ss, salen); -copyfd_io (0 , remotesock,1 ); -return 0 ; +return copyfd_io (0 , remotesock,1 ); }perror ("accept" );
@@ -499,6 +683,10 @@ int main_loop(void)return 2 ;check_getpeername_connect (fd); + +if (cfg_sndbuf) +set_sndbuf (fd, cfg_sndbuf); +return copyfd_io (0 , fd,1 ); }
@@ -509,18 +697,66 @@ int parse_proto(const char *proto)if (!strcasecmp (proto,"TCP" ))return IPPROTO_TCP ; -fprintf (stderr,"Unknown protocol: %s." , proto); +fprintf (stderr,"Unknown protocol: %s\n." , proto);die_usage ();/* silence compiler warning */ return 0 ; } +int parse_mode (const char *mode) +{ +if (!strcasecmp (mode,"poll" )) +return CFG_MODE_POLL ; +if (!strcasecmp (mode,"mmap" )) +return CFG_MODE_MMAP ; +if (!strcasecmp (mode,"sendfile" )) +return CFG_MODE_SENDFILE ; + +fprintf (stderr,"Unknown test mode: %s\n" , mode); +fprintf (stderr,"Supported modes are:\n" ); +fprintf (stderr,"\t\t\"poll\" - interleaved read/write using poll()\n" ); +fprintf (stderr,"\t\t\"mmap\" - send entire input file (mmap+write), then read response (-l will read input first)\n" ); +fprintf (stderr,"\t\t\"sendfile\" - send entire input file (sendfile), then read response (-l will read input first)\n" ); + +die_usage (); + +/* silence compiler warning */ +return 0 ; +} + +int parse_sndbuf (const char *size) +{ +unsigned long s; + + errno =0 ; + + s =strtoul (size,NULL ,0 ); + +if (errno) { +fprintf (stderr,"Invalid sndbuf size %s (%s)\n" , + size, +strerror (errno)); +die_usage (); + } + +if (s >INT_MAX ) { +fprintf (stderr,"Invalid sndbuf size %s (%s)\n" , + size, +strerror (ERANGE )); +die_usage (); + } + + cfg_sndbuf = s; + +return 0 ; +} +static void parse_opts (int argc,char **argv) {int c; -while ((c =getopt (argc, argv,"6lp:s:hut:" )) !=-1 ) { +while ((c =getopt (argc, argv,"6lp:s:hut:m:b:" )) !=-1 ) {switch (c) {case 'l' : listen_mode = true;
@@ -545,6 +781,12 @@ static void parse_opts(int argc, char **argv)if (poll_timeout <=0 ) poll_timeout =-1 ;break ; +case 'm' : + cfg_mode =parse_mode (optarg); +break ; +case 'b' : + cfg_sndbuf =parse_sndbuf (optarg); +break ; } }
@@ -571,6 +813,9 @@ int main(int argc, char *argv[])if (fd <0 )return 1 ; +if (cfg_sndbuf) +set_sndbuf (fd, cfg_sndbuf); +return main_loop_s (fd); }
tools/testing/selftests/net/mptcp/mptcp_connect.sh +33 -3
@@ -3,7 +3,7 @@ time_start=$(date +%s) -optstring="d:e:l:r:h6c" +optstring="b:d:e:l:r:h6c:m:" ret=0 sin="" sout=""
@@ -17,6 +17,9 @@ ethtool_random_on=true tc_delay="$((RANDOM%400))" tc_loss=$((RANDOM%101)) tc_reorder="" +testmode="" +sndbuf=0 +options_log=true if [ $tc_loss -eq 100 ];then tc_loss=1%
@@ -36,6 +39,8 @@ usage() { echo -e "\t-e: ethtool features to disable, e.g.: \"-e tso -e gso\" (default: randomly disable any of tso/gso/gro)" echo -e "\t-6: enable IPv6 tests (default: only test IPv4)" echo -e "\t-c: capture packets for each test using tcpdump (default: no capture)" + echo -e "\t-b: set sndbuf value (default: use kernel default)" + echo -e "\t-m: test mode (poll, sendfile; default: poll)" } while getopts "$optstring" option;do
@@ -68,6 +73,17 @@ while getopts "$optstring" option;do "c") capture=true ;; + "b") + if [ $OPTARG -ge 0 ];then + sndbuf="$OPTARG" + else + echo "-s requires numeric argument, got \"$OPTARG\"" 1>&2 + exit 1 + fi + ;; + "m") + testmode="$OPTARG" + ;; "?") usage $0 exit 1
@@ -294,10 +310,24 @@ do_transfer() srv_proto="$4" connect_addr="$5" local_addr="$6" + local extra_args="" port=$((10000+$TEST_COUNT)) TEST_COUNT=$((TEST_COUNT+1)) + if [ "$sndbuf" -gt 0 ]; then + extra_args="$extra_args -b $sndbuf" + fi + + if [ -n "$testmode" ]; then + extra_args="$extra_args -m $testmode" + fi + + if [ -n "$extra_args" ] && $options_log; then + options_log=false + echo "INFO: extra options: $extra_args" + fi + :> "$cout" :> "$sout" :> "$capout"
@@ -319,13 +349,13 @@ do_transfer() sleep 1 fi - ip netns exec ${listener_ns} ./mptcp_connect -t $timeout -l -p $port -s ${srv_proto} $local_addr < "$sin" > "$sout" & + ip netns exec ${listener_ns} ./mptcp_connect -t $timeout -l -p $port -s ${srv_proto} $extra_args $local_addr < "$sin" > "$sout" & spid=$! sleep 1 start=$(date +%s%3N) - ip netns exec ${connector_ns} ./mptcp_connect -t $timeout -p $port -s ${cl_proto} $connect_addr < "$cin" > "$cout" & + ip netns exec ${connector_ns} ./mptcp_connect -t $timeout -p $port -s ${cl_proto} $extra_args $connect_addr < "$cin" > "$cout" & cpid=$! wait $cpid
Signature · 1 line
2.23.0
Mat Martineau
[MPTCP] Re: [PATCH v2 01/13] selftest: add mmap-write support
Quoted 23 lines · Florian Westphal
No changes on default options. New option -b allows to set a lower send buffer size.
New option "-m mmap" allows to use a mode where the sender transmits the entire file in very large chunks (using mmap + write) instead of the default poll+read/write.
This is mainly useful to make sure we cope with large writes. I also added
sendfile()support (as its easy), but it won't work yet for mptcp sockets.should be squashed into mptcp: add basic kselftest for mptcp
Signed-off-by Florian Westphal <fw(a)strlen.de>---
.../selftests/net/mptcp/mptcp_connect.c| 257 +++++++++++++++++-.../selftests/net/mptcp/mptcp_connect.sh| 36 ++-2 files changed, 284 insertions(+), 9 deletions(-)tools/testing/selftests/net/mptcp/mptcp_connect.c +0
-0
...
tools/testing/selftests/net/mptcp/mptcp_connect.c static int copyfd_io(int infd, int peerfd, int outfd) · line 383
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +6
-0@@ -352,6 +375,168 @@ static int copyfd_io(int infd, int peerfd, int outfd)return 0 ; } +static int do_recvfile (int infd,int outfd) +{ +ssize_t r; + + do { + char buf[16536];
The array size makes me think you intended 2^14 (16384) but changed only the first two digits of 2^16 (65536). It doesn't make a real difference to the test, though.
Mat
tools/testing/selftests/net/mptcp/mptcp_connect.c static int copyfd_io(int infd, int peerfd, int outfd) · line 395
Quoted 12 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +12
-0+ + r =do_rnd_read (infd, buf,sizeof (buf)); +if (r >0 ) { +if (write (outfd, buf, r) != r) +break ; + }else if (r <0 ) { +perror ("read" ); + } + }while (r >0 ); + +return (int )r; +}
--
Mat Martineau
Intel
Matthieu Baerts
[MPTCP] Re: [PATCH v2 01/13] selftest: add mmap-write support
In reply to Florian WestphalHi Florian,
Quoted 10 lines · Florian Westphal
No changes on default options. New option -b allows to set a lower send buffer size.
New option "-m mmap" allows to use a mode where the sender transmits the entire file in very large chunks (using mmap + write) instead of the default poll+read/write.
This is mainly useful to make sure we cope with large writes. I also added
sendfile()support (as its easy), but it won't work yet for mptcp sockets.
Thank you for the patch!
[...]
tools/testing/selftests/net/mptcp/mptcp_connect.sh line 6
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1
-1@@ -3,7 +3,7 @@ time_start=$(date +%s) -optstring="d:e:l:r:h6c" +optstring="b:d:e:l:r:h6c:m:"
Just a small detail but the capture (-c) option doesn't any argument. I guess we should also apply this:
====
(quoted diff) +0 -0
b/tools/testing/selftests/net/mptcp/mptcp_connect.sh index 1f840c87be5d..61b9e2a9c891 100755
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1 -1
@@ -3,7 +3,7 @@ time_start=$(date +%s) -optstring="b:d:e:l:r:h4c:m:" +optstring="b:d:e:l:r:h4cm:" ret=0 sin="" sout=""
====
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
[MPTCP] Re: [PATCH v2 01/13] selftest: add mmap-write support
Quoted 12 lines · Matthieu Baerts
tools/testing/selftests/net/mptcp/mptcp_connect.sh line 4
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1
-1@@ -3,7 +3,7 @@ time_start=$(date +%s) -optstring="d:e:l:r:h6c" +optstring="b:d:e:l:r:h6c:m:"Just a small detail but the capture (-c) option doesn't any argument. I guess we should also apply this:
Review
Quoted 5 lines
(quoted diff) +1
-1-optstring="b:d:e:l:r:h4c:m:" +optstring="b:d:e:l:r:h4cm:" ret=0 sin="" sout=""
Oh, absolutely.
Can you also apply this fixlet that Mat pointed out?
tools/testing/selftests/net/mptcp/mptcp_connect.c +1 -1
@@ -391,7 +391,7 @@ static int do_recvfile(int infd, int outfd)ssize_t r; do { - char buf[16536]; + char buf[16384];
Thanks!
Matthieu Baerts
[MPTCP] Re: [PATCH v2 01/13] selftest: add mmap-write support
Hi Florian,
Quoted 13 lines · Florian Westphal
Quoted 11 lines · Matthieu Baerts
tools/testing/selftests/net/mptcp/mptcp_connect.sh line 4
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_connect.sh +1
-1@@ -3,7 +3,7 @@ time_start=$(date +%s) -optstring="d:e:l:r:h6c" +optstring="b:d:e:l:r:h6c:m:"Just a small detail but the capture (-c) option doesn't any argument. I guess we should also apply this:
Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +1
-1-optstring="b:d:e:l:r:h4c:m:" +optstring="b:d:e:l:r:h4cm:" ret=0 sin="" sout=""Oh, absolutely.
Great!
- 8c39e2086d0f: selftests:mptcp: fix typo in opts
tools/testing/selftests/net/mptcp/mptcp_connect.c static int do_recvfile(int infd, int outfd) · line 394
Quoted 11 lines
Can you also apply this fixlet that Mat pointed out?
tools/testing/selftests/net/mptcp/mptcp_connect.c +1
-1@@ -391,7 +391,7 @@ static int do_recvfile(int infd, int outfd)ssize_t r; do { - char buf[16536]; + char buf[16384];
Just did:
- 2acf87c192a7: selftests:mptcp: buf with a power 2 size
- c35e69234be2..39d0ec7ab1eb: result
Tests + export are in progress.
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
PATCH v2 2/13 selftests: make sockets non-blocking for default poll mode
In reply to Florian WestphalThis change makes tests fail because mptcp_poll may signal POLLIN when no data is there and POLLOUT when it should not.
Rest of series addresses this and makes selftest work again.
--- tools/testing/selftests/net/mptcp/mptcp_connect.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_connect.c +11 -0
@@ -279,6 +279,15 @@ static ssize_t do_rnd_read(const int fd, char *buf, const size_t len)return read (fd, buf, cap); } +static void set_nonblock (int fd) +{ +int flags =fcntl (fd,F_GETFL ); +if (flags ==-1 ) +return ; + +fcntl (fd,F_SETFL , flags |O_NONBLOCK ); +} +static int copyfd_io_poll (int infd,int peerfd,int outfd) {struct pollfd fds = {
@@ -288,6 +297,8 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd)unsigned int woff =0 , wlen =0 ;char wbuf[8192 ]; +set_nonblock (peerfd); +for (;;) {char rbuf[8192 ];ssize_t len;
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 3/13 mptcp: add wmem_queued accounting
In reply to Florian WestphalPeer could ack data at TCP level but refrain from sending mptcp-level ACKs. This could result in a growing the mptcp socket backlog indefinitely.
We should thus block mptcp_sendmsg until the peer has acked some of the sent data.
In order to be able to do so, increment the mptcp socket wmem_queued counter on memory allocation and decrement it when releasing the memory on mptcp-level ack reception.
Because TCP performns sndbuf auto-tuning up to tcp_wmem_max[2], make this the mptcp sk_sndbuf limit.
In the future we could add experiment with autotuning as TCP does in tcp_sndbuf_expand().
--- net/mptcp/protocol.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +8 -1
@@ -139,8 +139,11 @@ static inline bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,static void dfrag_clear (struct sock *sk,struct mptcp_data_frag *dfrag) { +int len = dfrag->data_len + dfrag->overhead; +list_del (&dfrag->list); -sk_mem_uncharge (sk, dfrag->data_len + dfrag->overhead); +sk_mem_uncharge (sk, len); +sk_wmem_queued_add (sk, -len);put_page (dfrag->page); }
@@ -304,6 +307,9 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,if (!dfrag_collapsed) {get_page (dfrag->page);list_add_tail (&dfrag->list, &msk->rtx_queue); +sk_wmem_queued_add (sk, frag_truesize); + }else { +sk_wmem_queued_add (sk, ret); }/* charge data on mptcp rtx queue to the master socket
@@ -711,6 +717,7 @@ static int mptcp_init_sock(struct sock *sk)return ret;sk_sockets_allocated_inc (sk); + sk->sk_sndbuf =sock_net (sk)->ipv4.sysctl_tcp_wmem[2 ];return 0 ; }
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 4/13 mptcp: allow partial cleaning of rtx head dfrag
In reply to Florian WestphalAfter adding wmem accouting for the mptcp socket we could get into a situation where the mptcp socket can't transmit more data, and mptcp_clean_una doesn't reduce wmem even if snd_una has advanced because it currently will only remove entire dfrags.
Allow advancing the dfrag head sequence and reduce wmem, even though this isn't correct (as we can't release the page).
Because we will soon block on mptcp sk in case wmem is too large, call sk_stream_write_space() in case we reduced the backlog so userspace task blocked in sendmsg or poll will be woken up.
This isn't an issue if the send buffer is large, but it is when SO_SNDBUF is used to reduce it to a lower value.
Note we can still get a deadlock for low SO_SNDBUF values in case both sides of the connection write to the socket: both could be blocked due to wmem being too small -- and current mptcp stack will only increment mptcp ack_seq on recv.
This doesn't happen with the selftest as it uses poll() and will always call recv if there is data to read.
--- net/mptcp/protocol.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +25 -3
@@ -137,13 +137,18 @@ static inline bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk, df->data_seq + df->data_len == msk->write_seq; } +static void dfrag_uncharge (struct sock *sk,int len) +{ +sk_mem_uncharge (sk, len); +sk_wmem_queued_add (sk, -len); +} +static void dfrag_clear (struct sock *sk,struct mptcp_data_frag *dfrag) {int len = dfrag->data_len + dfrag->overhead;list_del (&dfrag->list); -sk_mem_uncharge (sk, len); -sk_wmem_queued_add (sk, -len); +dfrag_uncharge (sk, len);put_page (dfrag->page); }
@@ -152,14 +157,31 @@ static void mptcp_clean_una(struct sock *sk)struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_data_frag *dtmp, *dfrag;u64 snd_una =atomic64_read (&msk->snd_una); +bool cleaned = false;list_for_each_entry_safe (dfrag, dtmp, &msk->rtx_queue, list) {if (after64 (dfrag->data_seq + dfrag->data_len, snd_una))break ;dfrag_clear (sk, dfrag); + cleaned = true; + } + + dfrag =mptcp_rtx_head (sk); +if (dfrag &&after64 (snd_una, dfrag->data_seq)) { +u64 delta = dfrag->data_seq + dfrag->data_len - snd_una; + + dfrag->data_seq += delta; + dfrag->data_len -= delta; + +dfrag_uncharge (sk, delta); + cleaned = true; + } + +if (cleaned) { +sk_mem_reclaim_partial (sk); +sk_stream_write_space (sk); } -sk_mem_reclaim_partial (sk); }/* ensure we get enough memory for the frag hdr, beyond some minimal amount of
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 5/13 mptcp: add and use mptcp RTX flag
In reply to Florian WestphalThis is needed in the (unlikely) case that userspace is blocked in mptcp_sendmsg because wmem is exhausted.
In that case, only the rtx work queue will clean the rtx backlog, but it could take several milliseconds until it runs next. So, allow it to get scheduled as soon as possible so wmem can be reclaimed if the mptcp socket sndbuf is exhausted.
Because such quick-schedule should not cause retransmits, add a flag that indicates when the work queue has been scheduled on behalf of the retransmit timer.
--- net/mptcp/options.c | 2 +- net/mptcp/protocol.c | 26 ++++++++++++++++++++------ net/mptcp/protocol.h | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-)
net/mptcp/options.c +1 -1
@@ -583,7 +583,7 @@ static void update_una(struct mptcp_sock *msk, old_snd_una =atomic64_cmpxchg (&msk->snd_una, snd_una, new_snd_una);if (old_snd_una == snd_una) { -mptcp_reset_timer ((struct sock *)msk); +mptcp_data_acked ((struct sock *)msk);break ; } }
net/mptcp/protocol.c +20 -6
@@ -40,7 +40,7 @@ static bool mptcp_timer_pending(struct sock *sk)return timer_pending (&inet_csk (sk)->icsk_retransmit_timer); } -void mptcp_reset_timer (struct sock *sk) +static void mptcp_reset_timer (struct sock *sk) {struct inet_connection_sock *icsk =inet_csk (sk);unsigned long tout;
@@ -52,6 +52,15 @@ void mptcp_reset_timer(struct sock *sk)sk_reset_timer (sk, &icsk->icsk_retransmit_timer, jiffies + tout); } +void mptcp_data_acked (struct sock *sk) +{ +mptcp_reset_timer (sk); + +if (!sk_stream_is_writeable (sk) && +schedule_work (&mptcp_sk (sk)->rtx_work)) +sock_hold (sk); +} +static void mptcp_stop_timer (struct sock *sk) {struct inet_connection_sock *icsk =inet_csk (sk);
@@ -623,6 +632,7 @@ static void mptcp_retransmit_handler(struct sock *sk)if (atomic64_read (&msk->snd_una) == msk->write_seq) {mptcp_stop_timer (sk); }else { +set_bit (MPTCP_WORK_RTX , &msk->flags);if (schedule_work (&msk->rtx_work))sock_hold (sk); }
@@ -647,7 +657,7 @@ static void mptcp_retransmit_timer(struct timer_list *t)sock_put (sk); } -static void mptcp_retransmit (struct work_struct *work) +static void mptcp_worker (struct work_struct *work) {int orig_len, orig_offset, ret, mss_now =0 , size_goal =0 ;struct mptcp_data_frag *dfrag;
@@ -663,6 +673,10 @@ static void mptcp_retransmit(struct work_struct *work)lock_sock (sk);mptcp_clean_una (sk); + +if (!test_and_clear_bit (MPTCP_WORK_RTX , &msk->flags)) + goto unlock; + dfrag =mptcp_rtx_head (sk);if (!dfrag) goto unlock;
@@ -715,7 +729,7 @@ static int __mptcp_init_sock(struct sock *sk)INIT_LIST_HEAD (&msk->conn_list);INIT_LIST_HEAD (&msk->rtx_queue); -INIT_WORK (&msk->rtx_work, mptcp_retransmit); +INIT_WORK (&msk->rtx_work, mptcp_worker);/* re-use the csk retrans timer for MPTCP-level retrans */ timer_setup (&msk->sk.icsk_retransmit_timer, mptcp_retransmit_timer,0 );
@@ -755,7 +769,7 @@ static void __mptcp_clear_xmit(struct sock *sk)dfrag_clear (sk, dfrag); } -static void mptcp_cancel_rtx_work (struct sock *sk) +static void mptcp_cancel_work (struct sock *sk) {struct mptcp_sock *msk =mptcp_sk (sk);
@@ -792,7 +806,7 @@ static void mptcp_close(struct sock *sk, long timeout)__mptcp_clear_xmit (sk);release_sock (sk); -mptcp_cancel_rtx_work (sk); +mptcp_cancel_work (sk);sk_common_release (sk); }
@@ -802,7 +816,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)lock_sock (sk);__mptcp_clear_xmit (sk);release_sock (sk); -mptcp_cancel_rtx_work (sk); +mptcp_cancel_work (sk);return tcp_disconnect (sk, flags); }
net/mptcp/protocol.h +2 -1
@@ -76,6 +76,7 @@/* MPTCP socket flags */ #define MPTCP_DATA_READY BIT(0) +#define MPTCP_WORK_RTX BIT(1)static inline __be32 mptcp_option (u8 subopt,u8 len,u8 nib,u8 field) {
@@ -290,7 +291,7 @@ void mptcp_get_options(const struct sk_buff *skb,void mptcp_finish_connect (struct sock *sk,int mp_capable);void mptcp_finish_join (struct sock *sk); -void mptcp_reset_timer (struct sock *sk); +void mptcp_data_acked (struct sock *sk);int mptcp_token_new_request (struct request_sock *req);void mptcp_token_destroy_request (u32 token);
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 6/13 sendmsg: block until mptcp sk is writeable
In reply to Florian WestphalThis disables transmit of new data until the peer has acked enough mptcp data to get below the wspace write threshold (more than half of wspace upperlimit is available again).
Also have poll not report EPOLLOUT in this case, its not relevant if a subflow is writeable.
The latter is a temporary workaround that is needed because mptcp_poll walks the subflows and calls __tcp_poll on each of them.
Because subflow ssk is usually writable, the EPOLLOUT needs to be removed if the mptcp sndbuf is exhausted.
This is only needed until __tcp_poll is removed later in the series.
v2: drop the "empty send" part as per comments from Paolo and Mat.
--- net/mptcp/protocol.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
net/mptcp/protocol.c +16 -8
@@ -406,23 +406,27 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)return ret; } + timeo =sock_sndtimeo (sk, msg->msg_flags &MSG_DONTWAIT ); + +mptcp_clean_una (sk); + +while (!sk_stream_memory_free (sk)) { + ret =sk_stream_wait_memory (sk, &timeo); +if (ret) + goto out; + +mptcp_clean_una (sk); + } + ssk =mptcp_subflow_get (msk);if (!ssk) {release_sock (sk);return -ENOTCONN ; } -if (!msg_data_left (msg)) { -pr_debug ("empty send" ); - ret =sock_sendmsg (ssk->sk_socket, msg); - goto out; - } -pr_debug ("conn_list->subflow=%p" , ssk);lock_sock (ssk); -mptcp_clean_una (sk); - timeo =sock_sndtimeo (sk, msg->msg_flags &MSG_DONTWAIT );while (msg_data_left (msg)) { ret =mptcp_sendmsg_frag (sk, ssk, msg,NULL , &timeo, &mss_now, &size_goal);
@@ -1312,6 +1316,10 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock, tcp_sock =mptcp_subflow_tcp_socket (subflow); ret |=__tcp_poll (tcp_sock->sk); } + +if (!sk_stream_is_writeable (sk)) + ret &= ~(EPOLLOUT |EPOLLWRNORM ); +release_sock (sk);return ret;
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 7/13 subflow: sk_data_ready: make wakeup on tcp sock conditional
In reply to Florian WestphalNo need for this unless we don't have a parent or the socket is not mp capable.
Only the mptcp socket will be waiting for events. In case the mptcp socket connected to a tcp-only peer, we're in fallback mode and need to wakeup the parent too.
--- net/mptcp/subflow.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/mptcp/subflow.c +5 -2
@@ -646,10 +646,13 @@ static void subflow_data_ready(struct sock *sk)struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk);struct sock *parent = subflow->conn; - subflow->tcp_sk_data_ready (sk); +if (!parent || !(subflow->mp_capable || subflow->mp_join)) { + subflow->tcp_sk_data_ready (sk); -if (!parent || !(subflow->mp_capable || subflow->mp_join)) +if (parent) + parent->sk_data_ready (parent);return ; + }/* always propagate the EoF */ if (mptcp_subflow_data_available (sk) || subflow->rx_eof) {
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 8/13 mptcp: add and use mptcp_subflow_get_retrans
In reply to Florian WestphalInstead of having retransmit worker grab first subflow on the list, make it always return NULL, unless either the first non-backup subflow on the list is idle or all normal subflows have already been removed.
In the latter case, the first idle backup subflow is used.
Rationale is that it makes no sense to attempt to retransmit at mptcp level if there is still unsent data in its write queue.
--- net/mptcp/protocol.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +32 -1
@@ -661,6 +661,37 @@ static void mptcp_retransmit_timer(struct timer_list *t)sock_put (sk); } +/* Find an idle subflow. Return NULL if there is unacked data at tcp +* level. +* +* A backup subflow is returned only if thats the only kind available. +*/ +static struct sock *mptcp_subflow_get_retrans (const struct mptcp_sock *msk) +{ +struct mptcp_subflow_context *subflow; +struct sock *backup =NULL ; + +sock_owned_by_me ((const struct sock *)msk); + +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk =mptcp_subflow_tcp_socket (subflow)->sk; + +/* still data outstanding at TCP level? Don't retransmit. */ +if (!tcp_write_queue_empty (ssk)) +return NULL ; + +if (subflow->backup) { +if (!backup) + backup = ssk; +continue ; + } + +return ssk; + } + +return backup; +} +static void mptcp_worker (struct work_struct *work) {int orig_len, orig_offset, ret, mss_now =0 , size_goal =0 ;
@@ -685,7 +716,7 @@ static void mptcp_worker(struct work_struct *work)if (!dfrag) goto unlock; - ssk =mptcp_subflow_get (msk); + ssk =mptcp_subflow_get_retrans (msk);if (!ssk) goto reset_unlock;
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 9/13 mptcp: sendmsg: transmit on backup if other subflows have been closed
In reply to Florian WestphalCurrently we always pick the first ssk on the list and then have mptcp_sendmsg_frag wait until more space becomes available in case that ssk has no write space available.
Instead check the first subflow on the list. If no more write space is available, then we need to either return -EAGAIN to userspace (nonblock case), or we need to wait until a subflow becomes available.
This is done by blocking the current thread via sk_stream_wait_memory() and then make the subflow sk_write_space() unblock the parent mptcp socket.
We can't acquire the mptcp socket lock from the subflow callbacks, but we can use the mptcp_sk->flags -- MPTCP_SEND_SPACE flag is added for this purpose. If it gets set, then at least one subflow has become available for writing.
v1: dumb-down the selection: just pick the first ssk on the list and make mptcp socket block if it has no wspace.
Backup is only used if no non-backup subflow exists.
v2: avoid another while loop and fold !ssk condition with wmem check
on parent mptcp socket (Paolo).
--- net/mptcp/protocol.c | 58 +++++++++++++++++++++++++++++++++++++++----- net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 5 +++- 3 files changed, 57 insertions(+), 7 deletions(-)
net/mptcp/protocol.c +52 -6
@@ -384,6 +384,43 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,return ret; } +static struct sock *mptcp_subflow_get_send (struct mptcp_sock *msk) +{ +struct mptcp_subflow_context *subflow; +struct sock *backup =NULL ; + +sock_owned_by_me ((const struct sock *)msk); + +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk =mptcp_subflow_tcp_socket (subflow)->sk; + +if (!sk_stream_memory_free (ssk)) { +struct socket *sock = ssk->sk_socket; + +if (sock) { +clear_bit (MPTCP_SEND_SPACE , &msk->flags); +smp_mb__after_atomic (); + +/* enables sk->write_space() callbacks */ +set_bit (SOCK_NOSPACE , &sock->flags); + } + +return NULL ; + } + +if (subflow->backup) { +if (!backup) + backup = ssk; + +continue ; + } + +return ssk; + } + +return backup; +} +static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) {int mss_now =0 , size_goal =0 , ret =0 ;
@@ -410,18 +447,19 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)mptcp_clean_una (sk); -while (!sk_stream_memory_free (sk)) { + ssk =mptcp_subflow_get_send (msk); +while (!sk_stream_memory_free (sk) || !ssk) { ret =sk_stream_wait_memory (sk, &timeo);if (ret) goto out;mptcp_clean_una (sk); - } - ssk =mptcp_subflow_get (msk); -if (!ssk) { -release_sock (sk); -return -ENOTCONN ; + ssk =mptcp_subflow_get_send (msk); +if (list_empty (&msk->conn_list)) { + ret = -ENOTCONN ; + goto out; + } }pr_debug ("conn_list->subflow=%p" , ssk);
@@ -1117,6 +1155,13 @@ bool mptcp_sk_is_subflow(const struct sock *sk)return subflow->mp_join ==1 ; } +static bool mptcp_memory_free (const struct sock *sk,int wake) +{ +struct mptcp_sock *msk =mptcp_sk (sk); + +return wake ?test_bit (MPTCP_SEND_SPACE , &msk->flags) : true; +} +static struct proto mptcp_prot = { .name ="MPTCP" , .owner =THIS_MODULE ,
@@ -1137,6 +1182,7 @@ static struct proto mptcp_prot = { .sockets_allocated = &mptcp_sockets_allocated, .memory_allocated = &tcp_memory_allocated, .memory_pressure = &tcp_memory_pressure, + .stream_memory_free = mptcp_memory_free, .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_tcp_wmem), .sysctl_mem = sysctl_tcp_mem, .obj_size = sizeof(struct mptcp_sock),
net/mptcp/protocol.h +1 -0
@@ -77,6 +77,7 @@/* MPTCP socket flags */ #define MPTCP_DATA_READY BIT(0)#define MPTCP_WORK_RTX BIT(1) +#define MPTCP_SEND_SPACE BIT(2)static inline __be32 mptcp_option (u8 subopt,u8 len,u8 nib,u8 field) {
net/mptcp/subflow.c +4 -1
@@ -670,8 +670,11 @@ static void subflow_write_space(struct sock *sk)struct sock *parent = subflow->conn;sk_stream_write_space (sk); -if (parent) +if (parent &&sk_stream_is_writeable (sk)) { +set_bit (MPTCP_SEND_SPACE , &mptcp_sk (parent)->flags); +smp_mb__after_atomic ();sk_stream_write_space (parent); + } } int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local,
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 10/13 recv: make DATA_READY reflect ssk in-sequence state
In reply to Florian WestphalIn order to make mptcp_poll independent of the subflows, we need to keep the mptcp DATA_READY flag in sync, i.e., if it is set, at least one ssk has in-sequence data.
If it is cleared, no further data is available.
Avoid the unconditional clearing on recv entry.
Instead make sure the flag is cleared on exit if there is no more in-sequence data available.
v2:
- add back 'done = true' assigment (Paolo)
- keep 'break' statements instead of 'goto out'. (Paolo)
--- net/mptcp/protocol.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
net/mptcp/protocol.c +26 -9
@@ -541,8 +541,10 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, {struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_subflow_context *subflow; +bool more_data_avail = false;struct mptcp_read_arg arg;read_descriptor_t desc; +bool wait_data = false;struct socket *ssock;struct tcp_sock *tp;bool done = false;
@@ -575,10 +577,6 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,u32 map_remaining;int bytes_read; -smp_mb__before_atomic (); -clear_bit (MPTCP_DATA_READY , &msk->flags); -smp_mb__after_atomic (); - ssk =mptcp_subflow_recv_lookup (msk);pr_debug ("msk=%p ssk=%p" , msk, ssk);if (!ssk)
@@ -588,7 +586,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, tp =tcp_sk (ssk);lock_sock (ssk); -while (mptcp_subflow_data_available (ssk) && !done) { + do { /* try to read as much data as available */ map_remaining = subflow->map_data_len - mptcp_subflow_get_map_offset(subflow);
@@ -600,7 +598,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,if (!copied) copied = bytes_read; done = true; -continue ; + goto next; } pr_debug("msk ack_seq=%llx -> %llx", msk->ack_seq,
@@ -609,18 +607,22 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, copied += bytes_read;if (copied >= len) { done = true; -continue ; + goto next; }if (tp->urg_data && tp->urg_seq == tp->copied_seq) {pr_err ("Urgent data present, cannot proceed" ); done = true; -continue ; + goto next; } - } +next: + more_data_avail =mptcp_subflow_data_available (ssk); + }while (more_data_avail && !done);release_sock (ssk);continue ; wait_for_data: + more_data_avail = false; +/* only the master socket status is relevant here. The exit * conditions mirror closely tcp_recvmsg() */
@@ -660,9 +662,24 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, }pr_debug ("block timeout %ld" , timeo); + wait_data = true;mptcp_wait_data (sk, &timeo); } +if (more_data_avail) { +if (!test_bit (MPTCP_DATA_READY , &msk->flags)) +set_bit (MPTCP_DATA_READY , &msk->flags); + }else if (!wait_data) { +clear_bit (MPTCP_DATA_READY , &msk->flags); + +/* .. race-breaker: ssk might get new data after last +* data_available() returns false. +*/ + ssk =mptcp_subflow_recv_lookup (msk); +if (unlikely (ssk)) +set_bit (MPTCP_DATA_READY , &msk->flags); + } +release_sock (sk);return copied; }
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 11/13 sendmsg: clear SEND_SPACE if write caused wmem to grow too large
In reply to Florian WestphalThis is needed when we get rid of __tcp_poll and let mptcp_poll only rely on msk->flags -- we need to avoid EPOLLOUT if the write filled too much sndbuf space.
--- net/mptcp/protocol.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
net/mptcp/protocol.c +17 -0
@@ -421,6 +421,22 @@ static struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)return backup; } +static void ssk_check_wmem (struct mptcp_sock *msk,struct sock *ssk) +{ +struct socket *sock; + +if (likely (sk_stream_is_writeable (ssk))) +return ; + + sock =READ_ONCE (ssk->sk_socket); + +if (sock) { +clear_bit (MPTCP_SEND_SPACE , &msk->flags); +smp_mb__after_atomic (); +set_bit (SOCK_NOSPACE , &sock->flags); + } +} +static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) {int mss_now =0 , size_goal =0 , ret =0 ;
@@ -485,6 +501,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)mptcp_reset_timer (sk); } +ssk_check_wmem (msk, ssk);release_sock (ssk); out:
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 12/13 mptcp_poll: don't consider subflow socket state anymore
In reply to Florian WestphalAfter previous patch, we do not need to call __tcp_poll anymore, we can use msk->flags instead to see if we have data available on a socket.
SEND_SPACE flag indicates when a subflow has enough space to accept more data, it gets cleared on mptcp_sendmsg() return in case ssk runs below the free watermark.
The commit "net: tcp: add __tcp_poll helper" can now be removed.
--- net/mptcp/protocol.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
net/mptcp/protocol.c +15 -15
@@ -189,7 +189,10 @@ static void mptcp_clean_una(struct sock *sk)if (cleaned) {sk_mem_reclaim_partial (sk); -sk_stream_write_space (sk); + +/* Only wake up writers if a subflow is ready */ +if (test_bit (MPTCP_SEND_SPACE , &msk->flags)) +sk_stream_write_space (sk); } }
@@ -837,6 +840,7 @@ static int __mptcp_init_sock(struct sock *sk)INIT_LIST_HEAD (&msk->rtx_queue);INIT_WORK (&msk->rtx_work, mptcp_worker); +__set_bit (MPTCP_SEND_SPACE , &msk->flags);/* re-use the csk retrans timer for MPTCP-level retrans */ timer_setup (&msk->sk.icsk_retransmit_timer, mptcp_retransmit_timer,0 );
@@ -1401,39 +1405,35 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,static __poll_t mptcp_poll (struct file *file,struct socket *sock,struct poll_table_struct *wait) { -struct mptcp_subflow_context *subflow;const struct mptcp_sock *msk;struct sock *sk = sock->sk;struct socket *ssock; -__poll_t ret =0 ; +__poll_t mask =0 ; msk =mptcp_sk (sk);lock_sock (sk); ssock =__mptcp_fallback_get_ref (msk);if (ssock) {release_sock (sk); - ret = ssock->ops->poll (file, ssock, wait); + mask = ssock->ops->poll (file, ssock, wait);sock_put (ssock->sk); -return ret; +return mask; }release_sock (sk);sock_poll_wait (file, sock, wait);lock_sock (sk); -mptcp_for_each_subflow (msk, subflow) { -struct socket *tcp_sock; - - tcp_sock =mptcp_subflow_tcp_socket (subflow); - ret |=__tcp_poll (tcp_sock->sk); - } - -if (!sk_stream_is_writeable (sk)) - ret &= ~(EPOLLOUT |EPOLLWRNORM ); +if (test_bit (MPTCP_DATA_READY , &msk->flags)) + mask =EPOLLIN |EPOLLRDNORM ; +if (sk_stream_is_writeable (sk) &&test_bit (MPTCP_SEND_SPACE , &msk->flags)) + mask |=EPOLLOUT |EPOLLWRNORM ; +if (sk->sk_shutdown &RCV_SHUTDOWN ) + mask |=EPOLLIN |EPOLLRDNORM |EPOLLRDHUP ;release_sock (sk); -return ret; +return mask; }static int mptcp_shutdown (struct socket *sock,int how)
Signature · 1 line
2.23.0
Florian Westphal
PATCH v2 13/13 sendmsg: truncate source buffer if mptcp sndbuf size was set from userspace
In reply to Florian WestphalIf userspace uses SO_SNDBUF to set a value, then truncate the buffer according to remaining wmem.
Otherwise, running selftest script with "-m mmap -b 4096" shows very large sucessful write() calls, as we're only limited by how much data the underlying tcp flow is willing to accept.
NB: It might make sense to carry SO_SNDBUF down to the subflows, but thats left out for now.
--- net/mptcp/protocol.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/mptcp/protocol.c +9 -0
@@ -483,6 +483,15 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)pr_debug ("conn_list->subflow=%p" , ssk); +if (unlikely (sk->sk_userlocks &SOCK_SNDBUF_LOCK )) { +int limit =sk_stream_wspace (sk); + +if (WARN_ON_ONCE (limit <=0 )) + limit =1 ; + +iov_iter_truncate (&msg->msg_iter, limit); + } +lock_sock (ssk);while (msg_data_left (msg)) { ret = mptcp_sendmsg_frag(sk, ssk, msg, NULL, &timeo, &mss_now,
Signature · 1 line
2.23.0
Paolo Abeni
Quoted 44 lines · Florian Westphal
This is the second iteration of the mptcp poll rework.
Most patches have no changes, the ones with changes have these highlighted in the changelog (6/9/10).
This addresses comments from Paolo. I've also axed the 'empty send' part as per comments from Paolo and Mat.
There were doubts as to the repeated invocations of
mptcp_send_frag()(RFC patch 13/14, "sendmsg: don't restartmptcp_sendmsg_frag"), I have dropped it from this iteration --mptcp_sendmsg_fragneeds rework which isn't related to this patch series.Old covert letter:
The first patch extends the test suite with a mmap-based mode to check large, blocking writes. This uncovered a minor problem with the earlier v2 wmem accounting patch series -- we would happily take a lot more data than sndbuf allowed, as we only limited based on what the subflow could accept. So with a 4k sndbuf we could easily accept 256kb or even more.
This patch doesn't change anything in the test suite behaviour however, you need to use "-b 4096" and/or "-m mmap" to enable this mode.
Second patch changes test suite to move to nonblocking io, this breaks mptcp because
mptcp_pollcan signal EPOLLIN when it shouldn't, so userspace gets-EAGAINeven though poll told it otherwise.Patches 3/4/5/6 are an update vs. last wmem accounting series. Remaining patches fix the nonblocking io behaviour.
mptcp_pollis made to be stand-alone, i.e. it no longer calls__tcp_pollon the subflow sockets and only considersmptcp_skstate.After this series the selftest works again and mptcp sk rtx queue is limited by msk wmem.
The patches can't easily be rebased/merged so I propose that I would squash this myself and send a pull request when done.
The following changes since commit
c925affd3fa9dd18e6c326cff510bd30087f0ac8:subflow: wake parent mptcp socket on subflow state change (2019-11-18 02:44:11 +0000)
Quoted 7 lines
are available in the Git repository at:
git://git.breakpoint.cc/fw/mptcp-next.gittcp_poll_removal_08for you to fetch changes up to
2bbcfcd464c6ff1626800cc2e7c02085e02f35e8:sendmsg: truncate source buffer if mptcp sndbuf size was set from userspace (2019-11-18 17:45:44 +0100)
The series LGTM, thanks Florian!
/P
Mat Martineau
Quoted 5 lines · Florian Westphal
This is the second iteration of the mptcp poll rework.
Most patches have no changes, the ones with changes have these highlighted in the changelog (6/9/10).
Quoted 7 lines
This addresses comments from Paolo. I've also axed the 'empty send' part as per comments from Paolo and Mat.
There were doubts as to the repeated invocations of
mptcp_send_frag()(RFC patch 13/14, "sendmsg: don't restartmptcp_sendmsg_frag"), I have dropped it from this iteration --mptcp_sendmsg_fragneeds rework which isn't related to this patch series.
The series looks good to me, with one minor comment on patch 1.
Mat
Quoted 63 lines
Old covert letter:
The first patch extends the test suite with a mmap-based mode to check large, blocking writes. This uncovered a minor problem with the earlier v2 wmem accounting patch series -- we would happily take a lot more data than sndbuf allowed, as we only limited based on what the subflow could accept. So with a 4k sndbuf we could easily accept 256kb or even more.
This patch doesn't change anything in the test suite behaviour however, you need to use "-b 4096" and/or "-m mmap" to enable this mode.
Second patch changes test suite to move to nonblocking io, this breaks mptcp because
mptcp_pollcan signal EPOLLIN when it shouldn't, so userspace gets-EAGAINeven though poll told it otherwise.Patches 3/4/5/6 are an update vs. last wmem accounting series. Remaining patches fix the nonblocking io behaviour.
mptcp_pollis made to be stand-alone, i.e. it no longer calls__tcp_pollon the subflow sockets and only considersmptcp_skstate.After this series the selftest works again and mptcp sk rtx queue is limited by msk wmem.
The patches can't easily be rebased/merged so I propose that I would squash this myself and send a pull request when done.
The following changes since commit
c925affd3fa9dd18e6c326cff510bd30087f0ac8:subflow: wake parent mptcp socket on subflow state change (2019-11-18 02:44:11 +0000)
are available in the Git repository at:
git://git.breakpoint.cc/fw/mptcp-next.gittcp_poll_removal_08for you to fetch changes up to
2bbcfcd464c6ff1626800cc2e7c02085e02f35e8:sendmsg: truncate source buffer if mptcp sndbuf size was set from userspace (2019-11-18 17:45:44 +0100)
----------------------------------------------------------------
Florian Westphal (13):
selftest: add mmap-write support
selftests: make sockets non-blocking for default poll mode
mptcp: addwmem_queuedaccounting
mptcp: allow partial cleaning of rtx head dfrag
mptcp: add and use mptcp RTX flag
sendmsg: block until mptcp sk is writeable
subflow:sk_data_ready: make wakeup on tcp sock conditional
mptcp: add and usemptcp_subflow_get_retrans
mptcp: sendmsg: transmit on backup if other subflows have been closed
recv: makeDATA_READYreflect ssk in-sequence state
sendmsg: clearSEND_SPACEif write caused wmem to grow too large
mptcp_poll: don't consider subflow socket state anymore
sendmsg: truncate source buffer if mptcp sndbuf size was set from userspacenet/mptcp/options.c | 2 +- net/mptcp/protocol.c | 249 ++++++++++++++++--- net/mptcp/protocol.h | 4 +- net/mptcp/subflow.c | 12 +- tools/testing/selftests/net/mptcp/mptcp_connect.c | 268 ++++++++++++++++++++- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 36 ++- 6 files changed, 518 insertions(+), 53 deletions(-)
Quoted 4 lines
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org
--
Mat Martineau
Intel
Florian Westphal
Quoted 6 lines · Mat Martineau
Quoted 4 lines
There were doubts as to the repeated invocations of
mptcp_send_frag()(RFC patch 13/14, "sendmsg: don't restartmptcp_sendmsg_frag"), I have dropped it from this iteration --mptcp_sendmsg_fragneeds rework which isn't related to this patch series.The series looks good to me, with one minor comment on patch 1.
Thanks, I can fix that up.
How to proceed? There are several patches in-flight. I think it might make sense to apply this series as-is, with no squashing.
We can then do another squash-marathon later on before next upstream submission.
Otherwise, I could start to squash this series here locally and then send a pull request.
What do you think?
Thanks!
Paolo Abeni
Quoted 6 lines · Florian Westphal
Quoted 5 lines · Mat Martineau
Quoted 4 lines
There were doubts as to the repeated invocations of
mptcp_send_frag()(RFC patch 13/14, "sendmsg: don't restartmptcp_sendmsg_frag"), I have dropped it from this iteration --mptcp_sendmsg_fragneeds rework which isn't related to this patch series.
Quoted 6 lines
Quoted 1 line
The series looks good to me, with one minor comment on patch 1.
Thanks, I can fix that up.
How to proceed? There are several patches in-flight. I think it might make sense to apply this series as-is, with no squashing.
I'm personally ok with that.
Can we wait for the series 'Awaiting Upstream' being applied, before going with this one?
Than v1 support can be rebased on top of the resulting tree (still to be applied just before self-tests).
Quoted 2 lines
We can then do another squash-marathon later on before next upstream submission.
Yep, we will likely need some kind of "code-freeze", and squash/bugfix only before the submission.
Cheers,
Paolo
Matthieu Baerts
Hi Florian, Paolo,
Quoted 11 lines · Paolo Abeni
Quoted 10 lines · Florian Westphal
Quoted 6 lines · Mat Martineau
Quoted 4 lines
There were doubts as to the repeated invocations of
mptcp_send_frag()(RFC patch 13/14, "sendmsg: don't restartmptcp_sendmsg_frag"), I have dropped it from this iteration --mptcp_sendmsg_fragneeds rework which isn't related to this patch series.The series looks good to me, with one minor comment on patch 1.
Thanks, I can fix that up.
Quoted 7 lines
Quoted 2 lines
How to proceed? There are several patches in-flight. I think it might make sense to apply this series as-is, with no squashing.
I'm personally ok with that.
Can we wait for the series 'Awaiting Upstream' being applied, before going with this one?
I was replying to Florian to say that I was going to do that :) I would like to apply these two series:
https://patchwork.ozlabs.org/project/mptcp/list/?state=8&delegate=100661
Ideally, I would also like to move commits after kselftests introduction but this can wait if needed.
Quoted 8 lines
Than v1 support can be rebased on top of the resulting tree (still to be applied just before self-tests).
Quoted 2 lines
We can then do another squash-marathon later on before next upstream submission.
Yep, we will likely need some kind of "code-freeze", and squash/bugfix only before the submission.
We just need to be careful that if we add a lot of modifications at the end of the series, it can make other new patches difficult to squash (based on new code, we need to apply on older code, then resolve conflicts, etc.).
But I understand that it takes time to do that and we might want to postpone that. As long as it is not too long, otherwise we might have to queue a few patches for a future squash :)
If we agree to put these 13 patches at the end (+ the two to include MPTCPv1 support?), I can easily do that when I get the go!
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Paolo Abeni
Quoted 22 lines · Matthieu Baerts
Hi Florian, Paolo,
Quoted 11 lines · Paolo Abeni
Quoted 10 lines · Florian Westphal
Quoted 6 lines · Mat Martineau
Quoted 4 lines
There were doubts as to the repeated invocations of
mptcp_send_frag()(RFC patch 13/14, "sendmsg: don't restartmptcp_sendmsg_frag"), I have dropped it from this iteration --mptcp_sendmsg_fragneeds rework which isn't related to this patch series.The series looks good to me, with one minor comment on patch 1.
Thanks, I can fix that up.
Quoted 7 lines
Quoted 2 lines
How to proceed? There are several patches in-flight. I think it might make sense to apply this series as-is, with no squashing.
I'm personally ok with that.
Can we wait for the series 'Awaiting Upstream' being applied, before going with this one?
Quoted 7 lines
I was replying to Florian to say that I was going to do that :) I would like to apply these two series:
https://patchwork.ozlabs.org/project/mptcp/list/?state=8&delegate=100661Ideally, I would also like to move commits after kselftests introduction but this can wait if needed.
If you could do that, I would appreciate the effort a lot: v1 patches rebasing could be started just after that.
Note: will cause some conflict on Makefile, due to pm.c being added after ctrl.c
Cheers,
Paolo
Matthieu Baerts
Hi Paolo,
Quoted 26 lines · Paolo Abeni
Quoted 25 lines · Matthieu Baerts
Hi Florian, Paolo,
Quoted 11 lines · Paolo Abeni
Quoted 10 lines · Florian Westphal
Quoted 6 lines · Mat Martineau
Quoted 4 lines
There were doubts as to the repeated invocations of
mptcp_send_frag()(RFC patch 13/14, "sendmsg: don't restartmptcp_sendmsg_frag"), I have dropped it from this iteration --mptcp_sendmsg_fragneeds rework which isn't related to this patch series.The series looks good to me, with one minor comment on patch 1.
Thanks, I can fix that up.
Quoted 7 lines
Quoted 2 lines
How to proceed? There are several patches in-flight. I think it might make sense to apply this series as-is, with no squashing.
I'm personally ok with that.
Can we wait for the series 'Awaiting Upstream' being applied, before going with this one?
I was replying to Florian to say that I was going to do that :) I would like to apply these two series:
Quoted 7 lines
Quoted 4 lines
https://patchwork.ozlabs.org/project/mptcp/list/?state=8&delegate=100661Ideally, I would also like to move commits after kselftests introduction but this can wait if needed.
If you could do that, I would appreciate the effort a lot: v1 patches rebasing could be started just after that.
Great, I am then going to:
- apply the two series that are waiting to be applied
- then move these 3 commits after "mptcp: add basic kselftest for mptcp":
mptcp: Add handling of incoming MP_JOIN requests
mptcp: Add ADD_ADDR handling
mptcp: Add path manager interface
- then can I add Florian' series at the end?
Quoted 2 lines
Note: will cause some conflict on
Makefile, due topm.cbeing added afterctrl.c
That's nothing :-)
But thank you for the notice!
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
Quoted 10 lines · Matthieu Baerts
Great, I am then going to:
- apply the two series that are waiting to be applied
- then move these 3 commits after "mptcp: add basic kselftest for mptcp":mptcp: Add handling of incoming
MP_JOINrequests
mptcp: AddADD_ADDRhandling
mptcp: Add path manager interface- then can I add Florian' series at the end?
Works for me. If you like you can also ping me once you're done with the pending series and I can send you a pull request with my patches applied on top.
Whatever makes your life easier. Let me know.
Matthieu Baerts
Hi Florian,
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Matthieu Baerts
Great, I am then going to:
- apply the two series that are waiting to be applied
- then move these 3 commits after "mptcp: add basic kselftest for mptcp":mptcp: Add handling of incoming
MP_JOINrequests
mptcp: AddADD_ADDRhandling
mptcp: Add path manager interface
Quoted 7 lines
Quoted 1 line
- then can I add Florian' series at the end?
Works for me. If you like you can also ping me once you're done with the pending series and I can send you a pull request with my patches applied on top.
Whatever makes your life easier. Let me know.
Thank you for the offer!
I only had some conflicts with mptcp_connect.sh due to the modifications I recently did and applied. It was then easy for me to resolve this.
I added all the 13 patches at the end of the series. Please tell me if I can do more (squash some commits in others) and/or stop the CI to sync with the latest net-next.
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium