Skip to content

Commit d3746a3

Browse files
junnan01-wuNipaLocal
authored and
NipaLocal
committed
vsock/virtio: fix variables initialization during resuming
When executing suspend to ram twice in a row, the `rx_buf_nr` and `rx_buf_max_nr` increase to three times vq->num_free. Then after virtqueue_get_buf and `rx_buf_nr` decreased in function virtio_transport_rx_work, the condition to fill rx buffer (rx_buf_nr < rx_buf_max_nr / 2) will never be met. It is because that `rx_buf_nr` and `rx_buf_max_nr` are initialized only in virtio_vsock_probe(), but they should be reset whenever virtqueues are recreated, like after a suspend/resume. Move the `rx_buf_nr` and `rx_buf_max_nr` initialization in virtio_vsock_vqs_init(), so we are sure that they are properly initialized, every time we initialize the virtqueues, either when we load the driver or after a suspend/resume. To prevent erroneous atomic load operations on the `queued_replies` in the virtio_transport_send_pkt_work() function which may disrupt the scheduling of vsock->rx_work when transmitting reply-required socket packets, this atomic variable must undergo synchronized initialization alongside the preceding two variables after a suspend/resume. Fixes: bd50c5d ("vsock/virtio: add support for device suspend/resume") Link: https://lore.kernel.org/virtualization/[email protected]/ Co-developed-by: Ying Gao <[email protected]> Signed-off-by: Ying Gao <[email protected]> Signed-off-by: Junnan Wu <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent c343c8f commit d3746a3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

net/vmw_vsock/virtio_transport.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,13 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock)
670670
};
671671
int ret;
672672

673+
mutex_lock(&vsock->rx_lock);
674+
vsock->rx_buf_nr = 0;
675+
vsock->rx_buf_max_nr = 0;
676+
mutex_unlock(&vsock->rx_lock);
677+
678+
atomic_set(&vsock->queued_replies, 0);
679+
673680
ret = virtio_find_vqs(vdev, VSOCK_VQ_MAX, vsock->vqs, vqs_info, NULL);
674681
if (ret < 0)
675682
return ret;
@@ -779,9 +786,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
779786

780787
vsock->vdev = vdev;
781788

782-
vsock->rx_buf_nr = 0;
783-
vsock->rx_buf_max_nr = 0;
784-
atomic_set(&vsock->queued_replies, 0);
785789

786790
mutex_init(&vsock->tx_lock);
787791
mutex_init(&vsock->rx_lock);

0 commit comments

Comments
 (0)