virtio: Remove virtio devices on device_shutdown()
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
@@ -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
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>
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@@ -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
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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
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
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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
Michael S. Tsirkin
maintainerQuoted 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>
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@@ -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
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
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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
Michael S. Tsirkin
maintainerQuoted 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 callpci_device_shutdownon 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
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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
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
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-pci00: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-pci00: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-pci00: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 at38000000c000(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-pci00: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 addr0x100C37904, size 2, region '(null)', reason: rejected Invalid read at addr0x1036F9002, size 2, region '(null)', reason: rejected Invalid read at addr0x1036F9002, size 2, region '(null)', reason: rejected Invalid write at addr0x1036F9A44, size 2, region '(null)', reason: rejected Invalid read at addr0x1036F7002, size 2, region '(null)', reason: rejected Invalid read at addr0x1036F7002, size 2, region '(null)', reason: rejected Invalid write at addr0x1036F7A44, 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
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>
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@@ -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)
Michael S. Tsirkin
maintainerQuoted 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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
Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>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@@ -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)
Michael S. Tsirkin
maintainerQuoted 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 12 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +0
-0@@ -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)
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 12 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +0
-0@@ -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)
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 12 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +0
-0@@ -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)
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 12 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +0
-0@@ -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
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 12 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +0
-0@@ -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
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 12 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +0
-0@@ -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
@@ -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)
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 addr0x102877A44, 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
---
drivers/virtio/virtio.c| 10 ++++++++++1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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){
structvirtio_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@@ -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.0Quoted 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)
Michael S. Tsirkin
maintainerQuoted 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 addr0x102877A44, 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
---
drivers/virtio/virtio.c| 10 ++++++++++1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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){
structvirtio_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@@ -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.0Quoted 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)
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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 belowvirtio_synchronize_cbs()guarantees that any
* interrupt for this line arriving after
*virtio_synchronize_vqs()has completed is guaranteed to see
*vq->brokenas 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@@ -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, structmodule *owner)
--
2.43.0Quoted 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)
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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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 belowvirtio_synchronize_cbs()guarantees that any
* interrupt for this line arriving after
*virtio_synchronize_vqs()has completed is guaranteed to see
*vq->brokenas 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@@ -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, structmodule *owner)
--
2.43.0Quoted 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)
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 addr0x102877A44, 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
---
drivers/virtio/virtio.c| 10 ++++++++++1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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){
structvirtio_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@@ -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.0Quoted 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)
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 addr0x102877A44, 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
---
drivers/virtio/virtio.c| 10 ++++++++++1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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){
structvirtio_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@@ -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.0Quoted 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)
Michael S. Tsirkin
maintainerQuoted 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 addr0x102877A44, 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
---
drivers/virtio/virtio.c| 10 ++++++++++1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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){
structvirtio_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@@ -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.0Quoted 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)
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 addr0x102877A44, 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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){
structvirtio_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
@@ -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@@ -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, structmodule *owner)
Signature · 1 line
2.43.0Quoted 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)
Michael S. Tsirkin
maintainerQuoted 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 addr0x102877A44, 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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){
structvirtio_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@@ -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@@ -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, structmodule *owner)
Signature · 1 line
2.43.0Quoted 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)
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 addr0x102877A44, 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.
Signed-off-by Kirill A. Shutemov <[email protected]>Reported-by Hongyu Ning <[email protected]>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]/)Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Thanks
Eric
Quoted 15 lines
--- drivers/virtio/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/virtio/virtio.c +3
-0@@ -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){
structvirtio_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@@ -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
-0int __register_virtio_driver(struct virtio_driver *driver, struct module*owner)
--
2.43.0yes, 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@@ -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, structmodule *owner)
Signature · 1 line
2.43.0Quoted 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)