On Thu, 2014-04-10 at 15:15 -0600, Alex Williamson wrote:
> On Thu, 2014-04-10 at 20:52 +0000, Stuart Yoder wrote:
> > > Another advantage to this approach is that we can specify a driver
> > > override to force a specific binding or prevent any binding.  For
> > > instance when an IOMMU group is exposed to userspace through VFIO
> > > we require that all devices within that group are owned by VFIO.
> > > However, devices can be hot-added into an IOMMU group, in which case
> > > we want to prevent the device from binding to any driver (preferred
> > > driver = "none") or perhaps have it automatically bind to vfio-pci.
> > > With driver_override it's a simple matter for this field to be set
> > > internally when the device is first discovered to prevent driver
> > > matches.
> > 
> > Alex, I think the patch looks good, but did have a question about
> > the hot-adding device scenario above.   How do you get the "field to
> > be set internally when the device is first discovered"?   What
> > hook is there to do that prior to the driver match processing?
> 
> Devices already need to be added to iommu groups prior to driver probe
> which happens either by the iommu driver calling bus_register_notifier()
> and looking for BUS_NOTIFY_ADD_DEVICE or they can register an add_device
> callback in their iommu_ops and let the iommu subsystem register the
> notifier.  When a device is then added to an iommu group, there is yet
> another notifier.  vfio calls iommu_group_register_notifier() and gets
> told via IOMMU_GROUP_NOTIFY_ADD_DEVICE when a device is added to a
> group.  We currently have a WARN_ON when a device is added to a live
> group - vfio_group_nb_add_dev().  I expect we'd just replace that with
> detecting the bus_type of the device and allocating a string with the
> proper vfio driver for the bus.  Thanks,

For instance, the below should work for PCI devices.  I imagine we'd
also want to print out some useful log message for this as well.
Thanks,

Alex

--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -486,7 +486,14 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, 
        if (!atomic_read(&group->container_users))
                return 0;
 
-       /* TODO Prevent device auto probing */
+       /* Only let PCI devices added to a live group bind to "vfio-pci" */
+       if (dev_is_pci(dev)) {
+               struct pci_dev *pdev = to_pci_dev(dev);
+               pdev->driver_override = kstrdup("vfio-pci", GFP_KERNEL);
+               if (pdev->driver_override)
+                       return 0;
+       }
+
        WARN("Device %s added to live group %d!\n", dev_name(dev),
             iommu_group_id(group->iommu_group));
 


_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to