From patchwork Tue Feb 11 21:02:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 864301 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9CD72627EF; Tue, 11 Feb 2025 21:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739309156; cv=none; b=lhvMHxMcwpFnAmFM6l0ttex/i3Q9K9p8UBeAIBduQ/xnuwINskR+9fiEcUavDtuB3provfO8mz3tVGsbrK2W69ZNxGOC+SoraIE1oM9CXFTmol/cHwkiBj/P9lN4ubkmN4fkccSnNZUzX5TmnBAuGd8ctxQpPVuGurR+vOSfQsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739309156; c=relaxed/simple; bh=31LpJUNvPXRT8Z6CSlJtIwY15E5H7sluasiMFMoNjTc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PvXRYzk4KZLXixzCzYH1y2xDtKF370bSmAMTIKs9IZaPb3JYyoTyu4Hu7onBnPM5+7/OeazLnSoPlCYklAsjpp9Uf+aibw03ZEdws5Kn4wWJsfslVNnDnE0y0BhDuu2h2sLhuWXVtkeSLHIb2m7+U7DnOZiEfRrSDE3fQOokoSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=oEQueXFV; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="oEQueXFV" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id d7342e8c6b5ededa; Tue, 11 Feb 2025 22:25:52 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 13B83770175; Tue, 11 Feb 2025 22:25:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1739309152; bh=31LpJUNvPXRT8Z6CSlJtIwY15E5H7sluasiMFMoNjTc=; h=From:Subject:Date; b=oEQueXFVNKfKq2izbXI620kezw+FaF8GYJHaUOBsbUxgUi1EGf0idEguf/Obi6DYZ ynAQzD+3QcCZvKJj8o8Oe5x8owdWk/RmpJnqV9OXOal6YSUCyMZQVsf1Gb4qale7go /IYR/SOPQEu/t4J6uiXpBVzsVAdVXzmW0c8/qvu4SrcyC5w+QWHMvb6Tm8Z+KsiY96 2owWs5gpefEXn6DPNy7JKJ/0WHzTW8yBxpRpxk/tLZ3xCtCJ/Zz8tvrqMNlACPAsqF YEvbHds10FVw4sSDOyE8OSKD2Vu+Rm7F2EKzTF7g+zhCIW9on17VSnnG+ZT2a7WPTT WsXBrFzoiLV3w== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Alan Stern , Ulf Hansson , Johan Hovold , Manivannan Sadhasivam , Jon Hunter Subject: [PATCH v1 01/10] PM: runtime: Introduce pm_runtime_no_support() Date: Tue, 11 Feb 2025 22:02:52 +0100 Message-ID: <22608556.EfDdHjke4D@rjwysocki.net> In-Reply-To: <2314745.iZASKD2KPV@rjwysocki.net> References: <2314745.iZASKD2KPV@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegvddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhtvghrnhesrhhofihlrghnugdrhhgrrhhvrghrugdrvgguuhdprhgtphhtthhopehulhhfrdhhrghnshhsohhnsehlihhnrghrohdrohhrghdprhgtphhtthhopehjohhhrghnsehkvghrnhgvlhdrohhrghdprhgtphh X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 From: Rafael J. Wysocki Introduce a new helper function called pm_runtime_no_support() for checking the power.last_status value indicating whether or not runtime PM has ever been enabled for the given device. Signed-off-by: Rafael J. Wysocki --- include/linux/pm_runtime.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -182,6 +182,19 @@ } /** + * pm_runtime_no_support - Check runtime PM support. + * @dev: Target device. + * + * Return %true if runtime PM is currently disabled for @dev and its last + * runtime PM status value is %RPM_INVALID, which means that runtime PM has + * never been enabled for it, or %false otherwise. + */ +static inline bool pm_runtime_no_support(struct device *dev) +{ + return dev->power.disable_depth && dev->power.last_status == RPM_INVALID; +} + +/** * pm_runtime_enabled - Check if runtime PM is enabled. * @dev: Target device. * @@ -284,6 +297,7 @@ static inline bool pm_runtime_suspended(struct device *dev) { return false; } static inline bool pm_runtime_active(struct device *dev) { return true; } static inline bool pm_runtime_status_suspended(struct device *dev) { return false; } +static inline bool pm_runtime_no_support(struct device *dev) { return true; } static inline bool pm_runtime_enabled(struct device *dev) { return false; } static inline void pm_runtime_no_callbacks(struct device *dev) {} From patchwork Tue Feb 11 21:09:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 864299 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6EC726280D; Tue, 11 Feb 2025 21:25:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739309158; cv=none; b=Yr5XR9OM/XHQhFe8R6sLzbqQ5vmJ5Tx2mu/RqflV3R4x7fT1N8g83oW/mC3VAS7YvTl41fg+4JB1tKOvdP6vwm+iYf3YYoOIWAD7HE+ySitP4gqav+aztIv8Sy5EgvatBVksJYCnKxKJsKkL+kV7j7EKwvw3crXDSV4uyMhD5Jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739309158; c=relaxed/simple; bh=zmNhGZJdY16x0lBsxEUPSi9daEXT4yca9scHTcNRzzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=klVxPIRLK4P/POJSMgcINUJk/DRbHur+jSCXJEXaf9jpBcOnKBxlbt4WMhAAgS0sC/Htw/NJrtCkEH00tCxE3qKSWsnX1IK2X/o6k1vl0t93HsitjHEx5FI1YfwKj4bMTlRNGg/PXMOho7hX/205RHCu65BjysRu6Ke+yyRl0K4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=UdE3VJlu; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="UdE3VJlu" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id 9daabc391473d490; Tue, 11 Feb 2025 22:25:48 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 0B026770175; Tue, 11 Feb 2025 22:25:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1739309148; bh=zmNhGZJdY16x0lBsxEUPSi9daEXT4yca9scHTcNRzzU=; h=From:Subject:Date; b=UdE3VJluhfkRx/T9oWQ97SBw5OQ80FdN/4yRVlBX5ep0aPRdpHYTj55d0Wt+ye4IK 5KcRI1zAz3TCSoZznKPcyL/LgqGmOJBC0nwwtzjCsAYRYT9oMhgd6ebeL06hYOX5An k7+hXmuPoGrp72XSfqHzpMipnluGlaWRNw2w9EjIe3/C8EZSwao12JIljnFAL7cTvB uXeJUqp40lGJ2i1srQgAfQBFP8aDDemicGhLVqL4mjiorhNDgICsTKenyKwMCTcCpP wvPyt2YG+senpQEP7z4Kqx8KxKmEFPreQ5oAUCDNZkJPrzdJT0f2/oAi9Do1EwCGmt KGXHAAOp+L5tg== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Alan Stern , Ulf Hansson , Johan Hovold , Manivannan Sadhasivam , Jon Hunter Subject: [PATCH v1 05/10] PM: runtime: Do not enable wakeup IRQs during system resume Date: Tue, 11 Feb 2025 22:09:11 +0100 Message-ID: <8546164.NyiUUSuA9g@rjwysocki.net> In-Reply-To: <2314745.iZASKD2KPV@rjwysocki.net> References: <2314745.iZASKD2KPV@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegvddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhtvghrnhesrhhofihlrghnugdrhhgrrhhvrghrugdrvgguuhdprhgtphhtthhopehulhhfrdhhrghnshhsohhnsehlihhnrghrohdrohhrghdprhgtphhtthhopehjohhhrghnsehkvghrnhgvlhdrohhrghdprhgtphh X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 From: Rafael J. Wysocki Enabling system wakeup IRQs during system resume transitions is not particularly useful, even on errors, so don't do it in the pm_runtime_force_resume() error path. Fixes: c46a0d5ae4f9 ("PM: runtime: Extend support for wakeirq for force_suspend|resume") Signed-off-by: Rafael J. Wysocki --- drivers/base/power/runtime.c | 1 - 1 file changed, 1 deletion(-) --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1978,7 +1978,6 @@ ret = callback ? callback(dev) : 0; if (ret) { pm_runtime_set_suspended(dev); - dev_pm_enable_wake_irq_check(dev, false); goto out; } From patchwork Tue Feb 11 21:19:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 864302 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC7F32627EC; Tue, 11 Feb 2025 21:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739309155; cv=none; b=e00qaohZjYwzPEvtbNmdeLhtzxhLaxHaAcDYP0dnRXko+gCBJJyl2Y5JLgafgoDCm2373m48qQG7v0V9UL+TlP5XsiyK009DbJG+p+aIdVKbyagIebcHcFbp27YEi9n8zk4ZbyT4AZn7m1emkeG9wcPhY2sUzNKILl2Jo8HO95Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739309155; c=relaxed/simple; bh=OrkfWzk4rOwXdbaA05EwAtgqA26NxnytAlDoPhIdPEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lQKewzB4C7EJp0tEmLWWCVx6tV68dGKmoIdL5NkoGtfKpr1emFeU6eFGmhNclUlpHOaFs20EXEctVy+cJjlvdyt7EPsfcLw8Bv6T9PTc0zSIpMHSGtVytJzp0GCRZXTyVSRghI46hfCU7gvPbQOi2qfuFwGJf78CN9B4ZdXNCUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=FSG2BFPQ; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="FSG2BFPQ" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id 78dce38ef4c9466c; Tue, 11 Feb 2025 22:25:45 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 22772770175; Tue, 11 Feb 2025 22:25:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1739309145; bh=OrkfWzk4rOwXdbaA05EwAtgqA26NxnytAlDoPhIdPEY=; h=From:Subject:Date; b=FSG2BFPQjhriNkTqRtnzq0OrBIgfgx2ep5iuEt2gejMEWnyM3l7hdoidJh4/mVduH tHgLmva6h7hJsvRaWPH7gfLygILxQPVnhCT6e2eaoc64tgXrbCiLrowIkW13BciI6v Bpvmon0Finl0+tAos4MAjLvkoM6kbf8IA4rSYGG9qqGZDP9NM4wcrGPUtKWZ/z0bGe 1TKWnHWTtRHK92ZzPWFCmysMQTAARoTVaus92G1QrNhTwfQZrrZHkxuwAE7Jp1TYH2 KS+4vbUhUzLArViUz2yDTQadJc7maDOA0huMny1rj7rwlxvyoH9+l2sQZgXZhjA+Jl 6GtkSLiexCrlQ== From: "Rafael J. Wysocki" To: Linux PM , Ulf Hansson Cc: LKML , Alan Stern , Johan Hovold , Manivannan Sadhasivam , Jon Hunter , Tony Lindgren Subject: [PATCH v1 08/10] PM: sleep: Make pm_runtime_force_resume() look at power.set_active Date: Tue, 11 Feb 2025 22:19:13 +0100 Message-ID: <3817761.MHq7AAxBmi@rjwysocki.net> In-Reply-To: <2314745.iZASKD2KPV@rjwysocki.net> References: <2314745.iZASKD2KPV@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegvddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuhhlfhdrhhgrnhhsshhonheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhtvghrnhesrhhofihlrghnugdrhhgrrhhvrghrugdrvgguuhdprhgtphhtthhopehjohhhrghnsehkvghrnhgvlhdrohhrghdprhgtphh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 From: Rafael J. Wysocki In theory (and also in practice after a change to come), pm_runtime_force_resume() can be called on a device with power.set_active set, in which case the core has already called pm_runtime_set_active() on it, and power.needs_force_resume may be clear. This happens when the core decides to resume a device because new information on it has become available during the "noirq" phase of system-wide suspend. In order to handle that case properly, make pm_runtime_force_resume() look at power.set_active in addition to power.needs_force_resume, so it does not skip the device when the former is set. Namely, make it invoke the callback for the device then, but without disabling the wake IRQ if pm_runtime_force_resume() has not enabled it. Also clear power.set_active in pm_runtime_force_resume() to prevent it from being taken into account twice in a row. Additionally, adjust the pm_runtime_force_resume() kerneldoc comment and the code comments inside it. Moreover, remove a remark regarding DPM_FLAG_SMART_SUSPEND from the pm_runtime_force_suspend() kerneldoc comment because it is not valid any more after this change. This change is not expected to alter the behavior in the case when power.needs_force_resume is set. Signed-off-by: Rafael J. Wysocki --- Unfortunately, I have not found a way to do this without adding a new device PM flag and now there are 2 flags specifically for pm_runtime_force_suspend/resume() which is a bit sad. Questions for Ulf: (1) How is the enabling of wakeirqs handled for devices that are runtime- suspended before system suspend, so pm_runtime_force_suspend() skips them? (2) What is supposed to happen to wakeirqs during system resume after pm_runtime_force_suspend() has enabled them, but hasn't set power.needs_force_resume at the same time? --- drivers/base/power/runtime.c | 41 ++++++++++++++++++++++++++--------------- include/linux/pm.h | 1 + 2 files changed, 27 insertions(+), 15 deletions(-) --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1897,10 +1897,6 @@ * sure the device is put into low power state and it should only be used during * system-wide PM transitions to sleep states. It assumes that the analogous * pm_runtime_force_resume() will be used to resume the device. - * - * Do not use with DPM_FLAG_SMART_SUSPEND as this can lead to an inconsistent - * state where this function has called the ->runtime_suspend callback but the - * PM core marks the driver as runtime active. */ int pm_runtime_force_suspend(struct device *dev) { @@ -1923,6 +1919,7 @@ goto err; dev_pm_enable_wake_irq_complete(dev); + dev->power.wake_irq_enabled = true; /* * If the device can stay in suspend after the system-wide transition @@ -1950,31 +1947,39 @@ * pm_runtime_force_resume - Force a device into resume state if needed. * @dev: Device to resume. * - * Prior invoking this function we expect the user to have brought the device - * into low power state by a call to pm_runtime_force_suspend(). Here we reverse - * those actions and bring the device into full power, if it is expected to be - * used on system resume. In the other case, we defer the resume to be managed - * via runtime PM. + * The primary role of this function is to reverse the actions carried out by + * pm_runtime_force_suspend() for @dev, so it must always be balanced with a + * matching invocation of the latter. Accordingly, it is only valid to call + * this function during system-wide resume transitions. + * + * Typically, it is used as a system resume callback of a device driver. * - * Typically this function may be invoked from a system resume callback. + * However, if @dev had been runtime-suspended before pm_runtime_force_suspend() + * was called for it and that function did nothing, but power.set_active has + * been set for it by the core, it still needs to be resumed. That special case + * is also handled by this function. */ int pm_runtime_force_resume(struct device *dev) { int (*callback)(struct device *); int ret = 0; - if (!dev->power.needs_force_resume) + if (!dev->power.needs_force_resume && !dev->power.set_active) goto out; /* - * The value of the parent's children counter is correct already, so - * just update the status of the device. + * The parent's active children counter an the suppliers' usage counters + * are correct already, so just update the status (even though it is + * already RPM_ACTIVE if power.set_active is set). */ __update_runtime_status(dev, RPM_ACTIVE); - callback = RPM_GET_CALLBACK(dev, runtime_resume); + if (dev->power.wake_irq_enabled) { + dev_pm_disable_wake_irq_check(dev, false); + dev->power.wake_irq_enabled = false; + } - dev_pm_disable_wake_irq_check(dev, false); + callback = RPM_GET_CALLBACK(dev, runtime_resume); ret = callback ? callback(dev) : 0; if (ret) { pm_runtime_set_suspended(dev); @@ -1982,6 +1987,12 @@ } pm_runtime_mark_last_busy(dev); + /* + * Clear power.set_active in case this function runs for the same + * device again. + */ + dev->power.set_active = false; + out: dev->power.needs_force_resume = 0; pm_runtime_enable(dev); --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -698,6 +698,7 @@ bool request_pending:1; bool deferred_resume:1; bool needs_force_resume:1; + bool wake_irq_enabled:1; bool runtime_auto:1; bool ignore_children:1; bool no_callbacks:1; From patchwork Tue Feb 11 21:25:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 864303 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 590B32627E3; Tue, 11 Feb 2025 21:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739309154; cv=none; b=pw8QZobIflxXVpeznX4Azn3K3CE8+aMoQBr1oh8sMJSq9lIosvXuW1sUzlFrk9JROHMnDayuqrAxLqmLq0r3QTqMeKqSUyCdrVGfQ49pRCRYeOH6u0K36LuDGPKRlJviO4INP6RyJkQxU1sNUNCzdZk5JlgnvMz+PiG78kKWvbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739309154; c=relaxed/simple; bh=cRfV58Kh8+/WrvCJJWhBR/V0oGVgKQc3FHgkhJO9CEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rbd4k5MLGgZfCl3LiR2LOfxbVQvHexpkRo/J9XapRjG0+Q4mdsK1ydHJegHx3mysPJA74hdUrzdnJZ8666LAmoSvGh3ZUMz34UQFebQTI002Z2qhD0B0HPjI0B+Dw6of1/+esGJbX2hq0SCqQGRSxeBUfFH2zutIUooNBLoHj/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=KAmVYPl3; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="KAmVYPl3" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id 31469b2175be8e51; Tue, 11 Feb 2025 22:25:43 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 3E994770175; Tue, 11 Feb 2025 22:25:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1739309143; bh=cRfV58Kh8+/WrvCJJWhBR/V0oGVgKQc3FHgkhJO9CEE=; h=From:Subject:Date; b=KAmVYPl3THXVXJPDHj7GSdRgIqGt6gy1+wrnDKKSB0vpQEpPX1ZBWZB7PJTugLHg1 Axni2/ZNjmuWWPcWjtPcKgLb7Tqalcj8+pp7WsPsudQ0YTkHgiNeV9qMDelXV1BI+i NlYXkH9KBVtDCgj8yAVpw1hYxA93kAxNqyOCI72eFVKG/KxsqNr+B9RQLUzv0/I++S F4gimHNrsZ7+9ETrZrxmyM2vV75SLCuTxD5g2SKcmFKqw4OUZZhOfG1aWaVEQGVRtf ccbeKgni+wMor+wWQ0mpydz7ru/eRS6NYp2PSOJqPOVUl3hYFlzxzFKiAJL2gR1b9A 6u19KVx+2i0uQ== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Alan Stern , Ulf Hansson , Johan Hovold , Manivannan Sadhasivam , Jon Hunter Subject: [PATCH v1 10/10] PM: runtime: Discover the lack of runtime PM support Date: Tue, 11 Feb 2025 22:25:29 +0100 Message-ID: <2511990.jE0xQCEvom@rjwysocki.net> In-Reply-To: <2314745.iZASKD2KPV@rjwysocki.net> References: <2314745.iZASKD2KPV@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegvddtkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhtvghrnhesrhhofihlrghnugdrhhgrrhhvrghrugdrvgguuhdprhgtphhtthhopehulhhfrdhhrghnshhsohhnsehlihhnrghrohdrohhrghdprhgtphhtthhopehjohhhrghnsehkvghrnhgvlhdrohhrghdprhgtphh X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 From: Rafael J. Wysocki Previous changes have updated the PM core to special-case devices that have never had runtime PM enabled in some places, but what if a device had had runtime PM enabled at one point, but then it was permanently disabled? Arguably, there is not much of a difference between such devices and the devices that have never had runtime PM enabled as far as system-wide suspend and resume is concerned, so they should be handled in the same way. For this reason, add a mechanism for discovering "lost" runtime PM support in devices with the help of the power.last_status field used for saving the last runtime PM status of the device known at the time when runtime PM was disabled for it. That field is set to RPM_INVALID initially and whenever runtime PM is enabled for a device (that is, when its power.disable_depth counter drops down to zero) and it is set to the current runtime PM status of the device when runtime PM is disabled (that is, the power.disable_depth counter becomes nonzero). Therefore, if power.last_status is equal to RPM_INVALID for a device with runtime PM disabled, it means that runtime PM has never been enabled for that device. The PM core will now change the power.last_status value to RPM_UNKNOWN for devices having runtime PM disabled and power.last_status different from RPM_INVALID during the "prepare" phase of system suspend. Then, __pm_runtime_disable() called subsequently on the device will set power.last_status to RPM_INVALID unless it changes from RPM_UNKNOWN to some other value in the meantime which requires enabling runtime PM for the device. When power.last_status becomes RPM_INVALID and runtime PM is still disabled, the device will be handled as a "no runtime PM support" one from that point on until runtime PM is enabled for it again. Signed-off-by: Rafael J. Wysocki --- drivers/base/power/main.c | 6 ++++++ drivers/base/power/runtime.c | 25 +++++++++++++++++++++++++ include/linux/pm.h | 1 + include/linux/pm_runtime.h | 2 ++ 4 files changed, 34 insertions(+) --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -1817,6 +1817,12 @@ * it again during the complete phase. */ pm_runtime_get_noresume(dev); + /* + * Devices that have had runtime PM disabled recently may need to be + * handled as though they have never supported it, so arrange for + * detecting that situation. + */ + pm_runtime_kick_last_status(dev); if (dev->power.syscore) return 0; --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1480,6 +1480,9 @@ if (dev->power.disable_depth > 0) { dev->power.disable_depth++; + if (dev->power.last_status == RPM_UNKNOWN) + dev->power.last_status = RPM_INVALID; + goto out; } @@ -1568,6 +1571,28 @@ EXPORT_SYMBOL_GPL(devm_pm_runtime_enable); /** + * pm_runtime_kick_last_status - Start runtime PM support verification. + * @dev: Target device. + * + * If runtime PM is currently disabled for @dev, but it has been enabled at one + * point, change power.last_status for it to RPM_UNKNOWN, and if it is still + * RPM_UNKNOWN when __pm_runtime_disabled() is called for @dev next time, it + * will be changed to RPM_INVALID indicating no runtime PM support going + * forward until pm_runtime_enable() is called for @dev. + * + * This function is used by the PM core. + */ +void pm_runtime_kick_last_status(struct device *dev) +{ + spin_lock_irq(&dev->power.lock); + + if (dev->power.disable_depth && dev->power.last_status != RPM_INVALID) + dev->power.last_status = RPM_UNKNOWN; + + spin_unlock_irq(&dev->power.lock); +} + +/** * pm_runtime_forbid - Block runtime PM of a device. * @dev: Device to handle. * --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -597,6 +597,7 @@ RPM_RESUMING, RPM_SUSPENDED, RPM_SUSPENDING, + RPM_UNKNOWN, }; /* --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -80,6 +80,7 @@ extern int pm_runtime_barrier(struct device *dev); extern void pm_runtime_enable(struct device *dev); extern void __pm_runtime_disable(struct device *dev, bool check_resume); +extern void pm_runtime_kick_last_status(struct device *dev); extern void pm_runtime_allow(struct device *dev); extern void pm_runtime_forbid(struct device *dev); extern void pm_runtime_no_callbacks(struct device *dev); @@ -288,6 +289,7 @@ static inline int pm_runtime_barrier(struct device *dev) { return 0; } static inline void pm_runtime_enable(struct device *dev) {} static inline void __pm_runtime_disable(struct device *dev, bool c) {} +static inline void pm_runtime_kick_last_status(struct device *dev) {} static inline void pm_runtime_allow(struct device *dev) {} static inline void pm_runtime_forbid(struct device *dev) {}