Skip to contentSkip to conversation

virtio: Remove virtio devices on device_shutdown()

PATCH In review Kirill A. Shutemov 7 participants 27 messages Aug 8, 2024 – Feb 18, 2025 virtio core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: Remove virtio devices on device_shutdown()

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.

---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +10 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 10 lines · Thu, Aug 08, 2024 at 09:51:41AM CEST, [email protected] wrote:

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.

Quoted 8 lines

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.

Could you provide a "Fixes:" tag pointing to the commit that introduced the bug?

Quoted 36 lines

---
drivers/virtio/virtio.c | 10 ++++++++++

1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +10 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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)
Signature · 1 line
2.43.0
#2 lore raw
Quoted 14 lines · Jiri Pirko
Quoted 13 lines · Thu, Aug 08, 2024 at 09:51:41AM CEST, [email protected] wrote:

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.

Quoted 8 lines
Quoted 5 lines

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

Could you provide a "Fixes:" tag pointing to the commit that introduced the bug?

I am not sure if it is a regression. Maybe it was there forever.

Hongyu, could you please check with bisect if it is possible to point to a specific commit?

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#3 lore raw
Quoted 18 lines · Thu, Aug 08, 2024 at 02:11:09PM CEST, [email protected] wrote:
Quoted 17 lines · Jiri Pirko
Quoted 16 lines · Thu, Aug 08, 2024 at 09:51:41AM CEST, [email protected] wrote:

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.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Could you provide a "Fixes:" tag pointing to the commit that introduced the bug?

I am not sure if it is a regression. Maybe it was there forever.

Does not have to be regression. You can blame the commit that added the code.

Quoted 6 lines

Hongyu, could you please check with bisect if it is possible to point to a specific commit?

Signature · 1 line
 Kiryl Shutsemau / Kirill A. Shutemov
#4 lore raw
In reply to Kirill A. Shutemov
Quoted 9 lines · Kirill A. Shutemov

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.

virtio is not doing a lot of 16 bit reads.
Are these the reads:

                virtio_cread(vdev, struct virtio_console_config, cols, &cols);
                virtio_cread(vdev, struct virtio_console_config, rows, &rows);

?

write is a bit puzzling too. This one?

bool vp_notify(struct virtqueue *vq)

{       
        /* we write the queue's selector into the notification register to
         * signal the other end */
        iowrite16(vq->index, (void __iomem *)vq->priv);
        return true;
}
Quoted 3 lines

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

You mention both MMIO and pci, I am confused. Removed by what? In what sense?

Quoted 6 lines

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

A bit worried about doing so much activity on shutdown, and for all devices, too. I'd like to understand what is going on a bit better - could be a symptom of a bigger problem (e.g. missing handling for suprise removal?).

Quoted 34 lines
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +10 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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)
Signature · 1 line
2.43.0
#5 lore raw
Quoted 21 lines · Michael S. Tsirkin
Quoted 9 lines · Kirill A. Shutemov

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.

virtio is not doing a lot of 16 bit reads.
Are these the reads:

                virtio_cread(vdev, struct virtio_console_config, cols, &cols);
                virtio_cread(vdev, struct virtio_console_config, rows, &rows);

?

write is a bit puzzling too. This one?

Quoted 7 lines

bool vp_notify(struct virtqueue *vq)

{       
        /* we write the queue's selector into the notification register to
         * signal the other end */
        iowrite16(vq->index, (void __iomem *)vq->priv);
        return true;
}

Given that we are talking about console issue, any suggestion on how to check?

Quoted 5 lines
Quoted 3 lines

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

You mention both MMIO and pci, I am confused.

By MMIO, I mean accesses to PCI BARs. But it is only my *guess* on the situation, I have limited knowledge of the area. I am not drivers guy.

Quoted 1 line

Removed by what? In what sense?

So device_shutdown() iterates over all device and we hit the problem when we get to virtio-pci devices and call pci_device_shutdown on them.

I *think* PCI BAR (or something else?) becomes unavailable after that but it is still accessed.

Quoted 4 lines
Quoted 4 lines

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

Quoted 8 lines
Quoted 2 lines

A bit worried about doing so much activity on shutdown, and for all devices, too. I'd like to understand what is going on a bit better - could be a symptom of a bigger problem (e.g. missing handling for suprise removal?).

I probably should have marked the patch as RFC. The patch was intended to start conversation. I am not sure it is correct. This patch just happened to work in our setup.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#6 lore raw
Quoted 30 lines · Kirill A. Shutemov
Quoted 21 lines · Michael S. Tsirkin
Quoted 9 lines · Kirill A. Shutemov

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.

virtio is not doing a lot of 16 bit reads.
Are these the reads:

                virtio_cread(vdev, struct virtio_console_config, cols, &cols);
                virtio_cread(vdev, struct virtio_console_config, rows, &rows);

?

write is a bit puzzling too. This one?

Quoted 7 lines

bool vp_notify(struct virtqueue *vq)

{       
        /* we write the queue's selector into the notification register to
         * signal the other end */
        iowrite16(vq->index, (void __iomem *)vq->priv);
        return true;
}
Quoted 2 lines

Given that we are talking about console issue, any suggestion on how to check?

If you do lspci -v on the device, we'll know where the BARs are, and can compare to 0x102877002, 0x102877A44.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

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

You mention both MMIO and pci, I am confused.

Quoted 7 lines

By MMIO, I mean accesses to PCI BARs. But it is only my *guess* on the situation, I have limited knowledge of the area. I am not drivers guy.

Quoted 1 line

Removed by what? In what sense?

So device_shutdown() iterates over all device and we hit the problem when we get to virtio-pci devices and call pci_device_shutdown on them.

Hmm that clears bus master. So maybe what we see is actually device trying to do DMA and failing? We'll need to know where do these addresses are on your system.

Quoted 22 lines

I *think* PCI BAR (or something else?) becomes unavailable after that but it is still accessed.

Quoted 4 lines
Quoted 4 lines

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

Quoted 8 lines
Quoted 2 lines

A bit worried about doing so much activity on shutdown, and for all devices, too. I'd like to understand what is going on a bit better - could be a symptom of a bigger problem (e.g. missing handling for suprise removal?).

I probably should have marked the patch as RFC. The patch was intended to start conversation. I am not sure it is correct. This patch just happened to work in our setup.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#7 lore raw
Quoted 31 lines · Michael S. Tsirkin
Quoted 30 lines · Kirill A. Shutemov
Quoted 28 lines · Michael S. Tsirkin
Quoted 9 lines · Kirill A. Shutemov

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.

virtio is not doing a lot of 16 bit reads.
Are these the reads:

                virtio_cread(vdev, struct virtio_console_config, cols, &cols);
                virtio_cread(vdev, struct virtio_console_config, rows, &rows);

?

write is a bit puzzling too. This one?

bool vp_notify(struct virtqueue *vq)

{       
        /* we write the queue's selector into the notification register to
         * signal the other end */
        iowrite16(vq->index, (void __iomem *)vq->priv);
        return true;
}
Quoted 6 lines
Quoted 2 lines

Given that we are talking about console issue, any suggestion on how to check?

If you do lspci -v on the device, we'll know where the BARs are, and can compare to 0x102877002, 0x102877A44.

00:01.0 Ethernet controller: Red Hat, Inc. Virtio 1.0 network device (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 21
Memory at 80005000 (32-bit, non-prefetchable) [size=4K] Memory at 380000000000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=4 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci

00:02.0 Communication controller: Red Hat, Inc. Virtio 1.0 socket (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 22 Memory at 80004000 (32-bit, non-prefetchable) [size=4K] Memory at 380000004000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable- Count=3 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci

00:03.0 Communication controller: Red Hat, Inc. Virtio 1.0 console (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 23 Memory at 80003000 (32-bit, non-prefetchable) [size=4K] Memory at 380000008000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=2 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci

00:04.0 SCSI storage controller: Red Hat, Inc. Virtio 1.0 block device (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 20
Memory at 80002000 (32-bit, non-prefetchable) [size=4K] Memory at 38000000c000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=17 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci

00:05.0 SCSI storage controller: Red Hat, Inc. Virtio 1.0 block device (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 21
Memory at 80001000 (32-bit, non-prefetchable) [size=4K] Memory at 380000010000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=17 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci
....
Invalid read at addr 0x100C37904, size 2, region '(null)', reason: rejected Invalid read at addr 0x1036F9002, size 2, region '(null)', reason: rejected Invalid read at addr 0x1036F9002, size 2, region '(null)', reason: rejected Invalid write at addr 0x1036F9A44, size 2, region '(null)', reason: rejected Invalid read at addr 0x1036F7002, size 2, region '(null)', reason: rejected Invalid read at addr 0x1036F7002, size 2, region '(null)', reason: rejected Invalid write at addr 0x1036F7A44, size 2, region '(null)', reason: rejected
....

Yeah, looks like it is not BARs.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#8 lore raw
Quoted 113 lines · Kirill A. Shutemov
Quoted 31 lines · Michael S. Tsirkin
Quoted 30 lines · Kirill A. Shutemov
Quoted 28 lines · Michael S. Tsirkin
Quoted 9 lines · Kirill A. Shutemov

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.

virtio is not doing a lot of 16 bit reads.
Are these the reads:

                virtio_cread(vdev, struct virtio_console_config, cols, &cols);
                virtio_cread(vdev, struct virtio_console_config, rows, &rows);

?

write is a bit puzzling too. This one?

bool vp_notify(struct virtqueue *vq)

{       
        /* we write the queue's selector into the notification register to
         * signal the other end */
        iowrite16(vq->index, (void __iomem *)vq->priv);
        return true;
}
Quoted 6 lines
Quoted 2 lines

Given that we are talking about console issue, any suggestion on how to check?

If you do lspci -v on the device, we'll know where the BARs are, and can compare to 0x102877002, 0x102877A44.

00:01.0 Ethernet controller: Red Hat, Inc. Virtio 1.0 network device (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 21
Memory at 80005000 (32-bit, non-prefetchable) [size=4K] Memory at 380000000000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=4 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci

00:02.0 Communication controller: Red Hat, Inc. Virtio 1.0 socket (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 22 Memory at 80004000 (32-bit, non-prefetchable) [size=4K] Memory at 380000004000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable- Count=3 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci

00:03.0 Communication controller: Red Hat, Inc. Virtio 1.0 console (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 23 Memory at 80003000 (32-bit, non-prefetchable) [size=4K] Memory at 380000008000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=2 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci

00:04.0 SCSI storage controller: Red Hat, Inc. Virtio 1.0 block device (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 20
Memory at 80002000 (32-bit, non-prefetchable) [size=4K] Memory at 38000000c000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=17 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci

00:05.0 SCSI storage controller: Red Hat, Inc. Virtio 1.0 block device (rev 01)
Subsystem: Red Hat, Inc. Device 1100
Flags: bus master, fast devsel, latency 0, IRQ 21
Memory at 80001000 (32-bit, non-prefetchable) [size=4K] Memory at 380000010000 (64-bit, prefetchable) [size=16K]
Capabilities: [98] MSI-X: Enable+ Count=17 Masked-
Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
Capabilities: [70] Vendor Specific Information: VirtIO: Notify
Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
Capabilities: [50] Vendor Specific Information: VirtIO: ISR
Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg Kernel driver in use: virtio-pci
....
Invalid read at addr 0x100C37904, size 2, region '(null)', reason: rejected Invalid read at addr 0x1036F9002, size 2, region '(null)', reason: rejected Invalid read at addr 0x1036F9002, size 2, region '(null)', reason: rejected Invalid write at addr 0x1036F9A44, size 2, region '(null)', reason: rejected Invalid read at addr 0x1036F7002, size 2, region '(null)', reason: rejected Invalid read at addr 0x1036F7002, size 2, region '(null)', reason: rejected Invalid write at addr 0x1036F7A44, size 2, region '(null)', reason: rejected
....

Quoted 1 line

Yeah, looks like it is not BARs.

Michael, can we get back to this?

So it looks like to be a DMA.

It is a TDX guest. Some TDX context: it has concept of private and shared memory. Private memory in only accessible to the guest. Shared memory is accessible by both host and guest. It is used for guest/host communication including DMA.

By default all memory is private and guest kernel converts some memory to shared. On kexec, we convert all memory back to private, so the next kernel can start from a known state. This conversion makes DMA impossible.

I think stopping devices before doing this conversion is a reasonable solution.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
Reviewed-by Tested-by on v1 1/1
#9 lore raw
In reply to Kirill A. Shutemov

Hi Kirill, Michael

Quoted 10 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/[email protected]/)

Thanks

Eric

Quoted 32 lines
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +10 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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)
#10 lore raw
Quoted 42 lines · Eric Auger

Hi Kirill, Michael

Quoted 10 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/[email protected]/)

Quoted 7 lines

Thanks

Eric

OK I'll re-review. Thanks!

Quoted 32 lines
Quoted 32 lines
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +10 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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)
#11 lore raw
In reply to Eric Auger
Quoted 61 lines · Eric Auger

Hi Kirill, Michael

Quoted 10 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/[email protected]/)

Thanks

Eric

Quoted 12 lines
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +0 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -356,6 +356,15 @@ static void virtio_dev_remove(struct device *_d)
 	of_node_put(dev->dev.of_node);
 }
 
Quoted 7 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 365

Quoted 7 lines
drivers/virtio/virtio.c +7 -0
+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);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

Quoted 13 lines
Quoted 13 lines
drivers/virtio/virtio.c +3 -0
+}
+
 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)
#12 lore raw

Hi,

Quoted 62 lines · Michael S. Tsirkin
Quoted 61 lines · Eric Auger

Hi Kirill, Michael

Quoted 10 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/[email protected]/)

Thanks

Eric

Quoted 12 lines
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +0 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -356,6 +356,15 @@ static void virtio_dev_remove(struct device *_d)
 	of_node_put(dev->dev.of_node);
 }
 
Quoted 12 lines
Quoted 7 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 365

Quoted 7 lines
drivers/virtio/virtio.c +7 -0
+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);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d)

{
        struct virtio_device *dev = dev_to_virtio(_d);

        virtio_reset_device(dev);
}

and it fixes my issue.

Kirill, would that fix you issue too?

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
 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)
#13 lore raw

Hi,

Quoted 88 lines · Eric Auger

Hi,

Quoted 62 lines · Michael S. Tsirkin
Quoted 61 lines · Eric Auger

Hi Kirill, Michael

Quoted 10 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/[email protected]/)

Thanks

Eric

Quoted 12 lines
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +0 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -356,6 +356,15 @@ static void virtio_dev_remove(struct device *_d)
 	of_node_put(dev->dev.of_node);
 }
 
Quoted 12 lines
Quoted 7 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 365

Quoted 7 lines
drivers/virtio/virtio.c +7 -0
+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);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d)

{
        struct virtio_device *dev = dev_to_virtio(_d);

        virtio_reset_device(dev);
}
Quoted 3 lines

and it fixes my issue.

Kirill, would that fix you issue too?

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
 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)
#14 lore raw
Quoted 87 lines · Eric Auger

Hi,

Quoted 84 lines · Eric Auger

Hi,

Quoted 62 lines · Michael S. Tsirkin
Quoted 61 lines · Eric Auger

Hi Kirill, Michael

Quoted 10 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/[email protected]/)

Thanks

Eric

Quoted 12 lines
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +0 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -356,6 +356,15 @@ static void virtio_dev_remove(struct device *_d)
 	of_node_put(dev->dev.of_node);
 }
 
Quoted 12 lines
Quoted 7 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 365

Quoted 7 lines
drivers/virtio/virtio.c +7 -0
+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);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d)

{
        struct virtio_device *dev = dev_to_virtio(_d);
Quoted 8 lines
Quoted 7 lines
        virtio_reset_device(dev);
}

and it fixes my issue.

Kirill, would that fix you issue too?

gentle ping.

I am on vacation this week. Will try to get around to it next week.

Signature · 1 line
  Kiryl Shutsemau / Kirill A. Shutemov
#15 lore raw
Quoted 92 lines · Kirill A. Shutemov
Quoted 91 lines · Eric Auger

Hi,

Quoted 88 lines · Eric Auger

Hi,

Quoted 62 lines · Michael S. Tsirkin
Quoted 61 lines · Eric Auger

Hi Kirill, Michael

Quoted 10 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/[email protected]/)

Thanks

Eric

Quoted 12 lines
---
 drivers/virtio/virtio.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +0 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -356,6 +356,15 @@ static void virtio_dev_remove(struct device *_d)
 	of_node_put(dev->dev.of_node);
 }
 
Quoted 12 lines
Quoted 7 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 365

Quoted 7 lines
drivers/virtio/virtio.c +7 -0
+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);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d)

{
        struct virtio_device *dev = dev_to_virtio(_d);

        virtio_reset_device(dev);
}
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

and it fixes my issue.

Kirill, would that fix you issue too?

gentle ping.

I am on vacation this week. Will try to get around to it next week.

OK. Enjoy your vacation!

Eric

Quoted 1 line
#16 lore raw
In reply to Eric Auger
Quoted 94 lines · Eric Auger

Hi,

Quoted 91 lines · Eric Auger

Hi,

Quoted 62 lines · Michael S. Tsirkin
Quoted 61 lines · Eric Auger

Hi Kirill, Michael

Quoted 10 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/[email protected]/)

Thanks

Eric

Quoted 12 lines
---
  drivers/virtio/virtio.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +0 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -356,6 +356,15 @@ static void virtio_dev_remove(struct device *_d)
  	of_node_put(dev->dev.of_node);
  }
 
Quoted 12 lines
Quoted 7 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 365

Quoted 7 lines
drivers/virtio/virtio.c +7 -0
+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);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d)

{
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
 drivers/virtio/virtio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +8 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask *virtio_irq_get_affinity(struct device *_d,
        return dev->config->get_vq_affinity(dev, irq_vec);
 }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
 static const struct bus_type virtio_bus = {
        .name  = "virtio",
        .match = virtio_dev_match,
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
        .probe = virtio_dev_probe,
        .remove = virtio_dev_remove,
        .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
 };
 
 int __register_virtio_driver(struct virtio_driver *driver, struct 

module *owner)
--
2.43.0

Quoted 38 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
  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)
#17 lore raw

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines

---
  drivers/virtio/virtio.c | 10 ++++++++++

  1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d) {
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Thanks

Eric

Quoted 81 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
 drivers/virtio/virtio.c | 8 ++++++++

 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

        .match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 

 int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)

Signature · 1 line
2.43.0
Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
   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)
#18 lore raw
Quoted 113 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines

---
  drivers/virtio/virtio.c | 10 ++++++++++

  1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d) {
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Quoted 7 lines

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Thanks

Eric

Ah, wait a second.

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

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

	/*
	 * 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);
        /*
         * The below virtio_synchronize_cbs() guarantees that any
         * interrupt for this line arriving after
         * virtio_synchronize_vqs() has completed is guaranteed to see
         * vq->broken as true.
         */
        virtio_synchronize_cbs(dev);
        dev->config->reset(dev);

I assume this still works for you, yes?

Quoted 81 lines
Quoted 81 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
 drivers/virtio/virtio.c | 8 ++++++++

 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

        .match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 

 int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)

Signature · 1 line
2.43.0
Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
   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)
#19 lore raw
Quoted 119 lines · Michael S. Tsirkin
Quoted 117 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines
---
  drivers/virtio/virtio.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d)

{
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Quoted 8 lines
Quoted 3 lines

Thanks

Eric

Ah, wait a second.

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

Where is such code? I think the virtcons_remove() is called so the console is unregistered from the subsystem.

Or for surprise removal, we have break the device in:

static void virtio_pci_remove(struct pci_dev *pci_dev)

{
        struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
        struct device *dev = get_device(&vp_dev->vdev.dev);

        /*
         * Device is marked broken on surprise removal so that virtio upper
         * layers can abort any ongoing operation.
         */
        if (!pci_device_is_present(pci_dev))
                virtio_break_device(&vp_dev->vdev);
Quoted 8 lines

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

Quoted 12 lines

/*
* 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);
/*
* The below virtio_synchronize_cbs() guarantees that any
* interrupt for this line arriving after
* virtio_synchronize_vqs() has completed is guaranteed to see
* vq->broken as true.
*/
virtio_synchronize_cbs(dev);

This seems to relate to doing this when we reintroduce the notification hardening.

Quoted 5 lines
        dev->config->reset(dev);

I assume this still works for you, yes?

Thanks

Quoted 84 lines
Quoted 83 lines
Quoted 83 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
 drivers/virtio/virtio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
        return dev->config->get_vq_affinity(dev, irq_vec);
 }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
 static const struct bus_type virtio_bus = {
        .name  = "virtio",

.match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
        .probe = virtio_dev_probe,
        .remove = virtio_dev_remove,
        .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
 };
 
 int __register_virtio_driver(struct virtio_driver *driver, struct

module *owner)
--
2.43.0

Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
  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)
#20 lore raw
Quoted 168 lines · Jason Wang
Quoted 119 lines · Michael S. Tsirkin
Quoted 117 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines
---
   drivers/virtio/virtio.c | 10 ++++++++++
   1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d)

{
          struct virtio_device *dev = dev_to_virtio(_d);

          virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Quoted 8 lines
Quoted 3 lines

Thanks

Eric

Ah, wait a second.

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

Where is such code? I think the virtcons_remove() is called so the console is unregistered from the subsystem.

Or for surprise removal, we have break the device in:

static void virtio_pci_remove(struct pci_dev *pci_dev)

{
         struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
         struct device *dev = get_device(&vp_dev->vdev.dev);

         /*
          * Device is marked broken on surprise removal so that virtio upper
          * layers can abort any ongoing operation.
          */
         if (!pci_device_is_present(pci_dev))
                 virtio_break_device(&vp_dev->vdev);
Quoted 8 lines

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

Quoted 12 lines

/*
* 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);
/*
* The below virtio_synchronize_cbs() guarantees that any
* interrupt for this line arriving after
* virtio_synchronize_vqs() has completed is guaranteed to see
* vq->broken as true.
*/
virtio_synchronize_cbs(dev);

Quoted 5 lines

This seems to relate to doing this when we reintroduce the notification hardening.

Quoted 2 lines
         dev->config->reset(dev);

quick update on above patch from Michael, it could fix the original issue in my test setup of vm kexec kernel switching, which is triggered with console=hvc0 cmdline.

Quoted 92 lines
Quoted 3 lines

I assume this still works for you, yes?

Thanks

Quoted 84 lines
Quoted 83 lines
Quoted 83 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
  drivers/virtio/virtio.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

.match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 
  int __register_virtio_driver(struct virtio_driver *driver, struct

module *owner)
--
2.43.0

Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
   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)
#21 lore raw
In reply to Michael S. Tsirkin

Hi Michael, Hongyu,

Quoted 149 lines · Michael S. Tsirkin
Quoted 113 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines

---
  drivers/virtio/virtio.c | 10 ++++++++++

  1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d) {
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Quoted 7 lines

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Thanks

Eric

Ah, wait a second.

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

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

	/*
	 * 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);
        /*
         * The below virtio_synchronize_cbs() guarantees that any
         * interrupt for this line arriving after
         * virtio_synchronize_vqs() has completed is guaranteed to see
         * vq->broken as true.
         */
        virtio_synchronize_cbs(dev);
        dev->config->reset(dev);
Quoted 1 line

I assume this still works for you, yes?

Would that still been done in the virtio_dev_shutdown()?

Is that what you tested Hongyu?

Eric

Quoted 85 lines
Quoted 84 lines
Quoted 84 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
 drivers/virtio/virtio.c | 8 ++++++++

 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

        .match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 

 int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)

Signature · 1 line
2.43.0
Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
   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)
#22 lore raw

Hi Michael,

Quoted 150 lines · Eric Auger

Hi Michael, Hongyu,

Quoted 147 lines · Michael S. Tsirkin
Quoted 113 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines

---
  drivers/virtio/virtio.c | 10 ++++++++++

  1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d) {
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Quoted 7 lines

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Thanks

Eric

Ah, wait a second.

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

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

	/*
	 * 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);
        /*
         * The below virtio_synchronize_cbs() guarantees that any
         * interrupt for this line arriving after
         * virtio_synchronize_vqs() has completed is guaranteed to see
         * vq->broken as true.
         */
        virtio_synchronize_cbs(dev);
        dev->config->reset(dev);

I have tested that code as an implentation of the virtio shutdown callback and yes it also fixes the viommu/vhost issue.

Michael, will you send a patch then?

Thanks

Eric

Quoted 94 lines
Quoted 3 lines

I assume this still works for you, yes?

Would that still been done in the virtio_dev_shutdown()?

Is that what you tested Hongyu?

Eric

Quoted 85 lines
Quoted 84 lines
Quoted 84 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
 drivers/virtio/virtio.c | 8 ++++++++

 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

        .match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 

 int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)

Signature · 1 line
2.43.0
Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
   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)
#23 lore raw
Quoted 153 lines · Eric Auger

Hi Michael,

Quoted 150 lines · Eric Auger

Hi Michael, Hongyu,

Quoted 147 lines · Michael S. Tsirkin
Quoted 113 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines

---
  drivers/virtio/virtio.c | 10 ++++++++++

  1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d) {
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Quoted 7 lines

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Thanks

Eric

Ah, wait a second.

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

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

	/*
	 * 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);
        /*
         * The below virtio_synchronize_cbs() guarantees that any
         * interrupt for this line arriving after
         * virtio_synchronize_vqs() has completed is guaranteed to see
         * vq->broken as true.
         */
        virtio_synchronize_cbs(dev);
        dev->config->reset(dev);
Quoted 8 lines

I have tested that code as an implentation of the virtio shutdown callback and yes it also fixes the viommu/vhost issue.

Michael, will you send a patch then?

Thanks

Eric

Was hoping for a confirmation from Ning.

Quoted 94 lines
Quoted 94 lines
Quoted 3 lines

I assume this still works for you, yes?

Would that still been done in the virtio_dev_shutdown()?

Is that what you tested Hongyu?

Eric

Quoted 85 lines
Quoted 84 lines
Quoted 84 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
 drivers/virtio/virtio.c | 8 ++++++++

 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

        .match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 

 int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)

Signature · 1 line
2.43.0
Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
   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)
#24 lore raw
In reply to Eric Auger
Quoted 152 lines · Eric Auger

Hi Michael, Hongyu,

Quoted 149 lines · Michael S. Tsirkin
Quoted 113 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines
---
   drivers/virtio/virtio.c | 10 ++++++++++
   1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d) {
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Quoted 7 lines

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Thanks

Eric

Ah, wait a second.

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

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

	/*
	 * 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);
         /*
          * The below virtio_synchronize_cbs() guarantees that any
          * interrupt for this line arriving after
          * virtio_synchronize_vqs() has completed is guaranteed to see
          * vq->broken as true.
          */
         virtio_synchronize_cbs(dev);
         dev->config->reset(dev);
Quoted 4 lines
Quoted 1 line

I assume this still works for you, yes?

Would that still been done in the virtio_dev_shutdown()?

Is that what you tested Hongyu?

Hi Eric,

my patch applied based on Michael's comments:

---
 drivers/virtio/virtio.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/virtio/virtio.c +20 -0
index ba37665188b5..458dc28be060 100644
@@ -395,6 +395,25 @@ static const struct cpumask *virtio_irq_get_affinity(struct device *_d,
        return dev->config->get_vq_affinity(dev, irq_vec);
 }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+        /*
+         * 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);
+        /*
+         * The below virtio_synchronize_cbs() guarantees that any
+         * interrupt for this line arriving after
+         * virtio_synchronize_vqs() has completed is guaranteed to see
+         * vq->broken as true.
+         */
+        virtio_synchronize_cbs(dev);
+        dev->config->reset(dev);
+       //virtio_reset_device(dev);
+}
+
 static const struct bus_type virtio_bus = {
        .name  = "virtio",
        .match = virtio_dev_match,
@@ -403,6 +422,7 @@ static const struct bus_type virtio_bus = {
        .probe = virtio_dev_probe,
        .remove = virtio_dev_remove,
        .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
 };
 
 int __register_virtio_driver(struct virtio_driver *driver, struct 

module *owner)
--
2.43.0

Quoted 89 lines

Eric

Quoted 85 lines
Quoted 84 lines
Quoted 84 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
  drivers/virtio/virtio.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

        .match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 
  int __register_virtio_driver(struct virtio_driver *driver, struct

module *owner)

Signature · 1 line
2.43.0
Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
   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)
#25 lore raw
Quoted 207 lines · Hongyu
Quoted 152 lines · Eric Auger

Hi Michael, Hongyu,

Quoted 149 lines · Michael S. Tsirkin
Quoted 113 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines
---
   drivers/virtio/virtio.c | 10 ++++++++++
   1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d) {
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Quoted 7 lines

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Thanks

Eric

Ah, wait a second.

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

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

	/*
	 * 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);
         /*
          * The below virtio_synchronize_cbs() guarantees that any
          * interrupt for this line arriving after
          * virtio_synchronize_vqs() has completed is guaranteed to see
          * vq->broken as true.
          */
         virtio_synchronize_cbs(dev);
         dev->config->reset(dev);
Quoted 4 lines
Quoted 1 line

I assume this still works for you, yes?

Would that still been done in the virtio_dev_shutdown()?

Is that what you tested Hongyu?

Hi Eric,

my patch applied based on Michael's comments:

---
 drivers/virtio/virtio.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/virtio/virtio.c +19 -0
index ba37665188b5..458dc28be060 100644
@@ -395,6 +395,25 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
        return dev->config->get_vq_affinity(dev, irq_vec);
 }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+        /*
+         * 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);
+        /*
+         * The below virtio_synchronize_cbs() guarantees that any
+         * interrupt for this line arriving after
+         * virtio_synchronize_vqs() has completed is guaranteed to see
+         * vq->broken as true.
+         */
+        virtio_synchronize_cbs(dev);
+        dev->config->reset(dev);
+       //virtio_reset_device(dev);
+}
+
 static const struct bus_type virtio_bus = {
        .name  = "virtio",

.match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +422,7 @@ static const struct bus_type virtio_bus = {
        .probe = virtio_dev_probe,
        .remove = virtio_dev_remove,
        .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
 };
 
 int __register_virtio_driver(struct virtio_driver *driver, struct module
Quoted 3 lines

*owner)
--
2.43.0

yes, that's the patch. Does it work for you? Addresses the problem? If yes I'll repost.

Quoted 90 lines
Quoted 90 lines

Eric

Quoted 85 lines
Quoted 84 lines
Quoted 84 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
  drivers/virtio/virtio.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

        .match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 
  int __register_virtio_driver(struct virtio_driver *driver, struct

module *owner)

Signature · 1 line
2.43.0
Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
   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)
#26 lore raw
Quoted 207 lines · Michael S. Tsirkin
Quoted 206 lines · Hongyu
Quoted 152 lines · Eric Auger

Hi Michael, Hongyu,

Quoted 149 lines · Michael S. Tsirkin
Quoted 113 lines · Eric Auger

Hi,

Quoted 99 lines · Hongyu
Quoted 96 lines · Eric Auger

Hi,

Quoted 93 lines · Eric Auger

Hi,

Quoted 69 lines · Michael S. Tsirkin
Quoted 68 lines · Eric Auger

Hi Kirill, Michael

Quoted 13 lines · Kirill A. Shutemov

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.

Quoted 8 lines

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.

Gentle ping on that patch that seems to have fallen though the cracks.

I think this fix is really needed. I have another test case with a rebooting guest exposed with virtio-net (backed by vhost-net) and viommu. Since there is currently no shutdown for the virtio-net, on reboot, the IOMMU is disabled through the native_machine_shutdown()/ x86_platform.iommu_shutdown() while the virtio-net is still alive.

Normally device_shutdown() should call virtio-net shutdown before the IOMMU tear down and we wouldn't see any spurious transactions after iommu shutdown.

With that fix, the above test case is fixed and I do not see spurious vhost IOTLB miss spurious requests.

For more details, see qemu thread ([PATCH] hw/virtio/vhost: Disable IOTLB callbacks when IOMMU gets disabled,
https://lore.kernel.org/all/20250120173339.865681-1-
[email protected]/)

Thanks

Eric

Quoted 15 lines
---
    drivers/virtio/virtio.c | 10 ++++++++++
    1 file changed, 10 insertions(+)
drivers/virtio/virtio.c +3 -0
index a9b93e99c23a..6c2f908eb22c 100644
@@ -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);
Quoted 8 lines
Quoted 3 lines

drivers/virtio/virtio.c static void virtio_dev_remove(struct device *_d) · line 364

Quoted 3 lines
drivers/virtio/virtio.c +3 -0
+
+    if (drv && drv->remove)
+        drv->remove(dev);

I am concerned that full remove is a heavyweight operation. Do not want to slow down reboots even more.
How about just doing a reset, instead?

I tested with

static void virtio_dev_shutdown(struct device *_d) {
         struct virtio_device *dev = dev_to_virtio(_d);

         virtio_reset_device(dev);
}

and it fixes my issue.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Kirill, would that fix you issue too?

Hi,

sorry for my late response, I synced with Kirill offline and did a retest.

The issue is still reproduced on my side, kexec will be stuck in case of "console=hvc0" append in kernel cmdline and even with such patch applied.

Thanks for testing!

Quoted 7 lines

Michael, it looks like the initial patch from Kyrill is the one that fixes both issues. virtio_reset_device() usage does not work for the initial bug report while it works for me. Other ideas?

Thanks

Eric

Ah, wait a second.

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

Hmm. I am not sure why that is a problem, but I assume some hypervisors just hang the system if you try to kick them after reset.
Unfortunate that spec did not disallow it.

If we want to prevent that, we want to do something like this:

	/*
	 * 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);
          /*
           * The below virtio_synchronize_cbs() guarantees that any
           * interrupt for this line arriving after
           * virtio_synchronize_vqs() has completed is guaranteed to see
           * vq->broken as true.
           */
          virtio_synchronize_cbs(dev);
          dev->config->reset(dev);
Quoted 4 lines
Quoted 1 line

I assume this still works for you, yes?

Would that still been done in the virtio_dev_shutdown()?

Is that what you tested Hongyu?

Hi Eric,

my patch applied based on Michael's comments:

---
  drivers/virtio/virtio.c | 20 ++++++++++++++++++++
  1 file changed, 20 insertions(+)
drivers/virtio/virtio.c +19 -0
index ba37665188b5..458dc28be060 100644
@@ -395,6 +395,25 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
         return dev->config->get_vq_affinity(dev, irq_vec);
  }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+        /*
+         * 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);
+        /*
+         * The below virtio_synchronize_cbs() guarantees that any
+         * interrupt for this line arriving after
+         * virtio_synchronize_vqs() has completed is guaranteed to see
+         * vq->broken as true.
+         */
+        virtio_synchronize_cbs(dev);
+        dev->config->reset(dev);
+       //virtio_reset_device(dev);
+}
+
  static const struct bus_type virtio_bus = {
         .name  = "virtio",

.match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +422,7 @@ static const struct bus_type virtio_bus = {
         .probe = virtio_dev_probe,
         .remove = virtio_dev_remove,
         .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
  };
 
Quoted 10 lines
Quoted 4 lines
drivers/virtio/virtio.c +0 -0
  int __register_virtio_driver(struct virtio_driver *driver, struct module

*owner)
--
2.43.0

yes, that's the patch. Does it work for you? Addresses the problem? If yes I'll repost.

yes, issue fixed on my side. Thanks.

Quoted 92 lines
Quoted 90 lines
Quoted 90 lines

Eric

Quoted 85 lines
Quoted 84 lines
Quoted 84 lines

my kernel code base is 6.14.0-rc2.

let me know if any more experiments needed.

---
   drivers/virtio/virtio.c | 8 ++++++++
   1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +7 -0
index ba37665188b5..f9f885d04763 100644
@@ -395,6 +395,13 @@ static const struct cpumask
 *virtio_irq_get_affinity(struct device *_d,
          return dev->config->get_vq_affinity(dev, irq_vec);
   }
 
+static void virtio_dev_shutdown(struct device *_d)
+{
+        struct virtio_device *dev = dev_to_virtio(_d);
+
+        virtio_reset_device(dev);
+}
+
   static const struct bus_type virtio_bus = {
          .name  = "virtio",

        .match = virtio_dev_match,

drivers/virtio/virtio.c +1 -0
@@ -403,6 +410,7 @@ static const struct bus_type virtio_bus = {
          .probe = virtio_dev_probe,
          .remove = virtio_dev_remove,
          .irq_get_affinity = virtio_irq_get_affinity,
+       .shutdown = virtio_dev_shutdown,
   };
 
   int __register_virtio_driver(struct virtio_driver *driver, struct

module *owner)

Signature · 1 line
2.43.0
Quoted 39 lines

gentle ping.

this also fixes another issue with qemu vSMMU + virtio-scsi-pci. With the above addition I get rid of spurious warning in qemu on guest reboot.

qemu-system-aarch64: virtio: zero sized buffers are not allowed
qemu-system-aarch64: vhost vring error in virtqueue 0: Invalid argument (22)

Would you mind if I respin?

Thanks

Eric

Quoted 20 lines

Thanks

Eric

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/virtio/virtio.c +3 -0
+}
+
    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)