Message ID | 1585542301-84087-11-git-send-email-yi.l.liu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | intel_iommu: expose Shared Virtual Addressing to VMs | expand |
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. > > Cc: Kevin Tian <kevin.tian@intel.com> > Cc: Jacob Pan <jacob.jun.pan@linux.intel.com> > Cc: Peter Xu <peterx@redhat.com> > Cc: Eric Auger <eric.auger@redhat.com> > Cc: Yi Sun <yi.y.sun@linux.intel.com> > Cc: David Gibson <david@gibson.dropbear.id.au> > Cc: Alex Williamson <alex.williamson@redhat.com> > Signed-off-by: Liu Yi L <yi.l.liu@intel.com> > --- > 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? > + pci_device_set_iommu_context(pdev, &container->iommu_ctx); > + } > + > return; > > out_deregister: > @@ -3072,9 +3078,16 @@ static void vfio_instance_finalize(Object *obj) > static void vfio_exitfn(PCIDevice *pdev) > { > VFIOPCIDevice *vdev = PCI_VFIO(pdev); > + VFIOContainer *container; > > vfio_unregister_req_notifier(vdev); > vfio_unregister_err_notifier(vdev); > + > + container = vdev->vbasedev.group->container; > + if (container->iommu_ctx.initialized) { > + pci_device_unset_iommu_context(pdev); > + } > + > pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); > if (vdev->irqchip_change_notifier.notify) { > kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier); > Thanks Eric
Hi Eric, > From: Auger Eric <eric.auger@redhat.com> > Sent: Tuesday, March 31, 2020 10:30 PM > To: Liu, Yi L <yi.l.liu@intel.com>; qemu-devel@nongnu.org; > 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@intel.com> > > Cc: Jacob Pan <jacob.jun.pan@linux.intel.com> > > Cc: Peter Xu <peterx@redhat.com> > > Cc: Eric Auger <eric.auger@redhat.com> > > Cc: Yi Sun <yi.y.sun@linux.intel.com> > > Cc: David Gibson <david@gibson.dropbear.id.au> > > Cc: Alex Williamson <alex.williamson@redhat.com> > > Signed-off-by: Liu Yi L <yi.l.liu@intel.com> > > --- > > 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
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) { + pci_device_set_iommu_context(pdev, &container->iommu_ctx); + } + return; out_deregister: @@ -3072,9 +3078,16 @@ static void vfio_instance_finalize(Object *obj) static void vfio_exitfn(PCIDevice *pdev) { VFIOPCIDevice *vdev = PCI_VFIO(pdev); + VFIOContainer *container; vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); + + container = vdev->vbasedev.group->container; + if (container->iommu_ctx.initialized) { + pci_device_unset_iommu_context(pdev); + } + pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); if (vdev->irqchip_change_notifier.notify) { kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
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. Cc: Kevin Tian <kevin.tian@intel.com> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com> Cc: Peter Xu <peterx@redhat.com> Cc: Eric Auger <eric.auger@redhat.com> Cc: Yi Sun <yi.y.sun@linux.intel.com> Cc: David Gibson <david@gibson.dropbear.id.au> Cc: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Liu Yi L <yi.l.liu@intel.com> --- hw/vfio/pci.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)