block: don't hold q->sysfs_lock in elevator_init_mq
authorMing Lei <ming.lei@redhat.com>
Tue, 27 Aug 2019 11:01:45 +0000 (19:01 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 27 Aug 2019 16:40:20 +0000 (10:40 -0600)
The original comment says:

q->sysfs_lock must be held to provide mutual exclusion between
elevator_switch() and here.

Which is simply wrong. elevator_init_mq() is only called from
blk_mq_init_allocated_queue, which is always called before the request
queue is registered via blk_register_queue(), for dm-rq or normal rq
based driver. However, queue's kobject is only exposed and added to sysfs
in blk_register_queue(). So there isn't such race between elevator_switch()
and elevator_init_mq().

So avoid to hold q->sysfs_lock in elevator_init_mq().

Cc: Christoph Hellwig <hch@infradead.org>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Mike Snitzer <snitzer@redhat.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/elevator.c

index 2f17d66d0e617e31b9b8dfb76899b2a0dbc5f8aa..33c15fb54ed1ecaa95130075684e991c67b7b066 100644 (file)
@@ -607,23 +607,19 @@ int elevator_init_mq(struct request_queue *q)
        if (q->nr_hw_queues != 1)
                return 0;
 
-       /*
-        * q->sysfs_lock must be held to provide mutual exclusion between
-        * elevator_switch() and here.
-        */
-       mutex_lock(&q->sysfs_lock);
+       WARN_ON_ONCE(test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags));
+
        if (unlikely(q->elevator))
-               goto out_unlock;
+               goto out;
 
        e = elevator_get(q, "mq-deadline", false);
        if (!e)
-               goto out_unlock;
+               goto out;
 
        err = blk_mq_init_sched(q, e);
        if (err)
                elevator_put(e);
-out_unlock:
-       mutex_unlock(&q->sysfs_lock);
+out:
        return err;
 }