diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/main.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/kernel/main.c b/kernel/main.c index 8ba7083..c96357b 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -65,11 +65,43 @@ struct nv_vgpu_type_info g_vgpu_type_infos[16]; int g_num_vgpu_types = 0; static DEFINE_MUTEX(g_vgpu_type_lock); +/* + * get_available - report available instances for an mdev type. + * + * The mdev core's shared parent->available_instances counter can drift + * (e.g. if a remove path ever fails to complete). Compute availability + * from our own authoritative device list instead. + */ +static unsigned int nv_vgpu_get_available(struct mdev_type *mtype) +{ + struct nv_vgpu_type_info *info; + struct nv_vgpu_device *vgpu; + const char *name = mtype->sysfs_name; + unsigned int active = 0, max = 1; + + /* Type dirs may carry an extra "nvidia-" prefix vs our type names */ + if (str_has_prefix(name, "nvidia-")) + name += strlen("nvidia-"); + info = nv_vgpu_find_type_info(name); + if (info && info->max_instances) + max = info->max_instances; + + mutex_lock(&nv_vgpu_driver.lock); + list_for_each_entry(vgpu, &nv_vgpu_driver.devices, list) { + if (vgpu->mdev && vgpu->mdev->type == mtype) + active++; + } + mutex_unlock(&nv_vgpu_driver.lock); + + return active >= max ? 0 : max - active; +} + struct mdev_driver nv_vgpu_mdev_driver = { .device_api = VFIO_DEVICE_API_PCI_STRING, .max_instances = 8, .probe = nv_vgpu_mdev_create, .remove = nv_vgpu_mdev_remove, + .get_available = nv_vgpu_get_available, .driver = { .name = "nvidia-vgpu-vfio-mdev", }, |
