Hi Eric, > From: Auger Eric <eric.auger@xxxxxxxxxx> > Sent: Tuesday, March 31, 2020 10:30 PM > To: Liu, Yi L <yi.l.liu@xxxxxxxxx>; qemu-devel@xxxxxxxxxx; > Subject: Re: [PATCH v2 10/22] vfio/pci: set host iommu context to vIOMMU > > Yi, > > On 3/30/20 6:24 AM, Liu Yi L wrote: > > For vfio-pci devices, it could use pci_device_set/unset_iommu() to > > expose host iommu context to vIOMMU emulators. vIOMMU emulators could > > make use the methods provided by host iommu context. e.g. > > propagate requests to host iommu. > I think I would squash this patch into the previous one. sure, I can make it. :-) > > > > Cc: Kevin Tian <kevin.tian@xxxxxxxxx> > > Cc: Jacob Pan <jacob.jun.pan@xxxxxxxxxxxxxxx> > > Cc: Peter Xu <peterx@xxxxxxxxxx> > > Cc: Eric Auger <eric.auger@xxxxxxxxxx> > > Cc: Yi Sun <yi.y.sun@xxxxxxxxxxxxxxx> > > Cc: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx> > > Cc: Alex Williamson <alex.williamson@xxxxxxxxxx> > > Signed-off-by: Liu Yi L <yi.l.liu@xxxxxxxxx> > > --- > > hw/vfio/pci.c | 13 +++++++++++++ > > 1 file changed, 13 insertions(+) > > > > diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5e75a95..c140c88 > > 100644 > > --- a/hw/vfio/pci.c > > +++ b/hw/vfio/pci.c > > @@ -2717,6 +2717,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) > > VFIOPCIDevice *vdev = PCI_VFIO(pdev); > > VFIODevice *vbasedev_iter; > > VFIOGroup *group; > > + VFIOContainer *container; > > char *tmp, *subsys, group_path[PATH_MAX], *group_name; > > Error *err = NULL; > > ssize_t len; > > @@ -3028,6 +3029,11 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) > > vfio_register_req_notifier(vdev); > > vfio_setup_resetfn_quirk(vdev); > > > > + container = vdev->vbasedev.group->container; > > + if (container->iommu_ctx.initialized) { > Sin't it possible to dynamically allocate the iommu_ctx so that you can simply check > container->iommu_ctx and discard the initialized field? iommu_ctx is allocated along with container as it is not a pointer in VFIOContainer. The only way to check it is to have flag. :-) Regards, Yi Liu