vsock: SOCK_LINGER rework
Subsystems (6)
v6 cover vsock: SOCK_LINGER rework
Change vsock's lingerning to wait on close() until all data is sent, i.e. until workers picked all the packets for processing.
Changes in v6:
- Make vsock_wait_sent() return bool, parametrize enable_so_linger() with timeout, don't open code DIV_ROUND_UP [Stefano]
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Move unsent_bytes fetching logic to utils.c
- Add a helper for enabling SO_LINGER
- Accommodate for close() taking a long time for reasons unrelated to lingering
- Separate and redo the testcase [Stefano]
- Enrich the comment [Stefano]
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- While in virtio, stick to virtio_transport_unsent_bytes() [Stefano]
- Squash the indentation reduction [Stefano]
- Pull SOCK_LINGER check into vsock_linger() [Stefano]
- Don't explicitly pass sk->sk_lingertime [Stefano]
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Set "vsock/virtio" topic where appropriate
- Do not claim that Hyper-V and VMCI ever lingered [Stefano]
- Move lingering to af_vsock core [Stefano]
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Comment that some transports do not implement unsent_bytes [Stefano]
- Reduce the indentation of virtio_transport_wait_close() [Stefano]
- Do not linger on shutdown(), expand the commit messages [Paolo]
- Link to v1: https://lore.kernel.org/r/[email protected]
Changes in v1:
- Do not assume unsent_bytes() is implemented by all transports [Stefano]
- Link to v0: https://lore.kernel.org/netdev/[email protected]/
---
Michal Luczaj (5):
vsock/virtio: Linger on unsent data
vsock: Move lingering logic to af_vsock core vsock/test: Introduce vsock_wait_sent() helper vsock/test: Introduce enable_so_linger() helper vsock/test: Add test for an unexpectedly lingering close()
include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 33 +++++++++++++ net/vmw_vsock/virtio_transport_common.c | 21 +-------- tools/testing/vsock/util.c | 38 +++++++++++++++ tools/testing/vsock/util.h | 2 + tools/testing/vsock/vsock_test.c | 83 +++++++++++++++++++++++---------- 6 files changed, 134 insertions(+), 44 deletions(-)
---
base-commit: f44092606a3f153bb7e6b277006b1f4a5b914cfc
change-id: 20250304-vsock-linger-9026e5f9986c
Best regards,
Signature · 1 line
Michal Luczaj <[email protected]>
PATCH v6 1/5 vsock/virtio: Linger on unsent data
Currently vsock's lingering effectively boils down to waiting (or timing out) until packets are consumed or dropped by the peer; be it by receiving the data, closing or shutting down the connection.
To align with the semantics described in the SO_LINGER section of man socket(7) and to mimic AF_INET's behaviour more closely, change the logic of a lingering close(): instead of waiting for all data to be handled, block until data is considered sent from the vsock's transport point of view. That is until worker picks the packets for processing and decrements virtio_vsock_sock::bytes_unsent down to 0.
Note that (some interpretation of) lingering was always limited to transports that called virtio_transport_wait_close() on transport release. This does not change, i.e. under Hyper-V and VMCI no lingering would be observed.
The implementation does not adhere strictly to man page's interpretation ofSO_LINGER: shutdown() will not trigger the lingering. This follows AF_INET.
--- net/vmw_vsock/virtio_transport_common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/vmw_vsock/virtio_transport_common.c +3 -1
@@ -1195,12 +1195,14 @@ static void virtio_transport_wait_close(struct sock *sk, long timeout) {if (timeout) {DEFINE_WAIT_FUNC (wait, woken_wake_function); +struct vsock_sock *vsk =vsock_sk (sk);add_wait_queue (sk_sleep (sk), &wait);do {if (sk_wait_event (sk, &timeout, -sock_flag (sk,SOCK_DONE ), &wait)) +virtio_transport_unsent_bytes (vsk) ==0 , + &wait))break ; }while (!signal_pending (current) && timeout);
Signature · 1 line
2.49.0
PATCH v6 2/5 vsock: Move lingering logic to af_vsock core
In reply to Michal LuczajLingering should be transport-independent in the long run. In preparation for supporting other transports, as well as the linger on shutdown(), move code to core.
Generalize by querying vsock_transport::unsent_bytes(), guard against the callback being unimplemented. Do not pass sk_lingertime explicitly. Pull SOCK_LINGER check into vsock_linger().
Flatten the function. Remove the nested block by inverting the condition:
return early on !timeout.
--- include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 33 +++++++++++++++++++++++++++++++++ net/vmw_vsock/virtio_transport_common.c | 23 ++--------------------- 3 files changed, 36 insertions(+), 21 deletions(-)
include/net/af_vsock.h +1 -0
@@ -221,6 +221,7 @@ void vsock_for_each_connected_socket(struct vsock_transport *transport, void (*fn)(struct sock *sk));int vsock_assign_transport (struct vsock_sock *vsk,struct vsock_sock *psk);bool vsock_find_cid (unsigned int cid); +void vsock_linger (struct sock *sk);/**** TAP ****/
net/vmw_vsock/af_vsock.c +33 -0
@@ -1013,6 +1013,39 @@ static int vsock_getname(struct socket *sock,return err; } +void vsock_linger (struct sock *sk) +{ +DEFINE_WAIT_FUNC (wait, woken_wake_function); +ssize_t (*unsent)(struct vsock_sock *vsk); +struct vsock_sock *vsk =vsock_sk (sk); +long timeout; + +if (!sock_flag (sk,SOCK_LINGER )) +return ; + + timeout = sk->sk_lingertime; +if (!timeout) +return ; + +/* Transports must implement `unsent_bytes` if they want to support +* SOCK_LINGER through `vsock_linger()` since we use it to check when +* the socket can be closed. +*/ + unsent = vsk->transport->unsent_bytes; +if (!unsent) +return ; + +add_wait_queue (sk_sleep (sk), &wait); + +do { +if (sk_wait_event (sk, &timeout,unsent (vsk) ==0 , &wait)) +break ; + }while (!signal_pending (current) && timeout); + +remove_wait_queue (sk_sleep (sk), &wait); +} +EXPORT_SYMBOL_GPL (vsock_linger); +static int vsock_shutdown (struct socket *sock,int mode) {int err;
net/vmw_vsock/virtio_transport_common.c +2 -21
@@ -1191,25 +1191,6 @@ static void virtio_transport_remove_sock(struct vsock_sock *vsk)vsock_remove_sock (vsk); } -static void virtio_transport_wait_close (struct sock *sk,long timeout) -{ -if (timeout) { -DEFINE_WAIT_FUNC (wait, woken_wake_function); -struct vsock_sock *vsk =vsock_sk (sk); - -add_wait_queue (sk_sleep (sk), &wait); - -do { -if (sk_wait_event (sk, &timeout, -virtio_transport_unsent_bytes (vsk) ==0 , - &wait)) -break ; - }while (!signal_pending (current) && timeout); - -remove_wait_queue (sk_sleep (sk), &wait); - } -} -static void virtio_transport_cancel_close_work (struct vsock_sock *vsk,bool cancel_timeout) {
@@ -1279,8 +1260,8 @@ static bool virtio_transport_close(struct vsock_sock *vsk)if ((sk->sk_shutdown &SHUTDOWN_MASK ) !=SHUTDOWN_MASK ) (void )virtio_transport_shutdown (vsk,SHUTDOWN_MASK ); -if (sock_flag (sk,SOCK_LINGER ) && !(current->flags &PF_EXITING )) -virtio_transport_wait_close (sk, sk->sk_lingertime); +if (!(current->flags &PF_EXITING )) +vsock_linger (sk);if (sock_flag (sk,SOCK_DONE )) {return true;
Signature · 1 line
2.49.0
PATCH v6 3/5 vsock/test: Introduce vsock_wait_sent() helper
In reply to Michal LuczajDistill the virtio_vsock_sock::bytes_unsent checking loop (ioctl SIOCOUTQ) and move it to utils. Tweak the comment.
--- tools/testing/vsock/util.c | 25 +++++++++++++++++++++++++ tools/testing/vsock/util.h | 1 + tools/testing/vsock/vsock_test.c | 23 ++++++----------------- 3 files changed, 32 insertions(+), 17 deletions(-)
tools/testing/vsock/util.c +25 -0
@@ -17,6 +17,7 @@#include <assert.h> #include <sys/epoll.h> #include <sys/mman.h> +#include <linux/sockios.h> #include "timeout.h" #include "control.h"
@@ -96,6 +97,30 @@ void vsock_wait_remote_close(int fd)close (epollfd); } +/* Wait until transport reports no data left to be sent. +* Return false if transport does not implement the unsent_bytes() callback. +*/ +bool vsock_wait_sent (int fd) +{ +int ret, sock_bytes_unsent; + +timeout_begin (TIMEOUT ); +do { + ret =ioctl (fd,SIOCOUTQ , &sock_bytes_unsent); +if (ret <0 ) { +if (errno ==EOPNOTSUPP ) +break ; + +perror ("ioctl(SIOCOUTQ)" ); +exit (EXIT_FAILURE ); + } +timeout_check ("SIOCOUTQ" ); + }while (sock_bytes_unsent !=0 ); +timeout_end (); + +return !ret; +} +/* Create socket <type>, bind to <cid, port> and return the file descriptor. */ int vsock_bind (unsigned int cid,unsigned int port,int type) {
tools/testing/vsock/util.h +1 -0
@@ -54,6 +54,7 @@ int vsock_stream_listen(unsigned int cid, unsigned int port);int vsock_seqpacket_accept (unsigned int cid,unsigned int port,struct sockaddr_vm *clientaddrp);void vsock_wait_remote_close (int fd); +bool vsock_wait_sent (int fd);void send_buf (int fd,const void *buf,size_t len,int flags,ssize_t expected_ret);void recv_buf (int fd,void *buf,size_t len,int flags,ssize_t expected_ret);
tools/testing/vsock/vsock_test.c +6 -17
@@ -21,7 +21,6 @@#include <poll.h> #include <signal.h> #include <sys/ioctl.h> -#include <linux/sockios.h> #include <linux/time64.h> #include "vsock_test_zerocopy.h"
@@ -1280,7 +1279,7 @@ static void test_unsent_bytes_server(const struct test_opts *opts, int type)static void test_unsent_bytes_client (const struct test_opts *opts,int type) {unsigned char buf[MSG_BUF_IOCTL_LEN ]; -int ret, fd, sock_bytes_unsent; +int fd; fd =vsock_connect (opts->peer_cid, opts->peer_port, type);if (fd <0 ) {
@@ -1297,22 +1296,12 @@ static void test_unsent_bytes_client(const struct test_opts *opts, int type)/* SIOCOUTQ isn't guaranteed to instantly track sent data. Even though * the "RECEIVED" message means that the other side has received the * data, there can be a delay in our kernel before updating the "unsent -* bytes" counter. Repeat SIOCOUTQ until it returns 0. +* bytes" counter. vsock_wait_sent() will repeat SIOCOUTQ until it +* returns 0. */ -timeout_begin (TIMEOUT ); -do { - ret =ioctl (fd,SIOCOUTQ , &sock_bytes_unsent); -if (ret <0 ) { -if (errno ==EOPNOTSUPP ) { -fprintf (stderr,"Test skipped, SIOCOUTQ not supported.\n" ); -break ; - } -perror ("ioctl" ); -exit (EXIT_FAILURE ); - } -timeout_check ("SIOCOUTQ" ); - }while (sock_bytes_unsent !=0 ); -timeout_end (); +if (!vsock_wait_sent (fd)) +fprintf (stderr,"Test skipped, SIOCOUTQ not supported.\n" ); +close (fd); }
Signature · 1 line
2.49.0
Re: [PATCH net-next v6 3/5] vsock/test: Introduce vsock_wait_sent() helper
Quoted 9 lines · Michal Luczaj
Distill the
virtio_vsock_sock::bytes_unsentchecking loop (ioctl SIOCOUTQ) and move it to utils. Tweak the comment.Signed-off-by Michal Luczaj <[email protected]>---
tools/testing/vsock/util.c | 25 +++++++++++++++++++++++++ tools/testing/vsock/util.h | 1 + tools/testing/vsock/vsock_test.c | 23 ++++++----------------- 3 files changed, 32 insertions(+), 17 deletions(-)
Quoted 109 lines
tools/testing/vsock/util.c +25
-0@@ -17,6 +17,7 @@#include <assert.h> #include <sys/epoll.h> #include <sys/mman.h> +#include <linux/sockios.h> #include "timeout.h" #include "control.h" @@ -96,6 +97,30 @@ void vsock_wait_remote_close(int fd)close (epollfd); } +/* Wait until transport reports no data left to be sent. +* Return false if transport does not implement the unsent_bytes() callback. +*/ +bool vsock_wait_sent (int fd) +{ +int ret, sock_bytes_unsent; + +timeout_begin (TIMEOUT ); +do { + ret =ioctl (fd,SIOCOUTQ , &sock_bytes_unsent); +if (ret <0 ) { +if (errno ==EOPNOTSUPP ) +break ; + +perror ("ioctl(SIOCOUTQ)" ); +exit (EXIT_FAILURE ); + } +timeout_check ("SIOCOUTQ" ); + }while (sock_bytes_unsent !=0 ); +timeout_end (); + +return !ret; +} +/* Create socket <type>, bind to <cid, port> and return the file descriptor. */ int vsock_bind (unsigned int cid,unsigned int port,int type) {tools/testing/vsock/util.h +1
-0@@ -54,6 +54,7 @@ int vsock_stream_listen(unsigned int cid, unsigned int port);int vsock_seqpacket_accept (unsigned int cid,unsigned int port,struct sockaddr_vm *clientaddrp);void vsock_wait_remote_close (int fd); +bool vsock_wait_sent (int fd);void send_buf (int fd,const void *buf,size_t len,int flags,ssize_t expected_ret);void recv_buf (int fd,void *buf,size_t len,int flags,ssize_t expected_ret);tools/testing/vsock/vsock_test.c +6
-17@@ -21,7 +21,6 @@#include <poll.h> #include <signal.h> #include <sys/ioctl.h> -#include <linux/sockios.h> #include <linux/time64.h> #include "vsock_test_zerocopy.h" @@ -1280,7 +1279,7 @@ static void test_unsent_bytes_server(const struct test_opts *opts, int type)static void test_unsent_bytes_client (const struct test_opts *opts,int type) {unsigned char buf[MSG_BUF_IOCTL_LEN ]; -int ret, fd, sock_bytes_unsent; +int fd; fd =vsock_connect (opts->peer_cid, opts->peer_port, type);if (fd <0 ) {@@ -1297,22 +1296,12 @@ static void test_unsent_bytes_client(const struct test_opts *opts, int type)/* SIOCOUTQ isn't guaranteed to instantly track sent data. Even though * the "RECEIVED" message means that the other side has received the * data, there can be a delay in our kernel before updating the "unsent -* bytes" counter. Repeat SIOCOUTQ until it returns 0. +* bytes" counter. vsock_wait_sent() will repeat SIOCOUTQ until it +* returns 0. */ -timeout_begin (TIMEOUT ); -do { - ret =ioctl (fd,SIOCOUTQ , &sock_bytes_unsent); -if (ret <0 ) { -if (errno ==EOPNOTSUPP ) { -fprintf (stderr,"Test skipped, SIOCOUTQ not supported.\n" ); -break ; - } -perror ("ioctl" ); -exit (EXIT_FAILURE ); - } -timeout_check ("SIOCOUTQ" ); - }while (sock_bytes_unsent !=0 ); -timeout_end (); +if (!vsock_wait_sent (fd)) +fprintf (stderr,"Test skipped, SIOCOUTQ not supported.\n" ); +close (fd); }Signature · 2 lines
-- 2.49.0
PATCH v6 4/5 vsock/test: Introduce enable_so_linger() helper
In reply to Michal LuczajAdd a helper function that sets SO_LINGER. Adapt the caller.
--- tools/testing/vsock/util.c | 13 +++++++++++++ tools/testing/vsock/util.h | 1 + tools/testing/vsock/vsock_test.c | 10 +--------- 3 files changed, 15 insertions(+), 9 deletions(-)
tools/testing/vsock/util.c +13 -0
@@ -823,3 +823,16 @@ void enable_so_zerocopy_check(int fd)setsockopt_int_check (fd,SOL_SOCKET ,SO_ZEROCOPY ,1 ,"setsockopt SO_ZEROCOPY" ); } + +void enable_so_linger (int fd,int timeout) +{ +struct linger optval = { + .l_onoff =1 , + .l_linger = timeout + }; + +if (setsockopt (fd,SOL_SOCKET ,SO_LINGER , &optval,sizeof (optval))) { +perror ("setsockopt(SO_LINGER)" ); +exit (EXIT_FAILURE ); + } +}
tools/testing/vsock/util.h +1 -0
@@ -80,4 +80,5 @@ void setsockopt_int_check(int fd, int level, int optname, int val,void setsockopt_timeval_check (int fd,int level,int optname,struct timeval val,char const *errmsg);void enable_so_zerocopy_check (int fd); +void enable_so_linger (int fd,int timeout);#endif /* UTIL_H */
tools/testing/vsock/vsock_test.c +1 -9
@@ -1813,10 +1813,6 @@ static void test_stream_connect_retry_server(const struct test_opts *opts)static void test_stream_linger_client (const struct test_opts *opts) { -struct linger optval = { - .l_onoff =1 , - .l_linger =1 - };int fd; fd =vsock_stream_connect (opts->peer_cid, opts->peer_port);
@@ -1825,11 +1821,7 @@ static void test_stream_linger_client(const struct test_opts *opts)exit (EXIT_FAILURE ); } -if (setsockopt (fd,SOL_SOCKET ,SO_LINGER , &optval,sizeof (optval))) { -perror ("setsockopt(SO_LINGER)" ); -exit (EXIT_FAILURE ); - } - +enable_so_linger (fd,1 );close (fd); }
Signature · 1 line
2.49.0
Re: [PATCH net-next v6 4/5] vsock/test: Introduce enable_so_linger() helper
Quoted 8 lines · Michal Luczaj
Add a helper function that sets
SO_LINGER. Adapt the caller.Signed-off-by Michal Luczaj <[email protected]>---
tools/testing/vsock/util.c | 13 +++++++++++++ tools/testing/vsock/util.h | 1 + tools/testing/vsock/vsock_test.c | 10 +--------- 3 files changed, 15 insertions(+), 9 deletions(-)
Quoted 64 lines
tools/testing/vsock/util.c +13
-0@@ -823,3 +823,16 @@ void enable_so_zerocopy_check(int fd)setsockopt_int_check (fd,SOL_SOCKET ,SO_ZEROCOPY ,1 ,"setsockopt SO_ZEROCOPY" ); } + +void enable_so_linger (int fd,int timeout) +{ +struct linger optval = { + .l_onoff =1 , + .l_linger = timeout + }; + +if (setsockopt (fd,SOL_SOCKET ,SO_LINGER , &optval,sizeof (optval))) { +perror ("setsockopt(SO_LINGER)" ); +exit (EXIT_FAILURE ); + } +}tools/testing/vsock/util.h +1
-0@@ -80,4 +80,5 @@ void setsockopt_int_check(int fd, int level, int optname, int val,void setsockopt_timeval_check (int fd,int level,int optname,struct timeval val,char const *errmsg);void enable_so_zerocopy_check (int fd); +void enable_so_linger (int fd,int timeout);#endif /* UTIL_H */ tools/testing/vsock/vsock_test.c +1
-9@@ -1813,10 +1813,6 @@ static void test_stream_connect_retry_server(const struct test_opts *opts)static void test_stream_linger_client (const struct test_opts *opts) { -struct linger optval = { - .l_onoff =1 , - .l_linger =1 - };int fd; fd =vsock_stream_connect (opts->peer_cid, opts->peer_port);@@ -1825,11 +1821,7 @@ static void test_stream_linger_client(const struct test_opts *opts)exit (EXIT_FAILURE ); } -if (setsockopt (fd,SOL_SOCKET ,SO_LINGER , &optval,sizeof (optval))) { -perror ("setsockopt(SO_LINGER)" ); -exit (EXIT_FAILURE ); - } - +enable_so_linger (fd,1 );close (fd); }Signature · 2 lines
-- 2.49.0
PATCH v6 5/5 vsock/test: Add test for an unexpectedly lingering close()
In reply to Michal LuczajThere was an issue with SO_LINGER: instead of blocking until all queued messages for the socket have been successfully sent (or the linger timeout has been reached), close() would block until packets were handled by the peer.
Add a test to alert on close() lingering when it should not.
--- tools/testing/vsock/vsock_test.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
tools/testing/vsock/vsock_test.c +52 -0
@@ -1839,6 +1839,53 @@ static void test_stream_linger_server(const struct test_opts *opts)close (fd); } +/* Half of the default to not risk timing out the control channel */ +#define LINGER_TIMEOUT (TIMEOUT / 2) + +static void test_stream_nolinger_client (const struct test_opts *opts) +{ +bool waited; +time_t ns; +int fd; + + fd =vsock_stream_connect (opts->peer_cid, opts->peer_port); +if (fd <0 ) { +perror ("connect" ); +exit (EXIT_FAILURE ); + } + +enable_so_linger (fd,LINGER_TIMEOUT ); +send_byte (fd,1 ,0 );/* Left unread to expose incorrect behaviour. */ + waited =vsock_wait_sent (fd); + + ns =current_nsec (); +close (fd); + ns =current_nsec () - ns; + +if (!waited) { +fprintf (stderr,"Test skipped, SIOCOUTQ not supported.\n" ); + }else if (DIV_ROUND_UP (ns,NSEC_PER_SEC ) >=LINGER_TIMEOUT ) { +fprintf (stderr,"Unexpected lingering\n" ); +exit (EXIT_FAILURE ); + } + +control_writeln ("DONE" ); +} + +static void test_stream_nolinger_server (const struct test_opts *opts) +{ +int fd; + + fd =vsock_stream_accept (VMADDR_CID_ANY , opts->peer_port,NULL ); +if (fd <0 ) { +perror ("accept" ); +exit (EXIT_FAILURE ); + } + +control_expectln ("DONE" ); +close (fd); +} +static struct test_case test_cases[] = { { .name ="SOCK_STREAM connection reset" ,
@@ -1999,6 +2046,11 @@ static struct test_case test_cases[] = { .run_client = test_stream_linger_client, .run_server = test_stream_linger_server, }, + { + .name = "SOCK_STREAM SO_LINGER close() on unread", + .run_client = test_stream_nolinger_client, + .run_server = test_stream_nolinger_server, + }, {}, };
Signature · 1 line
2.49.0
Re: [PATCH net-next v6 5/5] vsock/test: Add test for an unexpectedly lingering close()
Quoted 11 lines · Michal Luczaj
There was an issue with
SO_LINGER: instead of blocking until all queued messages for the socket have been successfully sent (or the linger timeout has been reached),close()would block until packets were handled by the peer.Add a test to alert on
close()lingering when it should not.Signed-off-by Michal Luczaj <[email protected]>---
tools/testing/vsock/vsock_test.c| 52 ++++++++++++++++++++++++++++++++++++++++1 file changed, 52 insertions(+)
Quoted 75 lines
tools/testing/vsock/vsock_test.c +52
-0@@ -1839,6 +1839,53 @@ static void test_stream_linger_server(const struct test_opts *opts)close (fd); } +/* Half of the default to not risk timing out the control channel */ +#define LINGER_TIMEOUT (TIMEOUT / 2) + +static void test_stream_nolinger_client (const struct test_opts *opts) +{ +bool waited; +time_t ns; +int fd; + + fd =vsock_stream_connect (opts->peer_cid, opts->peer_port); +if (fd <0 ) { +perror ("connect" ); +exit (EXIT_FAILURE ); + } + +enable_so_linger (fd,LINGER_TIMEOUT ); +send_byte (fd,1 ,0 );/* Left unread to expose incorrect behaviour. */ + waited =vsock_wait_sent (fd); + + ns =current_nsec (); +close (fd); + ns =current_nsec () - ns; + +if (!waited) { +fprintf (stderr,"Test skipped, SIOCOUTQ not supported.\n" ); + }else if (DIV_ROUND_UP (ns,NSEC_PER_SEC ) >=LINGER_TIMEOUT ) { +fprintf (stderr,"Unexpected lingering\n" ); +exit (EXIT_FAILURE ); + } + +control_writeln ("DONE" ); +} + +static void test_stream_nolinger_server (const struct test_opts *opts) +{ +int fd; + + fd =vsock_stream_accept (VMADDR_CID_ANY , opts->peer_port,NULL ); +if (fd <0 ) { +perror ("accept" ); +exit (EXIT_FAILURE ); + } + +control_expectln ("DONE" ); +close (fd); +} +static struct test_case test_cases[] = { { .name ="SOCK_STREAM connection reset" ,@@ -1999,6 +2046,11 @@ static struct test_case test_cases[] = { .run_client = test_stream_linger_client, .run_server = test_stream_linger_server, }, + { + .name = "SOCK_STREAM SO_LINGER close() on unread", + .run_client = test_stream_nolinger_client, + .run_server = test_stream_nolinger_server, + }, {}, };Signature · 2 lines
-- 2.49.0
Stefano Garzarella
maintainerQuoted 2 lines · Michal Luczaj
Change vsock's lingerning to wait on
close()until all data is sent, i.e. until workers picked all the packets for processing.
Thanks for the series and the patience :-)
LGTM! There should be my R-b for all patches.
Thanks,
Stefano
Quoted 62 lines
Changes in v6:
- Makevsock_wait_sent()return bool, parametrizeenable_so_linger()with timeout, don't open codeDIV_ROUND_UP[Stefano]
- Link to v5: https://lore.kernel.org/r/[email protected]Changes in v5:
- Moveunsent_bytesfetching logic toutils.c
- Add a helper for enablingSO_LINGER
- Accommodate forclose()taking a long time for reasons unrelated to lingering
- Separate and redo the testcase [Stefano]
- Enrich the comment [Stefano]
- Link to v4: https://lore.kernel.org/r/[email protected]Changes in v4:
- While in virtio, stick tovirtio_transport_unsent_bytes()[Stefano]
- Squash the indentation reduction [Stefano]
- PullSOCK_LINGERcheck intovsock_linger()[Stefano]
- Don't explicitly passsk->sk_lingertime[Stefano]
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- Set "vsock/virtio" topic where appropriate
- Do not claim that Hyper-V and VMCI ever lingered [Stefano]
- Move lingering toaf_vsockcore [Stefano]
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Comment that some transports do not implementunsent_bytes[Stefano]
- Reduce the indentation ofvirtio_transport_wait_close()[Stefano]
- Do not linger onshutdown(), expand the commit messages [Paolo]
- Link to v1: https://lore.kernel.org/r/[email protected]Changes in v1:
- Do not assumeunsent_bytes()is implemented by all transports [Stefano]
- Link to v0: https://lore.kernel.org/netdev/[email protected]/Signed-off-by Michal Luczaj <[email protected]>---
Michal Luczaj (5):
vsock/virtio: Linger on unsent data
vsock: Move lingering logic toaf_vsockcore vsock/test: Introducevsock_wait_sent()helper vsock/test: Introduceenable_so_linger()helper vsock/test: Add test for an unexpectedly lingeringclose()include/net/af_vsock.h | 1 + net/vmw_vsock/af_vsock.c | 33 +++++++++++++ net/vmw_vsock/virtio_transport_common.c | 21 +-------- tools/testing/vsock/util.c | 38 +++++++++++++++ tools/testing/vsock/util.h | 2 + tools/testing/vsock/vsock_test.c | 83 +++++++++++++++++++++++---------- 6 files changed, 134 insertions(+), 44 deletions(-)---
base-commit:f44092606a3f153bb7e6b277006b1f4a5b914cfc
change-id: 20250304-vsock-linger-9026e5f9986cBest regards,
Signature · 1 line
Michal Luczaj <[email protected]>
Quoted 7 lines · Stefano Garzarella
Quoted 2 lines · Michal Luczaj
Change vsock's lingerning to wait on
close()until all data is sent, i.e. until workers picked all the packets for processing.Thanks for the series and the patience :-)
LGTM! There should be my R-b for all patches.
I think it went smoothly, thanks for the reviews :)
Michal
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Thu, 22 May 2025 01:18:20 +0200 you wrote:
Change vsock's lingerning to wait on
close()until all data is sent, i.e. until workers picked all the packets for processing.Changes in v6:
- Makevsock_wait_sent()return bool, parametrizeenable_so_linger()with timeout, don't open codeDIV_ROUND_UP[Stefano]
- Link to v5: https://lore.kernel.org/r/[email protected][...]
Here is the summary with links:
- [net-next,v6,1/5] vsock/virtio: Linger on unsent data
https://git.kernel.org/netdev/net-next/c/1c39f5dbbfd2 - [net-next,v6,2/5] vsock: Move lingering logic to af_vsock core https://git.kernel.org/netdev/net-next/c/5ec40864aaec - [net-next,v6,3/5] vsock/test: Introduce vsock_wait_sent() helper https://git.kernel.org/netdev/net-next/c/e78e0596c762 - [net-next,v6,4/5] vsock/test: Introduce enable_so_linger() helper https://git.kernel.org/netdev/net-next/c/8b07b7e5c253 - [net-next,v6,5/5] vsock/test: Add test for an unexpectedly lingering close() https://git.kernel.org/netdev/net-next/c/393d070135ad
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html