vfio_group_fops_open() ensures there is only ever one struct file open for any struct vfio_group at any time: /* Do we need multiple instances of the group open? Seems not. */ opened = atomic_cmpxchg(&group->opened, 0, 1); if (opened) { vfio_group_put(group); return -EBUSY; Therefor the struct file * can be used directly to search the list of VFIO groups that KVM keeps instead of using the vfio_external_group_match_file() callback to try to figure out if the passed in FD matches the list or not. Delete vfio_external_group_match_file().
Unified · Split
| @@ -1685,15 +1685,6 @@ void vfio_group_put_external_user(struct vfio_group *group) · 1684 unmodified lines | |||
| 1685 | } | 1685 | } |
| 1686 | EXPORT_SYMBOL_GPL(vfio_group_put_external_user); | 1686 | EXPORT_SYMBOL_GPL(vfio_group_put_external_user); |
| 1687 | 1687 | ||
| 1688 | bool vfio_external_group_match_file(struct vfio_group *test_group, | ||
| 1689 | struct file *filep) | ||
| 1690 | { | ||
| 1691 | struct vfio_group *group = filep->private_data; | ||
| 1692 | |||
| 1693 | return (filep->f_op == &vfio_group_fops) && (group == test_group); | ||
| 1694 | } | ||
| 1695 | EXPORT_SYMBOL_GPL(vfio_external_group_match_file); | ||
| 1696 | |||
| 1697 | /** | 1688 | /** |
| 1698 | * vfio_file_iommu_group - Return the struct iommu_group for the vfio group file | 1689 | * vfio_file_iommu_group - Return the struct iommu_group for the vfio group file |
| 1699 | * @file: VFIO group file | 1690 | * @file: VFIO group file |
| @@ -138,8 +138,6 @@ int vfio_mig_get_next_state(struct vfio_device *device, · 137 unmodified lines | |||
| 138 | */ | 138 | */ |
| 139 | extern struct vfio_group *vfio_group_get_external_user(struct file *filep); | 139 | extern struct vfio_group *vfio_group_get_external_user(struct file *filep); |
| 140 | extern void vfio_group_put_external_user(struct vfio_group *group); | 140 | extern void vfio_group_put_external_user(struct vfio_group *group); |
| 141 | extern bool vfio_external_group_match_file(struct vfio_group *group, | ||
| 142 | struct file *filep); | ||
| 143 | extern struct iommu_group *vfio_file_iommu_group(struct file *file); | 141 | extern struct iommu_group *vfio_file_iommu_group(struct file *file); |
| 144 | extern long vfio_external_check_extension(struct vfio_group *group, | 142 | extern long vfio_external_check_extension(struct vfio_group *group, |
| 145 | unsigned long arg); | 143 | unsigned long arg); |
| @@ -49,22 +49,6 @@ static struct vfio_group *kvm_vfio_group_get_external_user(struct file *filep) · 48 unmodified lines | |||
| 49 | return vfio_group; | 49 | return vfio_group; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | static bool kvm_vfio_external_group_match_file(struct vfio_group *group, | ||
| 53 | struct file *filep) | ||
| 54 | { | ||
| 55 | bool ret, (*fn)(struct vfio_group *, struct file *); | ||
| 56 | |||
| 57 | fn = symbol_get(vfio_external_group_match_file); | ||
| 58 | if (!fn) | ||
| 59 | return false; | ||
| 60 | |||
| 61 | ret = fn(group, filep); | ||
| 62 | |||
| 63 | symbol_put(vfio_external_group_match_file); | ||
| 64 | |||
| 65 | return ret; | ||
| 66 | } | ||
| 67 | |||
| 68 | static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group) | 52 | static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group) |
| 69 | { | 53 | { |
| 70 | void (*fn)(struct vfio_group *); | 54 | void (*fn)(struct vfio_group *); |
| @@ -239,8 +223,7 @@ static int kvm_vfio_group_del(struct kvm_device *dev, unsigned int fd) · 168 unmodified lines | |||
| 239 | mutex_lock(&kv->lock); | 223 | mutex_lock(&kv->lock); |
| 240 | 224 | ||
| 241 | list_for_each_entry(kvg, &kv->group_list, node) { | 225 | list_for_each_entry(kvg, &kv->group_list, node) { |
| 242 | if (!kvm_vfio_external_group_match_file(kvg->vfio_group, | 226 | if (kvg->file != f.file) |
| 243 | f.file)) | ||
| 244 | continue; | 227 | continue; |
| 245 | 228 | ||
| 246 | list_del(&kvg->node); | 229 | list_del(&kvg->node); |