Re: [PATCHv2] serial: 8250: change lock order in serial8250_do_startup()

From: Petr Mladek
Date: Wed Aug 19 2020 - 05:21:17 EST


On Mon 2020-08-17 11:26:46, Sergey Senozhatsky wrote:
> We have a number of "uart.port->desc.lock vs desc.lock->uart.port"
> lockdep reports coming from 8250 driver; this causes a bit of trouble
> to people, so let's fix it.
>
> The problem is reverse lock order in two different call paths:
>
> chain #1:
>
> serial8250_do_startup()
> spin_lock_irqsave(&port->lock);
> disable_irq_nosync(port->irq);
> raw_spin_lock_irqsave(&desc->lock)
>
> chain #2:
>
> __report_bad_irq()
> raw_spin_lock_irqsave(&desc->lock)
> for_each_action_of_desc()
> printk()
> spin_lock_irqsave(&port->lock);
>
> Fix this by changing the order of locks in serial8250_do_startup():
> do disable_irq_nosync() first, which grabs desc->lock, and grab
> uart->port after that, so that chain #1 and chain #2 have same lock
> order.
>
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>

The patch is committed in printk/linux.git, branch for-5.10.

Best Regards,
Petr