* [PATCH] virtio_input: clear the virtqueue pointers on freeze
@ 2026-12-03 1:24 Mingbing Zhai
2026-12-03 1:27 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Mingbing Zhai @ 2026-12-03 1:24 UTC (permalink / raw)
To: kraxel
Cc: mst, jasowangio, eperezma, xuanzhuo, virtualization, linux-kernel,
stable, Mingbing Zhai
virtinput_freeze() tears down the virtqueues with del_vqs() but
leaves vi->evt and vi->sts pointing at the freed memory. If the
resume then fails (virtio_find_vqs() in virtinput_restore() fails),
the driver stays bound and the next freeze or remove uses the freed
queues in virtqueue_detach_unused_buf() and calls del_vqs() a second
time -- on virtio-mmio that also frees the same IRQs again.
Factor the detach and del_vqs() into virtinput_del_vqs(), clear the
pointers after the queues are gone, and make it a no-op once they
are. This mirrors the hwrng (0f7bf47f5a0c) and vsock (2a24ba1694f1)
fixes for a failed restore.
Fixes: 271c865161c5 ("Add virtio-input driver.")
Fixes: 528d92bfc093 ("virtio_input: Improve freeze handling")
Cc: stable@vger.kernel.org
Signed-off-by: Mingbing Zhai <zhaimingbing@cmss.chinamobile.com>
---
drivers/virtio/virtio_input.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
index e3bd0b9616f94..9cb1cd51f77bb 100644
--- a/drivers/virtio/virtio_input.c
+++ b/drivers/virtio/virtio_input.c
@@ -344,10 +344,27 @@ static int virtinput_probe(struct virtio_device *vdev)
return err;
}
-static void virtinput_remove(struct virtio_device *vdev)
+static void virtinput_del_vqs(struct virtio_device *vdev)
{
struct virtio_input *vi = vdev->priv;
void *buf;
+
+ /*
+ * After a failed restore the virtqueues are gone while the driver
+ * stays bound, so a later freeze or remove must not touch them.
+ */
+ if (!vi->sts)
+ return;
+
+ while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
+ kfree(buf);
+ vdev->config->del_vqs(vdev);
+ vi->evt = vi->sts = NULL;
+}
+
+static void virtinput_remove(struct virtio_device *vdev)
+{
+ struct virtio_input *vi = vdev->priv;
unsigned long flags;
spin_lock_irqsave(&vi->lock, flags);
@@ -357,9 +374,8 @@ static void virtinput_remove(struct virtio_device *vdev)
/* Callbacks use vi->idev. */
virtio_reset_device(vdev);
input_unregister_device(vi->idev);
- while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
- kfree(buf);
- vdev->config->del_vqs(vdev);
+
+ virtinput_del_vqs(vdev);
kfree(vi);
}
@@ -368,16 +384,13 @@ static int virtinput_freeze(struct virtio_device *vdev)
{
struct virtio_input *vi = vdev->priv;
unsigned long flags;
- void *buf;
spin_lock_irqsave(&vi->lock, flags);
vi->ready = false;
spin_unlock_irqrestore(&vi->lock, flags);
virtio_reset_device(vdev);
- while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
- kfree(buf);
- vdev->config->del_vqs(vdev);
+ virtinput_del_vqs(vdev);
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] virtio_input: clear the virtqueue pointers on freeze
2026-12-03 1:24 [PATCH] virtio_input: clear the virtqueue pointers on freeze Mingbing Zhai
@ 2026-12-03 1:27 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 1:27 UTC (permalink / raw)
To: Mingbing Zhai; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> virtinput_freeze() tears down the virtqueues with del_vqs() but
> leaves vi->evt and vi->sts pointing at the freed memory. If the
> resume then fails (virtio_find_vqs() in virtinput_restore() fails),
> the driver stays bound and the next freeze or remove uses the freed
> queues in virtqueue_detach_unused_buf() and calls del_vqs() a second
> time -- on virtio-mmio that also frees the same IRQs again.
>
> Factor the detach and del_vqs() into virtinput_del_vqs(), clear the
> pointers after the queues are gone, and make it a no-op once they
> are. This mirrors the hwrng (0f7bf47f5a0c) and vsock (2a24ba1694f1)
> fixes for a failed restore.
>
> Fixes: 271c865161c5 ("Add virtio-input driver.")
> Fixes: 528d92bfc093 ("virtio_input: Improve freeze handling")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mingbing Zhai <zhaimingbing@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203012445.1202-1-zhaimingbing@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 1:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 1:24 [PATCH] virtio_input: clear the virtqueue pointers on freeze Mingbing Zhai
2026-12-03 1:27 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox