Re: [PATCH 2/4] blk-mq: fix q->mq_map access race

From: Ming Lei
Date: Wed Jun 24 2015 - 05:23:56 EST


On Sun, Jun 21, 2015 at 9:52 PM, Akinobu Mita <akinobu.mita@xxxxxxxxx> wrote:
> CPU hotplug handling for blk-mq (blk_mq_queue_reinit) updates q->mq_map
> by blk_mq_update_queue_map() for all request queues in all_q_list.
> On the other hand, q->mq_map is released and set to NULL before
> deleting the queue from all_q_list.
>
> So if cpu hotplug event occurs in the window, invalid memory access
> can happen. Fix it by deleting the queue from all_q_list earlier
> than destroyng q->mq_map.

It should be better to free q->mq_map in blk_mq_release(), because
now blk_cleanup_queue() can be run before del_gendisk(), such as
loop and md.

>
> Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>
> Cc: Jens Axboe <axboe@xxxxxxxxx>
> ---
> block/blk-mq.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index ec94258..6487710 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -2038,6 +2038,10 @@ void blk_mq_free_queue(struct request_queue *q)
> {
> struct blk_mq_tag_set *set = q->tag_set;
>
> + mutex_lock(&all_q_mutex);
> + list_del_init(&q->all_q_node);
> + mutex_unlock(&all_q_mutex);

As commented for patch 1, the above can be moved to
blk_mq_unregister_disk() for fixing the issue of patch 1.

> +
> blk_mq_del_queue_tag_set(q);
>
> blk_mq_exit_hw_queues(q, set, set->nr_hw_queues);
> @@ -2048,10 +2052,6 @@ void blk_mq_free_queue(struct request_queue *q)
> kfree(q->mq_map);
>
> q->mq_map = NULL;
> -
> - mutex_lock(&all_q_mutex);
> - list_del_init(&q->all_q_node);
> - mutex_unlock(&all_q_mutex);
> }
>
> /* Basically redo blk_mq_init_queue with queue frozen */
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> Please read the FAQ at http://www.tux.org/lkml/



--
Ming Lei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/