Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <ying123.xu@samsung.com>
Signed-off-by: Ying Xu <ying123.xu@samsung.com>
Co-developed-by: Junnan Wu <junnan01.wu@samsung.com>
Signed-off-by: Junnan Wu <junnan01.wu@samsung.com>
Signed-off-by: Ying Gao <ying01.gao@samsung.com>
Message-Id: <20250812095118.3622717-1-ying01.gao@samsung.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Ying Gao and committed by
Michael S. Tsirkin
528d92bf 24fc6315

+4
+4
drivers/virtio/virtio_input.c
··· 360 360 { 361 361 struct virtio_input *vi = vdev->priv; 362 362 unsigned long flags; 363 + void *buf; 363 364 364 365 spin_lock_irqsave(&vi->lock, flags); 365 366 vi->ready = false; 366 367 spin_unlock_irqrestore(&vi->lock, flags); 367 368 369 + virtio_reset_device(vdev); 370 + while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL) 371 + kfree(buf); 368 372 vdev->config->del_vqs(vdev); 369 373 return 0; 370 374 }