Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: 8250: fix shared interrupts issues with SMP and RT kernels

With SMP kernels _irqsave spinlock disables only local interrupts, while
the shared serial interrupt could be assigned to the CPU that is not
currently starting up the serial port.

This might cause issues because serial8250_startup() routine issues
IRQ-triggering operations before registering the port in the IRQ chain
(though, this is fine to do and done explicitly because we don't want to
process any interrupts on the port startup).

With RT kernels and preemptable hardirqs, _irqsave spinlock does not
disable local hardirqs, and the bug could be reproduced much easily:

$ cat /dev/ttyS0 &
$ cat /dev/ttyS1
irq 42: nobody cared (try booting with the "irqpoll" option)
Call Trace:
[C0475EB0] [C0008A98] show_stack+0x4c/0x1ac (unreliable)
[C0475EF0] [C004BBD4] __report_bad_irq+0x34/0xb8
[C0475F10] [C004BD38] note_interrupt+0xe0/0x308
[C0475F50] [C004B09C] thread_simple_irq+0xdc/0x104
[C0475F70] [C004B3FC] do_irqd+0x338/0x3c8
[C0475FC0] [C00398E0] kthread+0xf8/0x100
[C0475FF0] [C0011FE0] original_kernel_thread+0x44/0x60
handlers:
[<c02112c4>] (serial8250_interrupt+0x0/0x138)
Disabling IRQ #42

After this, all serial ports on the given IRQ are non-functional.

To fix the issue we should explicitly disable shared IRQ before
issuing any IRQ-triggering operations.

I also changed spin_lock_irqsave to the ordinary spin_lock, since it
seems to be safe: chain does not contain new port (yet), thus nobody
will interfere us from the ISRs.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Anton Vorontsov and committed by
Linus Torvalds
768aec0b 88e88249

+6 -2
+6 -2
drivers/serial/8250.c
··· 1874 1874 * the interrupt is enabled. Delays are necessary to 1875 1875 * allow register changes to become visible. 1876 1876 */ 1877 - spin_lock_irqsave(&up->port.lock, flags); 1877 + spin_lock(&up->port.lock); 1878 + if (up->port.flags & UPF_SHARE_IRQ) 1879 + disable_irq_nosync(up->port.irq); 1878 1880 1879 1881 wait_for_xmitr(up, UART_LSR_THRE); 1880 1882 serial_out_sync(up, UART_IER, UART_IER_THRI); ··· 1888 1886 iir = serial_in(up, UART_IIR); 1889 1887 serial_out(up, UART_IER, 0); 1890 1888 1891 - spin_unlock_irqrestore(&up->port.lock, flags); 1889 + if (up->port.flags & UPF_SHARE_IRQ) 1890 + enable_irq(up->port.irq); 1891 + spin_unlock(&up->port.lock); 1892 1892 1893 1893 /* 1894 1894 * If the interrupt is not reasserted, setup a timer to