[Devel] [PATCH RHEL10 COMMIT] virtio: add virtio_device_shutdown() helper

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jun 29 21:15:44 MSK 2026


The commit is pushed to "branch-rh10-6.12.0-211.16.1.12.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-211.16.1.12.7.vz10
------>
commit faad5cac7f4f1d5215d7f4522f3829f3ad9e37ec
Author: Denis V. Lunev <den at openvz.org>
Date:   Mon Jun 29 14:34:53 2026 +0200

    virtio: add virtio_device_shutdown() helper
    
    The generic virtio bus .shutdown handler, virtio_dev_shutdown(), breaks
    and resets a device once it has established that the driver has no
    .shutdown of its own. A driver that does implement .shutdown, to quiesce
    its own activity first, still needs the same break and reset afterwards
    and would otherwise have to open code it.
    
    Factor the break + synchronize_cbs + reset sequence out of
    virtio_dev_shutdown() into an exported virtio_device_shutdown() helper so
    such drivers can reuse it instead of duplicating the core logic.
    
    No functional change.
    
    Feature: fix ms/virtio_balloon
    https://virtuozzo.atlassian.net/browse/VSTOR-135654
    Signed-off-by: Denis V. Lunev <den at openvz.org>
    
    Reviewed-by: David Hildenbrand <david at kernel.org>
---
 drivers/virtio/virtio.c | 41 +++++++++++++++++++++++++++--------------
 include/linux/virtio.h  |  1 +
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 63a478d62af77..1e09e0bd5929a 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -401,6 +401,32 @@ static const struct cpumask *virtio_irq_get_affinity(struct device *_d,
 	return dev->config->get_vq_affinity(dev, irq_vec);
 }
 
+/**
+ * virtio_device_shutdown - break and reset a device on shutdown
+ * @dev: the device
+ *
+ * Drivers with their own .shutdown method should quiesce their activity and
+ * then call this to stop the device the way the generic shutdown path does.
+ */
+void virtio_device_shutdown(struct virtio_device *dev)
+{
+	/*
+	 * Some devices get wedged if you kick them after they are
+	 * reset. Mark all vqs as broken to make sure we don't.
+	 */
+	virtio_break_device(dev);
+	/*
+	 * Guarantee that any callback will see vq->broken as true.
+	 */
+	virtio_synchronize_cbs(dev);
+	/*
+	 * As IOMMUs are reset on shutdown, this will block device access to memory.
+	 * Some devices get wedged if this happens, so reset to make sure it does not.
+	 */
+	dev->config->reset(dev);
+}
+EXPORT_SYMBOL_GPL(virtio_device_shutdown);
+
 static void virtio_dev_shutdown(struct device *_d)
 {
 	struct virtio_device *dev = dev_to_virtio(_d);
@@ -419,20 +445,7 @@ static void virtio_dev_shutdown(struct device *_d)
 		return;
 	}
 
-	/*
-	 * Some devices get wedged if you kick them after they are
-	 * reset. Mark all vqs as broken to make sure we don't.
-	 */
-	virtio_break_device(dev);
-	/*
-	 * Guarantee that any callback will see vq->broken as true.
-	 */
-	virtio_synchronize_cbs(dev);
-	/*
-	 * As IOMMUs are reset on shutdown, this will block device access to memory.
-	 * Some devices get wedged if this happens, so reset to make sure it does not.
-	 */
-	dev->config->reset(dev);
+	virtio_device_shutdown(dev);
 }
 
 static const struct bus_type virtio_bus = {
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 62b1c81e9a151..26a906b12b9a5 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -184,6 +184,7 @@ int virtio_device_freeze(struct virtio_device *dev);
 int virtio_device_restore(struct virtio_device *dev);
 #endif
 void virtio_reset_device(struct virtio_device *dev);
+void virtio_device_shutdown(struct virtio_device *dev);
 
 size_t virtio_max_dma_size(const struct virtio_device *vdev);
 


More information about the Devel mailing list