[PATCH 2/2] vsock/virtio: Don't reset the created SOCKET during s2r

2025-02-06 Thread Junnan Wu
From: Ying Gao 

If suspend is executed during vsock communication and the
socket is reset, the original socket will be unusable after resume.

Judge the value of vdev->priv in function virtio_vsock_vqs_del,
only when the function is invoked by virtio_vsock_remove,
all vsock connections will be reset.

Signed-off-by: Ying Gao 
Signed-off-by: Junnan Wu 
---
 net/vmw_vsock/virtio_transport.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 9eefd0fba92b..9df609581755 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -717,8 +717,10 @@ static void virtio_vsock_vqs_del(struct virtio_vsock 
*vsock)
struct sk_buff *skb;
 
/* Reset all connected sockets when the VQs disappear */
-   vsock_for_each_connected_socket(&virtio_transport.transport,
-   virtio_vsock_reset_sock);
+   if (!vdev->priv) {
+   vsock_for_each_connected_socket(&virtio_transport.transport,
+   virtio_vsock_reset_sock);
+   }
 
/* Stop all work handlers to make sure no one is accessing the device,
 * so we can safely call virtio_reset_device().
-- 
2.34.1




[PATCH 1/2] vsock/virtio: Move rx_buf_nr and rx_buf_max_nr initialization position

2025-02-06 Thread Junnan Wu
From: Ying Gao 

In function virtio_vsock_probe, it initializes the variables
"rx_buf_nr" and "rx_buf_max_nr",
but in function virtio_vsock_restore it doesn't.

Move the initizalition position into function virtio_vsock_vqs_start.

Once executing s2r twice in a row without
initializing rx_buf_nr and rx_buf_max_nr,
the rx_buf_max_nr increased to three times vq->num_free,
at this time, in function virtio_transport_rx_work,
the conditions to fill rx buffer
(rx_buf_nr < rx_buf_max_nr / 2) can't be met.

Signed-off-by: Ying Gao 
Signed-off-by: Junnan Wu 
---
 net/vmw_vsock/virtio_transport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index b58c3818f284..9eefd0fba92b 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -688,6 +688,8 @@ static void virtio_vsock_vqs_start(struct virtio_vsock 
*vsock)
mutex_unlock(&vsock->tx_lock);
 
mutex_lock(&vsock->rx_lock);
+   vsock->rx_buf_nr = 0;
+   vsock->rx_buf_max_nr = 0;
virtio_vsock_rx_fill(vsock);
vsock->rx_run = true;
mutex_unlock(&vsock->rx_lock);
@@ -779,8 +781,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 
vsock->vdev = vdev;
 
-   vsock->rx_buf_nr = 0;
-   vsock->rx_buf_max_nr = 0;
atomic_set(&vsock->queued_replies, 0);
 
mutex_init(&vsock->tx_lock);
-- 
2.34.1