From 0cd36102916db29f73daa5a6e1ab9c4eba0b68c0 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 4 Jan 2021 11:17:32 +0100 Subject: [PATCH] 5.4-stable patches added patches: scsi-block-fix-a-race-in-the-runtime-power-management-code.patch --- ...in-the-runtime-power-management-code.patch | 80 +++++++++++++++++++ queue-5.4/series | 1 + 2 files changed, 81 insertions(+) create mode 100644 queue-5.4/scsi-block-fix-a-race-in-the-runtime-power-management-code.patch diff --git a/queue-5.4/scsi-block-fix-a-race-in-the-runtime-power-management-code.patch b/queue-5.4/scsi-block-fix-a-race-in-the-runtime-power-management-code.patch new file mode 100644 index 00000000000..45bd2d87346 --- /dev/null +++ b/queue-5.4/scsi-block-fix-a-race-in-the-runtime-power-management-code.patch @@ -0,0 +1,80 @@ +From fa4d0f1992a96f6d7c988ef423e3127e613f6ac9 Mon Sep 17 00:00:00 2001 +From: Bart Van Assche +Date: Tue, 8 Dec 2020 21:29:44 -0800 +Subject: scsi: block: Fix a race in the runtime power management code + +From: Bart Van Assche + +commit fa4d0f1992a96f6d7c988ef423e3127e613f6ac9 upstream. + +With the current implementation the following race can happen: + + * blk_pre_runtime_suspend() calls blk_freeze_queue_start() and + blk_mq_unfreeze_queue(). + + * blk_queue_enter() calls blk_queue_pm_only() and that function returns + true. + + * blk_queue_enter() calls blk_pm_request_resume() and that function does + not call pm_request_resume() because the queue runtime status is + RPM_ACTIVE. + + * blk_pre_runtime_suspend() changes the queue status into RPM_SUSPENDING. + +Fix this race by changing the queue runtime status into RPM_SUSPENDING +before switching q_usage_counter to atomic mode. + +Link: https://lore.kernel.org/r/20201209052951.16136-2-bvanassche@acm.org +Fixes: 986d413b7c15 ("blk-mq: Enable support for runtime power management") +Cc: Ming Lei +Cc: Rafael J. Wysocki +Cc: stable +Reviewed-by: Christoph Hellwig +Reviewed-by: Hannes Reinecke +Reviewed-by: Jens Axboe +Acked-by: Alan Stern +Acked-by: Stanley Chu +Co-developed-by: Can Guo +Signed-off-by: Can Guo +Signed-off-by: Bart Van Assche +Signed-off-by: Martin K. Petersen +Signed-off-by: Greg Kroah-Hartman + +--- + block/blk-pm.c | 15 +++++++++------ + 1 file changed, 9 insertions(+), 6 deletions(-) + +--- a/block/blk-pm.c ++++ b/block/blk-pm.c +@@ -67,6 +67,10 @@ int blk_pre_runtime_suspend(struct reque + + WARN_ON_ONCE(q->rpm_status != RPM_ACTIVE); + ++ spin_lock_irq(&q->queue_lock); ++ q->rpm_status = RPM_SUSPENDING; ++ spin_unlock_irq(&q->queue_lock); ++ + /* + * Increase the pm_only counter before checking whether any + * non-PM blk_queue_enter() calls are in progress to avoid that any +@@ -89,15 +93,14 @@ int blk_pre_runtime_suspend(struct reque + /* Switch q_usage_counter back to per-cpu mode. */ + blk_mq_unfreeze_queue(q); + +- spin_lock_irq(&q->queue_lock); +- if (ret < 0) ++ if (ret < 0) { ++ spin_lock_irq(&q->queue_lock); ++ q->rpm_status = RPM_ACTIVE; + pm_runtime_mark_last_busy(q->dev); +- else +- q->rpm_status = RPM_SUSPENDING; +- spin_unlock_irq(&q->queue_lock); ++ spin_unlock_irq(&q->queue_lock); + +- if (ret) + blk_clear_pm_only(q); ++ } + + return ret; + } diff --git a/queue-5.4/series b/queue-5.4/series index 019fc59e7af..510b254a9d9 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -15,3 +15,4 @@ kvm-x86-reinstate-vendor-agnostic-check-on-spec_ctrl.patch powerpc-bitops-fix-possible-undefined-behaviour-with.patch jffs2-allow-setting-rp_size-to-zero-during-remountin.patch jffs2-fix-null-pointer-dereference-in-rp_size-fs-opt.patch +scsi-block-fix-a-race-in-the-runtime-power-management-code.patch -- 2.47.3