RPM, perfcnt and other minor fixes for Panfrost
Subsystems (3)
Adrián Larumbe
maintainerv2 cover RPM, perfcnt and other minor fixes for Panfrost
This patch series comes with some minor fixes for Panfrost. Some of the issues addressed were uncovered by LLM tools, while the one about RPM was traditionally debugged.
The only proper bug fixes are the ones for perfcnt and RPM, and the others are more about ensuring robustness. perfcnt bug was never observed in the open, because no one had faced a HW reset when a perfcnt session was ongoing. RPM fix addresses a well-known issue I had been observing for quite some time, but that I had completely misunderstood.
---
Changes in v2:
- Fixed race conditions introduced by the previous revision, in the RPM and HWPerf commits specifically. These can be consulted at [1]
- Don't attempt to suspend the device unconditionally at the end ofprobe(), and do it through autosuspend instead.
- Broke the RPM patch into one that fixes PM refcnt proper and another one for MMU enablement at device init time.
- Moved perfcnt GPU disable helper into its own commmit. Same for transplating shrinker initialisation and unplug.
- Added 'Fixes' and 'Reported-by' tags to all the relevant commits
- [1] https://sashiko.dev/#/patchset/20260526-claude-fixes-v1-0-16e92eaa4949%40collabora.com
- Link to v1: https://patch.msgid.link/[email protected]
To: Boris Brezillon <[email protected]>
To: Rob Herring <[email protected]>
To: Steven Price <[email protected]>
To: Adrián Larumbe <[email protected]>
To: Maarten Lankhorst <[email protected]>
To: Maxime Ripard <[email protected]>
To: Thomas Zimmermann <[email protected]>
To: David Airlie <[email protected]>
To: Simona Vetter <[email protected]>
To: Faith Ekstrand <[email protected]>
To: "Marty E. Plummer" <[email protected]>
To: Tomeu Vizoso <[email protected]>
To: Eric Anholt <[email protected]>
To: Alyssa Rosenzweig <[email protected]>
To: Robin Murphy <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Neil Armstrong <[email protected]>
---
Adrián Larumbe (7):
drm/panfrost: Check another bo field for cache option query drm/panfrost: Prevent division by 0
drm/panfrost: Move shrinker initialization and unplug one level down drm/panfrost: Move perfcnt GPU disable sequence into a helper drm/panfrost: Make reset sequence deal with an active HWPerf session drm/panfrost: Fix PM usage_count mishandling drm/panfrost: Explicitly enable MMU interrupts at device init
drivers/gpu/drm/panfrost/panfrost_devfreq.c | 3 +- drivers/gpu/drm/panfrost/panfrost_device.c | 8 +++ drivers/gpu/drm/panfrost/panfrost_drv.c | 14 ++--- drivers/gpu/drm/panfrost/panfrost_gem.h | 4 +- drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c | 8 +-- drivers/gpu/drm/panfrost/panfrost_mmu.c | 11 +++- drivers/gpu/drm/panfrost/panfrost_mmu.h | 2 + drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 77 ++++++++++++++++++------ drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 1 + 9 files changed, 90 insertions(+), 38 deletions(-)
---
base-commit: c1079aebb4de218caa86c44f9a53700d1a582683
change-id: 20260523-claude-fixes-82b03a134a8c
Best regards,
Signature · 1 line
Adrián Larumbe <[email protected]>
Adrián Larumbe
maintainerPATCH v2 1/7 drm/panfrost: Check another bo field for cache option query
When querying the properties of a BO, whether it was created in Writeback caching mode for userspace mappings, is recorded in a Panfrost BO's wb_mmap field.
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
@@ -659,7 +659,7 @@ static int panfrost_ioctl_query_bo_info(struct drm_device *dev, void *data,if (bo->is_heap) args->create_flags |=PANFROST_BO_HEAP ; -if (!bo->base.map_wc) +if (bo->wb_mmap) args->create_flags |=PANFROST_BO_WB_MMAP ; }
Signature · 1 line
2.53.0
Re: [PATCH v2 1/7] drm/panfrost: Check another bo field for cache option query
Quoted 8 lines · On Thu, 04 Jun 2026 18:35:20 +0100 Adrián Larumbe…
When querying the properties of a BO, whether it was created in Writeback caching mode for userspace mappings, is recorded in a Panfrost BO's
wb_mmapfield.Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes 62eedf1ccba5 ("drm/panfrost: Add flag to map GEM object Write-Back Cacheable")
Quoted 18 lines
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_drv.c +1
-1@@ -659,7 +659,7 @@ static int panfrost_ioctl_query_bo_info(struct drm_device *dev, void *data,if (bo->is_heap) args->create_flags |=PANFROST_BO_HEAP ; -if (!bo->base.map_wc) +if (bo->wb_mmap) args->create_flags |=PANFROST_BO_WB_MMAP ; }
Re: [PATCH v2 1/7] drm/panfrost: Check another bo field for cache option query
In reply to Adrián LarumbeQuoted 8 lines · Adrián Larumbe
When querying the properties of a BO, whether it was created in Writeback caching mode for userspace mappings, is recorded in a Panfrost BO's
wb_mmapfield.Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes 62eedf1ccba5 ("drm/panfrost: Add flag to map GEM object Write-Back Cacheable")
This is a subtle change in uABI because bo->base.map_wc reflects the actual properties of the buffer. So on a coherent device this will change. But it does match the intention/documentation of the ioctl (returning the creation flags), and I don't think user space could have been usefully relying on the current behaviour.
Quoted 18 lines
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_drv.c +1
-1@@ -659,7 +659,7 @@ static int panfrost_ioctl_query_bo_info(struct drm_device *dev, void *data,if (bo->is_heap) args->create_flags |=PANFROST_BO_HEAP ; -if (!bo->base.map_wc) +if (bo->wb_mmap) args->create_flags |=PANFROST_BO_WB_MMAP ; }
Adrián Larumbe
maintainerPATCH v2 2/7 drm/panfrost: Prevent division by 0
In reply to Adrián LarumbeWhen updating and debug-printing devfreq stats, in the very unlikely offchance that total device time is less than 100 ns, clamp it to 0 to avoid division by 0.
--- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_devfreq.c +2 -1
@@ -78,7 +78,8 @@ static int panfrost_devfreq_get_dev_status(struct device *dev,dev_dbg (pfdev->base.dev,"busy %lu total %lu %lu %% freq %lu MHz\n" , status->busy_time, status->total_time, - status->busy_time / (status->total_time /100 ), + status->total_time >=100 ? + status->busy_time / (status->total_time /100 ) :0 , status->current_frequency /1000 /1000 );return 0 ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 2/7] drm/panfrost: Prevent division by 0
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The exact same division-by-zero vulnerability fixed in panfrost_devfreq.c is present in the Lima, Panthor, and Nouveau (gk20a) drivers. --
commit dc73067c1030f65e3609c76a060b1b1176f85e4e
Author: Adrián Larumbe <[email protected]>
drm/panfrost: Prevent division by 0
This commit clamps the devfreq total_time to 0 when it is less than 100ns in panfrost_devfreq_get_dev_status() to prevent a division by zero error during debug printing.
drivers/gpu/drm/panfrost/panfrost_devfreq.c static int panfrost_devfreq_get_dev_status(struct device *dev, · line 82
Quoted 11 lines
drivers/gpu/drm/panfrost/panfrost_devfreq.c +2
-1@@ -78,7 +78,8 @@ static int panfrost_devfreq_get_dev_status(struct device *dev, dev_dbg(pfdev->base.dev, "busy %lu total %lu %lu %% freq %lu MHz\n", status->busy_time, status->total_time, - status->busy_time / (status->total_time / 100), + status->total_time >= 100 ? + status->busy_time / (status->total_time / 100) : 0,
[Severity: High]
This is a pre-existing issue, but the exact same division-by-zero vulnerability fixed here is also present in other DRM drivers.
In drivers/gpu/drm/lima/lima_devfreq.c:lima_devfreq_get_dev_status():
status->busy_time / (status->total_time / 100),
In drivers/gpu/drm/panthor/panthor_devfreq.c:panthor_devfreq_get_dev_status():
status->busy_time / (status->total_time / 100),
In drivers/gpu/drm/nouveau/nvkm/subdev/clk/gk20a_devfreq.c:gk20a_devfreq_get_dev_status():
status->busy_time / (status->total_time / 100),
If userspace repeatedly reads the devfreq load in quick succession, total_time can be less than 100ns, leading to a division-by-zero kernel panic when debug printing is enabled.
Should these other drivers be patched similarly?
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_devfreq.c +0
-0status->current_frequency / 1000 / 1000);return 0 ;}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Boris Brezillon
maintainerRe: [PATCH v2 2/7] drm/panfrost: Prevent division by 0
In reply to Adrián LarumbeQuoted 17 lines · On Thu, 04 Jun 2026 18:35:21 +0100 Adrián Larumbe…
When updating and debug-printing devfreq stats, in the very unlikely offchance that total device time is less than 100 ns, clamp it to 0 to avoid division by 0.
Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes f3ba91228e8e ("drm/panfrost: Add initial panfrost driver")--- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_devfreq.c +0
-0
drivers/gpu/drm/panfrost/panfrost_devfreq.c static int panfrost_devfreq_get_dev_status(struct device *dev, · line 82
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_devfreq.c +2
-1@@ -78,7 +78,8 @@ static int panfrost_devfreq_get_dev_status(struct device *dev, dev_dbg(pfdev->base.dev, "busy %lu total %lu %lu %% freq %lu MHz\n", status->busy_time, status->total_time, - status->busy_time / (status->total_time / 100), + status->total_time >= 100 ? + status->busy_time / (status->total_time / 100) : 0,
or:
status->busy_time * 100 / MAX(status->total_time, 1),
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_devfreq.c +0
-0status->current_frequency / 1000 / 1000);return 0 ;
Re: [PATCH v2 2/7] drm/panfrost: Prevent division by 0
Quoted 29 lines · Boris Brezillon
Quoted 17 lines · On Thu, 04 Jun 2026 18:35:21 +0100 Adrián Larumbe…
When updating and debug-printing devfreq stats, in the very unlikely offchance that total device time is less than 100 ns, clamp it to 0 to avoid division by 0.
Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes f3ba91228e8e ("drm/panfrost: Add initial panfrost driver")--- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_devfreq.c +0
-0drivers/gpu/drm/panfrost/panfrost_devfreq.c static int panfrost_devfreq_get_dev_status(struct device *dev, · line 82
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_devfreq.c +2
-1@@ -78,7 +78,8 @@ static int panfrost_devfreq_get_dev_status(struct device *dev, dev_dbg(pfdev->base.dev, "busy %lu total %lu %lu %% freq %lu MHz\n", status->busy_time, status->total_time, - status->busy_time / (status->total_time / 100), + status->total_time >= 100 ? + status->busy_time / (status->total_time / 100) : 0,or:
Quoted 2 lines
status->busy_time * 100 / MAX(status->total_time, 1),
I have to admit I prefer Boris' version ;)
But either way:
Quoted 5 lines
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_devfreq.c +0
-0status->current_frequency / 1000 / 1000);return 0 ;
Adrián Larumbe
maintainerRe: [PATCH v2 2/7] drm/panfrost: Prevent division by 0
Quoted 30 lines · Steven Price
Quoted 29 lines · Boris Brezillon
Quoted 17 lines · On Thu, 04 Jun 2026 18:35:21 +0100 Adrián Larumbe…
When updating and debug-printing devfreq stats, in the very unlikely offchance that total device time is less than 100 ns, clamp it to 0 to avoid division by 0.
Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes f3ba91228e8e ("drm/panfrost: Add initial panfrost driver")--- drivers/gpu/drm/panfrost/panfrost_devfreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_devfreq.c +0
-0drivers/gpu/drm/panfrost/panfrost_devfreq.c static int panfrost_devfreq_get_dev_status(struct device *dev, · line 82
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_devfreq.c +2
-1@@ -78,7 +78,8 @@ static int panfrost_devfreq_get_dev_status(struct device *dev, dev_dbg(pfdev->base.dev, "busy %lu total %lu %lu %% freq %lu MHz\n", status->busy_time, status->total_time, - status->busy_time / (status->total_time / 100), + status->total_time >= 100 ? + status->busy_time / (status->total_time / 100) : 0,or:
Quoted 6 lines
Quoted 2 lines
status->busy_time * 100 / MAX(status->total_time, 1),I have to admit I prefer Boris' version ;)
But either way:
Me too, I'm picking it for the next revision.
Quoted 7 lines
Reviewed-by Steven Price <[email protected]>Quoted 5 lines
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_devfreq.c +0
-0status->current_frequency / 1000 / 1000);return 0 ;
Adrian Larumbe
Adrián Larumbe
maintainerPATCH v2 3/7 drm/panfrost: Move shrinker initialization and unplug one level down
In reply to Adrián LarumbeSince the moment we call drm_dev_register() the device should be in a position to accept jobs, so it's best if the shrinker is already initialized by then.
On top of that, make shrinker functions take an panfrost_device pointer like other functions in the same sequence and rename them accordingly.
Essentially mimic the init/fini behaviour in Panthor.
--- drivers/gpu/drm/panfrost/panfrost_device.c | 7 +++++++ drivers/gpu/drm/panfrost/panfrost_drv.c | 6 ------ drivers/gpu/drm/panfrost/panfrost_gem.h | 4 ++-- drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c | 8 ++------ 4 files changed, 11 insertions(+), 14 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.c +7 -0
@@ -282,9 +282,15 @@ int panfrost_device_init(struct panfrost_device *pfdev)if (err) goto out_job; + err =panfrost_gem_shrinker_init (pfdev); +if (err) + goto out_perfcnt; +panfrost_gem_init (pfdev);return 0 ; +out_perfcnt: +panfrost_perfcnt_fini (pfdev); out_job:panfrost_jm_fini (pfdev); out_mmu:
@@ -306,6 +312,7 @@ int panfrost_device_init(struct panfrost_device *pfdev)void panfrost_device_fini (struct panfrost_device *pfdev) { +panfrost_gem_shrinker_fini (pfdev);panfrost_perfcnt_fini (pfdev);panfrost_jm_fini (pfdev);panfrost_mmu_fini (pfdev);
drivers/gpu/drm/panfrost/panfrost_drv.c +0 -6
@@ -1000,14 +1000,9 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; - err =panfrost_gem_shrinker_init (&pfdev->base); -if (err) - goto err_out2;return 0 ; -err_out2: -drm_dev_unregister (&pfdev->base); err_out1:pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);
@@ -1021,7 +1016,6 @@ static void panfrost_remove(struct platform_device *pdev)struct panfrost_device *pfdev =platform_get_drvdata (pdev);drm_dev_unregister (&pfdev->base); -panfrost_gem_shrinker_cleanup (&pfdev->base);pm_runtime_get_sync (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);
drivers/gpu/drm/panfrost/panfrost_gem.h +2 -2
@@ -154,8 +154,8 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo,void panfrost_gem_mapping_put (struct panfrost_gem_mapping *mapping);void panfrost_gem_teardown_mappings_locked (struct panfrost_gem_object *bo); -int panfrost_gem_shrinker_init (struct drm_device *dev); -void panfrost_gem_shrinker_cleanup (struct drm_device *dev); +int panfrost_gem_shrinker_init (struct panfrost_device *pfdev); +void panfrost_gem_shrinker_fini (struct panfrost_device *pfdev);void panfrost_gem_set_label (struct drm_gem_object *obj,const char *label); int panfrost_gem_sync(struct drm_gem_object *obj, u32 type,
drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +2 -6
@@ -95,10 +95,8 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)* * This function registers and sets up the panfrost shrinker. */ -int panfrost_gem_shrinker_init (struct drm_device *dev) +int panfrost_gem_shrinker_init (struct panfrost_device *pfdev) { -struct panfrost_device *pfdev =to_panfrost_device (dev); - pfdev->shrinker =shrinker_alloc (0 ,"drm-panfrost" );if (!pfdev->shrinker)return -ENOMEM ;
@@ -118,10 +116,8 @@ int panfrost_gem_shrinker_init(struct drm_device *dev)* * This function unregisters the panfrost shrinker. */ -void panfrost_gem_shrinker_cleanup (struct drm_device *dev) +void panfrost_gem_shrinker_fini (struct panfrost_device *pfdev) { -struct panfrost_device *pfdev =to_panfrost_device (dev); -if (pfdev->shrinker)shrinker_free (pfdev->shrinker); }
Signature · 1 line
2.53.0
Boris Brezillon
maintainerRe: [PATCH v2 3/7] drm/panfrost: Move shrinker initialization and unplug one level down
Quoted 22 lines · On Thu, 04 Jun 2026 18:35:22 +0100 Adrián Larumbe…
Since the moment we call
drm_dev_register()the device should be in a position to accept jobs, so it's best if the shrinker is already initialized by then.On top of that, make shrinker functions take an
panfrost_devicepointer like other functions in the same sequence and rename them accordingly.Essentially mimic the init/fini behaviour in Panthor.
Signed-off-by Adrián Larumbe <[email protected]>--- drivers/gpu/drm/panfrost/panfrost_device.c | 7 +++++++ drivers/gpu/drm/panfrost/panfrost_drv.c | 6 ------ drivers/gpu/drm/panfrost/panfrost_gem.h | 4 ++-- drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c | 8 ++------ 4 files changed, 11 insertions(+), 14 deletions(-)drivers/gpu/drm/panfrost/panfrost_device.c +0
-0
drivers/gpu/drm/panfrost/panfrost_device.c int panfrost_device_init(struct panfrost_device *pfdev) · line 289
Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_device.c +4
-0@@ -282,9 +282,15 @@ int panfrost_device_init(struct panfrost_device *pfdev)if (err) goto out_job; + err =panfrost_gem_shrinker_init (pfdev); +if (err) + goto out_perfcnt; +panfrost_gem_init (pfdev);
It feels weird to have the GEM shrinker initialized before the GEM component. Also, I'd consider the shrinker part of the GEM logic, so maybe call panfrost_gem_shrinker_init() from panfrost_gem_init() and change the prototype of panfrost_gem_init() to return an int.
Quoted 86 lines
drivers/gpu/drm/panfrost/panfrost_device.c +3
-0return 0 ; +out_perfcnt: +panfrost_perfcnt_fini (pfdev); out_job:panfrost_jm_fini (pfdev); out_mmu:@@ -306,6 +312,7 @@ int panfrost_device_init(struct panfrost_device *pfdev)void panfrost_device_fini (struct panfrost_device *pfdev) { +panfrost_gem_shrinker_fini (pfdev);panfrost_perfcnt_fini (pfdev);panfrost_jm_fini (pfdev);panfrost_mmu_fini (pfdev);drivers/gpu/drm/panfrost/panfrost_drv.c +0
-6@@ -1000,14 +1000,9 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; - err =panfrost_gem_shrinker_init (&pfdev->base); -if (err) - goto err_out2;return 0 ; -err_out2: -drm_dev_unregister (&pfdev->base); err_out1:pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);@@ -1021,7 +1016,6 @@ static void panfrost_remove(struct platform_device *pdev)struct panfrost_device *pfdev =platform_get_drvdata (pdev);drm_dev_unregister (&pfdev->base); -panfrost_gem_shrinker_cleanup (&pfdev->base);pm_runtime_get_sync (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);drivers/gpu/drm/panfrost/panfrost_gem.h +2
-2@@ -154,8 +154,8 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo,void panfrost_gem_mapping_put (struct panfrost_gem_mapping *mapping);void panfrost_gem_teardown_mappings_locked (struct panfrost_gem_object *bo); -int panfrost_gem_shrinker_init (struct drm_device *dev); -void panfrost_gem_shrinker_cleanup (struct drm_device *dev); +int panfrost_gem_shrinker_init (struct panfrost_device *pfdev); +void panfrost_gem_shrinker_fini (struct panfrost_device *pfdev);void panfrost_gem_set_label (struct drm_gem_object *obj,const char *label); int panfrost_gem_sync(struct drm_gem_object *obj, u32 type,drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +2
-6@@ -95,10 +95,8 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)* * This function registers and sets up the panfrost shrinker. */ -int panfrost_gem_shrinker_init (struct drm_device *dev) +int panfrost_gem_shrinker_init (struct panfrost_device *pfdev) { -struct panfrost_device *pfdev =to_panfrost_device (dev); - pfdev->shrinker =shrinker_alloc (0 ,"drm-panfrost" );if (!pfdev->shrinker)return -ENOMEM ;@@ -118,10 +116,8 @@ int panfrost_gem_shrinker_init(struct drm_device *dev)* * This function unregisters the panfrost shrinker. */ -void panfrost_gem_shrinker_cleanup (struct drm_device *dev) +void panfrost_gem_shrinker_fini (struct panfrost_device *pfdev) { -struct panfrost_device *pfdev =to_panfrost_device (dev); -if (pfdev->shrinker)shrinker_free (pfdev->shrinker); }
Adrián Larumbe
maintainerRe: [PATCH v2 3/7] drm/panfrost: Move shrinker initialization and unplug one level down
Quoted 28 lines · Boris Brezillon
Quoted 25 lines · On Thu, 04 Jun 2026 18:35:22 +0100 Adrián Larumbe…
Since the moment we call
drm_dev_register()the device should be in a position to accept jobs, so it's best if the shrinker is already initialized by then.On top of that, make shrinker functions take an
panfrost_devicepointer like other functions in the same sequence and rename them accordingly.Essentially mimic the init/fini behaviour in Panthor.
Signed-off-by Adrián Larumbe <[email protected]>--- drivers/gpu/drm/panfrost/panfrost_device.c | 7 +++++++ drivers/gpu/drm/panfrost/panfrost_drv.c | 6 ------ drivers/gpu/drm/panfrost/panfrost_gem.h | 4 ++-- drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c | 8 ++------ 4 files changed, 11 insertions(+), 14 deletions(-)drivers/gpu/drm/panfrost/panfrost_device.c +0
-0@@ -282,9 +282,15 @@ int panfrost_device_init(struct panfrost_device *pfdev)if (err) goto out_job;
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_device.c int panfrost_device_init(struct panfrost_device *pfdev) · line 289
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_device.c +4
-0+ err =panfrost_gem_shrinker_init (pfdev); +if (err) + goto out_perfcnt; +panfrost_gem_init (pfdev);It feels weird to have the GEM shrinker initialized before the GEM component. Also, I'd consider the shrinker part of the GEM logic, so maybe call
panfrost_gem_shrinker_init()frompanfrost_gem_init()and change the prototype ofpanfrost_gem_init()to return an int.
Will move the code around in the next revision.
Quoted 78 lines
Quoted 78 lines
drivers/gpu/drm/panfrost/panfrost_device.c +3
-0return 0 ; +out_perfcnt: +panfrost_perfcnt_fini (pfdev); out_job:panfrost_jm_fini (pfdev); out_mmu:@@ -306,6 +312,7 @@ int panfrost_device_init(struct panfrost_device *pfdev)void panfrost_device_fini (struct panfrost_device *pfdev) { +panfrost_gem_shrinker_fini (pfdev);panfrost_perfcnt_fini (pfdev);panfrost_jm_fini (pfdev);panfrost_mmu_fini (pfdev);drivers/gpu/drm/panfrost/panfrost_drv.c +0
-6@@ -1000,14 +1000,9 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; - err =panfrost_gem_shrinker_init (&pfdev->base); -if (err) - goto err_out2;return 0 ; -err_out2: -drm_dev_unregister (&pfdev->base); err_out1:pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);@@ -1021,7 +1016,6 @@ static void panfrost_remove(struct platform_device *pdev)struct panfrost_device *pfdev =platform_get_drvdata (pdev);drm_dev_unregister (&pfdev->base); -panfrost_gem_shrinker_cleanup (&pfdev->base);pm_runtime_get_sync (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);drivers/gpu/drm/panfrost/panfrost_gem.h +2
-2@@ -154,8 +154,8 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo,void panfrost_gem_mapping_put (struct panfrost_gem_mapping *mapping);void panfrost_gem_teardown_mappings_locked (struct panfrost_gem_object *bo); -int panfrost_gem_shrinker_init (struct drm_device *dev); -void panfrost_gem_shrinker_cleanup (struct drm_device *dev); +int panfrost_gem_shrinker_init (struct panfrost_device *pfdev); +void panfrost_gem_shrinker_fini (struct panfrost_device *pfdev);void panfrost_gem_set_label (struct drm_gem_object *obj,const char *label); int panfrost_gem_sync(struct drm_gem_object *obj, u32 type,drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +1
-4@@ -95,10 +95,8 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)* * This function registers and sets up the panfrost shrinker. */ -int panfrost_gem_shrinker_init (struct drm_device *dev) +int panfrost_gem_shrinker_init (struct panfrost_device *pfdev) { -struct panfrost_device *pfdev =to_panfrost_device (dev); - pfdev->shrinker =shrinker_alloc (0 ,"drm-panfrost" );if (!pfdev->shrinker)return -ENOMEM ;@@ -118,10 +116,8 @@ int panfrost_gem_shrinker_init(struct drm_device *dev)* * This function unregisters the panfrost shrinker. */ -void panfrost_gem_shrinker_cleanup (struct drm_device *dev)
Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c int panfrost_gem_shrinker_init(struct drm_device *dev) · line 123
Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +1
-2+void panfrost_gem_shrinker_fini (struct panfrost_device *pfdev) { -struct panfrost_device *pfdev =to_panfrost_device (dev); -if (pfdev->shrinker)shrinker_free (pfdev->shrinker); }
Adrian Larumbe
Adrián Larumbe
maintainerPATCH v2 4/7 drm/panfrost: Move perfcnt GPU disable sequence into a helper
In reply to Adrián LarumbeJust for the sake of avoiding repetition.
--- drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 31 ++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-)
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +13 -18
@@ -35,6 +35,16 @@ struct panfrost_perfcnt {struct completion dump_comp; }; +static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev) +{ +gpu_write (pfdev,GPU_PERFCNT_CFG , +GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +} +void panfrost_perfcnt_clean_cache_done (struct panfrost_device *pfdev) {complete (&pfdev->perfcnt->dump_comp);
@@ -193,12 +203,7 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,if (user != perfcnt->user)return -EINVAL ; -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +panfrost_perfcnt_gpu_disable (pfdev); perfcnt->user =NULL ;drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map);
@@ -327,12 +332,7 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev) perfcnt->bosize = size;/* Start with everything disabled. */ -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +panfrost_perfcnt_gpu_disable (pfdev);init_completion (&perfcnt->dump_comp);mutex_init (&perfcnt->lock);
@@ -344,10 +344,5 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev)void panfrost_perfcnt_fini (struct panfrost_device *pfdev) {/* Disable everything before leaving. */ -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +panfrost_perfcnt_gpu_disable (pfdev); }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 4/7] drm/panfrost: Move perfcnt GPU disable sequence into a helper
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The refactored `panfrost_perfcnt_gpu_disable()` helper reverses the register write sequence when…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The refactored panfrost_perfcnt_gpu_disable() helper reverses the register write sequence when disabling performance counters, potentially breaking the HW_ISSUE_8186 (PRLAM-8186) hardware workaround and risking hardware state corruption. --
commit b1a0eb47a40de5889be52c5109cc3ee780f78598
Author: Adrián Larumbe <[email protected]>
drm/panfrost: Move perfcnt GPU disable sequence into a helper
This commit refactors the performance counter disable sequences into a single helper function to avoid repetition.
Quoted 7 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +0
-0@@ -35,6 +35,16 @@ struct panfrost_perfcnt {struct completion dump_comp; };
drivers/gpu/drm/panfrost/panfrost_perfcnt.c struct panfrost_perfcnt { · line 46
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +9
-0+static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev) +{ +gpu_write (pfdev,GPU_PERFCNT_CFG , +GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +}
[Severity: High]
Does this new helper reverse the hardware disable sequence when called on actively running counters?
In the original panfrost_perfcnt_disable_locked(), the block enable registers (like GPU_PRFCNT_TILER_EN) were explicitly cleared to 0 before the master configuration GPU_PERFCNT_CFG was turned off. The new helper reverses this order.
Could shutting down the master configuration while sub-blocks are still actively generating events cause hardware state corruption or bus hangs?
Modifying the main configuration while the Tiler counters are actively enabled might also trigger hardware bugs (e.g., HW_ISSUE_8186), which the original sequence safely avoided.
[ ... ]
Quoted 11 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-6@@ -193,12 +203,7 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,if (user != perfcnt->user)return -EINVAL ; -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +panfrost_perfcnt_gpu_disable (pfdev);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v2 4/7] drm/panfrost: Move perfcnt GPU disable sequence into a helper
In reply to Adrián LarumbeQuoted 3 lines · On Thu, 04 Jun 2026 18:35:23 +0100 Adrián Larumbe…
Just for the sake of avoiding repetition.
Signed-off-by Adrián Larumbe <[email protected]>
Quoted 66 lines
--- drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 31 ++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-)drivers/gpu/drm/panfrost/panfrost_perfcnt.c +13
-18@@ -35,6 +35,16 @@ struct panfrost_perfcnt {struct completion dump_comp; }; +static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev) +{ +gpu_write (pfdev,GPU_PERFCNT_CFG , +GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +} +void panfrost_perfcnt_clean_cache_done (struct panfrost_device *pfdev) {complete (&pfdev->perfcnt->dump_comp);@@ -193,12 +203,7 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,if (user != perfcnt->user)return -EINVAL ; -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +panfrost_perfcnt_gpu_disable (pfdev); perfcnt->user =NULL ;drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map);@@ -327,12 +332,7 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev) perfcnt->bosize = size;/* Start with everything disabled. */ -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +panfrost_perfcnt_gpu_disable (pfdev);init_completion (&perfcnt->dump_comp);mutex_init (&perfcnt->lock);@@ -344,10 +344,5 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev)void panfrost_perfcnt_fini (struct panfrost_device *pfdev) {/* Disable everything before leaving. */ -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +panfrost_perfcnt_gpu_disable (pfdev); }
Re: [PATCH v2 4/7] drm/panfrost: Move perfcnt GPU disable sequence into a helper
In reply to Adrián LarumbeQuoted 3 lines · Adrián Larumbe
Just for the sake of avoiding repetition.
Signed-off-by Adrián Larumbe <[email protected]>
Quoted 66 lines
--- drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 31 ++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-)drivers/gpu/drm/panfrost/panfrost_perfcnt.c +13
-18@@ -35,6 +35,16 @@ struct panfrost_perfcnt {struct completion dump_comp; }; +static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev) +{ +gpu_write (pfdev,GPU_PERFCNT_CFG , +GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +} +void panfrost_perfcnt_clean_cache_done (struct panfrost_device *pfdev) {complete (&pfdev->perfcnt->dump_comp);@@ -193,12 +203,7 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,if (user != perfcnt->user)return -EINVAL ; -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +panfrost_perfcnt_gpu_disable (pfdev); perfcnt->user =NULL ;drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map);@@ -327,12 +332,7 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev) perfcnt->bosize = size;/* Start with everything disabled. */ -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +panfrost_perfcnt_gpu_disable (pfdev);init_completion (&perfcnt->dump_comp);mutex_init (&perfcnt->lock);@@ -344,10 +344,5 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev)void panfrost_perfcnt_fini (struct panfrost_device *pfdev) {/* Disable everything before leaving. */ -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +panfrost_perfcnt_gpu_disable (pfdev); }
Adrián Larumbe
maintainerPATCH v2 5/7 drm/panfrost: Make reset sequence deal with an active HWPerf session
In reply to Adrián LarumbeRight now, if there's a HW reset and an HWPerf session is active, panfrost_mmu_reset() will reset the AS count for every single open file's mmu struct back to 0, and also invalidate their AS numbers. Then, when disabling hwperf, panfrost_mmu_as_put() will WARN that mmu->as_count is less than zero.
Fix this by introducing a perfcnt HW reset path.
The choice was made to render perfcnt unusable after reset, so that a user might have to reprogram it with a full disable/enable sequence before requesting more perfcnt dumps.
--- drivers/gpu/drm/panfrost/panfrost_device.c | 1 + drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 46 ++++++++++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_device.c +1 -0
@@ -426,6 +426,7 @@ bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev,void panfrost_device_reset (struct panfrost_device *pfdev,bool enable_job_int) { +panfrost_perfcnt_reset (pfdev);panfrost_gpu_soft_reset (pfdev);panfrost_gpu_power_on (pfdev);
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +45 -1
88 lines not on this page · raw message
drivers/gpu/drm/panfrost/panfrost_perfcnt.h +1 -0
@@ -14,5 +14,6 @@ int panfrost_ioctl_perfcnt_enable(struct drm_device *dev, void *data, struct drm_file *file_priv);int panfrost_ioctl_perfcnt_dump (struct drm_device *dev,void *data,struct drm_file *file_priv); +void panfrost_perfcnt_reset (struct panfrost_device *pfdev);#endif
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Address Space reference (mmu->as_count) permanently leaks when hardware reset aborts…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Address Space reference (mmu->as_count) permanently leaks when hardware reset aborts perfcnt_enable_locked.
- [High] A TOCTOU race between disable_locked and the asynchronous reset workqueue reintroduces the mmu->as_count underflow WARN.
- [Medium] A positive error code (EAGAIN) is incorrectly returned directly to userspace instead of the negative standard (-EAGAIN).
- [Medium] Spurious initialization failures occur for new perfcnt sessions due to a stale hw_reset_happened flag. --
commit 555dc068f79668462a998f3ee4fa95ead697090d
Author: Adrián Larumbe <[email protected]>
drm/panfrost: Make reset sequence deal with an active HWPerf session
This commit introduces a perfcnt HW reset path to handle active HWPerf sessions during a HW reset. It renders perfcnt unusable after reset and notifies the user to take recovery measures.
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +0
-0
[ ... ]
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 196
Quoted 11 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +7
-0@@ -173,6 +187,16 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,if (panfrost_has_hw_issue (pfdev,HW_ISSUE_8186 ))gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0xffffffff ); +/* If a reset happened, we've no way of knowing whether it was between the time we called +* panfrost_mmu_as_get() or before perfcnt_enable(), so clearing this flag and going forward +* isn't possible. We must clear the flag and try again in the hopes no resets will happen +* between this and the next ioctl invocation. +*/ +if (atomic_cmpxchg (&perfcnt->hw_reset_happened,1 ,0 )) { + ret =EAGAIN ;
[Severity: Medium]
Does this return a positive error code directly to userspace instead of the standard negative one (-EAGAIN)?
DRM ioctls pass positive return values directly back to user space as the ioctl syscall result. Because of this, user space will incorrectly interpret this as success and subsequently fail on dump ioctls since the session wasn't actually enabled.
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 197
Quoted 1 line
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0+ goto err_disable;
[Severity: High]
Can this leak the Address Space reference if a hardware reset aborts the enable sequence?
If a GPU reset occurs before panfrost_mmu_as_get() is called, the reset handler clears mmu->as_count to 0, and then panfrost_mmu_as_get() increments it to 1. The code subsequently detects the reset via the hw_reset_happened flag, clears it, and jumps to err_disable here. Because err_disable skips panfrost_mmu_as_put(), the AS slot reference is permanently leaked, eventually exhausting the limited hardware AS slots.
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+ } +/* The BO ref is retained by the mapping. */ drm_gem_object_put (&bo->base);
[ ... ]
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev, · line 239
Quoted 7 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-1@@ -209,7 +235,8 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map); perfcnt->buf =NULL ;panfrost_gem_close (&perfcnt->mapping->obj->base.base, file_priv); -panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu); +if (!atomic_read (&perfcnt->hw_reset_happened)) +panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);
[Severity: High]
Could a race between this check and an asynchronous reset reintroduce the mmu->as_count underflow WARN that this patch was explicitly intended to prevent?
The non-atomic gap between reading the flag and executing panfrost_mmu_as_put() creates an exposure window. If an interleaved asynchronous hardware reset occurs in this window, panfrost_device_reset() will clear mmu->as_count to 0. The subsequent execution of panfrost_mmu_as_put() decrements it to -1, directly triggering the WARN.
Quoted 3 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +0
-0panfrost_gem_mapping_put (perfcnt->mapping); perfcnt->mapping =NULL ;pm_runtime_put_autosuspend (pfdev->base.dev);
[ ... ]
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +6
-0@@ -346,3 +373,20 @@ void panfrost_perfcnt_fini(struct panfrost_device *pfdev)/* Disable everything before leaving. */ panfrost_perfcnt_gpu_disable (pfdev); } + +void panfrost_perfcnt_reset (struct panfrost_device *pfdev) +{ +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt; + +/* Since this function will be called either from a scheduled HW reset
drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 391
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +10
-0+* or a runtime resume, tearing down any perfcnt resources means we're +* doomed to deadlocking with perfcnt_{enable/disable}, since we'd have +* to take the perfecnt lock. On top of that, it'd also violate DMA fence +* signalling rules because GFP_KERNEL allocations are made with the perfcnt +* lock taken in perfcnt_enable. In light of this, the only thing we can do +* is disabling perfcnt unconditionally, and notifying the perfcnt user of +* the reset having happpened so that they can take recovery measures. +*/ +panfrost_perfcnt_gpu_disable (pfdev); +atomic_set (&perfcnt->hw_reset_happened,1 );
[Severity: Medium]
Will this unconditionally set the reset flag even if no perfcnt session is active, causing the next new session to spuriously fail?
Since this function is called during any GPU reset, it sets the flag even when perfcnt->user == NULL. If user space later attempts to start a completely new session, panfrost_perfcnt_enable_locked() will consume this stale flag and abort with EAGAIN, functionally breaking the feature on the first attempt after a reset.
Quoted 1 line
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Adrián Larumbe
maintainerRe: [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session
Quoted 117 lines · On 2026-06-04 17:49:17+00:00, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Address Space reference (mmu->as_count) permanently leaks when hardware reset abortsperfcnt_enable_locked.
- [High] A TOCTOU race betweendisable_lockedand the asynchronous reset workqueue reintroduces themmu->as_countunderflow WARN.
- [Medium] A positive error code (EAGAIN) is incorrectly returned directly to userspace instead of the negative standard (-EAGAIN).
- [Medium] Spurious initialization failures occur for new perfcnt sessions due to a stalehw_reset_happenedflag. --commit
555dc068f79668462a998f3ee4fa95ead697090d
Author: Adrián Larumbe <[email protected]>drm/panfrost: Make reset sequence deal with an active HWPerf session
This commit introduces a perfcnt HW reset path to handle active HWPerf sessions during a HW reset. It renders perfcnt unusable after reset and notifies the user to take recovery measures.
Fixes 7786fd108777 ("drm/panfrost: Expose performance counters through unstable ioctls")Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +0
-0[ ... ]
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 196
Quoted 11 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +7
-0@@ -173,6 +187,16 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,if (panfrost_has_hw_issue (pfdev,HW_ISSUE_8186 ))gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0xffffffff ); +/* If a reset happened, we've no way of knowing whether it was between the time we called +* panfrost_mmu_as_get() or before perfcnt_enable(), so clearing this flag and going forward +* isn't possible. We must clear the flag and try again in the hopes no resets will happen +* between this and the next ioctl invocation. +*/ +if (atomic_cmpxchg (&perfcnt->hw_reset_happened,1 ,0 )) { + ret =EAGAIN ;[Severity: Medium]
Does this return a positive error code directly to userspace instead of the standard negative one (-EAGAIN)?DRM ioctls pass positive return values directly back to user space as the ioctl syscall result. Because of this, user space will incorrectly interpret this as success and subsequently fail on dump ioctls since the session wasn't actually enabled.
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 197
Quoted 1 line
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0+ goto err_disable;[Severity: High]
Can this leak the Address Space reference if a hardware reset aborts the enable sequence?If a GPU reset occurs before
panfrost_mmu_as_get()is called, the reset handler clearsmmu->as_countto 0, and thenpanfrost_mmu_as_get()increments it to 1. The code subsequently detects the reset via thehw_reset_happenedflag, clears it, and jumps toerr_disablehere. Becauseerr_disableskipspanfrost_mmu_as_put(), the AS slot reference is permanently leaked, eventually exhausting the limited hardware AS slots.Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+ } +/* The BO ref is retained by the mapping. */ drm_gem_object_put (&bo->base);[ ... ]
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev, · line 239
Quoted 7 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-1@@ -209,7 +235,8 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map); perfcnt->buf =NULL ;panfrost_gem_close (&perfcnt->mapping->obj->base.base, file_priv); -panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu); +if (!atomic_read (&perfcnt->hw_reset_happened)) +panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);[Severity: High]
Could a race between this check and an asynchronous reset reintroduce themmu->as_countunderflow WARN that this patch was explicitly intended to prevent?The non-atomic gap between reading the flag and executing
panfrost_mmu_as_put()creates an exposure window. If an interleaved asynchronous hardware reset occurs in this window,panfrost_device_reset()will clearmmu->as_countto 0. The subsequent execution ofpanfrost_mmu_as_put()decrements it to -1, directly triggering the WARN.Quoted 3 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +0
-0panfrost_gem_mapping_put (perfcnt->mapping); perfcnt->mapping =NULL ;pm_runtime_put_autosuspend (pfdev->base.dev);[ ... ]
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +6
-0@@ -346,3 +373,20 @@ void panfrost_perfcnt_fini(struct panfrost_device *pfdev)/* Disable everything before leaving. */ panfrost_perfcnt_gpu_disable (pfdev); } + +void panfrost_perfcnt_reset (struct panfrost_device *pfdev) +{ +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt; + +/* Since this function will be called either from a scheduled HW reset drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 391
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +10
-0+* or a runtime resume, tearing down any perfcnt resources means we're +* doomed to deadlocking with perfcnt_{enable/disable}, since we'd have +* to take the perfecnt lock. On top of that, it'd also violate DMA fence +* signalling rules because GFP_KERNEL allocations are made with the perfcnt +* lock taken in perfcnt_enable. In light of this, the only thing we can do +* is disabling perfcnt unconditionally, and notifying the perfcnt user of +* the reset having happpened so that they can take recovery measures. +*/ +panfrost_perfcnt_gpu_disable (pfdev); +atomic_set (&perfcnt->hw_reset_happened,1 );[Severity: Medium]
Will this unconditionally set the reset flag even if no perfcnt session is active, causing the next new session to spuriously fail?
Quoted 5 lines
Since this function is called during any GPU reset, it sets the flag even when
perfcnt->user== NULL. If user space later attempts to start a completely new session,panfrost_perfcnt_enable_locked()will consume this stale flag and abort with EAGAIN, functionally breaking the feature on the first attempt after a reset.
Revealed by b4 review tui:
"For HW with HW_ISSUE_8186 (the Tiler-counter erratum that the enable path goes out of its way to handle by toggling Tiler around the CFG write), turning off the master CFG while Tiler counters are still enabled is the exact ordering the enable path tries to avoid. The commit message does not acknowledge this functional change, and there is no analysis of whether the new sequence is safe on HW_ISSUE_8186 parts. (Also flagged by sashiko-bot.) **Suggested fix:** Either preserve the original disable order in the helper (zero block enables before clearing CFG), or document/justify in the commit message that the new order is safe on all supported GPUs including HW_ISSUE_8186 ones, and drop the "no functional change" framing."
If it's true this breaks a HW quirk workaround, I might have to drop this patch altogether.
Boris Brezillon
maintainerRe: [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session
In reply to Adrián LarumbeQuoted 11 lines · On Thu, 04 Jun 2026 18:35:24 +0100 Adrián Larumbe…
Right now, if there's a HW reset and an HWPerf session is active,
panfrost_mmu_reset()will reset the AS count for every single open file's mmu struct back to 0, and also invalidate their AS numbers. Then, when disabling hwperf,panfrost_mmu_as_put()will WARN thatmmu->as_countis less than zero.Fix this by introducing a perfcnt HW reset path.
The choice was made to render perfcnt unusable after reset, so that a user might have to reprogram it with a full disable/enable sequence before requesting more perfcnt dumps.
Can't we do better than that. We store the config of the perf session, so if a reset is in progress, we can simply block on it, restore the old config in the post_reset path, and get going with the DUMP request once the reset has been done. There's certainly something to do to report the discontinuity to userspace, but that's something we can reflect through and extra field added to drm_panfrost_perfcnt_dump.
Quoted 68 lines
Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes 7786fd108777 ("drm/panfrost: Expose performance counters through unstable ioctls")--- drivers/gpu/drm/panfrost/panfrost_device.c | 1 + drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 46 ++++++++++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_device.c +1
-0@@ -426,6 +426,7 @@ bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev,void panfrost_device_reset (struct panfrost_device *pfdev,bool enable_job_int) { +panfrost_perfcnt_reset (pfdev);panfrost_gpu_soft_reset (pfdev);panfrost_gpu_power_on (pfdev);drivers/gpu/drm/panfrost/panfrost_perfcnt.c +14
-0@@ -33,6 +33,7 @@ struct panfrost_perfcnt {struct panfrost_file_priv *user;struct mutex lock;struct completion dump_comp; +atomic_t hw_reset_happened; };static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev)@@ -57,9 +58,13 @@ void panfrost_perfcnt_sample_done(struct panfrost_device *pfdev)static int panfrost_perfcnt_dump_locked (struct panfrost_device *pfdev) { +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt;u64 gpuva;int ret; +if (atomic_read (&perfcnt->hw_reset_happened)) +return -EIO ; +reinit_completion (&pfdev->perfcnt->dump_comp); gpuva = pfdev->perfcnt->mapping->mmnode.start <<PAGE_SHIFT ;gpu_write (pfdev,GPU_PERFCNT_BASE_LO ,lower_32_bits (gpuva));@@ -140,6 +145,15 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, goto err_vunmap; } +/* If a reset is ongoing, the AS we get right below will be torn +* down, so rather than waiting until this becomes obvious in a +* perfcnt_dump() ioctl, we ask the user to try again slightly later. +*/ +if (atomic_read (&pfdev->reset.pending)) { + ret = -EAGAIN ; + goto err_vunmap; + } + ret =panfrost_mmu_as_get (pfdev, perfcnt->mapping->mmu);if (ret <0 ) goto err_vunmap;@@ -173,6 +187,16 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,if (panfrost_has_hw_issue (pfdev,HW_ISSUE_8186 ))gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0xffffffff );
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 198
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +9
-0+/* If a reset happened, we've no way of knowing whether it was between the time we called +* panfrost_mmu_as_get() or before perfcnt_enable(), so clearing this flag and going forward +* isn't possible. We must clear the flag and try again in the hopes no resets will happen +* between this and the next ioctl invocation. +*/ +if (atomic_cmpxchg (&perfcnt->hw_reset_happened,1 ,0 )) { + ret =EAGAIN ; + goto err_disable; + }
This should really be transparent to the user, apart from reporting that samples might have been lost because of the reset.
Quoted 14 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +3
-0+/* The BO ref is retained by the mapping. */ drm_gem_object_put (&bo->base);@@ -180,6 +204,8 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,return 0 ; +err_disable: +panfrost_perfcnt_gpu_disable (pfdev); err_vunmap:drm_gem_vunmap (&bo->base, &map); err_put_mapping:
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev, · line 239
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-1@@ -209,7 +235,8 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map); perfcnt->buf =NULL ;panfrost_gem_close (&perfcnt->mapping->obj->base.base, file_priv); -panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu); +if (!atomic_read (&perfcnt->hw_reset_happened)) +panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);
Why not call panfrost_mmu_as_put() in panfrost_perfcnt_pre_reset(), which is called before panfrost_mmu_reset()? If we do that, the AS should be returned, and we can add a panfrost_perfcnt_post_reset() that's called after panfrost_mmu_reset() and which re-acquires the AS and re-instantiate the perfcnt settings.
Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0panfrost_gem_mapping_put (perfcnt->mapping); perfcnt->mapping =NULL ;pm_runtime_put_autosuspend (pfdev->base.dev);@@ -346,3 +373,20 @@ void panfrost_perfcnt_fini(struct panfrost_device *pfdev)/* Disable everything before leaving. */ panfrost_perfcnt_gpu_disable (pfdev); } +
drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 386
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +10
-0+void panfrost_perfcnt_reset (struct panfrost_device *pfdev) +{ +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt; + +/* Since this function will be called either from a scheduled HW reset +* or a runtime resume, tearing down any perfcnt resources means we're +* doomed to deadlocking with perfcnt_{enable/disable}, since we'd have +* to take the perfecnt lock. On top of that, it'd also violate DMA fence +* signalling rules because GFP_KERNEL allocations are made with the perfcnt +* lock taken in perfcnt_enable.
Question is, do we really need these allocation to happen with the lock held? And if yes, can't we protect perfcnt ops with a separate reset lock?
drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 388
Quoted 3 lines
In light of this, the only thing we can do
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+* is disabling perfcnt unconditionally, and notifying the perfcnt user of +* the reset having happpened so that they can take recovery measures.
Informing userspace about the discontinuity is fine, but I think we should try to restore the config in a post_reset() hook.
Quoted 16 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +4
-0+*/ +panfrost_perfcnt_gpu_disable (pfdev); +atomic_set (&perfcnt->hw_reset_happened,1 ); +}drivers/gpu/drm/panfrost/panfrost_perfcnt.h +1
-0@@ -14,5 +14,6 @@ int panfrost_ioctl_perfcnt_enable(struct drm_device *dev, void *data, struct drm_file *file_priv);int panfrost_ioctl_perfcnt_dump (struct drm_device *dev,void *data,struct drm_file *file_priv); +void panfrost_perfcnt_reset (struct panfrost_device *pfdev);#endif
Steven Price
maintainerRe: [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session
Quoted 15 lines · Boris Brezillon
Quoted 11 lines · On Thu, 04 Jun 2026 18:35:24 +0100 Adrián Larumbe…
Right now, if there's a HW reset and an HWPerf session is active,
panfrost_mmu_reset()will reset the AS count for every single open file's mmu struct back to 0, and also invalidate their AS numbers. Then, when disabling hwperf,panfrost_mmu_as_put()will WARN thatmmu->as_countis less than zero.Fix this by introducing a perfcnt HW reset path.
The choice was made to render perfcnt unusable after reset, so that a user might have to reprogram it with a full disable/enable sequence before requesting more perfcnt dumps.
Quoted 6 lines
Can't we do better than that. We store the config of the perf session, so if a reset is in progress, we can simply block on it, restore the old config in the
post_resetpath, and get going with the DUMP request once the reset has been done. There's certainly something to do to report the discontinuity to userspace, but that's something we can reflect through and extra field added todrm_panfrost_perfcnt_dump.
I agree with Boris' point, ideally reset should be as transparent as possible. Reporting that it has happened is useful, but there's no need to force user space into restoring the context unnecessarily.
One other minor issue below.
Quoted 69 lines
Quoted 69 lines
Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes 7786fd108777 ("drm/panfrost: Expose performance counters through unstable ioctls")--- drivers/gpu/drm/panfrost/panfrost_device.c | 1 + drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 46 ++++++++++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_device.c +1
-0@@ -426,6 +426,7 @@ bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev,void panfrost_device_reset (struct panfrost_device *pfdev,bool enable_job_int) { +panfrost_perfcnt_reset (pfdev);panfrost_gpu_soft_reset (pfdev);panfrost_gpu_power_on (pfdev);drivers/gpu/drm/panfrost/panfrost_perfcnt.c +14
-0@@ -33,6 +33,7 @@ struct panfrost_perfcnt {struct panfrost_file_priv *user;struct mutex lock;struct completion dump_comp; +atomic_t hw_reset_happened; };static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev)@@ -57,9 +58,13 @@ void panfrost_perfcnt_sample_done(struct panfrost_device *pfdev)static int panfrost_perfcnt_dump_locked (struct panfrost_device *pfdev) { +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt;u64 gpuva;int ret; +if (atomic_read (&perfcnt->hw_reset_happened)) +return -EIO ; +reinit_completion (&pfdev->perfcnt->dump_comp); gpuva = pfdev->perfcnt->mapping->mmnode.start <<PAGE_SHIFT ;gpu_write (pfdev,GPU_PERFCNT_BASE_LO ,lower_32_bits (gpuva));@@ -140,6 +145,15 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, goto err_vunmap; } +/* If a reset is ongoing, the AS we get right below will be torn +* down, so rather than waiting until this becomes obvious in a +* perfcnt_dump() ioctl, we ask the user to try again slightly later. +*/ +if (atomic_read (&pfdev->reset.pending)) { + ret = -EAGAIN ; + goto err_vunmap; + } + ret =panfrost_mmu_as_get (pfdev, perfcnt->mapping->mmu);if (ret <0 ) goto err_vunmap;@@ -173,6 +187,16 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,if (panfrost_has_hw_issue (pfdev,HW_ISSUE_8186 ))gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0xffffffff );
Quoted 7 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 196
Quoted 7 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +7
-0+/* If a reset happened, we've no way of knowing whether it was between the time we called +* panfrost_mmu_as_get() or before perfcnt_enable(), so clearing this flag and going forward +* isn't possible. We must clear the flag and try again in the hopes no resets will happen +* between this and the next ioctl invocation. +*/ +if (atomic_cmpxchg (&perfcnt->hw_reset_happened,1 ,0 )) { + ret =EAGAIN ;
Missing '-' on EAGAIN.
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 198
Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+ goto err_disable; + }This should really be transparent to the user, apart from reporting that samples might have been lost because of the reset.
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0+/* The BO ref is retained by the mapping. */ drm_gem_object_put (&bo->base);
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 207
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0@@ -180,6 +204,8 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,return 0 ; +err_disable:
We're leaking the AS reference here - you need a panfrost_mmu_as_put() call.
Quoted 11 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev, · line 239
Quoted 11 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +3
-1+panfrost_perfcnt_gpu_disable (pfdev); err_vunmap:drm_gem_vunmap (&bo->base, &map); err_put_mapping:@@ -209,7 +235,8 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map); perfcnt->buf =NULL ;panfrost_gem_close (&perfcnt->mapping->obj->base.base, file_priv); -panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu); +if (!atomic_read (&perfcnt->hw_reset_happened)) +panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);
The atomic_read() scares me - is this really safe and not subject to races?
Thanks,
Steve
Quoted 54 lines
Why not call
panfrost_mmu_as_put()inpanfrost_perfcnt_pre_reset(), which is called beforepanfrost_mmu_reset()? If we do that, the AS should be returned, and we can add apanfrost_perfcnt_post_reset()that's called afterpanfrost_mmu_reset()and which re-acquires the AS and re-instantiate the perfcnt settings.Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0panfrost_gem_mapping_put (perfcnt->mapping); perfcnt->mapping =NULL ;pm_runtime_put_autosuspend (pfdev->base.dev);@@ -346,3 +373,20 @@ void panfrost_perfcnt_fini(struct panfrost_device *pfdev)/* Disable everything before leaving. */ panfrost_perfcnt_gpu_disable (pfdev); } +drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 386
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +10
-0+void panfrost_perfcnt_reset (struct panfrost_device *pfdev) +{ +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt; + +/* Since this function will be called either from a scheduled HW reset +* or a runtime resume, tearing down any perfcnt resources means we're +* doomed to deadlocking with perfcnt_{enable/disable}, since we'd have +* to take the perfecnt lock. On top of that, it'd also violate DMA fence +* signalling rules because GFP_KERNEL allocations are made with the perfcnt +* lock taken in perfcnt_enable. Question is, do we really need these allocation to happen with the lock held? And if yes, can't we protect perfcnt ops with a separate reset lock?
drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 388
Quoted 3 lines
In light of this, the only thing we can do
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+* is disabling perfcnt unconditionally, and notifying the perfcnt user of +* the reset having happpened so that they can take recovery measures. Informing userspace about the discontinuity is fine, but I think we should try to restore the config in a
post_reset()hook.Quoted 16 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +4
-0+*/ +panfrost_perfcnt_gpu_disable (pfdev); +atomic_set (&perfcnt->hw_reset_happened,1 ); +}drivers/gpu/drm/panfrost/panfrost_perfcnt.h +1
-0@@ -14,5 +14,6 @@ int panfrost_ioctl_perfcnt_enable(struct drm_device *dev, void *data, struct drm_file *file_priv);int panfrost_ioctl_perfcnt_dump (struct drm_device *dev,void *data,struct drm_file *file_priv); +void panfrost_perfcnt_reset (struct panfrost_device *pfdev);#endif
Adrián Larumbe
maintainerRe: [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session
Quoted 23 lines · Steven Price
Quoted 15 lines · Boris Brezillon
Quoted 11 lines · On Thu, 04 Jun 2026 18:35:24 +0100 Adrián Larumbe…
Right now, if there's a HW reset and an HWPerf session is active,
panfrost_mmu_reset()will reset the AS count for every single open file's mmu struct back to 0, and also invalidate their AS numbers. Then, when disabling hwperf,panfrost_mmu_as_put()will WARN thatmmu->as_countis less than zero.Fix this by introducing a perfcnt HW reset path.
The choice was made to render perfcnt unusable after reset, so that a user might have to reprogram it with a full disable/enable sequence before requesting more perfcnt dumps.
Quoted 6 lines
Can't we do better than that. We store the config of the perf session, so if a reset is in progress, we can simply block on it, restore the old config in the
post_resetpath, and get going with the DUMP request once the reset has been done. There's certainly something to do to report the discontinuity to userspace, but that's something we can reflect through and extra field added todrm_panfrost_perfcnt_dump.
Quoted 5 lines
I agree with Boris' point, ideally reset should be as transparent as possible. Reporting that it has happened is useful, but there's no need to force user space into restoring the context unnecessarily.
One other minor issue below.
I think the fact that this is going to require a non-negligible amount of effort in thinking out a stat-save-and-restore sequence for perfcnt in the event of a reset, I guess I'd better leave it off for another series of its own.
Quoted 69 lines
Quoted 69 lines
Quoted 69 lines
Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes 7786fd108777 ("drm/panfrost: Expose performance counters through unstable ioctls")--- drivers/gpu/drm/panfrost/panfrost_device.c | 1 + drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 46 ++++++++++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_device.c +1
-0@@ -426,6 +426,7 @@ bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev,void panfrost_device_reset (struct panfrost_device *pfdev,bool enable_job_int) { +panfrost_perfcnt_reset (pfdev);panfrost_gpu_soft_reset (pfdev);panfrost_gpu_power_on (pfdev);drivers/gpu/drm/panfrost/panfrost_perfcnt.c +14
-0@@ -33,6 +33,7 @@ struct panfrost_perfcnt {struct panfrost_file_priv *user;struct mutex lock;struct completion dump_comp; +atomic_t hw_reset_happened; };static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev)@@ -57,9 +58,13 @@ void panfrost_perfcnt_sample_done(struct panfrost_device *pfdev)static int panfrost_perfcnt_dump_locked (struct panfrost_device *pfdev) { +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt;u64 gpuva;int ret; +if (atomic_read (&perfcnt->hw_reset_happened)) +return -EIO ; +reinit_completion (&pfdev->perfcnt->dump_comp); gpuva = pfdev->perfcnt->mapping->mmnode.start <<PAGE_SHIFT ;gpu_write (pfdev,GPU_PERFCNT_BASE_LO ,lower_32_bits (gpuva));@@ -140,6 +145,15 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, goto err_vunmap; } +/* If a reset is ongoing, the AS we get right below will be torn +* down, so rather than waiting until this becomes obvious in a +* perfcnt_dump() ioctl, we ask the user to try again slightly later. +*/ +if (atomic_read (&pfdev->reset.pending)) { + ret = -EAGAIN ; + goto err_vunmap; + } + ret =panfrost_mmu_as_get (pfdev, perfcnt->mapping->mmu);if (ret <0 ) goto err_vunmap;@@ -173,6 +187,16 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,if (panfrost_has_hw_issue (pfdev,HW_ISSUE_8186 ))gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0xffffffff );
Quoted 9 lines
Quoted 7 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 196
Quoted 7 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +7
-0+/* If a reset happened, we've no way of knowing whether it was between the time we called +* panfrost_mmu_as_get() or before perfcnt_enable(), so clearing this flag and going forward +* isn't possible. We must clear the flag and try again in the hopes no resets will happen +* between this and the next ioctl invocation. +*/ +if (atomic_cmpxchg (&perfcnt->hw_reset_happened,1 ,0 )) { + ret =EAGAIN ;Missing '-' on EAGAIN.
Acked.
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 198
Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+ goto err_disable; + }This should really be transparent to the user, apart from reporting that samples might have been lost because of the reset.
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0+/* The BO ref is retained by the mapping. */ drm_gem_object_put (&bo->base);
Quoted 7 lines
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 207
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0@@ -180,6 +204,8 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,return 0 ; +err_disable:We're leaking the AS reference here - you need a
panfrost_mmu_as_put()call.
Acked, will fix.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0+panfrost_perfcnt_gpu_disable (pfdev); err_vunmap:drm_gem_vunmap (&bo->base, &map); err_put_mapping:@@ -209,7 +235,8 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev, · line 239
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-1drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map); perfcnt->buf =NULL ;panfrost_gem_close (&perfcnt->mapping->obj->base.base, file_priv); -panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu); +if (!atomic_read (&perfcnt->hw_reset_happened)) +panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);The
atomic_read()scares me - is this really safe and not subject to races?
You're right, it's racy because the thread executing the ioctl could be scheduled out right before panfrost_mmu_as_put() is executed, then a reset come through in the meantime, and by the time it's resumed the as_count would again be < 0. I guess I need a proper spinlock to protect access to the mmu struct from perfcnt.
Quoted 57 lines
Thanks,
SteveQuoted 54 lines
Why not call
panfrost_mmu_as_put()inpanfrost_perfcnt_pre_reset(), which is called beforepanfrost_mmu_reset()? If we do that, the AS should be returned, and we can add apanfrost_perfcnt_post_reset()that's called afterpanfrost_mmu_reset()and which re-acquires the AS and re-instantiate the perfcnt settings.Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +1
-0panfrost_gem_mapping_put (perfcnt->mapping); perfcnt->mapping =NULL ;pm_runtime_put_autosuspend (pfdev->base.dev);@@ -346,3 +373,20 @@ void panfrost_perfcnt_fini(struct panfrost_device *pfdev)/* Disable everything before leaving. */ panfrost_perfcnt_gpu_disable (pfdev); } +drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 386
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +10
-0+void panfrost_perfcnt_reset (struct panfrost_device *pfdev) +{ +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt; + +/* Since this function will be called either from a scheduled HW reset +* or a runtime resume, tearing down any perfcnt resources means we're +* doomed to deadlocking with perfcnt_{enable/disable}, since we'd have +* to take the perfecnt lock. On top of that, it'd also violate DMA fence +* signalling rules because GFP_KERNEL allocations are made with the perfcnt +* lock taken in perfcnt_enable. Question is, do we really need these allocation to happen with the lock held? And if yes, can't we protect perfcnt ops with a separate reset lock?
drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 388
Quoted 3 lines
In light of this, the only thing we can do
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+* is disabling perfcnt unconditionally, and notifying the perfcnt user of +* the reset having happpened so that they can take recovery measures. Informing userspace about the discontinuity is fine, but I think we should try to restore the config in a
post_reset()hook.Quoted 16 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +4
-0+*/ +panfrost_perfcnt_gpu_disable (pfdev); +atomic_set (&perfcnt->hw_reset_happened,1 ); +}drivers/gpu/drm/panfrost/panfrost_perfcnt.h +1
-0@@ -14,5 +14,6 @@ int panfrost_ioctl_perfcnt_enable(struct drm_device *dev, void *data, struct drm_file *file_priv);int panfrost_ioctl_perfcnt_dump (struct drm_device *dev,void *data,struct drm_file *file_priv); +void panfrost_perfcnt_reset (struct panfrost_device *pfdev);#endif
Adrian Larumbe
Adrián Larumbe
maintainerRe: [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session
In reply to Boris BrezillonQuoted 15 lines · Boris Brezillon
Quoted 11 lines · On Thu, 04 Jun 2026 18:35:24 +0100 Adrián Larumbe…
Right now, if there's a HW reset and an HWPerf session is active,
panfrost_mmu_reset()will reset the AS count for every single open file's mmu struct back to 0, and also invalidate their AS numbers. Then, when disabling hwperf,panfrost_mmu_as_put()will WARN thatmmu->as_countis less than zero.Fix this by introducing a perfcnt HW reset path.
The choice was made to render perfcnt unusable after reset, so that a user might have to reprogram it with a full disable/enable sequence before requesting more perfcnt dumps.
Quoted 6 lines
Can't we do better than that. We store the config of the perf session, so if a reset is in progress, we can simply block on it, restore the old config in the
post_resetpath, and get going with the DUMP request once the reset has been done. There's certainly something to do to report the discontinuity to userspace, but that's something we can reflect through and extra field added todrm_panfrost_perfcnt_dump.
Do you mean perfcnt_dump() should wait until the reset is finished in the ioctl itself? However it makes me wonder what we could do when the reset happens and there's an going perfcnt_enable() ioctl, and the reset might render the initialised state void.
Quoted 99 lines
Quoted 67 lines
Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes 7786fd108777 ("drm/panfrost: Expose performance counters through unstable ioctls")--- drivers/gpu/drm/panfrost/panfrost_device.c | 1 + drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 46 ++++++++++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_device.c +1
-0@@ -426,6 +426,7 @@ bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev,void panfrost_device_reset (struct panfrost_device *pfdev,bool enable_job_int) { +panfrost_perfcnt_reset (pfdev);panfrost_gpu_soft_reset (pfdev);panfrost_gpu_power_on (pfdev);drivers/gpu/drm/panfrost/panfrost_perfcnt.c +14
-0@@ -33,6 +33,7 @@ struct panfrost_perfcnt {struct panfrost_file_priv *user;struct mutex lock;struct completion dump_comp; +atomic_t hw_reset_happened; };static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev)@@ -57,9 +58,13 @@ void panfrost_perfcnt_sample_done(struct panfrost_device *pfdev)static int panfrost_perfcnt_dump_locked (struct panfrost_device *pfdev) { +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt;u64 gpuva;int ret; +if (atomic_read (&perfcnt->hw_reset_happened)) +return -EIO ; +reinit_completion (&pfdev->perfcnt->dump_comp); gpuva = pfdev->perfcnt->mapping->mmnode.start <<PAGE_SHIFT ;gpu_write (pfdev,GPU_PERFCNT_BASE_LO ,lower_32_bits (gpuva));@@ -140,6 +145,15 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, goto err_vunmap; } +/* If a reset is ongoing, the AS we get right below will be torn +* down, so rather than waiting until this becomes obvious in a +* perfcnt_dump() ioctl, we ask the user to try again slightly later. +*/ +if (atomic_read (&pfdev->reset.pending)) { + ret = -EAGAIN ; + goto err_vunmap; + } + ret =panfrost_mmu_as_get (pfdev, perfcnt->mapping->mmu);if (ret <0 ) goto err_vunmap;@@ -173,6 +187,16 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,if (panfrost_has_hw_issue (pfdev,HW_ISSUE_8186 ))gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0xffffffff );drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 198
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +9
-0+/* If a reset happened, we've no way of knowing whether it was between the time we called +* panfrost_mmu_as_get() or before perfcnt_enable(), so clearing this flag and going forward +* isn't possible. We must clear the flag and try again in the hopes no resets will happen +* between this and the next ioctl invocation. +*/ +if (atomic_cmpxchg (&perfcnt->hw_reset_happened,1 ,0 )) { + ret =EAGAIN ; + goto err_disable; + }This should really be transparent to the user, apart from reporting that samples might have been lost because of the reset.
Quoted 18 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +3
-1+/* The BO ref is retained by the mapping. */ drm_gem_object_put (&bo->base);@@ -180,6 +204,8 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,return 0 ; +err_disable: +panfrost_perfcnt_gpu_disable (pfdev); err_vunmap:drm_gem_vunmap (&bo->base, &map); err_put_mapping:@@ -209,7 +235,8 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map); perfcnt->buf =NULL ;panfrost_gem_close (&perfcnt->mapping->obj->base.base, file_priv); -panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);
Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev, · line 239
Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+if (!atomic_read (&perfcnt->hw_reset_happened)) +panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);Why not call
panfrost_mmu_as_put()inpanfrost_perfcnt_pre_reset(), which is called beforepanfrost_mmu_reset()? If we do that, the AS should be returned, and we can add apanfrost_perfcnt_post_reset()that's called afterpanfrost_mmu_reset()and which re-acquires the AS and re-instantiate the perfcnt settings.
I was doing this revision 1, but then that could lead to races because panfrost_perfcnt_reset() and panfrost_perfcnt_disable_locked() could call panfrost_mmu_as_put() right after another, leaving the as_count at -1.
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +7
-0panfrost_gem_mapping_put (perfcnt->mapping); perfcnt->mapping =NULL ;pm_runtime_put_autosuspend (pfdev->base.dev);@@ -346,3 +373,20 @@ void panfrost_perfcnt_fini(struct panfrost_device *pfdev)/* Disable everything before leaving. */ panfrost_perfcnt_gpu_disable (pfdev); } + +void panfrost_perfcnt_reset (struct panfrost_device *pfdev) +{ +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt; + +/* Since this function will be called either from a scheduled HW reset +* or a runtime resume, tearing down any perfcnt resources means we're
Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev)
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +4
-0+* doomed to deadlocking with perfcnt_{enable/disable}, since we'd have +* to take the perfecnt lock. On top of that, it'd also violate DMA fence +* signalling rules because GFP_KERNEL allocations are made with the perfcnt +* lock taken in perfcnt_enable. Question is, do we really need these allocation to happen with the lock held? And if yes, can't we protect perfcnt ops with a separate reset lock?
I'd rather do the latter, I think Panthor is doing something like that already?
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev) · line 388
Quoted 3 lines
In light of this, the only thing we can do
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+* is disabling perfcnt unconditionally, and notifying the perfcnt user of +* the reset having happpened so that they can take recovery measures. Informing userspace about the discontinuity is fine, but I think we should try to restore the config in a
post_reset()hook.
Boris Brezillon
maintainerRe: [PATCH v2 5/7] drm/panfrost: Make reset sequence deal with an active HWPerf session
Quoted 23 lines · On Tue, 16 Jun 2026 23:39:01 +0100 Adrián Larumbe…
Quoted 15 lines · Boris Brezillon
Quoted 11 lines · On Thu, 04 Jun 2026 18:35:24 +0100 Adrián Larumbe…
Right now, if there's a HW reset and an HWPerf session is active,
panfrost_mmu_reset()will reset the AS count for every single open file's mmu struct back to 0, and also invalidate their AS numbers. Then, when disabling hwperf,panfrost_mmu_as_put()will WARN thatmmu->as_countis less than zero.Fix this by introducing a perfcnt HW reset path.
The choice was made to render perfcnt unusable after reset, so that a user might have to reprogram it with a full disable/enable sequence before requesting more perfcnt dumps.
Quoted 6 lines
Can't we do better than that. We store the config of the perf session, so if a reset is in progress, we can simply block on it, restore the old config in the
post_resetpath, and get going with the DUMP request once the reset has been done. There's certainly something to do to report the discontinuity to userspace, but that's something we can reflect through and extra field added todrm_panfrost_perfcnt_dump.
Quoted 2 lines
Do you mean
perfcnt_dump()should wait until the reset is finished in the ioctl itself?
Yes. You shouldn't be allowed to interact with the HW while a reset is in progress (or even pending), because you're guaranteed it won't do what you want.
Quoted 3 lines
However it makes me wonder what we could do when the reset happens and there's an going
perfcnt_enable()ioctl, and the reset might render the initialised state void.
That's exactly the sort of issues I'm talking about. Given reset interferes with the perfcnt config, you have to make sure you restore the previous state after a reset, and report back the transient failure on the next DUMP request coming from userspace.
Quoted 109 lines
Quoted 100 lines
Quoted 68 lines
Reported-by Claude <[email protected]>Signed-off-by Adrián Larumbe <[email protected]>Fixes 7786fd108777 ("drm/panfrost: Expose performance counters through unstable ioctls")--- drivers/gpu/drm/panfrost/panfrost_device.c | 1 + drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 46 ++++++++++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_device.c +1
-0@@ -426,6 +426,7 @@ bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev,void panfrost_device_reset (struct panfrost_device *pfdev,bool enable_job_int) { +panfrost_perfcnt_reset (pfdev);panfrost_gpu_soft_reset (pfdev);panfrost_gpu_power_on (pfdev);drivers/gpu/drm/panfrost/panfrost_perfcnt.c +14
-0@@ -33,6 +33,7 @@ struct panfrost_perfcnt {struct panfrost_file_priv *user;struct mutex lock;struct completion dump_comp; +atomic_t hw_reset_happened; };static void panfrost_perfcnt_gpu_disable (struct panfrost_device *pfdev)@@ -57,9 +58,13 @@ void panfrost_perfcnt_sample_done(struct panfrost_device *pfdev)static int panfrost_perfcnt_dump_locked (struct panfrost_device *pfdev) { +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt;u64 gpuva;int ret; +if (atomic_read (&perfcnt->hw_reset_happened)) +return -EIO ; +reinit_completion (&pfdev->perfcnt->dump_comp); gpuva = pfdev->perfcnt->mapping->mmnode.start <<PAGE_SHIFT ;gpu_write (pfdev,GPU_PERFCNT_BASE_LO ,lower_32_bits (gpuva));@@ -140,6 +145,15 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, goto err_vunmap; } +/* If a reset is ongoing, the AS we get right below will be torn +* down, so rather than waiting until this becomes obvious in a +* perfcnt_dump() ioctl, we ask the user to try again slightly later. +*/ +if (atomic_read (&pfdev->reset.pending)) { + ret = -EAGAIN ; + goto err_vunmap; + } + ret =panfrost_mmu_as_get (pfdev, perfcnt->mapping->mmu);if (ret <0 ) goto err_vunmap;@@ -173,6 +187,16 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,if (panfrost_has_hw_issue (pfdev,HW_ISSUE_8186 ))gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0xffffffff );drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev, · line 198
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +9
-0+/* If a reset happened, we've no way of knowing whether it was between the time we called +* panfrost_mmu_as_get() or before perfcnt_enable(), so clearing this flag and going forward +* isn't possible. We must clear the flag and try again in the hopes no resets will happen +* between this and the next ioctl invocation. +*/ +if (atomic_cmpxchg (&perfcnt->hw_reset_happened,1 ,0 )) { + ret =EAGAIN ; + goto err_disable; + }This should really be transparent to the user, apart from reporting that samples might have been lost because of the reset.
Quoted 18 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +3
-1+/* The BO ref is retained by the mapping. */ drm_gem_object_put (&bo->base);@@ -180,6 +204,8 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,return 0 ; +err_disable: +panfrost_perfcnt_gpu_disable (pfdev); err_vunmap:drm_gem_vunmap (&bo->base, &map); err_put_mapping:@@ -209,7 +235,8 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map); perfcnt->buf =NULL ;panfrost_gem_close (&perfcnt->mapping->obj->base.base, file_priv); -panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev, · line 239
Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2
-0+if (!atomic_read (&perfcnt->hw_reset_happened)) +panfrost_mmu_as_put (pfdev, perfcnt->mapping->mmu);Why not call
panfrost_mmu_as_put()inpanfrost_perfcnt_pre_reset(), which is called beforepanfrost_mmu_reset()? If we do that, the AS should be returned, and we can add apanfrost_perfcnt_post_reset()that's called afterpanfrost_mmu_reset()and which re-acquires the AS and re-instantiate the perfcnt settings.
Quoted 3 lines
I was doing this revision 1, but then that could lead to races because
panfrost_perfcnt_reset()andpanfrost_perfcnt_disable_locked()could callpanfrost_mmu_as_put()right after another, leaving theas_countat -1.
That's something you solve with locking/proper-serialization. Calling panfrost_mmu_as_put() conditionally in the disable path is just papering over the race.
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +7
-0panfrost_gem_mapping_put (perfcnt->mapping); perfcnt->mapping =NULL ;pm_runtime_put_autosuspend (pfdev->base.dev);@@ -346,3 +373,20 @@ void panfrost_perfcnt_fini(struct panfrost_device *pfdev)/* Disable everything before leaving. */ panfrost_perfcnt_gpu_disable (pfdev); } + +void panfrost_perfcnt_reset (struct panfrost_device *pfdev) +{ +struct panfrost_perfcnt *perfcnt = pfdev->perfcnt; + +/* Since this function will be called either from a scheduled HW reset +* or a runtime resume, tearing down any perfcnt resources means we're Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c void panfrost_perfcnt_fini(struct panfrost_device *pfdev)
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +4
-0+* doomed to deadlocking with perfcnt_{enable/disable}, since we'd have +* to take the perfecnt lock. On top of that, it'd also violate DMA fence +* signalling rules because GFP_KERNEL allocations are made with the perfcnt +* lock taken in perfcnt_enable. Question is, do we really need these allocation to happen with the lock held? And if yes, can't we protect perfcnt ops with a separate reset lock?
Quoted 1 line
I'd rather do the latter, I think Panthor is doing something like that already?
Allocating resources before acquiring the lock to check if another session exists sounds like a better option IMHO. Yes, you might end up releasing everything because another active session exists, but that's fine.
Adrián Larumbe
maintainerPATCH v2 6/7 drm/panfrost: Fix PM usage_count mishandling
In reply to Adrián LarumbeDuring device probe(), failure to do a PM get() will leave the usage_count set to 0, which is the value assigned at device creation time. That means when the autosuspend delay expires, runtime suspend callback won't be invoked, so the device will remain powered on forever.
On top of that, failure to call PM put() during device unplug means Panfrost device's PM usage_count increases monotonically for every new module reload.
The combined outcome of both of the above was that devfreq OPP transition notifications would be printed all the time, even when no jobs are being submitted. This quickly fills the kernel ring buffer with junk.
Even direr than that was the fact MMU interrupts are only enabled when the device is reset, so after device probe() the very first job targeting the tiler heap BO would always time out, because the driver's PM runtime resume callback would not be invoked.
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_drv.c +5 -1
@@ -989,6 +989,7 @@ static int panfrost_probe(struct platform_device *pdev)pm_runtime_set_active (pfdev->base.dev);pm_runtime_mark_last_busy (pfdev->base.dev);pm_runtime_enable (pfdev->base.dev); +pm_runtime_get_noresume (pfdev->base.dev);pm_runtime_set_autosuspend_delay (pfdev->base.dev,50 );/* ~3 frames */ pm_runtime_use_autosuspend (pfdev->base.dev);
@@ -1000,10 +1001,12 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; +pm_runtime_put_autosuspend (pfdev->base.dev);return 0 ; err_out1: +pm_runtime_put_noidle (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);pm_runtime_set_suspended (pfdev->base.dev);
@@ -1018,8 +1021,9 @@ static void panfrost_remove(struct platform_device *pdev)drm_dev_unregister (&pfdev->base);pm_runtime_get_sync (pfdev->base.dev); -pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev); +pm_runtime_put_noidle (pfdev->base.dev); +pm_runtime_disable (pfdev->base.dev);pm_runtime_set_suspended (pfdev->base.dev); }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 6/7] drm/panfrost: Fix PM usage_count mishandling
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Reordering PM teardown in device removal and probe error paths creates race conditions (UAF/kernel panics) and violates PM domain rules.
Pre-existing issues:
- [High] Improper DRM device unplug allows subsequent ioctls to access freed driver resources, causing Use-After-Free. --
commit 385821af932c300aa013c14b13508c8e9cf10f64
Author: Adrián Larumbe <[email protected]>
drm/panfrost: Fix PM usage_count mishandling
This commit addresses a PM usage_count mishandling issue during device probe and unplug. It adds balanced PM get/put calls to prevent devices from staying powered on indefinitely or triggering constant devfreq OPP transition notifications.
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +0
-0
[ ... ]
drivers/gpu/drm/panfrost/panfrost_drv.c static int panfrost_probe(struct platform_device *pdev) · line 1011
Quoted 12 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-0@@ -1000,10 +1001,12 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; +pm_runtime_put_autosuspend (pfdev->base.dev);return 0 ; err_out1: +pm_runtime_put_noidle (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
Does dropping the usage count before pm_runtime_disable() create a race condition where the suspend callback can run and disable clocks before hardware shutdown?
Because the usage count is dropped early, a concurrent PM event could trigger the suspend callback, disabling clocks. Then, panfrost_device_fini() calls panfrost_gpu_fini() which writes to MMIO registers. Could writing to unclocked registers on ARM SoCs cause fatal bus errors or panics?
Quoted 1 line
drivers/gpu/drm/panfrost/panfrost_drv.c +0
-0pm_runtime_set_suspended (pfdev->base.dev);
[ ... ]
drivers/gpu/drm/panfrost/panfrost_drv.c static void panfrost_remove(struct platform_device *pdev) · line 1021
Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +0
-0@@ -1018,8 +1021,9 @@ static void panfrost_remove(struct platform_device *pdev)drm_dev_unregister (&pfdev->base);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
This is a pre-existing issue, but does using drm_dev_unregister() instead of drm_dev_unplug() allow subsequent ioctls to access freed driver resources?
Because drm_dev_unregister() removes the device from sysfs but does not set the dev->unplugged flag, the DRM core (drm_ioctl_kernel) does not block ioctls from userspace processes that already hold an open file descriptor.
Since panfrost_remove() proceeds to call panfrost_device_fini() which destroys critical structures (job manager, MMU contexts, shrinker lists) and powers down hardware, could a user issuing an ioctl during or after driver unbind via sysfs access freed structures and unmapped MMIO regions, resulting in a use-after-free?
drivers/gpu/drm/panfrost/panfrost_drv.c static void panfrost_remove(struct platform_device *pdev) · line 1026
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-1pm_runtime_get_sync (pfdev->base.dev); -pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev); +pm_runtime_put_noidle (pfdev->base.dev); +pm_runtime_disable (pfdev->base.dev);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
Does placing pm_runtime_put_noidle() and pm_runtime_disable() after panfrost_device_fini() create a window where runtime PM can access freed structures?
pm_runtime_put_noidle() drops the PM usage count to 0. At this point, a concurrent PM event (e.g., userspace writing to /sys/.../power/control) can trigger panfrost_device_runtime_suspend() before pm_runtime_disable() executes.
Since panfrost_device_fini() has already destroyed driver structures like the job manager, would the suspend callback access freed memory (like checking panfrost_jm_is_idle), causing a use-after-free?
Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +0
-0pm_runtime_set_suspended (pfdev->base.dev); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Boris Brezillon
maintainerRe: [PATCH v2 6/7] drm/panfrost: Fix PM usage_count mishandling
In reply to Adrián LarumbeQuoted 38 lines · On Thu, 04 Jun 2026 18:35:25 +0100 Adrián Larumbe…
During device
probe(), failure to do a PMget()will leave theusage_countset to 0, which is the value assigned at device creation time. That means when the autosuspend delay expires, runtime suspend callback won't be invoked, so the device will remain powered on forever.On top of that, failure to call PM
put()during device unplug means Panfrost device's PMusage_countincreases monotonically for every new module reload.The combined outcome of both of the above was that devfreq OPP transition notifications would be printed all the time, even when no jobs are being submitted. This quickly fills the kernel ring buffer with junk.
Even direr than that was the fact MMU interrupts are only enabled when the device is reset, so after device
probe()the very first job targeting the tiler heap BO would always time out, because the driver's PM runtime resume callback would not be invoked.Signed-off-by Adrián Larumbe <[email protected]>Fixes 635430797d3f ("drm/panfrost: Rework runtime PM initialization")Fixes 876b15d2c88d ("drm/panfrost: Fix module unload")--- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_drv.c +1
-0@@ -989,6 +989,7 @@ static int panfrost_probe(struct platform_device *pdev)pm_runtime_set_active (pfdev->base.dev);pm_runtime_mark_last_busy (pfdev->base.dev);pm_runtime_enable (pfdev->base.dev); +pm_runtime_get_noresume (pfdev->base.dev);pm_runtime_set_autosuspend_delay (pfdev->base.dev,50 );/* ~3 frames */ pm_runtime_use_autosuspend (pfdev->base.dev);
drivers/gpu/drm/panfrost/panfrost_drv.c static int panfrost_probe(struct platform_device *pdev) · line 1009
Quoted 9 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-0@@ -1000,10 +1001,12 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; +pm_runtime_put_autosuspend (pfdev->base.dev);return 0 ; err_out1: +pm_runtime_put_noidle (pfdev->base.dev);
Do we really need this get_noresume/put_noidle dance, can't use call pm_runtime_dont_use_autosuspend() instead like is done in panthor, or is panthor broken too?
Quoted 15 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-1pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);pm_runtime_set_suspended (pfdev->base.dev);@@ -1018,8 +1021,9 @@ static void panfrost_remove(struct platform_device *pdev)drm_dev_unregister (&pfdev->base);pm_runtime_get_sync (pfdev->base.dev); -pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev); +pm_runtime_put_noidle (pfdev->base.dev); +pm_runtime_disable (pfdev->base.dev);pm_runtime_set_suspended (pfdev->base.dev); }
Adrián Larumbe
maintainerRe: [PATCH v2 6/7] drm/panfrost: Fix PM usage_count mishandling
Quoted 46 lines · Boris Brezillon
Quoted 43 lines · On Thu, 04 Jun 2026 18:35:25 +0100 Adrián Larumbe…
During device
probe(), failure to do a PMget()will leave theusage_countset to 0, which is the value assigned at device creation time. That means when the autosuspend delay expires, runtime suspend callback won't be invoked, so the device will remain powered on forever.On top of that, failure to call PM
put()during device unplug means Panfrost device's PMusage_countincreases monotonically for every new module reload.The combined outcome of both of the above was that devfreq OPP transition notifications would be printed all the time, even when no jobs are being submitted. This quickly fills the kernel ring buffer with junk.
Even direr than that was the fact MMU interrupts are only enabled when the device is reset, so after device
probe()the very first job targeting the tiler heap BO would always time out, because the driver's PM runtime resume callback would not be invoked.Signed-off-by Adrián Larumbe <[email protected]>Fixes 635430797d3f ("drm/panfrost: Rework runtime PM initialization")Fixes 876b15d2c88d ("drm/panfrost: Fix module unload")--- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_drv.c +2
-0@@ -989,6 +989,7 @@ static int panfrost_probe(struct platform_device *pdev)pm_runtime_set_active (pfdev->base.dev);pm_runtime_mark_last_busy (pfdev->base.dev);pm_runtime_enable (pfdev->base.dev); +pm_runtime_get_noresume (pfdev->base.dev);pm_runtime_set_autosuspend_delay (pfdev->base.dev,50 );/* ~3 frames */ pm_runtime_use_autosuspend (pfdev->base.dev);@@ -1000,10 +1001,12 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; +pm_runtime_put_autosuspend (pfdev->base.dev);
Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_drv.c static int panfrost_probe(struct platform_device *pdev) · line 1009
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +1
-0return 0 ; err_out1: +pm_runtime_put_noidle (pfdev->base.dev);Do we really need this get_noresume/put_noidle dance, can't use call
pm_runtime_dont_use_autosuspend()instead like is done in panthor, or is panthor broken too?
We need get_noresume() because after panfrost_device_init(), the device is powered up but that is not reflected in the device's PM refcnt. Then pm_runtime_put_autosuspend() will decrement the refcnt back to 0 and let the autosuspend window expire before suspending the device, unless someone starts using it immediately.
pm_runtime_dont_use_autosuspend() is not mandatory if we manually call pm_runtime_disable() at device unplug time or when probe() fails. pm_runtime_use_autosuspend()'s docs say:
pm_runtime_use_autosuspend - Allow autosuspend to be used for a device. @dev: Target device.
Allow the runtime PM autosuspend mechanism to be used for @dev whenever requested (or "autosuspend" will be handled as direct runtime-suspend for it).
NOTE: It's important to undo this with pm_runtime_dont_use_autosuspend() at driver exit time unless your driver initially enabled pm_runtime with devm_pm_runtime_enable() (which handles it for you).
Panthor uses devm_pm_runtime_enable(), which makes me suspect perhaps it doesn't need to explicitly call pm_runtime_dont_use_autosuspend().
Panthor also manages PM refcnt fine at driver probe(), inside panthor_device_init():
``` c
ret = pm_runtime_resume_and_get(ptdev->base.dev);
if (ret)
return ret;
/* If PM is disabled, we need to call panthor_device_resume() manually. */
if (!IS_ENABLED(CONFIG_PM)) {
ret = panthor_device_resume(ptdev->base.dev);
if (ret)
return ret;
}
```If we want a similar thing in Panfrost, then we should move all clock and devfreq enablement into panfrost_device_runtime_resume() and do pm_runtime_resume_and_get() right before panfrost_gpu_init().
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +0
-0pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);pm_runtime_set_suspended (pfdev->base.dev);@@ -1018,8 +1021,9 @@ static void panfrost_remove(struct platform_device *pdev)drm_dev_unregister (&pfdev->base);
Quoted 9 lines
drivers/gpu/drm/panfrost/panfrost_drv.c static void panfrost_remove(struct platform_device *pdev) · line 1029
Quoted 9 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-1pm_runtime_get_sync (pfdev->base.dev); -pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev); +pm_runtime_put_noidle (pfdev->base.dev); +pm_runtime_disable (pfdev->base.dev);pm_runtime_set_suspended (pfdev->base.dev); }
Adrian Larumbe
Boris Brezillon
maintainerRe: [PATCH v2 6/7] drm/panfrost: Fix PM usage_count mishandling
Quoted 56 lines · On Tue, 16 Jun 2026 21:17:53 +0100 Adrián Larumbe…
Quoted 46 lines · Boris Brezillon
Quoted 43 lines · On Thu, 04 Jun 2026 18:35:25 +0100 Adrián Larumbe…
During device
probe(), failure to do a PMget()will leave theusage_countset to 0, which is the value assigned at device creation time. That means when the autosuspend delay expires, runtime suspend callback won't be invoked, so the device will remain powered on forever.On top of that, failure to call PM
put()during device unplug means Panfrost device's PMusage_countincreases monotonically for every new module reload.The combined outcome of both of the above was that devfreq OPP transition notifications would be printed all the time, even when no jobs are being submitted. This quickly fills the kernel ring buffer with junk.
Even direr than that was the fact MMU interrupts are only enabled when the device is reset, so after device
probe()the very first job targeting the tiler heap BO would always time out, because the driver's PM runtime resume callback would not be invoked.Signed-off-by Adrián Larumbe <[email protected]>Fixes 635430797d3f ("drm/panfrost: Rework runtime PM initialization")Fixes 876b15d2c88d ("drm/panfrost: Fix module unload")--- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_drv.c +2
-0@@ -989,6 +989,7 @@ static int panfrost_probe(struct platform_device *pdev)pm_runtime_set_active (pfdev->base.dev);pm_runtime_mark_last_busy (pfdev->base.dev);pm_runtime_enable (pfdev->base.dev); +pm_runtime_get_noresume (pfdev->base.dev);pm_runtime_set_autosuspend_delay (pfdev->base.dev,50 );/* ~3 frames */ pm_runtime_use_autosuspend (pfdev->base.dev);@@ -1000,10 +1001,12 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; +pm_runtime_put_autosuspend (pfdev->base.dev);Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_drv.c static int panfrost_probe(struct platform_device *pdev) · line 1009
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +1
-0return 0 ; err_out1: +pm_runtime_put_noidle (pfdev->base.dev);Do we really need this get_noresume/put_noidle dance, can't use call
pm_runtime_dont_use_autosuspend()instead like is done in panthor, or is panthor broken too?
Quoted 4 lines
We need
get_noresume()because afterpanfrost_device_init(), the device is powered up but that is not reflected in the device's PM refcnt. Thenpm_runtime_put_autosuspend()will decrement the refcnt back to 0 and let the autosuspend window expire before suspending the device, unless someone starts using it immediately.
That's more or less what I'm questioning. Can't we make it so panfrost_clk_init() doesn't call clk_prepare_enable() on its clks, and then have a pm_runtime_resume_and_get() in panfrost_device_init() just before we start interacting with the HW components (so basically before panfrost_gpu_init()). Then you don't need this get_noresume/put_noidle() dance, because the init path is just considered like any other path that needs to interact with the HW.
Quoted 13 lines
pm_runtime_dont_use_autosuspend()is not mandatory if we manually callpm_runtime_disable()at device unplug time or whenprobe()fails. pm_runtime_use_autosuspend()'s docs say:
pm_runtime_use_autosuspend- Allow autosuspend to be used for a device. @dev: Target device.
Allow the runtime PM autosuspend mechanism to be used for @dev whenever requested (or "autosuspend" will be handled as direct runtime-suspend for it).
NOTE: It's important to undo this withpm_runtime_dont_use_autosuspend()at driver exit time unless your driver initially enabledpm_runtimewithdevm_pm_runtime_enable()(which handles it for you).
Quoted 2 lines
Panthor uses
devm_pm_runtime_enable(), which makes me suspect perhaps it doesn't need to explicitly callpm_runtime_dont_use_autosuspend().
Yep, devm_pm_runtime_enable() takes care of that, indeed.
Quoted 16 lines
Panthor also manages PM refcnt fine at driver
probe(), insidepanthor_device_init():``` c ret = pm_runtime_resume_and_get(ptdev->base.dev); if (ret) return ret; /* If PM is disabled, we need to call panthor_device_resume() manually. */ if (!IS_ENABLED(CONFIG_PM)) { ret = panthor_device_resume(ptdev->base.dev); if (ret) return ret; } ```
Quoted 3 lines
If we want a similar thing in Panfrost, then we should move all clock and devfreq enablement into
panfrost_device_runtime_resume()and dopm_runtime_resume_and_get()right beforepanfrost_gpu_init().
This ^. You probably want to keep clk_prepare() in the clk_init() path, since resume/suspend() only enable/disable the clks.
Steven Price
maintainerRe: [PATCH v2 6/7] drm/panfrost: Fix PM usage_count mishandling
In reply to Adrián LarumbeQuoted 39 lines · Adrián Larumbe
During device
probe(), failure to do a PMget()will leave theusage_countset to 0, which is the value assigned at device creation time. That means when the autosuspend delay expires, runtime suspend callback won't be invoked, so the device will remain powered on forever.On top of that, failure to call PM
put()during device unplug means Panfrost device's PMusage_countincreases monotonically for every new module reload.The combined outcome of both of the above was that devfreq OPP transition notifications would be printed all the time, even when no jobs are being submitted. This quickly fills the kernel ring buffer with junk.
Even direr than that was the fact MMU interrupts are only enabled when the device is reset, so after device
probe()the very first job targeting the tiler heap BO would always time out, because the driver's PM runtime resume callback would not be invoked.Signed-off-by Adrián Larumbe <[email protected]>Fixes 635430797d3f ("drm/panfrost: Rework runtime PM initialization")Fixes 876b15d2c88d ("drm/panfrost: Fix module unload")--- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_drv.c +1
-0@@ -989,6 +989,7 @@ static int panfrost_probe(struct platform_device *pdev)pm_runtime_set_active (pfdev->base.dev);pm_runtime_mark_last_busy (pfdev->base.dev);pm_runtime_enable (pfdev->base.dev); +pm_runtime_get_noresume (pfdev->base.dev);pm_runtime_set_autosuspend_delay (pfdev->base.dev,50 );/* ~3 frames */ pm_runtime_use_autosuspend (pfdev->base.dev);@@ -1000,10 +1001,12 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 )
drivers/gpu/drm/panfrost/panfrost_drv.c static int panfrost_probe(struct platform_device *pdev) · line 1011
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-0goto err_out1; +pm_runtime_put_autosuspend (pfdev->base.dev);return 0 ; err_out1: +pm_runtime_put_noidle (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);
Sashiko is concerned that dropping the usage count before pm_runtime_disable() could cause things to turn off too early, and I have to agree it sounds like it could be a problem:
Quoted 7 lines · Sashiko
Does dropping the usage count before
pm_runtime_disable()create a race condition where the suspend callback can run and disable clocks before hardware shutdown?
Because the usage count is dropped early, a concurrent PM event could trigger the suspend callback, disabling clocks. Then,panfrost_device_fini()callspanfrost_gpu_fini()which writes to MMIO registers. Could writing to unclocked registers on ARM SoCs cause fatal bus errors or panics?
Sashiko also suggests we might have some other (partially pre-existing) issues here.
https://sashiko.dev/#/patchset/20260604-claude-fixes-v2-0-57c6bd4c1655%40collabora.com
Thanks,
Steve
Quoted 13 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-1pm_runtime_set_suspended (pfdev->base.dev);@@ -1018,8 +1021,9 @@ static void panfrost_remove(struct platform_device *pdev)drm_dev_unregister (&pfdev->base);pm_runtime_get_sync (pfdev->base.dev); -pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev); +pm_runtime_put_noidle (pfdev->base.dev); +pm_runtime_disable (pfdev->base.dev);pm_runtime_set_suspended (pfdev->base.dev); }
Adrián Larumbe
maintainerRe: [PATCH v2 6/7] drm/panfrost: Fix PM usage_count mishandling
Quoted 55 lines · Steven Price
Quoted 39 lines · Adrián Larumbe
During device
probe(), failure to do a PMget()will leave theusage_countset to 0, which is the value assigned at device creation time. That means when the autosuspend delay expires, runtime suspend callback won't be invoked, so the device will remain powered on forever.On top of that, failure to call PM
put()during device unplug means Panfrost device's PMusage_countincreases monotonically for every new module reload.The combined outcome of both of the above was that devfreq OPP transition notifications would be printed all the time, even when no jobs are being submitted. This quickly fills the kernel ring buffer with junk.
Even direr than that was the fact MMU interrupts are only enabled when the device is reset, so after device
probe()the very first job targeting the tiler heap BO would always time out, because the driver's PM runtime resume callback would not be invoked.Signed-off-by Adrián Larumbe <[email protected]>Fixes 635430797d3f ("drm/panfrost: Rework runtime PM initialization")Fixes 876b15d2c88d ("drm/panfrost: Fix module unload")--- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_drv.c +1
-0@@ -989,6 +989,7 @@ static int panfrost_probe(struct platform_device *pdev)pm_runtime_set_active (pfdev->base.dev);pm_runtime_mark_last_busy (pfdev->base.dev);pm_runtime_enable (pfdev->base.dev); +pm_runtime_get_noresume (pfdev->base.dev);pm_runtime_set_autosuspend_delay (pfdev->base.dev,50 );/* ~3 frames */ pm_runtime_use_autosuspend (pfdev->base.dev);@@ -1000,10 +1001,12 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 )drivers/gpu/drm/panfrost/panfrost_drv.c static int panfrost_probe(struct platform_device *pdev) · line 1011
Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-0goto err_out1; +pm_runtime_put_autosuspend (pfdev->base.dev);return 0 ; err_out1: +pm_runtime_put_noidle (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);Sashiko is concerned that dropping the usage count before
pm_runtime_disable()could cause things to turn off too early, and I have to agree it sounds like it could be a problem:
Quoted 8 lines
Quoted 7 lines · Sashiko
Does dropping the usage count before
pm_runtime_disable()create a race condition where the suspend callback can run and disable clocks before hardware shutdown?
Because the usage count is dropped early, a concurrent PM event could trigger the suspend callback, disabling clocks. Then,panfrost_device_fini()callspanfrost_gpu_fini()which writes to MMIO registers. Could writing to unclocked registers on ARM SoCs cause fatal bus errors or panics?
I think this could be an issue if the device were already registered and someone could drive the pm resume and then suspend sequence through an ioctl, but because this is an error path and yet the device was never made available, I can't imagine how this could happen.
Maybe if the panfrost device had any children devices, and when one of them did a put autosuspend, the refcnt would be propagdated back to Panfrost and then trigger the scenario described by shashiko.
However, I've just realised it's alright to call pm_runtime_put_noidle() even after pm_runtime_disable(). Seems that the latter just prevents any further suspends or resumes on the PM device, but we're still in control of the refcnt, so moving pm_runtime_put_noidle() right after panfrost_device_fini() should be fine.
Quoted 4 lines
Sashiko also suggests we might have some other (partially pre-existing) issues here.
https://sashiko.dev/#/patchset/20260604-claude-fixes-v2-0-57c6bd4c1655%40collabora.com
I'll look into all the pre-existing issues and write fixes for the next patch series revision.
Quoted 7 lines
Thanks,
SteveQuoted 4 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +0
-0pm_runtime_set_suspended (pfdev->base.dev);@@ -1018,8 +1021,9 @@ static void panfrost_remove(struct platform_device *pdev)drm_dev_unregister (&pfdev->base);
Quoted 9 lines
drivers/gpu/drm/panfrost/panfrost_drv.c static void panfrost_remove(struct platform_device *pdev) · line 1029
Quoted 9 lines
drivers/gpu/drm/panfrost/panfrost_drv.c +2
-1pm_runtime_get_sync (pfdev->base.dev); -pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev); +pm_runtime_put_noidle (pfdev->base.dev); +pm_runtime_disable (pfdev->base.dev);pm_runtime_set_suspended (pfdev->base.dev); }
Adrian Larumbe
Adrián Larumbe
maintainerPATCH v2 7/7 drm/panfrost: Explicitly enable MMU interrupts at device init
In reply to Adrián LarumbeBecause the device must be in a position to accept jobs between the time drm_dev_register() is called and autosuspend first kicks in, there's a very narrow window inbetween during which jobs targeting the tiler buffer object would time out, since the device's PM status is 'Active', but no MMU interrupts were enabled at device initialisation time.
--- drivers/gpu/drm/panfrost/panfrost_mmu.c | 11 +++++++++-- drivers/gpu/drm/panfrost/panfrost_mmu.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/panfrost/panfrost_mmu.c +9 -2
@@ -336,6 +336,12 @@ void panfrost_mmu_as_put(struct panfrost_device *pfdev, struct panfrost_mmu *mmuWARN_ON (atomic_read (&mmu->as_count) <0 ); } +void panfrost_mmu_enable_interrupts (struct panfrost_device *pfdev) +{ +mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); +mmu_write (pfdev,MMU_INT_MASK , ~0 ); +} +void panfrost_mmu_reset (struct panfrost_device *pfdev) {struct panfrost_mmu *mmu, *mmu_tmp;
@@ -355,8 +361,7 @@ void panfrost_mmu_reset(struct panfrost_device *pfdev)spin_unlock (&pfdev->as_lock); -mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); -mmu_write (pfdev,MMU_INT_MASK , ~0 ); +panfrost_mmu_enable_interrupts (pfdev); }static size_t get_pgsize (u64 addr,size_t size,size_t *count)
@@ -970,6 +975,8 @@ int panfrost_mmu_init(struct panfrost_device *pfdev)return err; } +panfrost_mmu_enable_interrupts (pfdev); +return 0 ; }
drivers/gpu/drm/panfrost/panfrost_mmu.h +2 -0
@@ -12,6 +12,8 @@ struct panfrost_mmu;int panfrost_mmu_map (struct panfrost_gem_mapping *mapping);void panfrost_mmu_unmap (struct panfrost_gem_mapping *mapping); +void panfrost_mmu_enable_interrupts (struct panfrost_device *pfdev); +int panfrost_mmu_init (struct panfrost_device *pfdev);void panfrost_mmu_fini (struct panfrost_device *pfdev);void panfrost_mmu_reset (struct panfrost_device *pfdev);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 7/7] drm/panfrost: Explicitly enable MMU interrupts at device init
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The MMU IRQ handler remains active while device clocks and power domains are disabled during error teardown, causing unclocked MMIO accesses (S-Error).
- [High] panfrost_reset() does not mask or synchronize the MMU interrupt before resetting the GPU hardware, leading to a race condition with the MMU IRQ thread. --
commit cac1cfb873df895888c7871605b659cdaf55b78e
Author: Adrián Larumbe <[email protected]> Date: Thu Jun 4 17:35:26 2026 +0000
drm/panfrost: Explicitly enable MMU interrupts at device init
Because the device must be in a position to accept jobs between the time drm_dev_register() is called and autosuspend first kicks in, there's a very narrow window inbetween during which jobs targeting the tiler buffer object would time out, since the device's PM status is 'Active', but no MMU interrupts were enabled at device initialisation time.
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_mmu.c +0
-0
[ ... ]
drivers/gpu/drm/panfrost/panfrost_mmu.c void panfrost_mmu_reset(struct panfrost_device *pfdev) · line 365
Quoted 8 lines
drivers/gpu/drm/panfrost/panfrost_mmu.c +1
-2@@ -355,8 +361,7 @@ void panfrost_mmu_reset(struct panfrost_device *pfdev)spin_unlock (&pfdev->as_lock); -mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); -mmu_write (pfdev,MMU_INT_MASK , ~0 ); +panfrost_mmu_enable_interrupts (pfdev); }
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the interrupt handling during reset, does panfrost_reset() need to mask and synchronize the MMU interrupt before resetting the hardware?
When a job timeout occurs, panfrost_reset() correctly masks and synchronizes the job manager interrupts:
drivers/gpu/drm/panfrost/panfrost_job.c:panfrost_reset() {
/* 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_device_reset(pfdev, true);...
}
However, it does not do the same for the MMU interrupt (pfdev->mmu_irq).
Because MMU faults often cause job timeouts, the panfrost_mmu_irq_handler_thread could be actively running concurrently on another CPU.
If the IRQ thread attempts to handle an MMU page fault, it will write to MMU registers while panfrost_device_reset() concurrently calls panfrost_gpu_soft_reset() to reset the hardware.
Can uncoordinated MMIO accesses to hardware undergoing a soft reset lead to unpredictable behavior or bus errors?
[ ... ]
drivers/gpu/drm/panfrost/panfrost_mmu.c int panfrost_mmu_init(struct panfrost_device *pfdev) · line 979
Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_mmu.c +2
-0@@ -970,6 +975,8 @@ int panfrost_mmu_init(struct panfrost_device *pfdev)return err; } +panfrost_mmu_enable_interrupts (pfdev); +
[Severity: High]
This is a pre-existing issue, but by explicitly enabling the MMU interrupts here during init, does this expose a race condition in the device initialization error paths?
If a subsequent initialization step like panfrost_jm_init() fails, panfrost_device_init() will jump to the out_mmu label:
drivers/gpu/drm/panfrost/panfrost_device.c:panfrost_device_init() {
...
err = panfrost_jm_init(pfdev); if (err) goto out_mmu; ... out_mmu: panfrost_mmu_fini(pfdev); ... out_clk: panfrost_clk_fini(pfdev);
...
}
panfrost_mmu_fini() masks the interrupt in hardware, but does not synchronize or disable the IRQ handler in the kernel:
void panfrost_mmu_fini(struct panfrost_device *pfdev)
{
mmu_write(pfdev, MMU_INT_MASK, 0);
}Because panfrost_mmu_init() registers a shared threaded IRQ handler using devm_request_threaded_irq(), the handler remains active during the rest of the teardown.
If an interrupt fires or the thread runs after panfrost_clk_fini() has disabled the hardware clocks, panfrost_mmu_irq_handler() will read unclocked MMIO registers (e.g., mmu_read(pfdev, MMU_INT_STAT)).
Could this lead to a fatal S-Error (synchronous external abort)?
Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_mmu.c +0
-0return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Boris Brezillon
maintainerRe: [PATCH v2 7/7] drm/panfrost: Explicitly enable MMU interrupts at device init
In reply to Adrián LarumbeQuoted 54 lines · On Thu, 04 Jun 2026 18:35:26 +0100 Adrián Larumbe…
Because the device must be in a position to accept jobs between the time
drm_dev_register()is called and autosuspend first kicks in, there's a very narrow window inbetween during which jobs targeting the tiler buffer object would time out, since the device's PM status is 'Active', but no MMU interrupts were enabled at device initialisation time.Signed-off-by Adrián Larumbe <[email protected]>Fixes 73e467f60acd ("drm/panfrost: Consolidate reset handling")--- drivers/gpu/drm/panfrost/panfrost_mmu.c | 11 +++++++++-- drivers/gpu/drm/panfrost/panfrost_mmu.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-)drivers/gpu/drm/panfrost/panfrost_mmu.c +9
-2@@ -336,6 +336,12 @@ void panfrost_mmu_as_put(struct panfrost_device *pfdev, struct panfrost_mmu *mmuWARN_ON (atomic_read (&mmu->as_count) <0 ); } +void panfrost_mmu_enable_interrupts (struct panfrost_device *pfdev) +{ +mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); +mmu_write (pfdev,MMU_INT_MASK , ~0 ); +} +void panfrost_mmu_reset (struct panfrost_device *pfdev) {struct panfrost_mmu *mmu, *mmu_tmp;@@ -355,8 +361,7 @@ void panfrost_mmu_reset(struct panfrost_device *pfdev)spin_unlock (&pfdev->as_lock); -mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); -mmu_write (pfdev,MMU_INT_MASK , ~0 ); +panfrost_mmu_enable_interrupts (pfdev); }static size_t get_pgsize (u64 addr,size_t size,size_t *count)@@ -970,6 +975,8 @@ int panfrost_mmu_init(struct panfrost_device *pfdev)return err; } +panfrost_mmu_enable_interrupts (pfdev); +return 0 ; }drivers/gpu/drm/panfrost/panfrost_mmu.h +0
-0
drivers/gpu/drm/panfrost/panfrost_mmu.h struct panfrost_mmu; · line 15
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_mmu.h +1
-0@@ -12,6 +12,8 @@ struct panfrost_mmu;int panfrost_mmu_map (struct panfrost_gem_mapping *mapping);void panfrost_mmu_unmap (struct panfrost_gem_mapping *mapping); +void panfrost_mmu_enable_interrupts (struct panfrost_device *pfdev);
You don't need to expose this function, it's only used inside panfrost_mmu.c.
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_mmu.h +1
-0+int panfrost_mmu_init (struct panfrost_device *pfdev);void panfrost_mmu_fini (struct panfrost_device *pfdev);void panfrost_mmu_reset (struct panfrost_device *pfdev);
Adrián Larumbe
maintainerRe: [PATCH v2 7/7] drm/panfrost: Explicitly enable MMU interrupts at device init
Quoted 60 lines · Boris Brezillon
Quoted 57 lines · On Thu, 04 Jun 2026 18:35:26 +0100 Adrián Larumbe…
Because the device must be in a position to accept jobs between the time
drm_dev_register()is called and autosuspend first kicks in, there's a very narrow window inbetween during which jobs targeting the tiler buffer object would time out, since the device's PM status is 'Active', but no MMU interrupts were enabled at device initialisation time.Signed-off-by Adrián Larumbe <[email protected]>Fixes 73e467f60acd ("drm/panfrost: Consolidate reset handling")--- drivers/gpu/drm/panfrost/panfrost_mmu.c | 11 +++++++++-- drivers/gpu/drm/panfrost/panfrost_mmu.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-)drivers/gpu/drm/panfrost/panfrost_mmu.c +9
-2@@ -336,6 +336,12 @@ void panfrost_mmu_as_put(struct panfrost_device *pfdev, struct panfrost_mmu *mmuWARN_ON (atomic_read (&mmu->as_count) <0 ); } +void panfrost_mmu_enable_interrupts (struct panfrost_device *pfdev) +{ +mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); +mmu_write (pfdev,MMU_INT_MASK , ~0 ); +} +void panfrost_mmu_reset (struct panfrost_device *pfdev) {struct panfrost_mmu *mmu, *mmu_tmp;@@ -355,8 +361,7 @@ void panfrost_mmu_reset(struct panfrost_device *pfdev)spin_unlock (&pfdev->as_lock); -mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); -mmu_write (pfdev,MMU_INT_MASK , ~0 ); +panfrost_mmu_enable_interrupts (pfdev); }static size_t get_pgsize (u64 addr,size_t size,size_t *count)@@ -970,6 +975,8 @@ int panfrost_mmu_init(struct panfrost_device *pfdev)return err; } +panfrost_mmu_enable_interrupts (pfdev); +return 0 ; }drivers/gpu/drm/panfrost/panfrost_mmu.h +0
-0@@ -12,6 +12,8 @@ struct panfrost_mmu;int panfrost_mmu_map (struct panfrost_gem_mapping *mapping);void panfrost_mmu_unmap (struct panfrost_gem_mapping *mapping);
Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_mmu.h struct panfrost_mmu; · line 15
Quoted 1 line
drivers/gpu/drm/panfrost/panfrost_mmu.h +1
-0+void panfrost_mmu_enable_interrupts (struct panfrost_device *pfdev);You don't need to expose this function, it's only used inside
panfrost_mmu.c.
Will remove in the next revision.
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_mmu.h struct panfrost_mmu; · line 19
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_mmu.h +1
-0+int panfrost_mmu_init (struct panfrost_device *pfdev);void panfrost_mmu_fini (struct panfrost_device *pfdev);void panfrost_mmu_reset (struct panfrost_device *pfdev);
Adrian Larumbe