Skip to contentSkip to conversation

accel/ivpu: Correct mutex unlock order in job submission

PATCH In review Jacek Lawrynowicz 2 participants 7 messages Apr 25, 2025 – Apr 30, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 accel/ivpu: Correct mutex unlock order in job submission

From: Karol Wachowski <[email protected]>

The mutex unlock for vdev->submitted_jobs_lock was incorrectly placed after unlocking file_priv->lock. Change order of unlocks to avoid potential race conditions.

Fixes 5bbccadaf33e ("accel/ivpu: Abort all jobs after command queue unregister")
---
 drivers/accel/ivpu/ivpu_job.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_job.c +1 -1
index 863e3cd6ace51..540923ffcbf8d 100644
@@ -681,8 +681,8 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority, u32 cmdq_id)
 err_erase_xa:
 	xa_erase(&vdev->submitted_jobs_xa, job->job_id);
 err_unlock:
-	mutex_unlock(&vdev->submitted_jobs_lock);
 	mutex_unlock(&file_priv->lock);
+	mutex_unlock(&vdev->submitted_jobs_lock);
 	ivpu_rpm_put(vdev);
 	return ret;
 }
Signature · 1 line
2.45.1
#1 lore raw
Quoted 4 lines · Jacek Lawrynowicz

From: Karol Wachowski <[email protected]>

The mutex unlock for vdev->submitted_jobs_lock was incorrectly placed after unlocking file_priv->lock. Change order of unlocks to avoid potential

This should read "before unlocking", right?

Quoted 23 lines

race conditions.

Fixes 5bbccadaf33e ("accel/ivpu: Abort all jobs after command queue unregister")
---
  drivers/accel/ivpu/ivpu_job.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_job.c +1 -1
index 863e3cd6ace51..540923ffcbf8d 100644
@@ -681,8 +681,8 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority, u32 cmdq_id)
  err_erase_xa:
  	xa_erase(&vdev->submitted_jobs_xa, job->job_id);
  err_unlock:
-	mutex_unlock(&vdev->submitted_jobs_lock);
  	mutex_unlock(&file_priv->lock);
+	mutex_unlock(&vdev->submitted_jobs_lock);
  	ivpu_rpm_put(vdev);
  	return ret;
  }
#2 lore raw

Hi,

Quoted 7 lines · Jeff Hugo
Quoted 4 lines · Jacek Lawrynowicz

From: Karol Wachowski <[email protected]>

The mutex unlock for vdev->submitted_jobs_lock was incorrectly placed after unlocking file_priv->lock. Change order of unlocks to avoid potential

This should read "before unlocking", right?

Yes, I will correct the commit message after submitting this patch :)

Quoted 24 lines
Quoted 23 lines

race conditions.

Fixes 5bbccadaf33e ("accel/ivpu: Abort all jobs after command queue unregister")

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

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_job.c +0 -0
index 863e3cd6ace51..540923ffcbf8d 100644
@@ -681,8 +681,8 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority, u32 cmdq_id)

  err_erase_xa:
      xa_erase(&vdev->submitted_jobs_xa, job->job_id); err_unlock:
-    mutex_unlock(&vdev->submitted_jobs_lock); mutex_unlock(&file_priv->lock);
+    mutex_unlock(&vdev->submitted_jobs_lock); ivpu_rpm_put(vdev);
      return ret;
  }

#3 lore raw
Quoted 4 lines · Jacek Lawrynowicz

Hi,

Quoted 1 line · Jeff Hugo

On 4/25/2025 3:36 AM, Jacek Lawrynowicz wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

From: Karol Wachowski <[email protected]>

The mutex unlock for vdev->submitted_jobs_lock was incorrectly placed after unlocking file_priv->lock. Change order of unlocks to avoid potential

This should read "before unlocking", right?

Yes, I will correct the commit message after submitting this patch :)

It does not look like this would apply to -next. Does it depend on something else? The locking order in -next appears correct.

Quoted 26 lines
Quoted 25 lines
Quoted 24 lines

race conditions.

Fixes 5bbccadaf33e ("accel/ivpu: Abort all jobs after command queue unregister")
---
   drivers/accel/ivpu/ivpu_job.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_job.c +1 -1
index 863e3cd6ace51..540923ffcbf8d 100644
@@ -681,8 +681,8 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority, u32 cmdq_id)
   err_erase_xa:
       xa_erase(&vdev->submitted_jobs_xa, job->job_id);
   err_unlock:
-    mutex_unlock(&vdev->submitted_jobs_lock);
       mutex_unlock(&file_priv->lock);
+    mutex_unlock(&vdev->submitted_jobs_lock);
       ivpu_rpm_put(vdev);
       return ret;
   }
#4 lore raw

Hi,

Quoted 7 lines · Jeff Hugo
Quoted 6 lines · Jacek Lawrynowicz

Hi,

Quoted 3 lines · Jeff Hugo
Quoted 2 lines · Jacek Lawrynowicz

From: Karol Wachowski <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The mutex unlock for vdev->submitted_jobs_lock was incorrectly placed after unlocking file_priv->lock. Change order of unlocks to avoid potential

This should read "before unlocking", right?

Yes, I will correct the commit message after submitting this patch :)

It does not look like this would apply to -next.  Does it depend on something else?  The locking order in -next appears correct.

Both -fixes and -next have incorrect order, see:
https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next/drivers/accel/ivpu/ivpu_job.c#L683
https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-fixes/drivers/accel/ivpu/ivpu_job.c#L683

The patch applies to both without issues.

Regards,
Jacek

Reviewed-by
#5 lore raw
Quoted 17 lines · Jacek Lawrynowicz

Hi,

Quoted 14 lines · Jeff Hugo
Quoted 12 lines · Jacek Lawrynowicz

Hi,

Quoted 7 lines · Jeff Hugo
Quoted 4 lines · Jacek Lawrynowicz

From: Karol Wachowski <[email protected]>

The mutex unlock for vdev->submitted_jobs_lock was incorrectly placed after unlocking file_priv->lock. Change order of unlocks to avoid potential

This should read "before unlocking", right?

Yes, I will correct the commit message after submitting this patch :)

Quoted 7 lines
Quoted 1 line

It does not look like this would apply to -next.  Does it depend on something else?  The locking order in -next appears correct.

Both -fixes and -next have incorrect order, see:
https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next/drivers/accel/ivpu/ivpu_job.c#L683
https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-fixes/drivers/accel/ivpu/ivpu_job.c#L683

The patch applies to both without issues.

Huh, I'm not sure what I was looking at yesterday. I'm seeing it today.

Assuming the commit message fix discussed previously

#6 lore raw
In reply to Jacek Lawrynowicz

Fixed commit message and applied to drm-misc-fixes

Quoted 27 lines · Jacek Lawrynowicz

From: Karol Wachowski <[email protected]>

The mutex unlock for vdev->submitted_jobs_lock was incorrectly placed after unlocking file_priv->lock. Change order of unlocks to avoid potential race conditions.

Fixes 5bbccadaf33e ("accel/ivpu: Abort all jobs after command queue unregister")
---
 drivers/accel/ivpu/ivpu_job.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_job.c +1 -1
index 863e3cd6ace51..540923ffcbf8d 100644
@@ -681,8 +681,8 @@ static int ivpu_job_submit(struct ivpu_job *job, u8 priority, u32 cmdq_id)
 err_erase_xa:
 	xa_erase(&vdev->submitted_jobs_xa, job->job_id);
 err_unlock:
-	mutex_unlock(&vdev->submitted_jobs_lock);
 	mutex_unlock(&file_priv->lock);
+	mutex_unlock(&vdev->submitted_jobs_lock);
 	ivpu_rpm_put(vdev);
 	return ret;
 }