From: Kishon Vijay Abraham I <kishon@ti.com>
To: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Andrew Murray <amurray@thegoodpenguin.co.uk>,
Vidya Sagar <vidyas@nvidia.com>,
Athani Nadeem Ladkhan <nadeem@cadence.com>,
Tom Joseph <tjoseph@cadence.com>
Cc: <linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Kishon Vijay Abraham I <kishon@ti.com>
Subject: [PATCH v2 4/5] PCI: endpoint: Protect concurrent access to pci_epf_ops with mutex
Date: Wed, 12 Feb 2020 16:55:13 +0530 [thread overview]
Message-ID: <20200212112514.2000-5-kishon@ti.com> (raw)
In-Reply-To: <20200212112514.2000-1-kishon@ti.com>
Protect concurrent access to pci_epf_ops with mutex.
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
drivers/pci/endpoint/pci-epf-core.c | 11 ++++++++++-
include/linux/pci-epf.h | 3 +++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 93f28c65ace0..6e0648991b5c 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -35,7 +35,9 @@ void pci_epf_unbind(struct pci_epf *epf)
return;
}
+ mutex_lock(&epf->lock);
epf->driver->ops->unbind(epf);
+ mutex_unlock(&epf->lock);
module_put(epf->driver->owner);
}
EXPORT_SYMBOL_GPL(pci_epf_unbind);
@@ -49,6 +51,8 @@ EXPORT_SYMBOL_GPL(pci_epf_unbind);
*/
int pci_epf_bind(struct pci_epf *epf)
{
+ int ret;
+
if (!epf->driver) {
dev_WARN(&epf->dev, "epf device not bound to driver\n");
return -EINVAL;
@@ -57,7 +61,11 @@ int pci_epf_bind(struct pci_epf *epf)
if (!try_module_get(epf->driver->owner))
return -EAGAIN;
- return epf->driver->ops->bind(epf);
+ mutex_lock(&epf->lock);
+ ret = epf->driver->ops->bind(epf);
+ mutex_unlock(&epf->lock);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(pci_epf_bind);
@@ -252,6 +260,7 @@ struct pci_epf *pci_epf_create(const char *name)
device_initialize(dev);
dev->bus = &pci_epf_bus_type;
dev->type = &pci_epf_type;
+ mutex_init(&epf->lock);
ret = dev_set_name(dev, "%s", name);
if (ret) {
diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h
index 4993f7f6439b..bcdf4f07bde7 100644
--- a/include/linux/pci-epf.h
+++ b/include/linux/pci-epf.h
@@ -110,6 +110,7 @@ struct pci_epf_bar {
* @driver: the EPF driver to which this EPF device is bound
* @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
* @nb: notifier block to notify EPF of any EPC events (like linkup)
+ * @lock: mutex to protect pci_epf_ops
*/
struct pci_epf {
struct device dev;
@@ -124,6 +125,8 @@ struct pci_epf {
struct pci_epf_driver *driver;
struct list_head list;
struct notifier_block nb;
+ /* mutex to protect against concurrent access of pci_epf_ops */
+ struct mutex lock;
};
#define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
--
2.17.1
next prev parent reply other threads:[~2020-02-12 11:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-12 11:25 [PATCH v2 0/5] PCI: Endpoint: Miscellaneous improvements Kishon Vijay Abraham I
2020-02-12 11:25 ` [PATCH v2 1/5] PCI: endpoint: Use notification chain mechanism to notify EPC events to EPF Kishon Vijay Abraham I
2020-02-17 12:14 ` Vidya Sagar
2020-02-12 11:25 ` [PATCH v2 2/5] PCI: endpoint: Replace spinlock with mutex Kishon Vijay Abraham I
2021-06-11 9:52 ` Vidya Sagar
2021-06-20 13:21 ` Vidya Sagar
2021-06-21 5:14 ` Kishon Vijay Abraham I
2021-06-21 9:38 ` Vidya Sagar
2021-06-21 13:37 ` Kishon Vijay Abraham I
2021-06-22 5:29 ` Vidya Sagar
2020-02-12 11:25 ` [PATCH v2 3/5] PCI: endpoint: Protect concurrent access to memory allocation " Kishon Vijay Abraham I
2020-02-12 11:25 ` Kishon Vijay Abraham I [this message]
2020-02-12 11:25 ` [PATCH v2 5/5] PCI: endpoint: Assign function number for each PF in EPC core Kishon Vijay Abraham I
2020-02-21 15:54 ` [PATCH v2 0/5] PCI: Endpoint: Miscellaneous improvements Lorenzo Pieralisi
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=20200212112514.2000-5-kishon@ti.com \
--to=kishon@ti.com \
--cc=amurray@thegoodpenguin.co.uk \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=nadeem@cadence.com \
--cc=tjoseph@cadence.com \
--cc=vidyas@nvidia.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.