From: sashiko-bot@kernel.org
To: "Praneeth Balasubramanian" <praneethb2002@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH 3/4] tty: atmel_serial: take the port lock in console write
Date: Sat, 05 Dec 2026 06:59:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-251173@kernel.org> (raw)
In-Reply-To: <20261205063536.2519566-4-praneethb2002@gmail.com>
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 <praneethb2002@gmail.com>
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_port *port, unsigned char ch)
> atmel_uart_write_char(port, ch);
> }
>
> -/*
> - * Interrupts are disabled on entering
> - */
> static void atmel_console_write(struct console *co, const char *s, u_int count)
> {
> struct uart_port *port = &atmel_ports[co->index].uart;
> struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
> unsigned int status, imr;
> unsigned int pdc_tx;
> + unsigned long flags;
> + int locked = 1;
> +
> + if (port->sysrq)
> + locked = 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 = 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 = 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 */
<hardirq>
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 == 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205063536.2519566-1-praneethb2002@gmail.com?part=3
next prev parent reply other threads:[~2026-12-05 6:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 6:35 [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers Praneeth Balasubramanian
2026-12-05 6:35 ` [PATCH 1/4] tty: hvsi: fix stack overread in hvsi_version_respond() Praneeth Balasubramanian
2026-12-05 6:53 ` sashiko-bot
2026-12-05 6:35 ` [PATCH 2/4] serial: men_z135_uart: do not release an unrequested memory region Praneeth Balasubramanian
2026-12-05 6:35 ` [PATCH 3/4] tty: atmel_serial: take the port lock in console write Praneeth Balasubramanian
2026-12-05 6:59 ` sashiko-bot [this message]
2026-12-05 6:35 ` [PATCH 4/4] mxser: take termios_rwsem in mxser_set_serial_info() Praneeth Balasubramanian
2026-12-05 6:56 ` sashiko-bot
2026-12-05 6:59 ` [PATCH 0/4] tty: fix a stack overread and missing locking in serial drivers sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-251173@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=praneethb2002@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox