[RAMEN9610-21380]USB: core: Fix races in character device registration and deregistraion
[GitHub/MotorolaMobilityLLC/kernel-slsi.git] / block / bfq-iosched.c
index a4783da90ba882f29ac1159b67dc1b24296ead5b..3b44bd28fc4521e40c787c5bd7957443fcb506c5 100644 (file)
 #include "blk-mq-tag.h"
 #include "blk-mq-sched.h"
 #include "bfq-iosched.h"
+#include "blk-wbt.h"
 
 #define BFQ_BFQQ_FNS(name)                                             \
 void bfq_mark_bfqq_##name(struct bfq_queue *bfqq)                      \
@@ -1202,6 +1203,24 @@ static unsigned int bfq_wr_duration(struct bfq_data *bfqd)
        return dur;
 }
 
+/*
+ * Return the farthest future time instant according to jiffies
+ * macros.
+ */
+static unsigned long bfq_greatest_from_now(void)
+{
+       return jiffies + MAX_JIFFY_OFFSET;
+}
+
+/*
+ * Return the farthest past time instant according to jiffies
+ * macros.
+ */
+static unsigned long bfq_smallest_from_now(void)
+{
+       return jiffies - MAX_JIFFY_OFFSET;
+}
+
 static void bfq_update_bfqq_wr_on_rq_arrival(struct bfq_data *bfqd,
                                             struct bfq_queue *bfqq,
                                             unsigned int old_wr_coeff,
@@ -1216,7 +1235,19 @@ static void bfq_update_bfqq_wr_on_rq_arrival(struct bfq_data *bfqd,
                        bfqq->wr_coeff = bfqd->bfq_wr_coeff;
                        bfqq->wr_cur_max_time = bfq_wr_duration(bfqd);
                } else {
-                       bfqq->wr_start_at_switch_to_srt = jiffies;
+                       /*
+                        * No interactive weight raising in progress
+                        * here: assign minus infinity to
+                        * wr_start_at_switch_to_srt, to make sure
+                        * that, at the end of the soft-real-time
+                        * weight raising periods that is starting
+                        * now, no interactive weight-raising period
+                        * may be wrongly considered as still in
+                        * progress (and thus actually started by
+                        * mistake).
+                        */
+                       bfqq->wr_start_at_switch_to_srt =
+                               bfq_smallest_from_now();
                        bfqq->wr_coeff = bfqd->bfq_wr_coeff *
                                BFQ_SOFTRT_WEIGHT_FACTOR;
                        bfqq->wr_cur_max_time =
@@ -1677,7 +1708,6 @@ static void bfq_requests_merged(struct request_queue *q, struct request *rq,
 
        if (!RB_EMPTY_NODE(&rq->rb_node))
                goto end;
-       spin_lock_irq(&bfqq->bfqd->lock);
 
        /*
         * If next and rq belong to the same bfq_queue and next is older
@@ -1701,7 +1731,6 @@ static void bfq_requests_merged(struct request_queue *q, struct request *rq,
 
        bfq_remove_request(q, next);
 
-       spin_unlock_irq(&bfqq->bfqd->lock);
 end:
        bfqg_stats_update_io_merged(bfqq_group(bfqq), next->cmd_flags);
 }
@@ -2897,24 +2926,6 @@ static unsigned long bfq_bfqq_softrt_next_start(struct bfq_data *bfqd,
                   jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4);
 }
 
-/*
- * Return the farthest future time instant according to jiffies
- * macros.
- */
-static unsigned long bfq_greatest_from_now(void)
-{
-       return jiffies + MAX_JIFFY_OFFSET;
-}
-
-/*
- * Return the farthest past time instant according to jiffies
- * macros.
- */
-static unsigned long bfq_smallest_from_now(void)
-{
-       return jiffies - MAX_JIFFY_OFFSET;
-}
-
 /**
  * bfq_bfqq_expire - expire a queue.
  * @bfqd: device owning the queue.
@@ -4446,8 +4457,16 @@ static void bfq_prepare_request(struct request *rq, struct bio *bio)
        bool new_queue = false;
        bool bfqq_already_existing = false, split = false;
 
-       if (!rq->elv.icq)
+       /*
+        * Even if we don't have an icq attached, we should still clear
+        * the scheduler pointers, as they might point to previously
+        * allocated bic/bfqq structs.
+        */
+       if (!rq->elv.icq) {
+               rq->elv.priv[0] = rq->elv.priv[1] = NULL;
                return;
+       }
+
        bic = icq_to_bic(rq->elv.icq);
 
        spin_lock_irq(&bfqd->lock);
@@ -4775,7 +4794,7 @@ static int bfq_init_queue(struct request_queue *q, struct elevator_type *e)
        bfq_init_root_group(bfqd->root_group, bfqd);
        bfq_init_entity(&bfqd->oom_bfqq.entity, bfqd->root_group);
 
-
+       wbt_disable_default(q);
        return 0;
 
 out_free: