linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	linux-serial@vger.kernel.org
Subject: Re: [PATCH 1/2] tty: serial: 8250: always call tx_chars under spinlock
Date: Wed, 9 Dec 2020 12:23:25 +0100	[thread overview]
Message-ID: <X9CzrUVgyqeuREKK@localhost> (raw)
In-Reply-To: <20201209091728.2357-1-s.trumtrar@pengutronix.de>

On Wed, Dec 09, 2020 at 10:17:27AM +0100, Steffen Trumtrar wrote:
> In most cases serial8250_tx_chars is called with spinlock held.
> Fix the remaining location, too.

Please explain where __start_tx() is called without holding the port
lock and consider fixing that up.

> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> ---
>  drivers/tty/serial/8250/8250_port.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index b0af13074cd3..3310c2b70138 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -1559,6 +1559,7 @@ static void serial8250_stop_tx(struct uart_port *port)
>  static inline void __start_tx(struct uart_port *port)
>  {
>  	struct uart_8250_port *up = up_to_u8250p(port);
> +	unsigned long flags;
>  
>  	if (up->dma && !up->dma->tx_dma(up))
>  		return;
> @@ -1569,8 +1570,11 @@ static inline void __start_tx(struct uart_port *port)
>  
>  			lsr = serial_in(up, UART_LSR);
>  			up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
> -			if (lsr & UART_LSR_THRE)
> +			if (lsr & UART_LSR_THRE) {
> +				spin_lock_irqsave(&port->lock, flags);
>  				serial8250_tx_chars(up);
> +				spin_unlock_irqrestore(&port->lock, flags);
> +			}

Since several callers of __start_tx() do hold the lock, this change will
introduce a deadlock.

>  		}
>  	}

Johan

  parent reply	other threads:[~2020-12-09 11:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-09  9:17 [PATCH 1/2] tty: serial: 8250: always call tx_chars under spinlock Steffen Trumtrar
2020-12-09  9:17 ` [PATCH 2/2] tty: serial: 8250: wait till transmitter is empty Steffen Trumtrar
2020-12-09 11:26   ` Johan Hovold
2021-01-04 11:47     ` Steffen Trumtrar
2020-12-09 11:23 ` Johan Hovold [this message]
2021-01-04 11:42   ` [PATCH 1/2] tty: serial: 8250: always call tx_chars under spinlock Steffen Trumtrar
     [not found]   ` <87ft3hdj3n.fsf@pengutronix.de>
2021-01-05  7:33     ` Steffen Trumtrar

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=X9CzrUVgyqeuREKK@localhost \
    --to=johan@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=s.trumtrar@pengutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).