All callers have a struct vfio_device trivially available, pass it in directly and avoid calling the expensive vfio_group_get_from_dev().
Unified · Split
| @@ -810,8 +810,8 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev) · 809 unmodified lines | ||
| 810 | 810 | vgpu->group_notifier.notifier_call = intel_vgpu_group_notifier; |
| 811 | 811 | |
| 812 | 812 | 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); | |
| 815 | 815 | if (ret != 0) { |
| 816 | 816 | gvt_vgpu_err("vfio_register_notifier for iommu failed: %d\n", |
| 817 | 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 | 821 | 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); | |
| 824 | 824 | if (ret != 0) { |
| 825 | 825 | gvt_vgpu_err("vfio_register_notifier for group failed: %d\n", |
| 826 | 826 | ret); |
| @@ -873,12 +873,12 @@ undo_group: · 46 unmodified lines | ||
| 873 | 873 | vgpu->vfio_group = NULL; |
| 874 | 874 | |
| 875 | 875 | 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); | |
| 878 | 878 | |
| 879 | 879 | 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); | |
| 882 | 882 | out: |
| 883 | 883 | return ret; |
| 884 | 884 | } |
| @@ -907,13 +907,13 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) · 22 unmodified lines | ||
| 907 | 907 | |
| 908 | 908 | intel_gvt_release_vgpu(vgpu); |
| 909 | 909 | |
| 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); | |
| 912 | 912 | drm_WARN(&i915->drm, ret, |
| 913 | 913 | "vfio_unregister_notifier for iommu failed: %d\n", ret); |
| 914 | 914 | |
| 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); | |
| 917 | 917 | drm_WARN(&i915->drm, ret, |
| 918 | 918 | "vfio_unregister_notifier for group failed: %d\n", ret); |
| 919 | 919 | |
| @@ -183,7 +183,7 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) · 182 unmodified lines | ||
| 183 | 183 | |
| 184 | 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 | 187 | &events, &private->nb); |
| 188 | 188 | if (ret) |
| 189 | 189 | return ret; |
| @@ -204,8 +204,7 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) · 14 unmodified lines | ||
| 204 | 204 | |
| 205 | 205 | out_unregister: |
| 206 | 206 | 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); | |
| 209 | 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 | 223 | cp_free(&private->cp); |
| 225 | 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 | |
| 229 | 228 | static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private, |
| @@ -1406,21 +1406,21 @@ static int vfio_ap_mdev_open_device(struct vfio_device *vdev) · 1405 unmodified lines | ||
| 1406 | 1406 | matrix_mdev->group_notifier.notifier_call = vfio_ap_mdev_group_notifier; |
| 1407 | 1407 | events = VFIO_GROUP_NOTIFY_SET_KVM; |
| 1408 | 1408 | |
| 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); | |
| 1411 | 1411 | if (ret) |
| 1412 | 1412 | return ret; |
| 1413 | 1413 | |
| 1414 | 1414 | matrix_mdev->iommu_notifier.notifier_call = vfio_ap_mdev_iommu_notifier; |
| 1415 | 1415 | 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); | |
| 1418 | 1418 | if (ret) |
| 1419 | 1419 | goto out_unregister_group; |
| 1420 | 1420 | return 0; |
| 1421 | 1421 | |
| 1422 | 1422 | out_unregister_group: |
| 1423 | − vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY, | |
| 1423 | + vfio_unregister_notifier(vdev, VFIO_GROUP_NOTIFY, | |
| 1424 | 1424 | &matrix_mdev->group_notifier); |
| 1425 | 1425 | return ret; |
| 1426 | 1426 | } |
| @@ -1430,9 +1430,9 @@ static void vfio_ap_mdev_close_device(struct vfio_device *vdev) · 3 unmodified lines | ||
| 1430 | 1430 | struct ap_matrix_mdev *matrix_mdev = |
| 1431 | 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 | 1434 | &matrix_mdev->iommu_notifier); |
| 1435 | − vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY, | |
| 1435 | + vfio_unregister_notifier(vdev, VFIO_GROUP_NOTIFY, | |
| 1436 | 1436 | &matrix_mdev->group_notifier); |
| 1437 | 1437 | vfio_ap_mdev_unset_kvm(matrix_mdev); |
| 1438 | 1438 | } |
| @@ -2484,19 +2484,16 @@ static int vfio_unregister_group_notifier(struct vfio_group *group, · 2483 unmodified lines | ||
| 2484 | 2484 | return ret; |
| 2485 | 2485 | } |
| 2486 | 2486 | |
| 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) | |
| 2489 | 2490 | { |
| 2490 | − struct vfio_group *group; | |
| 2491 | + struct vfio_group *group = device->group; | |
| 2491 | 2492 | int ret; |
| 2492 | 2493 | |
| 2493 | − if (!dev || !nb || !events || (*events == 0)) | |
| 2494 | + if (!nb || !events || (*events == 0)) | |
| 2494 | 2495 | return -EINVAL; |
| 2495 | 2496 | |
| 2496 | − group = vfio_group_get_from_dev(dev); | |
| 2497 | − if (!group) | |
| 2498 | − return -ENODEV; | |
| 2499 | − | |
| 2500 | 2497 | switch (type) { |
| 2501 | 2498 | case VFIO_IOMMU_NOTIFY: |
| 2502 | 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 | 2504 | default: |
| 2508 | 2505 | ret = -EINVAL; |
| 2509 | 2506 | } |
| 2510 | − | |
| 2511 | − vfio_group_put(group); | |
| 2512 | 2507 | return ret; |
| 2513 | 2508 | } |
| 2514 | 2509 | EXPORT_SYMBOL(vfio_register_notifier); |
| 2515 | 2510 | |
| 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, | |
| 2517 | 2513 | struct notifier_block *nb) |
| 2518 | 2514 | { |
| 2519 | − struct vfio_group *group; | |
| 2515 | + struct vfio_group *group = device->group; | |
| 2520 | 2516 | int ret; |
| 2521 | 2517 | |
| 2522 | − if (!dev || !nb) | |
| 2518 | + if (!nb) | |
| 2523 | 2519 | return -EINVAL; |
| 2524 | 2520 | |
| 2525 | − group = vfio_group_get_from_dev(dev); | |
| 2526 | − if (!group) | |
| 2527 | − return -ENODEV; | |
| 2528 | − | |
| 2529 | 2521 | switch (type) { |
| 2530 | 2522 | case VFIO_IOMMU_NOTIFY: |
| 2531 | 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 | 2528 | default: |
| 2537 | 2529 | ret = -EINVAL; |
| 2538 | 2530 | } |
| 2539 | − | |
| 2540 | − vfio_group_put(group); | |
| 2541 | 2531 | return ret; |
| 2542 | 2532 | } |
| 2543 | 2533 | EXPORT_SYMBOL(vfio_unregister_notifier); |
| @@ -178,11 +178,11 @@ enum vfio_notify_type { · 177 unmodified lines | ||
| 178 | 178 | /* events for VFIO_GROUP_NOTIFY */ |
| 179 | 179 | #define VFIO_GROUP_NOTIFY_SET_KVM BIT(0) |
| 180 | 180 | |
| 181 | −extern int vfio_register_notifier(struct device *dev, | |
| 181 | +extern int vfio_register_notifier(struct vfio_device *device, | |
| 182 | 182 | enum vfio_notify_type type, |
| 183 | 183 | unsigned long *required_events, |
| 184 | 184 | struct notifier_block *nb); |
| 185 | −extern int vfio_unregister_notifier(struct device *dev, | |
| 185 | +extern int vfio_unregister_notifier(struct vfio_device *device, | |
| 186 | 186 | enum vfio_notify_type type, |
| 187 | 187 | struct notifier_block *nb); |
| 188 | 188 | |