Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1712827rdh; Fri, 24 Nov 2023 23:48:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFujV1OhLxThUgl0R0kkZ3zSFaWPzHpYaiFz5OCGdaum/P+q/a+a2OKQ+zXXbqKHy8XJXUj X-Received: by 2002:a05:6830:1bd6:b0:6d6:4c92:1ad with SMTP id v22-20020a0568301bd600b006d64c9201admr6025601ota.32.1700898498251; Fri, 24 Nov 2023 23:48:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700898498; cv=none; d=google.com; s=arc-20160816; b=0QNTX1cO4RbCnASr+6zKczcX1SBrtK6V3JRoIWhVzgCZtnW38+VrSnv4FqzKH5cUBd Oyxjgv80KLqyELEl3aqeG6zEFpmyAo/h2uMZ54+M8BUqLSU4W38YpKsZTLY/RcEfD06T 2CjfHAFj+5Z/MCCUGnQGoN6CR9c70gvYKZza7FMXZNHRJ+RjhcUE5Qt55F2WTM794O5L 6ZgTl0uVTMWMwo4qP33kHujc0zNnsn8b9YbEmWEDQjj0V5ICep3G8VDX/2+hIUXXvTCw voBWv4gctyPI5WHxZf3bxiJZH03XdDdQnEhUAhOZ4k4EH6w4LEQ1HmPja4GuXWXxTz12 0dcw== 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=WiZfk6IDliCXgEuES9OWAPwK9O9f1Zp6C9UWy0x6BdA=; fh=4eP8kgwjQgZELYhlYBiRlPDZfidV+SLRLr1T1jdERRk=; b=EaJQDj9KCyPh6gAB2cQGU0gRmgyHkoBi5LLmxuwhBvSV+Llv7WJsvEkTCLqIDtzP02 5nqrWK/ARhbT9Fynm6ZyLDylvpBkeT6N24nh2U9WhOuwoWaYWdowSHU3WB4JR093Zmno 20rAWliZ97QVFtRTNDygihCSl5SFtqW25pbOh8pggIxy6lNHhlQtSocOgV1BLDscQ/XY 0wM6/AorCrVONlK2mLJQHK/WLDCKEVrtXiSHLkB0DV7XCm3FwauRyeDyZQYP7OrjSK6i 3W5SH3vPvKhPeCNBk4M4txMA0lWUSpcRvumh58PkmyFAIT4PzTyUCYg2CNdKLyUrVzfM ByRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=UMngcpQf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id c3-20020a630d03000000b005aaf19c3981si5427706pgl.329.2023.11.24.23.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 23:48:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=fail header.i=@atomide.com header.s=25mailst header.b=UMngcpQf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 9188C8025C8A; Fri, 24 Nov 2023 23:48:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229550AbjKYHr7 (ORCPT + 99 others); Sat, 25 Nov 2023 02:47:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjKYHr5 (ORCPT ); Sat, 25 Nov 2023 02:47:57 -0500 Received: from mail5.25mail.st (mail5.25mail.st [74.50.62.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1DA103; Fri, 24 Nov 2023 23:48:04 -0800 (PST) Received: from localhost (91-158-86-216.elisa-laajakaista.fi [91.158.86.216]) by mail5.25mail.st (Postfix) with ESMTPSA id 6670A60BB6; Sat, 25 Nov 2023 07:47:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=atomide.com; s=25mailst; t=1700898483; bh=o4lIe4eNp1y/0VGduOx/UtfXBQ2vvGebZj9NwAsAxgM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UMngcpQfkXdPLMnolftdZDmK9QthJ3GsNPQp4WLBnjgFsSBpvt7MQq/FIF+vDLhsT 2jCdrNjsf75rJvGELZpKCHXKA+t09W8rAiImry0jS5q2UYT/N64m1gagimsQ8oQvMV SYnIaS7UKmzTvVWgWNEnGHceu3qBYY+1WhLglg5axpAiBIXVFZm+ask+7AD3TqUopy lL/wI+riqnRVTqpwfb9i4TcfA7iS4Et1o18xjRVmovO+YfkppVRTyHmcenGyV0FGf9 e6uk30VwrOs45UiLfCO6Lq0cNLQWIudBRWHbcN/JsXStBkRCKkjsWECPPeE6dzrsfU coAwMwlPXDyHA== Date: Sat, 25 Nov 2023 09:47:38 +0200 From: Tony Lindgren To: Xuewen Yan Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, john.ogness@linutronix.de, tglx@linutronix.de, andriy.shevchenko@linux.intel.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, ke.wang@unisoc.com, xuewen.yan94@gmail.com Subject: Re: [RFC PATCH] serial: core: Use pm_runtime_get_sync() in uart_start() Message-ID: <20231125074738.GJ5169@atomide.com> References: <20231124122258.1050-1-xuewen.yan@unisoc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231124122258.1050-1-xuewen.yan@unisoc.com> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, 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 pete.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 (pete.vger.email [0.0.0.0]); Fri, 24 Nov 2023 23:48:15 -0800 (PST) * Xuewen Yan [231124 12:25]: > 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 Are these spinlock vs raw spinlock nesting warnings from lockdep? If so can you please post the full warnings somewhere? Or if some extra steps are needed to reproduce please describe that too. Chances are very high that your serial port is already runtime active at this point unless you manually idle it so that's why I'm wondering as all that likely is happening here is a check on the runtime PM usage count. > So let us use pm_runtime_get_sync() to prevent these. We need to fix this some other way as we can't use pm_runtime_get_sync() here. The sync call variants require setting pm_runtime_irq_safe() for the device. And this is what we really want to avoid as it takes a permanent usage count on the parent device. What we want to do here is to get runtime PM to wake-up the device if idle and try tx again after runtime PM resume as needed. Just guessing at this point.. To me it sounds like the fix might be to use a raw spinlock for uart_port_lock() and uart_port_unlock()? Regards, Tony > 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) > -- > 2.25.1 >