Skip to content

Commit 2a7e32d

Browse files
committed
PCI: Fix pci_cfg_wait queue locking problem
The pci_cfg_wait queue is used to prevent user-space config accesses to devices while they are recovering from reset. Previously we used these operations on pci_cfg_wait: __add_wait_queue(&pci_cfg_wait, ...) __remove_wait_queue(&pci_cfg_wait, ...) wake_up_all(&pci_cfg_wait) The wake_up acquires the wait queue lock, but the add and remove do not. Originally these were all protected by the pci_lock, but cdcb33f ("PCI: Avoid possible deadlock on pci_lock and p->pi_lock"), moved wake_up_all() outside pci_lock, so it could race with add/remove operations, which caused occasional kernel panics, e.g., during vfio-pci hotplug/unplug testing: Unable to handle kernel read from unreadable memory at virtual address ffff802dac469000 Resolve this by using wait_event() instead of __add_wait_queue() and __remove_wait_queue(). The wait queue lock is held by both wait_event() and wake_up_all(), so it provides mutual exclusion. Fixes: cdcb33f ("PCI: Avoid possible deadlock on pci_lock and p->pi_lock") Link: https://lore.kernel.org/linux-pci/[email protected]/T/#u Based-on: https://lore.kernel.org/linux-pci/[email protected]/ Based-on-patch-by: Xiang Zheng <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Tested-by: Xiang Zheng <[email protected]> Cc: Heyi Guo <[email protected]> Cc: Biaoxiang Ye <[email protected]>
1 parent b3a9e3b commit 2a7e32d

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

drivers/pci/access.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,13 @@ EXPORT_SYMBOL(pci_bus_set_ops);
204204
static DECLARE_WAIT_QUEUE_HEAD(pci_cfg_wait);
205205

206206
static noinline void pci_wait_cfg(struct pci_dev *dev)
207+
__must_hold(&pci_lock)
207208
{
208-
DECLARE_WAITQUEUE(wait, current);
209-
210-
__add_wait_queue(&pci_cfg_wait, &wait);
211209
do {
212-
set_current_state(TASK_UNINTERRUPTIBLE);
213210
raw_spin_unlock_irq(&pci_lock);
214-
schedule();
211+
wait_event(pci_cfg_wait, !dev->block_cfg_access);
215212
raw_spin_lock_irq(&pci_lock);
216213
} while (dev->block_cfg_access);
217-
__remove_wait_queue(&pci_cfg_wait, &wait);
218214
}
219215

220216
/* Returns 0 on success, negative values indicate error. */

0 commit comments

Comments
 (0)