serial: 8250: fix potential deadlock in rs485-mode
authorTomas Melin <tomas.melin@vaisala.com>
Fri, 27 Oct 2017 12:16:30 +0000 (15:16 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 4 Nov 2017 11:38:04 +0000 (12:38 +0100)
commitb86f86e8e7c5264bb8f5835d60f9ec840d9f5a7a
tree452b8086bcef1fd44b004158bb85d112fa01fe79
parent4fefcbff8be52c7e68feefa0c96fb8e06923aab3
serial: 8250: fix potential deadlock in rs485-mode

Canceling hrtimer when holding uart spinlock can deadlock.

CPU0: syscall write
          -> get uart port spinlock
              -> write uart
                  -> start_tx_rs485
                      -> hrtimer_cancel
                          -> wait for hrtimer callback to finish

CPU1: hrtimer IRQ
          -> run hrtimer
              -> em485_handle_stop_tx
                  -> get uart port spinlock

CPU0 is waiting for the hrtimer callback to finish, but the hrtimer
callback running on CPU1 is waiting to get the uart port spinlock.

This deadlock can be avoided by not canceling the hrtimers in these paths.
Setting active_timer=NULL can be done without accessing hrtimer,
and that will effectively cancel operations that would otherwise have been
performed by the hrtimer callback.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_port.c