On Fri, Mar 02, 2018 at 04:12:01PM +0100, Paolo Bonzini wrote: > On 01/03/2018 11:33, Liu, Yi L wrote: > > This patch adds pci_device_notify_iommu() for notify virtual IOMMU > > emulator when assigned device is added. And adds a new notify_func > > in PCIBus. vIOMMU emulator provides the instance of this notify_func. > > > > Reason: > > When virtual IOMMU is exposed to guest, vIOMMU emulator needs to > > programm host IOMMU to setup DMA mapping for assigned devices. This > > is a per-device operation, to be efficient, vIOMMU emulator needs > > to record the assigned devices. > > > > Example: devices assigned thru vfio, vfio_realize would call > > pci_device_notify_iommu() to notify vIOMMU emulator to record necessary > > info for assigned device. > > I think the notification should not be left to the individual device. > Instead, the add notification should be done in pci_setup_sva_ops, and > the delete notification should be done in pci_qdev_unrealize, before > calling pc->exit, and only if dev->sva_ops is not NULL.
Agreed. I think it works together with your comments against "[PATCH v3 05/12] hw/pci: introduce PCISVAOps to PCIDevice". Would apply it in next version. > In general I think it's better to change your names from "assigned_dev" > to "sva_dev", because the point of the list is to only iterate over > devices that might be interested in using SVA. For "assigned_dev", my purpose is to distinguish "assigned devices" from emulated devices. Only the SVA usage on "assigned devices" is cared here. But it is true only SVA capable device is interested. So I may need to rename it as "assigned_sva_dev". How about your opinion? Thanks, Yi Liu