From: Jiang Liu <liuj97@gmail.com>
To: Yinghai Lu <yinghai@kernel.org>,
Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Dan Zink <dan.zink@compaq.com>,
Greg Kroah-Hartman <greg@kroah.com>,
Dely Sy <dely.l.sy@intel.com>
Cc: Jiang Liu <jiang.liu@huawei.com>, Jiang Liu <liuj97@gmail.com>,
Keping Chen <chenkeping@huawei.com>,
linux-pci@vger.kernel.org
Subject: [PATCH RFC 10/17] PCI: serialize hotplug operaitons triggered by the shpchp driver
Date: Tue, 17 Apr 2012 00:29:04 +0800 [thread overview]
Message-ID: <1334593751-5916-11-git-send-email-jiang.liu@huawei.com> (raw)
In-Reply-To: <1334593751-5916-1-git-send-email-jiang.liu@huawei.com>
Use PCI hotplug lock to serialize hotplug operations triggered by the
shpchp driver.
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
---
drivers/pci/hotplug/shpchp.h | 2 ++
drivers/pci/hotplug/shpchp_core.c | 3 ++-
drivers/pci/hotplug/shpchp_ctrl.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index 6691dc4..07f3b2d 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -157,6 +157,7 @@ struct controller {
#define BLINKINGOFF_STATE 2
#define POWERON_STATE 3
#define POWEROFF_STATE 4
+#define SHUTDOWN_STATE 5
/* Error messages */
#define INTERLOCK_OPEN 0x00000002
@@ -179,6 +180,7 @@ extern u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl);
extern u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl);
extern int shpchp_configure_device(struct slot *p_slot);
extern int shpchp_unconfigure_device(struct slot *p_slot);
+extern void shpchp_shutdown_slot(struct slot *slot);
extern void cleanup_slots(struct controller *ctrl);
extern void shpchp_queue_pushbutton_work(struct work_struct *work);
extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 19762b3..71cc5f2 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -172,10 +172,11 @@ void cleanup_slots(struct controller *ctrl)
list_for_each_safe(tmp, next, &ctrl->slot_list) {
slot = list_entry(tmp, struct slot, slot_list);
- list_del(&slot->slot_list);
flush_workqueue(shpchp_wq);
cancel_delayed_work_sync(&slot->work);
+ shpchp_shutdown_slot(slot);
flush_workqueue(shpchp_ordered_wq);
+ list_del(&slot->slot_list);
pci_hp_deregister(slot->hotplug_slot);
}
}
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index b00b09b..7b8e3a6 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -31,6 +31,7 @@
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/slab.h>
+#include <linux/delay.h>
#include <linux/pci.h>
#include "../pci.h"
#include "shpchp.h"
@@ -406,6 +407,18 @@ static void shpchp_pushbutton_thread(struct work_struct *work)
struct pushbutton_work_info *info =
container_of(work, struct pushbutton_work_info, work);
struct slot *p_slot = info->p_slot;
+ bool shutdown;
+
+ /* Break possible deadlock by using pci_hotplug_try_enter() */
+ while (!pci_hotplug_try_enter()) {
+ mutex_lock(&p_slot->lock);
+ shutdown = p_slot->state == SHUTDOWN_STATE;
+ mutex_unlock(&p_slot->lock);
+ if (shutdown)
+ goto out;
+ else
+ mdelay(1);
+ }
mutex_lock(&p_slot->lock);
switch (p_slot->state) {
@@ -427,6 +440,9 @@ static void shpchp_pushbutton_thread(struct work_struct *work)
}
mutex_unlock(&p_slot->lock);
+ pci_hotplug_exit();
+
+out:
kfree(info);
}
@@ -729,3 +745,19 @@ int shpchp_sysfs_disable_slot(struct slot *p_slot)
return retval;
}
+
+void shpchp_shutdown_slot(struct slot *slot)
+{
+ u8 getstatus;
+
+ mutex_lock(&slot->lock);
+ slot->state = SHUTDOWN_STATE;
+ mutex_unlock(&slot->lock);
+
+ slot->hpc_ops->set_attention_status(slot, 0);
+ slot->hpc_ops->get_power_status(slot, &getstatus);
+ if (getstatus)
+ slot->hpc_ops->green_led_on(slot);
+ else
+ slot->hpc_ops->green_led_off(slot);
+}
--
1.7.5.4
next prev parent reply other threads:[~2012-04-16 16:33 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-16 16:28 [PATCH RFC 00/17] Introduce a global lock to serialize all PCI hotplug Jiang Liu
2012-04-16 16:28 ` [PATCH RFC 01/17] PCI: introduce pci_bus_get()/pci_bus_put() to hide PCI implementation details Jiang Liu
2012-04-16 16:28 ` [PATCH RFC 02/17] PCI: introduce recursive rwsem to serialize PCI hotplug operations Jiang Liu
2012-04-16 16:28 ` [PATCH RFC 03/17] PCI: replace pci_remove_rescan_mutex with the PCI hotplug lock Jiang Liu
2012-04-16 16:28 ` [PATCH RFC 04/17] PCI: serialize hotplug operations triggered by PCI hotplug sysfs interfaces Jiang Liu
2012-04-16 16:28 ` [PATCH RFC 05/17] PCI: correctly flush workqueue when destroy pcie hotplug controller Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 06/17] PCI: prepare for serializing hotplug operations triggered by pciehp driver Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 07/17] PCI: serialize hotplug operaitons triggered by the " Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 08/17] PCI: fix two race windows when probing/removing SHPC controller Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 09/17] PCI: correctly flush workqueues and timer when destroy " Jiang Liu
2012-04-16 16:29 ` Jiang Liu [this message]
2012-04-16 16:29 ` [PATCH RFC 11/17] PCI: release IO resource in error handling path in cpcihp_generic_init() Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 12/17] PCI: clean up all resources in error handling path in zt5550_hc_init_one() Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 13/17] PCI: trivial code clean up in cpci_hotplug_core.c Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 14/17] PCI: fix race windows when shutting down cpcihp controller Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 15/17] PCI: hold a reference count to the PCI bus used by cpcihp drivers Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 16/17] PCI: serialize PCI hotplug operations triggered " Jiang Liu
2012-04-16 16:29 ` [PATCH RFC 17/17] PCI: serialize PCI hotplug operations triggered by fakephp drivers Jiang Liu
2012-04-16 21:33 ` [PATCH RFC 00/17] Introduce a global lock to serialize all PCI hotplug Greg KH
2012-04-17 11:57 ` Jiang Liu
2012-04-17 14:53 ` Jiang Liu
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=1334593751-5916-11-git-send-email-jiang.liu@huawei.com \
--to=liuj97@gmail.com \
--cc=bhelgaas@google.com \
--cc=chenkeping@huawei.com \
--cc=dan.zink@compaq.com \
--cc=dely.l.sy@intel.com \
--cc=greg@kroah.com \
--cc=jiang.liu@huawei.com \
--cc=kaneshige.kenji@jp.fujitsu.com \
--cc=linux-pci@vger.kernel.org \
--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).