kernel_optimize_test/kernel/irq
Thomas Pfaff e6e61aab49 genirq: Synchronize interrupt thread startup
commit 8707898e22fd665bc1d7b18b809be4b56ce25bdd upstream.

A kernel hang can be observed when running setserial in a loop on a kernel
with force threaded interrupts. The sequence of events is:

   setserial
     open("/dev/ttyXXX")
       request_irq()
     do_stuff()
      -> serial interrupt
         -> wake(irq_thread)
	      desc->threads_active++;
     close()
       free_irq()
         kthread_stop(irq_thread)
     synchronize_irq() <- hangs because desc->threads_active != 0

The thread is created in request_irq() and woken up, but does not get on a
CPU to reach the actual thread function, which would handle the pending
wake-up. kthread_stop() sets the should stop condition which makes the
thread immediately exit, which in turn leaves the stale threads_active
count around.

This problem was introduced with commit 519cc8652b, which addressed a
interrupt sharing issue in the PCIe code.

Before that commit free_irq() invoked synchronize_irq(), which waits for
the hard interrupt handler and also for associated threads to complete.

To address the PCIe issue synchronize_irq() was replaced with
__synchronize_hardirq(), which only waits for the hard interrupt handler to
complete, but not for threaded handlers.

This was done under the assumption, that the interrupt thread already
reached the thread function and waits for a wake-up, which is guaranteed to
be handled before acting on the stop condition. The problematic case, that
the thread would not reach the thread function, was obviously overlooked.

Make sure that the interrupt thread is really started and reaches
thread_fn() before returning from __setup_irq().

This utilizes the existing wait queue in the interrupt descriptor. The
wait queue is unused for non-shared interrupts. For shared interrupts the
usage might cause a spurious wake-up of a waiter in synchronize_irq() or the
completion of a threaded handler might cause a spurious wake-up of the
waiter for the ready flag. Both are harmless and have no functional impact.

[ tglx: Amended changelog ]

Fixes: 519cc8652b ("genirq: Synchronize only with single thread on free_irq()")
Signed-off-by: Thomas Pfaff <tpfaff@pcs.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/552fe7b4-9224-b183-bb87-a8f36d335690@pcs.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-05-12 12:25:32 +02:00
..
affinity.c genirq/affinity: Consider that CPUs on nodes can be unbalanced 2022-04-20 09:23:29 +02:00
autoprobe.c genirq: Delay deactivation in free_irq() 2019-07-03 10:12:28 +02:00
chip.c genirq: Provide IRQCHIP_AFFINITY_PRE_STARTUP 2021-08-18 08:59:15 +02:00
cpuhotplug.c genirq, sched/isolation: Isolate from handling managed interrupts 2020-01-22 16:29:49 +01:00
debug.h
debugfs.c Merge branch 'irq/qcom-pdc-wakeup' into irq/irqchip-next 2020-10-06 11:28:03 +01:00
devres.c
dummychip.c
generic-chip.c
handle.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
internals.h genirq: Synchronize interrupt thread startup 2022-05-12 12:25:32 +02:00
ipi.c
irq_sim.c genirq/irq_sim: Simplify the API 2020-05-18 10:30:21 +01:00
irqdesc.c genirq: Synchronize interrupt thread startup 2022-05-12 12:25:32 +02:00
irqdomain.c genirq/irqdomain: Don't try to free an interrupt that has no mapping 2020-12-30 11:53:25 +01:00
Kconfig genirq: Let GENERIC_IRQ_IPI select IRQ_DOMAIN_HIERARCHY 2020-10-15 21:41:44 +01:00
Makefile genirq/timings: Add selftest for circular array 2019-06-12 10:47:04 +02:00
manage.c genirq: Synchronize interrupt thread startup 2022-05-12 12:25:32 +02:00
matrix.c genirq/matrix: Prevent allocation counter corruption 2021-05-11 14:47:17 +02:00
migration.c
msi.c genirq/msi: Ensure deactivation on teardown 2021-08-18 08:59:15 +02:00
pm.c genirq/PM: Introduce IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND flag 2020-10-06 11:23:41 +01:00
proc.c genirq: Allow interrupts to be excluded from /proc/interrupts 2020-09-13 17:04:38 +01:00
resend.c genirq: Walk the irq_data hierarchy when resending an interrupt 2020-09-06 18:25:23 +01:00
settings.h genirq: Allow interrupts to be excluded from /proc/interrupts 2020-09-13 17:04:38 +01:00
spurious.c genirq: Add missing __must_hold() sparse annotation 2020-01-09 18:03:37 +01:00
timings.c genirq/timings: Fix error return code in irq_timings_test_irqs() 2021-09-15 09:50:29 +02:00