Skip to contentSkip to conversation

virtio: do not require IOMMU to be created in advance

PATCH Jason Wang 1 participant 1 message Mar 7, 2017 4 messages not in the archive

lore
Share & tools
lore

Jason Wang

author
#4 lore raw
In reply to a message not in the archive

miss the list, cced.

Quoted 62 lines · Jason Wang
Quoted 52 lines · Peter Xu
Quoted 13 lines · Jason Wang
Quoted 11 lines · Jason Wang

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

Quoted 5 lines
Quoted 2 lines
Cc Paolo Bonzini<[email protected]>

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<--------

hw/pci/pci.c +3 -3
index a563555..f71ad54 100644
@@ -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--------
Quoted 3 lines

Thanks,

-- peterx

I like this, will post V3.

Thanks