On Tue, Mar 07, 2017 at 04:02:09PM +0800, Jason Wang wrote:
On 2017年03月06日 15:22, Jason Wang wrote:
After commit 96a8821d2141 ("virtio: unbreak virtio-pci with IOMMU
after caching ring translations"), IOMMU was required to be created in
advance. This is because we can only get the correct dma_as after pci
IOMMU (e.g intel_iommu) was initialized. This is suboptimal and
inconvenient for user. This patch releases this by:
- introduce a bus_master_ready method for PCIDeviceClass and trigger
this during pci_init_bus_master
- implement virtio-pci method and 1) reset the dma_as 2) re-register
the memory listener to the new dma_as
Cc: Paolo Bonzini<address@hidden>
Signed-off-by: Jason Wang<address@hidden>
This patch breaks hotplug by calling reset_dma_as() when virtio is not
initialized. Will post V2 to call bus_master_ready() only at
pcibus_machine_done().
A tiny issue with above fix would be: bus_master_ready() will not be
called when do device hot-plug. If we want that interface to be a
general one for the whole PCI framework, then imho we'd better call it
as well for hot-plug devices. So instead, do you like below fix?
--------8<--------
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index a563555..f71ad54 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -995,9 +995,6 @@ static PCIDevice
*do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
pci_dev->devfn = devfn;
pci_dev->requester_id_cache = pci_req_id_cache_get(pci_dev);
- if (qdev_hotplug) {
- pci_init_bus_master(pci_dev);
- }
pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
pci_dev->irq_state = 0;
pci_config_alloc(pci_dev);
@@ -1967,6 +1964,10 @@ static void pci_qdev_realize(DeviceState
*qdev, Error **errp)
}
}
+ if (qdev_hotplug) {
+ pci_init_bus_master(pci_dev);
+ }
+
/* rom loading */
is_default_rom = false;
if (pci_dev->romfile == NULL && pc->romfile != NULL) {
-------->8--------
Thanks,
-- peterx