aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vfio/pci/vfio_pci.c
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2013-06-10 18:40:57 -0400
committerAlex Williamson <alex.williamson@redhat.com>2013-07-24 18:36:41 -0400
commitd24cdbfd28b7e0ffecb1e281d73e73c03a57f734 (patch)
tree5121604d0025974356f09bb0027e018f1be05e03 /drivers/vfio/pci/vfio_pci.c
parentc64019302bbb0b445484d870e674ab34a19a18a1 (diff)
vfio-pci: Avoid deadlock on remove
If an attempt is made to unbind a device from vfio-pci while that device is in use, the request is blocked until the device becomes unused. Unfortunately, that unbind path still grabs the device_lock, which certain things like __pci_reset_function() also want to take. This means we need to try to acquire the locks ourselves and use the pre-locked version, __pci_reset_function_locked(). Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio/pci/vfio_pci.c')
-rw-r--r--drivers/vfio/pci/vfio_pci.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index c5179e269df6..cef6002acbd4 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -137,8 +137,27 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)
137 */ 137 */
138 pci_write_config_word(pdev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE); 138 pci_write_config_word(pdev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE);
139 139
140 if (vdev->reset_works) 140 /*
141 __pci_reset_function(pdev); 141 * Careful, device_lock may already be held. This is the case if
142 * a driver unbind is blocked. Try to get the locks ourselves to
143 * prevent a deadlock.
144 */
145 if (vdev->reset_works) {
146 bool reset_done = false;
147
148 if (pci_cfg_access_trylock(pdev)) {
149 if (device_trylock(&pdev->dev)) {
150 __pci_reset_function_locked(pdev);
151 reset_done = true;
152 device_unlock(&pdev->dev);
153 }
154 pci_cfg_access_unlock(pdev);
155 }
156
157 if (!reset_done)
158 pr_warn("%s: Unable to acquire locks for reset of %s\n",
159 __func__, dev_name(&pdev->dev));
160 }
142 161
143 pci_restore_state(pdev); 162 pci_restore_state(pdev);
144} 163}