vfio: Remove vfio_external_group_match_file()
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 4 May 2022 19:14:42 +0000 (16:14 -0300)
committerAlex Williamson <alex.williamson@redhat.com>
Fri, 13 May 2022 16:14:19 +0000 (10:14 -0600)
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().

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/4-v3-f7729924a7ea+25e33-vfio_kvm_no_group_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio.c
include/linux/vfio.h
virt/kvm/vfio.c

index 25f90f3773de9aa08f2218f96cc5fb25c072e976..4805e18f2272e2dac735afa9f5a058815fd4011c 100644 (file)
@@ -1685,15 +1685,6 @@ void vfio_group_put_external_user(struct vfio_group *group)
 }
 EXPORT_SYMBOL_GPL(vfio_group_put_external_user);
 
-bool vfio_external_group_match_file(struct vfio_group *test_group,
-                                   struct file *filep)
-{
-       struct vfio_group *group = filep->private_data;
-
-       return (filep->f_op == &vfio_group_fops) && (group == test_group);
-}
-EXPORT_SYMBOL_GPL(vfio_external_group_match_file);
-
 /**
  * vfio_file_iommu_group - Return the struct iommu_group for the vfio group file
  * @file: VFIO group file
index d8c34c8490cbbf67cae50f54b1212c7356191de4..df0adecdf1ea35ffaefcf3a6b1a240a1f89e393a 100644 (file)
@@ -138,8 +138,6 @@ int vfio_mig_get_next_state(struct vfio_device *device,
  */
 extern struct vfio_group *vfio_group_get_external_user(struct file *filep);
 extern void vfio_group_put_external_user(struct vfio_group *group);
-extern bool vfio_external_group_match_file(struct vfio_group *group,
-                                          struct file *filep);
 extern struct iommu_group *vfio_file_iommu_group(struct file *file);
 extern long vfio_external_check_extension(struct vfio_group *group,
                                          unsigned long arg);
index 9b7384dde158c14fe61a66ad53bc0be42c1afebe..0b84916c3f71a0b62dd07b963e1abc2a836f18e8 100644 (file)
@@ -49,22 +49,6 @@ static struct vfio_group *kvm_vfio_group_get_external_user(struct file *filep)
        return vfio_group;
 }
 
-static bool kvm_vfio_external_group_match_file(struct vfio_group *group,
-                                              struct file *filep)
-{
-       bool ret, (*fn)(struct vfio_group *, struct file *);
-
-       fn = symbol_get(vfio_external_group_match_file);
-       if (!fn)
-               return false;
-
-       ret = fn(group, filep);
-
-       symbol_put(vfio_external_group_match_file);
-
-       return ret;
-}
-
 static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group)
 {
        void (*fn)(struct vfio_group *);
@@ -239,8 +223,7 @@ static int kvm_vfio_group_del(struct kvm_device *dev, unsigned int fd)
        mutex_lock(&kv->lock);
 
        list_for_each_entry(kvg, &kv->group_list, node) {
-               if (!kvm_vfio_external_group_match_file(kvg->vfio_group,
-                                                       f.file))
+               if (kvg->file != f.file)
                        continue;
 
                list_del(&kvg->node);