Rework runtime suspend and SPI domain validation
Subsystems (3)
v4 cover Rework runtime suspend and SPI domain validation
Hi Martin,
The SCSI runtime suspend and SPI domain validation mechanisms both use scsi_device_quiesce(). scsi_device_quiesce() restricts blk_queue_enter() to BLK_MQ_REQ_PREEMPT requests. There is a conflict between the requirements of runtime suspend and SCSI domain validation: no requests must be sent to runtime suspended devices that are in the state RPM_SUSPENDED while BLK_MQ_REQ_PREEMPT requests must be processed during SCSI domain validation. This conflict is resolved by reworking the SCSI domain validation implementation.
Hybernation, runtime suspend and SCSI domain validation have been retested.
Please consider this patch series for kernel v5.11.
Thanks,
Bart.
Changes between v3 and v4:
- Instead of creating a second request queue for SPI DV, set RQF_PM.
Changes between v2 and v3:
- Inlined scsi_mq_alloc_queue() into scsi_alloc_sdev() as requested by Christoph.
Changes between v1 and v2:
- Rebased this patch series on top of kernel v5.10-rc1.
Alan Stern (1):
block: Do not accept any requests while suspended
Bart Van Assche (8):
block: Fix a race in the runtime power management code
block: Introduce BLK_MQ_REQ_PM
ide: Do not set the RQF_PREEMPT flag for sense requests
ide: Mark power management requests with RQF_PM instead of RQF_PREEMPT
scsi: Do not wait for a request in scsi_eh_lock_door()
scsi_transport_spi: Set RQF_PM for domain validation commands
scsi: Only process PM requests if rpm_status != RPM_ACTIVE
block: Remove RQF_PREEMPT and BLK_MQ_REQ_PREEMPT
block/blk-core.c | 12 ++++++------ block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 4 ++-- block/blk-pm.c | 15 +++++++++------ block/blk-pm.h | 14 +++++++++----- drivers/ide/ide-atapi.c | 1 - drivers/ide/ide-io.c | 7 +------ drivers/ide/ide-pm.c | 2 +- drivers/scsi/scsi_error.c | 7 ++++++- drivers/scsi/scsi_lib.c | 27 ++++++++++++++------------- drivers/scsi/scsi_transport_spi.c | 27 +++++++++++++++++++-------- include/linux/blk-mq.h | 4 ++-- include/linux/blkdev.h | 6 +----- 13 files changed, 70 insertions(+), 57 deletions(-)
PATCH v4 1/9 block: Fix a race in the runtime power management code
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.
--- block/blk-pm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
block/blk-pm.c +9 -6
@@ -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; }
PATCH v4 2/9 block: Introduce BLK_MQ_REQ_PM
In reply to Bart Van AsscheIntroduce the BLK_MQ_REQ_PM flag. This flag makes the request allocation functions set RQF_PM. This is the first step towards removing BLK_MQ_REQ_PREEMPT.
--- block/blk-core.c | 7 ++++--- block/blk-mq.c | 2 ++ include/linux/blk-mq.h | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-)
block/blk-core.c +4 -3
@@ -424,11 +424,11 @@ EXPORT_SYMBOL(blk_cleanup_queue);/** * blk_queue_enter() - try to increase q->q_usage_counter * @q: request queue pointer -* @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PREEMPT +* @flags: BLK_MQ_REQ_NOWAIT, BLK_MQ_REQ_PM and/or BLK_MQ_REQ_PREEMPT */ int blk_queue_enter (struct request_queue *q,blk_mq_req_flags_t flags) { -const bool pm = flags &BLK_MQ_REQ_PREEMPT ; +const bool pm = flags & (BLK_MQ_REQ_PM |BLK_MQ_REQ_PREEMPT );while (true) {bool success = false;
@@ -630,7 +630,8 @@ struct request *blk_get_request(struct request_queue *q, unsigned int op,struct request *req;WARN_ON_ONCE (op &REQ_NOWAIT ); -WARN_ON_ONCE (flags & ~(BLK_MQ_REQ_NOWAIT |BLK_MQ_REQ_PREEMPT )); +WARN_ON_ONCE (flags & ~(BLK_MQ_REQ_NOWAIT |BLK_MQ_REQ_PM | +BLK_MQ_REQ_PREEMPT )); req =blk_mq_alloc_request (q, op, flags);if (!IS_ERR (req) && q->mq_ops->initialize_rq_fn)
block/blk-mq.c +2 -0
@@ -292,6 +292,8 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->mq_hctx = data->hctx; rq->rq_flags =0 ; rq->cmd_flags = data->cmd_flags; +if (data->flags &BLK_MQ_REQ_PM ) + rq->rq_flags |=RQF_PM ;if (data->flags &BLK_MQ_REQ_PREEMPT ) rq->rq_flags |=RQF_PREEMPT ;if (blk_queue_io_stat (data->q))
include/linux/blk-mq.h +2 -0
@@ -444,6 +444,8 @@ enum {BLK_MQ_REQ_NOWAIT = (__force blk_mq_req_flags_t)(1 <<0 ),/* allocate from reserved pool */ BLK_MQ_REQ_RESERVED = (__force blk_mq_req_flags_t)(1 <<1 ), +/* set RQF_PM */ +BLK_MQ_REQ_PM = (__force blk_mq_req_flags_t)(1 <<2 ),/* set RQF_PREEMPT */ BLK_MQ_REQ_PREEMPT = (__force blk_mq_req_flags_t)(1 << 3), };
Re: [PATCH v4 2/9] block: Introduce BLK_MQ_REQ_PM
Looks good,
Re: [PATCH v4 2/9] block: Introduce BLK_MQ_REQ_PM
In reply to Bart Van AsscheQuoted 12 lines · Bart Van Assche
Introduce the
BLK_MQ_REQ_PMflag. This flag makes the request allocation functions setRQF_PM. This is the first step towards removingBLK_MQ_REQ_PREEMPT.Cc Alan Stern <[email protected]>Cc Stanley Chu <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Ming Lei <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Can Guo <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Quoted 6 lines
--- block/blk-core.c | 7 ++++--- block/blk-mq.c | 2 ++ include/linux/blk-mq.h | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
PATCH v4 3/9 ide: Do not set the RQF_PREEMPT flag for sense requests
In reply to Bart Van AsscheRQF_PREEMPT is used for two different purposes in the legacy IDE code:
1. To mark power management requests.
2. To mark requests that should preempt another request. An (old) explanation of that feature is as follows:
"The IDE driver in the Linux kernel normally uses a series of busywait delays during its initialization. When the driver executes these busywaits, the kernel does nothing for the duration of the wait. The time spent in these waits could be used for other initialization activities, if they could be run concurrently with these waits.
More specifically, busywait-style delays such as udelay() in module init functions inhibit kernel preemption because the Big Kernel Lock is held, while yielding APIs such as schedule_timeout() allow preemption. This is true because the kernel handles the BKL specially and releases and reacquires it across reschedules allowed by the current thread.
This IDE-preempt specification requires that the driver eliminate these busywaits and replace them with a mechanism that allows other work to proceed while the IDE driver is initializing."
Since I haven't found an implementation of (2), do not set the PREEMPT flag for sense requests. This patch causes sense requests to be postponed while a drive is suspended instead of being submitted to ide_queue_rq().
If it would ever be necessary to restore the IDE PREEMPT functionality, that can be done by introducing a new flag in struct ide_request.
--- drivers/ide/ide-atapi.c | 1 - drivers/ide/ide-io.c | 5 ----- 2 files changed, 6 deletions(-)
drivers/ide/ide-atapi.c +0 -1
@@ -223,7 +223,6 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq) sense_rq->rq_disk = rq->rq_disk; sense_rq->cmd_flags =REQ_OP_DRV_IN ;ide_req (sense_rq)->type =ATA_PRIV_SENSE ; - sense_rq->rq_flags |=RQF_PREEMPT ; req->cmd[0 ] =GPCMD_REQUEST_SENSE ; req->cmd[4 ] = cmd_len;
drivers/ide/ide-io.c +0 -5
@@ -515,11 +515,6 @@ blk_status_t ide_issue_rq(ide_drive_t *drive, struct request *rq,* above to return us whatever is in the queue. Since we call * ide_do_request() ourselves, we end up taking requests while * the queue is blocked... -* -* We let requests forced at head of queue with ide-preempt -* though. I hope that doesn't happen too much, hopefully not -* unless the subdriver triggers such a thing in its own PM -* state machine. */ if ((drive->dev_flags & IDE_DFLAG_BLOCKED) && ata_pm_request(rq) == 0 &&
Re: [PATCH v4 3/9] ide: Do not set the RQF_PREEMPT flag for sense requests
Looks good,
Re: [PATCH v4 3/9] ide: Do not set the RQF_PREEMPT flag for sense requests
In reply to Bart Van AsscheQuoted 38 lines · Bart Van Assche
RQF_PREEMPTis used for two different purposes in the legacy IDE code:
1. To mark power management requests.
2. To mark requests that should preempt another request. An (old) explanation of that feature is as follows:
"The IDE driver in the Linux kernel normally uses a series of busywait delays during its initialization. When the driver executes these busywaits, the kernel does nothing for the duration of the wait. The time spent in these waits could be used for other initialization activities, if they could be run concurrently with these waits.More specifically, busywait-style delays such as
udelay()in module init functions inhibit kernel preemption because the Big Kernel Lock is held, while yielding APIs such asschedule_timeout()allow preemption. This is true because the kernel handles the BKL specially and releases and reacquires it across reschedules allowed by the current thread.This IDE-preempt specification requires that the driver eliminate these busywaits and replace them with a mechanism that allows other work to proceed while the IDE driver is initializing."
Since I haven't found an implementation of (2), do not set the PREEMPT flag for sense requests. This patch causes sense requests to be postponed while a drive is suspended instead of being submitted to
ide_queue_rq().If it would ever be necessary to restore the IDE PREEMPT functionality, that can be done by introducing a new flag in struct
ide_request.Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc David S. Miller <[email protected]>Cc Alan Stern <[email protected]>Cc Can Guo <[email protected]>Cc Stanley Chu <[email protected]>Cc Ming Lei <[email protected]>Cc Rafael J. Wysocki <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Quoted 5 lines
--- drivers/ide/ide-atapi.c | 1 - drivers/ide/ide-io.c | 5 ----- 2 files changed, 6 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
PATCH v4 4/9 ide: Mark power management requests with RQF_PM instead of RQF_PREEMPT
In reply to Bart Van AsscheThis is another step that prepares for the removal of RQF_PREEMPT.
--- drivers/ide/ide-io.c | 2 +- drivers/ide/ide-pm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/ide/ide-io.c +1 -1
@@ -518,7 +518,7 @@ blk_status_t ide_issue_rq(ide_drive_t *drive, struct request *rq,*/ if ((drive->dev_flags &IDE_DFLAG_BLOCKED ) &&ata_pm_request (rq) ==0 && - (rq->rq_flags &RQF_PREEMPT ) ==0 ) { + (rq->rq_flags &RQF_PM ) ==0 ) {/* there should be no pending command at this point */ ide_unlock_port (hwif); goto plug_device;
drivers/ide/ide-pm.c +1 -1
@@ -77,7 +77,7 @@ int generic_ide_resume(struct device *dev) }memset (&rqpm,0 ,sizeof (rqpm)); - rq =blk_get_request (drive->queue,REQ_OP_DRV_IN ,BLK_MQ_REQ_PREEMPT ); + rq =blk_get_request (drive->queue,REQ_OP_DRV_IN ,BLK_MQ_REQ_PM );ide_req (rq)->type =ATA_PRIV_PM_RESUME ;ide_req (rq)->special = &rqpm; rqpm.pm_step =IDE_PM_START_RESUME ;
Re: [PATCH v4 4/9] ide: Mark power management requests with RQF_PM instead of RQF_PREEMPT
Looks good,
Re: [PATCH v4 4/9] ide: Mark power management requests with RQF_PM instead of RQF_PREEMPT
In reply to Bart Van AsscheQuoted 11 lines · Bart Van Assche
This is another step that prepares for the removal of
RQF_PREEMPT.Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc David S. Miller <[email protected]>Cc Alan Stern <[email protected]>Cc Can Guo <[email protected]>Cc Stanley Chu <[email protected]>Cc Ming Lei <[email protected]>Cc Rafael J. Wysocki <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Quoted 5 lines
--- drivers/ide/ide-io.c | 2 +- drivers/ide/ide-pm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
PATCH v4 5/9 scsi: Do not wait for a request in scsi_eh_lock_door()
In reply to Bart Van Asschescsi_eh_lock_door() is the only function in the SCSI error handler that calls blk_get_request(). It is not guaranteed that a request is available when scsi_eh_lock_door() is called. Hence pass the BLK_MQ_REQ_NOWAIT flag to blk_get_request().
--- drivers/scsi/scsi_error.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/scsi_error.c +6 -1
@@ -1993,7 +1993,12 @@ static void scsi_eh_lock_door(struct scsi_device *sdev)struct request *req;struct scsi_request *rq; - req =blk_get_request (sdev->request_queue,REQ_OP_SCSI_IN ,0 ); +/* +* It is not guaranteed that a request is available nor that +* sdev->request_queue is unfrozen. Hence the BLK_MQ_REQ_NOWAIT below. +*/ + req =blk_get_request (sdev->request_queue,REQ_OP_SCSI_IN , +BLK_MQ_REQ_NOWAIT );if (IS_ERR (req))return ; rq =scsi_req (req);
Re: [PATCH v4 5/9] scsi: Do not wait for a request in scsi_eh_lock_door()
Quoted 25 lines · Bart Van Assche
scsi_eh_lock_door()is the only function in the SCSI error handler that callsblk_get_request(). It is not guaranteed that a request is available whenscsi_eh_lock_door()is called. Hence pass theBLK_MQ_REQ_NOWAITflag toblk_get_request().Reviewed-by Alan Stern <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Cc Can Guo <[email protected]>Cc Stanley Chu <[email protected]>Cc Ming Lei <[email protected]>Cc Rafael J. Wysocki <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/scsi/scsi_error.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/scsi/scsi_error.c +0
-0@@ -1993,7 +1993,12 @@ static void scsi_eh_lock_door(struct scsi_device *sdev)struct request *req;struct scsi_request *rq;
drivers/scsi/scsi_error.c static void scsi_eh_lock_door(struct scsi_device *sdev) · line 2004
Quoted 10 lines
drivers/scsi/scsi_error.c +6
-1- req =blk_get_request (sdev->request_queue,REQ_OP_SCSI_IN ,0 ); +/* +* It is not guaranteed that a request is available nor that +* sdev->request_queue is unfrozen. Hence the BLK_MQ_REQ_NOWAIT below. +*/ + req =blk_get_request (sdev->request_queue,REQ_OP_SCSI_IN , +BLK_MQ_REQ_NOWAIT );if (IS_ERR (req))return ; rq =scsi_req (req);
Well ... had been thinking about that one, too.
The idea of this function is that prior to SCSI EH the device was locked
via scsi_set_medium_removal(). And during SCSI EH the device might have become unlocked, so we need to lock it again. However, scsi_set_medium_removal() not only issues the PREVENT_ALLOW_MEDIUM_REMOVAL command, but also sets the 'locked' flag based on the result. So if we fail to get a request here, shouldn't we unset the 'locked' flag, too?
And what does happen if we fail here? There is no return value, hence SCSI EH might run to completion, and the system will continue with an unlocked door ...
Not sure if that's a good idea.
But anyway, at the very least unset the 'locked' flag upon failure such that the internal state is correctly updated.
_Actually_, the flag should be unset after each successful SCSI EH step, to mirror the actual state. But this is probably out of scope for this patch.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v4 5/9] scsi: Do not wait for a request in scsi_eh_lock_door()
Quoted 23 lines · Hannes Reinecke
Quoted 12 lines · Bart Van Assche
drivers/scsi/scsi_error.c +3
-0@@ -1993,7 +1993,12 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) struct request *req; struct scsi_request *rq; - req = blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, 0); + /* +* It is not guaranteed that a request is available nor that +* sdev->request_queue is unfrozen. Hence the BLK_MQ_REQ_NOWAIT Quoted 8 lines
below.
+ */
+ req =blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, + BLK_MQ_REQ_NOWAIT);
if (IS_ERR(req))
return;
rq =scsi_req(req);Well ... had been thinking about that one, too.
Quoted 8 lines
The idea of this function is that prior to SCSI EH the device was locked via
scsi_set_medium_removal(). And during SCSI EH the device might have become unlocked, so we need to lock it again.
However,scsi_set_medium_removal()not only issues thePREVENT_ALLOW_MEDIUM_REMOVALcommand, but also sets the 'locked' flag based on the result.
So if we fail to get a request here, shouldn't we unset the 'locked' flag, too?
Probably not. My interpretation of the 'locked' flag is that it represents the door state before error handling began. The following code in the SCSI error handler restores the door state after a bus reset:
if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) {
scsi_eh_lock_door(sdev);
sdev->was_reset = 0;
}Quoted 4 lines
And what does happen if we fail here? There is no return value, hence SCSI EH might run to completion, and the system will continue with an unlocked door ...
Not sure if that's a good idea.
How about applying the following patch on top of patch 5/9?
drivers/scsi/scsi_error.c +5 -4
@@ -1988,7 +1988,7 @@ static void eh_lock_door_done(struct request *req, blk_status_t status)* We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the * head of the devices request queue, and continue. */ -static void scsi_eh_lock_door (struct scsi_device *sdev) +static int scsi_eh_lock_door (struct scsi_device *sdev) {struct request *req;struct scsi_request *rq;
@@ -2000,7 +2000,7 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) req =blk_get_request (sdev->request_queue,REQ_OP_SCSI_IN ,BLK_MQ_REQ_NOWAIT );if (IS_ERR (req)) -return ; +return PTR_ERR (req); rq =scsi_req (req); rq->cmd[0 ] =ALLOW_MEDIUM_REMOVAL ;
@@ -2016,6 +2016,7 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) rq->retries =5 ;blk_execute_rq_nowait (req->q,NULL , req,1 , eh_lock_door_done); +return 0 ; }/**
@@ -2037,8 +2038,8 @@ static void scsi_restart_operations(struct Scsi_Host *shost)* is no point trying to lock the door of an off-line device. */ shost_for_each_device (sdev, shost) { -if (scsi_device_online (sdev) && sdev->was_reset && sdev->locked) { -scsi_eh_lock_door (sdev); +if (scsi_device_online (sdev) && sdev->was_reset && + sdev->locked &&scsi_eh_lock_door (sdev) ==0 ) { sdev->was_reset =0 ; } }
Thanks,
Bart.
Re: [PATCH v4 5/9] scsi: Do not wait for a request in scsi_eh_lock_door()
Quoted 81 lines · Bart Van Assche
Quoted 23 lines · Hannes Reinecke
Quoted 12 lines · Bart Van Assche
drivers/scsi/scsi_error.c +3
-0@@ -1993,7 +1993,12 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) struct request *req; struct scsi_request *rq; - req = blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, 0); + /* +* It is not guaranteed that a request is available nor that +* sdev->request_queue is unfrozen. Hence the BLK_MQ_REQ_NOWAIT Quoted 8 lines
below.
+ */
+ req =blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, + BLK_MQ_REQ_NOWAIT);
if (IS_ERR(req))
return;
rq =scsi_req(req);Well ... had been thinking about that one, too.
Quoted 8 lines
The idea of this function is that prior to SCSI EH the device was locked via
scsi_set_medium_removal(). And during SCSI EH the device might have become unlocked, so we need to lock it again.
However,scsi_set_medium_removal()not only issues thePREVENT_ALLOW_MEDIUM_REMOVALcommand, but also sets the 'locked' flag based on the result.
So if we fail to get a request here, shouldn't we unset the 'locked' flag, too?Probably not. My interpretation of the 'locked' flag is that it represents the door state before error handling began. The following code in the SCSI error handler restores the door state after a bus reset:
if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) { scsi_eh_lock_door(sdev); sdev->was_reset = 0; }Quoted 4 lines
And what does happen if we fail here? There is no return value, hence SCSI EH might run to completion, and the system will continue with an unlocked door ...
Not sure if that's a good idea.How about applying the following patch on top of patch 5/9?
drivers/scsi/scsi_error.c +3
-2@@ -1988,7 +1988,7 @@ static void eh_lock_door_done(struct request *req, blk_status_t status)* We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the * head of the devices request queue, and continue. */ -static void scsi_eh_lock_door (struct scsi_device *sdev) +static int scsi_eh_lock_door (struct scsi_device *sdev) {struct request *req;struct scsi_request *rq;@@ -2000,7 +2000,7 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) req =blk_get_request (sdev->request_queue,REQ_OP_SCSI_IN ,BLK_MQ_REQ_NOWAIT );if (IS_ERR (req)) -return ; +return PTR_ERR (req); rq =scsi_req (req); rq->cmd[0 ] =ALLOW_MEDIUM_REMOVAL ;@@ -2016,6 +2016,7 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) rq->retries =5 ;blk_execute_rq_nowait (req->q,NULL , req,1 , eh_lock_door_done); +return 0 ; }/**
drivers/scsi/scsi_error.c static void scsi_restart_operations(struct Scsi_Host *shost) · line 2045
Quoted 10 lines
drivers/scsi/scsi_error.c +2
-2@@ -2037,8 +2038,8 @@ static void scsi_restart_operations(struct Scsi_Host *shost)* is no point trying to lock the door of an off-line device. */ shost_for_each_device (sdev, shost) { -if (scsi_device_online (sdev) && sdev->was_reset && sdev->locked) { -scsi_eh_lock_door (sdev); +if (scsi_device_online (sdev) && sdev->was_reset && + sdev->locked &&scsi_eh_lock_door (sdev) ==0 ) { sdev->was_reset =0 ; } }
I probably didn't make myself clear.
As per SBC (in this case, sbc3r36) the effects of PREVENT_ALLOW_MEDIUM_REMOVAL are being reset by a successfull LUN Reset, Hard Reset, Power/On Reset, or an I_T Nexus loss. Which incidentally maps nicely onto SCSI EH, so after a successful SCSI EH the door will be unlocked (which is why we need to call scsi_eh_lock_door()). In the SCSI midlayer this state is being reflected by the 'locked' flag.
Now, if scsi_eh_lock_door() is _not_ being executed due to a blk_get_request() failure, the device remains unlocked, and as such the 'locked' flag would need to be _unset_.
So I was thinking more along these lines:
@@ -2030,7 +2037,8 @@ static void scsi_restart_operations(struct Scsi_Host *shost)
*/
shost_for_each_device(sdev, shost) {
if (scsi_device_online(sdev) && sdev->was_reset &&
sdev->locked) {
- scsi_eh_lock_door(sdev);
+ if (scsi_eh_lock_door(sdev) < 0)
+ sdev->locked = 0;
sdev->was_reset = 0;
}
}Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v4 5/9] scsi: Do not wait for a request in scsi_eh_lock_door()
Quoted 106 lines · Hannes Reinecke
Quoted 81 lines · Bart Van Assche
Quoted 23 lines · Hannes Reinecke
Quoted 12 lines · Bart Van Assche
drivers/scsi/scsi_error.c +3
-0@@ -1993,7 +1993,12 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) struct request *req; struct scsi_request *rq; - req = blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, 0); + /* +* It is not guaranteed that a request is available nor that +* sdev->request_queue is unfrozen. Hence the BLK_MQ_REQ_NOWAIT Quoted 8 lines
below.
+ */
+ req =blk_get_request(sdev->request_queue, REQ_OP_SCSI_IN, + BLK_MQ_REQ_NOWAIT);
if (IS_ERR(req))
return;
rq =scsi_req(req);Well ... had been thinking about that one, too.
Quoted 8 lines
The idea of this function is that prior to SCSI EH the device was locked via
scsi_set_medium_removal(). And during SCSI EH the device might have become unlocked, so we need to lock it again.
However,scsi_set_medium_removal()not only issues thePREVENT_ALLOW_MEDIUM_REMOVALcommand, but also sets the 'locked' flag based on the result.
So if we fail to get a request here, shouldn't we unset the 'locked' flag, too?Probably not. My interpretation of the 'locked' flag is that it represents the door state before error handling began. The following code in the SCSI error handler restores the door state after a bus reset:
if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) { scsi_eh_lock_door(sdev); sdev->was_reset = 0; }Quoted 4 lines
And what does happen if we fail here? There is no return value, hence SCSI EH might run to completion, and the system will continue with an unlocked door ...
Not sure if that's a good idea.How about applying the following patch on top of patch 5/9?
drivers/scsi/scsi_error.c +3
-2@@ -1988,7 +1988,7 @@ static void eh_lock_door_done(struct request *req, blk_status_t status)* We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the * head of the devices request queue, and continue. */ -static void scsi_eh_lock_door (struct scsi_device *sdev) +static int scsi_eh_lock_door (struct scsi_device *sdev) {struct request *req;struct scsi_request *rq;@@ -2000,7 +2000,7 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) req =blk_get_request (sdev->request_queue,REQ_OP_SCSI_IN ,BLK_MQ_REQ_NOWAIT );if (IS_ERR (req)) -return ; +return PTR_ERR (req); rq =scsi_req (req); rq->cmd[0 ] =ALLOW_MEDIUM_REMOVAL ;@@ -2016,6 +2016,7 @@ static void scsi_eh_lock_door(struct scsi_device *sdev) rq->retries =5 ;blk_execute_rq_nowait (req->q,NULL , req,1 , eh_lock_door_done); +return 0 ; }/** drivers/scsi/scsi_error.c static void scsi_restart_operations(struct Scsi_Host *shost) · line 2045
Quoted 10 lines
drivers/scsi/scsi_error.c +2
-2@@ -2037,8 +2038,8 @@ static void scsi_restart_operations(struct Scsi_Host *shost)* is no point trying to lock the door of an off-line device. */ shost_for_each_device (sdev, shost) { -if (scsi_device_online (sdev) && sdev->was_reset && sdev->locked) { -scsi_eh_lock_door (sdev); +if (scsi_device_online (sdev) && sdev->was_reset && + sdev->locked &&scsi_eh_lock_door (sdev) ==0 ) { sdev->was_reset =0 ; } }I probably didn't make myself clear.
As per SBC (in this case, sbc3r36) the effects ofPREVENT_ALLOW_MEDIUM_REMOVALare being reset by a successfull LUN Reset, Hard Reset, Power/On Reset, or anI_TNexus loss. Which incidentally maps nicely onto SCSI EH, so after a successful SCSI EH the door will be unlocked (which is why we need to callscsi_eh_lock_door()).
In the SCSI midlayer this state is being reflected by the 'locked' flag. Now, ifscsi_eh_lock_door()is _not_ being executed due to ablk_get_request()failure, the device remains unlocked, and as such the 'locked' flag would need to be _unset_.So I was thinking more along these lines:
Review static void scsi_restart_operations(struct Scsi_Host · line 2043
Quoted 8 lines
(quoted diff) +2
-1@@ -2030,7 +2037,8 @@ static void scsi_restart_operations(struct Scsi_Host *shost) */ shost_for_each_device(sdev, shost) { if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) { - scsi_eh_lock_door(sdev); + if (scsi_eh_lock_door(sdev) < 0) + sdev->locked = 0;
BTW, scsi_eh_lock_door() returns void, and it can't be sync because there may not be any driver tag available. Even though it is available, the host state isn't running yet, so the command can't be queued to LLD yet.
Maybe the above lines should be put after host state is updated to RUNNING.
Also changing to NOWAIT can't avoid the issue completely, what if 'none' is used?
Thanks,
Ming
Re: [PATCH v4 5/9] scsi: Do not wait for a request in scsi_eh_lock_door()
Quoted 10 lines · Ming Lei
BTW,
scsi_eh_lock_door()returns void, and it can't be sync because there may not be any driver tag available. Even though it is available, the host state isn't running yet, so the command can't be queued to LLD yet.Maybe the above lines should be put after host state is updated to RUNNING.
Also changing to NOWAIT can't avoid the issue completely, what if 'none' is used?
Hi Ming,
I am considering to drop this patch since the latest version of the SPI DV patch no longer introduces a new blk_mq_freeze_queue() call in the SPI DV code. In other words, any potential issues with scsi_eh_lock_door() are existing issues and are not made worse by my patch series.
Thanks,
Bart.
PATCH v4 6/9 scsi_transport_spi: Set RQF_PM for domain validation commands
In reply to Bart Van AsscheDisable runtime power management during domain validation. Since a later patch removes RQF_PREEMPT, set RQF_PM for domain validation commands such that these are executed in the quiesced SCSI device state.
--- drivers/scsi/scsi_transport_spi.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/scsi/scsi_transport_spi.c +19 -8
@@ -117,12 +117,16 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd, sshdr = &sshdr_tmp;for (i =0 ; i <DV_RETRIES ; i++) { +/* +* The purpose of the RQF_PM flag below is to bypass the +* SDEV_QUIESCE state. +*/ result =scsi_execute (sdev, cmd, dir, buffer, bufflen, sense, sshdr,DV_TIMEOUT ,/* retries */ 1 ,REQ_FAILFAST_DEV |REQ_FAILFAST_TRANSPORT |REQ_FAILFAST_DRIVER , -0 ,NULL ); +RQF_PM ,NULL );if (driver_byte (result) !=DRIVER_SENSE || sshdr->sense_key !=UNIT_ATTENTION )break ;
@@ -1005,23 +1009,26 @@ spi_dv_device(struct scsi_device *sdev)*/ lock_system_sleep (); +if (scsi_autopm_get_device (sdev)) + goto unlock_system_sleep; +if (unlikely (spi_dv_in_progress (starget))) - goto unlock; + goto put_autopm;if (unlikely (scsi_device_get (sdev))) - goto unlock; + goto put_autopm;spi_dv_in_progress (starget) =1 ; buffer =kzalloc (len,GFP_KERNEL );if (unlikely (!buffer)) - goto out_put; + goto put_sdev;/* We need to verify that the actual device will quiesce; the * later target quiesce is just a nice to have */ if (unlikely (scsi_device_quiesce (sdev))) - goto out_free; + goto free_buffer;scsi_target_quiesce (starget);
@@ -1041,12 +1048,16 @@ spi_dv_device(struct scsi_device *sdev)spi_initial_dv (starget) =1 ; - out_free: +free_buffer:kfree (buffer); - out_put: + +put_sdev:spi_dv_in_progress (starget) =0 ;scsi_device_put (sdev); -unlock: +put_autopm: +scsi_autopm_put_device (sdev); + +unlock_system_sleep:unlock_system_sleep (); }EXPORT_SYMBOL (spi_dv_device);
Re: [PATCH v4 6/9] scsi_transport_spi: Set RQF_PM for domain validation commands
Looks good,
PATCH v4 7/9 scsi: Only process PM requests if rpm_status != RPM_ACTIVE
In reply to Bart Van AsscheInstead of submitting all SCSI commands submitted with scsi_execute() to a SCSI device if rpm_status != RPM_ACTIVE, only submit RQF_PM (power management requests) if rpm_status != RPM_ACTIVE. This patch makes the SCSI core handle the runtime power management status (rpm_status) as it should be handled.
--- drivers/scsi/scsi_lib.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
drivers/scsi/scsi_lib.c +14 -13
@@ -249,7 +249,8 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, req =blk_get_request (sdev->request_queue, data_direction ==DMA_TO_DEVICE ? -REQ_OP_SCSI_OUT :REQ_OP_SCSI_IN ,BLK_MQ_REQ_PREEMPT ); +REQ_OP_SCSI_OUT :REQ_OP_SCSI_IN , + rq_flags &RQF_PM ?BLK_MQ_REQ_PM :0 );if (IS_ERR (req))return ret; rq =scsi_req (req);
@@ -1206,6 +1207,8 @@ static blk_status_t scsi_device_state_check(struct scsi_device *sdev, struct request *req) {switch (sdev->sdev_state) { +case SDEV_CREATED : +return BLK_STS_OK ;case SDEV_OFFLINE :case SDEV_TRANSPORT_OFFLINE :/*
@@ -1232,18 +1235,18 @@ scsi_device_state_check(struct scsi_device *sdev, struct request *req)return BLK_STS_RESOURCE ;case SDEV_QUIESCE :/* -* If the devices is blocked we defer normal commands. +* If the device is blocked we only accept power management +* commands. */ -if (req && !(req->rq_flags &RQF_PREEMPT )) +if (req &&WARN_ON_ONCE (!(req->rq_flags &RQF_PM )))return BLK_STS_RESOURCE ;return BLK_STS_OK ;default :/* * For any other not fully online state we only allow -* special commands. In particular any user initiated -* command is not allowed. +* power management commands. */ -if (req && !(req->rq_flags &RQF_PREEMPT )) +if (req && !(req->rq_flags &RQF_PM ))return BLK_STS_IOERR ;return BLK_STS_OK ; }
@@ -2517,15 +2520,13 @@ void sdev_evt_send_simple(struct scsi_device *sdev,EXPORT_SYMBOL_GPL (sdev_evt_send_simple);/** -* scsi_device_quiesce - Block user issued commands. +* scsi_device_quiesce - Block all commands except power management. * @sdev: scsi device to quiesce. * * This works by trying to transition to the SDEV_QUIESCE state * (which must be a legal transition). When the device is in this -* state, only special requests will be accepted, all others will -* be deferred. Since special requests may also be requeued requests, -* a successful return doesn't guarantee the device will be -* totally quiescent. +* state, only power management requests will be accepted, all others will +* be deferred. * * Must be called with user context, may sleep. *
@@ -2587,12 +2588,12 @@ void scsi_device_resume(struct scsi_device *sdev)* device deleted during suspend) */ mutex_lock (&sdev->state_mutex); +if (sdev->sdev_state ==SDEV_QUIESCE ) +scsi_device_set_state (sdev,SDEV_RUNNING );if (sdev->quiesced_by) { sdev->quiesced_by =NULL ;blk_clear_pm_only (sdev->request_queue); } -if (sdev->sdev_state ==SDEV_QUIESCE ) -scsi_device_set_state (sdev,SDEV_RUNNING );mutex_unlock (&sdev->state_mutex); }EXPORT_SYMBOL (scsi_device_resume);
Re: [PATCH v4 7/9] scsi: Only process PM requests if rpm_status != RPM_ACTIVE
Looks good,
Re: [PATCH v4 7/9] scsi: Only process PM requests if rpm_status != RPM_ACTIVE
In reply to Bart Van AsscheQuoted 14 lines · Bart Van Assche
Instead of submitting all SCSI commands submitted with
scsi_execute()to a SCSI device ifrpm_status!=RPM_ACTIVE, only submitRQF_PM(power management requests) ifrpm_status!=RPM_ACTIVE. This patch makes the SCSI core handle the runtime power management status (rpm_status) as it should be handled.Cc Christoph Hellwig <[email protected]>Cc Can Guo <[email protected]>Cc Stanley Chu <[email protected]>Cc Alan Stern <[email protected]>Cc Ming Lei <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Martin Kepplinger <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Quoted 4 lines
--- drivers/scsi/scsi_lib.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)Reviewed-by Hannes Reinecke <[email protected]>
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
PATCH v4 8/9 block: Remove RQF_PREEMPT and BLK_MQ_REQ_PREEMPT
In reply to Bart Van AsscheRemove flag RQF_PREEMPT and BLK_MQ_REQ_PREEMPT since these are no longer used by any kernel code.
--- block/blk-core.c | 7 +++---- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 2 -- include/linux/blk-mq.h | 2 -- include/linux/blkdev.h | 6 +----- 5 files changed, 4 insertions(+), 14 deletions(-)
block/blk-core.c +3 -4
@@ -424,11 +424,11 @@ EXPORT_SYMBOL(blk_cleanup_queue);/** * blk_queue_enter() - try to increase q->q_usage_counter * @q: request queue pointer -* @flags: BLK_MQ_REQ_NOWAIT, BLK_MQ_REQ_PM and/or BLK_MQ_REQ_PREEMPT +* @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PM */ int blk_queue_enter (struct request_queue *q,blk_mq_req_flags_t flags) { -const bool pm = flags & (BLK_MQ_REQ_PM |BLK_MQ_REQ_PREEMPT ); +const bool pm = flags &BLK_MQ_REQ_PM ;while (true) {bool success = false;
@@ -630,8 +630,7 @@ struct request *blk_get_request(struct request_queue *q, unsigned int op,struct request *req;WARN_ON_ONCE (op &REQ_NOWAIT ); -WARN_ON_ONCE (flags & ~(BLK_MQ_REQ_NOWAIT |BLK_MQ_REQ_PM | -BLK_MQ_REQ_PREEMPT )); +WARN_ON_ONCE (flags & ~(BLK_MQ_REQ_NOWAIT |BLK_MQ_REQ_PM )); req =blk_mq_alloc_request (q, op, flags);if (!IS_ERR (req) && q->mq_ops->initialize_rq_fn)
block/blk-mq-debugfs.c +0 -1
@@ -297,7 +297,6 @@ static const char *const rqf_name[] = {RQF_NAME (MIXED_MERGE ),RQF_NAME (MQ_INFLIGHT ),RQF_NAME (DONTPREP ), -RQF_NAME (PREEMPT ),RQF_NAME (FAILED ),RQF_NAME (QUIET ), RQF_NAME(ELVPRIV),
block/blk-mq.c +0 -2
@@ -294,8 +294,6 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->cmd_flags = data->cmd_flags;if (data->flags &BLK_MQ_REQ_PM ) rq->rq_flags |=RQF_PM ; -if (data->flags &BLK_MQ_REQ_PREEMPT ) - rq->rq_flags |=RQF_PREEMPT ;if (blk_queue_io_stat (data->q)) rq->rq_flags |=RQF_IO_STAT ;INIT_LIST_HEAD (&rq->queuelist);
include/linux/blk-mq.h +0 -2
@@ -446,8 +446,6 @@ enum {BLK_MQ_REQ_RESERVED = (__force blk_mq_req_flags_t)(1 <<1 ),/* set RQF_PM */ BLK_MQ_REQ_PM = (__force blk_mq_req_flags_t)(1 << 2), -/* set RQF_PREEMPT */ - BLK_MQ_REQ_PREEMPT = (__force blk_mq_req_flags_t)(1 << 3), }; struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
include/linux/blkdev.h +1 -5
@@ -79,9 +79,6 @@ typedef __u32 __bitwise req_flags_t;#define RQF_MQ_INFLIGHT ((__force req_flags_t)(1 << 6))/* don't call prep for this one */ #define RQF_DONTPREP ((__force req_flags_t)(1 << 7)) -/* set for "ide_preempt" requests and also for requests for which the SCSI -"quiesce" state must be ignored. */ -#define RQF_PREEMPT ((__force req_flags_t)(1 << 8))/* vaguely specified driver internal error. Ignored by the block layer */ #define RQF_FAILED ((__force req_flags_t)(1 << 10))/* don't warn about errors */
@@ -430,8 +427,7 @@ struct request_queue {unsigned long queue_flags;/* * Number of contexts that have called blk_set_pm_only(). If this -* counter is above zero then only RQF_PM and RQF_PREEMPT requests are -* processed. +* counter is above zero then only RQF_PM requests are processed. */ atomic_t pm_only;
Re: [PATCH v4 8/9] block: Remove RQF_PREEMPT and BLK_MQ_REQ_PREEMPT
Looks good,
Re: [PATCH v4 8/9] block: Remove RQF_PREEMPT and BLK_MQ_REQ_PREEMPT
In reply to Bart Van AsscheQuoted 11 lines · Bart Van Assche
Remove flag
RQF_PREEMPTandBLK_MQ_REQ_PREEMPTsince these are no longer used by any kernel code.Cc Christoph Hellwig <[email protected]>Cc Can Guo <[email protected]>Cc Stanley Chu <[email protected]>Cc Alan Stern <[email protected]>Cc Ming Lei <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Martin Kepplinger <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Quoted 8 lines
--- block/blk-core.c | 7 +++---- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 2 -- include/linux/blk-mq.h | 2 -- include/linux/blkdev.h | 6 +----- 5 files changed, 4 insertions(+), 14 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
PATCH v4 9/9 block: Do not accept any requests while suspended
In reply to Bart Van AsscheFrom: Alan Stern <[email protected]>
blk_queue_enter() accepts BLK_MQ_REQ_PM requests independent of the runtime power management state. Now that SCSI domain validation no longer depends on this behavior, modify the behavior of blk_queue_enter() as follows:
- Do not accept any requests while suspended.
- Only process power management requests while suspending or resuming.
Submitting BLK_MQ_REQ_PM requests to a device that is runtime suspended causes runtime-suspended devices not to resume as they should. The request which should cause a runtime resume instead gets issued directly, without resuming the device first. Of course the device can't handle it properly, the I/O fails, and the device remains suspended.
The problem is fixed by checking that the queue's runtime-PM status isn't RPM_SUSPENDED before allowing a request to be issued, and queuing a runtime-resume request if it is. In particular, the inline blk_pm_request_resume() routine is renamed blk_pm_resume_queue() and the code is unified by merging the surrounding checks into the routine. If the queue isn't set up for runtime PM, or there currently is no restriction on allowed requests, the request is allowed. Likewise if the BLK_MQ_REQ_PM flag is set and the status isn't RPM_SUSPENDED. Otherwise a runtime resume is queued and the request is blocked until conditions are more suitable.
[ bvanassche: modified commit message and removed Cc: stable because without
the previous patches from this series this patch would break parallel SCSI domain validation ]
--- block/blk-core.c | 6 +++--- block/blk-pm.h | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-)
block/blk-core.c +3 -3
@@ -440,7 +440,8 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)* responsible for ensuring that that counter is * globally visible before the queue is unfrozen. */ -if (pm || !blk_queue_pm_only (q)) { +if ((pm && q->rpm_status !=RPM_SUSPENDED ) || + !blk_queue_pm_only (q)) { success = true; }else {percpu_ref_put (&q->q_usage_counter);
@@ -465,8 +466,7 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)wait_event (q->mq_freeze_wq, (!q->mq_freeze_depth && - (pm || (blk_pm_request_resume (q), - !blk_queue_pm_only (q)))) || +blk_pm_resume_queue (pm, q)) ||blk_queue_dying (q));if (blk_queue_dying (q))return -ENODEV ;
block/blk-pm.h +9 -5
@@ -6,11 +6,14 @@#include <linux/pm_runtime.h> #ifdef CONFIG_PM -static inline void blk_pm_request_resume (struct request_queue *q) +static inline int blk_pm_resume_queue (const bool pm,struct request_queue *q) { -if (q->dev && (q->rpm_status ==RPM_SUSPENDED || - q->rpm_status ==RPM_SUSPENDING )) -pm_request_resume (q->dev); +if (!q->dev || !blk_queue_pm_only (q)) +return 1 ;/* Nothing to do */ +if (pm && q->rpm_status !=RPM_SUSPENDED ) +return 1 ;/* Request allowed */ +pm_request_resume (q->dev); +return 0 ; }static inline void blk_pm_mark_last_busy (struct request *rq)
@@ -44,8 +47,9 @@ static inline void blk_pm_put_request(struct request *rq) --rq->q->nr_pending; }#else -static inline void blk_pm_request_resume (struct request_queue *q) +static inline int blk_pm_resume_queue (const bool pm,struct request_queue *q) { +return 1 ; }static inline void blk_pm_mark_last_busy (struct request *rq)
Re: [PATCH v4 9/9] block: Do not accept any requests while suspended
Quoted 33 lines · Bart Van Assche
From: Alan Stern <[email protected]>
blk_queue_enter()acceptsBLK_MQ_REQ_PMrequests independent of the runtime power management state. Now that SCSI domain validation no longer depends on this behavior, modify the behavior ofblk_queue_enter()as follows:
- Do not accept any requests while suspended.
- Only process power management requests while suspending or resuming.Submitting
BLK_MQ_REQ_PMrequests to a device that is runtime suspended causes runtime-suspended devices not to resume as they should. The request which should cause a runtime resume instead gets issued directly, without resuming the device first. Of course the device can't handle it properly, the I/O fails, and the device remains suspended.The problem is fixed by checking that the queue's runtime-PM status isn't
RPM_SUSPENDEDbefore allowing a request to be issued, and queuing a runtime-resume request if it is. In particular, the inlineblk_pm_request_resume()routine is renamedblk_pm_resume_queue()and the code is unified by merging the surrounding checks into the routine. If the queue isn't set up for runtime PM, or there currently is no restriction on allowed requests, the request is allowed. Likewise if theBLK_MQ_REQ_PMflag is set and the status isn'tRPM_SUSPENDED. Otherwise a runtime resume is queued and the request is blocked until conditions are more suitable.Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Can Guo <[email protected]>Reviewed-by Stanley Chu <[email protected]>Cc Ming Lei <[email protected]>Cc Rafael J. Wysocki <[email protected]>Reported-and-tested-by Martin Kepplinger <[email protected]>Signed-off-by Alan Stern <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Quoted 8 lines
[ bvanassche: modified commit message and removed Cc: stable because without
the previous patches from this series this patch would break parallel SCSI domain validation ]--- block/blk-core.c | 6 +++--- block/blk-pm.h | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Jens,
Any objections to me picking this up?
Quoted 11 lines
The SCSI runtime suspend and SPI domain validation mechanisms both use
scsi_device_quiesce().scsi_device_quiesce()restrictsblk_queue_enter()toBLK_MQ_REQ_PREEMPTrequests. There is a conflict between the requirements of runtime suspend and SCSI domain
validation: no requests must be sent to runtime suspended devices that are in the stateRPM_SUSPENDEDwhileBLK_MQ_REQ_PREEMPTrequests must be processed during SCSI domain validation. This conflict is resolved by reworking the SCSI domain validation implementation.Hybernation, runtime suspend and SCSI domain validation have been retested.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 4 lines · Martin K. Petersen
Jens,
Any objections to me picking this up?
No, go ahead. Looks good to me, you can add:
to the series.
Signature · 1 line
Jens Axboe
Martin K. Petersen
AppliedBart,
Quoted 8 lines
The SCSI runtime suspend and SPI domain validation mechanisms both use
scsi_device_quiesce().scsi_device_quiesce()restrictsblk_queue_enter()toBLK_MQ_REQ_PREEMPTrequests. There is a conflict between the requirements of runtime suspend and SCSI domain
validation: no requests must be sent to runtime suspended devices that are in the stateRPM_SUSPENDEDwhileBLK_MQ_REQ_PREEMPTrequests must be processed during SCSI domain validation. This conflict is resolved by reworking the SCSI domain validation implementation.
Applied to 5.11/scsi-staging except for patch #5. Appreciate all that work that went into this series!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering