From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E8A9C433E6 for ; Tue, 5 Jan 2021 07:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C975022581 for ; Tue, 5 Jan 2021 07:34:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726776AbhAEHea (ORCPT ); Tue, 5 Jan 2021 02:34:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725822AbhAEHe3 (ORCPT ); Tue, 5 Jan 2021 02:34:29 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 719E3C061574 for ; Mon, 4 Jan 2021 23:33:49 -0800 (PST) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0] helo=leviathan.pengutronix.de) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwgqe-0003Gm-7x; Tue, 05 Jan 2021 08:33:44 +0100 References: <20201209091728.2357-1-s.trumtrar@pengutronix.de> <87ft3hdj3n.fsf@pengutronix.de> User-agent: mu4e 1.4.12; emacs 28.0.50 From: Steffen Trumtrar To: Johan Hovold Cc: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org Subject: Re: [PATCH 1/2] tty: serial: 8250: always call tx_chars under spinlock In-reply-to: <87ft3hdj3n.fsf@pengutronix.de> Date: Tue, 05 Jan 2021 08:33:43 +0100 Message-ID: <87r1mzon1k.fsf@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: s.trumtrar@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-serial@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Steffen Trumtrar writes: > Hi! > > Johan Hovold 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 >>> --- >>> 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 |