virtio: unbreak virtio-pci with IOMMU after caching ring translations
PATCH 1/1 virtio: unbreak virtio-pci with IOMMU after caching ring translations
Commit c611c76417f5 ("virtio: add MemoryListener to cache ring translations") registers a memory listener to dma_as. This may not work when IOMMU is enabled: dma_as(bus_master_as) were initialized in pcibus_machine_done() after virtio_realize(). This will cause a segfault. Fixing this by using pci_device_iommu_address_space() instead to make sure address space were initialized at this time.
With this fix, IOMMU device were required to be initialized before any virtio-pci devices.
--- hw/virtio/virtio-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-pci.c +1 -1
@@ -1153,7 +1153,7 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d)VirtIOPCIProxy *proxy =VIRTIO_PCI (d);PCIDevice *dev = &proxy->pci_dev; -return pci_get_address_space (dev); +return pci_device_iommu_address_space (dev); } static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
Signature · 1 line
2.7.4
Quoted 7 lines · Jason Wang
Commit
c611c76417f5("virtio: add MemoryListener to cache ring translations") registers a memory listener todma_as. This may not work when IOMMU is enabled:dma_as(bus_master_as)were initialized inpcibus_machine_done()aftervirtio_realize(). This will cause a segfault. Fixing this by usingpci_device_iommu_address_space()instead to make sure address space were initialized at this time.
Quoted 6 lines
With this fix, IOMMU device were required to be initialized before any virtio-pci devices.
Fixes c611c76417f5 ("virtio: add MemoryListener to cache ring translations")Cc Paolo Bonzini <[email protected]>Signed-off-by Jason Wang <[email protected]>
This is very ugly. I guess it's better than broken IOMMU ... Paolo?
Quoted 19 lines
--- hw/virtio/virtio-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/virtio-pci.c +1
-1@@ -1153,7 +1153,7 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d)VirtIOPCIProxy *proxy =VIRTIO_PCI (d);PCIDevice *dev = &proxy->pci_dev; -return pci_get_address_space (dev); +return pci_device_iommu_address_space (dev); } static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,Signature · 1 line
2.7.4
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Jason Wang
Commit
c611c76417f5("virtio: add MemoryListener to cache ring translations") registers a memory listener todma_as. This may not work when IOMMU is enabled:dma_as(bus_master_as)were initialized inpcibus_machine_done()aftervirtio_realize(). This will cause a segfault. Fixing this by usingpci_device_iommu_address_space()instead to make sure address space were initialized at this time.
Quoted 8 lines
Quoted 6 lines
With this fix, IOMMU device were required to be initialized before any virtio-pci devices.
Fixes c611c76417f5 ("virtio: add MemoryListener to cache ring translations")Cc Paolo Bonzini <[email protected]>Signed-off-by Jason Wang <[email protected]>This is very ugly. I guess it's better than broken IOMMU ... Paolo?
Maybe we can delay the registering of memory listener on bus master enabling or status setting.
Thanks
Quoted 20 lines
Quoted 20 lines
--- hw/virtio/virtio-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/virtio/virtio-pci.c +1
-1@@ -1153,7 +1153,7 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState *d)VirtIOPCIProxy *proxy =VIRTIO_PCI (d);PCIDevice *dev = &proxy->pci_dev; -return pci_get_address_space (dev); +return pci_device_iommu_address_space (dev); } static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,Signature · 1 line
2.7.4
Quoted 10 lines · Jason Wang
Quoted 7 lines
Quoted 5 lines
Fixes c611c76417f5 ("virtio: add MemoryListener to cache ringtranslations")
Cc Paolo Bonzini <[email protected]>Signed-off-by Jason Wang <[email protected]>This is very ugly. I guess it's better than broken IOMMU ... Paolo?
Maybe we can delay the registering of memory listener on bus master enabling or status setting.
Can we add a callback to PCIDeviceClass, and invoke it from pci_init_bus_master?
Paolo
Quoted 6 lines · Paolo Bonzini
Quoted 4 lines · Jason Wang
Quoted 4 lines
Quoted 4 lines
Fixes c611c76417f5 ("virtio: add MemoryListener to cache ringtranslations")
Cc Paolo Bonzini <[email protected]>Signed-off-by Jason Wang <[email protected]>
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
This is very ugly. I guess it's better than broken IOMMU ... Paolo?
Maybe we can delay the registering of memory listener on bus master enabling or status setting.
Can we add a callback to PCIDeviceClass, and invoke it from
pci_init_bus_master?Paolo
This looks pci specific, I post a fix that reset the dma_as during status set which can solve this issue too. Please have a look.
Thanks