* Patch "blk-mq: fix race between updating nr_hw_queues and switching io sched" has been added to the 4.15-stable tree
@ 2018-04-09 9:36 gregkh
0 siblings, 0 replies; only message in thread
From: gregkh @ 2018-04-09 9:36 UTC (permalink / raw)
To: ming.lei, alexander.levin, axboe, gregkh, hch, yi.zhang
Cc: stable, stable-commits
This is a note to let you know that I've just added the patch titled
blk-mq: fix race between updating nr_hw_queues and switching io sched
to the 4.15-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
blk-mq-fix-race-between-updating-nr_hw_queues-and-switching-io-sched.patch
and it can be found in the queue-4.15 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.
>From foo@baz Mon Apr 9 10:16:32 CEST 2018
From: Ming Lei <ming.lei@redhat.com>
Date: Sat, 6 Jan 2018 16:27:40 +0800
Subject: blk-mq: fix race between updating nr_hw_queues and switching io sched
From: Ming Lei <ming.lei@redhat.com>
[ Upstream commit fb350e0ad99359768e1e80b4784692031ec340e4 ]
In both elevator_switch_mq() and blk_mq_update_nr_hw_queues(), sched tags
can be allocated, and q->nr_hw_queue is used, and race is inevitable, for
example: blk_mq_init_sched() may trigger use-after-free on hctx, which is
freed in blk_mq_realloc_hw_ctxs() when nr_hw_queues is decreased.
This patch fixes the race be holding q->sysfs_lock.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Tested-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
block/blk-mq.c | 4 ++++
1 file changed, 4 insertions(+)
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2388,6 +2388,9 @@ static void blk_mq_realloc_hw_ctxs(struc
struct blk_mq_hw_ctx **hctxs = q->queue_hw_ctx;
blk_mq_sysfs_unregister(q);
+
+ /* protect against switching io scheduler */
+ mutex_lock(&q->sysfs_lock);
for (i = 0; i < set->nr_hw_queues; i++) {
int node;
@@ -2432,6 +2435,7 @@ static void blk_mq_realloc_hw_ctxs(struc
}
}
q->nr_hw_queues = i;
+ mutex_unlock(&q->sysfs_lock);
blk_mq_sysfs_register(q);
}
Patches currently in stable-queue which might be from ming.lei@redhat.com are
queue-4.15/blk-mq-avoid-to-map-cpu-into-stale-hw-queue.patch
queue-4.15/blk-mq-fix-kernel-oops-in-blk_mq_tag_idle.patch
queue-4.15/blk-mq-fix-race-between-updating-nr_hw_queues-and-switching-io-sched.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-04-09 9:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-09 9:36 Patch "blk-mq: fix race between updating nr_hw_queues and switching io sched" has been added to the 4.15-stable tree gregkh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).