* [PATCH] blk-mq: move cancel of requeue_work to the front of blk_exit_queue
@ 2019-08-12 12:36 zhengbin
2019-08-12 13:00 ` Ming Lei
2019-08-12 14:14 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: zhengbin @ 2019-08-12 12:36 UTC (permalink / raw)
To: axboe, bvanassche, jejb, martin.petersen, ming.lei, linux-block
Cc: houtao1, zhengbin13
blk_exit_queue will free elevator_data, while blk_mq_requeue_work
will access it. Move cancel of requeue_work to the front of
blk_exit_queue to avoid use-after-free.
blk_exit_queue blk_mq_requeue_work
__elevator_exit blk_mq_run_hw_queues
blk_mq_exit_sched blk_mq_run_hw_queue
dd_exit_queue blk_mq_hctx_has_pending
kfree(elevator_data) blk_mq_sched_has_work
dd_has_work
Fixes: fbc2a15e3433 ("blk-mq: move cancel of requeue_work into blk_mq_release")
Signed-off-by: zhengbin <zhengbin13@huawei.com>
---
block/blk-mq.c | 2 --
block/blk-sysfs.c | 3 +++
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index f78d328..a8e6a58 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2666,8 +2666,6 @@ void blk_mq_release(struct request_queue *q)
struct blk_mq_hw_ctx *hctx, *next;
int i;
- cancel_delayed_work_sync(&q->requeue_work);
-
queue_for_each_hw_ctx(q, hctx, i)
WARN_ON_ONCE(hctx && list_empty(&hctx->hctx_list));
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 977c659..9bfa3ea 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -892,6 +892,9 @@ static void __blk_release_queue(struct work_struct *work)
blk_free_queue_stats(q->stats);
+ if (queue_is_mq(q))
+ cancel_delayed_work_sync(&q->requeue_work);
+
blk_exit_queue(q);
blk_queue_free_zone_bitmaps(q);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] blk-mq: move cancel of requeue_work to the front of blk_exit_queue
2019-08-12 12:36 [PATCH] blk-mq: move cancel of requeue_work to the front of blk_exit_queue zhengbin
@ 2019-08-12 13:00 ` Ming Lei
2019-08-12 14:14 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2019-08-12 13:00 UTC (permalink / raw)
To: zhengbin; +Cc: axboe, bvanassche, jejb, martin.petersen, linux-block, houtao1
On Mon, Aug 12, 2019 at 08:36:55PM +0800, zhengbin wrote:
> blk_exit_queue will free elevator_data, while blk_mq_requeue_work
> will access it. Move cancel of requeue_work to the front of
> blk_exit_queue to avoid use-after-free.
>
> blk_exit_queue blk_mq_requeue_work
> __elevator_exit blk_mq_run_hw_queues
> blk_mq_exit_sched blk_mq_run_hw_queue
> dd_exit_queue blk_mq_hctx_has_pending
> kfree(elevator_data) blk_mq_sched_has_work
> dd_has_work
>
> Fixes: fbc2a15e3433 ("blk-mq: move cancel of requeue_work into blk_mq_release")
> Signed-off-by: zhengbin <zhengbin13@huawei.com>
> ---
> block/blk-mq.c | 2 --
> block/blk-sysfs.c | 3 +++
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index f78d328..a8e6a58 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -2666,8 +2666,6 @@ void blk_mq_release(struct request_queue *q)
> struct blk_mq_hw_ctx *hctx, *next;
> int i;
>
> - cancel_delayed_work_sync(&q->requeue_work);
> -
> queue_for_each_hw_ctx(q, hctx, i)
> WARN_ON_ONCE(hctx && list_empty(&hctx->hctx_list));
>
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index 977c659..9bfa3ea 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -892,6 +892,9 @@ static void __blk_release_queue(struct work_struct *work)
>
> blk_free_queue_stats(q->stats);
>
> + if (queue_is_mq(q))
> + cancel_delayed_work_sync(&q->requeue_work);
> +
> blk_exit_queue(q);
>
> blk_queue_free_zone_bitmaps(q);
Looks fine:
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Thanks,
Ming
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] blk-mq: move cancel of requeue_work to the front of blk_exit_queue
2019-08-12 12:36 [PATCH] blk-mq: move cancel of requeue_work to the front of blk_exit_queue zhengbin
2019-08-12 13:00 ` Ming Lei
@ 2019-08-12 14:14 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2019-08-12 14:14 UTC (permalink / raw)
To: zhengbin, bvanassche, jejb, martin.petersen, ming.lei, linux-block
Cc: houtao1
On 8/12/19 5:36 AM, zhengbin wrote:
> blk_exit_queue will free elevator_data, while blk_mq_requeue_work
> will access it. Move cancel of requeue_work to the front of
> blk_exit_queue to avoid use-after-free.
>
> blk_exit_queue blk_mq_requeue_work
> __elevator_exit blk_mq_run_hw_queues
> blk_mq_exit_sched blk_mq_run_hw_queue
> dd_exit_queue blk_mq_hctx_has_pending
> kfree(elevator_data) blk_mq_sched_has_work
> dd_has_work
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-12 14:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 12:36 [PATCH] blk-mq: move cancel of requeue_work to the front of blk_exit_queue zhengbin
2019-08-12 13:00 ` Ming Lei
2019-08-12 14:14 ` Jens Axboe
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).