platform/mellanox: fix potential deadlock in the tmfifo driver
authorLiming Sun <lsun@mellanox.com>
Fri, 20 Dec 2019 17:04:33 +0000 (12:04 -0500)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 10 Jan 2020 09:57:21 +0000 (11:57 +0200)
commit3454eeeebd115891f34aa2e76eccf08c9b0882bb
tree85647ee62af925e7349f400b98fd562f7e4a77ba
parent84abc5a1c924548099a2d9cd0e8b8c1928ef5b55
platform/mellanox: fix potential deadlock in the tmfifo driver

This commit fixes the potential deadlock caused by the console Rx
and Tx processing at the same time. Rx and Tx both take the console
and tmfifo spinlock but in different order which causes potential
deadlock. The fix is to use different tmfifo spinlock for Rx and
Tx since they protect different resources and it's safe to split
the lock.

Below is the reported call trace when copying/pasting large string
in the console.

Rx:
    _raw_spin_lock_irqsave (hvc lock)
    __hvc_poll
    hvc_poll
    in_intr
    vring_interrupt
    mlxbf_tmfifo_rxtx_one_desc (tmfifo lock)
    mlxbf_tmfifo_rxtx
    mlxbf_tmfifo_work_rxtx
Tx:
    _raw_spin_lock_irqsave (tmfifo lock)
    mlxbf_tmfifo_virtio_notify
    virtqueue_notify
    virtqueue_kick
    put_chars
    hvc_push
    hvc_write (hvc lock)
    ...
    do_tty_write
    tty_write

Fixes: 1357dfd7261f ("platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc")
Cc: <stable@vger.kernel.org> # 5.4+
Reviewed-by: David Woods <dwoods@mellanox.com>
Signed-off-by: Liming Sun <lsun@mellanox.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/platform/mellanox/mlxbf-tmfifo.c