From: Arun Iyengar <[email protected]>

panfrost_reset() cancels the job in _NEXT with JS_COMMAND_NOP and
soft-stops the running one. If the running job completes instead,
panfrost_jm_handle_irq() takes the cancelled job for done too: its
fence is signalled and it never runs.

As the Arm driver does, read JS_HEAD_NEXT after the NOP; if it still
holds the job, take it off the slot and restart it with the others.
Found by Sashiko. Not reproduced.

Fixes: 030761e097b4 ("drm/panfrost: Queue jobs on the hardware")
Cc: [email protected]
Reported-by: Sashiko <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Arun Iyengar <[email protected]>
---
 drivers/gpu/drm/panfrost/panfrost_job.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c 
b/drivers/gpu/drm/panfrost/panfrost_job.c
index b5b523cb2..c9bd3555f 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,22 @@ 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);
+
+               /* Never started: take it off, or the IRQ handler completes it. 
*/
+               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 +732,9 @@ panfrost_reset(struct panfrost_device *pfdev,
         */
        spin_lock(&pfdev->js->job_lock);
        for (i = 0; i < NUM_JOB_SLOTS; i++) {
+               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


Reply via email to