Message ID | 20230308132903.465159-10-yi.l.liu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | cover-letter: Add vfio_device cdev for iommufd support | expand |
> From: Liu, Yi L <yi.l.liu@intel.com> > Sent: Wednesday, March 8, 2023 9:29 PM > > @@ -2429,10 +2429,23 @@ static int vfio_pci_dev_set_hot_reset(struct > vfio_device_set *dev_set, > > list_for_each_entry(cur_vma, &dev_set->device_list, > vdev.dev_set_list) { > /* > - * Test whether all the affected devices are contained by the > + * Test whether all the affected devices can be reset by the > + * user. The affected devices may already been opened or > not > + * yet. > + * > + * For the devices not opened yet, user can reset them as it > + * reason is that the hot reset is done under the protection > + * of the dev_set->lock, and device open is also under this > + * lock. During the hot reset, such devices can not be opened > + * by other users. > + * > + * For the devices that have been opened, needs to check the > + * ownership. If the user provides a set of group fds, test > + * whether all the opened affected devices are contained by > the > * set of groups provided by the user. > */ * Test whether all the affected devices can be reset by the * user. * * Resetting an unused device (not opened) is safe, because * dev_set->lock is held in hot reset path so this device * cannot race being opened by another user simultaneously. * * Otherwise all opened devices in the dev_set must be * contained by the set of groups provided by the user. the rest looks good: Reviewed-by: Kevin Tian <kevin.tian@intel.com>
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 65bbef562268..f13b093557a9 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -2429,10 +2429,23 @@ static int vfio_pci_dev_set_hot_reset(struct vfio_device_set *dev_set, list_for_each_entry(cur_vma, &dev_set->device_list, vdev.dev_set_list) { /* - * Test whether all the affected devices are contained by the + * Test whether all the affected devices can be reset by the + * user. The affected devices may already been opened or not + * yet. + * + * For the devices not opened yet, user can reset them as it + * reason is that the hot reset is done under the protection + * of the dev_set->lock, and device open is also under this + * lock. During the hot reset, such devices can not be opened + * by other users. + * + * For the devices that have been opened, needs to check the + * ownership. If the user provides a set of group fds, test + * whether all the opened affected devices are contained by the * set of groups provided by the user. */ - if (!vfio_dev_in_groups(cur_vma, groups)) { + if (cur_vma->vdev.open_count && + !vfio_dev_in_groups(cur_vma, groups)) { ret = -EINVAL; goto err_undo; } diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 0552e8dcf0cb..f96e5689cffc 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -673,6 +673,14 @@ struct vfio_pci_hot_reset_info { * VFIO_DEVICE_PCI_HOT_RESET - _IOW(VFIO_TYPE, VFIO_BASE + 13, * struct vfio_pci_hot_reset) * + * Userspace requests hot reset for the devices it uses. Due to the + * underlying topology, multiple devices can be affected in the reset + * while some might be opened by another user. To avoid interference + * the calling user must ensure all affected devices, if opened, are + * owned by itself. + * + * The ownership is proved by an array of group fds. + * * Return: 0 on success, -errno on failure. */ struct vfio_pci_hot_reset {
If the affected device is not opened by any user, it is not necessary to check its ownership as it will not be opened by any user if a user is hot resetting a device within this dev_set. Signed-off-by: Yi Liu <yi.l.liu@intel.com> --- drivers/vfio/pci/vfio_pci_core.c | 17 +++++++++++++++-- include/uapi/linux/vfio.h | 8 ++++++++ 2 files changed, 23 insertions(+), 2 deletions(-)