Enhance virtio-vsock connection semantics
Subsystems (5)
v3 cover Enhance virtio-vsock connection semantics
This series improves the semantics behind the way virtio-vsock server accepts connections coming from the client. Whenever the server receives a connection request from the client, if it is bound to the socket but not yet listening, it will answer with a RST packet. The point is to ensure each request from the client is quickly processed so that the client can decide about the strategy of retrying or not.
The series includes along with the improvement patch a new test to ensure the behavior is consistent across all hypervisors drivers.
Sebastien Boeuf (2):
net: virtio_vsock: Enhance connection semantics
tools: testing: vsock: Test when server is bound but not listening
net/vmw_vsock/virtio_transport_common.c | 1 + tools/testing/vsock/vsock_test.c | 77 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+)
Signature · 13 lines
2.20.1 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH v3 1/2 net: virtio_vsock: Enhance connection semantics
Whenever the vsock backend on the host sends a packet through the RX queue, it expects an answer on the TX queue. Unfortunately, there is one case where the host side will hang waiting for the answer and might effectively never recover if no timeout mechanism was implemented.
This issue happens when the guest side starts binding to the socket, which insert a new bound socket into the list of already bound sockets. At this time, we expect the guest to also start listening, which will trigger the sk_state to move from TCP_CLOSE to TCP_LISTEN. The problem occurs if the host side queued a RX packet and triggered an interrupt right between the end of the binding process and the beginning of the listening process. In this specific case, the function processing the packet virtio_transport_recv_pkt() will find a bound socket, which means it will hit the switch statement checking for the sk_state, but the state won't be changed into TCP_LISTEN yet, which leads the code to pick the default statement. This default statement will only free the buffer, while it should also respond to the host side, by sending a packet on its TX queue.
In order to simply fix this unfortunate chain of events, it is important that in case the default statement is entered, and because at this stage we know the host side is waiting for an answer, we must send back a packet containing the operation VIRTIO_VSOCK_OP_RST.
One could say that a proper timeout mechanism on the host side will be enough to avoid the backend to hang. But the point of this patch is to ensure the normal use case will be provided with proper responsiveness when it comes to establishing the connection.
--- net/vmw_vsock/virtio_transport_common.c | 1 + 1 file changed, 1 insertion(+)
net/vmw_vsock/virtio_transport_common.c +1 -0
@@ -1153,6 +1153,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,virtio_transport_free_pkt (pkt);break ;default : + (void )virtio_transport_reset_no_sock (t, pkt);virtio_transport_free_pkt (pkt);break ; }
Signature · 13 lines
2.20.1 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH v3 2/2 tools: testing: vsock: Test when server is bound but not listening
In reply to Sebastien BoeufWhenever the server side of vsock is binding to the socket, but not listening yet, we expect the behavior from the client to be identical to what happens when the server is not even started.
This new test runs the server side so that it binds to the socket without ever listening to it. The client side will try to connect and should receive an ECONNRESET error.
This new test provides a way to validate the previously introduced patch for making sure the server side will always answer with a RST packet in case the client requested a new connection.
--- tools/testing/vsock/vsock_test.c | 77 ++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
tools/testing/vsock/vsock_test.c +77 -0
@@ -55,6 +55,78 @@ static void test_stream_connection_reset(const struct test_opts *opts)close (fd); } +static void test_stream_bind_only_client (const struct test_opts *opts) +{ +union { +struct sockaddr sa; +struct sockaddr_vm svm; + } addr = { + .svm = { + .svm_family =AF_VSOCK , + .svm_port =1234 , + .svm_cid = opts->peer_cid, + }, + }; +int ret; +int fd; + +/* Wait for the server to be ready */ +control_expectln ("BIND" ); + + fd =socket (AF_VSOCK ,SOCK_STREAM ,0 ); + +timeout_begin (TIMEOUT ); +do { + ret =connect (fd, &addr.sa,sizeof (addr.svm)); +timeout_check ("connect" ); + }while (ret <0 && errno ==EINTR ); +timeout_end (); + +if (ret !=-1 ) { +fprintf (stderr,"expected connect(2) failure, got %d\n" , ret); +exit (EXIT_FAILURE ); + } +if (errno !=ECONNRESET ) { +fprintf (stderr,"unexpected connect(2) errno %d\n" , errno); +exit (EXIT_FAILURE ); + } + +/* Notify the server that the client has finished */ +control_writeln ("DONE" ); + +close (fd); +} + +static void test_stream_bind_only_server (const struct test_opts *opts) +{ +union { +struct sockaddr sa; +struct sockaddr_vm svm; + } addr = { + .svm = { + .svm_family =AF_VSOCK , + .svm_port =1234 , + .svm_cid =VMADDR_CID_ANY , + }, + }; +int fd; + + fd =socket (AF_VSOCK ,SOCK_STREAM ,0 ); + +if (bind (fd, &addr.sa,sizeof (addr.svm)) <0 ) { +perror ("bind" ); +exit (EXIT_FAILURE ); + } + +/* Notify the client that the server is ready */ +control_writeln ("BIND" ); + +/* Wait for the client to finish */ +control_expectln ("DONE" ); + +close (fd); +} +static void test_stream_client_close_client (const struct test_opts *opts) {int fd;
@@ -212,6 +284,11 @@ static struct test_case test_cases[] = { .name = "SOCK_STREAM connection reset", .run_client = test_stream_connection_reset, }, + { + .name = "SOCK_STREAM bind only", + .run_client = test_stream_bind_only_client, + .run_server = test_stream_bind_only_server, + }, { .name = "SOCK_STREAM client close", .run_client = test_stream_client_close_client,
Signature · 13 lines
2.20.1 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Quoted 10 lines · Sebastien Boeuf
This series improves the semantics behind the way virtio-vsock server accepts connections coming from the client. Whenever the server receives a connection request from the client, if it is bound to the socket but not yet listening, it will answer with a RST packet. The point is to ensure each request from the client is quickly processed so that the client can decide about the strategy of retrying or not.
The series includes along with the improvement patch a new test to ensure the behavior is consistent across all hypervisors drivers.
Quoted 8 lines
Sebastien Boeuf (2):
net:virtio_vsock: Enhance connection semantics
tools: testing: vsock: Test when server is bound but not listeningnet/vmw_vsock/virtio_transport_common.c | 1 + tools/testing/vsock/vsock_test.c | 77 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+)
Thanks,
now they apply cleanly!
Quoted 20 lines · Stefano Garzarella
Quoted 19 lines · Sebastien Boeuf
This series improves the semantics behind the way virtio-vsock server
accepts connections coming from the client. Whenever the server receives a connection request from the client, if it is bound to the
socket but not yet listening, it will answer with a RST packet. The point is to ensure each request from the client is quickly processed
so that the client can decide about the strategy of retrying or not.The series includes along with the improvement patch a new test to ensure the behavior is consistent across all hypervisors drivers.
Sebastien Boeuf (2):
net:virtio_vsock: Enhance connection semantics
tools: testing: vsock: Test when server is bound but not
listening
Quoted 8 lines
Quoted 5 lines
net/vmw_vsock/virtio_transport_common.c | 1 + tools/testing/vsock/vsock_test.c | 77 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+)Thanks,
now they apply cleanly!
Great!
Quoted 4 lines
Tested-by Stefano Garzarella <[email protected]>Reviewed-by Stefano Garzarella <[email protected]>
---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
David Miller
maintainerFrom: Sebastien Boeuf <[email protected]>
Date: Fri, 14 Feb 2020 12:48:00 +0100
Quoted 9 lines
This series improves the semantics behind the way virtio-vsock server accepts connections coming from the client. Whenever the server receives a connection request from the client, if it is bound to the socket but not yet listening, it will answer with a RST packet. The point is to ensure each request from the client is quickly processed so that the client can decide about the strategy of retrying or not.
The series includes along with the improvement patch a new test to ensure the behavior is consistent across all hypervisors drivers.
Series applied to net-next, thanks Sebastien.
Quoted 14 lines · David Miller
From: Sebastien Boeuf <[email protected]>
Date: Fri, 14 Feb 2020 12:48:00 +0100Quoted 11 lines
This series improves the semantics behind the way virtio-vsock server
accepts connections coming from the client. Whenever the server receives a connection request from the client, if it is bound to the
socket but not yet listening, it will answer with a RST packet. The point is to ensure each request from the client is quickly processed
so that the client can decide about the strategy of retrying or not.
Quoted 4 lines
Quoted 2 lines
The series includes along with the improvement patch a new test to ensure the behavior is consistent across all hypervisors drivers.
Series applied to net-next, thanks Sebastien.
Thank you very much, I really appreciate how quickly things went :)
Sebastien
---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.