From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796453943; b=1fFeogfmhH+BL/FB1k6N1IWjH+7G8jatWcI2Sq7FxvkwhQrI3EnqGD9xV1COXYCw5ymM TnJ97c0r0aDcR/s55ahchQMF7uIVZ9FuS3YmY773okC8dIWvzk0lAcjEV/PQwZy/U4Fnv /uSGcj38+xhnxk9N6p8Fu1KWTdv+VLM5kLKz2DzDic3O25/NSuKBRGmSBJOs9cK1YBQvG fs6pqexovBPG095yA7r7BwOG0CmFP+gGH06N04SLGe2e8kf6UIoKaAjS7MiCVDnzoa0ez saco+SYVQHjrAyop1d+5HAFi2szG4Gm25+sGHDzEr4qoiKYMsQvd9lKRmc0C5UAJDCA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796453943; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=gstsgpyMXb/5CeWUG5uL1iCX/Aw1uGwuZZbhW4XnRcY=; b=UWzSCN20uL/VayEuy1rY1Ggvmv9GcaAj8esL8OL8cZsSqR+1wRE5d4B2GoumkH/nT8Ny AeQJzHvgEl28l+eYMwUgnPH3VKzJljaOQVqWA85ccmcCmpwbFRwNCEvwQeP6D1q0CdxO7 lDHcNnuqdBIIFByrUkEJ5S05PEbCzn8WqhhVLuuBTBfPZvnvvUG5s6BoRNeDEZck/sqRW kL6BUgpvXUkuEH6OYRVmxtY9X9WhjyKJ7koQ1uUR8OMAJ8UWizY0RnxvZEI6Kg3yb74D6 cRp+bzOQYDDuD+Ty9J5B0ymp6ytIqPx3aUuJpe6wK+mnjjLfK/yhUQ73BhhM+AKUOFw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cZloc5vg; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4B22606A322 for ; Sat, 5 Dec 2026 06:59:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cZloc5vg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2ED1C1F0092B; Sat, 5 Dec 2026 06:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796453943; bh=gstsgpyMXb/5CeWUG5uL1iCX/Aw1uGwuZZbhW4XnRcY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cZloc5vgA4LFKXYuFWZ/sTrhcmtdjMHJ0rfSeWSLyktis5T25ZWlIOY+PakqUbT4P ESBt3KGLqELwrY+zBEdkr8ET8H5RRmyRD+1FRo/+Uu324PJIHdPxfq6o8cl1LHDLJ2 3gRHiwlEHHWimJMOzgSW1EXnmtQvYdtBDJN0/+KM74FOHQKutDhnvsFuBjB7iI2xfu rCAbFQyGyFoyLJvVHdbjJbZW0wqckrux11fAjlVjffFmqXnFLeTE1o9GjuqL7zEhCN SLa87bCNvvX96ct+gAMDh9zP7lu7vj6v8a87LjpR97GDFJe7YQYFpPpVJw0n5dL6TN aGckrtHBwAJAA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 3/4] tty: atmel_serial: take the port lock in console write Reply-To: sashiko-reviews@lists.linux.dev To: "Praneeth Balasubramanian" Cc: linux-serial@vger.kernel.org In-Reply-To: <20261205063536.2519566-4-praneethb2002@gmail.com> References: <20261205063536.2519566-1-praneethb2002@gmail.com> <20261205063536.2519566-4-praneethb2002@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 06:59:02 +0000 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Critical] tty: atmel_serial: recursive port lock deadlock on logging under port lock - [High] tty: atmel_serial: hardirq/softirq deadlock on port lock with RX/TX tasklets - [High] tty: atmel_serial: AB-BA deadlock between port lock and console_owner - [High] tty: atmel_serial: irq-unsafe port lock deadlocks with atmel_console_write() - [Medium] tty: atmel_serial: port->sysrq check skips lock indefinitely after break -- commit 99224e11232161cad99f0c12681da9d80a90e8dd Author: Praneeth Balasubramanian tty: atmel_serial: take the port lock in console write This commit acquires port->lock with uart_port_lock_irqsave() in atmel_console_write() to serialize console output against other TX paths, skipping the lock when port->sysrq is set and using a trylock when oops_in_progress is set. > diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel= _serial.c > index c3880259e3bce..7446c956262ae 100644 > --- a/drivers/tty/serial/atmel_serial.c > +++ b/drivers/tty/serial/atmel_serial.c > @@ -2560,15 +2560,21 @@ static void atmel_console_putchar(struct uart_por= t *port, unsigned char ch) > atmel_uart_write_char(port, ch); > } > =20 > -/* > - * Interrupts are disabled on entering > - */ > static void atmel_console_write(struct console *co, const char *s, u_int= count) > { > struct uart_port *port =3D &atmel_ports[co->index].uart; > struct atmel_uart_port *atmel_port =3D to_atmel_uart_port(port); > unsigned int status, imr; > unsigned int pdc_tx; > + unsigned long flags; > + int locked =3D 1; > + > + if (port->sysrq) > + locked =3D 0; [Severity: Medium] Can this skip port->lock indefinitely after a lone serial break? When a break arrives on the console port, uart_handle_break() sets port->sysrq =3D jiffies + SYSRQ_TIMEOUT and atmel_tasklet_rx_func() immediately drops port->lock. No timer clears port->sysrq; it stays non-zero until another RX character or break arrives, leaving atmel_console_write() completely unlocked (and preemptible with IRQs enabled on PREEMPT_RT) and re-exposing the TX register races against atmel_stop_tx() and atmel_start_tx(). Switching atmel_rx_from_ring() to uart_prepare_sysrq_char() and atmel_tasklet_rx_func() to uart_unlock_and_check_sysrq_irqrestore() runs handle_sysrq() outside port->lock so atmel_console_write() never needs to bypass locking on port->sysrq. Also, the commit message says atmel_rx_chars() calls uart_handle_sysrq_char() under port->lock and that this follows the pl011 pattern, whereas atmel_rx_from_ring() is the caller and amba-pl011.c uses uart_prepare_sysrq_char() and nbcon callbacks rather than skipping the lock on port->sysrq. > + else if (oops_in_progress) > + locked =3D uart_port_trylock_irqsave(port, &flags); > + else > + uart_port_lock_irqsave(port, &flags); [Severity: Critical] Does taking port->lock here self-deadlock whenever atmel_serial logs while holding port->lock? On non-PREEMPT_RT kernels, dev_err(), dev_warn(), and dev_dbg() invoke atmel_console_write() synchronously on the same CPU. An unprivileged local user with the console tty open can trigger a deterministic hang via TIOCSISO7816 with tg > 255: uart_set_iso7816_config() holds port->lock across atmel_config_iso7816(), which calls dev_err() and re-enters atmel_console_write(). Even when logging on a non-console Atmel UART, all uart_port locks share lockdep class port_lock_key and trigger a recursive-locking splat. [Severity: High] Can this self-deadlock against atmel_tasklet_rx_func() and atmel_tasklet_tx_func() when a hardirq calls printk()? Both tasklets run in softirq context with local hard interrupts enabled and acquire port->lock via plain uart_port_lock(port) (which does not disable hardirqs). On non-PREEMPT_RT kernels, legacy con->write() runs synchronously in hardirq context: atmel_tasklet_rx_func() uart_port_lock(port) /* hardirqs still enabled */ atmel_interrupt() atmel_handle_transmit() dev_warn(...) -> printk() atmel_console_write() uart_port_lock_irqsave(port, &flags) <-- spins forever Both tasklet callbacks need to use IRQ-disabling port lock variants (uart_port_lock_irqsave() or uart_port_lock_irq()) if atmel_console_write() takes port->lock. [Severity: High] Does this introduce an ABBA deadlock between port->lock and console_owner on SMP? atmel_rx_from_ring() calls uart_handle_sysrq_char() -> handle_sysrq() -> printk() while atmel_tasklet_rx_func() holds port->lock, which can spin waiting on console_owner in console_trylock_spinning(). Meanwhile, another CPU printing to the console holds console_owner, observes port->sysrq =3D=3D 0 in atmel_console_write(), and blocks on port->lock: CPU0 CPU1 ---- ---- lock(&port->lock) lock(console_owner) lock(console_owner) lock(&port->lock) *** DEADLOCK *** CPU0: atmel_tasklet_rx_func() -> atmel_rx_from_ring() -> uart_handle_sysrq_char() -> handle_sysrq() -> printk() -> console_trylock_spinning() CPU1: printk() -> console_emit_next_record() -> atmel_console_write() Using uart_prepare_sysrq_char() under port->lock and dispatching SysRq after unlock via uart_unlock_and_check_sysrq_irqrestore() removes this lock-order inversion. [Severity: High] Can atmel_tx_dma() and atmel_tasklet_tx_func() also hang the system on CONFIG_SMP or CONFIG_DEBUG_SPINLOCK builds once atmel_console_write() takes port->lock? atmel_tasklet_tx_func() takes port->lock with plain uart_port_lock(port) and calls atmel_tx_dma(), which calls dev_err() on DMA prep or submit failures. On non-PREEMPT_RT kernels built with CONFIG_SMP (such as multi_v7_defconfig or arm64) or CONFIG_DEBUG_SPINLOCK, either a hardirq printk() interrupting the tasklet or a dev_err() from atmel_tx_dma() on the console port immediately self-deadlocks in uart_port_lock_irqsave(). Disabling interrupts when locking in the tasklets and avoiding dev_err() or dev_warn() under port->lock are needed alongside this change. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205063536.2519= 566-1-praneethb2002@gmail.com?part=3D3