virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio: Remove virtio devices on device_shutdown()
@ 2024-08-08  7:51 Kirill A. Shutemov
  2024-08-08 11:37 ` Jiri Pirko
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Kirill A. Shutemov @ 2024-08-08  7:51 UTC (permalink / raw)
  To: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Eugenio Pérez
  Cc: virtualization, linux-kernel, Kirill A. Shutemov, Hongyu Ning

Hongyu reported a hang on kexec in a VM. QEMU reported invalid memory
accesses during the hang.

	Invalid read at addr 0x102877002, size 2, region '(null)', reason: rejected
	Invalid write at addr 0x102877A44, size 2, region '(null)', reason: rejected
	...

It was traced down to virtio-console. Kexec works fine if virtio-console
is not in use.

Looks like virtio-console continues to write to the MMIO even after
underlying virtio-pci device is removed.

The problem can be mitigated by removing all virtio devices on virtio
bus shutdown.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Hongyu Ning <hongyu.ning@linux.intel.com>
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index a9b93e99c23a..6c2f908eb22c 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -356,6 +356,15 @@ static void virtio_dev_remove(struct device *_d)
 	of_node_put(dev->dev.of_node);
 }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+	struct virtio_device *dev = dev_to_virtio(_d);
+	struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
+
+	if (drv && drv->remove)
+		drv->remove(dev);
+}
+
 static const struct bus_type virtio_bus = {
 	.name  = "virtio",
 	.match = virtio_dev_match,
@@ -363,6 +372,7 @@ static const struct bus_type virtio_bus = {
 	.uevent = virtio_uevent,
 	.probe = virtio_dev_probe,
 	.remove = virtio_dev_remove,
+	.shutdown = virtio_dev_shutdown,
 };
 
 int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2025-02-18  1:49 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08  7:51 [PATCH] virtio: Remove virtio devices on device_shutdown() Kirill A. Shutemov
2024-08-08 11:37 ` Jiri Pirko
2024-08-08 12:11   ` Kirill A. Shutemov
2024-08-08 15:28     ` Jiri Pirko
2024-08-08 12:10 ` Michael S. Tsirkin
2024-08-08 13:15   ` Kirill A. Shutemov
2024-08-08 15:03     ` Michael S. Tsirkin
2024-08-08 15:28       ` Kirill A. Shutemov
2024-11-04 10:22         ` Kirill A. Shutemov
2025-01-31  9:53 ` Eric Auger
2025-01-31 11:55   ` Michael S. Tsirkin
2025-02-03 14:48   ` Michael S. Tsirkin
2025-02-04 11:46     ` Eric Auger
2025-02-06  8:59       ` Eric Auger
2025-02-06 10:04         ` Kirill A. Shutemov
2025-02-06 16:27           ` Eric Auger
2025-02-14  7:21         ` Ning, Hongyu
2025-02-14  7:56           ` Eric Auger
2025-02-14 12:16             ` Michael S. Tsirkin
2025-02-17  3:29               ` Jason Wang
2025-02-17  7:49                 ` Ning, Hongyu
2025-02-17  9:25               ` Eric Auger
2025-02-17 16:59                 ` Eric Auger
2025-02-17 23:20                   ` Michael S. Tsirkin
2025-02-17 23:57                 ` Ning, Hongyu
2025-02-18  0:12                   ` Michael S. Tsirkin
2025-02-18  1:49                     ` Ning, Hongyu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).