* [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes
@ 2026-11-28 17:26 Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 01/17] drm/panfrost: Freeze the reset workqueue during system sleep Arun Iyengar via B4 Relay
` (16 more replies)
0 siblings, 17 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
Fixes for problems found running the GLES, Vulkan and OpenCL
conformance tests with Mesa on a Mali-G31 (Allwinner H616), and for
problems Sashiko found around them:
- 1-4, 14, 15: reset and timeout paths vs power management, heap BO
cache sync, a mapping being freed.
- 5-8: BO mapping error paths.
- 9-13: races around panfrost_reset().
- 16: soft-stop and resume a job still active at the timeout.
- 17: name the BOs around an unhandled page fault.
Open points: a job that keeps reaching task boundaries is never killed;
stopping a long job holds all slots (here at most 349 ms); 16 can go
separately.
Tested v4 on v7.3 with Mesa 26.2: no regressions in 1196 dEQP/KHR
cases and 9 OpenCL CTS groups; v5's 15 was run through the reset and
long-job tests. 2-4 and 9-12 were not reproduced.
Developed with Claude (Anthropic) as coding assistant (investigation,
code, commit messages); I reviewed them and ran the tests.
---
Changes in v5:
- Patch 15: job_lock around the mask and the IRQ thread's unmask
instead of a second mask write (Sashiko on v4). The hard IRQ
handler still does not touch the GPU while it is suspended.
- Link to v4: https://patch.msgid.link/20261126-panfrost-long-jobs-v4-0-23579629ceca@gmail.com
Changes in v4:
- New patches 1, 14 and 15 (Sashiko on v3). Patch 2 clears
reset.pending in runtime resume and leaves system sleep to patch 1.
- Shorter commit messages and comments; test results in 1, 6, 7, 14
and 15.
- Renumbered: v3 1-12 are now 2-13, v3 13 and 14 are now 16 and 17.
- Rebased onto the current drm-misc-next.
- Link to v3: https://patch.msgid.link/20261113-panfrost-long-jobs-v3-0-80ae78d38f6e@gmail.com
Changes in v3:
- Patch 1: disable the reset work across system sleep (Sashiko).
- New patches 7, 10 and 11 (Sashiko); shorter messages and comments.
- Renumbered and rebased onto the current drm-misc-next.
- Link to v2: https://patch.msgid.link/20261112-panfrost-long-jobs-v2-0-a06830da3d99@gmail.com
Changes in v2:
- New patches 1-3, 7 and 8 for Sashiko's findings on v1.
- Patches 6, 10 and 11 reworked and v1 4/7 dropped after Sashiko's review.
- Renumbered and rebased onto the current drm-misc-next.
- Link to v1: https://lore.kernel.org/r/20261110-panfrost-long-jobs-v1-0-24508939ae8d@gmail.com
---
Arun Iyengar (17):
drm/panfrost: Freeze the reset workqueue during system sleep
drm/panfrost: Power the GPU up for a reset queued from the MMU code
drm/panfrost: Refuse to sync the CPU caches of a heap BO
drm/panfrost: Don't take a reference on a mapping that is being freed
drm/panfrost: Don't WARN when a GEM mapping cannot get its pages
drm/panfrost: Unwind a failed GPU mapping without dropping its pages
drm/panfrost: Give back the pages of a heap chunk that failed to map
drm/panfrost: Don't WARN for a heap folio a neighbouring chunk filled
drm/panfrost: Don't signal a job cancelled from _NEXT at a reset as done
drm/panfrost: Don't cancel a job that completed during a reset
drm/panfrost: Drop the cycle counter only for a job that holds it
drm/panfrost: Don't take a job that was never started for done
drm/panfrost: Wait for the soft-stopped slots with the live slot status
drm/panfrost: Keep the GPU powered in the job timeout handler
drm/panfrost: Keep the job interrupts masked during a reset
drm/panfrost: Soft-stop and resume a job that outlives the timeout
drm/panfrost: Name the BOs around an unhandled page fault
drivers/gpu/drm/panfrost/panfrost_device.c | 1 +
drivers/gpu/drm/panfrost/panfrost_gem.c | 3 +
drivers/gpu/drm/panfrost/panfrost_job.c | 259 ++++++++++++++++++++++-------
drivers/gpu/drm/panfrost/panfrost_job.h | 3 +
drivers/gpu/drm/panfrost/panfrost_mmu.c | 145 ++++++++++++++--
5 files changed, 337 insertions(+), 74 deletions(-)
---
base-commit: 8a6e49c8557d3ba0fe4c7f1cb7f428289b13bfed
change-id: 20261110-panfrost-long-jobs-1643287a2ac1
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 01/17] drm/panfrost: Freeze the reset workqueue during system sleep
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 02/17] drm/panfrost: Power the GPU up for a reset queued from the MMU code Arun Iyengar via B4 Relay
` (15 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
pm_runtime_force_suspend() can power the GPU off under the timeout
handler or the reset work. Make their workqueue freezable.
Fixes: f3ba91228e8e ("drm/panfrost: Add initial panfrost driver")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-210830@kernel.org/
Closes: https://sashiko.dev/#/patchset/20261113-panfrost-long-jobs-v3-0-80ae78d38f6e@gmail.com?part=13
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: new (Sashiko on v3 01/14 and 13/14). Tested with s2idle entered in
a test-only 8 s hold in both: before, the GPU was runtime suspended
inside panfrost_reset(); after, the freezer waited for the work.
---
drivers/gpu/drm/panfrost/panfrost_job.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index 6a604b5da..79b302fef 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -893,7 +893,7 @@ int panfrost_jm_init(struct panfrost_device *pfdev)
return ret;
}
- pfdev->reset.wq = alloc_ordered_workqueue("panfrost-reset", 0);
+ pfdev->reset.wq = alloc_ordered_workqueue("panfrost-reset", WQ_FREEZABLE);
if (!pfdev->reset.wq)
return -ENOMEM;
args.timeout_wq = pfdev->reset.wq;
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 02/17] drm/panfrost: Power the GPU up for a reset queued from the MMU code
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 01/17] drm/panfrost: Freeze the reset workqueue during system sleep Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 03/17] drm/panfrost: Refuse to sync the CPU caches of a heap BO Arun Iyengar via B4 Relay
` (14 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
panfrost_reset_work() calls panfrost_reset() without a runtime PM
reference, and the MMU code that queues it drops its own right after.
Take a reference in the work. A GPU that cannot be resumed is reset by
its next runtime resume, so clear reset.pending there. Not reproduced.
Fixes: f9ab9c66f080 ("drm/panfrost: Reset the GPU when the AS_ACTIVE bit is stuck")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-206548@kernel.org/
Closes: https://lore.kernel.org/all/sashiko-outbox-212557@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: clear reset.pending in runtime resume (Sashiko 212557); system
sleep is left to patch 1.
---
drivers/gpu/drm/panfrost/panfrost_device.c | 1 +
drivers/gpu/drm/panfrost/panfrost_job.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c
index 40eda3612..3c5f077db 100644
--- a/drivers/gpu/drm/panfrost/panfrost_device.c
+++ b/drivers/gpu/drm/panfrost/panfrost_device.c
@@ -540,6 +540,7 @@ static int panfrost_device_runtime_resume(struct device *dev)
}
}
+ atomic_set(&pfdev->reset.pending, 0);
panfrost_device_reset(pfdev, true);
panfrost_devfreq_resume(pfdev);
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index 79b302fef..b5b523cb2 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -810,7 +810,12 @@ static void panfrost_reset_work(struct work_struct *work)
struct panfrost_device *pfdev;
pfdev = container_of(work, struct panfrost_device, reset.work);
+
+ if (pm_runtime_resume_and_get(pfdev->base.dev))
+ return;
+
panfrost_reset(pfdev, NULL);
+ pm_runtime_put_autosuspend(pfdev->base.dev);
}
static const struct drm_sched_backend_ops panfrost_sched_ops = {
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 03/17] drm/panfrost: Refuse to sync the CPU caches of a heap BO
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 01/17] drm/panfrost: Freeze the reset workqueue during system sleep Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 02/17] drm/panfrost: Power the GPU up for a reset queued from the MMU code Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 04/17] drm/panfrost: Don't take a reference on a mapping that is being freed Arun Iyengar via B4 Relay
` (13 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
On a coherent GPU, PANFROST_SYNC_BO on a heap BO dereferences the NULL
entries of its sparse page array. Heap BOs cannot be CPU-mapped:
return -EINVAL. Not tested on a coherent GPU.
Fixes: 7be45f548976 ("drm/panfrost: Add a PANFROST_SYNC_BO ioctl")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-206561@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: shorter commit message.
---
drivers/gpu/drm/panfrost/panfrost_gem.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c
index 518f24549..8067c5533 100644
--- a/drivers/gpu/drm/panfrost/panfrost_gem.c
+++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
@@ -569,6 +569,9 @@ panfrost_gem_sync(struct drm_gem_object *obj, u32 type, u32 offset, u32 size)
if (drm_gem_is_imported(&shmem->base))
return -EINVAL;
+ if (bo->is_heap)
+ return -EINVAL;
+
switch (type) {
case PANFROST_BO_SYNC_CPU_CACHE_FLUSH:
case PANFROST_BO_SYNC_CPU_CACHE_FLUSH_AND_INVALIDATE:
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 04/17] drm/panfrost: Don't take a reference on a mapping that is being freed
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (2 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 03/17] drm/panfrost: Refuse to sync the CPU caches of a heap BO Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 05/17] drm/panfrost: Don't WARN when a GEM mapping cannot get its pages Arun Iyengar via B4 Relay
` (12 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
A mapping stays in the drm_mm after its last reference is dropped, so
a GPU fault can revive it with kref_get(). Use kref_get_unless_zero().
Not reproduced.
Fixes: bdefca2d8dc0 ("drm/panfrost: Add the panfrost_gem_mapping concept")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/sashiko-outbox-206570@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: shorter commit message.
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index faa62643c..789a64fd3 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -576,7 +576,8 @@ addr_to_mapping(struct panfrost_device *pfdev, int as, u64 addr)
offset < (node->start + node->size)) {
mapping = drm_mm_node_to_panfrost_mapping(node);
- kref_get(&mapping->refcount);
+ if (!kref_get_unless_zero(&mapping->refcount))
+ mapping = NULL;
break;
}
}
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 05/17] drm/panfrost: Don't WARN when a GEM mapping cannot get its pages
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (3 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 04/17] drm/panfrost: Don't take a reference on a mapping that is being freed Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 06/17] drm/panfrost: Unwind a failed GPU mapping without dropping " Arun Iyengar via B4 Relay
` (11 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
Failing at a memory cgroup limit is an ordinary error returned to
userspace. Drop the WARN_ON().
Fixes: f3ba91228e8e ("drm/panfrost: Add initial panfrost driver")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: shorter commit message.
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index 789a64fd3..e70ae393e 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -480,7 +480,7 @@ int panfrost_mmu_map(struct panfrost_gem_mapping *mapping)
prot |= IOMMU_NOEXEC;
sgt = drm_gem_shmem_get_pages_sgt(shmem);
- if (WARN_ON(IS_ERR(sgt)))
+ if (IS_ERR(sgt))
return PTR_ERR(sgt);
ret = mmu_map_sg(pfdev, mapping->mmu, mapping->mmnode.start << PAGE_SHIFT,
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 06/17] drm/panfrost: Unwind a failed GPU mapping without dropping its pages
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (4 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 05/17] drm/panfrost: Don't WARN when a GEM mapping cannot get its pages Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 07/17] drm/panfrost: Give back the pages of a heap chunk that failed to map Arun Iyengar via B4 Relay
` (10 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
Two error paths leave wrong state when a BO mapping fails part-way:
- If mmu_map_sg() fails, panfrost_mmu_map() calls
drm_gem_shmem_put_pages_locked() without the reservation lock and
drops pages that shmem->sgt still maps (an imported BO underflows
pages_use_count). Keep the pages.
- If ops->map_pages() fails, the PTEs that call mapped stay in a VA
range drm_mm hands out again. Unmap and flush them too.
Tested with a test-only map_pages() failure: before, the pages were
freed under the cached sg table and an imported BO kept 512 PTEs;
after, neither.
Fixes: 4da352cf8fb1 ("drm/panfrost: Handle page mapping failure")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: test result added; no code change.
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index e70ae393e..e59a16b68 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -442,8 +442,10 @@ static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu,
ret = ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot,
GFP_KERNEL, &mapped);
- if (ret)
+ if (ret) {
+ total_mapped += mapped;
goto err_unmap_pages;
+ }
/* Don't get stuck if things have gone wrong */
mapped = max(mapped, pgsize);
@@ -459,7 +461,10 @@ static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu,
return 0;
err_unmap_pages:
- mmu_unmap_range(mmu, start_iova, total_mapped);
+ if (total_mapped) {
+ mmu_unmap_range(mmu, start_iova, total_mapped);
+ panfrost_mmu_flush_range(pfdev, mmu, start_iova, total_mapped);
+ }
return ret;
}
@@ -483,18 +488,15 @@ int panfrost_mmu_map(struct panfrost_gem_mapping *mapping)
if (IS_ERR(sgt))
return PTR_ERR(sgt);
+ /* shmem->sgt holds the only page reference: keep the pages. */
ret = mmu_map_sg(pfdev, mapping->mmu, mapping->mmnode.start << PAGE_SHIFT,
prot, sgt);
if (ret)
- goto err_put_pages;
+ return ret;
mapping->active = true;
return 0;
-
-err_put_pages:
- drm_gem_shmem_put_pages_locked(shmem);
- return ret;
}
void panfrost_mmu_unmap(struct panfrost_gem_mapping *mapping)
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 07/17] drm/panfrost: Give back the pages of a heap chunk that failed to map
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (5 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 06/17] drm/panfrost: Unwind a failed GPU mapping without dropping " Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 08/17] drm/panfrost: Don't WARN for a heap folio a neighbouring chunk filled Arun Iyengar via B4 Relay
` (9 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
If growing a heap BO by a 2 MB chunk fails after the chunk's folios
were read, they stay in bo->base.pages without an sg table. The next
fault in the chunk finds them owned and hits the drm_WARN_ON() that
commit b49c35ba0ce1 added.
On those error paths, put the folios read and clear their entries:
whole folios, as the fill loop wrote them, except those a neighbouring
chunk owns.
Tested with a test-only failure after the read: before, the next fault
WARNed for each of the 512 pages; after, none. Folios larger than a
chunk (16K/64K pages) are from reading the code.
Fixes: b49c35ba0ce1 ("drm/panfrost: Fix a page leak in panfrost_mmu_map_fault_addr() when THP is on")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: test result added; no code change.
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 40 +++++++++++++++++++++++++++++----
1 file changed, 36 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index e59a16b68..9edf66f6e 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -592,6 +592,27 @@ addr_to_mapping(struct panfrost_device *pfdev, int as, u64 addr)
#define NUM_FAULT_PAGES (SZ_2M / PAGE_SIZE)
+/* [start, end) is whole folios: it can reach past the 2 MB chunk. */
+static void panfrost_heap_put_pages(struct page **pages, pgoff_t start,
+ pgoff_t end)
+{
+ while (start < end) {
+ struct folio *folio;
+
+ if (!pages[start]) {
+ start++;
+ continue;
+ }
+
+ folio = page_folio(pages[start]);
+ do {
+ pages[start++] = NULL;
+ } while (start < end && pages[start] &&
+ page_folio(pages[start]) == folio);
+ folio_put(folio);
+ }
+}
+
static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
u64 addr)
{
@@ -600,7 +621,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
struct panfrost_gem_object *bo;
struct address_space *mapping;
struct drm_gem_object *obj;
- pgoff_t page_offset, nr_pages;
+ pgoff_t page_offset, nr_pages, got_start, got_end;
struct sg_table *sgt;
struct page **pages;
@@ -659,17 +680,22 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
mapping = bo->base.base.filp->f_mapping;
mapping_set_unevictable(mapping);
+ got_start = page_offset;
+ got_end = page_offset;
+
for (pgoff_t pg = page_offset; pg < page_offset + NUM_FAULT_PAGES;) {
bool already_owned = false;
struct folio *folio;
+ pgoff_t first;
folio = shmem_read_folio(mapping, pg);
if (IS_ERR(folio)) {
ret = PTR_ERR(folio);
- goto err_unlock;
+ goto err_put_chunk;
}
pg &= ~(folio_nr_pages(folio) - 1);
+ first = pg;
for (u32 i = 0; i < folio_nr_pages(folio) && pg < nr_pages; i++) {
if (pages[pg])
already_owned = true;
@@ -681,14 +707,18 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
* there's no valid reason for a folio range to be partially
* populated.
*/
- if (drm_WARN_ON(&pfdev->base, already_owned))
+ if (drm_WARN_ON(&pfdev->base, already_owned)) {
folio_put(folio);
+ } else {
+ got_start = min(got_start, first);
+ got_end = max(got_end, pg);
+ }
}
ret = sg_alloc_table_from_pages(sgt, pages + page_offset,
NUM_FAULT_PAGES, 0, SZ_2M, GFP_KERNEL);
if (ret)
- goto err_unlock;
+ goto err_put_chunk;
ret = dma_map_sgtable(pfdev->base.dev, sgt, DMA_BIDIRECTIONAL, 0);
if (ret)
@@ -715,6 +745,8 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
dma_unmap_sgtable(pfdev->base.dev, sgt, DMA_BIDIRECTIONAL, 0);
err_map:
sg_free_table(sgt);
+err_put_chunk:
+ panfrost_heap_put_pages(pages, got_start, got_end);
err_unlock:
dma_resv_unlock(obj->resv);
err_bo:
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 08/17] drm/panfrost: Don't WARN for a heap folio a neighbouring chunk filled
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (6 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 07/17] drm/panfrost: Give back the pages of a heap chunk that failed to map Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 09/17] drm/panfrost: Don't signal a job cancelled from _NEXT at a reset as done Arun Iyengar via B4 Relay
` (8 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
With 16K or 64K pages, a THP folio can be larger than the 2 MB heap
chunk, and the first fault in it fills the page array of neighbouring
chunks too. Every later fault there WARNs, although dropping the extra
folio reference is all it has to do. Warn only for a folio that fits
in the chunk. Not reproduced (4K pages here).
Fixes: b49c35ba0ce1 ("drm/panfrost: Fix a page leak in panfrost_mmu_map_fault_addr() when THP is on")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-210837@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index 9edf66f6e..92a4d2963 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -703,11 +703,13 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
pages[pg++] = folio_page(folio, i);
}
- /* We always fill the page array at a folio granularity so
- * there's no valid reason for a folio range to be partially
- * populated.
+ /* We always fill the page array at a folio granularity, so a
+ * folio is already owned only if it is larger than the chunk
+ * and the fault of a neighbouring chunk filled it.
*/
- if (drm_WARN_ON(&pfdev->base, already_owned)) {
+ if (already_owned) {
+ drm_WARN_ON(&pfdev->base,
+ folio_nr_pages(folio) <= NUM_FAULT_PAGES);
folio_put(folio);
} else {
got_start = min(got_start, first);
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 09/17] drm/panfrost: Don't signal a job cancelled from _NEXT at a reset as done
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (7 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 08/17] drm/panfrost: Don't WARN for a heap folio a neighbouring chunk filled Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 10/17] drm/panfrost: Don't cancel a job that completed during a reset Arun Iyengar via B4 Relay
` (7 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
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: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-206581@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
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
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 10/17] drm/panfrost: Don't cancel a job that completed during a reset
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (8 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 09/17] drm/panfrost: Don't signal a job cancelled from _NEXT at a reset as done Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 11/17] drm/panfrost: Drop the cycle counter only for a job that holds it Arun Iyengar via B4 Relay
` (6 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
A job that completes during panfrost_reset() has its jc cleared, so
drm_sched_start() cancels it. Return its done fence instead. Depends
on the previous patch. Not reproduced.
Fixes: 03877d621db0 ("drm/scheduler: mark jobs without fence as canceled")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-206581@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: shorter commit message.
---
drivers/gpu/drm/panfrost/panfrost_job.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index c9bd3555f..a64c33047 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -409,11 +409,9 @@ static struct dma_fence *panfrost_job_run(struct drm_sched_job *sched_job)
if (unlikely(job->base.s_fence->finished.error))
return NULL;
- /* Nothing to execute: can happen if the job has finished while
- * we were resetting the GPU.
- */
+ /* Done in the reset: drm_sched_start() cancels it without a fence */
if (!job->jc)
- return NULL;
+ return dma_fence_get(job->done_fence);
fence = panfrost_fence_create(pfdev, slot);
if (IS_ERR(fence))
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 11/17] drm/panfrost: Drop the cycle counter only for a job that holds it
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (9 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 10/17] drm/panfrost: Don't cancel a job that completed during a reset Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 12/17] drm/panfrost: Don't take a job that was never started for done Arun Iyengar via B4 Relay
` (5 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
While a reset is pending, panfrost_job_hw_submit() queues a job without
starting it or taking a cycle counter reference, and a stopped job is
resubmitted with is_profiled still set. panfrost_reset() drops a
reference for each, so use_count goes negative. The reset hides this
today; without one (patch 16) the counter is no longer started.
Record whether a job holds a reference. Found by Sashiko. Not
reproduced.
Fixes: f11b0417eec2 ("drm/panfrost: Add fdinfo support GPU load metrics")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-210891@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/gpu/drm/panfrost/panfrost_job.c | 19 +++++++++++++------
drivers/gpu/drm/panfrost/panfrost_job.h | 1 +
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index a64c33047..fcddc13bf 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -160,6 +160,14 @@ panfrost_get_job_chain_flag(const struct panfrost_job *job)
return (f->seqno & 1) ? JS_CONFIG_JOB_CHAIN_FLAG : 0;
}
+static void panfrost_job_put_cycle_counter(struct panfrost_job *job)
+{
+ if (job->cycle_counter_ref) {
+ panfrost_cycle_counter_put(job->pfdev);
+ job->cycle_counter_ref = false;
+ }
+}
+
static struct panfrost_job *
panfrost_dequeue_job(struct panfrost_device *pfdev, int slot)
{
@@ -174,8 +182,7 @@ panfrost_dequeue_job(struct panfrost_device *pfdev, int slot)
panfrost_cycle_counter_read(pfdev) - job->start_cycles;
}
- if (job->requirements & PANFROST_JD_REQ_CYCLE_COUNT || job->is_profiled)
- panfrost_cycle_counter_put(pfdev);
+ panfrost_job_put_cycle_counter(job);
pfdev->jobs[slot][0] = pfdev->jobs[slot][1];
pfdev->jobs[slot][1] = NULL;
@@ -259,8 +266,10 @@ static int panfrost_job_hw_submit(struct panfrost_job *job, int js)
job->is_profiled = pfdev->profile_mode;
if (job->requirements & PANFROST_JD_REQ_CYCLE_COUNT ||
- job->is_profiled)
+ job->is_profiled) {
panfrost_cycle_counter_get(pfdev);
+ job->cycle_counter_ref = true;
+ }
if (job->is_profiled) {
job->start_time = ktime_get();
@@ -734,9 +743,7 @@ panfrost_reset(struct panfrost_device *pfdev,
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)
- panfrost_cycle_counter_put(pfdev->jobs[i][j]->pfdev);
+ panfrost_job_put_cycle_counter(pfdev->jobs[i][j]);
pm_runtime_put_noidle(pfdev->base.dev);
panfrost_devfreq_record_idle(&pfdev->pfdevfreq);
}
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.h b/drivers/gpu/drm/panfrost/panfrost_job.h
index 3e3b97178..7f71e4c38 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.h
+++ b/drivers/gpu/drm/panfrost/panfrost_job.h
@@ -36,6 +36,7 @@ struct panfrost_job {
struct panfrost_engine_usage *engine_usage;
bool is_profiled;
+ bool cycle_counter_ref;
ktime_t start_time;
u64 start_cycles;
};
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 12/17] drm/panfrost: Don't take a job that was never started for done
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (10 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 11/17] drm/panfrost: Drop the cycle counter only for a job that holds it Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 13/17] drm/panfrost: Wait for the soft-stopped slots with the live slot status Arun Iyengar via B4 Relay
` (4 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
reset.pending is set before panfrost_reset() masks the job interrupt.
A job queued but not started in that window, behind a running job that
completes, is taken for done: its fence is signalled and it never runs.
Mark a job started when JS_COMMAND_START is written, and leave the
others to the reset. Found by Sashiko. Not reproduced.
Fixes: 030761e097b4 ("drm/panfrost: Queue jobs on the hardware")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-210891@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/gpu/drm/panfrost/panfrost_job.c | 8 ++++++--
drivers/gpu/drm/panfrost/panfrost_job.h | 2 ++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index fcddc13bf..0946da3af 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -261,6 +261,7 @@ static int panfrost_job_hw_submit(struct panfrost_job *job, int js)
spin_lock(&pfdev->js->job_lock);
subslot = panfrost_enqueue_job(pfdev, js, job);
+ job->started = false;
/* Don't queue the job if a reset is in progress */
if (!atomic_read(&pfdev->reset.pending)) {
job->is_profiled = pfdev->profile_mode;
@@ -276,6 +277,7 @@ static int panfrost_job_hw_submit(struct panfrost_job *job, int js)
job->start_cycles = panfrost_cycle_counter_read(pfdev);
}
+ job->started = true;
job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START);
dev_dbg(pfdev->base.dev,
"JS: Submitting atom %p to js[%d][%d] with head=0x%llx AS %d",
@@ -584,7 +586,8 @@ static void panfrost_jm_handle_irq(struct panfrost_device *pfdev, u32 status)
if (failed[j]) {
panfrost_job_handle_err(pfdev, failed[j], j);
- } else if (pfdev->jobs[j][0] && !(js_state & MK_JS_MASK(j))) {
+ } else if (pfdev->jobs[j][0] && pfdev->jobs[j][0]->started &&
+ !(js_state & MK_JS_MASK(j))) {
/* When the current job doesn't fail, the JM dequeues
* the next job without waiting for an ACK, this means
* we can have 2 jobs dequeued and only catch the
@@ -592,7 +595,8 @@ static void panfrost_jm_handle_irq(struct panfrost_device *pfdev, u32 status)
* are inactive, but one job remains in pfdev->jobs[j],
* consider it done. Of course that doesn't apply if a
* failure happened since we cancelled execution of the
- * job in _NEXT (see above).
+ * job in _NEXT (see above), or if the job was queued
+ * while a reset was pending and never started.
*/
if (WARN_ON(!done[j][0]))
done[j][0] = panfrost_dequeue_job(pfdev, j);
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.h b/drivers/gpu/drm/panfrost/panfrost_job.h
index 7f71e4c38..0ed45e28b 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.h
+++ b/drivers/gpu/drm/panfrost/panfrost_job.h
@@ -37,6 +37,8 @@ struct panfrost_job {
struct panfrost_engine_usage *engine_usage;
bool is_profiled;
bool cycle_counter_ref;
+ /* JS_COMMAND_START written */
+ bool started;
ktime_t start_time;
u64 start_cycles;
};
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 13/17] drm/panfrost: Wait for the soft-stopped slots with the live slot status
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (11 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 12/17] drm/panfrost: Don't take a job that was never started for done Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 14/17] drm/panfrost: Keep the GPU powered in the job timeout handler Arun Iyengar via B4 Relay
` (3 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
panfrost_reset() waits for the soft-stopped slots by polling
JOB_INT_JS_STATE, a snapshot taken at the last JOB_INT_CLEAR write. A
job started into an idle slot shows as idle, and the wait ends at once.
The GPU reset hides this. With the job resumed instead (patch 16), its
resubmission ran while the first run was still stopping (Mali-G31,
OpenCL CTS Integer Ops):
Unable to handle kernel NULL pointer dereference at virtual address 00000000000000f8
pc : panfrost_dequeue_job+0x2c/0xd8 [panfrost]
Wait until no JS_STATUS reads ACTIVE, and make panfrost_dequeue_job()
return NULL for an empty slot (a WARN, not an Oops).
Fixes: 030761e097b4 ("drm/panfrost: Queue jobs on the hardware")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/gpu/drm/panfrost/panfrost_job.c | 34 +++++++++++++--------------------
1 file changed, 13 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index 0946da3af..722f87ebe 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -173,7 +173,8 @@ panfrost_dequeue_job(struct panfrost_device *pfdev, int slot)
{
struct panfrost_job *job = pfdev->jobs[slot][0];
- WARN_ON(!job);
+ if (WARN_ON(!job))
+ return NULL;
if (job->is_profiled && job->engine_usage) {
job->engine_usage->elapsed_ns[slot] +=
@@ -645,25 +646,18 @@ static void panfrost_jm_handle_irqs(struct panfrost_device *pfdev)
}
}
-static u32 panfrost_active_slots(struct panfrost_device *pfdev,
- u32 *js_state_mask, u32 js_state)
+/* JOB_INT_JS_STATE is a snapshot: it can show a busy slot as idle. */
+static bool panfrost_slots_idle(struct panfrost_device *pfdev)
{
- u32 rawstat;
-
- if (!(js_state & *js_state_mask))
- return 0;
-
- rawstat = job_read(pfdev, JOB_INT_RAWSTAT);
- if (rawstat) {
- unsigned int i;
+ unsigned int i;
- for (i = 0; i < NUM_JOB_SLOTS; i++) {
- if (rawstat & MK_JS_MASK(i))
- *js_state_mask &= ~MK_JS_MASK(i);
- }
+ for (i = 0; i < NUM_JOB_SLOTS; i++) {
+ if (job_read(pfdev, JS_STATUS(i)) ==
+ DRM_PANFROST_EXCEPTION_ACTIVE)
+ return false;
}
- return js_state & *js_state_mask;
+ return true;
}
static void
@@ -671,9 +665,8 @@ 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;
+ bool cookie, idle;
int ret;
if (!atomic_read(&pfdev->reset.pending))
@@ -724,9 +717,8 @@ panfrost_reset(struct panfrost_device *pfdev,
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,
- !panfrost_active_slots(pfdev, &js_state_mask, js_state),
- 10, 10000);
+ ret = read_poll_timeout(panfrost_slots_idle, idle, idle, 10, 10000,
+ false, pfdev);
if (ret)
dev_err(pfdev->base.dev, "Soft-stop failed\n");
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 14/17] drm/panfrost: Keep the GPU powered in the job timeout handler
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (12 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 13/17] drm/panfrost: Wait for the soft-stopped slots with the live slot status Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 15/17] drm/panfrost: Keep the job interrupts masked during a reset Arun Iyengar via B4 Relay
` (2 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
panfrost_job_timedout() accesses the GPU without a runtime PM reference
of its own. If the job completes after the fence check, the GPU can
autosuspend first (clocks off on GPU_PM_RT). Take a reference with
pm_runtime_get_noresume(): if the fence is still unsignalled after
that, the job's own reference was held.
Tested on an H616 with a test-only wait after the fence check: before,
the GPU suspended 50 ms after the fence; after, it stayed active.
Fixes: f3ba91228e8e ("drm/panfrost: Add initial panfrost driver")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-212575@kernel.org/
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: new.
---
drivers/gpu/drm/panfrost/panfrost_job.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index 722f87ebe..74cc3dd02 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -775,8 +775,8 @@ panfrost_reset(struct panfrost_device *pfdev,
dma_fence_end_signalling(cookie);
}
-static enum drm_gpu_sched_stat panfrost_job_timedout(struct drm_sched_job
- *sched_job)
+static enum drm_gpu_sched_stat
+panfrost_job_handle_timeout(struct drm_sched_job *sched_job)
{
struct panfrost_job *job = to_panfrost_job(sched_job);
struct panfrost_device *pfdev = job->pfdev;
@@ -821,6 +821,19 @@ static enum drm_gpu_sched_stat panfrost_job_timedout(struct drm_sched_job
return DRM_GPU_SCHED_STAT_RESET;
}
+static enum drm_gpu_sched_stat panfrost_job_timedout(struct drm_sched_job
+ *sched_job)
+{
+ struct panfrost_device *pfdev = to_panfrost_job(sched_job)->pfdev;
+ enum drm_gpu_sched_stat stat;
+
+ pm_runtime_get_noresume(pfdev->base.dev);
+ stat = panfrost_job_handle_timeout(sched_job);
+ pm_runtime_put_autosuspend(pfdev->base.dev);
+
+ return stat;
+}
+
static void panfrost_reset_work(struct work_struct *work)
{
struct panfrost_device *pfdev;
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 15/17] drm/panfrost: Keep the job interrupts masked during a reset
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (13 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 14/17] drm/panfrost: Keep the GPU powered in the job timeout handler Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 16/17] drm/panfrost: Soft-stop and resume a job that outlives the timeout Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 17/17] drm/panfrost: Name the BOs around an unhandled page fault Arun Iyengar via B4 Relay
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
panfrost_reset() masks the job interrupts without setting
PANFROST_COMP_BIT_JOB, so a running IRQ thread unmasks them. Use
panfrost_jm_suspend_irq() there.
Take job_lock around its mask and set_bit, and around the IRQ
thread's bit test and unmask: a thread that tested the bit before
could otherwise unmask after it, and the hard IRQ handler returns
IRQ_NONE without masking while the bit is set.
Fixes: 1d0cab5461d7 ("drm/panfrost: Make sure job interrupts are masked before resetting")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20261113-panfrost-long-jobs-v3-0-80ae78d38f6e@gmail.com?part=8
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v5: job_lock instead of a second mask write (Sashiko on v4). With a
test-only hold in the IRQ thread after its bit test and a job
interrupt pending, v4 unmasked after the reset's mask (100005
IRQ_NONE, IRQ disabled); v5 did not in 8 of 8 resets (3 IRQ_NONE in
all, at most one per reset).
v4: new (Sashiko on v3 08/14 and 13/14).
---
drivers/gpu/drm/panfrost/panfrost_job.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index 74cc3dd02..ebdf16968 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -455,9 +455,11 @@ void panfrost_jm_enable_interrupts(struct panfrost_device *pfdev)
void panfrost_jm_suspend_irq(struct panfrost_device *pfdev)
{
+ spin_lock(&pfdev->js->job_lock);
+ job_write(pfdev, JOB_INT_MASK, 0);
set_bit(PANFROST_COMP_BIT_JOB, pfdev->is_suspended);
+ spin_unlock(&pfdev->js->job_lock);
- job_write(pfdev, JOB_INT_MASK, 0);
synchronize_irq(pfdev->js->irq);
}
@@ -696,8 +698,7 @@ panfrost_reset(struct panfrost_device *pfdev,
/* Mask job interrupts and synchronize to make sure we won't be
* interrupted during our reset.
*/
- job_write(pfdev, JOB_INT_MASK, 0);
- synchronize_irq(pfdev->js->irq);
+ panfrost_jm_suspend_irq(pfdev);
spin_lock(&pfdev->js->job_lock);
for (i = 0; i < NUM_JOB_SLOTS; i++) {
@@ -860,8 +861,10 @@ static irqreturn_t panfrost_jm_irq_handler_thread(int irq, void *data)
panfrost_jm_handle_irqs(pfdev);
/* Enable interrupts only if we're not about to get suspended */
+ spin_lock(&pfdev->js->job_lock);
if (!test_bit(PANFROST_COMP_BIT_JOB, pfdev->is_suspended))
job_write(pfdev, JOB_INT_MASK, ALL_JS_INT_MASK);
+ spin_unlock(&pfdev->js->job_lock);
return IRQ_HANDLED;
}
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 16/17] drm/panfrost: Soft-stop and resume a job that outlives the timeout
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (14 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 15/17] drm/panfrost: Keep the job interrupts masked during a reset Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 17/17] drm/panfrost: Name the BOs around an unhandled page fault Arun Iyengar via B4 Relay
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
At the 500 ms job timeout panfrost resets the GPU and the job is lost,
but OpenCL kernels and heavy fragment jobs can take seconds on a small
GPU. On a Mali-G31 this fails OpenCL CTS Integer Ops long math and
Thread Dimensions, KHR-GLES31 mixedSequence (a 0.7 s fragment job) and
dEQP-VK spirv_assembly vec4 fragment cases.
Do as the Arm driver does:
- A job still ACTIVE at the timeout is soft-stopped and resumed from
JS_TAIL, without a reset or karma. Its slot gets
JOB_SOFT_STOP_TIMEOUT_MS (5 s) to reach a task boundary.
- A job still active then is hard-stopped and gets karma and a
devcoredump; the other stopped jobs are resumed.
- If the hard stop has no effect within JOB_HARD_STOP_TIMEOUT_MS
(0.5 s), the GPU is reset and that job is failed, not restarted.
- A reset requested meanwhile (job fault, MMU) overrides the stop-only
request, PANFROST_RESET_STOP_ONLY.
- A job that completes between the fence check and the JS_STATUS read
is a spurious timeout.
- Without a reset, the AS references of jobs cancelled from _NEXT are
released here.
With this, those cases pass; two vec4 fragment cases take 4-6 s.
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
v4: the runtime PM reference in panfrost_reset() moved to patch 14.
---
drivers/gpu/drm/panfrost/panfrost_job.c | 152 +++++++++++++++++++++++++++-----
1 file changed, 129 insertions(+), 23 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index ebdf16968..934c5f39f 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -27,6 +27,13 @@
#define MAX_JM_CTX_PER_FILE 64
#define JOB_TIMEOUT_MS 500
+/* Arm driver: DEFAULT_JS_HARD_STOP_TICKS_SS, DEFAULT_JS_RESET_TICKS_SS */
+#define JOB_SOFT_STOP_TIMEOUT_MS 5000
+#define JOB_HARD_STOP_TIMEOUT_MS 500
+
+/* reset.pending: stop the slots, no GPU reset; 1 overrides it */
+#define PANFROST_RESET_STOP_ONLY 2
+
#define job_write(dev, reg, data) writel(data, dev->iomem + (reg))
#define job_read(dev, reg) readl(dev->iomem + (reg))
@@ -662,13 +669,25 @@ static bool panfrost_slots_idle(struct panfrost_device *pfdev)
return true;
}
+/* The second job if the first's DONE is still pending */
+static struct panfrost_job *
+panfrost_running_job(struct panfrost_device *pfdev, unsigned int slot)
+{
+ if (pfdev->jobs[slot][1] &&
+ (job_read(pfdev, JOB_INT_RAWSTAT) & JOB_INT_MASK_DONE(slot)))
+ return pfdev->jobs[slot][1];
+
+ return pfdev->jobs[slot][0];
+}
+
static void
panfrost_reset(struct panfrost_device *pfdev,
- struct drm_sched_job *bad)
+ struct drm_sched_job *bad, bool job_active)
{
struct panfrost_job *evicted[NUM_JOB_SLOTS] = {};
+ struct panfrost_job *hung[NUM_JOB_SLOTS] = {};
+ bool cookie, idle, stop_failed = false, reset_gpu;
unsigned int i, j;
- bool cookie, idle;
int ret;
if (!atomic_read(&pfdev->reset.pending))
@@ -692,7 +711,7 @@ panfrost_reset(struct panfrost_device *pfdev,
cookie = dma_fence_begin_signalling();
- if (bad)
+ if (bad && !job_active)
drm_sched_increase_karma(bad);
/* Mask job interrupts and synchronize to make sure we won't be
@@ -717,20 +736,65 @@ panfrost_reset(struct panfrost_device *pfdev,
}
spin_unlock(&pfdev->js->job_lock);
- /* Wait at most 10ms for soft-stops to complete */
- ret = read_poll_timeout(panfrost_slots_idle, idle, idle, 10, 10000,
+ /* No slot may be active when we touch the queues. */
+ ret = read_poll_timeout(panfrost_slots_idle, idle, idle,
+ job_active ? 200 : 10,
+ job_active ? JOB_SOFT_STOP_TIMEOUT_MS * 1000 : 10000,
false, pfdev);
+ if (ret && job_active) {
+ dev_err(pfdev->base.dev,
+ "Soft-stop failed after %u ms (js status 0x%x 0x%x 0x%x), hard-stopping the active slots\n",
+ JOB_SOFT_STOP_TIMEOUT_MS,
+ job_read(pfdev, JS_STATUS(0)), job_read(pfdev, JS_STATUS(1)),
+ job_read(pfdev, JS_STATUS(2)));
+
+ for (i = 0; i < NUM_JOB_SLOTS; i++) {
+ if (job_read(pfdev, JS_STATUS(i)) ==
+ DRM_PANFROST_EXCEPTION_ACTIVE)
+ hung[i] = panfrost_running_job(pfdev, i);
+ if (hung[i])
+ drm_sched_increase_karma(&hung[i]->base);
+ }
+
+ /* The dump allocates memory: leave the signalling section. */
+ dma_fence_end_signalling(cookie);
+ for (i = 0; i < NUM_JOB_SLOTS; i++) {
+ if (hung[i])
+ panfrost_core_dump(hung[i]);
+ }
+ cookie = dma_fence_begin_signalling();
+
+ for (i = 0; i < NUM_JOB_SLOTS; i++) {
+ if (job_read(pfdev, JS_STATUS(i)) ==
+ DRM_PANFROST_EXCEPTION_ACTIVE)
+ job_write(pfdev, JS_COMMAND(i), JS_COMMAND_HARD_STOP);
+ }
+
+ ret = read_poll_timeout(panfrost_slots_idle, idle, idle, 200,
+ JOB_HARD_STOP_TIMEOUT_MS * 1000, false,
+ pfdev);
+ stop_failed = ret;
+ }
+
if (ret)
- dev_err(pfdev->base.dev, "Soft-stop failed\n");
+ dev_err(pfdev->base.dev,
+ "%s failed (js status 0x%x 0x%x 0x%x), resetting the GPU\n",
+ job_active ? "Hard-stop" : "Soft-stop",
+ job_read(pfdev, JS_STATUS(0)), job_read(pfdev, JS_STATUS(1)),
+ job_read(pfdev, JS_STATUS(2)));
/* Handle the remaining interrupts before we reset. */
panfrost_jm_handle_irqs(pfdev);
+ reset_gpu = !job_active || stop_failed ||
+ atomic_read(&pfdev->reset.pending) != PANFROST_RESET_STOP_ONLY;
+
/* Remaining interrupts have been handled, but we might still have
- * stuck jobs. Let's make sure the PM counters stay balanced by
+ * stuck jobs, and jobs that were waiting in _NEXT when it was
+ * cancelled. Let's make sure the PM counters stay balanced by
* manually calling pm_runtime_put_noidle() and
- * panfrost_devfreq_record_idle() for each stuck job.
+ * panfrost_devfreq_record_idle() for each of them.
* Let's also make sure the cycle counting register's refcnt is
* kept balanced to prevent it from running forever
*/
@@ -740,19 +804,36 @@ panfrost_reset(struct panfrost_device *pfdev,
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++) {
- panfrost_job_put_cycle_counter(pfdev->jobs[i][j]);
+ struct panfrost_job *job = pfdev->jobs[i][j];
+
+ panfrost_job_put_cycle_counter(job);
pm_runtime_put_noidle(pfdev->base.dev);
panfrost_devfreq_record_idle(&pfdev->pfdevfreq);
+
+ /* A GPU reset drops the AS references itself. */
+ if (!reset_gpu)
+ panfrost_mmu_as_put(pfdev, job->mmu);
+
+ /* Restarted, it would only time out again. */
+ if (stop_failed && job == hung[i])
+ dma_fence_set_error(&job->base.s_fence->finished,
+ -ECANCELED);
}
}
memset(pfdev->jobs, 0, sizeof(pfdev->jobs));
spin_unlock(&pfdev->js->job_lock);
/* Proceed with reset now. */
- panfrost_device_reset(pfdev, false);
+ if (reset_gpu) {
+ panfrost_device_reset(pfdev, false);
- /* GPU has been reset, we can clear the reset pending bit. */
- atomic_set(&pfdev->reset.pending, 0);
+ /* GPU has been reset, we can clear the reset pending bit. */
+ atomic_set(&pfdev->reset.pending, 0);
+ } else {
+ /* A reset requested since stays pending for its requester. */
+ atomic_cmpxchg(&pfdev->reset.pending,
+ PANFROST_RESET_STOP_ONLY, 0);
+ }
/* Now resubmit jobs that were previously queued but didn't have a
* chance to finish.
@@ -782,6 +863,8 @@ panfrost_job_handle_timeout(struct drm_sched_job *sched_job)
struct panfrost_job *job = to_panfrost_job(sched_job);
struct panfrost_device *pfdev = job->pfdev;
int js = panfrost_job_get_slot(job);
+ bool job_active;
+ u32 js_status;
/*
* If the GPU managed to complete this jobs fence, the timeout has
@@ -806,18 +889,41 @@ panfrost_job_handle_timeout(struct drm_sched_job *sched_job)
return DRM_GPU_SCHED_STAT_NO_HANG;
}
- dev_err(pfdev->base.dev, "gpu sched timeout, js=%d, config=0x%x, status=0x%x, head=0x%x, tail=0x%x, sched_job=%p",
- js,
- job_read(pfdev, JS_CONFIG(js)),
- job_read(pfdev, JS_STATUS(js)),
- job_read(pfdev, JS_HEAD_LO(js)),
- job_read(pfdev, JS_TAIL_LO(js)),
- sched_job);
+ js_status = job_read(pfdev, JS_STATUS(js));
+ job_active = js_status == DRM_PANFROST_EXCEPTION_ACTIVE;
- panfrost_core_dump(job);
+ /* The job may have completed since the fence check above. */
+ if (!job_active) {
+ if (job_read(pfdev, JOB_INT_RAWSTAT) & JOB_INT_MASK_DONE(js))
+ return DRM_GPU_SCHED_STAT_NO_HANG;
- atomic_set(&pfdev->reset.pending, 1);
- panfrost_reset(pfdev, sched_job);
+ synchronize_irq(pfdev->js->irq);
+ if (dma_fence_is_signaled(job->done_fence))
+ return DRM_GPU_SCHED_STAT_NO_HANG;
+ }
+
+ if (job_active) {
+ dev_dbg(pfdev->base.dev, "job still active after %u ms, js=%d, head=0x%x, sched_job=%p: soft-stopping it to resume",
+ JOB_TIMEOUT_MS, js, job_read(pfdev, JS_HEAD_LO(js)),
+ sched_job);
+ } else {
+ dev_err(pfdev->base.dev, "gpu sched timeout, js=%d, config=0x%x, status=0x%x, head=0x%x, tail=0x%x, sched_job=%p",
+ js,
+ job_read(pfdev, JS_CONFIG(js)),
+ js_status,
+ job_read(pfdev, JS_HEAD_LO(js)),
+ job_read(pfdev, JS_TAIL_LO(js)),
+ sched_job);
+
+ panfrost_core_dump(job);
+ }
+
+ if (job_active)
+ atomic_cmpxchg(&pfdev->reset.pending, 0,
+ PANFROST_RESET_STOP_ONLY);
+ else
+ atomic_set(&pfdev->reset.pending, 1);
+ panfrost_reset(pfdev, sched_job, job_active);
return DRM_GPU_SCHED_STAT_RESET;
}
@@ -844,7 +950,7 @@ static void panfrost_reset_work(struct work_struct *work)
if (pm_runtime_resume_and_get(pfdev->base.dev))
return;
- panfrost_reset(pfdev, NULL);
+ panfrost_reset(pfdev, NULL, false);
pm_runtime_put_autosuspend(pfdev->base.dev);
}
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 17/17] drm/panfrost: Name the BOs around an unhandled page fault
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
` (15 preceding siblings ...)
2026-11-28 17:26 ` [PATCH v5 16/17] drm/panfrost: Soft-stop and resume a job that outlives the timeout Arun Iyengar via B4 Relay
@ 2026-11-28 17:26 ` Arun Iyengar via B4 Relay
16 siblings, 0 replies; 18+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-11-28 17:26 UTC (permalink / raw)
To: Boris Brezillon, Rob Herring, Steven Price, Adrián Larumbe,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
An unhandled GPU page fault reports only the VA, which does not tell
an overrun of a BO from a stale or garbage pointer. Also print the BO
that contains the address, or else its nearest neighbours: VA range,
size, distance, heap/noexec and the userspace label. For an OpenCL
image read on a Mali-G31 it showed the texture unit reading past the
end of a 96-bit-per-texel texture. Heap growth faults are not
affected.
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 76 +++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index 92a4d2963..0f81fee10 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -590,6 +590,81 @@ addr_to_mapping(struct panfrost_device *pfdev, int as, u64 addr)
return mapping;
}
+static void panfrost_mmu_print_fault_bo(struct panfrost_device *pfdev,
+ struct panfrost_gem_mapping *m,
+ u64 addr, const char *where)
+{
+ struct panfrost_gem_object *bo = m->obj;
+ u64 start = m->mmnode.start << PAGE_SHIFT;
+ u64 end = (m->mmnode.start + m->mmnode.size) << PAGE_SHIFT;
+ u64 dist = addr < start ? start - addr : addr >= end ? addr - end : addr - start;
+
+ mutex_lock(&bo->label.lock);
+ dev_err(pfdev->base.dev,
+ "fault bo: %s: VA [0x%llx-0x%llx) size 0x%zx, fault at %s0x%llx%s%s, label \"%s\"\n",
+ where, start, end, bo->base.base.size,
+ addr < start ? "-" : addr >= end ? "end+" : "start+", dist,
+ bo->is_heap ? ", heap" : "", bo->noexec ? ", noexec" : "",
+ bo->label.str ? bo->label.str : "");
+ mutex_unlock(&bo->label.lock);
+}
+
+static void panfrost_mmu_report_fault_bos(struct panfrost_device *pfdev,
+ int as, u64 addr)
+{
+ struct panfrost_gem_mapping *below = NULL, *above = NULL;
+ u64 offset = addr >> PAGE_SHIFT;
+ struct drm_mm_node *node;
+ struct panfrost_mmu *mmu;
+ bool inside = false;
+
+ spin_lock(&pfdev->as_lock);
+ list_for_each_entry(mmu, &pfdev->as_lru_list, list) {
+ if (as == mmu->as)
+ goto found_mmu;
+ }
+ spin_unlock(&pfdev->as_lock);
+ dev_err(pfdev->base.dev, "fault bo: no context holds AS%d\n", as);
+ return;
+
+found_mmu:
+ spin_lock(&mmu->mm_lock);
+ drm_mm_for_each_node(node, &mmu->mm) {
+ struct panfrost_gem_mapping *m = drm_mm_node_to_panfrost_mapping(node);
+
+ if (!kref_read(&m->refcount))
+ continue;
+ if (node->start > offset) {
+ above = m;
+ break;
+ }
+ below = m;
+ }
+ if (below) {
+ inside = offset < below->mmnode.start + below->mmnode.size;
+ if (inside)
+ above = NULL;
+ if (!kref_get_unless_zero(&below->refcount))
+ below = NULL;
+ }
+ if (above && !kref_get_unless_zero(&above->refcount))
+ above = NULL;
+ spin_unlock(&mmu->mm_lock);
+ spin_unlock(&pfdev->as_lock);
+
+ if (!below && !above)
+ dev_err(pfdev->base.dev, "fault bo: AS%d has no BO\n", as);
+ if (below) {
+ panfrost_mmu_print_fault_bo(pfdev, below, addr,
+ inside ? "inside" : "below");
+ panfrost_gem_mapping_put(below);
+ }
+ if (above) {
+ panfrost_mmu_print_fault_bo(pfdev, above, addr, "above");
+ panfrost_gem_mapping_put(above);
+ }
+}
+
#define NUM_FAULT_PAGES (SZ_2M / PAGE_SIZE)
/* [start, end) is whole folios: it can reach past the 2 MB chunk. */
@@ -964,6 +1039,7 @@ static irqreturn_t panfrost_mmu_irq_handler_thread(int irq, void *data)
exception_type, panfrost_exception_name(exception_type),
access_type, access_type_name(pfdev, fault_status),
source_id);
+ panfrost_mmu_report_fault_bos(pfdev, as, addr);
spin_lock(&pfdev->as_lock);
/* Ignore MMU interrupts on this AS until it's been
--
2.55.0
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-11-28 17:27 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 17:26 [PATCH v5 00/17] drm/panfrost: Resume long jobs instead of resetting, and mapping error path fixes Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 01/17] drm/panfrost: Freeze the reset workqueue during system sleep Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 02/17] drm/panfrost: Power the GPU up for a reset queued from the MMU code Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 03/17] drm/panfrost: Refuse to sync the CPU caches of a heap BO Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 04/17] drm/panfrost: Don't take a reference on a mapping that is being freed Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 05/17] drm/panfrost: Don't WARN when a GEM mapping cannot get its pages Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 06/17] drm/panfrost: Unwind a failed GPU mapping without dropping " Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 07/17] drm/panfrost: Give back the pages of a heap chunk that failed to map Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 08/17] drm/panfrost: Don't WARN for a heap folio a neighbouring chunk filled Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 09/17] drm/panfrost: Don't signal a job cancelled from _NEXT at a reset as done Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 10/17] drm/panfrost: Don't cancel a job that completed during a reset Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 11/17] drm/panfrost: Drop the cycle counter only for a job that holds it Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 12/17] drm/panfrost: Don't take a job that was never started for done Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 13/17] drm/panfrost: Wait for the soft-stopped slots with the live slot status Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 14/17] drm/panfrost: Keep the GPU powered in the job timeout handler Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 15/17] drm/panfrost: Keep the job interrupts masked during a reset Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 16/17] drm/panfrost: Soft-stop and resume a job that outlives the timeout Arun Iyengar via B4 Relay
2026-11-28 17:26 ` [PATCH v5 17/17] drm/panfrost: Name the BOs around an unhandled page fault Arun Iyengar via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®