[PATCH v3 08/14] drm/panfrost: Don't signal a job cancelled from _NEXT at a reset as done
From: Arun Iyengar via B4 Relay
Date: Fri Nov 13 2026 - 07:20:36 EST
From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
panfrost_reset() cancels the job in each slot's _NEXT registers with
JS_COMMAND_NOP and soft-stops the running one. If the running job
completes instead of stopping, panfrost_jm_handle_irq() dequeues it,
finds both subslots inactive and takes the cancelled job, now at the
head of the slot, for done as well. The cancelled job gets its jc
cleared and its done fence signalled: drm_sched_resubmit_jobs() does not
run it again, and it completes with -ECANCELED without having run.
The Arm driver reads JS_HEAD_NEXT after the NOP: if it still holds the
job, the job has not started and is evicted. Do the same: take an
evicted job off the slot while the remaining interrupts are handled and
put it back afterwards, so that it is restarted with the others.
Found by code review (Sashiko) of "Soft-stop and resume a job that
outlives the timeout", which widens the window. Not reproduced.
Fixes: 030761e097b4 ("drm/panfrost: Queue jobs on the hardware")
Cc: stable@xxxxxxxxxxxxxxx
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://lore.kernel.org/all/sashiko-outbox-206581@xxxxxxxxxx/
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
drivers/gpu/drm/panfrost/panfrost_job.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index 7319511db..1bb70b07d 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -659,6 +659,7 @@ static void
panfrost_reset(struct panfrost_device *pfdev,
struct drm_sched_job *bad)
{
+ struct panfrost_job *evicted[NUM_JOB_SLOTS] = {};
u32 js_state, js_state_mask = 0xffffffff;
unsigned int i, j;
bool cookie;
@@ -694,11 +695,25 @@ panfrost_reset(struct panfrost_device *pfdev,
job_write(pfdev, JOB_INT_MASK, 0);
synchronize_irq(pfdev->js->irq);
+ spin_lock(&pfdev->js->job_lock);
for (i = 0; i < NUM_JOB_SLOTS; i++) {
/* Cancel the next job and soft-stop the running job. */
job_write(pfdev, JS_COMMAND_NEXT(i), JS_COMMAND_NOP);
+
+ /* A job still in _NEXT after the NOP never started. Take it
+ * off the slot, or panfrost_jm_handle_irq() takes it for done
+ * if the running job completes instead of stopping.
+ */
+ if (pfdev->jobs[i][1] &&
+ (job_read(pfdev, JS_HEAD_NEXT_LO(i)) ||
+ job_read(pfdev, JS_HEAD_NEXT_HI(i)))) {
+ evicted[i] = pfdev->jobs[i][1];
+ pfdev->jobs[i][1] = NULL;
+ }
+
job_write(pfdev, JS_COMMAND(i), JS_COMMAND_SOFT_STOP);
}
+ spin_unlock(&pfdev->js->job_lock);
/* Wait at most 10ms for soft-stops to complete */
ret = readl_poll_timeout(pfdev->iomem + JOB_INT_JS_STATE, js_state,
@@ -720,6 +735,10 @@ panfrost_reset(struct panfrost_device *pfdev,
*/
spin_lock(&pfdev->js->job_lock);
for (i = 0; i < NUM_JOB_SLOTS; i++) {
+ /* Put the evicted job back, to be restarted. */
+ if (evicted[i])
+ pfdev->jobs[i][pfdev->jobs[i][0] ? 1 : 0] = evicted[i];
+
for (j = 0; j < ARRAY_SIZE(pfdev->jobs[0]) && pfdev->jobs[i][j]; j++) {
if (pfdev->jobs[i][j]->requirements & PANFROST_JD_REQ_CYCLE_COUNT ||
pfdev->jobs[i][j]->is_profiled)
--
2.55.0