summaryrefslogtreecommitdiffstats
path: root/kernel/irq/manage.c
diff options
context:
space:
mode:
authorLukas Wunner <lukas@wunner.de>2018-06-24 04:35:30 -0400
committerThomas Gleixner <tglx@linutronix.de>2018-06-24 08:17:27 -0400
commit519cc8652b3a1d3d0a02257afbe9573ad644da26 (patch)
treee6809cf5de7b9e7c2bbf1a5ec80dbb1a5a1b9a06 /kernel/irq/manage.c
parent836557bd58e5e65c05c73af9f6ebed885dbfccfc (diff)
genirq: Synchronize only with single thread on free_irq()
When pciehp is converted to threaded IRQ handling, removal of unplugged devices below a PCIe hotplug port happens synchronously in the IRQ thread. Removal of devices typically entails a call to free_irq() by their drivers. If those devices share their IRQ with the hotplug port, __free_irq() deadlocks because it calls synchronize_irq() to wait for all hard IRQ handlers as well as all threads sharing the IRQ to finish. Actually it's sufficient to wait only for the IRQ thread of the removed device, so call synchronize_hardirq() to wait for all hard IRQ handlers to finish, but no longer for any threads. Compensate by rearranging the control flow in irq_wait_for_interrupt() such that the device's thread is allowed to run one last time after kthread_stop() has been called. kthread_stop() blocks until the IRQ thread has completed. On completion the IRQ thread clears its oneshot thread_mask bit. This is safe because __free_irq() holds the request_mutex, thereby preventing __setup_irq() from handing out the same oneshot thread_mask bit to a newly requested action. Stack trace for posterity: INFO: task irq/17-pciehp:94 blocked for more than 120 seconds. schedule+0x28/0x80 synchronize_irq+0x6e/0xa0 __free_irq+0x15a/0x2b0 free_irq+0x33/0x70 pciehp_release_ctrl+0x98/0xb0 pcie_port_remove_service+0x2f/0x40 device_release_driver_internal+0x157/0x220 bus_remove_device+0xe2/0x150 device_del+0x124/0x340 device_unregister+0x16/0x60 remove_iter+0x1a/0x20 device_for_each_child+0x4b/0x90 pcie_port_device_remove+0x1e/0x30 pci_device_remove+0x36/0xb0 device_release_driver_internal+0x157/0x220 pci_stop_bus_device+0x7d/0xa0 pci_stop_bus_device+0x3d/0xa0 pci_stop_and_remove_bus_device+0xe/0x20 pciehp_unconfigure_device+0xb8/0x160 pciehp_disable_slot+0x84/0x130 pciehp_ist+0x158/0x190 irq_thread_fn+0x1b/0x50 irq_thread+0x143/0x1a0 kthread+0x111/0x130 Signed-off-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Mika Westerberg <mika.westerberg@linux.intel.com> Cc: linux-pci@vger.kernel.org Link: https://lkml.kernel.org/r/d72b41309f077c8d3bee6cc08ad3662d50b5d22a.1529828292.git.lukas@wunner.de
Diffstat (limited to 'kernel/irq/manage.c')
-rw-r--r--kernel/irq/manage.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 123a227d3357..1f8be33572a7 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -790,9 +790,19 @@ static irqreturn_t irq_forced_secondary_handler(int irq, void *dev_id)
790 790
791static int irq_wait_for_interrupt(struct irqaction *action) 791static int irq_wait_for_interrupt(struct irqaction *action)
792{ 792{
793 set_current_state(TASK_INTERRUPTIBLE); 793 for (;;) {
794 set_current_state(TASK_INTERRUPTIBLE);
794 795
795 while (!kthread_should_stop()) { 796 if (kthread_should_stop()) {
797 /* may need to run one last time */
798 if (test_and_clear_bit(IRQTF_RUNTHREAD,
799 &action->thread_flags)) {
800 __set_current_state(TASK_RUNNING);
801 return 0;
802 }
803 __set_current_state(TASK_RUNNING);
804 return -1;
805 }
796 806
797 if (test_and_clear_bit(IRQTF_RUNTHREAD, 807 if (test_and_clear_bit(IRQTF_RUNTHREAD,
798 &action->thread_flags)) { 808 &action->thread_flags)) {
@@ -800,10 +810,7 @@ static int irq_wait_for_interrupt(struct irqaction *action)
800 return 0; 810 return 0;
801 } 811 }
802 schedule(); 812 schedule();
803 set_current_state(TASK_INTERRUPTIBLE);
804 } 813 }
805 __set_current_state(TASK_RUNNING);
806 return -1;
807} 814}
808 815
809/* 816/*
@@ -1024,7 +1031,7 @@ static int irq_thread(void *data)
1024 /* 1031 /*
1025 * This is the regular exit path. __free_irq() is stopping the 1032 * This is the regular exit path. __free_irq() is stopping the
1026 * thread via kthread_stop() after calling 1033 * thread via kthread_stop() after calling
1027 * synchronize_irq(). So neither IRQTF_RUNTHREAD nor the 1034 * synchronize_hardirq(). So neither IRQTF_RUNTHREAD nor the
1028 * oneshot mask bit can be set. 1035 * oneshot mask bit can be set.
1029 */ 1036 */
1030 task_work_cancel(current, irq_thread_dtor); 1037 task_work_cancel(current, irq_thread_dtor);
@@ -1241,7 +1248,7 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
1241 1248
1242 /* 1249 /*
1243 * Protects against a concurrent __free_irq() call which might wait 1250 * Protects against a concurrent __free_irq() call which might wait
1244 * for synchronize_irq() to complete without holding the optional 1251 * for synchronize_hardirq() to complete without holding the optional
1245 * chip bus lock and desc->lock. Also protects against handing out 1252 * chip bus lock and desc->lock. Also protects against handing out
1246 * a recycled oneshot thread_mask bit while it's still in use by 1253 * a recycled oneshot thread_mask bit while it's still in use by
1247 * its previous owner. 1254 * its previous owner.
@@ -1612,11 +1619,11 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
1612 /* 1619 /*
1613 * Drop bus_lock here so the changes which were done in the chip 1620 * Drop bus_lock here so the changes which were done in the chip
1614 * callbacks above are synced out to the irq chips which hang 1621 * callbacks above are synced out to the irq chips which hang
1615 * behind a slow bus (I2C, SPI) before calling synchronize_irq(). 1622 * behind a slow bus (I2C, SPI) before calling synchronize_hardirq().
1616 * 1623 *
1617 * Aside of that the bus_lock can also be taken from the threaded 1624 * Aside of that the bus_lock can also be taken from the threaded
1618 * handler in irq_finalize_oneshot() which results in a deadlock 1625 * handler in irq_finalize_oneshot() which results in a deadlock
1619 * because synchronize_irq() would wait forever for the thread to 1626 * because kthread_stop() would wait forever for the thread to
1620 * complete, which is blocked on the bus lock. 1627 * complete, which is blocked on the bus lock.
1621 * 1628 *
1622 * The still held desc->request_mutex() protects against a 1629 * The still held desc->request_mutex() protects against a
@@ -1628,7 +1635,7 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
1628 unregister_handler_proc(irq, action); 1635 unregister_handler_proc(irq, action);
1629 1636
1630 /* Make sure it's not being used on another CPU: */ 1637 /* Make sure it's not being used on another CPU: */
1631 synchronize_irq(irq); 1638 synchronize_hardirq(irq);
1632 1639
1633#ifdef CONFIG_DEBUG_SHIRQ 1640#ifdef CONFIG_DEBUG_SHIRQ
1634 /* 1641 /*
@@ -1646,6 +1653,12 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
1646 } 1653 }
1647#endif 1654#endif
1648 1655
1656 /*
1657 * The action has already been removed above, but the thread writes
1658 * its oneshot mask bit when it completes. Though request_mutex is
1659 * held across this which prevents __setup_irq() from handing out
1660 * the same bit to a newly requested action.
1661 */
1649 if (action->thread) { 1662 if (action->thread) {
1650 kthread_stop(action->thread); 1663 kthread_stop(action->thread);
1651 put_task_struct(action->thread); 1664 put_task_struct(action->thread);