From nobody Wed Dec 17 15:38:28 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 462DDC61DF7 for ; Fri, 24 Nov 2023 12:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230405AbjKXMXN (ORCPT ); Fri, 24 Nov 2023 07:23:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbjKXMXK (ORCPT ); Fri, 24 Nov 2023 07:23:10 -0500 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA04D71 for ; Fri, 24 Nov 2023 04:23:15 -0800 (PST) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 3AOCN5bb035990; Fri, 24 Nov 2023 20:23:05 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4ScDWm2myJz2K25CP; Fri, 24 Nov 2023 20:17:40 +0800 (CST) Received: from BJ10918NBW01.spreadtrum.com (10.0.73.73) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 24 Nov 2023 20:23:03 +0800 From: Xuewen Yan To: , , , , CC: , , , , , Subject: [RFC PATCH] serial: core: Use pm_runtime_get_sync() in uart_start() Date: Fri, 24 Nov 2023 20:22:58 +0800 Message-ID: <20231124122258.1050-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.0.73.73] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 3AOCN5bb035990 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The commit 84a9582fd203("serial: core: Start managing serial controllers to= enable runtime PM") use the pm_runtime_get() after uart_port_lock() which would close the irq a= nd disable preement. At this time, pm_runtime_get may cause the following two problems: (1) deadlock in try_to_wake_up: uart_write() uart_port_lock() <<< get lock __uart_start __pm_runtime_resume rpm_resume queue_work_on try_to_wake_up _printk uart_console_write ... uart_port_lock() <<< wait forever (2) scheduling while atomic: uart_write() uart_port_lock() <<< get lock __uart_start __pm_runtime_resume rpm_resume chedule() << sleep So let us use pm_runtime_get_sync() to prevent these. Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to en= able runtime PM") Signed-off-by: Xuewen Yan --- drivers/tty/serial/serial_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index f1348a509552..902f7ed35f4d 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -145,7 +145,7 @@ static void __uart_start(struct uart_state *state) port_dev =3D port->port_dev; =20 /* Increment the runtime PM usage count for the active check below */ - err =3D pm_runtime_get(&port_dev->dev); + err =3D pm_runtime_get_sync(&port_dev->dev); if (err < 0 && err !=3D -EINPROGRESS) { pm_runtime_put_noidle(&port_dev->dev); return; @@ -159,7 +159,7 @@ static void __uart_start(struct uart_state *state) if (!pm_runtime_enabled(port->dev) || pm_runtime_active(port->dev)) port->ops->start_tx(port); pm_runtime_mark_last_busy(&port_dev->dev); - pm_runtime_put_autosuspend(&port_dev->dev); + pm_runtime_put_sync_autosuspend(&port_dev->dev); } =20 static void uart_start(struct tty_struct *tty) --=20 2.25.1