Commit 21c13829 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson

vfio: Remove vfio_group dev_counter

This counts the number of devices attached to a vfio_group, ie the number
of items in the group->device_list.

It is only read in vfio_pin_pages(), as some kind of protection against
limitations in type1.

However, with all the code cleanups in this area, now that
vfio_pin_pages() accepts a vfio_device directly it is redundant.  All
drivers are already calling vfio_register_emulated_iommu_dev() which
directly creates a group specifically for the device and thus it is
guaranteed that there is a singleton group.

Leave a note in the comment about this requirement and remove the logic.
Reviewed-by: default avatarYi Liu <yi.l.liu@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/0-v2-d4374a7bf0c9+c4-vfio_dev_counter_jgg@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 453e6c98
...@@ -75,7 +75,6 @@ struct vfio_group { ...@@ -75,7 +75,6 @@ struct vfio_group {
struct list_head vfio_next; struct list_head vfio_next;
struct list_head container_next; struct list_head container_next;
enum vfio_group_type type; enum vfio_group_type type;
unsigned int dev_counter;
struct rw_semaphore group_rwsem; struct rw_semaphore group_rwsem;
struct kvm *kvm; struct kvm *kvm;
struct file *opened_file; struct file *opened_file;
...@@ -609,7 +608,6 @@ static int __vfio_register_dev(struct vfio_device *device, ...@@ -609,7 +608,6 @@ static int __vfio_register_dev(struct vfio_device *device,
mutex_lock(&group->device_lock); mutex_lock(&group->device_lock);
list_add(&device->group_next, &group->device_list); list_add(&device->group_next, &group->device_list);
group->dev_counter++;
mutex_unlock(&group->device_lock); mutex_unlock(&group->device_lock);
return 0; return 0;
...@@ -697,7 +695,6 @@ void vfio_unregister_group_dev(struct vfio_device *device) ...@@ -697,7 +695,6 @@ void vfio_unregister_group_dev(struct vfio_device *device)
mutex_lock(&group->device_lock); mutex_lock(&group->device_lock);
list_del(&device->group_next); list_del(&device->group_next);
group->dev_counter--;
mutex_unlock(&group->device_lock); mutex_unlock(&group->device_lock);
if (group->type == VFIO_NO_IOMMU || group->type == VFIO_EMULATED_IOMMU) if (group->type == VFIO_NO_IOMMU || group->type == VFIO_EMULATED_IOMMU)
...@@ -1991,6 +1988,9 @@ EXPORT_SYMBOL(vfio_set_irqs_validate_and_prepare); ...@@ -1991,6 +1988,9 @@ EXPORT_SYMBOL(vfio_set_irqs_validate_and_prepare);
* @prot [in] : protection flags * @prot [in] : protection flags
* @pages[out] : array of host pages * @pages[out] : array of host pages
* Return error or number of pages pinned. * Return error or number of pages pinned.
*
* A driver may only call this function if the vfio_device was created
* by vfio_register_emulated_iommu_dev().
*/ */
int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova,
int npage, int prot, struct page **pages) int npage, int prot, struct page **pages)
...@@ -2006,9 +2006,6 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, ...@@ -2006,9 +2006,6 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova,
if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) if (npage > VFIO_PIN_PAGES_MAX_ENTRIES)
return -E2BIG; return -E2BIG;
if (group->dev_counter > 1)
return -EINVAL;
/* group->container cannot change while a vfio device is open */ /* group->container cannot change while a vfio device is open */
container = group->container; container = group->container;
driver = container->iommu_driver; driver = container->iommu_driver;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment