block: mq-deadline: check if elevator is attached to queue in dd_finish_request
PATCH 1/1 block: mq-deadline: check if elevator is attached to queue in dd_finish_request
in dd_finish_request(), per_prio points to a rq->elv.priv[0], which could be free memory if an in-flight requests completes after its associated scheduler has been freed
--- block/mq-deadline.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
block/mq-deadline.c +9 -7
@@ -751,13 +751,15 @@ static void dd_finish_request(struct request *rq) {struct dd_per_prio *per_prio = rq->elv.priv[0 ]; -/* -* The block layer core may call dd_finish_request() without having -* called dd_insert_requests(). Skip requests that bypassed I/O -* scheduling. See also blk_mq_request_bypass_insert(). -*/ -if (per_prio) -atomic_inc (&per_prio->stats.completed); +if (rq->q->elevator) { +/* +* The block layer core may call dd_finish_request() without having +* called dd_insert_requests(). Skip requests that bypassed I/O +* scheduling. See also blk_mq_request_bypass_insert(). +*/ +if (per_prio) +atomic_inc (&per_prio->stats.completed); + } }static bool dd_has_work_for_prio (struct dd_per_prio *per_prio)
Signature · 1 line
2.43.0
Quoted 24 lines · Elijah Wright
in
dd_finish_request(),per_priopoints to a rq->elv.priv[0], which could be free memory if an in-flight requests completes after its associated scheduler has been freedSigned-off-by Elijah Wright <[email protected]>--- block/mq-deadline.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)block/mq-deadline.c +0
-7@@ -751,13 +751,15 @@ static void dd_finish_request(struct request *rq) {struct dd_per_prio *per_prio = rq->elv.priv[0 ]; -/* -* The block layer core may call dd_finish_request() without having -* called dd_insert_requests(). Skip requests that bypassed I/O -* scheduling. See also blk_mq_request_bypass_insert(). -*/ -if (per_prio) -atomic_inc (&per_prio->stats.completed);
block/mq-deadline.c static void dd_finish_request(struct request *rq) · line 763
Quoted 10 lines
block/mq-deadline.c +9
-0+if (rq->q->elevator) { +/* +* The block layer core may call dd_finish_request() without having +* called dd_insert_requests(). Skip requests that bypassed I/O +* scheduling. See also blk_mq_request_bypass_insert(). +*/ +if (per_prio) +atomic_inc (&per_prio->stats.completed); + } }
The warnings in dd_exit_sched() will be triggered if dd_finish_request() is ever called with rq->q->elevator == NULL.
If this can happen, it should be fixed in the block layer core instead of in the mq-deadline scheduler.
Thanks,
Bart.
I see. would it be possible to detach the elevator from the queue in elevator_exit instead?
Quoted 45 lines · Bart Van Assche
Quoted 26 lines · Elijah Wright
in
dd_finish_request(),per_priopoints to a rq->elv.priv[0], which could be free memory if an in-flight requests completes after its associated scheduler has been freedSigned-off-by Elijah Wright <[email protected]>---
block/mq-deadline.c| 16 +++++++++-------1 file changed, 9 insertions(+), 7 deletions(-)block/mq-deadline.c +3
-7@@ -751,13 +751,15 @@ static void dd_finish_request(struct request *rq) { struct dd_per_prio *per_prio = rq->elv.priv[0]; - /* - * The block layer core may call dd_finish_request() without having - * called dd_insert_requests(). Skip requests that bypassed I/O - * scheduling. See also blk_mq_request_bypass_insert(). - */ - if (per_prio) - atomic_inc(&per_prio->stats.completed); + if (rq->q->elevator) { + /* +* The block layer core may call dd_finish_request() without Quoted 8 lines
having
+ * calleddd_insert_requests(). Skip requests that bypassed I/O + * scheduling. See alsoblk_mq_request_bypass_insert(). + */
+ if (per_prio)
+atomic_inc(&per_prio->stats.completed);
+ }
}The warnings in
dd_exit_sched()will be triggered ifdd_finish_request()is ever called withrq->q->elevator== NULL.If this can happen, it should be fixed in the block layer core instead of in the mq-deadline scheduler.
Thanks,
Bart.
Quoted 1 line · Elijah Wright
I see. would it be possible to detach the elevator from the queue in
elevator_exitinstead?
elevator_switch() is called with the request queue frozen. q_usage_counter is dropped after the blk_mq_finish_request() call returned. So what you described in your patch description can't happen.
Bart.