diff mbox series

[06/10] vfio: Remove vfio_external_group_match_file()

Message ID 6-v1-33906a626da1+16b0-vfio_kvm_no_group_jgg@nvidia.com (mailing list archive)
State New, archived
Headers show
Series Remove vfio_group from the struct file facing VFIO API | expand

Commit Message

Jason Gunthorpe April 14, 2022, 6:46 p.m. UTC
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().

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/vfio.c  |  9 ---------
 include/linux/vfio.h |  2 --
 virt/kvm/vfio.c      | 19 +------------------
 3 files changed, 1 insertion(+), 29 deletions(-)

Comments

Tian, Kevin April 15, 2022, 4:02 a.m. UTC | #1
> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Friday, April 15, 2022 2:46 AM
> 
> 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().
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

> ---
>  drivers/vfio/vfio.c  |  9 ---------
>  include/linux/vfio.h |  2 --
>  virt/kvm/vfio.c      | 19 +------------------
>  3 files changed, 1 insertion(+), 29 deletions(-)
> 
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 4d62de69705573..eb65b4c80ece64 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -1989,15 +1989,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 file
>   * @filep: VFIO file
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index e5ca7d5a0f1584..d09a1856d4e5ea 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -145,8 +145,6 @@ extern struct vfio_group
> *vfio_group_get_external_user(struct file *filep);
>  extern void vfio_group_put_external_user(struct vfio_group *group);
>  extern struct vfio_group *vfio_group_get_external_user_from_dev(struct
> device
>  								*dev);
> -extern bool vfio_external_group_match_file(struct vfio_group *group,
> -					   struct file *filep);
>  extern long vfio_external_check_extension(struct vfio_group *group,
>  					  unsigned long arg);
>  const struct vfio_file_ops *vfio_file_get_ops(struct file *filep);
> diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
> index 743e4870fa1825..955cabc0683b29 100644
> --- a/virt/kvm/vfio.c
> +++ b/virt/kvm/vfio.c
> @@ -60,22 +60,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 *);
> @@ -244,8 +228,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->filp != f.file)
>  			continue;
> 
>  		list_del(&kvg->node);
> --
> 2.35.1
Christoph Hellwig April 15, 2022, 7:32 a.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 4d62de69705573..eb65b4c80ece64 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -1989,15 +1989,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 file
  * @filep: VFIO file
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index e5ca7d5a0f1584..d09a1856d4e5ea 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -145,8 +145,6 @@  extern struct vfio_group *vfio_group_get_external_user(struct file *filep);
 extern void vfio_group_put_external_user(struct vfio_group *group);
 extern struct vfio_group *vfio_group_get_external_user_from_dev(struct device
 								*dev);
-extern bool vfio_external_group_match_file(struct vfio_group *group,
-					   struct file *filep);
 extern long vfio_external_check_extension(struct vfio_group *group,
 					  unsigned long arg);
 const struct vfio_file_ops *vfio_file_get_ops(struct file *filep);
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index 743e4870fa1825..955cabc0683b29 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -60,22 +60,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 *);
@@ -244,8 +228,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->filp != f.file)
 			continue;
 
 		list_del(&kvg->node);