Skip to contentSkip to conversation

block: mq-deadline: check if elevator is attached to queue in dd_finish_request

PATCH In review Elijah Wright 2 participants 4 messages Jun 17, 2025 – Jun 18, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

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
index 2edf1cac06d5..4d7b21b144d3 100644
@@ -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
#1 lore raw
Quoted 24 lines · Elijah Wright

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 +0 -7
index 2edf1cac06d5..4d7b21b144d3 100644
@@ -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.

#2 lore raw

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_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 +3 -7
index 2edf1cac06d5..4d7b21b144d3 100644
@@ -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
+        * 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.

#3 lore raw
Quoted 1 line · Elijah Wright

I see. would it be possible to detach the elevator from the queue in elevator_exit instead?

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.