History

vfio: Make vfio_(un)register_notifier accept a vfio_device

All callers have a struct vfio_device trivially available, pass it in directly and avoid calling the expensive vfio_group_get_from_dev().

Jason Gunthorpe committed 4 years ago

Commit 09ea48e1 parent a77109f5 files · +33 −44Browse files

Unified · Split

5 files
  1. drivers/gpu/drm/i915/gvt/kvmgt.c +12 −12
  2. drivers/s390/cio/vfio_ccw_ops.c +3 −4
  3. drivers/s390/crypto/vfio_ap_ops.c +7 −7
  4. drivers/vfio/vfio.c +9 −19
  5. include/linux/vfio.h +2 −2
drivers/gpu/drm/i915/gvt/kvmgt.c+12−12
@@ -810,8 +810,8 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev) · 809 unmodified lines
810810 vgpu->group_notifier.notifier_call = intel_vgpu_group_notifier;
811811
812812 events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
813− ret = vfio_register_notifier(vfio_dev->dev, VFIO_IOMMU_NOTIFY, &events,
814− &vgpu->iommu_notifier);
813+ ret = vfio_register_notifier(vfio_dev, VFIO_IOMMU_NOTIFY, &events,
814+ &vgpu->iommu_notifier);
815815 if (ret != 0) {
816816 gvt_vgpu_err("vfio_register_notifier for iommu failed: %d\n",
817817 ret);
@@ -819,8 +819,8 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev) · 1 unmodified line
819819 }
820820
821821 events = VFIO_GROUP_NOTIFY_SET_KVM;
822− ret = vfio_register_notifier(vfio_dev->dev, VFIO_GROUP_NOTIFY, &events,
823− &vgpu->group_notifier);
822+ ret = vfio_register_notifier(vfio_dev, VFIO_GROUP_NOTIFY, &events,
823+ &vgpu->group_notifier);
824824 if (ret != 0) {
825825 gvt_vgpu_err("vfio_register_notifier for group failed: %d\n",
826826 ret);
@@ -873,12 +873,12 @@ undo_group: · 46 unmodified lines
873873 vgpu->vfio_group = NULL;
874874
875875 undo_register:
876− vfio_unregister_notifier(vfio_dev->dev, VFIO_GROUP_NOTIFY,
877− &vgpu->group_notifier);
876+ vfio_unregister_notifier(vfio_dev, VFIO_GROUP_NOTIFY,
877+ &vgpu->group_notifier);
878878
879879 undo_iommu:
880− vfio_unregister_notifier(vfio_dev->dev, VFIO_IOMMU_NOTIFY,
881− &vgpu->iommu_notifier);
880+ vfio_unregister_notifier(vfio_dev, VFIO_IOMMU_NOTIFY,
881+ &vgpu->iommu_notifier);
882882 out:
883883 return ret;
884884 }
@@ -907,13 +907,13 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) · 22 unmodified lines
907907
908908 intel_gvt_release_vgpu(vgpu);
909909
910− ret = vfio_unregister_notifier(vgpu->vfio_device.dev, VFIO_IOMMU_NOTIFY,
911− &vgpu->iommu_notifier);
910+ ret = vfio_unregister_notifier(&vgpu->vfio_device, VFIO_IOMMU_NOTIFY,
911+ &vgpu->iommu_notifier);
912912 drm_WARN(&i915->drm, ret,
913913 "vfio_unregister_notifier for iommu failed: %d\n", ret);
914914
915− ret = vfio_unregister_notifier(vgpu->vfio_device.dev, VFIO_GROUP_NOTIFY,
916− &vgpu->group_notifier);
915+ ret = vfio_unregister_notifier(&vgpu->vfio_device, VFIO_GROUP_NOTIFY,
916+ &vgpu->group_notifier);
917917 drm_WARN(&i915->drm, ret,
918918 "vfio_unregister_notifier for group failed: %d\n", ret);
919919
drivers/s390/cio/vfio_ccw_ops.c+3−4
@@ -183,7 +183,7 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) · 182 unmodified lines
183183
184184 private->nb.notifier_call = vfio_ccw_mdev_notifier;
185185
186− ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
186+ ret = vfio_register_notifier(vdev, VFIO_IOMMU_NOTIFY,
187187 &events, &private->nb);
188188 if (ret)
189189 return ret;
@@ -204,8 +204,7 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) · 14 unmodified lines
204204
205205 out_unregister:
206206 vfio_ccw_unregister_dev_regions(private);
207− vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
208− &private->nb);
207+ vfio_unregister_notifier(vdev, VFIO_IOMMU_NOTIFY, &private->nb);
209208 return ret;
210209 }
211210
@@ -223,7 +222,7 @@ static void vfio_ccw_mdev_close_device(struct vfio_device *vdev) · 11 unmodified lines
223222
224223 cp_free(&private->cp);
225224 vfio_ccw_unregister_dev_regions(private);
226− vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &private->nb);
225+ vfio_unregister_notifier(vdev, VFIO_IOMMU_NOTIFY, &private->nb);
227226 }
228227
229228 static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private,
drivers/s390/crypto/vfio_ap_ops.c+7−7
@@ -1406,21 +1406,21 @@ static int vfio_ap_mdev_open_device(struct vfio_device *vdev) · 1405 unmodified lines
14061406 matrix_mdev->group_notifier.notifier_call = vfio_ap_mdev_group_notifier;
14071407 events = VFIO_GROUP_NOTIFY_SET_KVM;
14081408
1409− ret = vfio_register_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
1410− &events, &matrix_mdev->group_notifier);
1409+ ret = vfio_register_notifier(vdev, VFIO_GROUP_NOTIFY, &events,
1410+ &matrix_mdev->group_notifier);
14111411 if (ret)
14121412 return ret;
14131413
14141414 matrix_mdev->iommu_notifier.notifier_call = vfio_ap_mdev_iommu_notifier;
14151415 events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
1416− ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
1417− &events, &matrix_mdev->iommu_notifier);
1416+ ret = vfio_register_notifier(vdev, VFIO_IOMMU_NOTIFY, &events,
1417+ &matrix_mdev->iommu_notifier);
14181418 if (ret)
14191419 goto out_unregister_group;
14201420 return 0;
14211421
14221422 out_unregister_group:
1423− vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
1423+ vfio_unregister_notifier(vdev, VFIO_GROUP_NOTIFY,
14241424 &matrix_mdev->group_notifier);
14251425 return ret;
14261426 }
@@ -1430,9 +1430,9 @@ static void vfio_ap_mdev_close_device(struct vfio_device *vdev) · 3 unmodified lines
14301430 struct ap_matrix_mdev *matrix_mdev =
14311431 container_of(vdev, struct ap_matrix_mdev, vdev);
14321432
1433− vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
1433+ vfio_unregister_notifier(vdev, VFIO_IOMMU_NOTIFY,
14341434 &matrix_mdev->iommu_notifier);
1435− vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
1435+ vfio_unregister_notifier(vdev, VFIO_GROUP_NOTIFY,
14361436 &matrix_mdev->group_notifier);
14371437 vfio_ap_mdev_unset_kvm(matrix_mdev);
14381438 }
drivers/vfio/vfio.c+9−19
@@ -2484,19 +2484,16 @@ static int vfio_unregister_group_notifier(struct vfio_group *group, · 2483 unmodified lines
24842484 return ret;
24852485 }
24862486
2487−int vfio_register_notifier(struct device *dev, enum vfio_notify_type type,
2488− unsigned long *events, struct notifier_block *nb)
2487+int vfio_register_notifier(struct vfio_device *device,
2488+ enum vfio_notify_type type, unsigned long *events,
2489+ struct notifier_block *nb)
24892490 {
2490− struct vfio_group *group;
2491+ struct vfio_group *group = device->group;
24912492 int ret;
24922493
2493− if (!dev || !nb || !events || (*events == 0))
2494+ if (!nb || !events || (*events == 0))
24942495 return -EINVAL;
24952496
2496− group = vfio_group_get_from_dev(dev);
2497− if (!group)
2498− return -ENODEV;
2499−
25002497 switch (type) {
25012498 case VFIO_IOMMU_NOTIFY:
25022499 ret = vfio_register_iommu_notifier(group, events, nb);
@@ -2507,25 +2504,20 @@ int vfio_register_notifier(struct device *dev, enum vfio_notify_type type, · 4 unmodified lines
25072504 default:
25082505 ret = -EINVAL;
25092506 }
2510−
2511− vfio_group_put(group);
25122507 return ret;
25132508 }
25142509 EXPORT_SYMBOL(vfio_register_notifier);
25152510
2516−int vfio_unregister_notifier(struct device *dev, enum vfio_notify_type type,
2511+int vfio_unregister_notifier(struct vfio_device *device,
2512+ enum vfio_notify_type type,
25172513 struct notifier_block *nb)
25182514 {
2519− struct vfio_group *group;
2515+ struct vfio_group *group = device->group;
25202516 int ret;
25212517
2522− if (!dev || !nb)
2518+ if (!nb)
25232519 return -EINVAL;
25242520
2525− group = vfio_group_get_from_dev(dev);
2526− if (!group)
2527− return -ENODEV;
2528−
25292521 switch (type) {
25302522 case VFIO_IOMMU_NOTIFY:
25312523 ret = vfio_unregister_iommu_notifier(group, nb);
@@ -2536,8 +2528,6 @@ int vfio_unregister_notifier(struct device *dev, enum vfio_notify_type type, · 4 unmodified lines
25362528 default:
25372529 ret = -EINVAL;
25382530 }
2539−
2540− vfio_group_put(group);
25412531 return ret;
25422532 }
25432533 EXPORT_SYMBOL(vfio_unregister_notifier);
include/linux/vfio.h+2−2
@@ -178,11 +178,11 @@ enum vfio_notify_type { · 177 unmodified lines
178178 /* events for VFIO_GROUP_NOTIFY */
179179 #define VFIO_GROUP_NOTIFY_SET_KVM BIT(0)
180180
181−extern int vfio_register_notifier(struct device *dev,
181+extern int vfio_register_notifier(struct vfio_device *device,
182182 enum vfio_notify_type type,
183183 unsigned long *required_events,
184184 struct notifier_block *nb);
185−extern int vfio_unregister_notifier(struct device *dev,
185+extern int vfio_unregister_notifier(struct vfio_device *device,
186186 enum vfio_notify_type type,
187187 struct notifier_block *nb);
188188