qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC v1 08/18] vfio/pci: add vfio bind/unbind_gpasid im


From: Liu, Yi L
Subject: Re: [Qemu-devel] [RFC v1 08/18] vfio/pci: add vfio bind/unbind_gpasid implementation
Date: Wed, 10 Jul 2019 12:30:33 +0000

> From: Auger Eric [mailto:address@hidden]
> 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 <address@hidden>
> > Cc: Jacob Pan <address@hidden>
> > Cc: Peter Xu <address@hidden>
> > Cc: Eric Auger <address@hidden>
> > Cc: Yi Sun <address@hidden>
> > Cc: David Gibson <address@hidden>
> > Signed-off-by: Liu Yi L <address@hidden>
> > ---
> >  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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]