mirror of
https://github.com/lkl/linux.git
synced 2025-12-19 16:13:19 +09:00
vfio/mdev: add mdev available instance checking to the core
Many of the mdev drivers use a simple counter for keeping track of the available instances. Move this code to the core code and store the counter in the mdev_parent. Implement it using correct locking, fixing mdpy. Drivers just provide the value in the mdev_driver at registration time and the core code takes care of maintaining it and exposing the value in sysfs. [hch: count instances per-parent instead of per-type, use an atomic_t to avoid taking mdev_list_lock in the show method] Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com> Reviewed-by: Eric Farman <farman@linux.ibm.com> Link: https://lore.kernel.org/r/20220923092652.100656-15-hch@lst.de Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
committed by
Alex Williamson
parent
685a1537f4
commit
9c799c224d
@@ -45,6 +45,7 @@ struct mdev_parent {
|
||||
struct rw_semaphore unreg_sem;
|
||||
struct mdev_type **types;
|
||||
unsigned int nr_types;
|
||||
atomic_t available_instances;
|
||||
};
|
||||
|
||||
static inline struct mdev_device *to_mdev_device(struct device *dev)
|
||||
@@ -55,6 +56,7 @@ static inline struct mdev_device *to_mdev_device(struct device *dev)
|
||||
/**
|
||||
* struct mdev_driver - Mediated device driver
|
||||
* @device_api: string to return for the device_api sysfs
|
||||
* @max_instances: maximum number of instances supported (optional)
|
||||
* @probe: called when new device created
|
||||
* @remove: called when device removed
|
||||
* @get_available: Return the max number of instances that can be created
|
||||
@@ -63,6 +65,7 @@ static inline struct mdev_device *to_mdev_device(struct device *dev)
|
||||
**/
|
||||
struct mdev_driver {
|
||||
const char *device_api;
|
||||
unsigned int max_instances;
|
||||
int (*probe)(struct mdev_device *dev);
|
||||
void (*remove)(struct mdev_device *dev);
|
||||
unsigned int (*get_available)(struct mdev_type *mtype);
|
||||
|
||||
Reference in New Issue
Block a user