[PATCH v3 10/12] vfio: Mark cdev usage in vfio_device

Yi Liu
2023-04-01T14:44:43Z

There are users that need to check if vfio_device is opened as cdev.
e.g. vfio-pci. This adds a flag in vfio_device, it will be set in the
cdev path when device is opened. This is not used at this moment, but
a preparation for vfio device cdev support.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
include/linux/vfio.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index f8fb9ab25188..d9a0770e5fc1 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -62,6 +62,7 @@ struct vfio_device {
struct iommufd_device *iommufd_device;
bool iommufd_attached;
#endif
+ bool cdev_opened;
};

/**
@@ -151,6 +152,12 @@ vfio_iommufd_physical_devid(struct vfio_device *vdev, u32 *id)
((int (*)(struct vfio_device *vdev, u32 *pt_id)) NULL)
#endif

+static inline bool vfio_device_cdev_opened(struct vfio_device *device)
+{
+ lockdep_assert_held(&device->dev_set->lock);
+ return device->cdev_opened;
+}
+
/**
* @migration_set_state: Optional callback to change the migration state for
* devices that support migration. It's mandatory for
--
2.34.1