Re: [PATCH v4 2/4] serial: 8250: introduce serial8250_discard_data()
From: John Ogness
Date: Fri Apr 25 2025 - 04:22:35 EST
On 2025-04-25, Yunhui Cui <cuiyunhui@xxxxxxxxxxxxx> wrote:
> To prevent triggering PSLVERR, it is necessary to check whether the
> UART_LSR_DR bit of UART_LSR is set before reading UART_RX.
> Ensure atomicity of UART_LSR and UART_RX, put serial8250_discard_data()
> under port->lock.
>
> Signed-off-by: Yunhui Cui <cuiyunhui@xxxxxxxxxxxxx>
> ---
> drivers/tty/serial/8250/8250.h | 15 +++++++++++
> drivers/tty/serial/8250/8250_port.c | 42 ++++++++++++++---------------
> 2 files changed, 36 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index a913135d5217..802ac50357c0 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -2137,25 +2136,21 @@ static void wait_for_xmitr(struct uart_8250_port *up, int bits)
> static int serial8250_get_poll_char(struct uart_port *port)
> {
> struct uart_8250_port *up = up_to_u8250p(port);
> - int status;
> + int status = NO_POLL_CHAR;
> u16 lsr;
>
> serial8250_rpm_get(up);
>
> + uart_port_lock_irqsave(port, &flags);
> lsr = serial_port_in(port, UART_LSR);
The ->poll_get_char() callback is used for kdb/kgdb.
Adding a spinlock here could lead to deadlock. However, I see that
serial8250_rpm_get() is already in there, which goes down a rabbit hole
of possible issues. So I guess we really don't care about possible
kdb/kgdb deadlocks for now.
I can look into cleaning this up with my next 8250 nbcon console
series. So for now, I am OK with you adding the spin_lock() in this
callback.
John Ogness