From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380932; b=LMXgv3iytSO5vcnxI53BTT0e1SHFNZl9DoQLVHVNRTZb+wYkNVBj10cl6rLuMT0hZvUG 3kSjacJzSTbAiYU9Zem81Eq4/eLjwlX65b8dgRVDh/oEDq9MRI6sFhYeeWsMoXuBFGGex K8UUQ4pVRd/JhgZrvgtgZiDYo8kg0+3bPHr4c8p2ADwncJvARANVWjKdR6njY+oeKkLLJ O649/m/t5/VZNn8hNNOq0XR2m8PrkdZDq24HrkRtTpMaYHcMHWLNEiYRTTeMoGdqRMD8D U9p4zVQ8qbW8sOYSJ0+WAvxh60Qcb9wgmaSs8tUfvtPV9z/7/gsbhblJHXIL1lboGaA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380932; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=FiuFaLEF48zjE5GbXurgy/IazMRdw8/uGFrpp8Rs7x0=; b=CF1E1NLacWKqTRRiPLzTknf9QTTHr6utrZiK2ahsHk4NQWmdN0fgdWMhVSHsK8Cz40ZA Jj5bIMp927amnujafVxdfeEQ+3sRHSN3hpt0/EYpBjz2ggJ7yAqQbZT4zdywZcxJ41om/ 9xPVsYY2oNKuyB2fAuHkuPSSIBNWR9o5sY7hMu9hDQyB+8nc/5sD6Lh/N6wPAPRzS0FiW H10nJehznS3aN7fxND+KK7qeB+mVl7GyJGJg8ZbACG8mlOzfGDW5Ai7Px3GzXP8bdM9eM nwVUe/nQJ9WT5hsIkeYsFiDJtbHJZkQfSVUhznjHh/Cu4FXlx8pdUmBK1qrmSALAgZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=LQTbHjoS; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2D1C606A337; Fri, 4 Dec 2026 10:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=LQTbHjoS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DE8C1F000C2; Fri, 4 Dec 2026 10:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380931; bh=FiuFaLEF48zjE5GbXurgy/IazMRdw8/uGFrpp8Rs7x0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LQTbHjoSqUG2hIzuvGxcVg9l0EhlQmb5cMS7Gj++TE/1FfE6o4qduCQheXALtFnjM KYVRPXOeKYmIKL/HQQtCmAhqj5hcQrVqXCEzB3iYoU1Sh7+c8DFTQuog4Q6u/vaV7n FCxsaftyfwhTR9ptd4KF4XqIbnCHrOClOOpJg33k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bart Van Assche , Stanley Jhu , "Rafael J. Wysocki (Intel)" , Jens Axboe Subject: [PATCH 7.3 445/742] block: Keep RPM_ACTIVE in blk_pre_runtime_resume() when already active Date: Fri, 4 Dec 2026 19:05:09 +0900 Message-ID: <20261204100646.971116046@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stanley Jhu commit 657d7c48b84f2ef0bf885b47cf2318823bc72970 upstream. Since commit eef1d74bf88f ("PM: runtime: Only set runtime_error on suspend callback failures"), a failed runtime resume leaves dev->power.runtime_error at 0 with runtime_status set to RPM_SUSPENDED, so later runtime resume requests run sdev_runtime_resume() again: 1. A runtime suspend increments q->pm_only from 0 to 1 and sets q->rpm_status to RPM_SUSPENDED. 2. The first runtime resume fails in the driver callback, and blk_post_runtime_resume() sets q->rpm_status to RPM_ACTIVE and calls blk_clear_pm_only(), decrementing q->pm_only from 1 to 0 so recovery commands can enter the queue (intended since commit 6e1fcab00a23 ("scsi: block: pm: Always set request queue runtime active in blk_post_runtime_resume()")). 3. A retried runtime resume calls blk_pre_runtime_resume(), which overwrites q->rpm_status from RPM_ACTIVE to RPM_RESUMING, so blk_post_runtime_resume() sees old_status != RPM_ACTIVE and calls blk_clear_pm_only() a second time without a matching blk_set_pm_only(). 4. q->pm_only underflows from 0 to -1 (triggering WARN_ON_ONCE in blk_clear_pm_only()), blocking non-PM requests in blk_queue_enter() and __bio_queue_enter() while the device is RPM_ACTIVE, and the next runtime suspend increments q->pm_only from -1 to 0, letting non-PM requests dispatch while RPM_SUSPENDED. This hits the UFS device well-known LUN by default and SCSI disks with manage_runtime_start_stop enabled (ATA and FireWire sbp2 defaults). Transition q->rpm_status to RPM_RESUMING in blk_pre_runtime_resume() only when it is RPM_SUSPENDED, and call blk_clear_pm_only() in blk_post_runtime_resume() only when old_status is RPM_RESUMING, pairing each clear with a completed runtime suspend. Tested on QEMU ARM64 UFS in SDB and MCQ modes by injecting runtime-resume START STOP UNIT failures on the UFS device well-known LUN, confirming zero pm_only underflows and balanced runtime PM cycles. Fixes: eef1d74bf88f ("PM: runtime: Only set runtime_error on suspend callback failures") Cc: stable@vger.kernel.org # v7.3+ Reviewed-by: Bart Van Assche Signed-off-by: Stanley Jhu Acked-by: Rafael J. Wysocki (Intel) Link: https://patch.msgid.link/20261104112744.1630864-1-stanleyjhu@google.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-pm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/block/blk-pm.c +++ b/block/blk-pm.c @@ -142,7 +142,8 @@ EXPORT_SYMBOL(blk_post_runtime_suspend); * * Description: * Update the queue's runtime status to RESUMING in preparation for the - * runtime resume of the device. + * runtime resume of the device if the queue is runtime suspended, or keep + * RPM_ACTIVE if a previous failed runtime resume already reactivated it. * * This function should be called near the start of the device's * runtime_resume callback. @@ -153,7 +154,9 @@ void blk_pre_runtime_resume(struct reque return; spin_lock_irq(&q->queue_lock); - q->rpm_status = RPM_RESUMING; + /* Keep RPM_ACTIVE if a prior failed resume reactivated the queue. */ + if (q->rpm_status == RPM_SUSPENDED) + q->rpm_status = RPM_RESUMING; spin_unlock_irq(&q->queue_lock); } EXPORT_SYMBOL(blk_pre_runtime_resume); @@ -168,8 +171,8 @@ EXPORT_SYMBOL(blk_pre_runtime_resume); * driver or error handler will need to communicate with the device. * * This function should be called near the end of the device's - * runtime_resume callback to correct queue runtime PM status and re-enable - * peeking requests from the queue. + * runtime_resume callback to mark the queue runtime active and clear + * pm_only if the queue was resuming. */ void blk_post_runtime_resume(struct request_queue *q) { @@ -185,7 +188,7 @@ void blk_post_runtime_resume(struct requ pm_request_autosuspend(q->dev); spin_unlock_irq(&q->queue_lock); - if (old_status != RPM_ACTIVE) + if (old_status == RPM_RESUMING) blk_clear_pm_only(q); } EXPORT_SYMBOL(blk_post_runtime_resume);