From: Joseph Qi <jiangqi903@gmail.com>
To: Bart Van Assche <bart.vanassche@wdc.com>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Joseph Qi <joseph.qi@linux.alibaba.com>,
Philipp Reisner <philipp.reisner@linbit.com>,
Ulf Hansson <ulf.hansson@linaro.org>,
Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH v4 5/6] block: Fix a race between the cgroup code and request queue initialization
Date: Fri, 23 Feb 2018 17:52:23 +0800 [thread overview]
Message-ID: <33eefa94-b0fc-9ac4-6b16-39c3ad8fc293@gmail.com> (raw)
In-Reply-To: <20180223010808.25765-6-bart.vanassche@wdc.com>
On 18/2/23 09:08, Bart Van Assche wrote:
> Initialize the request queue lock earlier such that the following
> race can no longer occur:
>
> blk_init_queue_node() blkcg_print_blkgs()
> blk_alloc_queue_node (1)
> q->queue_lock = &q->__queue_lock (2)
> blkcg_init_queue(q) (3)
> spin_lock_irq(blkg->q->queue_lock) (4)
> q->queue_lock = lock (5)
> spin_unlock_irq(blkg->q->queue_lock) (6)
>
> (1) allocate an uninitialized queue;
> (2) initialize queue_lock to its default internal lock;
> (3) initialize blkcg part of request queue, which will create blkg and
> then insert it to blkg_list;
> (4) traverse blkg_list and find the created blkg, and then take its
> queue lock, here it is the default *internal lock*;
> (5) *race window*, now queue_lock is overridden with *driver specified
> lock*;
> (6) now unlock *driver specified lock*, not the locked *internal lock*,
> unlock balance breaks.
>
> The changes in this patch are as follows:
> - Move the .queue_lock initialization from blk_init_queue_node() into
> blk_alloc_queue_node().
> - Only override the .queue_lock pointer for legacy queues because it
> is not useful for blk-mq queues to override this pointer.
> - For all all block drivers that initialize .queue_lock explicitly,
> change the blk_alloc_queue() call in the driver into a
> blk_alloc_queue_node() call and remove the explicit .queue_lock
> initialization. Additionally, initialize the spin lock that will
> be used as queue lock earlier if necessary.
>
> Reported-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Joseph Qi <joseph.qi@linux.alibaba.com>
> Cc: Philipp Reisner <philipp.reisner@linbit.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Kees Cook <keescook@chromium.org>
Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
next prev parent reply other threads:[~2018-02-23 9:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-23 1:08 [PATCH v4 0/6] Fix races between blkcg code and request queue initialization and cleanup Bart Van Assche
2018-02-23 1:08 ` [PATCH v4 1/6] block/loop: Delete gendisk before cleaning up the request queue Bart Van Assche
2018-02-23 8:22 ` Johannes Thumshirn
2018-02-23 9:49 ` Joseph Qi
2018-02-23 1:08 ` [PATCH v4 2/6] md: " Bart Van Assche
2018-02-23 8:22 ` Johannes Thumshirn
2018-02-23 9:50 ` Joseph Qi
2018-02-23 1:08 ` [PATCH v4 3/6] zram: " Bart Van Assche
2018-02-23 8:23 ` Johannes Thumshirn
2018-02-23 9:51 ` Joseph Qi
2018-02-23 1:08 ` [PATCH v4 4/6] block: Add a third argument to blk_alloc_queue_node() Bart Van Assche
2018-02-23 8:26 ` Johannes Thumshirn
2018-02-23 16:07 ` Bart Van Assche
2018-02-23 9:48 ` Joseph Qi
2018-02-23 1:08 ` [PATCH v4 5/6] block: Fix a race between the cgroup code and request queue initialization Bart Van Assche
2018-02-23 9:52 ` Joseph Qi [this message]
2018-02-23 1:08 ` [PATCH v4 6/6] block: Fix a race between request queue removal and the block cgroup controller Bart Van Assche
2018-02-23 9:54 ` Joseph Qi
2018-02-24 12:44 ` [PATCH v4 0/6] Fix races between blkcg code and request queue initialization and cleanup Ming Lei
2018-02-27 23:37 ` Bart Van Assche
2018-02-27 23:37 ` Bart Van Assche
2018-02-28 15:33 ` Jens Axboe
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=33eefa94-b0fc-9ac4-6b16-39c3ad8fc293@gmail.com \
--to=jiangqi903@gmail.com \
--cc=axboe@kernel.dk \
--cc=bart.vanassche@wdc.com \
--cc=hch@lst.de \
--cc=joseph.qi@linux.alibaba.com \
--cc=keescook@chromium.org \
--cc=linux-block@vger.kernel.org \
--cc=philipp.reisner@linbit.com \
--cc=ulf.hansson@linaro.org \
/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