Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp634202iog; Mon, 13 Jun 2022 09:33:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v5RrP0J1ao56Q6tgTwi6AlZZ1rU0Kl0i9RId4TOSfyZY6K7OpXyMoRZghsFtNYKna/WEVi X-Received: by 2002:a17:90a:468d:b0:1df:39da:322b with SMTP id z13-20020a17090a468d00b001df39da322bmr613120pjf.137.1655138025985; Mon, 13 Jun 2022 09:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655138025; cv=none; d=google.com; s=arc-20160816; b=NRu+XattpRXWCVcehLOfEk5hiLbe/r5rFx1wLlP5w35P5EQlONlkIoUTTIV4+rNdj+ kKYOWqnrpXiQ4UVJaSNGRkMK92SphVlKCMg06gSfogA2Gu5dw/CrtNSVQaHrFgH4UHtF o+d8JjqumDGRmnJjzNaAfDowRvhCkSrTzStLBUXxWIrnBALNi8Tq75fr9bxu0xsiHDke le5dBFdrzMSElaaqXkmKx8P09n6DmwAwVmVm8Nek3gUkZRIFWX+ZpsEtGqnd3keuN0qc mehioNcPOfXDaYOPqEreliGfynbQDj/CBsip0XI+LNDSHI4IxJt0q/13El1mc37avbeD GGsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bnwabRwvxgoyVC1uheohsMWVn0ucdgx+hbFOxj6IAiM=; b=osOBcVXKhrXysa5xvP/6Tp89rdMv+j7g1JIohpInSSvpUIrW5VBW1r1vlxWb+15izK lWAYv+PP/2Za/milCDlH/pB58quAeT+yEqtWIx1UNlvY6D/vjVqiHklTFFLEmhWKRYko krgQ+jGPwlCnNGTMKh9MKz7Tp5ZsEq0e7PXEAnHQxtv82gFQRn8Pd8K/a2Jr8SuEutmF GRg4LhQloFIBNKsPue81CRd3ktd07QJT2t9j7b1w3lvfx+ryFfAG4bZAVTIAw76ZlI/p EIJStluFSPTDtTzV1UN1HdmPG6yQarYMz4c157ueeXPw8+gwpkOJ68ZRj2tqh4jZeTaa WUQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0H7tLbe2; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a170902e80b00b0016511ed9294si11832006plg.86.2022.06.13.09.33.31; Mon, 13 Jun 2022 09:33:45 -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=@linuxfoundation.org header.s=korg header.b=0H7tLbe2; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241291AbiFMNFC (ORCPT + 99 others); Mon, 13 Jun 2022 09:05:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355507AbiFMMzR (ORCPT ); Mon, 13 Jun 2022 08:55:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A9BBB4AC; Mon, 13 Jun 2022 04:15:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 13785B80EAA; Mon, 13 Jun 2022 11:15:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 612BCC34114; Mon, 13 Jun 2022 11:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655118931; bh=Khduy9z1D5fs1MdqY+9JrX/W2pwEvQY+bI09HiNPlUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0H7tLbe2ou4TgS0nJlhkP784VE0SmvlPA0F9YUa7lVZTq34sAtGH03KR0Px3Z9w+k JIEMpe5ZLN9rKpkgXQ9QXZ9NvMetwaFwMp7PpVkRoiaiSKbT/NyWvqpvpF4uZocMJh u5GstjLAiC5krOlNCzjiuy7Gvom2MII2jAgCPplc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Szyprowski , Petr Mladek , Jiri Slaby , Neil Armstrong , John Ogness , Sasha Levin Subject: [PATCH 5.15 052/247] serial: meson: acquire port->lock in startup() Date: Mon, 13 Jun 2022 12:09:14 +0200 Message-Id: <20220613094924.532927936@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: John Ogness [ Upstream commit 589f892ac8ef244e47c5a00ffd8605daa1eaef8e ] 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 Fixes: ff7693d079e5 ("ARM: meson: serial: add MesonX SoC on-chip uart driver") Reported-by: Marek Szyprowski Tested-by: Marek Szyprowski Reviewed-by: Petr Mladek Reviewed-by: Jiri Slaby Acked-by: Neil Armstrong Signed-off-by: John Ogness Link: https://lore.kernel.org/r/20220508103547.626355-1-john.ogness@linutronix.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- 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 efee3935917f..62e6c1af1344 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); -- 2.35.1