]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.10.7/vfio-rework-group-release-notifier-warning.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.10.7 / vfio-rework-group-release-notifier-warning.patch
1 From 65b1adebfe43c642dfe3b109edb5d992db5fbe72 Mon Sep 17 00:00:00 2001
2 From: Alex Williamson <alex.williamson@redhat.com>
3 Date: Tue, 21 Mar 2017 13:19:09 -0600
4 Subject: vfio: Rework group release notifier warning
5
6 From: Alex Williamson <alex.williamson@redhat.com>
7
8 commit 65b1adebfe43c642dfe3b109edb5d992db5fbe72 upstream.
9
10 The intent of the original warning is make sure that the mdev vendor
11 driver has removed any group notifiers at the point where the group
12 is closed by the user. Theoretically this would be through an
13 orderly shutdown where any devices are release prior to the group
14 release. We can't always count on an orderly shutdown, the user can
15 close the group before the notifier can be removed or the user task
16 might be killed. We'd like to add this sanity test when the group is
17 idle and the only references are from the devices within the group
18 themselves, but we don't have a good way to do that. Instead check
19 both when the group itself is removed and when the group is opened.
20 A bit later than we'd prefer, but better than the current over
21 aggressive approach.
22
23 Fixes: ccd46dbae77d ("vfio: support notifier chain in vfio_group")
24 Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
25 Cc: Jike Song <jike.song@intel.com>
26 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
27
28 ---
29 drivers/vfio/vfio.c | 8 +++++---
30 1 file changed, 5 insertions(+), 3 deletions(-)
31
32 --- a/drivers/vfio/vfio.c
33 +++ b/drivers/vfio/vfio.c
34 @@ -403,6 +403,7 @@ static void vfio_group_release(struct kr
35 struct iommu_group *iommu_group = group->iommu_group;
36
37 WARN_ON(!list_empty(&group->device_list));
38 + WARN_ON(group->notifier.head);
39
40 list_for_each_entry_safe(unbound, tmp,
41 &group->unbound_list, unbound_next) {
42 @@ -1573,6 +1574,10 @@ static int vfio_group_fops_open(struct i
43 return -EBUSY;
44 }
45
46 + /* Warn if previous user didn't cleanup and re-init to drop them */
47 + if (WARN_ON(group->notifier.head))
48 + BLOCKING_INIT_NOTIFIER_HEAD(&group->notifier);
49 +
50 filep->private_data = group;
51
52 return 0;
53 @@ -1584,9 +1589,6 @@ static int vfio_group_fops_release(struc
54
55 filep->private_data = NULL;
56
57 - /* Any user didn't unregister? */
58 - WARN_ON(group->notifier.head);
59 -
60 vfio_group_try_dissolve_container(group);
61
62 atomic_dec(&group->opened);