linux-stable/kernel/irq
Thomas Gleixner 19d39a3810 genirq: Keep chip buslock across irq_request/release_resources()
Moving the irq_request/release_resources() callbacks out of the spinlocked,
irq disabled and bus locked region, unearthed an interesting abuse of the
irq_bus_lock/irq_bus_sync_unlock() callbacks.

The OMAP GPIO driver does merily power management inside of them. The
irq_request_resources() callback of this GPIO irqchip calls a function
which reads a GPIO register. That read aborts now because the clock of the
GPIO block is not magically enabled via the irq_bus_lock() callback.

Move the callbacks under the bus lock again to prevent this. In the
free_irq() path this requires to drop the bus_lock before calling
synchronize_irq() and reaquiring it before calling the
irq_release_resources() callback.

The bus lock can't be held because:

   1) The data which has been changed between bus_lock/un_lock is cached in
      the irq chip driver private data and needs to go out to the irq chip
      via the slow bus (usually SPI or I2C) before calling
      synchronize_irq().

      That's the reason why this bus_lock/unlock magic exists in the first
      place, as you cannot do SPI/I2C transactions while holding desc->lock
      with interrupts disabled.

   2) synchronize_irq() will actually deadlock, if there is a handler on
      flight. These chips use threaded handlers for obvious reasons, as
      they allow to do SPI/I2C communication. When the threaded handler
      returns then bus_lock needs to be taken in irq_finalize_oneshot() as
      we need to talk to the actual irq chip once more. After that the
      threaded handler is marked done, which makes synchronize_irq() return.

      So if we hold bus_lock accross the synchronize_irq() call, the
      handler cannot mark itself done because it blocks on the bus
      lock. That in turn makes synchronize_irq() wait forever on the
      threaded handler to complete....

Add the missing unlock of desc->request_mutex in the error path of
__free_irq() and add a bunch of comments to explain the locking and
protection rules.

Fixes: 46e48e2573 ("genirq: Move irq resource handling out of spinlocked region")
Reported-and-tested-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Reported-and-tested-by: Tony Lindgren <tony@atomide.com>
Reported-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Not-longer-ranted-at-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>
2017-07-12 10:14:42 +02:00
..
affinity.c genirq/affinity: Assign vectors to all present CPUs 2017-06-22 18:21:26 +02:00
autoprobe.c genirq: Add force argument to irq_startup() 2017-06-22 18:21:24 +02:00
chip.c genirq: Force inlining of __irq_startup_managed to prevent build failure 2017-07-04 12:36:44 +02:00
cpuhotplug.c genirq/cpuhotplug: Avoid irq affinity setting for single targets 2017-06-22 18:21:25 +02:00
debug.h irq: hide debug macros so they don't collide with others. 2012-04-23 12:30:03 -04:00
debugfs.c genirq/debugfs: Remove pointless NULL pointer check 2017-06-24 11:43:53 +02:00
devres.c irq/generic-chip: Provide devm_irq_setup_generic_chip() 2017-06-21 15:53:11 +02:00
dummychip.c Merge branch 'linus' into irq/core 2015-06-05 22:25:01 +02:00
generic-chip.c irq/generic-chip: Export irq_init_generic_chip() locally 2017-06-21 15:53:11 +02:00
handle.c genirq/timings: Add infrastructure to track the interrupt timings 2017-06-24 11:44:11 +02:00
internals.h genirq/debugfs: Fix build for !CONFIG_IRQ_DOMAIN 2017-07-04 12:36:43 +02:00
ipi.c genirq: Fix missing irq allocation affinity hint 2016-07-19 10:49:47 +02:00
irqdesc.c genirq: Add mutex to irq desc to serialize request/free_irq() 2017-07-04 12:46:16 +02:00
irqdomain.c irqdomain: Allow ACPI device nodes to be used as irqdomain identifiers 2017-07-07 12:13:29 +02:00
Kconfig genirq/timings: Add infrastructure to track the interrupt timings 2017-06-24 11:44:11 +02:00
Makefile genirq/timings: Add infrastructure to track the interrupt timings 2017-06-24 11:44:11 +02:00
manage.c genirq: Keep chip buslock across irq_request/release_resources() 2017-07-12 10:14:42 +02:00
migration.c genirq: Provide irq_fixup_move_pending() 2017-06-22 18:21:13 +02:00
msi.c genirq/irqdomain: Remove auto-recursive hierarchy support 2017-06-22 18:29:34 +02:00
pm.c Merge branches 'irq-urgent-for-linus' and 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2015-11-15 09:30:48 -08:00
proc.c genirq: Introduce effective affinity mask 2017-06-22 18:21:20 +02:00
resend.c genirq: Remove irq argument from irq flow handlers 2015-09-16 15:47:51 +02:00
settings.h genirq: Add flag to force mask in disable_irq[_nosync]() 2015-10-11 11:33:42 +02:00
spurious.c genirq: Clarify logic calculating bogus irqreturn_t values 2017-02-16 15:32:19 +01:00
timings.c genirq/timings: Add infrastructure for estimating the next interrupt arrival time 2017-06-24 11:44:39 +02:00