From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Yunhui Cui <cuiyunhui@bytedance.com>
Cc: ilpo.jarvinen@linux.intel.com, gregkh@linuxfoundation.org,
jirislaby@kernel.org, john.ogness@linutronix.de,
pmladek@suse.com, arnd@arndb.de, namcao@linutronix.de,
benjamin.larsson@genexis.eu, schnelle@linux.ibm.com,
heikki.krogerus@linux.intel.com, markus.mayer@linaro.org,
tim.kryger@linaro.org, matt.porter@linaro.org,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH v3] serial: 8250: fix panic due to PSLVERR
Date: Mon, 14 Apr 2025 11:47:36 +0300 [thread overview]
Message-ID: <Z_zLqH1Moavhi52x@smile.fi.intel.com> (raw)
In-Reply-To: <20250414031450.42237-1-cuiyunhui@bytedance.com>
On Mon, Apr 14, 2025 at 11:14:50AM +0800, Yunhui Cui wrote:
You forgot to rebase against latest tty-next or, if there is something
in the latter (but I don't see right now), even tty-testing.
> When the PSLVERR_RESP_EN parameter is set to 1, the device generates
> an error response if an attempt is made to read an empty RBR (Receive
> Buffer Register) while the FIFO is enabled.
>
> In serial8250_do_startup(), calling serial_port_out(port, UART_LCR,
> UART_LCR_WLEN8) triggers dw8250_check_lcr(), which invokes
> dw8250_force_idle() and serial8250_clear_and_reinit_fifos(). The latter
> function enables the FIFO via serial_out(p, UART_FCR, p->fcr).
> Execution proceeds to the dont_test_tx_en label:
> ...
> serial_port_in(port, UART_RX);
> This satisfies the PSLVERR trigger condition.
>
> Because another CPU(e.g., using printk()) is accessing the UART (UART
> is busy), the current CPU fails the check (value & ~UART_LCR_SPAR) ==
> (lcr & ~UART_LCR_SPAR), causing it to enter dw8250_force_idle().
>
> To fix this, all calls to serial_out(UART_LCR) and serial_in(UART_RX)
> should be executed under port->lock. Additionally, checking the readiness
> via UART_LSR should also be done under port->lock.
>
> Panic backtrace:
> [ 0.442336] Oops - unknown exception [#1]
> [ 0.442343] epc : dw8250_serial_in32+0x1e/0x4a
> [ 0.442351] ra : serial8250_do_startup+0x2c8/0x88e
> ...
> [ 0.442416] console_on_rootfs+0x26/0x70
This patch seems need split to three. See below.
...
First of all, while everything looks better now, there is a chance in the
future to miss the same issue again. In order to avoid that I suggest to
introduce a new helper where you made this check _and_ add a comment why.
(Note that currently you have a mixture of serial_in()/serial_port_in() in
some cases.)
static inline unsigned int serial8250_discard_data(struct uart_8250_port *up)
{
u16 lsr;
lsr = serial_in(up, UART_LSR);
if (lsr & UART_LSR_DR)
return serial_in(up, UART_RX);
return 0;
}
And this can be one patch (patch 2).
...
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
Changes here deserve the separate patch (patch 1).
...
> + /*
> + * Serial_in(p, UART_RX) should be under port->lock, but we can't add
serial_in()
> + * it to avoid AA deadlock as we're unsure if serial_out*(...UART_LCR)
> + * is under port->lock.
> + */
> + lockdep_assert_held_once(&p->lock);
...
> + uart_port_lock_irqsave(port, &flags);
And one patch (patch 3) about locking.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-04-14 8:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-14 3:14 [PATCH v3] serial: 8250: fix panic due to PSLVERR Yunhui Cui
2025-04-14 8:47 ` Andy Shevchenko [this message]
2025-04-21 2:55 ` [External] " yunhui cui
2025-04-22 7:44 ` Andy Shevchenko
2025-04-14 11:41 ` Ilpo Järvinen
2025-04-16 12:04 ` Ilpo Järvinen
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=Z_zLqH1Moavhi52x@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=benjamin.larsson@genexis.eu \
--cc=cuiyunhui@bytedance.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=markus.mayer@linaro.org \
--cc=matt.porter@linaro.org \
--cc=namcao@linutronix.de \
--cc=pmladek@suse.com \
--cc=schnelle@linux.ibm.com \
--cc=tim.kryger@linaro.org \
/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