Skip to content

Commit 7870f63

Browse files
author
Alex Williamson
committed
vfio: Export the device set open count
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2155664 Conflicts: Context, container code has not yet been split out via cdc71fe ("vfio: Move container code into drivers/vfio/container.c") commit 5cd189e Author: Anthony DeRossi <ajderossi@gmail.com> Date: Wed Nov 9 17:40:26 2022 -0800 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> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 2682d4e commit 7870f63

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
@@ -302,6 +302,19 @@ static void vfio_container_put(struct vfio_container *container)
302302
kref_put(&container->kref, vfio_container_release);
303303
}
304304

305+
unsigned int vfio_device_set_open_count(struct vfio_device_set *dev_set)
306+
{
307+
struct vfio_device *cur;
308+
unsigned int open_count = 0;
309+
310+
lockdep_assert_held(&dev_set->lock);
311+
312+
list_for_each_entry(cur, &dev_set->device_list, dev_set_list)
313+
open_count += cur->open_count;
314+
return open_count;
315+
}
316+
EXPORT_SYMBOL_GPL(vfio_device_set_open_count);
317+
305318
/*
306319
* Group objects - create, release, get, put, search
307320
*/

include/linux/vfio.h

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

147147
int vfio_assign_device_set(struct vfio_device *device, void *set_id);
148+
unsigned int vfio_device_set_open_count(struct vfio_device_set *dev_set);
148149

149150
int vfio_mig_get_next_state(struct vfio_device *device,
150151
enum vfio_device_mig_state cur_fsm,

0 commit comments

Comments
 (0)