Skip to content

Commit 67f3b2f

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: avoid to iterate over stale request
blk-mq can't run allocating driver tag and updating ->rqs[tag] atomically, meantime blk-mq doesn't clear ->rqs[tag] after the driver tag is released. So there is chance to iterating over one stale request just after the tag is allocated and before updating ->rqs[tag]. scsi_host_busy_iter() calls scsi_host_check_in_flight() to count scsi in-flight requests after scsi host is blocked, so no new scsi command can be marked as SCMD_STATE_INFLIGHT. However, driver tag allocation still can be run by blk-mq core. One request is marked as SCMD_STATE_INFLIGHT, but this request may have been kept in another slot of ->rqs[], meantime the slot can be allocated out but ->rqs[] isn't updated yet. Then this in-flight request is counted twice as SCMD_STATE_INFLIGHT. This way causes trouble in handling scsi error. Fixes the issue by not iterating over stale request. Cc: [email protected] Cc: "Martin K. Petersen" <[email protected]> Reported-by: luojiaxing <[email protected]> Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 6880fa6 commit 67f3b2f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

block/blk-mq-tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static struct request *blk_mq_find_and_get_req(struct blk_mq_tags *tags,
208208

209209
spin_lock_irqsave(&tags->lock, flags);
210210
rq = tags->rqs[bitnr];
211-
if (!rq || !refcount_inc_not_zero(&rq->ref))
211+
if (!rq || rq->tag != bitnr || !refcount_inc_not_zero(&rq->ref))
212212
rq = NULL;
213213
spin_unlock_irqrestore(&tags->lock, flags);
214214
return rq;

0 commit comments

Comments
 (0)