Skip to contentSkip to conversation

accel/ivpu: fix HWS command queue leak on registration failure

PATCH In review Karol Wachowski 2 participants 3 messages Jun 11 – Jun 15

Subsystems (2)
lore
Share & tools
lore

Karol Wachowski

author maintainer
#0 lore raw

PATCH 1/1 accel/ivpu: fix HWS command queue leak on registration failure

A command queue is considered valid and usable by the driver only when it has a doorbell ID assigned (db_id != 0), meaning both the FW cmdq creation and doorbell registration completed successfully.

However, when either ivpu_register_db() or set_context_sched_properties() fails after ivpu_hws_cmdq_init() has already created the cmdq in FW, the command queue is left registered in FW while the driver treats it as uninitialized (db_id remains 0). On the next submission attempt the driver tries to register the same cmdq again, which fails because FW already has an entry for it.

Fix by calling ivpu_jsm_hws_destroy_cmdq() on error paths to properly unwind FW state and allow subsequent registration attempts to succeed.

Fixes 0c7c13186866 ("accel/ivpu: Add API for command queue create/destroy/submit")
---
 drivers/accel/ivpu/ivpu_job.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/accel/ivpu/ivpu_job.c +5 -5
index 521931d1f7fc..b24f31a8b567 100644
@@ -208,9 +208,9 @@ static int ivpu_hws_cmdq_init(struct ivpu_file_priv *file_priv, struct ivpu_cmdq
 	ret = ivpu_jsm_hws_set_context_sched_properties(vdev, file_priv->ctx.id, cmdq->id,
 							priority);
 	if (ret)
-		return ret;
+		ivpu_jsm_hws_destroy_cmdq(vdev, file_priv->ctx.id, cmdq->id);
 
-	return 0;
+	return ret;
 }
 
 static int ivpu_register_db(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *cmdq)
@@ -281,10 +281,10 @@ static int ivpu_cmdq_register(struct ivpu_file_priv *file_priv, struct ivpu_cmdq
 	}
 
 	ret = ivpu_register_db(file_priv, cmdq);
-	if (ret)
-		return ret;
+	if (ret && vdev->fw->sched_mode == VPU_SCHEDULING_MODE_HW)
+		ivpu_jsm_hws_destroy_cmdq(vdev, file_priv->ctx.id, cmdq->id);
 
-	return 0;
+	return ret;
 }
 
 static int ivpu_cmdq_unregister(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *cmdq)
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 40 lines · Karol Wachowski

A command queue is considered valid and usable by the driver only when it has a doorbell ID assigned (db_id != 0), meaning both the FW cmdq creation and doorbell registration completed successfully.

However, when either ivpu_register_db() or set_context_sched_properties() fails after ivpu_hws_cmdq_init() has already created the cmdq in FW, the command queue is left registered in FW while the driver treats it as uninitialized (db_id remains 0). On the next submission attempt the driver tries to register the same cmdq again, which fails because FW already has an entry for it.

Fix by calling ivpu_jsm_hws_destroy_cmdq() on error paths to properly unwind FW state and allow subsequent registration attempts to succeed.

Fixes 0c7c13186866 ("accel/ivpu: Add API for command queue create/destroy/submit")
---
  drivers/accel/ivpu/ivpu_job.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/accel/ivpu/ivpu_job.c +2 -2
index 521931d1f7fc..b24f31a8b567 100644
@@ -208,9 +208,9 @@ static int ivpu_hws_cmdq_init(struct ivpu_file_priv *file_priv, struct ivpu_cmdq
  	ret = ivpu_jsm_hws_set_context_sched_properties(vdev, file_priv->ctx.id, cmdq->id,
  							priority);
  	if (ret)
-		return ret;
+		ivpu_jsm_hws_destroy_cmdq(vdev, file_priv->ctx.id, cmdq->id);
 
-	return 0;
+	return ret;
  }
 
  static int ivpu_register_db(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *cmdq)
@@ -281,10 +281,10 @@ static int ivpu_cmdq_register(struct ivpu_file_priv *file_priv, struct ivpu_cmdq
  	}
 
  	ret = ivpu_register_db(file_priv, cmdq);

drivers/accel/ivpu/ivpu_job.c static int ivpu_cmdq_register(struct ivpu_file_priv *file_priv, struct ivpu_cmdq · line 290

Quoted 10 lines
drivers/accel/ivpu/ivpu_job.c +3 -3
-	if (ret)
-		return ret;
+	if (ret && vdev->fw->sched_mode == VPU_SCHEDULING_MODE_HW)
+		ivpu_jsm_hws_destroy_cmdq(vdev, file_priv->ctx.id, cmdq->id);
 
-	return 0;
+	return ret;
  }
 
  static int ivpu_cmdq_unregister(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *cmdq)
author maintainer Applied
#2 lore raw
Quoted 43 lines · Andrzej Kacprowski
Quoted 42 lines · Karol Wachowski

A command queue is considered valid and usable by the driver only when it has a doorbell ID assigned (db_id != 0), meaning both the FW cmdq creation and doorbell registration completed successfully.

However, when either ivpu_register_db() or set_context_sched_properties() fails after ivpu_hws_cmdq_init() has already created the cmdq in FW, the command queue is left registered in FW while the driver treats it as uninitialized (db_id remains 0). On the next submission attempt the driver tries to register the same cmdq again, which fails because FW already has an entry for it.

Fix by calling ivpu_jsm_hws_destroy_cmdq() on error paths to properly unwind FW state and allow subsequent registration attempts to succeed.

Fixes 0c7c13186866 ("accel/ivpu: Add API for command queue create/ destroy/submit")

---
  drivers/accel/ivpu/ivpu_job.c | 10 +++++-----

  1 file changed, 5 insertions(+), 5 deletions(-)
drivers/accel/ivpu/ivpu_job.c +0 -0
index 521931d1f7fc..b24f31a8b567 100644
@@ -208,9 +208,9 @@ static int ivpu_hws_cmdq_init(struct 

ivpu_file_priv *file_priv, struct ivpu_cmdq
      ret = ivpu_jsm_hws_set_context_sched_properties(vdev, file_priv-

Quoted 1 line

ctx.id, cmdq->id,

                              priority);
      if (ret)
-        return ret;
+        ivpu_jsm_hws_destroy_cmdq(vdev, file_priv->ctx.id, cmdq->id);
-    return 0;
+    return ret;
  }
  static int ivpu_register_db(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *cmdq)

drivers/accel/ivpu/ivpu_job.c +0 -0
@@ -281,10 +281,10 @@ static int ivpu_cmdq_register(struct 

ivpu_file_priv *file_priv, struct ivpu_cmdq
      }
      ret = ivpu_register_db(file_priv, cmdq);
-    if (ret)
-        return ret;

Quoted 8 lines
Quoted 6 lines

+    if (ret && vdev->fw->sched_mode == VPU_SCHEDULING_MODE_HW)
+        ivpu_jsm_hws_destroy_cmdq(vdev, file_priv->ctx.id, cmdq->id);
-    return 0;
+    return ret;
  }
  static int ivpu_cmdq_unregister(struct ivpu_file_priv *file_priv, struct ivpu_cmdq *cmdq)

Pushed to drm-misc-fixes.