From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0DACD1FDD; Mon, 4 Aug 2025 00:39:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754267979; cv=none; b=H8WYn/c5L0gOEmn+rGE5vUTwGjQb4FUih74nnhEEiNtQR7pGOXkUuBfmB5ZRYFz+JQ5hxsF/ZfQY2gydafCaqO0AviQe7NSDq2mpDuxKToDVUFfJ2/4gAqb4EiAGLk6l2MK/10MU2EKpqyQQcU48iq3esGzAtxM1VOCBKjUxn8Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754267979; c=relaxed/simple; bh=PpBau8v62RpHB08pG6eLjarnZyi4UNO0F29qg72ImxM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FYr2fFFO5AsSUbKgQnG5e6jt2kDHG4yte9FIKu/ZArcmekZ5hank3OvvJHCqRFRIEevAt6xKu50YFl0KRyyPdasiWW6r60NuK4dLpzyeRO0W4wcttF/XxzyilS8ygHgURqVeD2+h1e2jmSixCcU3kQut5WJxZHx62LE0hVK1pHU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JQhdmrKO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JQhdmrKO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40FC8C4CEF8; Mon, 4 Aug 2025 00:39:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754267978; bh=PpBau8v62RpHB08pG6eLjarnZyi4UNO0F29qg72ImxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JQhdmrKOP1HHxUXb9DmRoS3Bu6L/Nze8FfMIqW7dfwwF3iPVohm3gJC5dC42tap6T DkXDQqq5z+Kl4J07SthKnDI1rKk1tBn3QHpKhU5l9SsyGEbkSPaFvKttjpiU6ahRRt hIIVHolUh3kFgaiMQy8ulGiObf0+pyNsxX+0h3rrRah2Cz1Erxu/J4vd/gPIFTp759 mpnxedz5cUHuY3q5XsngSfUX6gpTNnuoezVEUPmFBqJoPgbQSFdj4Y2W9i1OdtHRk1 NQlwRplhvPTiUm6MramhI98Cnogn9fLvYJrQVf8KUrOhDNWcNyTxpVIPAhiRxC2NWC h6NWSg89GhchA== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: "Rafael J. Wysocki" , Ulf Hansson , Sasha Levin , rafael@kernel.org, linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 21/44] PM: runtime: Clear power.needs_force_resume in pm_runtime_reinit() Date: Sun, 3 Aug 2025 20:38:26 -0400 Message-Id: <20250804003849.3627024-21-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250804003849.3627024-1-sashal@kernel.org> References: <20250804003849.3627024-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.189 Content-Transfer-Encoding: 8bit From: "Rafael J. Wysocki" [ Upstream commit 89d9cec3b1e9c49bae9375a2db6dc49bc7468af0 ] Clear power.needs_force_resume in pm_runtime_reinit() in case it has been set by pm_runtime_force_suspend() invoked from a driver remove callback. Suggested-by: Ulf Hansson Signed-off-by: Rafael J. Wysocki Reviewed-by: Ulf Hansson Link: https://patch.msgid.link/9495163.CDJkKcVGEf@rjwysocki.net Signed-off-by: Sasha Levin --- LLM Generated explanations, may be completely bogus: **Backport Status: YES** This commit is a clear bugfix that should be backported to stable kernel trees for the following reasons: 1. **It fixes a real bug**: The commit addresses a specific issue where `power.needs_force_resume` flag is not cleared in `pm_runtime_reinit()` when a device is removed. If a driver calls `pm_runtime_force_suspend()` from its remove callback (which sets `needs_force_resume = 1`), this flag remains set even after the device is removed and potentially re-probed. 2. **The fix is minimal and contained**: The change adds just 5 lines of code (including comments) to clear a single flag. The modification is: ```c dev->power.needs_force_resume = false; ``` This is a very low-risk change that only affects the specific condition being fixed. 3. **It prevents state leakage**: Looking at the code flow: - `pm_runtime_force_suspend()` sets `dev->power.needs_force_resume = 1` (line in runtime.c) - When a driver is removed, `pm_runtime_remove()` calls `pm_runtime_reinit()` - Without this fix, if the device is re-probed, it would still have `needs_force_resume = 1` from the previous instance - This could lead to incorrect PM runtime behavior where `pm_runtime_force_resume()` would incorrectly think it needs to resume a device that was never suspended in the current probe cycle 4. **Related to previous stable fixes**: The git history shows a previous commit `c745253e2a69` ("PM: runtime: Fix unpaired parent child_count for force_resume") was already marked for stable (4.16+), indicating that issues with the `needs_force_resume` flag have been problematic enough to warrant stable backports. 5. **Clear bug scenario**: The commit message describes a specific scenario where this happens - when `pm_runtime_force_suspend()` is called from a driver remove callback. This is a legitimate use case where drivers want to ensure devices are suspended before removal. 6. **No architectural changes**: This is purely a bugfix that clears a flag that should have been cleared during reinitialization. It doesn't introduce new features or change any APIs. The fix ensures proper PM runtime state management across device removal and re-probing cycles, which is important for system stability and correct power management behavior. drivers/base/power/runtime.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 35e1a090ef90..26ea7f5c8d42 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1714,6 +1714,11 @@ void pm_runtime_reinit(struct device *dev) pm_runtime_put(dev->parent); } } + /* + * Clear power.needs_force_resume in case it has been set by + * pm_runtime_force_suspend() invoked from a driver remove callback. + */ + dev->power.needs_force_resume = false; } /** -- 2.39.5