From patchwork Fri Nov 24 12:22:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuewen Yan X-Patchwork-Id: 169401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp1139895vqx; Fri, 24 Nov 2023 04:23:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4lg+pUTdqduIlAYHWzoX62TxYjIFYrdhrA22G7HrnorOuU8cq8jzK5sQSdFANu7UrUuIU X-Received: by 2002:a17:902:76cc:b0:1cc:bf6b:f3b1 with SMTP id j12-20020a17090276cc00b001ccbf6bf3b1mr2342292plt.37.1700828609089; Fri, 24 Nov 2023 04:23:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700828609; cv=none; d=google.com; s=arc-20160816; b=qYCwHWTubtofoJjLw05DW/dHsbsDJXIIO3mRTnP+leEQH3pJ9JcTBKFxC0CzpvCG/F wlQQ93nzuUzIQf+vrX/nygG/B3x9cNVzgTQqyf3Gf3TIfiUBrtlsQxGldAkGkmH4z7bU l+rHVQmdQpuHDoDk6ZmN8nEnQI4iJhj6JrdMagbqW+1N4nN1olgYMDaHjk1rtdk4cEcB 15wOms2gsUEIA7SbGOSd2KzT4Q5EsJc69ebVE+Lxeb9FlTaboEVwjZB4kevxiSHfevjR aVO4S9G29bSI4Fth7NuZhk1057XaKHqfIb7IAK391IfTzinHSC94I50WcVlJERVbjW92 t/qw== 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 :message-id:date:subject:cc:to:from; bh=bv/WX530uY0qa/VgTWGCgOQ+Hvcfd6knLUn7MByixo4=; fh=MeRHEwlAxpS0NyeN4+QA1Nknoloy36VfytkNHCRBBgQ=; b=OttGsH+wBCR1okq5HQfpYSrT5Hcu7LiHsKU60oIB9rb/SfDCb1upr0KDXXLcg501uV kDQI+fww3sV6/npI8+Cjo9sDmFZmaijCv3wWBbWVPcF0Jg8eXkE9XaMdKDSZjxjeBu3h niiUHoILZssE+6cr4LmlU3/fe4w4cMMzZGhLojlozEX3nyQYsadniHFN1ZCYOcEGQTZL vOeBtl3SnRtgC41Bul06JJBup2c/5cbPo7Vx5Zkq3YSHBGt4W/cByMVpbJG6ikFpghiP uiKc7RNct4/FFGmtwTuihN0rbQ/XoFvpDE40mkiNZfBTH2AexCXluHghc+GxTiQXoGl8 VNSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id l1-20020a170903244100b001b9c3498526si3382554pls.433.2023.11.24.04.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 04:23:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 7806583CE950; Fri, 24 Nov 2023 04:23:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230418AbjKXMXM (ORCPT + 99 others); Fri, 24 Nov 2023 07:23:12 -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 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 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 24 Nov 2023 04:23:22 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783448059811946291 X-GMAIL-MSGID: 1783448059811946291 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 and 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 enable 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_core.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 = port->port_dev; /* Increment the runtime PM usage count for the active check below */ - err = pm_runtime_get(&port_dev->dev); + err = pm_runtime_get_sync(&port_dev->dev); if (err < 0 && err != -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); } static void uart_start(struct tty_struct *tty)