Skip to content

Commit 528d92b

Browse files
Ying Gaomstsirkin
authored andcommitted
virtio_input: Improve freeze handling
When executing suspend to ram, if lacking the operations to reset device and free unused buffers before deleting a vq, resource leaks and inconsistent device status will appear. According to chapter "3.3.1 Driver Requirements: Device Cleanup:" of virtio-specification: Driver MUST ensure a virtqueue isn’t live (by device reset) before removing exposed buffers. Therefore, modify the virtinput_freeze function to reset the device and delete the unused buffers before deleting the virtqueue, just like virtinput_remove does. Co-developed-by: Ying Xu <[email protected]> Signed-off-by: Ying Xu <[email protected]> Co-developed-by: Junnan Wu <[email protected]> Signed-off-by: Junnan Wu <[email protected]> Signed-off-by: Ying Gao <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 24fc631 commit 528d92b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/virtio/virtio_input.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,15 @@ static int virtinput_freeze(struct virtio_device *vdev)
360360
{
361361
struct virtio_input *vi = vdev->priv;
362362
unsigned long flags;
363+
void *buf;
363364

364365
spin_lock_irqsave(&vi->lock, flags);
365366
vi->ready = false;
366367
spin_unlock_irqrestore(&vi->lock, flags);
367368

369+
virtio_reset_device(vdev);
370+
while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
371+
kfree(buf);
368372
vdev->config->del_vqs(vdev);
369373
return 0;
370374
}

0 commit comments

Comments
 (0)