Message ID | 1562324511-2910-9-git-send-email-yi.l.liu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | intel_iommu: expose Shared Virtual Addressing to VM | expand |
Hi Liu, On 7/5/19 1:01 PM, Liu Yi L wrote: > This patch adds vfio implementation PCIPASIDOps.bind_gpasid/unbind_pasid(). > These two functions are used to propagate guest pasid bind and unbind > requests to host via vfio container ioctl. > > 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> > Signed-off-by: Liu Yi L <yi.l.liu@intel.com> > --- > hw/vfio/pci.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 54 insertions(+) > > diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c > index ab184ad..892b46c 100644 > --- a/hw/vfio/pci.c > +++ b/hw/vfio/pci.c > @@ -2744,9 +2744,63 @@ static int vfio_pci_device_request_pasid_free(PCIBus *bus, > return ret; > } > > +static void vfio_pci_device_bind_gpasid(PCIBus *bus, int32_t devfn, > + struct gpasid_bind_data *g_bind_data) > +{ > + PCIDevice *pdev = bus->devices[devfn]; > + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); > + VFIOContainer *container = vdev->vbasedev.group->container; > + struct vfio_iommu_type1_bind *bind; > + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; > + unsigned long argsz; > + > + argsz = sizeof(*bind) + sizeof(*bind_guest_pasid); > + bind = g_malloc0(argsz); > + bind->argsz = argsz; > + bind->bind_type = VFIO_IOMMU_BIND_GUEST_PASID; > + bind_guest_pasid = (struct vfio_iommu_type1_bind_guest_pasid *) &bind->data; > + bind_guest_pasid->bind_data = *g_bind_data; > + > + rcu_read_lock(); why do you need the rcu_read_lock? > + if (ioctl(container->fd, VFIO_IOMMU_BIND, bind) != 0) { > + error_report("vfio_pci_device_bind_gpasid:" > + " bind failed, contanier: %p", container); container > + } > + rcu_read_unlock(); > + g_free(bind); > +} > + > +static void vfio_pci_device_unbind_gpasid(PCIBus *bus, int32_t devfn, > + struct gpasid_bind_data *g_bind_data) > +{ > + PCIDevice *pdev = bus->devices[devfn]; > + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); > + VFIOContainer *container = vdev->vbasedev.group->container; > + struct vfio_iommu_type1_bind *bind; > + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; > + unsigned long argsz; > + > + argsz = sizeof(*bind) + sizeof(*bind_guest_pasid); > + bind = g_malloc0(argsz); > + bind->argsz = argsz; > + bind->bind_type = VFIO_IOMMU_BIND_GUEST_PASID; > + bind_guest_pasid = (struct vfio_iommu_type1_bind_guest_pasid *) &bind->data; > + bind_guest_pasid->bind_data = *g_bind_data; > + > + rcu_read_lock(); > + if (ioctl(container->fd, VFIO_IOMMU_UNBIND, bind) != 0) { > + error_report("vfio_pci_device_unbind_gpasid:" > + " unbind failed, contanier: %p", container); container > + } > + rcu_read_unlock(); > + g_free(bind); > +} > + > static PCIPASIDOps vfio_pci_pasid_ops = { > .alloc_pasid = vfio_pci_device_request_pasid_alloc, > .free_pasid = vfio_pci_device_request_pasid_free, > + .bind_gpasid = vfio_pci_device_bind_gpasid, > + .unbind_gpasid = vfio_pci_device_unbind_gpasid, > }; > > static void vfio_realize(PCIDevice *pdev, Error **errp) > Thanks Eric
> From: Auger Eric [mailto:eric.auger@redhat.com] > Sent: Tuesday, July 9, 2019 4:38 PM > Subject: Re: [RFC v1 08/18] vfio/pci: add vfio bind/unbind_gpasid implementation > > Hi Liu, > > On 7/5/19 1:01 PM, Liu Yi L wrote: > > This patch adds vfio implementation PCIPASIDOps.bind_gpasid/unbind_pasid(). > > These two functions are used to propagate guest pasid bind and unbind > > requests to host via vfio container ioctl. > > > > 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> > > Signed-off-by: Liu Yi L <yi.l.liu@intel.com> > > --- > > hw/vfio/pci.c | 54 > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 54 insertions(+) > > > > diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index ab184ad..892b46c > > 100644 > > --- a/hw/vfio/pci.c > > +++ b/hw/vfio/pci.c > > @@ -2744,9 +2744,63 @@ static int vfio_pci_device_request_pasid_free(PCIBus > *bus, > > return ret; > > } > > > > +static void vfio_pci_device_bind_gpasid(PCIBus *bus, int32_t devfn, > > + struct gpasid_bind_data > > +*g_bind_data) { > > + PCIDevice *pdev = bus->devices[devfn]; > > + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); > > + VFIOContainer *container = vdev->vbasedev.group->container; > > + struct vfio_iommu_type1_bind *bind; > > + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; > > + unsigned long argsz; > > + > > + argsz = sizeof(*bind) + sizeof(*bind_guest_pasid); > > + bind = g_malloc0(argsz); > > + bind->argsz = argsz; > > + bind->bind_type = VFIO_IOMMU_BIND_GUEST_PASID; > > + bind_guest_pasid = (struct vfio_iommu_type1_bind_guest_pasid *) &bind- > >data; > > + bind_guest_pasid->bind_data = *g_bind_data; > > + > > + rcu_read_lock(); > why do you need the rcu_read_lock? > > + if (ioctl(container->fd, VFIO_IOMMU_BIND, bind) != 0) { > > + error_report("vfio_pci_device_bind_gpasid:" > > + " bind failed, contanier: %p", container); > container nice catch. :-) > > + } > > + rcu_read_unlock(); > > + g_free(bind); > > +} > > + > > +static void vfio_pci_device_unbind_gpasid(PCIBus *bus, int32_t devfn, > > + struct gpasid_bind_data > > +*g_bind_data) { > > + PCIDevice *pdev = bus->devices[devfn]; > > + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); > > + VFIOContainer *container = vdev->vbasedev.group->container; > > + struct vfio_iommu_type1_bind *bind; > > + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; > > + unsigned long argsz; > > + > > + argsz = sizeof(*bind) + sizeof(*bind_guest_pasid); > > + bind = g_malloc0(argsz); > > + bind->argsz = argsz; > > + bind->bind_type = VFIO_IOMMU_BIND_GUEST_PASID; > > + bind_guest_pasid = (struct vfio_iommu_type1_bind_guest_pasid *) &bind- > >data; > > + bind_guest_pasid->bind_data = *g_bind_data; > > + > > + rcu_read_lock(); > > + if (ioctl(container->fd, VFIO_IOMMU_UNBIND, bind) != 0) { > > + error_report("vfio_pci_device_unbind_gpasid:" > > + " unbind failed, contanier: %p", container); > container oops, Thanks, > > + } > > + rcu_read_unlock(); > > + g_free(bind); > > +} > > + > > static PCIPASIDOps vfio_pci_pasid_ops = { > > .alloc_pasid = vfio_pci_device_request_pasid_alloc, > > .free_pasid = vfio_pci_device_request_pasid_free, > > + .bind_gpasid = vfio_pci_device_bind_gpasid, > > + .unbind_gpasid = vfio_pci_device_unbind_gpasid, > > }; > > > > static void vfio_realize(PCIDevice *pdev, Error **errp) > > > > Thanks > > Eric Yi Liu
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index ab184ad..892b46c 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2744,9 +2744,63 @@ static int vfio_pci_device_request_pasid_free(PCIBus *bus, return ret; } +static void vfio_pci_device_bind_gpasid(PCIBus *bus, int32_t devfn, + struct gpasid_bind_data *g_bind_data) +{ + PCIDevice *pdev = bus->devices[devfn]; + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOContainer *container = vdev->vbasedev.group->container; + struct vfio_iommu_type1_bind *bind; + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; + unsigned long argsz; + + argsz = sizeof(*bind) + sizeof(*bind_guest_pasid); + bind = g_malloc0(argsz); + bind->argsz = argsz; + bind->bind_type = VFIO_IOMMU_BIND_GUEST_PASID; + bind_guest_pasid = (struct vfio_iommu_type1_bind_guest_pasid *) &bind->data; + bind_guest_pasid->bind_data = *g_bind_data; + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_BIND, bind) != 0) { + error_report("vfio_pci_device_bind_gpasid:" + " bind failed, contanier: %p", container); + } + rcu_read_unlock(); + g_free(bind); +} + +static void vfio_pci_device_unbind_gpasid(PCIBus *bus, int32_t devfn, + struct gpasid_bind_data *g_bind_data) +{ + PCIDevice *pdev = bus->devices[devfn]; + VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOContainer *container = vdev->vbasedev.group->container; + struct vfio_iommu_type1_bind *bind; + struct vfio_iommu_type1_bind_guest_pasid *bind_guest_pasid; + unsigned long argsz; + + argsz = sizeof(*bind) + sizeof(*bind_guest_pasid); + bind = g_malloc0(argsz); + bind->argsz = argsz; + bind->bind_type = VFIO_IOMMU_BIND_GUEST_PASID; + bind_guest_pasid = (struct vfio_iommu_type1_bind_guest_pasid *) &bind->data; + bind_guest_pasid->bind_data = *g_bind_data; + + rcu_read_lock(); + if (ioctl(container->fd, VFIO_IOMMU_UNBIND, bind) != 0) { + error_report("vfio_pci_device_unbind_gpasid:" + " unbind failed, contanier: %p", container); + } + rcu_read_unlock(); + g_free(bind); +} + static PCIPASIDOps vfio_pci_pasid_ops = { .alloc_pasid = vfio_pci_device_request_pasid_alloc, .free_pasid = vfio_pci_device_request_pasid_free, + .bind_gpasid = vfio_pci_device_bind_gpasid, + .unbind_gpasid = vfio_pci_device_unbind_gpasid, }; static void vfio_realize(PCIDevice *pdev, Error **errp)
This patch adds vfio implementation PCIPASIDOps.bind_gpasid/unbind_pasid(). These two functions are used to propagate guest pasid bind and unbind requests to host via vfio container ioctl. 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> Signed-off-by: Liu Yi L <yi.l.liu@intel.com> --- hw/vfio/pci.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)