[PATCH] drm/imagination: Don't hold queues.lock across drm_sched_stop() on reset
From: Ryan Brue
Date: Wed Nov 25 2026 - 18:28:25 EST
pvr_queue_device_pre_reset() calls drm_sched_stop() on every queue with
pvr_dev->queues.lock held. drm_sched_stop() waits for the scheduler's
run_job work, and that work takes queues.lock in
pvr_queue_update_active_state(). A hard reset that starts while a job is
being submitted therefore deadlocks: the reset and the queue stay stuck,
and lockdep reports the circular dependency.
Take a context reference on each queue under queues.lock, move the queues
to a list of their own, and stop them after dropping the lock, as the
timeout handler already does. A queue whose context is already being
released has no jobs left and is skipped. post_reset() starts the same
queues and drops the references from a work item, because the last
reference releases the context, which takes reset_sem while the reset
still holds it.
Fixes: eaf01ee5ba28 ("drm/imagination: Implement job submission and scheduling")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://lore.kernel.org/r/20260630095216.498D61F000E9@xxxxxxxxxxxxxxx
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ryan Brue <ryanbrue.dev@xxxxxxxxx>
---
Sashiko flagged this ABBA deadlock in June, in its review of the
drm_sched_entity_fini() fix, and I have hit it on an MT8173 tablet
(GX6250, BVNC 4.40.2.51), first through lockdep and once as a real hang.
Tested on that board with lockdep and a local debug hook that forces a
hard reset from the watchdog under glmark2, plus a 20 ms sleep in
run_job before it takes queues.lock to make the race certain. Without
this patch, the first forced reset gives lockdep's circular-dependency
report, the reset never completes, and the job timeout handler then
oopses on a NULL parent fence. With it, seven hard resets over two
boots (four forced, three that the watchdog started on its own) gave
no lockdep report and no hung task, and new GPU work ran correctly
afterwards.
This patch was developed with the help of an LLM.
---
drivers/gpu/drm/imagination/pvr_device.h | 7 +++++
drivers/gpu/drm/imagination/pvr_queue.c | 50 +++++++++++++++++++++++++++-----
drivers/gpu/drm/imagination/pvr_queue.h | 13 +++++++++
3 files changed, 62 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/imagination/pvr_device.h b/drivers/gpu/drm/imagination/pvr_device.h
index c246122b4caf..f495ee9234e6 100644
--- a/drivers/gpu/drm/imagination/pvr_device.h
+++ b/drivers/gpu/drm/imagination/pvr_device.h
@@ -236,6 +236,13 @@ struct pvr_device {
/** @queues.lock: Lock protecting access to the active/idle
* lists. */
struct mutex lock;
+
+ /**
+ * @queues.resetting: Queues stopped by a hard reset, linked by
+ * pvr_queue::reset_node. Only used with @reset_sem held for
+ * writing.
+ */
+ struct list_head resetting;
} queues;
/**
diff --git a/drivers/gpu/drm/imagination/pvr_queue.c b/drivers/gpu/drm/imagination/pvr_queue.c
index 34b826381aa2..56751c192ce6 100644
--- a/drivers/gpu/drm/imagination/pvr_queue.c
+++ b/drivers/gpu/drm/imagination/pvr_queue.c
@@ -1242,6 +1242,23 @@ static void reg_state_init(void *cpu_ptr, void *priv)
}
}
+static void pvr_queue_reset_put_work(struct work_struct *w)
+{
+ struct pvr_queue *queue = container_of(w, struct pvr_queue, reset_put_work);
+
+ pvr_context_put(queue->ctx);
+}
+
+static void pvr_queue_reset_hold(struct pvr_queue *queue, struct list_head *list)
+{
+ /* A put still pending from the last reset hands its reference over. */
+ if (!cancel_work(&queue->reset_put_work) &&
+ !pvr_context_get_if_referenced(queue->ctx))
+ return;
+
+ list_add_tail(&queue->reset_node, list);
+}
+
/**
* pvr_queue_create() - Create a queue object.
* @ctx: The context this queue will be attached to.
@@ -1375,6 +1392,9 @@ struct pvr_queue *pvr_queue_create(struct pvr_context *ctx,
if (err)
goto err_sched_fini;
+ INIT_LIST_HEAD(&queue->reset_node);
+ INIT_WORK(&queue->reset_put_work, pvr_queue_reset_put_work);
+
mutex_lock(&pvr_dev->queues.lock);
list_add_tail(&queue->node, &pvr_dev->queues.idle);
mutex_unlock(&pvr_dev->queues.lock);
@@ -1402,26 +1422,39 @@ struct pvr_queue *pvr_queue_create(struct pvr_context *ctx,
void pvr_queue_device_pre_reset(struct pvr_device *pvr_dev)
{
+ struct list_head *resetting = &pvr_dev->queues.resetting;
struct pvr_queue *queue;
+ lockdep_assert_held_write(&pvr_dev->reset_sem);
+
+ /*
+ * drm_sched_stop() waits for the run_job work, which takes
+ * queues.lock, so it can't be called with queues.lock held. Pin the
+ * queues and stop them without it. A queue whose context is already
+ * being released has no jobs left, so it needs no stopping.
+ */
mutex_lock(&pvr_dev->queues.lock);
list_for_each_entry(queue, &pvr_dev->queues.idle, node)
- pvr_queue_stop(queue, NULL);
+ pvr_queue_reset_hold(queue, resetting);
list_for_each_entry(queue, &pvr_dev->queues.active, node)
- pvr_queue_stop(queue, NULL);
+ pvr_queue_reset_hold(queue, resetting);
mutex_unlock(&pvr_dev->queues.lock);
+
+ list_for_each_entry(queue, resetting, reset_node)
+ pvr_queue_stop(queue, NULL);
}
void pvr_queue_device_post_reset(struct pvr_device *pvr_dev)
{
- struct pvr_queue *queue;
+ struct pvr_queue *queue, *tmp;
- mutex_lock(&pvr_dev->queues.lock);
- list_for_each_entry(queue, &pvr_dev->queues.active, node)
- pvr_queue_start(queue);
- list_for_each_entry(queue, &pvr_dev->queues.idle, node)
+ lockdep_assert_held_write(&pvr_dev->reset_sem);
+
+ list_for_each_entry_safe(queue, tmp, &pvr_dev->queues.resetting, reset_node) {
pvr_queue_start(queue);
- mutex_unlock(&pvr_dev->queues.lock);
+ list_del_init(&queue->reset_node);
+ queue_work(pvr_dev->sched_wq, &queue->reset_put_work);
+ }
}
/**
@@ -1489,6 +1522,7 @@ int pvr_queue_device_init(struct pvr_device *pvr_dev)
INIT_LIST_HEAD(&pvr_dev->queues.active);
INIT_LIST_HEAD(&pvr_dev->queues.idle);
+ INIT_LIST_HEAD(&pvr_dev->queues.resetting);
err = drmm_mutex_init(from_pvr_device(pvr_dev), &pvr_dev->queues.lock);
if (err)
return err;
diff --git a/drivers/gpu/drm/imagination/pvr_queue.h b/drivers/gpu/drm/imagination/pvr_queue.h
index 149cc6d124bf..d46e9bb7b4f8 100644
--- a/drivers/gpu/drm/imagination/pvr_queue.h
+++ b/drivers/gpu/drm/imagination/pvr_queue.h
@@ -90,6 +90,19 @@ struct pvr_queue {
/** @node: Used to add the queue to the active/idle queue list. */
struct list_head node;
+ /**
+ * @reset_node: Used to add the queue to pvr_device::queues::resetting
+ * while a hard reset has it stopped. The queue holds a reference on
+ * its context while it is on that list.
+ */
+ struct list_head reset_node;
+
+ /**
+ * @reset_put_work: Drops the context reference taken by a hard reset.
+ * Context release can't run under pvr_device::reset_sem.
+ */
+ struct work_struct reset_put_work;
+
/**
* @in_flight_job_count: Number of jobs submitted to the CCCB that
* have not been processed yet.
---
base-commit: 479e381e77dcde0dfcc9d51e89ff3273da199804
change-id: 20261125-rbrue-suez-pvr-pre-reset-lock-e2d7f7a44211
Best regards,
--
Ryan Brue <ryanbrue.dev@xxxxxxxxx>