From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Williamson Subject: [PATCH 1/2] vfio: Flush signals on device request interruption Date: Tue, 14 Apr 2015 12:14:45 -0600 Message-ID: <20150414181445.6081.32372.stgit@gimli.home> References: <20150414180228.6081.10459.stgit@gimli.home> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org To: alex.williamson@redhat.com Return-path: In-Reply-To: <20150414180228.6081.10459.stgit@gimli.home> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org Signals don't just interrupt our wait, they remain pending such that subsequent wait_events timeout immediately. This can cause a CPU to spin with a single signal. Flush signals if we receive an interruption and also log information about the reason the task is blocked. Signed-off-by: Alex Williamson Cc: stable@vger.kernel.org # v4.0 --- drivers/vfio/vfio.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 0d33662..4c786d4 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -710,6 +710,7 @@ void *vfio_del_group_dev(struct device *dev) void *device_data = device->device_data; struct vfio_unbound_dev *unbound; unsigned int i = 0; + long ret; /* * The group exists so long as we have a device reference. Get @@ -755,9 +756,15 @@ void *vfio_del_group_dev(struct device *dev) vfio_device_put(device); - } while (wait_event_interruptible_timeout(vfio.release_q, - !vfio_dev_present(group, dev), - HZ * 10) <= 0); + ret = wait_event_interruptible_timeout(vfio.release_q, + !vfio_dev_present(group, dev), HZ * 10); + if (ret == -ERESTARTSYS) { + flush_signals(current); + dev_warn_ratelimited(dev, "Device is currently in use, task \"%s\" (%d) blocked until device is released", + current->comm, + task_pid_nr(current)); + } + } while (ret <= 0); vfio_group_put(group);