From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Ming Lei <ming.lei@redhat.com>,
Christoph Hellwig <hch@infradead.org>,
Hannes Reinecke <hare@suse.com>,
Greg KH <gregkh@linuxfoundation.org>,
Mike Snitzer <snitzer@redhat.com>,
Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH V2 2/6] block: don't hold q->sysfs_lock in elevator_init_mq
Date: Wed, 21 Aug 2019 17:15:02 +0800 [thread overview]
Message-ID: <20190821091506.21196-3-ming.lei@redhat.com> (raw)
In-Reply-To: <20190821091506.21196-1-ming.lei@redhat.com>
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 just exposed 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>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/elevator.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/block/elevator.c b/block/elevator.c
index 2f17d66d0e61..37b918dc4676 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -608,22 +608,22 @@ int elevator_init_mq(struct request_queue *q)
return 0;
/*
- * q->sysfs_lock must be held to provide mutual exclusion between
- * elevator_switch() and here.
+ * We are called from blk_mq_init_allocated_queue() only, at that
+ * time the request queue isn't registered yet, so the queue
+ * kobject isn't exposed to userspace. No need to worry about race
+ * with elevator_switch(), and no need to hold q->sysfs_lock.
*/
- mutex_lock(&q->sysfs_lock);
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;
}
--
2.20.1
next prev parent reply other threads:[~2019-08-21 9:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-21 9:15 [PATCH V2 0/6] block: don't acquire .sysfs_lock before removing mq & iosched kobjects Ming Lei
2019-08-21 9:15 ` [PATCH V2 1/6] block: Remove blk_mq_register_dev() Ming Lei
2019-08-21 9:15 ` Ming Lei [this message]
2019-08-21 15:51 ` [PATCH V2 2/6] block: don't hold q->sysfs_lock in elevator_init_mq Bart Van Assche
2019-08-21 9:15 ` [PATCH V2 3/6] blk-mq: don't hold q->sysfs_lock in blk_mq_map_swqueue Ming Lei
2019-08-21 15:53 ` Bart Van Assche
2019-08-26 2:11 ` Ming Lei
2019-08-21 9:15 ` [PATCH V2 4/6] blk-mq: don't hold q->sysfs_lock in blk_mq_realloc_hw_ctxs() Ming Lei
2019-08-21 15:56 ` Bart Van Assche
2019-08-26 2:25 ` Ming Lei
2019-08-21 9:15 ` [PATCH V2 5/6] block: add helper for checking if queue is registered Ming Lei
2019-08-21 15:57 ` Bart Van Assche
2019-08-21 9:15 ` [PATCH V2 6/6] block: split .sysfs_lock into two locks Ming Lei
2019-08-21 16:18 ` Bart Van Assche
2019-08-22 1:28 ` Ming Lei
2019-08-22 19:52 ` Bart Van Assche
2019-08-23 1:08 ` Ming Lei
2019-08-23 16:36 ` Bart Van Assche
2019-08-23 16:46 ` Bart Van Assche
2019-08-23 22:49 ` Ming Lei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190821091506.21196-3-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=gregkh@linuxfoundation.org \
--cc=hare@suse.com \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=snitzer@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox