linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Liu <liuj97@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>, Yinghai Lu <yinghai@kernel.org>
Cc: Jiang Liu <jiang.liu@huawei.com>,
	"Rafael J . Wysocki" <rjw@sisk.pl>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Gu Zheng <guz.fnst@cn.fujitsu.com>,
	Toshi Kani <toshi.kani@hp.com>,
	Myron Stowe <myron.stowe@redhat.com>,
	Yijing Wang <wangyijing@huawei.com>, Jiang Liu <liuj97@gmail.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Jeremy Fitzhardinge <jeremy@goop.org>,
	xen-devel@lists.xensource.com,
	virtualization@lists.linux-foundation.org
Subject: [RFC PATCH v2, part3 08/11] PCI, xen-pcifront: use PCI bus lock to protect PCI device hotplug
Date: Thu, 16 May 2013 23:50:56 +0800	[thread overview]
Message-ID: <1368719459-24800-9-git-send-email-jiang.liu@huawei.com> (raw)
In-Reply-To: <1368719459-24800-1-git-send-email-jiang.liu@huawei.com>

Use PCI bus lock to protect concurrent PCI device hotplug operations.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: xen-devel@lists.xensource.com
Cc: virtualization@lists.linux-foundation.org
Cc: linux-pci@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/pci/xen-pcifront.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 6aa2c0f..2b213b3 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -505,6 +505,7 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
 
 	/* Create SysFS and notify udev of the devices. Aka: "going live" */
 	pci_bus_add_devices(b);
+	pci_bus_unlock(b, true);
 
 	return err;
 
@@ -538,6 +539,11 @@ static int pcifront_rescan_root(struct pcifront_device *pdev,
 		/* If the bus is unknown, create it. */
 		return pcifront_scan_root(pdev, domain, bus);
 
+	if (pci_bus_lock(b, PCI_BUS_STATE_STOPPING - 1, true) < 0) {
+		err = -EBUSY;
+		goto out;
+	}
+
 	err = pcifront_scan_bus(pdev, domain, bus, b);
 
 	/* Claim resources before going "live" with our devices */
@@ -545,6 +551,9 @@ static int pcifront_rescan_root(struct pcifront_device *pdev,
 
 	/* Create SysFS and notify udev of the devices. Aka: "going live" */
 	pci_bus_add_devices(b);
+	pci_bus_unlock(b, true);
+
+out:
 	pci_bus_put(b);
 
 	return err;
@@ -559,8 +568,11 @@ static void pcifront_free_roots(struct pcifront_device *pdev)
 
 	for_each_pci_root_bus(bus) {
 		sd = bus->sysdata;
-		if (sd->pdev == pdev) {
+		if (sd->pdev != pdev)
+			continue;
+		if (pci_bus_lock(bus, PCI_BUS_STATE_REMOVED - 1, true) == 0) {
 			pci_stop_root_bus(bus);
+			/* it also unlocks PCI buses */
 			pci_remove_root_bus(bus);
 		}
 	}
@@ -1042,7 +1054,7 @@ static int pcifront_detach_devices(struct pcifront_device *pdev)
 				domain, bus, slot, func);
 			continue;
 		}
-		pci_stop_and_remove_bus_device(pci_dev);
+		pci_stop_and_remove_device(pci_dev);
 		pci_dev_put(pci_dev);
 
 		dev_dbg(&pdev->xdev->dev,
-- 
1.8.1.2


  parent reply	other threads:[~2013-05-16 15:51 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-16 15:50 [RFC PATCH v2, part3 00/11] Introduce PCI bus lock and state machine Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 01/11] PCI: introduce bus lock and state machine to serialize PCI hotplug operations Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 02/11] PCI: implement state machine for PCI bus Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 03/11] PCI: introduce a state machine to manage PCI device lifecycle Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 04/11] PCI: introduce helper function pci_stop_and_remove_device() Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 05/11] PCI: enhance PCI core logic to support PCI bus lock Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 06/11] PCI, sysfs: use PCI bus lock to serialize hotplug operations triggered by sysfs Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 07/11] PCI, xen-pcifront: use new PCI interfaces to simplify implementation Jiang Liu
2013-06-07 14:50   ` Konrad Rzeszutek Wilk
2013-06-07 15:17     ` Jiang Liu
2013-06-07 15:38     ` Konrad Rzeszutek Wilk
2013-06-07 16:50       ` Jiang Liu
2013-06-07 17:07         ` Konrad Rzeszutek Wilk
2013-06-09 16:50           ` Jiang Liu
2013-06-10 16:58             ` Konrad Rzeszutek Wilk
2013-06-10 17:08               ` Jiang Liu
2013-06-14 18:07                 ` Konrad Rzeszutek Wilk
2013-06-07 15:50     ` Jiang Liu
2013-05-16 15:50 ` Jiang Liu [this message]
2013-05-16 15:50 ` [RFC PATCH v2, part3 09/11] PCI, acpiphp: use PCI bus lock to protect PCI device hotplug Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 10/11] PCI, pciehp: " Jiang Liu
2013-05-16 15:50 ` [RFC PATCH v2, part3 11/11] PCI, ACPI, pci_root: " Jiang Liu
2013-05-16 19:59   ` Rafael J. Wysocki
2013-05-22  9:48 ` [RFC PATCH v2, part3 00/11] Introduce PCI bus lock and state machine Gu Zheng
2013-05-28  4:51   ` Yinghai Lu

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=1368719459-24800-9-git-send-email-jiang.liu@huawei.com \
    --to=liuj97@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guz.fnst@cn.fujitsu.com \
    --cc=jeremy@goop.org \
    --cc=jiang.liu@huawei.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=myron.stowe@redhat.com \
    --cc=rjw@sisk.pl \
    --cc=toshi.kani@hp.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=wangyijing@huawei.com \
    --cc=xen-devel@lists.xensource.com \
    --cc=yinghai@kernel.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;
as well as URLs for NNTP newsgroup(s).