@@ -71,7 +71,6 @@ struct vfio_group {
71
71
struct vfio_container * container ;
72
72
struct list_head device_list ;
73
73
struct mutex device_lock ;
74
- struct notifier_block nb ;
75
74
struct list_head vfio_next ;
76
75
struct list_head container_next ;
77
76
atomic_t opened ;
@@ -274,8 +273,6 @@ void vfio_unregister_iommu_driver(const struct vfio_iommu_driver_ops *ops)
274
273
}
275
274
EXPORT_SYMBOL_GPL (vfio_unregister_iommu_driver );
276
275
277
- static int vfio_iommu_group_notifier (struct notifier_block * nb ,
278
- unsigned long action , void * data );
279
276
static void vfio_group_get (struct vfio_group * group );
280
277
281
278
/*
@@ -395,13 +392,6 @@ static struct vfio_group *vfio_create_group(struct iommu_group *iommu_group,
395
392
goto err_put ;
396
393
}
397
394
398
- group -> nb .notifier_call = vfio_iommu_group_notifier ;
399
- err = iommu_group_register_notifier (iommu_group , & group -> nb );
400
- if (err ) {
401
- ret = ERR_PTR (err );
402
- goto err_put ;
403
- }
404
-
405
395
mutex_lock (& vfio .group_lock );
406
396
407
397
/* Did we race creating this group? */
@@ -422,7 +412,6 @@ static struct vfio_group *vfio_create_group(struct iommu_group *iommu_group,
422
412
423
413
err_unlock :
424
414
mutex_unlock (& vfio .group_lock );
425
- iommu_group_unregister_notifier (group -> iommu_group , & group -> nb );
426
415
err_put :
427
416
put_device (& group -> dev );
428
417
return ret ;
@@ -447,7 +436,6 @@ static void vfio_group_put(struct vfio_group *group)
447
436
cdev_device_del (& group -> cdev , & group -> dev );
448
437
mutex_unlock (& vfio .group_lock );
449
438
450
- iommu_group_unregister_notifier (group -> iommu_group , & group -> nb );
451
439
put_device (& group -> dev );
452
440
}
453
441
@@ -503,141 +491,6 @@ static struct vfio_device *vfio_group_get_device(struct vfio_group *group,
503
491
return NULL ;
504
492
}
505
493
506
- /*
507
- * Some drivers, like pci-stub, are only used to prevent other drivers from
508
- * claiming a device and are therefore perfectly legitimate for a user owned
509
- * group. The pci-stub driver has no dependencies on DMA or the IOVA mapping
510
- * of the device, but it does prevent the user from having direct access to
511
- * the device, which is useful in some circumstances.
512
- *
513
- * We also assume that we can include PCI interconnect devices, ie. bridges.
514
- * IOMMU grouping on PCI necessitates that if we lack isolation on a bridge
515
- * then all of the downstream devices will be part of the same IOMMU group as
516
- * the bridge. Thus, if placing the bridge into the user owned IOVA space
517
- * breaks anything, it only does so for user owned devices downstream. Note
518
- * that error notification via MSI can be affected for platforms that handle
519
- * MSI within the same IOVA space as DMA.
520
- */
521
- static const char * const vfio_driver_allowed [] = { "pci-stub" };
522
-
523
- static bool vfio_dev_driver_allowed (struct device * dev ,
524
- struct device_driver * drv )
525
- {
526
- if (dev_is_pci (dev )) {
527
- struct pci_dev * pdev = to_pci_dev (dev );
528
-
529
- if (pdev -> hdr_type != PCI_HEADER_TYPE_NORMAL )
530
- return true;
531
- }
532
-
533
- return match_string (vfio_driver_allowed ,
534
- ARRAY_SIZE (vfio_driver_allowed ),
535
- drv -> name ) >= 0 ;
536
- }
537
-
538
- /*
539
- * A vfio group is viable for use by userspace if all devices are in
540
- * one of the following states:
541
- * - driver-less
542
- * - bound to a vfio driver
543
- * - bound to an otherwise allowed driver
544
- * - a PCI interconnect device
545
- *
546
- * We use two methods to determine whether a device is bound to a vfio
547
- * driver. The first is to test whether the device exists in the vfio
548
- * group. The second is to test if the device exists on the group
549
- * unbound_list, indicating it's in the middle of transitioning from
550
- * a vfio driver to driver-less.
551
- */
552
- static int vfio_dev_viable (struct device * dev , void * data )
553
- {
554
- struct vfio_group * group = data ;
555
- struct vfio_device * device ;
556
- struct device_driver * drv = READ_ONCE (dev -> driver );
557
-
558
- if (!drv || vfio_dev_driver_allowed (dev , drv ))
559
- return 0 ;
560
-
561
- device = vfio_group_get_device (group , dev );
562
- if (device ) {
563
- vfio_device_put (device );
564
- return 0 ;
565
- }
566
-
567
- return - EINVAL ;
568
- }
569
-
570
- /*
571
- * Async device support
572
- */
573
- static int vfio_group_nb_add_dev (struct vfio_group * group , struct device * dev )
574
- {
575
- struct vfio_device * device ;
576
-
577
- /* Do we already know about it? We shouldn't */
578
- device = vfio_group_get_device (group , dev );
579
- if (WARN_ON_ONCE (device )) {
580
- vfio_device_put (device );
581
- return 0 ;
582
- }
583
-
584
- /* Nothing to do for idle groups */
585
- if (!atomic_read (& group -> container_users ))
586
- return 0 ;
587
-
588
- /* TODO Prevent device auto probing */
589
- dev_WARN (dev , "Device added to live group %d!\n" ,
590
- iommu_group_id (group -> iommu_group ));
591
-
592
- return 0 ;
593
- }
594
-
595
- static int vfio_group_nb_verify (struct vfio_group * group , struct device * dev )
596
- {
597
- /* We don't care what happens when the group isn't in use */
598
- if (!atomic_read (& group -> container_users ))
599
- return 0 ;
600
-
601
- return vfio_dev_viable (dev , group );
602
- }
603
-
604
- static int vfio_iommu_group_notifier (struct notifier_block * nb ,
605
- unsigned long action , void * data )
606
- {
607
- struct vfio_group * group = container_of (nb , struct vfio_group , nb );
608
- struct device * dev = data ;
609
-
610
- switch (action ) {
611
- case IOMMU_GROUP_NOTIFY_ADD_DEVICE :
612
- vfio_group_nb_add_dev (group , dev );
613
- break ;
614
- case IOMMU_GROUP_NOTIFY_DEL_DEVICE :
615
- /*
616
- * Nothing to do here. If the device is in use, then the
617
- * vfio sub-driver should block the remove callback until
618
- * it is unused. If the device is unused or attached to a
619
- * stub driver, then it should be released and we don't
620
- * care that it will be going away.
621
- */
622
- break ;
623
- case IOMMU_GROUP_NOTIFY_BIND_DRIVER :
624
- dev_dbg (dev , "%s: group %d binding to driver\n" , __func__ ,
625
- iommu_group_id (group -> iommu_group ));
626
- break ;
627
- case IOMMU_GROUP_NOTIFY_BOUND_DRIVER :
628
- dev_dbg (dev , "%s: group %d bound to driver %s\n" , __func__ ,
629
- iommu_group_id (group -> iommu_group ), dev -> driver -> name );
630
- BUG_ON (vfio_group_nb_verify (group , dev ));
631
- break ;
632
- case IOMMU_GROUP_NOTIFY_UNBIND_DRIVER :
633
- dev_dbg (dev , "%s: group %d unbinding from driver %s\n" ,
634
- __func__ , iommu_group_id (group -> iommu_group ),
635
- dev -> driver -> name );
636
- break ;
637
- }
638
- return NOTIFY_OK ;
639
- }
640
-
641
494
/*
642
495
* VFIO driver API
643
496
*/
0 commit comments