Hi Jason,
On 2022/8/16 00:50, Jason Gunthorpe wrote:
This counts the number of devices attached to a vfio_group, ie the number
of items in the group->device_list.
yes. This dev_counter is added to ensure only singleton vfio group supports
pin page. Although I don't think it is a good approach as it only counts
the registered devices.
https://lore.kernel.org/kvm/1584035607-23166-8-git-send-email-kwankhede@xxxxxxxxxx/
It is only read in vfio_pin_pages(), however that function already does
vfio_assert_device_open(). Given an opened device has to already be
properly setup with a group, this test and variable are redundant. Remove
it.
But still have a doubt on your change. The vfio_assert_device_open() means
the input vfio_device is properly set up with a group. But it doesn't mean
the group is singleton. right? So your removal is not an apple to apple
replacement so far. Did I miss anything here? Perhaps this removal is good
cleanup but may be done with a different claim. :-)
Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
---
drivers/vfio/vfio_main.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 7cb56c382c97a2..76a73890d853e6 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -74,7 +74,6 @@ struct vfio_group {
struct list_head vfio_next;
struct list_head container_next;
enum vfio_group_type type;
- unsigned int dev_counter;
struct rw_semaphore group_rwsem;
struct kvm *kvm;
struct file *opened_file;
@@ -608,7 +607,6 @@ static int __vfio_register_dev(struct vfio_device *device,
mutex_lock(&group->device_lock);
list_add(&device->group_next, &group->device_list);
- group->dev_counter++;
mutex_unlock(&group->device_lock);
return 0;
@@ -696,7 +694,6 @@ void vfio_unregister_group_dev(struct vfio_device *device)
mutex_lock(&group->device_lock);
list_del(&device->group_next);
- group->dev_counter--;
mutex_unlock(&group->device_lock);
if (group->type == VFIO_NO_IOMMU || group->type == VFIO_EMULATED_IOMMU)
@@ -1961,9 +1958,6 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova,
if (npage > VFIO_PIN_PAGES_MAX_ENTRIES)
return -E2BIG;
- if (group->dev_counter > 1)
- return -EINVAL;
-
/* group->container cannot change while a vfio device is open */
container = group->container;
driver = container->iommu_driver;
base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
--
Regards,
Yi Liu