Commit 8b0219e3 authored by Alex Williamson's avatar Alex Williamson Committed by Greg Kroah-Hartman

vfio: Rework group release notifier warning

commit 65b1adeb upstream.

The intent of the original warning is make sure that the mdev vendor
driver has removed any group notifiers at the point where the group
is closed by the user.  Theoretically this would be through an
orderly shutdown where any devices are release prior to the group
release.  We can't always count on an orderly shutdown, the user can
close the group before the notifier can be removed or the user task
might be killed.  We'd like to add this sanity test when the group is
idle and the only references are from the devices within the group
themselves, but we don't have a good way to do that.  Instead check
both when the group itself is removed and when the group is opened.
A bit later than we'd prefer, but better than the current over
aggressive approach.

Fixes: ccd46dba ("vfio: support notifier chain in vfio_group")
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Cc: Jike Song <jike.song@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0d05871e
...@@ -403,6 +403,7 @@ static void vfio_group_release(struct kref *kref) ...@@ -403,6 +403,7 @@ static void vfio_group_release(struct kref *kref)
struct iommu_group *iommu_group = group->iommu_group; struct iommu_group *iommu_group = group->iommu_group;
WARN_ON(!list_empty(&group->device_list)); WARN_ON(!list_empty(&group->device_list));
WARN_ON(group->notifier.head);
list_for_each_entry_safe(unbound, tmp, list_for_each_entry_safe(unbound, tmp,
&group->unbound_list, unbound_next) { &group->unbound_list, unbound_next) {
...@@ -1573,6 +1574,10 @@ static int vfio_group_fops_open(struct inode *inode, struct file *filep) ...@@ -1573,6 +1574,10 @@ static int vfio_group_fops_open(struct inode *inode, struct file *filep)
return -EBUSY; return -EBUSY;
} }
/* Warn if previous user didn't cleanup and re-init to drop them */
if (WARN_ON(group->notifier.head))
BLOCKING_INIT_NOTIFIER_HEAD(&group->notifier);
filep->private_data = group; filep->private_data = group;
return 0; return 0;
...@@ -1584,9 +1589,6 @@ static int vfio_group_fops_release(struct inode *inode, struct file *filep) ...@@ -1584,9 +1589,6 @@ static int vfio_group_fops_release(struct inode *inode, struct file *filep)
filep->private_data = NULL; filep->private_data = NULL;
/* Any user didn't unregister? */
WARN_ON(group->notifier.head);
vfio_group_try_dissolve_container(group); vfio_group_try_dissolve_container(group);
atomic_dec(&group->opened); atomic_dec(&group->opened);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment