]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.4.28/pci-pciehp-use-per-slot-workqueues-to-avoid-deadlock.patch
Drop watchdog patch
[thirdparty/kernel/stable-queue.git] / releases / 3.4.28 / pci-pciehp-use-per-slot-workqueues-to-avoid-deadlock.patch
1 From c2be6f93b383c873a4f9d521afa49b1b67d06085 Mon Sep 17 00:00:00 2001
2 From: Yijing Wang <wangyijing@huawei.com>
3 Date: Fri, 11 Jan 2013 10:15:54 +0800
4 Subject: PCI: pciehp: Use per-slot workqueues to avoid deadlock
5
6 From: Yijing Wang <wangyijing@huawei.com>
7
8 commit c2be6f93b383c873a4f9d521afa49b1b67d06085 upstream.
9
10 When we have a hotplug-capable PCIe port with a second hotplug-capable
11 PCIe port below it, removing the device below the upstream port causes
12 a deadlock.
13
14 The deadlock happens because we use the pciehp_wq workqueue to run
15 pciehp_power_thread(), which uses pciehp_disable_slot() to remove devices
16 below the upstream port. When we remove the downstream PCIe port, we call
17 pciehp_remove(), the pciehp driver's .remove() method. That calls
18 flush_workqueue(pciehp_wq), which deadlocks because the
19 pciehp_power_thread() work item is still running.
20
21 This patch avoids the deadlock by creating a workqueue for every PCIe port
22 and removing the single shared workqueue.
23
24 Here's the call path that leads to the deadlock:
25
26 pciehp_queue_pushbutton_work
27 queue_work(pciehp_wq) # queue pciehp_power_thread
28 ...
29
30 pciehp_power_thread
31 pciehp_disable_slot
32 remove_board
33 pciehp_unconfigure_device
34 pci_stop_and_remove_bus_device
35 ...
36 pciehp_remove # pciehp driver .remove method
37 pciehp_release_ctrl
38 pcie_cleanup_slot
39 flush_workqueue(pciehp_wq)
40
41 This is fairly urgent because it can be caused by simply unplugging a
42 Thunderbolt adapter, as reported by Daniel below.
43
44 [bhelgaas: changelog]
45 Reference: http://lkml.kernel.org/r/CAMVG2ssiRgcTD1bej2tkUUfsWmpL5eNtPcNif9va2-Gzb2u8nQ@mail.gmail.com
46 Reported-and-tested-by: Daniel J Blueman <daniel@quora.org>
47 Reviewed-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
48 Signed-off-by: Yijing Wang <wangyijing@huawei.com>
49 Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
50 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
51
52 ---
53 drivers/pci/hotplug/pciehp.h | 2 +-
54 drivers/pci/hotplug/pciehp_core.c | 11 ++---------
55 drivers/pci/hotplug/pciehp_ctrl.c | 8 ++++----
56 drivers/pci/hotplug/pciehp_hpc.c | 11 ++++++++++-
57 4 files changed, 17 insertions(+), 15 deletions(-)
58
59 --- a/drivers/pci/hotplug/pciehp.h
60 +++ b/drivers/pci/hotplug/pciehp.h
61 @@ -44,7 +44,6 @@ extern bool pciehp_poll_mode;
62 extern int pciehp_poll_time;
63 extern bool pciehp_debug;
64 extern bool pciehp_force;
65 -extern struct workqueue_struct *pciehp_wq;
66
67 #define dbg(format, arg...) \
68 do { \
69 @@ -78,6 +77,7 @@ struct slot {
70 struct hotplug_slot *hotplug_slot;
71 struct delayed_work work; /* work for button event */
72 struct mutex lock;
73 + struct workqueue_struct *wq;
74 };
75
76 struct event_info {
77 --- a/drivers/pci/hotplug/pciehp_core.c
78 +++ b/drivers/pci/hotplug/pciehp_core.c
79 @@ -42,7 +42,6 @@ bool pciehp_debug;
80 bool pciehp_poll_mode;
81 int pciehp_poll_time;
82 bool pciehp_force;
83 -struct workqueue_struct *pciehp_wq;
84
85 #define DRIVER_VERSION "0.4"
86 #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
87 @@ -340,18 +339,13 @@ static int __init pcied_init(void)
88 {
89 int retval = 0;
90
91 - pciehp_wq = alloc_workqueue("pciehp", 0, 0);
92 - if (!pciehp_wq)
93 - return -ENOMEM;
94 -
95 pciehp_firmware_init();
96 retval = pcie_port_service_register(&hpdriver_portdrv);
97 dbg("pcie_port_service_register = %d\n", retval);
98 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
99 - if (retval) {
100 - destroy_workqueue(pciehp_wq);
101 + if (retval)
102 dbg("Failure to register service\n");
103 - }
104 +
105 return retval;
106 }
107
108 @@ -359,7 +353,6 @@ static void __exit pcied_cleanup(void)
109 {
110 dbg("unload_pciehpd()\n");
111 pcie_port_service_unregister(&hpdriver_portdrv);
112 - destroy_workqueue(pciehp_wq);
113 info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
114 }
115
116 --- a/drivers/pci/hotplug/pciehp_ctrl.c
117 +++ b/drivers/pci/hotplug/pciehp_ctrl.c
118 @@ -49,7 +49,7 @@ static int queue_interrupt_event(struct
119 info->p_slot = p_slot;
120 INIT_WORK(&info->work, interrupt_event_handler);
121
122 - queue_work(pciehp_wq, &info->work);
123 + queue_work(p_slot->wq, &info->work);
124
125 return 0;
126 }
127 @@ -344,7 +344,7 @@ void pciehp_queue_pushbutton_work(struct
128 kfree(info);
129 goto out;
130 }
131 - queue_work(pciehp_wq, &info->work);
132 + queue_work(p_slot->wq, &info->work);
133 out:
134 mutex_unlock(&p_slot->lock);
135 }
136 @@ -377,7 +377,7 @@ static void handle_button_press_event(st
137 if (ATTN_LED(ctrl))
138 pciehp_set_attention_status(p_slot, 0);
139
140 - queue_delayed_work(pciehp_wq, &p_slot->work, 5*HZ);
141 + queue_delayed_work(p_slot->wq, &p_slot->work, 5*HZ);
142 break;
143 case BLINKINGOFF_STATE:
144 case BLINKINGON_STATE:
145 @@ -439,7 +439,7 @@ static void handle_surprise_event(struct
146 else
147 p_slot->state = POWERON_STATE;
148
149 - queue_work(pciehp_wq, &info->work);
150 + queue_work(p_slot->wq, &info->work);
151 }
152
153 static void interrupt_event_handler(struct work_struct *work)
154 --- a/drivers/pci/hotplug/pciehp_hpc.c
155 +++ b/drivers/pci/hotplug/pciehp_hpc.c
156 @@ -874,23 +874,32 @@ static void pcie_shutdown_notification(s
157 static int pcie_init_slot(struct controller *ctrl)
158 {
159 struct slot *slot;
160 + char name[32];
161
162 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
163 if (!slot)
164 return -ENOMEM;
165
166 + snprintf(name, sizeof(name), "pciehp-%u", PSN(ctrl));
167 + slot->wq = alloc_workqueue(name, 0, 0);
168 + if (!slot->wq)
169 + goto abort;
170 +
171 slot->ctrl = ctrl;
172 mutex_init(&slot->lock);
173 INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work);
174 ctrl->slot = slot;
175 return 0;
176 +abort:
177 + kfree(slot);
178 + return -ENOMEM;
179 }
180
181 static void pcie_cleanup_slot(struct controller *ctrl)
182 {
183 struct slot *slot = ctrl->slot;
184 cancel_delayed_work(&slot->work);
185 - flush_workqueue(pciehp_wq);
186 + destroy_workqueue(slot->wq);
187 kfree(slot);
188 }
189