From: Govindarajulu Varadarajan <gvaradar@cisco.com>
To: benve@cisco.com, bhelgaas@google.com, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org, jlbec@evilplan.org, hch@lst.de,
mingo@redhat.com, peterz@infradead.org
Cc: Govindarajulu Varadarajan <gvaradar@cisco.com>
Subject: [PATCH 2/4] pci: code refactor pci_bus_lock/unlock/trylock
Date: Wed, 27 Sep 2017 14:42:18 -0700 [thread overview]
Message-ID: <20170927214220.41216-3-gvaradar@cisco.com> (raw)
In-Reply-To: <20170927214220.41216-1-gvaradar@cisco.com>
Introduce __pci_bus_trylock and __pci_bus_unlock with lock and unlock cb
functions as arguments. User can pass on what they want to lock in pci_dev.
Signed-off-by: Govindarajulu Varadarajan <gvaradar@cisco.com>
---
drivers/pci/pci.c | 38 +++++++++++++++++++++++++++-----------
include/linux/pci.h | 16 ++++++++++++++++
2 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 6078dfc11b11..3c6a9210f27c 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -4377,29 +4377,38 @@ static void pci_bus_lock(struct pci_bus *bus)
}
}
-/* Unlock devices from the bottom of the tree up */
-static void pci_bus_unlock(struct pci_bus *bus)
+void __pci_bus_unlock(struct pci_bus *bus,
+ void (*unlock)(struct pci_dev *dev))
{
struct pci_dev *dev;
list_for_each_entry(dev, &bus->devices, bus_list) {
if (dev->subordinate)
- pci_bus_unlock(dev->subordinate);
- pci_dev_unlock(dev);
+ __pci_bus_unlock(dev->subordinate, unlock);
+ unlock(dev);
}
}
+EXPORT_SYMBOL_GPL(__pci_bus_unlock);
-/* Return 1 on successful lock, 0 on contention */
-static int pci_bus_trylock(struct pci_bus *bus)
+/* Unlock devices from the bottom of the tree up */
+static void pci_bus_unlock(struct pci_bus *bus)
+{
+ __pci_bus_unlock(bus, pci_dev_unlock);
+}
+
+int __pci_bus_trylock(struct pci_bus *bus,
+ int (*lock)(struct pci_dev *dev),
+ void (*unlock)(struct pci_dev *dev))
{
struct pci_dev *dev;
list_for_each_entry(dev, &bus->devices, bus_list) {
- if (!pci_dev_trylock(dev))
+ if (!lock(dev))
goto unlock;
if (dev->subordinate) {
- if (!pci_bus_trylock(dev->subordinate)) {
- pci_dev_unlock(dev);
+ if (!__pci_bus_trylock(dev->subordinate, lock,
+ unlock)) {
+ unlock(dev);
goto unlock;
}
}
@@ -4409,11 +4418,18 @@ static int pci_bus_trylock(struct pci_bus *bus)
unlock:
list_for_each_entry_continue_reverse(dev, &bus->devices, bus_list) {
if (dev->subordinate)
- pci_bus_unlock(dev->subordinate);
- pci_dev_unlock(dev);
+ __pci_bus_unlock(dev->subordinate, unlock);
+ unlock(dev);
}
return 0;
}
+EXPORT_SYMBOL_GPL(__pci_bus_trylock);
+
+/* Return 1 on successful lock, 0 on contention */
+static int pci_bus_trylock(struct pci_bus *bus)
+{
+ return __pci_bus_trylock(bus, pci_dev_trylock, pci_dev_unlock);
+}
/* Do any devices on or below this slot prevent a bus reset? */
static bool pci_slot_resetable(struct pci_slot *slot)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index b4b1a8a164c0..33359c64cd2e 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1515,6 +1515,22 @@ void pci_cfg_access_lock(struct pci_dev *dev);
bool pci_cfg_access_trylock(struct pci_dev *dev);
void pci_cfg_access_unlock(struct pci_dev *dev);
+void __pci_bus_unlock(struct pci_bus *bus,
+ void (*unlock)(struct pci_dev *dev));
+int __pci_bus_trylock(struct pci_bus *bus,
+ int (*lock)(struct pci_dev *dev),
+ void (*unlock)(struct pci_dev *dev));
+static inline int pci_device_trylock(struct pci_dev *dev)
+{
+ return device_trylock(&dev->dev);
+}
+
+static inline void pci_device_unlock(struct pci_dev *dev)
+{
+ device_unlock(&dev->dev);
+}
+
+
/*
* PCI domain support. Sometimes called PCI segment (eg by ACPI),
* a PCI domain is defined to be a set of PCI buses which share
--
2.14.1
next prev parent reply other threads:[~2017-09-27 21:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 21:42 [PATCH 0/4] pci aer: fix deadlock in do_recovery Govindarajulu Varadarajan
2017-09-27 21:42 ` [PATCH 1/4] pci: introduce __pci_walk_bus for caller with pci_bus_sem held Govindarajulu Varadarajan
2017-09-28 16:12 ` Sinan Kaya
2017-09-28 23:52 ` Govindarajulu Varadarajan
2017-09-27 21:42 ` Govindarajulu Varadarajan [this message]
2017-09-27 21:42 ` [PATCH 3/4] pci aer: fix deadlock in do_recovery Govindarajulu Varadarajan
2017-09-28 16:47 ` Sinan Kaya
2017-09-28 23:46 ` Govindarajulu Varadarajan
2017-09-29 13:32 ` Sinan Kaya
2017-09-30 6:00 ` Govindarajulu Varadarajan
2017-09-27 21:42 ` [PATCH 4/4] lockdep: make MAX_LOCK_DEPTH configurable from Kconfig Govindarajulu Varadarajan
2017-09-28 9:26 ` Peter Zijlstra
2017-09-28 23:51 ` Govindarajulu Varadarajan
2017-09-29 16:23 ` Bjorn Helgaas
2017-09-30 6:03 ` Govindarajulu Varadarajan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170927214220.41216-3-gvaradar@cisco.com \
--to=gvaradar@cisco.com \
--cc=benve@cisco.com \
--cc=bhelgaas@google.com \
--cc=hch@lst.de \
--cc=jlbec@evilplan.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®