• Peter Zijlstra's avatar
    serial: pl011: Fix lockdep splat when handling magic-sysrq interrupt · 53faca2f
    Peter Zijlstra authored
    commit 534cf755d9df99e214ddbe26b91cd4d81d2603e2 upstream.
    Issuing a magic-sysrq via the PL011 causes the following lockdep splat,
    which is easily reproducible under QEMU:
      | sysrq: Changing Loglevel
      | sysrq: Loglevel set to 9
      | ======================================================
      | WARNING: possible circular locking dependency detected
      | 5.9.0-rc7 #1 Not tainted
      | ------------------------------------------------------
      | systemd-journal/138 is trying to acquire lock:
      | ffffab133ad950c0 (console_owner){-.-.}-{0:0}, at: console_lock_spinning_enable+0x34/0x70
      | but task is already holding lock:
      | ffff0001fd47b098 (&port_lock_key){-.-.}-{2:2}, at: pl011_int+0x40/0x488
      | which lock already depends on the new lock.
      |  Possible unsafe locking scenario:
      |        CPU0                    CPU1
      |        ----                    ----
      |   lock(&port_lock_key);
      |                                lock(console_owner);
      |                                lock(&port_lock_key);
      |   lock(console_owner);
      |  *** DEADLOCK ***
    The issue being that CPU0 takes 'port_lock' on the irq path in pl011_int()
    before taking 'console_owner' on the printk() path, whereas CPU1 takes
    the two locks in the opposite order on the printk() path due to setting
    the "console_owner" prior to calling into into the actual console driver.
    Fix this in the same way as the msm-serial driver by dropping 'port_lock'
    before handling the sysrq.
    Cc: <stable@vger.kernel.org> # 4.19+
    Cc: Russell King <linux@armlinux.org.uk>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Jiri Slaby <jirislaby@kernel.org>
    Link: https://lore.kernel.org/r/20200811101313.GA6970@willie-the-truck
    Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
    Tested-by: default avatarWill Deacon <will@kernel.org>
    Signed-off-by: default avatarWill Deacon <will@kernel.org>
    Link: https://lore.kernel.org/r/20200930120432.16551-1-will@kernel.org
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
amba-pl011.c 71.6 KB