Skip to content

Commit db7d4d7

Browse files
committed
vfio: Fix runaway interruptible timeout
Commit 13060b6 ("vfio: Add and use device request op for vfio bus drivers") incorrectly makes use of an interruptible timeout. When interrupted, the signal remains pending resulting in subsequent timeouts occurring instantly. This makes the loop spin at a much higher rate than intended. Instead of making this completely non-interruptible, we can change this into a sort of interruptible-once behavior and use the "once" to log debug information. The driver API doesn't allow us to abort and return an error code. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Fixes: 13060b6 Cc: stable@vger.kernel.org # v4.0
1 parent 5f55d2a commit db7d4d7

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

drivers/vfio/vfio.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ void *vfio_del_group_dev(struct device *dev)
710710
void *device_data = device->device_data;
711711
struct vfio_unbound_dev *unbound;
712712
unsigned int i = 0;
713+
long ret;
714+
bool interrupted = false;
713715

714716
/*
715717
* The group exists so long as we have a device reference. Get
@@ -755,9 +757,22 @@ void *vfio_del_group_dev(struct device *dev)
755757

756758
vfio_device_put(device);
757759

758-
} while (wait_event_interruptible_timeout(vfio.release_q,
759-
!vfio_dev_present(group, dev),
760-
HZ * 10) <= 0);
760+
if (interrupted) {
761+
ret = wait_event_timeout(vfio.release_q,
762+
!vfio_dev_present(group, dev), HZ * 10);
763+
} else {
764+
ret = wait_event_interruptible_timeout(vfio.release_q,
765+
!vfio_dev_present(group, dev), HZ * 10);
766+
if (ret == -ERESTARTSYS) {
767+
interrupted = true;
768+
dev_warn(dev,
769+
"Device is currently in use, task"
770+
" \"%s\" (%d) "
771+
"blocked until device is released",
772+
current->comm, task_pid_nr(current));
773+
}
774+
}
775+
} while (ret <= 0);
761776

762777
vfio_group_put(group);
763778

0 commit comments

Comments
 (0)