]> git.baikalelectronics.ru Git - kernel.git/commit
vsock/virtio: discard packets only when socket is really closed
authorStefano Garzarella <sgarzare@redhat.com>
Fri, 20 Nov 2020 10:47:36 +0000 (11:47 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 24 Nov 2020 00:36:29 +0000 (16:36 -0800)
commit55a1acddb71ddc79d60c498deb23ca525862b73f
treef3bf150c9f8c15d14a3af2ec08b55c85441a6bc4
parent09acdfcff97690501062cc60386ebc5b302572b7
vsock/virtio: discard packets only when socket is really closed

Starting from commit 753ecf64b2c5 ("virtio_vsock: Fix race condition
in virtio_transport_recv_pkt"), we discard packets in
virtio_transport_recv_pkt() if the socket has been released.

When the socket is connected, we schedule a delayed work to wait the
RST packet from the other peer, also if SHUTDOWN_MASK is set in
sk->sk_shutdown.
This is done to complete the virtio-vsock shutdown algorithm, releasing
the port assigned to the socket definitively only when the other peer
has consumed all the packets.

If we discard the RST packet received, the socket will be closed only
when the VSOCK_CLOSE_TIMEOUT is reached.

Sergio discovered the issue while running ab(1) HTTP benchmark using
libkrun [1] and observing a latency increase with that commit.

To avoid this issue, we discard packet only if the socket is really
closed (SOCK_DONE flag is set).
We also set SOCK_DONE in virtio_transport_release() when we don't need
to wait any packets from the other peer (we didn't schedule the delayed
work). In this case we remove the socket from the vsock lists, releasing
the port assigned.

[1] https://github.com/containers/libkrun

Fixes: 753ecf64b2c5 ("virtio_vsock: Fix race condition in virtio_transport_recv_pkt")
Cc: justin.he@arm.com
Reported-by: Sergio Lopez <slp@redhat.com>
Tested-by: Sergio Lopez <slp@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Jia He <justin.he@arm.com>
Link: https://lore.kernel.org/r/20201120104736.73749-1-sgarzare@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/vmw_vsock/virtio_transport_common.c