Skip to contentSkip to conversation

drm/panthor: Reset queue slots if termination fails

PATCH Superseded Ashley Smith 4 participants 4 messages May 19, 2025 – May 26, 2025

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/panthor: Reset queue slots if termination fails

This fixes a bug where if we timeout after a suspend and the termination fails, due to waiting on a fence that will never be signalled for example, we do not resume the group correctly. The fix forces a reset for groups that are not terminated correctly.

---
Changes in v2:
- Fixed syntax error

---
 drivers/gpu/drm/panthor/panthor_sched.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_sched.c +10 -1
index 43ee57728de5..65d8ae3dcac1 100644
@@ -2727,8 +2727,17 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
 			 * automatically terminate all active groups, so let's
 			 * force the state to halted here.
 			 */
-			if (csg_slot->group->state != PANTHOR_CS_GROUP_TERMINATED)
+			if (csg_slot->group->state != PANTHOR_CS_GROUP_TERMINATED) {
 				csg_slot->group->state = PANTHOR_CS_GROUP_TERMINATED;
+
+				/* Reset the queue slots manually if the termination
+				 * request failed.
+				 */
+				for (i = 0; i < group->queue_count; i++) {
+					if (group->queues[i])
+						cs_slot_reset_locked(ptdev, csg_id, i);
+				}
+			}
 			slot_mask &= ~BIT(csg_id);
 		}
 	}

base-commit: 9934ab18051118385c7ea44d8e14175edbe6dc9c

Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Ashley Smith

This fixes a bug where if we timeout after a suspend and the termination fails, due to waiting on a fence that will never be signalled for example, we do not resume the group correctly. The fix forces a reset for groups that are not terminated correctly.

Best regards,
Liviu

Quoted 35 lines

---
Changes in v2:
- Fixed syntax error

---
 drivers/gpu/drm/panthor/panthor_sched.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_sched.c +10 -1
index 43ee57728de5..65d8ae3dcac1 100644
@@ -2727,8 +2727,17 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
 			 * automatically terminate all active groups, so let's
 			 * force the state to halted here.
 			 */
-			if (csg_slot->group->state != PANTHOR_CS_GROUP_TERMINATED)
+			if (csg_slot->group->state != PANTHOR_CS_GROUP_TERMINATED) {
 				csg_slot->group->state = PANTHOR_CS_GROUP_TERMINATED;
+
+				/* Reset the queue slots manually if the termination
+				 * request failed.
+				 */
+				for (i = 0; i < group->queue_count; i++) {
+					if (group->queues[i])
+						cs_slot_reset_locked(ptdev, csg_id, i);
+				}
+			}
 			slot_mask &= ~BIT(csg_id);
 		}
 	}

base-commit: 9934ab18051118385c7ea44d8e14175edbe6dc9c

Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Ashley Smith
Quoted 6 lines · Ashley Smith

This fixes a bug where if we timeout after a suspend and the termination fails, due to waiting on a fence that will never be signalled for example, we do not resume the group correctly. The fix forces a reset for groups that are not terminated correctly.

Quoted 32 lines

---
Changes in v2:
- Fixed syntax error

---
 drivers/gpu/drm/panthor/panthor_sched.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_sched.c +10 -1
index 43ee57728de5..65d8ae3dcac1 100644
@@ -2727,8 +2727,17 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
 			 * automatically terminate all active groups, so let's
 			 * force the state to halted here.
 			 */
-			if (csg_slot->group->state != PANTHOR_CS_GROUP_TERMINATED)
+			if (csg_slot->group->state != PANTHOR_CS_GROUP_TERMINATED) {
 				csg_slot->group->state = PANTHOR_CS_GROUP_TERMINATED;
+
+				/* Reset the queue slots manually if the termination
+				 * request failed.
+				 */
+				for (i = 0; i < group->queue_count; i++) {
+					if (group->queues[i])
+						cs_slot_reset_locked(ptdev, csg_id, i);
+				}
+			}
 			slot_mask &= ~BIT(csg_id);
 		}
 	}

base-commit: 9934ab18051118385c7ea44d8e14175edbe6dc9c

maintainer
#3 lore raw
In reply to Ashley Smith
Quoted 6 lines · On Mon, 19 May 2025 15:50:19 +0100 Ashley Smith <[email protected]>…

This fixes a bug where if we timeout after a suspend and the termination fails, due to waiting on a fence that will never be signalled for example, we do not resume the group correctly. The fix forces a reset for groups that are not terminated correctly.

We clearly need a Fixes tag, otherwise "drm/panthor: Make the timeout per-queue instead of per-job" will be backported, but not this one, which will lead to UAF. Can you send a v5 with both patches in the same series, each with a proper Fixes tag?

Quoted 32 lines

---
Changes in v2:
- Fixed syntax error

---
 drivers/gpu/drm/panthor/panthor_sched.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_sched.c +10 -1
index 43ee57728de5..65d8ae3dcac1 100644
@@ -2727,8 +2727,17 @@ void panthor_sched_suspend(struct panthor_device *ptdev)
 			 * automatically terminate all active groups, so let's
 			 * force the state to halted here.
 			 */
-			if (csg_slot->group->state != PANTHOR_CS_GROUP_TERMINATED)
+			if (csg_slot->group->state != PANTHOR_CS_GROUP_TERMINATED) {
 				csg_slot->group->state = PANTHOR_CS_GROUP_TERMINATED;
+
+				/* Reset the queue slots manually if the termination
+				 * request failed.
+				 */
+				for (i = 0; i < group->queue_count; i++) {
+					if (group->queues[i])
+						cs_slot_reset_locked(ptdev, csg_id, i);
+				}
+			}
 			slot_mask &= ~BIT(csg_id);
 		}
 	}

base-commit: 9934ab18051118385c7ea44d8e14175edbe6dc9c