Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2496471rdh; Sun, 26 Nov 2023 08:17:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJ1gTaK/QX+k5xYinIGHb/II3ToFmBws2qWK9Z9qyjfeOlIgtd9jM7LR87KD9yDklkUdvo X-Received: by 2002:a17:90b:4c50:b0:285:8407:6152 with SMTP id np16-20020a17090b4c5000b0028584076152mr9818252pjb.8.1701015468964; Sun, 26 Nov 2023 08:17:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701015468; cv=none; d=google.com; s=arc-20160816; b=REwIw+YlSQ9QTH3FCNk2xbOkMFaluUkNDl+YJ+n4J2l9ZpJDj16YITZ5dfMHa4PMvn HkiDKsqXqBSoDi2go3655eYSY33xyq01cfR+R7ACOkk4r/RG4YfK4BTeUVXSb7lRqovA R1l3HdGHYn4OTQdL+XplPjchq6W4I/m4P5LC1VqdjPiUWmVld2R9EUZpPPth8p5ZhHxS 8FLvk14GNKkzf5iLHdljHd4U+yu/IeaIi3ZRt+56l2gVgwvO02/6NohCJa+/ykfhX7qJ efstxWm7birRWe8Ev10hugakbw0+EqjTbOiOVxtDyx8MWEminZQ7jmI5Qrr9aVnbrnbG //dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=KA0lDoV5G5Peuw5aoWsAKffieXWD7sSMsne9MKzdxaY=; fh=oqrotdXGKSxIyXJ5Me7XDE1sxjZE9QqY7t8eSpycfBg=; b=uPlgBMajgziGnOLb7COlGab3E62t26o0U4LN7nnhgz8cWNDL979ScBCPg6aapOLQ/Q KdRjQ4ODpP87kdbDdf3+Vzo6di3wsBcO7/sDeIjtfyp+sa6HaZ8QBuRJGpucEA79jlMi yAK0NeLgvhMN5hcVdF+I80meG4vkR9zSnRot/aev1aG/yasXxFaG8jQ+Aq8gBbJJmLAM 4kTKd2pxCrFRkeH6mK8djCON37z69IAGyLDq1NxMvReVaD+IPazak9jWUdHeGB3GoxGJ 0/qIhDeKG/DI9xB0rnoC0MrD0/W1zBOzfuGe9eOIaCdu2i2P9p/ZgduDygfy1zVhCuB1 aHKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="zqKWyY/n"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=BwrXFy+s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id u18-20020a17090a891200b002850eff7dd6si7818595pjn.173.2023.11.26.08.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 08:17:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="zqKWyY/n"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=BwrXFy+s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 22B6180AC456; Sun, 26 Nov 2023 08:17:46 -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 S230091AbjKZQR1 (ORCPT + 99 others); Sun, 26 Nov 2023 11:17:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjKZQRZ (ORCPT ); Sun, 26 Nov 2023 11:17:25 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 244A9D3; Sun, 26 Nov 2023 08:17:32 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701015450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KA0lDoV5G5Peuw5aoWsAKffieXWD7sSMsne9MKzdxaY=; b=zqKWyY/nAZnzrOIpYqQo3Mwy8WSs9c7+XOPgm2+o1WwBNEC67xa83d4yMbyVK6czzKZPQ2 Skaao1godL5ZD2rPS+mt8k+vEPW0BnSYU8btf+x8lEA1gX4DakjWm21JUHI15v0IZdAiTS zXMSBZKB15Fz06rwapGAutBGxIpiu5Keu6kdOBDP5jxILlStTTUk/wmy9EepSyGzpfjgnF SRIjUuWekFbmHiKMEzkTQpM07geuA+Wr29seaX4HkMRfKiwUPlQc61whaUdRobZifFW/Tc 1ef7o1Uvj46KeWbgVOJ9uWh+zGSL3fQoJ2HlYJB0mKryTdyyzP+ujlgH1vutpw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701015450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KA0lDoV5G5Peuw5aoWsAKffieXWD7sSMsne9MKzdxaY=; b=BwrXFy+skkl94ocXW+NpEpjC6YMKz11ciAZNDycQ9gm9LG7BWdgEs+Jsa0S/DJdy9favH/ BGxy2msUs7eRYeAg== To: Xuewen Yan , gregkh@linuxfoundation.org, jirislaby@kernel.org, ilpo.jarvinen@linux.intel.com, tony@atomide.com Cc: 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, Petr Mladek , Sergey Senozhatsky , Steven Rostedt Subject: Re: [RFC PATCH] serial: core: Use pm_runtime_get_sync() in uart_start() In-Reply-To: <20231124122258.1050-1-xuewen.yan@unisoc.com> References: <20231124122258.1050-1-xuewen.yan@unisoc.com> Date: Sun, 26 Nov 2023 17:23:26 +0106 Message-ID: <87il5o32w9.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, 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]); Sun, 26 Nov 2023 08:17:46 -0800 (PST) [Added printk maintainers CC.] On 2023-11-24, Xuewen Yan wrote: > 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 I suppose you got this because of the lockdep message generated by #2. It probably would make sense to call __printk_safe_enter() inside uart_port_lock(). This would allow printk() to automatically defer the printing for that CPU until the port lock is released. > (2) scheduling while atomic: > uart_write() > uart_port_lock() <<< get lock > __uart_start > __pm_runtime_resume > rpm_resume > schedule() << sleep rpm_resume() is a fascinating function. It requires the caller to hold a spin_lock (dev->power.lock) with interrupts disabled. But it seems to believe that this is the *only* spin_lock held so that it can temporarily spin_unlock and call might_sleep() functions. In the case of uart_write(), it certainly is not the only spin_lock held. I do not know enough about the internals of RPM to suggest a proper solution. But it looks like rpm_resume() cannot assume dev->power.lock is the only spin_lock held by the caller. John Ogness