* [PATCH] PCI: Avoid possible deadlock on pci_lock and p->pi_lock
@ 2017-01-18 23:46 Bjorn Helgaas
2017-01-30 22:56 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Bjorn Helgaas @ 2017-01-18 23:46 UTC (permalink / raw)
To: linux-pci; +Cc: Jan Kiszka, linux-kernel, Matthew Wilcox
pci_lock is an IRQ-safe spinlock that protects all accesses to PCI
configuration space (see PCI_OP_READ() and PCI_OP_WRITE() in pci/access.c).
The pci_cfg_access_unlock() path acquires pci_lock, then p->pi_lock (inside
wake_up_all()). According to lockdep, there is a possible path involving
snbep_uncore_pci_read_counter() that could acquire them in the reverse
order: acquiring p->pi_lock, then pci_lock, which could result in a
deadlock. Lockdep details are in the bugzilla below.
Avoid the possible deadlock by dropping pci_lock before waking up any
config access waiters.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=192901
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/access.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index db239547fefd..68bd7201d8bc 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -684,8 +684,9 @@ void pci_cfg_access_unlock(struct pci_dev *dev)
WARN_ON(!dev->block_cfg_access);
dev->block_cfg_access = 0;
- wake_up_all(&pci_cfg_wait);
raw_spin_unlock_irqrestore(&pci_lock, flags);
+
+ wake_up_all(&pci_cfg_wait);
}
EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] PCI: Avoid possible deadlock on pci_lock and p->pi_lock
2017-01-18 23:46 [PATCH] PCI: Avoid possible deadlock on pci_lock and p->pi_lock Bjorn Helgaas
@ 2017-01-30 22:56 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2017-01-30 22:56 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, Jan Kiszka, linux-kernel, Matthew Wilcox
On Wed, Jan 18, 2017 at 05:46:12PM -0600, Bjorn Helgaas wrote:
> pci_lock is an IRQ-safe spinlock that protects all accesses to PCI
> configuration space (see PCI_OP_READ() and PCI_OP_WRITE() in pci/access.c).
>
> The pci_cfg_access_unlock() path acquires pci_lock, then p->pi_lock (inside
> wake_up_all()). According to lockdep, there is a possible path involving
> snbep_uncore_pci_read_counter() that could acquire them in the reverse
> order: acquiring p->pi_lock, then pci_lock, which could result in a
> deadlock. Lockdep details are in the bugzilla below.
>
> Avoid the possible deadlock by dropping pci_lock before waking up any
> config access waiters.
>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=192901
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Applied to pci/enumeration for v4.11.
> ---
> drivers/pci/access.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/access.c b/drivers/pci/access.c
> index db239547fefd..68bd7201d8bc 100644
> --- a/drivers/pci/access.c
> +++ b/drivers/pci/access.c
> @@ -684,8 +684,9 @@ void pci_cfg_access_unlock(struct pci_dev *dev)
> WARN_ON(!dev->block_cfg_access);
>
> dev->block_cfg_access = 0;
> - wake_up_all(&pci_cfg_wait);
> raw_spin_unlock_irqrestore(&pci_lock, flags);
> +
> + wake_up_all(&pci_cfg_wait);
> }
> EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-30 22:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-18 23:46 [PATCH] PCI: Avoid possible deadlock on pci_lock and p->pi_lock Bjorn Helgaas
2017-01-30 22:56 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).