linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: Johan Hovold <johan@kernel.org>
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: Tue, 05 Jan 2021 08:33:43 +0100	[thread overview]
Message-ID: <87r1mzon1k.fsf@pengutronix.de> (raw)
In-Reply-To: <87ft3hdj3n.fsf@pengutronix.de>


Steffen Trumtrar <s.trumtrar@pengutronix.de> writes:

> Hi!
>
> Johan Hovold <johan@kernel.org> writes:
>
>> 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.
>>
>
> Meh, yeah :(
>
> Seem like the correct solution would be to fix start_tx_rs485 and
> serial8250_start_tx instead.
>

Scratch that. This patch is bogus, I'm stupid, port-lock is already held
by uart_write apart from the hrtimer-callback.

Sorry for the noise.


Best regards,
Steffen Trumtrar

--
Pengutronix e.K.                | Dipl.-Inform. Steffen Trumtrar |
Steuerwalder Str. 21            | https://www.pengutronix.de/    |
31137 Hildesheim, Germany       | Phone: +49-5121-206917-0       |
Amtsgericht Hildesheim, HRA 2686| Fax:   +49-5121-206917-5555    |

      parent reply	other threads:[~2021-01-05  7:34 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 ` [PATCH 1/2] tty: serial: 8250: always call tx_chars under spinlock Johan Hovold
2021-01-04 11:42   ` Steffen Trumtrar
     [not found]   ` <87ft3hdj3n.fsf@pengutronix.de>
2021-01-05  7:33     ` Steffen Trumtrar [this message]

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