blk-mq: use queisced elevator switch
PATCH 1/1 blk-mq: use queisced elevator switch
From: Keith Busch <[email protected]>
The hctx's work may be racing with the elevator switch that occurs when reinitializing hardware queues. This happens because the queue is merely frozen in this context, but that only prevents requests from allocating and doesn't stop the hctx work from running. When swapping the io scheduler, this leaves a race condition open where the work may get a pointer to an elevator that's being torn down. Use the quiesced elevator switch instead.
--- block/blk-mq.c | 6 +++--- block/blk.h | 3 +-- block/elevator.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-)
block/blk-mq.c +3 -3
@@ -4470,14 +4470,14 @@ static bool blk_mq_elv_switch_none(struct list_head *head,list_add (&qe->node, head);/* -* After elevator_switch_mq, the previous elevator_queue will be +* After elevator_switch, the previous elevator_queue will be * released by elevator_release. The reference of the io scheduler * module get by elevator_get will also be put. So we need to get * a reference of the io scheduler module here to prevent it to be * removed. */ __module_get (qe->type->elevator_owner); -elevator_switch_mq (q,NULL ); +elevator_switch (q,NULL );mutex_unlock (&q->sysfs_lock);return true;
@@ -4509,7 +4509,7 @@ static void blk_mq_elv_switch_back(struct list_head *head,kfree (qe);mutex_lock (&q->sysfs_lock); -elevator_switch_mq (q, t); +elevator_switch (q, t);mutex_unlock (&q->sysfs_lock); }
block/blk.h +1 -2
@@ -270,8 +270,7 @@ bool blk_bio_list_merge(struct request_queue *q, struct list_head *list,void blk_insert_flush (struct request *rq); -int elevator_switch_mq (struct request_queue *q, -struct elevator_type *new_e); +int elevator_switch (struct request_queue *q,struct elevator_type *new_e);void elevator_exit (struct request_queue *q);int elv_register_queue (struct request_queue *q,bool uevent);void elv_unregister_queue (struct request_queue *q);
block/elevator.c +2 -2
@@ -588,7 +588,7 @@ void elv_unregister(struct elevator_type *e) }EXPORT_SYMBOL_GPL (elv_unregister); -int elevator_switch_mq (struct request_queue *q, +static int elevator_switch_mq (struct request_queue *q,struct elevator_type *new_e) {int ret;
@@ -723,7 +723,7 @@ void elevator_init_mq(struct request_queue *q)* need for the new one. this way we have a chance of going back to the old * one, if the new one fails init for some reason. */ -static int elevator_switch (struct request_queue *q,struct elevator_type *new_e) +int elevator_switch (struct request_queue *q,struct elevator_type *new_e) {int err;
Signature · 1 line
2.30.2
Looks good, although the subject has a spelling error and would benefit from ammend where the quiesced switch is used, e.g.
blk-mq: use quiesced elevator switch when updating number of queues
Quoted 11 lines · Keith Busch
From: Keith Busch <[email protected]>
The hctx's work may be racing with the elevator switch that occurs when reinitializing hardware queues. This happens because the queue is merely frozen in this context, but that only prevents requests from allocating and doesn't stop the hctx work from running. When swapping the io scheduler, this leaves a race condition open where the work may get a pointer to an elevator that's being torn down. Use the quiesced elevator switch instead.
Quoted 1 line
Signed-off-by Keith Busch <[email protected]>
This patch should fix one kernel panic when running stress test(elevator switch vs
nvme pci reset/scan).