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
810 vgpu->group_notifier.notifier_call = intel_vgpu_group_notifier;810 vgpu->group_notifier.notifier_call = intel_vgpu_group_notifier;
811 811
812 events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;812 events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
813 ret = vfio_register_notifier(vfio_dev->dev, VFIO_IOMMU_NOTIFY, &events,813 ret = vfio_register_notifier(vfio_dev, VFIO_IOMMU_NOTIFY, &events,
814 &vgpu->iommu_notifier);814 &vgpu->iommu_notifier);
815 if (ret != 0) {815 if (ret != 0) {
816 gvt_vgpu_err("vfio_register_notifier for iommu failed: %d\n",816 gvt_vgpu_err("vfio_register_notifier for iommu failed: %d\n",
817 ret);817 ret);
@@ -819,8 +819,8 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev) · 1 unmodified line
819 }819 }
820 820
821 events = VFIO_GROUP_NOTIFY_SET_KVM;821 events = VFIO_GROUP_NOTIFY_SET_KVM;
822 ret = vfio_register_notifier(vfio_dev->dev, VFIO_GROUP_NOTIFY, &events,822 ret = vfio_register_notifier(vfio_dev, VFIO_GROUP_NOTIFY, &events,
823 &vgpu->group_notifier);823 &vgpu->group_notifier);
824 if (ret != 0) {824 if (ret != 0) {
825 gvt_vgpu_err("vfio_register_notifier for group failed: %d\n",825 gvt_vgpu_err("vfio_register_notifier for group failed: %d\n",
826 ret);826 ret);
@@ -873,12 +873,12 @@ undo_group: · 46 unmodified lines
873 vgpu->vfio_group = NULL;873 vgpu->vfio_group = NULL;
874 874
875undo_register:875undo_register:
876 vfio_unregister_notifier(vfio_dev->dev, VFIO_GROUP_NOTIFY,876 vfio_unregister_notifier(vfio_dev, VFIO_GROUP_NOTIFY,
877 &vgpu->group_notifier);877 &vgpu->group_notifier);
878 878
879undo_iommu:879undo_iommu:
880 vfio_unregister_notifier(vfio_dev->dev, VFIO_IOMMU_NOTIFY,880 vfio_unregister_notifier(vfio_dev, VFIO_IOMMU_NOTIFY,
881 &vgpu->iommu_notifier);881 &vgpu->iommu_notifier);
882out:882out:
883 return ret;883 return ret;
884}884}
@@ -907,13 +907,13 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) · 22 unmodified lines
907 907
908 intel_gvt_release_vgpu(vgpu);908 intel_gvt_release_vgpu(vgpu);
909 909
910 ret = vfio_unregister_notifier(vgpu->vfio_device.dev, VFIO_IOMMU_NOTIFY,910 ret = vfio_unregister_notifier(&vgpu->vfio_device, VFIO_IOMMU_NOTIFY,
911 &vgpu->iommu_notifier);911 &vgpu->iommu_notifier);
912 drm_WARN(&i915->drm, ret,912 drm_WARN(&i915->drm, ret,
913 "vfio_unregister_notifier for iommu failed: %d\n", ret);913 "vfio_unregister_notifier for iommu failed: %d\n", ret);
914 914
915 ret = vfio_unregister_notifier(vgpu->vfio_device.dev, VFIO_GROUP_NOTIFY,915 ret = vfio_unregister_notifier(&vgpu->vfio_device, VFIO_GROUP_NOTIFY,
916 &vgpu->group_notifier);916 &vgpu->group_notifier);
917 drm_WARN(&i915->drm, ret,917 drm_WARN(&i915->drm, ret,
918 "vfio_unregister_notifier for group failed: %d\n", ret);918 "vfio_unregister_notifier for group failed: %d\n", ret);
919 919
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
183 183
184 private->nb.notifier_call = vfio_ccw_mdev_notifier;184 private->nb.notifier_call = vfio_ccw_mdev_notifier;
185 185
186 ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,186 ret = vfio_register_notifier(vdev, VFIO_IOMMU_NOTIFY,
187 &events, &private->nb);187 &events, &private->nb);
188 if (ret)188 if (ret)
189 return ret;189 return ret;
@@ -204,8 +204,7 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) · 14 unmodified lines
204 204
205out_unregister:205out_unregister:
206 vfio_ccw_unregister_dev_regions(private);206 vfio_ccw_unregister_dev_regions(private);
207 vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,207 vfio_unregister_notifier(vdev, VFIO_IOMMU_NOTIFY, &private->nb);
208 &private->nb);
209 return ret;208 return ret;
210}209}
211 210
@@ -223,7 +222,7 @@ static void vfio_ccw_mdev_close_device(struct vfio_device *vdev) · 11 unmodified lines
223 222
224 cp_free(&private->cp);223 cp_free(&private->cp);
225 vfio_ccw_unregister_dev_regions(private);224 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);
227}226}
228 227
229static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private,228static 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
1406 matrix_mdev->group_notifier.notifier_call = vfio_ap_mdev_group_notifier;1406 matrix_mdev->group_notifier.notifier_call = vfio_ap_mdev_group_notifier;
1407 events = VFIO_GROUP_NOTIFY_SET_KVM;1407 events = VFIO_GROUP_NOTIFY_SET_KVM;
1408 1408
1409 ret = vfio_register_notifier(vdev->dev, VFIO_GROUP_NOTIFY,1409 ret = vfio_register_notifier(vdev, VFIO_GROUP_NOTIFY, &events,
1410 &events, &matrix_mdev->group_notifier);1410 &matrix_mdev->group_notifier);
1411 if (ret)1411 if (ret)
1412 return ret;1412 return ret;
1413 1413
1414 matrix_mdev->iommu_notifier.notifier_call = vfio_ap_mdev_iommu_notifier;1414 matrix_mdev->iommu_notifier.notifier_call = vfio_ap_mdev_iommu_notifier;
1415 events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;1415 events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
1416 ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,1416 ret = vfio_register_notifier(vdev, VFIO_IOMMU_NOTIFY, &events,
1417 &events, &matrix_mdev->iommu_notifier);1417 &matrix_mdev->iommu_notifier);
1418 if (ret)1418 if (ret)
1419 goto out_unregister_group;1419 goto out_unregister_group;
1420 return 0;1420 return 0;
1421 1421
1422out_unregister_group:1422out_unregister_group:
1423 vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY,1423 vfio_unregister_notifier(vdev, VFIO_GROUP_NOTIFY,
1424 &matrix_mdev->group_notifier);1424 &matrix_mdev->group_notifier);
1425 return ret;1425 return ret;
1426}1426}
@@ -1430,9 +1430,9 @@ static void vfio_ap_mdev_close_device(struct vfio_device *vdev) · 3 unmodified lines
1430 struct ap_matrix_mdev *matrix_mdev =1430 struct ap_matrix_mdev *matrix_mdev =
1431 container_of(vdev, struct ap_matrix_mdev, vdev);1431 container_of(vdev, struct ap_matrix_mdev, vdev);
1432 1432
1433 vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,1433 vfio_unregister_notifier(vdev, VFIO_IOMMU_NOTIFY,
1434 &matrix_mdev->iommu_notifier);1434 &matrix_mdev->iommu_notifier);
1435 vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY,1435 vfio_unregister_notifier(vdev, VFIO_GROUP_NOTIFY,
1436 &matrix_mdev->group_notifier);1436 &matrix_mdev->group_notifier);
1437 vfio_ap_mdev_unset_kvm(matrix_mdev);1437 vfio_ap_mdev_unset_kvm(matrix_mdev);
1438}1438}
drivers/vfio/vfio.c+9−19
@@ -2484,19 +2484,16 @@ static int vfio_unregister_group_notifier(struct vfio_group *group, · 2483 unmodified lines
2484 return ret;2484 return ret;
2485}2485}
2486 2486
2487int vfio_register_notifier(struct device *dev, enum vfio_notify_type type,2487int vfio_register_notifier(struct vfio_device *device,
2488 unsigned long *events, struct notifier_block *nb)2488 enum vfio_notify_type type, unsigned long *events,
2489 struct notifier_block *nb)
2489{2490{
2490 struct vfio_group *group;2491 struct vfio_group *group = device->group;
2491 int ret;2492 int ret;
2492 2493
2493 if (!dev || !nb || !events || (*events == 0))2494 if (!nb || !events || (*events == 0))
2494 return -EINVAL;2495 return -EINVAL;
2495 2496
2496 group = vfio_group_get_from_dev(dev);
2497 if (!group)
2498 return -ENODEV;
2499
2500 switch (type) {2497 switch (type) {
2501 case VFIO_IOMMU_NOTIFY:2498 case VFIO_IOMMU_NOTIFY:
2502 ret = vfio_register_iommu_notifier(group, events, nb);2499 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
2507 default:2504 default:
2508 ret = -EINVAL;2505 ret = -EINVAL;
2509 }2506 }
2510
2511 vfio_group_put(group);
2512 return ret;2507 return ret;
2513}2508}
2514EXPORT_SYMBOL(vfio_register_notifier);2509EXPORT_SYMBOL(vfio_register_notifier);
2515 2510
2516int vfio_unregister_notifier(struct device *dev, enum vfio_notify_type type,2511int vfio_unregister_notifier(struct vfio_device *device,
2512 enum vfio_notify_type type,
2517 struct notifier_block *nb)2513 struct notifier_block *nb)
2518{2514{
2519 struct vfio_group *group;2515 struct vfio_group *group = device->group;
2520 int ret;2516 int ret;
2521 2517
2522 if (!dev || !nb)2518 if (!nb)
2523 return -EINVAL;2519 return -EINVAL;
2524 2520
2525 group = vfio_group_get_from_dev(dev);
2526 if (!group)
2527 return -ENODEV;
2528
2529 switch (type) {2521 switch (type) {
2530 case VFIO_IOMMU_NOTIFY:2522 case VFIO_IOMMU_NOTIFY:
2531 ret = vfio_unregister_iommu_notifier(group, nb);2523 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
2536 default:2528 default:
2537 ret = -EINVAL;2529 ret = -EINVAL;
2538 }2530 }
2539
2540 vfio_group_put(group);
2541 return ret;2531 return ret;
2542}2532}
2543EXPORT_SYMBOL(vfio_unregister_notifier);2533EXPORT_SYMBOL(vfio_unregister_notifier);
include/linux/vfio.h+2−2
@@ -178,11 +178,11 @@ enum vfio_notify_type { · 177 unmodified lines
178/* events for VFIO_GROUP_NOTIFY */178/* events for VFIO_GROUP_NOTIFY */
179#define VFIO_GROUP_NOTIFY_SET_KVM BIT(0)179#define VFIO_GROUP_NOTIFY_SET_KVM BIT(0)
180 180
181extern int vfio_register_notifier(struct device *dev,181extern int vfio_register_notifier(struct vfio_device *device,
182 enum vfio_notify_type type,182 enum vfio_notify_type type,
183 unsigned long *required_events,183 unsigned long *required_events,
184 struct notifier_block *nb);184 struct notifier_block *nb);
185extern int vfio_unregister_notifier(struct device *dev,185extern int vfio_unregister_notifier(struct vfio_device *device,
186 enum vfio_notify_type type,186 enum vfio_notify_type type,
187 struct notifier_block *nb);187 struct notifier_block *nb);
188 188