Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5833655iob; Tue, 10 May 2022 04:57:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxj5+Zu8Z7f9GUtD1MGTCdiHo5i/Ly7ppoP/ioOqEICh8k1EAjjY6SRkj5FWycT7q9DHe2h X-Received: by 2002:a17:90b:1e03:b0:1dc:5a7d:bba8 with SMTP id pg3-20020a17090b1e0300b001dc5a7dbba8mr22569575pjb.156.1652183878570; Tue, 10 May 2022 04:57:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652183878; cv=none; d=google.com; s=arc-20160816; b=heUy7rEf6Ncg3FXU3HXJHBoMUKPqYjfPpf15EznS2frkKExzSwvO/V7GdqNnRu+TMY 3z9xVkSCNKD298v+IS/JjlJhljLsHSch4/F+AuD29uHVYOjHnPS1nsHCPvAPsn/HZdco B9DBJmOWkVbeLGSkzeQ8Z5gGf6Yo/tCZctZEQvkzq17H2btEdFJnH5UWsl+/Aqm+BBs0 YEzUcOW/m791Ep24X8QJwwrg7rpMIFEPeW8fhWsZawo3WTAtcchSZwZd883H73H1ObGz 1+8HgcBDhTx5SxLTC8tJck8zkGjSvhAUff5N6uuQPAbBm+LgrvGzB3NN3Mwjf9FoYA/s O99Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qcfAdFbkeA1g2Kl2Spj7OETJ7n3bgekm6dIioojJcl8=; b=USLVdhc82hsAvnnlfQ3TxzbWnM4oO/8ffWyKAo00Xu+4iJ+ASBKNQrKSMoFAQTFDpf UIa7nXQU4xFCyQYdfuG27/1iClzstl/o6yyC3Sxlb4oZzamPiGkEhHgRoZsn5tCpnXjP au0KXdoQBBMIs/awnD8HnEAvCmXaj5Xaaja5pGU98alHbcH2476c/Ilb+eGVJmGRyZrA g0WahJLzj2d2ddfmW3zQLItwDrht7p5DB0tIDK3r/17hQ2rXlykP98oJPLRC4y8kK1Rr 3iSWFjd7AX4S+Y9je12/cgXnGaeyZaygQUcIADoAfundtaGr8B3n6HHoOtyUKW+rOMCC HuNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=V54Hntel; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o24-20020a635a18000000b003aaba22d1casi18520150pgb.399.2022.05.10.04.57.43; Tue, 10 May 2022 04:57:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=V54Hntel; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239016AbiEJJlg (ORCPT + 99 others); Tue, 10 May 2022 05:41:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238987AbiEJJlX (ORCPT ); Tue, 10 May 2022 05:41:23 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCF24F31; Tue, 10 May 2022 02:37:25 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 88E461F896; Tue, 10 May 2022 09:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1652175444; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qcfAdFbkeA1g2Kl2Spj7OETJ7n3bgekm6dIioojJcl8=; b=V54Hntelf6pY6fAx/5lPsUuPLcR7TM2P2PkyAjxf5AXhodVs+nRJMTrUKMY87vv/V9LRqO YWVj+YsmEOYLsr92BgVlFds/ZEIaxMM1YHwFuffoAmYhI9n6UEn611z7FxRtmK/9jtdLtE mrJ5wsKIErdVYKKUNV0X0INQoCXRwro= Received: from suse.cz (unknown [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id BA5C72C141; Tue, 10 May 2022 09:37:23 +0000 (UTC) Date: Tue, 10 May 2022 11:37:23 +0200 From: Petr Mladek To: Neil Armstrong Cc: John Ogness , Greg Kroah-Hartman , Kevin Hilman , Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org, Jiri Slaby , Jerome Brunet , Martin Blumenstingl , linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, Marek Szyprowski Subject: Re: [PATCH v1] serial: meson: acquire port->lock in startup() Message-ID: References: <20220508103547.626355-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 2022-05-09 09:36:40, Neil Armstrong wrote: > On 08/05/2022 12:35, John Ogness wrote: > > The uart_ops startup() callback is called without interrupts > > disabled and without port->lock locked, relatively late during the > > boot process (from the call path of console_on_rootfs()). If the > > device is a console, it was already previously registered and could > > be actively printing messages. > > > > Since the startup() callback is reading/writing registers used by > > the console write() callback (AML_UART_CONTROL), its access must > > be synchronized using the port->lock. Currently it is not. > > > > The startup() callback is the only function that explicitly enables > > interrupts. Without the synchronization, it is possible that > > interrupts become accidentally permanently disabled. > > > > CPU0 CPU1 > > meson_serial_console_write meson_uart_startup > > -------------------------- ------------------ > > spin_lock(port->lock) > > val = readl(AML_UART_CONTROL) > > uart_console_write() > > writel(INT_EN, AML_UART_CONTROL) > > writel(val, AML_UART_CONTROL) > > spin_unlock(port->lock) > > > > Add port->lock synchronization to meson_uart_startup() to avoid > > racing with meson_serial_console_write(). > > > > Also add detailed comments to meson_uart_reset() explaining why it > > is *not* using port->lock synchronization. > > > > Link: https://lore.kernel.org/lkml/2a82eae7-a256-f70c-fd82-4e510750906e@samsung.com > > Reported-by: Marek Szyprowski > > Signed-off-by: John Ogness > > Tested-by: Marek Szyprowski > > --- > > drivers/tty/serial/meson_uart.c | 13 +++++++++++++ > > 1 file changed, 13 insertions(+) > > > > diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c > > index 2bf1c57e0981..39021dac09cc 100644 > > --- a/drivers/tty/serial/meson_uart.c > > +++ b/drivers/tty/serial/meson_uart.c > > @@ -253,6 +253,14 @@ static const char *meson_uart_type(struct uart_port *port) > > return (port->type == PORT_MESON) ? "meson_uart" : NULL; > > } > > +/* > > + * This function is called only from probe() using a temporary io mapping > > + * in order to perform a reset before setting up the device. Since the > > + * temporarily mapped region was successfully requested, there can be no > > + * console on this port at this time. Hence it is not necessary for this > > + * function to acquire the port->lock. (Since there is no console on this > > + * port at this time, the port->lock is not initialized yet.) > > + */ > > static void meson_uart_reset(struct uart_port *port) > > { > > u32 val; > > @@ -267,9 +275,12 @@ static void meson_uart_reset(struct uart_port *port) > > static int meson_uart_startup(struct uart_port *port) > > { > > + unsigned long flags; > > u32 val; > > int ret = 0; > > + spin_lock_irqsave(&port->lock, flags); > > + > > val = readl(port->membase + AML_UART_CONTROL); > > val |= AML_UART_CLEAR_ERR; > > writel(val, port->membase + AML_UART_CONTROL); > > @@ -285,6 +296,8 @@ static int meson_uart_startup(struct uart_port *port) > > val = (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2)); > > writel(val, port->membase + AML_UART_MISC); > > + spin_unlock_irqrestore(&port->lock, flags); > > + > > ret = request_irq(port->irq, meson_uart_interrupt, 0, > > port->name, port); > > > > base-commit: 672c0c5173427e6b3e2a9bbb7be51ceeec78093a > > Thanks for fixing this, it may also fix an uart apparent lockup I encountered > several time while developing on the platform, but the target was still alive > so it matches. > > So I'll add: > Fixes: ff7693d079e5 ("ARM: meson: serial: add MesonX SoC on-chip uart driver") > > and > > Acked-by: Neil Armstrong Neil, may I assume that you are going to queue this fix for 5.19, please? Feel free to add: Reviewed-by: Petr Mladek Best Regards, Petr