* [PATCH v3 1/9] block: Fix a race in the runtime power management code [not found] <20201123031749.14912-1-bvanassche@acm.org> @ 2020-11-23 3:17 ` Bart Van Assche 2020-11-23 6:46 ` Hannes Reinecke 0 siblings, 1 reply; 2+ messages in thread From: Bart Van Assche @ 2020-11-23 3:17 UTC (permalink / raw) To: Martin K . Petersen Cc: James E . J . Bottomley, Jens Axboe, Christoph Hellwig, Ming Lei, linux-scsi, linux-block, Bart Van Assche, Alan Stern, Stanley Chu, Rafael J . Wysocki, stable, Can Guo 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. Acked-by: Alan Stern <stern@rowland.harvard.edu> Acked-by: Stanley Chu <stanley.chu@mediatek.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Ming Lei <ming.lei@redhat.com> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Cc: stable <stable@vger.kernel.org> Fixes: 986d413b7c15 ("blk-mq: Enable support for runtime power management") Signed-off-by: Can Guo <cang@codeaurora.org> Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- block/blk-pm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/block/blk-pm.c b/block/blk-pm.c index b85234d758f7..17bd020268d4 100644 --- a/block/blk-pm.c +++ b/block/blk-pm.c @@ -67,6 +67,10 @@ int blk_pre_runtime_suspend(struct request_queue *q) 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 request_queue *q) /* 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; } ^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3 1/9] block: Fix a race in the runtime power management code 2020-11-23 3:17 ` [PATCH v3 1/9] block: Fix a race in the runtime power management code Bart Van Assche @ 2020-11-23 6:46 ` Hannes Reinecke 0 siblings, 0 replies; 2+ messages in thread From: Hannes Reinecke @ 2020-11-23 6:46 UTC (permalink / raw) To: Bart Van Assche, Martin K . Petersen Cc: James E . J . Bottomley, Jens Axboe, Christoph Hellwig, Ming Lei, linux-scsi, linux-block, Alan Stern, Stanley Chu, Rafael J . Wysocki, stable, Can Guo On 11/23/20 4:17 AM, Bart Van Assche wrote: > 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. > > Acked-by: Alan Stern <stern@rowland.harvard.edu> > Acked-by: Stanley Chu <stanley.chu@mediatek.com> > Reviewed-by: Christoph Hellwig <hch@lst.de> > Cc: Ming Lei <ming.lei@redhat.com> > Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > Cc: stable <stable@vger.kernel.org> > Fixes: 986d413b7c15 ("blk-mq: Enable support for runtime power management") > Signed-off-by: Can Guo <cang@codeaurora.org> > Signed-off-by: Bart Van Assche <bvanassche@acm.org> > --- > block/blk-pm.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > Reviewed-by: Hannes Reinecke <hare@suse.de> Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-23 6:46 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <20201123031749.14912-1-bvanassche@acm.org> 2020-11-23 3:17 ` [PATCH v3 1/9] block: Fix a race in the runtime power management code Bart Van Assche 2020-11-23 6:46 ` Hannes Reinecke
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).