summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJianchao Wang <jianchao.w.wang@oracle.com>2018-04-17 11:46:20 +0800
committerJens Axboe <axboe@kernel.dk>2018-04-16 21:56:41 -0600
commitf4560231ec42092c6662acccabb28c6cac9f5dfb (patch)
tree99f63bfa99798a198838f49306e5fe0fbbbcf86c
parentb3906535ccc6cd04c42f9b1c7e31d1947b3ebc74 (diff)
downloadlinux-0-day-f4560231ec42092c6662acccabb28c6cac9f5dfb.tar.gz
linux-0-day-f4560231ec42092c6662acccabb28c6cac9f5dfb.tar.xz
blk-mq: start request gstate with gen 1
rq->gstate and rq->aborted_gstate both are zero before rqs are allocated. If we have a small timeout, when the timer fires, there could be rqs that are never allocated, and also there could be rq that has been allocated but not initialized and started. At the moment, the rq->gstate and rq->aborted_gstate both are 0, thus the blk_mq_terminate_expired will identify the rq is timed out and invoke .timeout early. For scsi, this will cause scsi_times_out to be invoked before the scsi_cmnd is not initialized, scsi_cmnd->device is still NULL at the moment, then we will get crash. Cc: Bart Van Assche <bart.vanassche@wdc.com> Cc: Tejun Heo <tj@kernel.org> Cc: Ming Lei <ming.lei@redhat.com> Cc: Martin Steigerwald <Martin@Lichtvoll.de> Cc: stable@vger.kernel.org Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--block/blk-core.c4
-rw-r--r--block/blk-mq.c7
2 files changed, 11 insertions, 0 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index 3e77409e5a840..85909b431eb0d 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -201,6 +201,10 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
rq->part = NULL;
seqcount_init(&rq->gstate_seq);
u64_stats_init(&rq->aborted_gstate_sync);
+ /*
+ * See comment of blk_mq_init_request
+ */
+ WRITE_ONCE(rq->gstate, MQ_RQ_GEN_INC);
}
EXPORT_SYMBOL(blk_rq_init);
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 0dc9e341c2a72..e4aa368173678 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2042,6 +2042,13 @@ static int blk_mq_init_request(struct blk_mq_tag_set *set, struct request *rq,
seqcount_init(&rq->gstate_seq);
u64_stats_init(&rq->aborted_gstate_sync);
+ /*
+ * start gstate with gen 1 instead of 0, otherwise it will be equal
+ * to aborted_gstate, and be identified timed out by
+ * blk_mq_terminate_expired.
+ */
+ WRITE_ONCE(rq->gstate, MQ_RQ_GEN_INC);
+
return 0;
}