From patchwork Mon May 8 08:20:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 91026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1997700vqo; Mon, 8 May 2023 01:34:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7VLIgCenUxGnXkhmf8WpRm08Y0qrC/mVX3wYJab1uHIh3YK3pj9BdlmhHr6TPpPN7dKyiz X-Received: by 2002:a05:6a20:8e19:b0:ee:524e:8426 with SMTP id y25-20020a056a208e1900b000ee524e8426mr10673461pzj.31.1683534862728; Mon, 08 May 2023 01:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683534862; cv=none; d=google.com; s=arc-20160816; b=lXOapIG78juqBv74Q+lg2KpzZNl/bJRMOXgLHYstt3FFe+fcztrDdJN72psVLAWzdk X1gqszOUUv73I6F7VLeQ2idJLKDjDwZmDEZpXXgZ7Nv7Bs34lX/vHcT50v04qIcC0F+r /38mAcg0x48e5ZgRg9GI2W7DKdsaN9cVM/6LjApLqna9rsQXyAobvK5dkto0z3O+DDVG 5UXwzRsdycrCguxAiMNrr1JNFGlItJPKjaomq4AHoZ8k2+ykPJxEWZTCJmSqK+2ggL4H KZhinlFuz0Og0b4nuDk/h0AvE5LK4Ak4ZBvwbeEeu5QOxPQ0oYtjYP0aHe5G+nv8PHY5 D8nQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=SdBPHpNs8y1BygS4BXfCOOjKzxbO4k+Xt12lh0hVAYM=; b=dfOQbqPN4cBFtIQrxEaygOyi+ZggWoftph2Lw08aDrV7IDW/9H2xq2pnFyNDZN2cDh YC19XXDBNo0qlsHjksDJOWXLW5+GyC2jijxVTv1ekHQiHdmjoLpPitTjSnQrWFXZf0NE pyzuhzUnWMwhlIvZQpYs0wF4t2bKY+RT9oec1XKzpgI1M/wYXa6q6Sk4/KQcW85QKxyA 3unOXfjw1pGdR5S1L3FSIItaEKPXNOfCFLhPvzK/n97iU37ZWmnI0Akju3Zx2iw2uwDY sbFSQI/9AZCeSU6+nDqIpeNOD/8KLGOw1+VYiJHBvobqT/3g5EyDP03O95JRoLHS88gX HOtQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w71-20020a63824a000000b0051358b5c88bsi7887011pgd.452.2023.05.08.01.34.09; Mon, 08 May 2023 01:34:22 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233628AbjEHIUg (ORCPT + 99 others); Mon, 8 May 2023 04:20:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232438AbjEHIUf (ORCPT ); Mon, 8 May 2023 04:20:35 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1FD471AEF2; Mon, 8 May 2023 01:20:30 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id BB2998121; Mon, 8 May 2023 08:20:27 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Peter Hurley , Sebastian Andrzej Siewior Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Johan Hovold , Vignesh Raghavendra , linux-omap@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] serial: 8250: omap: Fix freeing of resources on failed register Date: Mon, 8 May 2023 11:20:11 +0300 Message-Id: <20230508082014.23083-2-tony@atomide.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230508082014.23083-1-tony@atomide.com> References: <20230508082014.23083-1-tony@atomide.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765314252060052845?= X-GMAIL-MSGID: =?utf-8?q?1765314252060052845?= If serial8250_register_8250_port() fails, the SoC can hang as the deferred PMQoS work will still run as is not flushed and removed. Fixes: 61929cf0169d ("tty: serial: Add 8250-core based omap driver") Signed-off-by: Tony Lindgren Reviewed-by: Ilpo Järvinen --- drivers/tty/serial/8250/8250_omap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -1532,7 +1532,9 @@ static int omap8250_probe(struct platform_device *pdev) err: pm_runtime_dont_use_autosuspend(&pdev->dev); pm_runtime_put_sync(&pdev->dev); + flush_work(&priv->qos_work); pm_runtime_disable(&pdev->dev); + cpu_latency_qos_remove_request(&priv->pm_qos_request); return ret; } From patchwork Mon May 8 08:20:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 91022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1994958vqo; Mon, 8 May 2023 01:27:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ea4iKNe31xVugHrr4uqAko47nZUKF8BlC/b1uvC5JYcg7PcmpJvZZAtu6It48kGC1+y+A X-Received: by 2002:a05:6a20:3d94:b0:d9:6660:8746 with SMTP id s20-20020a056a203d9400b000d966608746mr13053356pzi.18.1683534471392; Mon, 08 May 2023 01:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683534471; cv=none; d=google.com; s=arc-20160816; b=vxzB0xZMouh69qWkiBXed21e5FBOJCMLnYaGKPOF8c5k0t+pCNsnOYLM1Jdb/8mpIE tm7TlkKcAjrxbqByksfpUsqYRPY2NNeTaTtAHX7FQ9m5CjbjZRN6X/xFEevCacqML/Kt pFBOhcffDI2EoklaBS1YV1F6sOcbBC1uVelzfcZjxx8FM0i037FQNl29eF7H9C72cBF0 Q5+2bNwQzoW02dbnIWO69U0f70/K6qTHYhfyEoHyAAd4XY8CHKQPMOakac+wrYweKjuW MDdnkGBMxUXt4DIdyP38KIn7hIgjk+I6EtQuoQzdq987J5uZiiOyGSLh2XbBMJpOWaEy Joog== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=F5fh73nLprL65xbD+z2mYae1uRUJt/Q9O3BO4s3yxlA=; b=FkOfVocyxRVLtSU5JMCi3d0vwklTL9Skf1QmhqIE9wfIru2cqR5P/4+0eVsflOM/GF Mprc2tvfeW/hbzc6+Y68rrG1KkgsDC204r5ALIBTbgMldO310Hd6rvKr34+Q/n5urvmZ O1kHb3X9W+eY7U71EvDnRFDEYvEMHUhUBP86VSeM/W9JL2Wcs4qXsXYkCmOGAKaiyVfR w5wU58C3/aovpyaS4Oh0tMkiINIAbpCFJWRbBca69K/1DP8bEOG53XcvOIUXsiL+9vRl LC03IS59v+H+pY+KW068Lu3RBw5q+DG1JyThlLv3IZ8QtuRaPx3qeeZ3mgUACw8CGoXG CAzg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c11-20020a63350b000000b0052c6b9b185esi7538111pga.86.2023.05.08.01.27.38; Mon, 08 May 2023 01:27:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233640AbjEHIUj (ORCPT + 99 others); Mon, 8 May 2023 04:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233587AbjEHIUg (ORCPT ); Mon, 8 May 2023 04:20:36 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 414521C0CC; Mon, 8 May 2023 01:20:35 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 1174781BC; Mon, 8 May 2023 08:20:32 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-omap@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] serial: 8250: omap: Fix imprecise external abort for omap_8250_pm() Date: Mon, 8 May 2023 11:20:12 +0300 Message-Id: <20230508082014.23083-3-tony@atomide.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230508082014.23083-1-tony@atomide.com> References: <20230508082014.23083-1-tony@atomide.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765313841846497455?= X-GMAIL-MSGID: =?utf-8?q?1765313841846497455?= We must idle the uart only after serial8250_unregister_port(). Otherwise unbinding the uart via sysfs while doing cat on the port produces an imprecise external abort: mem_serial_in from omap_8250_pm+0x44/0xf4 omap_8250_pm from uart_hangup+0xe0/0x194 uart_hangup from __tty_hangup.part.0+0x37c/0x3a8 __tty_hangup.part.0 from uart_remove_one_port+0x9c/0x22c uart_remove_one_port from serial8250_unregister_port+0x60/0xe8 serial8250_unregister_port from omap8250_remove+0x6c/0xd0 omap8250_remove from platform_remove+0x28/0x54 Turns out the driver needs to have runtime PM functional before the driver probe calls serial8250_register_8250_port(). And it needs runtime PM after driver remove calls serial8250_unregister_port(). On probe, we need to read registers before registering the port in omap_serial_fill_features_erratas(). We do that with custom uart_read() already. On remove, after serial8250_unregister_port(), we need to write to the uart registers to idle the device. Let's add a custom uart_write() for that. Currently the uart register access depends on port->membase to be initialized, which won't work after serial8250_unregister_port(). Let's use priv->membase instead, and use it for runtime PM related functions to remove the dependency to port->membase for early and late register access. Note that during use, we need to check for a valid port in the runtime PM related functions. This is needed for the optional wakeup configuration. We now need to set the drvdata a bit earlier so it's available for the runtime PM functions. With the port checks in runtime PM functions, the old checks for priv in omap8250_runtime_suspend() and omap8250_runtime_resume() functions are no longer needed and are removed. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_omap.c | 70 ++++++++++++++++------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -32,6 +32,7 @@ #include "8250.h" #define DEFAULT_CLK_SPEED 48000000 +#define OMAP_UART_REGSHIFT 2 #define UART_ERRATA_i202_MDR1_ACCESS (1 << 0) #define OMAP_UART_WER_HAS_TX_WAKEUP (1 << 1) @@ -115,6 +116,7 @@ #define UART_OMAP_RX_LVL 0x19 struct omap8250_priv { + void __iomem *membase; int line; u8 habit; u8 mdr1; @@ -159,9 +161,14 @@ static void omap_8250_rx_dma_flush(struct uart_8250_port *p); static inline void omap_8250_rx_dma_flush(struct uart_8250_port *p) { } #endif -static u32 uart_read(struct uart_8250_port *up, u32 reg) +static u32 uart_read(struct omap8250_priv *priv, u32 reg) { - return readl(up->port.membase + (reg << up->port.regshift)); + return readl(priv->membase + (reg << OMAP_UART_REGSHIFT)); +} + +static void uart_write(struct omap8250_priv *priv, u32 reg, u32 val) +{ + writel(val, priv->membase + (reg << OMAP_UART_REGSHIFT)); } /* @@ -548,7 +555,7 @@ static void omap_serial_fill_features_erratas(struct uart_8250_port *up, u32 mvr, scheme; u16 revision, major, minor; - mvr = uart_read(up, UART_OMAP_MVER); + mvr = uart_read(priv, UART_OMAP_MVER); /* Check revision register scheme */ scheme = mvr >> OMAP_UART_MVR_SCHEME_SHIFT; @@ -1394,7 +1401,7 @@ static int omap8250_probe(struct platform_device *pdev) UPF_HARD_FLOW; up.port.private_data = priv; - up.port.regshift = 2; + up.port.regshift = OMAP_UART_REGSHIFT; up.port.fifosize = 64; up.tx_loadsz = 64; up.capabilities = UART_CAP_FIFO; @@ -1457,6 +1464,8 @@ static int omap8250_probe(struct platform_device *pdev) DEFAULT_CLK_SPEED); } + priv->membase = membase; + priv->line = -ENODEV; priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; priv->calc_latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; cpu_latency_qos_add_request(&priv->pm_qos_request, priv->latency); @@ -1464,6 +1473,8 @@ static int omap8250_probe(struct platform_device *pdev) spin_lock_init(&priv->rx_dma_lock); + platform_set_drvdata(pdev, priv); + device_init_wakeup(&pdev->dev, true); pm_runtime_enable(&pdev->dev); pm_runtime_use_autosuspend(&pdev->dev); @@ -1525,7 +1536,6 @@ static int omap8250_probe(struct platform_device *pdev) goto err; } priv->line = ret; - platform_set_drvdata(pdev, priv); pm_runtime_mark_last_busy(&pdev->dev); pm_runtime_put_autosuspend(&pdev->dev); return 0; @@ -1547,11 +1557,12 @@ static int omap8250_remove(struct platform_device *pdev) if (err) return err; + serial8250_unregister_port(priv->line); + priv->line = -ENODEV; pm_runtime_dont_use_autosuspend(&pdev->dev); pm_runtime_put_sync(&pdev->dev); flush_work(&priv->qos_work); pm_runtime_disable(&pdev->dev); - serial8250_unregister_port(priv->line); cpu_latency_qos_remove_request(&priv->pm_qos_request); device_init_wakeup(&pdev->dev, false); return 0; @@ -1627,7 +1638,6 @@ static int omap8250_lost_context(struct uart_8250_port *up) static int omap8250_soft_reset(struct device *dev) { struct omap8250_priv *priv = dev_get_drvdata(dev); - struct uart_8250_port *up = serial8250_get_port(priv->line); int timeout = 100; int sysc; int syss; @@ -1641,20 +1651,20 @@ static int omap8250_soft_reset(struct device *dev) * needing omap8250_soft_reset() quirk. Do it in two writes as * recommended in the comment for omap8250_update_scr(). */ - serial_out(up, UART_OMAP_SCR, OMAP_UART_SCR_DMAMODE_1); - serial_out(up, UART_OMAP_SCR, + uart_write(priv, UART_OMAP_SCR, OMAP_UART_SCR_DMAMODE_1); + uart_write(priv, UART_OMAP_SCR, OMAP_UART_SCR_DMAMODE_1 | OMAP_UART_SCR_DMAMODE_CTL); - sysc = serial_in(up, UART_OMAP_SYSC); + sysc = uart_read(priv, UART_OMAP_SYSC); /* softreset the UART */ sysc |= OMAP_UART_SYSC_SOFTRESET; - serial_out(up, UART_OMAP_SYSC, sysc); + uart_write(priv, UART_OMAP_SYSC, sysc); /* By experiments, 1us enough for reset complete on AM335x */ do { udelay(1); - syss = serial_in(up, UART_OMAP_SYSS); + syss = uart_read(priv, UART_OMAP_SYSS); } while (--timeout && !(syss & OMAP_UART_SYSS_RESETDONE)); if (!timeout) { @@ -1668,13 +1678,10 @@ static int omap8250_soft_reset(struct device *dev) static int omap8250_runtime_suspend(struct device *dev) { struct omap8250_priv *priv = dev_get_drvdata(dev); - struct uart_8250_port *up; + struct uart_8250_port *up = NULL; - /* In case runtime-pm tries this before we are setup */ - if (!priv) - return 0; - - up = serial8250_get_port(priv->line); + if (priv->line >= 0) + up = serial8250_get_port(priv->line); /* * When using 'no_console_suspend', the console UART must not be * suspended. Since driver suspend is managed by runtime suspend, @@ -1682,7 +1689,7 @@ static int omap8250_runtime_suspend(struct device *dev) * active during suspend. */ if (priv->is_suspending && !console_suspend_enabled) { - if (uart_console(&up->port)) + if (up && uart_console(&up->port)) return -EBUSY; } @@ -1693,13 +1700,15 @@ static int omap8250_runtime_suspend(struct device *dev) if (ret) return ret; - /* Restore to UART mode after reset (for wakeup) */ - omap8250_update_mdr1(up, priv); - /* Restore wakeup enable register */ - serial_out(up, UART_OMAP_WER, priv->wer); + if (up) { + /* Restore to UART mode after reset (for wakeup) */ + omap8250_update_mdr1(up, priv); + /* Restore wakeup enable register */ + serial_out(up, UART_OMAP_WER, priv->wer); + } } - if (up->dma && up->dma->rxchan) + if (up && up->dma && up->dma->rxchan) omap_8250_rx_dma_flush(up); priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; @@ -1711,18 +1720,15 @@ static int omap8250_runtime_suspend(struct device *dev) static int omap8250_runtime_resume(struct device *dev) { struct omap8250_priv *priv = dev_get_drvdata(dev); - struct uart_8250_port *up; + struct uart_8250_port *up = NULL; - /* In case runtime-pm tries this before we are setup */ - if (!priv) - return 0; + if (priv->line >= 0) + up = serial8250_get_port(priv->line); - up = serial8250_get_port(priv->line); - - if (omap8250_lost_context(up)) + if (up && omap8250_lost_context(up)) omap8250_restore_regs(up); - if (up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2)) + if (up && up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2)) omap_8250_rx_dma(up); priv->latency = priv->calc_latency; From patchwork Mon May 8 08:20:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 91027 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2000721vqo; Mon, 8 May 2023 01:41:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5TeGxf6qWvRLY4XSSZdfMBtOhnqjMGQmZoq9R0chd835wRnuSfpSOlZwNXExF5lzOXqMvQ X-Received: by 2002:a17:902:654a:b0:1a9:37f4:6345 with SMTP id d10-20020a170902654a00b001a937f46345mr8267271pln.12.1683535300347; Mon, 08 May 2023 01:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683535300; cv=none; d=google.com; s=arc-20160816; b=IMRHeVPsszZMLBqH604QnSqzC5SokKB2tIK8NCyNJDVfawBPDrGhWSKZ+ZNPHA1TMs WnEccBNWMtwlOqmlcIFL3MBwGrsiQF1okcOCXroL2YMCS/+aHHBHTPie2d7qhAzw8tkw 3OJ0EmFdqaVimEt47+GFTy9PA24sgami6wd3lwM+xsc0tptMlUZQwVzYx/WUwPWyPSb7 c4B4qMGWJn13i9kKeBKMoCS+QsZgno/W1DvF/waHhbwIJguVpJx1xXELXUOsm8GgbW/w tGaAID4fta4Zeft/3pbYhTqReWjqU8hjgdCGZj45PQ6yXxq54OpJ8rkhuHb20yNiQmJN 8EMA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=B4+aNI0SCkXZcK6Id3izAzVpgvcl3s/FEZagJxjkNX8=; b=lOo3WlZIh1ZMIbKcFDhd/lMwIc18pwld7PRKWv6JgEQaC5rcI43jncGexsES5d4W2r XDNt2f2ceSwIlN+htjNqI2ZT8OZYlxZzM7lak+e7pr9Yiyxi1TsyUZVeUhxidkUSnz4J NXB5W1Ynea5MGA/5Pu9DpwAexLzzh9zuaQ6uHvHx6rM3nmOwFWY/Ai3SCKBhfD7dn6Lz ZwKRwdHiv3dY7uw2EX5WND6NpdRZ6Xvb62GsgFtcHZnySJl4q7l79FceFE7GfWHGH09n yeAoub8eIYcU2Uw9aAQQtY5H2opQ6Ry2n6GAzPVO3eGkYIK7hgGsrxq0sK3u5SqoomSJ ARbA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gp13-20020a17090adf0d00b0024ff1023d7esi9920967pjb.12.2023.05.08.01.41.27; Mon, 08 May 2023 01:41:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233459AbjEHIUy (ORCPT + 99 others); Mon, 8 May 2023 04:20:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233658AbjEHIUn (ORCPT ); Mon, 8 May 2023 04:20:43 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 49C0E1E98E; Mon, 8 May 2023 01:20:41 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 198178111; Mon, 8 May 2023 08:20:38 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-omap@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] serial: 8250: omap: Fix life cycle issues for interrupt handlers Date: Mon, 8 May 2023 11:20:13 +0300 Message-Id: <20230508082014.23083-4-tony@atomide.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230508082014.23083-1-tony@atomide.com> References: <20230508082014.23083-1-tony@atomide.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765314711323157343?= X-GMAIL-MSGID: =?utf-8?q?1765314711323157343?= We have the struct uart_8250_port instance recycled on device rebind while the struct omap8250_priv instance is not. For the console uart, __tty_hangup() does not call tty->ops->hangup() as cons_filp stays open, and uart shutdown won't get called. This means we have a stale priv->wakeirq handler around after unbind, and port->irq is not freed on unbind. There's no need to claim the interrupts on startup. We can fix this and simplify the driver a bit by claiming the interrupts in probe, and clearing them on remove. For the device interrupt, we can use devm_request_irq(). To do this, we change omap8250_irq() to use struct omap8250_priv data directly so we don't have to wait for the assigned port from serial8250_register_8250_port(). We must also drop IRQF_SHARED to set IRQ_NOAUTOEN to avoid spurious interrupts until the port has been registered. There's no need for IRQF_SHARED for 8250_omap, the serial port interrupt lines are dedicated lines. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_omap.c | 33 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -623,9 +623,9 @@ static int omap_8250_dma_handle_irq(struct uart_port *port); static irqreturn_t omap8250_irq(int irq, void *dev_id) { - struct uart_port *port = dev_id; - struct omap8250_priv *priv = port->private_data; - struct uart_8250_port *up = up_to_u8250p(port); + struct omap8250_priv *priv = dev_id; + struct uart_8250_port *up = serial8250_get_port(priv->line); + struct uart_port *port = &up->port; unsigned int iir, lsr; int ret; @@ -709,11 +709,6 @@ static int omap_8250_startup(struct uart_port *port) } } - ret = request_irq(port->irq, omap8250_irq, IRQF_SHARED, - dev_name(port->dev), port); - if (ret < 0) - goto err; - up->ier = UART_IER_RLSI | UART_IER_RDI; serial_out(up, UART_IER, up->ier); @@ -730,14 +725,11 @@ static int omap_8250_startup(struct uart_port *port) if (up->dma && !(priv->habit & UART_HAS_EFR2)) up->dma->rx_dma(up); + enable_irq(up->port.irq); + pm_runtime_mark_last_busy(port->dev); pm_runtime_put_autosuspend(port->dev); return 0; -err: - pm_runtime_mark_last_busy(port->dev); - pm_runtime_put_autosuspend(port->dev); - dev_pm_clear_wake_irq(port->dev); - return ret; } static void omap_8250_shutdown(struct uart_port *port) @@ -757,6 +749,8 @@ static void omap_8250_shutdown(struct uart_port *port) up->ier = 0; serial_out(up, UART_IER, 0); + disable_irq_nosync(up->port.irq); + dev_pm_clear_wake_irq(port->dev); if (up->dma) serial8250_release_dma(up); @@ -770,8 +764,6 @@ static void omap_8250_shutdown(struct uart_port *port) pm_runtime_mark_last_busy(port->dev); pm_runtime_put_autosuspend(port->dev); - free_irq(port->irq, port); - dev_pm_clear_wake_irq(port->dev); } static void omap_8250_throttle(struct uart_port *port) @@ -1451,8 +1443,6 @@ static int omap8250_probe(struct platform_device *pdev) &up.overrun_backoff_time_ms) != 0) up.overrun_backoff_time_ms = 0; - priv->wakeirq = irq_of_parse_and_map(np, 1); - pdata = of_device_get_match_data(&pdev->dev); if (pdata) priv->habit |= pdata->habit; @@ -1530,6 +1520,15 @@ static int omap8250_probe(struct platform_device *pdev) } } #endif + + irq_set_status_flags(irq, IRQ_NOAUTOEN); + ret = devm_request_irq(&pdev->dev, irq, omap8250_irq, 0, + dev_name(&pdev->dev), priv); + if (ret < 0) + return ret; + + priv->wakeirq = irq_of_parse_and_map(np, 1); + ret = serial8250_register_8250_port(&up); if (ret < 0) { dev_err(&pdev->dev, "unable to register 8250 port\n"); From patchwork Mon May 8 08:20:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 91023 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1995371vqo; Mon, 8 May 2023 01:29:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4swQXtoi3jxmyujWUa0MUwVdrWKpUVMw4mMy2TW8DYFB4G9GPux05GPiyxCuj0tS87P6DE X-Received: by 2002:a17:902:ce81:b0:1a6:e564:6046 with SMTP id f1-20020a170902ce8100b001a6e5646046mr13029662plg.46.1683534542756; Mon, 08 May 2023 01:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683534542; cv=none; d=google.com; s=arc-20160816; b=n0RTxqZL2aQfWr08vgzNARXiLNKoKTIu8SC812EMvw0wBSyEqUciaKg8ziFshzEIST XW0KC5raUoOKLIOzTmx9L0GBuJRAEheQN3fCvRZFFF03W0MQdZz9bR1cJO4XjybcHpUl gyI2yY/2YWTl+90KD6VAz+gfrP6uibnPLYIfumgjiLs3RBGuEJPbXGA34PkyPj0tDTfn jEWcZ+Eb5AQCzSyYVWGCjO1J1e0xL0Nf4t4qSUmpqfFbecuY8KnmN8yz8XDklMfvY0nw BIU7dmK4omkjxELWHvHg/Y0WgcMSYPgWar0f0lTrxVGSgWBgF+DjiHyrkcylk4QGTL5y +l9Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bWZQWJVzcDspdMLGZvVDG7s32MtAO4hCII5PjBmOu8o=; b=RPvodbz/4w62EvASgNoj2aFzkJVH6hJVGu8DW9eEngsQseAggeh4fK3oNLZyMb9whm DSJ1Mc8aY0vdgd9Zt2wVyB/eX0ryCRcGcqd3hgDAnPoeyisiOH0/g9jGKtff8eReEh38 4fAxYKxos38PVjE9BnPPkMdlKVcP5/UFa9sAVDmfRcNaKx707LYYj82XAWnKt9FA9Gpw Hd89+DXnZzHlq6BY1ePw6jSOKRvGJtenqAIrwyZ8AtSeQ+siGF76Dt+in+rr77rYyGUf vNMix6nrL1/CVvpzKSpj/t8q5CRX3kTCcz6RU8DXIdKmigsEcJAffB6v59LxG3y9n+pO LDVA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a170903244900b001aafda896b3si8170181pls.626.2023.05.08.01.28.49; Mon, 08 May 2023 01:29:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233487AbjEHIVI (ORCPT + 99 others); Mon, 8 May 2023 04:21:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233655AbjEHIUz (ORCPT ); Mon, 8 May 2023 04:20:55 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB4401F4BF; Mon, 8 May 2023 01:20:46 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 675FD8111; Mon, 8 May 2023 08:20:44 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-omap@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] serial: 8250: omap: Shut down on remove for console uart Date: Mon, 8 May 2023 11:20:14 +0300 Message-Id: <20230508082014.23083-5-tony@atomide.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230508082014.23083-1-tony@atomide.com> References: <20230508082014.23083-1-tony@atomide.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765313916592590346?= X-GMAIL-MSGID: =?utf-8?q?1765313916592590346?= When unbinding the console uart, we want to power down the uart hardware on remove. For the console uart, the normal shutdown path will never get called as the cons_filp stays open. Let's rearrange the dma related functions a bit so we can call driver shutdown also on console uart rebind. Currently we set up->dma on probe, but that causes issues calling omap_8250_shutdown() on remove. The dma startup will not get called on the next rebind as we still have up->dma set from probe. Note that serial8250_release_dma() already checks for dma so we can remove the check for it in 8205_omap driver. With these changes we also avoid hogging dma virtual channels for the unused uarts that may be limited on some devices. Signed-off-by: Tony Lindgren --- drivers/tty/serial/8250/8250_omap.c | 36 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -679,6 +679,7 @@ static int omap_8250_startup(struct uart_port *port) { struct uart_8250_port *up = up_to_u8250p(port); struct omap8250_priv *priv = port->private_data; + struct uart_8250_dma *dma = &priv->omap8250_dma; int ret; if (priv->wakeirq) { @@ -697,16 +698,16 @@ static int omap_8250_startup(struct uart_port *port) up->msr_saved_flags = 0; /* Disable DMA for console UART */ - if (uart_console(port)) - up->dma = NULL; - - if (up->dma) { + if (dma->fn && !uart_console(port)) { + up->dma = &priv->omap8250_dma; ret = serial8250_request_dma(up); if (ret) { dev_warn_ratelimited(port->dev, "failed to request DMA\n"); up->dma = NULL; } + } else { + up->dma = NULL; } up->ier = UART_IER_RLSI | UART_IER_RDI; @@ -752,8 +753,8 @@ static void omap_8250_shutdown(struct uart_port *port) disable_irq_nosync(up->port.irq); dev_pm_clear_wake_irq(port->dev); - if (up->dma) - serial8250_release_dma(up); + serial8250_release_dma(up); + up->dma = NULL; /* * Disable break condition and FIFOs @@ -1499,24 +1500,24 @@ static int omap8250_probe(struct platform_device *pdev) ret = of_property_count_strings(np, "dma-names"); if (ret == 2) { struct omap8250_dma_params *dma_params = NULL; + struct uart_8250_dma *dma = &priv->omap8250_dma; - up.dma = &priv->omap8250_dma; - up.dma->fn = the_no_dma_filter_fn; - up.dma->tx_dma = omap_8250_tx_dma; - up.dma->rx_dma = omap_8250_rx_dma; + dma->fn = the_no_dma_filter_fn; + dma->tx_dma = omap_8250_tx_dma; + dma->rx_dma = omap_8250_rx_dma; if (pdata) dma_params = pdata->dma_params; if (dma_params) { - up.dma->rx_size = dma_params->rx_size; - up.dma->rxconf.src_maxburst = dma_params->rx_trigger; - up.dma->txconf.dst_maxburst = dma_params->tx_trigger; + dma->rx_size = dma_params->rx_size; + dma->rxconf.src_maxburst = dma_params->rx_trigger; + dma->txconf.dst_maxburst = dma_params->tx_trigger; priv->rx_trigger = dma_params->rx_trigger; priv->tx_trigger = dma_params->tx_trigger; } else { - up.dma->rx_size = RX_TRIGGER; - up.dma->rxconf.src_maxburst = RX_TRIGGER; - up.dma->txconf.dst_maxburst = TX_TRIGGER; + dma->rx_size = RX_TRIGGER; + dma->rxconf.src_maxburst = RX_TRIGGER; + dma->txconf.dst_maxburst = TX_TRIGGER; } } #endif @@ -1550,12 +1551,15 @@ static int omap8250_probe(struct platform_device *pdev) static int omap8250_remove(struct platform_device *pdev) { struct omap8250_priv *priv = platform_get_drvdata(pdev); + struct uart_8250_port *up; int err; err = pm_runtime_resume_and_get(&pdev->dev); if (err) return err; + up = serial8250_get_port(priv->line); + omap_8250_shutdown(&up->port); serial8250_unregister_port(priv->line); priv->line = -ENODEV; pm_runtime_dont_use_autosuspend(&pdev->dev);