Merge branch 'for-linus' of git://git.kernel.dk/linux-block

Pull final block fixes from Jens Axboe:
 "This week and last we've been fixing some corner cases related to
  blk-mq, mostly.  I ended up pulling most of that out of for-linus
  yesterday, which is why the branch looks fresh.  The rest were
  postponed for 3.18.

  This pull request contains:

   - Fix from Christoph, avoiding a stack overflow when FUA insertion
     would recursive infinitely.

   - Fix from David Hildenbrand on races between the timeout handler and
     uninitialized requests.  Fixes a real issue that virtio_blk has run
     into.

   - A few fixes from me:

        - Ensure that request deadline/timeout is ordered before the
          request is marked as started.

        - A potential oops on out-of-memory, when we scale the queue
          depth of the device and retry.

        - A hang fix on requeue from SCSI, where the hardware queue
          would be stopped when we attempt to re-run it (and hence
          nothing would happen, stalling progress).

        - A fix for commit 2da78092, where the cleanup path was moved
          to RCU, but a debug might_sleep() was inadvertently left in
          the code.  This causes warnings for people"

* 'for-linus' of git://git.kernel.dk/linux-block:
  genhd: fix leftover might_sleep() in blk_free_devt()
  blk-mq: use blk_mq_start_hw_queues() when running requeue work
  blk-mq: fix potential oops on out-of-memory in __blk_mq_alloc_rq_maps()
  blk-mq: avoid infinite recursion with the FUA flag
  blk-mq: Avoid race condition with uninitialized requests
  blk-mq: request deadline must be visible before marking rq as started
diff --git a/block/blk-exec.c b/block/blk-exec.c
index f4d27b1..9924725 100644
--- a/block/blk-exec.c
+++ b/block/blk-exec.c
@@ -56,6 +56,7 @@
 	bool is_pm_resume;
 
 	WARN_ON(irqs_disabled());
+	WARN_ON(rq->cmd_type == REQ_TYPE_FS);
 
 	rq->rq_disk = bd_disk;
 	rq->end_io = done;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 383ea0c..c88e608 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -203,7 +203,6 @@
 	if (tag != BLK_MQ_TAG_FAIL) {
 		rq = data->hctx->tags->rqs[tag];
 
-		rq->cmd_flags = 0;
 		if (blk_mq_tag_busy(data->hctx)) {
 			rq->cmd_flags = REQ_MQ_INFLIGHT;
 			atomic_inc(&data->hctx->nr_active);
@@ -258,6 +257,7 @@
 
 	if (rq->cmd_flags & REQ_MQ_INFLIGHT)
 		atomic_dec(&hctx->nr_active);
+	rq->cmd_flags = 0;
 
 	clear_bit(REQ_ATOM_STARTED, &rq->atomic_flags);
 	blk_mq_put_tag(hctx, tag, &ctx->last_tag);
@@ -393,6 +393,12 @@
 	blk_add_timer(rq);
 
 	/*
+	 * Ensure that ->deadline is visible before set the started
+	 * flag and clear the completed flag.
+	 */
+	smp_mb__before_atomic();
+
+	/*
 	 * Mark us as started and clear complete. Complete might have been
 	 * set if requeue raced with timeout, which then marked it as
 	 * complete. So be sure to clear complete again when we start
@@ -473,7 +479,11 @@
 		blk_mq_insert_request(rq, false, false, false);
 	}
 
-	blk_mq_run_queues(q, false);
+	/*
+	 * Use the start variant of queue running here, so that running
+	 * the requeue work will kick stopped queues.
+	 */
+	blk_mq_start_hw_queues(q);
 }
 
 void blk_mq_add_to_requeue_list(struct request *rq, bool at_head)
@@ -957,14 +967,9 @@
 
 	hctx = q->mq_ops->map_queue(q, ctx->cpu);
 
-	if (rq->cmd_flags & (REQ_FLUSH | REQ_FUA) &&
-	    !(rq->cmd_flags & (REQ_FLUSH_SEQ))) {
-		blk_insert_flush(rq);
-	} else {
-		spin_lock(&ctx->lock);
-		__blk_mq_insert_request(hctx, rq, at_head);
-		spin_unlock(&ctx->lock);
-	}
+	spin_lock(&ctx->lock);
+	__blk_mq_insert_request(hctx, rq, at_head);
+	spin_unlock(&ctx->lock);
 
 	if (run_queue)
 		blk_mq_run_hw_queue(hctx, async);
@@ -1404,6 +1409,8 @@
 		left -= to_do * rq_size;
 		for (j = 0; j < to_do; j++) {
 			tags->rqs[i] = p;
+			tags->rqs[i]->atomic_flags = 0;
+			tags->rqs[i]->cmd_flags = 0;
 			if (set->ops->init_request) {
 				if (set->ops->init_request(set->driver_data,
 						tags->rqs[i], hctx_idx, i,
@@ -1956,7 +1963,6 @@
 	while (--i >= 0)
 		blk_mq_free_rq_map(set, set->tags[i], i);
 
-	set->tags = NULL;
 	return -ENOMEM;
 }
 
diff --git a/block/genhd.c b/block/genhd.c
index 09da5e4..e6723bd 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -445,8 +445,6 @@
  */
 void blk_free_devt(dev_t devt)
 {
-	might_sleep();
-
 	if (devt == MKDEV(0, 0))
 		return;