Skip to content

Commit 5cd189e

Browse files
anthonydeAlex Williamson
authored andcommitted
vfio: Export the device set open count
The open count of a device set is the sum of the open counts of all devices in the set. Drivers can use this value to determine whether shared resources are in use without tracking them manually or accessing the private open_count in vfio_device. Signed-off-by: Anthony DeRossi <ajderossi@gmail.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Link: https://lore.kernel.org/r/20221110014027.28780-3-ajderossi@gmail.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 7fdba00 commit 5cd189e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

drivers/vfio/vfio_main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ static void vfio_release_device_set(struct vfio_device *device)
125125
xa_unlock(&vfio_device_set_xa);
126126
}
127127

128+
unsigned int vfio_device_set_open_count(struct vfio_device_set *dev_set)
129+
{
130+
struct vfio_device *cur;
131+
unsigned int open_count = 0;
132+
133+
lockdep_assert_held(&dev_set->lock);
134+
135+
list_for_each_entry(cur, &dev_set->device_list, dev_set_list)
136+
open_count += cur->open_count;
137+
return open_count;
138+
}
139+
EXPORT_SYMBOL_GPL(vfio_device_set_open_count);
140+
128141
/*
129142
* Group objects - create, release, get, put, search
130143
*/

include/linux/vfio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ int vfio_register_emulated_iommu_dev(struct vfio_device *device);
189189
void vfio_unregister_group_dev(struct vfio_device *device);
190190

191191
int vfio_assign_device_set(struct vfio_device *device, void *set_id);
192+
unsigned int vfio_device_set_open_count(struct vfio_device_set *dev_set);
192193

193194
int vfio_mig_get_next_state(struct vfio_device *device,
194195
enum vfio_device_mig_state cur_fsm,

0 commit comments

Comments
 (0)