netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Enhance virtio-vsock connection semantics
@ 2020-02-14 11:48 Sebastien Boeuf
  2020-02-14 11:48 ` [PATCH v3 1/2] net: virtio_vsock: Enhance " Sebastien Boeuf
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Sebastien Boeuf @ 2020-02-14 11:48 UTC (permalink / raw)
  To: netdev; +Cc: sgarzare, stefanha, davem, 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

 net/vmw_vsock/virtio_transport_common.c |  1 +
 tools/testing/vsock/vsock_test.c        | 77 +++++++++++++++++++++++++
 2 files changed, 78 insertions(+)

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/2] net: virtio_vsock: Enhance connection semantics
  2020-02-14 11:48 [PATCH v3 0/2] Enhance virtio-vsock connection semantics Sebastien Boeuf
@ 2020-02-14 11:48 ` Sebastien Boeuf
  2020-02-14 11:48 ` [PATCH v3 2/2] tools: testing: vsock: Test when server is bound but not listening Sebastien Boeuf
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Sebastien Boeuf @ 2020-02-14 11:48 UTC (permalink / raw)
  To: netdev; +Cc: sgarzare, stefanha, davem, Sebastien Boeuf

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.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
---
 net/vmw_vsock/virtio_transport_common.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index d9f0c9c5425a..2f696124bab6 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -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;
 	}
-- 
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.


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 2/2] tools: testing: vsock: Test when server is bound but not listening
  2020-02-14 11:48 [PATCH v3 0/2] Enhance virtio-vsock connection semantics Sebastien Boeuf
  2020-02-14 11:48 ` [PATCH v3 1/2] net: virtio_vsock: Enhance " Sebastien Boeuf
@ 2020-02-14 11:48 ` Sebastien Boeuf
  2020-02-14 12:18 ` [PATCH v3 0/2] Enhance virtio-vsock connection semantics Stefano Garzarella
  2020-02-17  3:02 ` David Miller
  3 siblings, 0 replies; 7+ messages in thread
From: Sebastien Boeuf @ 2020-02-14 11:48 UTC (permalink / raw)
  To: netdev; +Cc: sgarzare, stefanha, davem, Sebastien Boeuf

Whenever 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.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
---
 tools/testing/vsock/vsock_test.c | 77 ++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
index 1d8b93f1af31..5a4fb80fa832 100644
--- a/tools/testing/vsock/vsock_test.c
+++ b/tools/testing/vsock/vsock_test.c
@@ -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,
-- 
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.


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/2] Enhance virtio-vsock connection semantics
  2020-02-14 11:48 [PATCH v3 0/2] Enhance virtio-vsock connection semantics Sebastien Boeuf
  2020-02-14 11:48 ` [PATCH v3 1/2] net: virtio_vsock: Enhance " Sebastien Boeuf
  2020-02-14 11:48 ` [PATCH v3 2/2] tools: testing: vsock: Test when server is bound but not listening Sebastien Boeuf
@ 2020-02-14 12:18 ` Stefano Garzarella
  2020-02-14 12:20   ` Boeuf, Sebastien
  2020-02-17  3:02 ` David Miller
  3 siblings, 1 reply; 7+ messages in thread
From: Stefano Garzarella @ 2020-02-14 12:18 UTC (permalink / raw)
  To: Sebastien Boeuf; +Cc: netdev, stefanha, davem

On Fri, Feb 14, 2020 at 12:48:00PM +0100, Sebastien Boeuf wrote:
> 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(+)
> 

Thanks,
now they apply cleanly!

Tested-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/2] Enhance virtio-vsock connection semantics
  2020-02-14 12:18 ` [PATCH v3 0/2] Enhance virtio-vsock connection semantics Stefano Garzarella
@ 2020-02-14 12:20   ` Boeuf, Sebastien
  0 siblings, 0 replies; 7+ messages in thread
From: Boeuf, Sebastien @ 2020-02-14 12:20 UTC (permalink / raw)
  To: sgarzare; +Cc: stefanha, netdev, davem

On Fri, 2020-02-14 at 13:18 +0100, Stefano Garzarella wrote:
> On Fri, Feb 14, 2020 at 12:48:00PM +0100, Sebastien Boeuf wrote:
> > 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(+)
> > 
> 
> Thanks,
> now they apply cleanly!

Great!

> 
> Tested-by: Stefano Garzarella <sgarzare@redhat.com>
> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
> 
---------------------------------------------------------------------
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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/2] Enhance virtio-vsock connection semantics
  2020-02-14 11:48 [PATCH v3 0/2] Enhance virtio-vsock connection semantics Sebastien Boeuf
                   ` (2 preceding siblings ...)
  2020-02-14 12:18 ` [PATCH v3 0/2] Enhance virtio-vsock connection semantics Stefano Garzarella
@ 2020-02-17  3:02 ` David Miller
  2020-02-17  7:43   ` Boeuf, Sebastien
  3 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2020-02-17  3:02 UTC (permalink / raw)
  To: sebastien.boeuf; +Cc: netdev, sgarzare, stefanha

From: Sebastien Boeuf <sebastien.boeuf@intel.com>
Date: Fri, 14 Feb 2020 12:48:00 +0100

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 0/2] Enhance virtio-vsock connection semantics
  2020-02-17  3:02 ` David Miller
@ 2020-02-17  7:43   ` Boeuf, Sebastien
  0 siblings, 0 replies; 7+ messages in thread
From: Boeuf, Sebastien @ 2020-02-17  7:43 UTC (permalink / raw)
  To: davem; +Cc: sgarzare, stefanha, netdev

On Sun, 2020-02-16 at 19:02 -0800, David Miller wrote:
> From: Sebastien Boeuf <sebastien.boeuf@intel.com>
> Date: Fri, 14 Feb 2020 12:48:00 +0100
> 
> > 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.

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-02-17  7:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 11:48 [PATCH v3 0/2] Enhance virtio-vsock connection semantics Sebastien Boeuf
2020-02-14 11:48 ` [PATCH v3 1/2] net: virtio_vsock: Enhance " Sebastien Boeuf
2020-02-14 11:48 ` [PATCH v3 2/2] tools: testing: vsock: Test when server is bound but not listening Sebastien Boeuf
2020-02-14 12:18 ` [PATCH v3 0/2] Enhance virtio-vsock connection semantics Stefano Garzarella
2020-02-14 12:20   ` Boeuf, Sebastien
2020-02-17  3:02 ` David Miller
2020-02-17  7:43   ` Boeuf, Sebastien

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).