* dispatch may still be in-progress since we dispatch requests
         * from more than one contexts.
         *
-        * No need to quiesce queue if it isn't initialized yet since
-        * blk_freeze_queue() should be enough for cases of passthrough
-        * request.
+        * We rely on driver to deal with the race in case that queue
+        * initialization isn't done.
         */
 -      if (q->mq_ops && blk_queue_init_done(q))
 +      if (queue_is_mq(q) && blk_queue_init_done(q))
                blk_mq_quiesce_queue(q);
  
        /* for synchronous bio-based driver finish in-flight integrity i/o */
 
                q->last_merge = NULL;
  }
  
 -/*
 - * Steal a bit from this field for legacy IO path atomic IO marking. Note that
 - * setting the deadline clears the bottom bit, potentially clearing the
 - * completed bit. The user has to be OK with this (current ones are fine).
 - */
 -static inline void blk_rq_set_deadline(struct request *rq, unsigned long time)
 -{
 -      rq->__deadline = time & ~0x1UL;
 -}
 -
 -static inline unsigned long blk_rq_deadline(struct request *rq)
 -{
 -      return rq->__deadline & ~0x1UL;
 -}
 -
+ /*
+  * The max size one bio can handle is UINT_MAX becasue bvec_iter.bi_size
+  * is defined as 'unsigned int', meantime it has to aligned to with logical
+  * block size which is the minimum accepted unit by hardware.
+  */
+ static inline unsigned int bio_allowed_max_sectors(struct request_queue *q)
+ {
+       return round_down(UINT_MAX, queue_logical_block_size(q)) >> 9;
+ }
+ 
  /*
   * Internal io_context interface
   */
 
                destroy_rcu_head(&cmd->rcu);
        }
  
 -      if (req->mq_ctx) {
 -              /*
 -               * In the MQ case the command gets freed by __blk_mq_end_request,
 -               * so we have to do all cleanup that depends on it earlier.
 -               *
 -               * We also can't kick the queues from irq context, so we
 -               * will have to defer it to a workqueue.
 -               */
 -              scsi_mq_uninit_cmd(cmd);
 -
 -              /*
 -               * queue is still alive, so grab the ref for preventing it
 -               * from being cleaned up during running queue.
 -               */
 -              percpu_ref_get(&q->q_usage_counter);
 -
 -              __blk_mq_end_request(req, error);
 -
 -              if (scsi_target(sdev)->single_lun ||
 -                  !list_empty(&sdev->host->starved_list))
 -                      kblockd_schedule_work(&sdev->requeue_work);
 -              else
 -                      blk_mq_run_hw_queues(q, true);
 -
 -              percpu_ref_put(&q->q_usage_counter);
 -      } else {
 -              unsigned long flags;
 +      /*
 +       * In the MQ case the command gets freed by __blk_mq_end_request,
 +       * so we have to do all cleanup that depends on it earlier.
 +       *
 +       * We also can't kick the queues from irq context, so we
 +       * will have to defer it to a workqueue.
 +       */
 +      scsi_mq_uninit_cmd(cmd);
  
 -              if (bidi_bytes)
 -                      scsi_release_bidi_buffers(cmd);
 -              scsi_release_buffers(cmd);
 -              scsi_put_command(cmd);
++      /*
++       * queue is still alive, so grab the ref for preventing it
++       * from being cleaned up during running queue.
++       */
++      percpu_ref_get(&q->q_usage_counter);
+ 
 -              spin_lock_irqsave(q->queue_lock, flags);
 -              blk_finish_request(req, error);
 -              spin_unlock_irqrestore(q->queue_lock, flags);
 +      __blk_mq_end_request(req, error);
  
 -              scsi_run_queue(q);
 -      }
 +      if (scsi_target(sdev)->single_lun ||
 +          !list_empty(&sdev->host->starved_list))
 +              kblockd_schedule_work(&sdev->requeue_work);
 +      else
 +              blk_mq_run_hw_queues(q, true);
  
++      percpu_ref_put(&q->q_usage_counter);
        put_device(&sdev->sdev_gendev);
        return false;
  }