Skip to contentSkip to conversation

drm/panthor: Evict groups before VM termination

PATCH Superseded Ketil Johnsen 4 participants 7 messages Dec 18, 2025 – Dec 19, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/panthor: Evict groups before VM termination

Ensure all related groups are evicted and suspended before VM destruction takes place.

This fixes an issue where panthor_vm_destroy() destroys and unmaps the heap context while there are still on slot groups using this. The FW will do a write out to the heap context when a CSG (group) is suspended, so a premature unmap of the heap context will cause a GPU page fault.
This page fault is quite harmless, and do not affect the continued operation of the GPU.

Fixes 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
---
 drivers/gpu/drm/panthor/panthor_mmu.c   |  4 ++++
 drivers/gpu/drm/panthor/panthor_sched.c | 16 ++++++++++++++++
 drivers/gpu/drm/panthor/panthor_sched.h |  1 +
 3 files changed, 21 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +4 -0
index 74230f7199121..0e4b301a9c70e 100644
@@ -1537,6 +1537,10 @@ static void panthor_vm_destroy(struct panthor_vm *vm)
 
 	vm->destroyed = true;
 
+	/* Tell scheduler to stop all GPU work related to this VM */
+	if (refcount_read(&vm->as.active_cnt) > 0)
+		panthor_sched_prepare_for_vm_destruction(vm->ptdev);
+
 	mutex_lock(&vm->heaps.lock);
 	panthor_heap_pool_destroy(vm->heaps.pool);
 	vm->heaps.pool = NULL;
drivers/gpu/drm/panthor/panthor_sched.c +16 -0
index f680edcd40aad..fbbaab9b25efb 100644
@@ -2930,6 +2930,22 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev)
 		sched_queue_delayed_work(ptdev->scheduler, tick, 0);
 }
 
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev)
+{
+	/* FW can write out internal state, like the heap context, during CSG
+	 * suspend. It is therefore important that the scheduler has fully
+	 * evicted any pending and related groups before VM destruction can
+	 * safely continue. Failure to do so can lead to GPU page faults.
+	 * A controlled termination of a Panthor instance involves destroying
+	 * the group(s) before the VM. This means any relevant group eviction
+	 * has already been initiated by this point, and we just need to
+	 * ensure that any pending tick_work() has been completed.
+	 */
+	if (ptdev->scheduler) {
+		flush_work(&ptdev->scheduler->tick_work.work);
+	}
+}
+
 void panthor_sched_resume(struct panthor_device *ptdev)
 {
 	/* Force a tick to re-evaluate after a resume. */
drivers/gpu/drm/panthor/panthor_sched.h +1 -0
index f4a475aa34c0a..9a8692de8aded 100644
@@ -50,6 +50,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev);
 void panthor_sched_resume(struct panthor_device *ptdev);
 
 void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
 void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
 
 void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 47 lines · Ketil Johnsen

Ensure all related groups are evicted and suspended before VM destruction takes place.

This fixes an issue where panthor_vm_destroy() destroys and unmaps the heap context while there are still on slot groups using this. The FW will do a write out to the heap context when a CSG (group) is suspended, so a premature unmap of the heap context will cause a GPU page fault.
This page fault is quite harmless, and do not affect the continued operation of the GPU.

Fixes 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
---
 drivers/gpu/drm/panthor/panthor_mmu.c   |  4 ++++
 drivers/gpu/drm/panthor/panthor_sched.c | 16 ++++++++++++++++
 drivers/gpu/drm/panthor/panthor_sched.h |  1 +
 3 files changed, 21 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +4 -0
index 74230f7199121..0e4b301a9c70e 100644
@@ -1537,6 +1537,10 @@ static void panthor_vm_destroy(struct panthor_vm *vm)
 
 	vm->destroyed = true;
 
+	/* Tell scheduler to stop all GPU work related to this VM */
+	if (refcount_read(&vm->as.active_cnt) > 0)
+		panthor_sched_prepare_for_vm_destruction(vm->ptdev);
+
 	mutex_lock(&vm->heaps.lock);
 	panthor_heap_pool_destroy(vm->heaps.pool);
 	vm->heaps.pool = NULL;
drivers/gpu/drm/panthor/panthor_sched.c +4 -0
index f680edcd40aad..fbbaab9b25efb 100644
@@ -2930,6 +2930,22 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev)
 		sched_queue_delayed_work(ptdev->scheduler, tick, 0);
 }
 
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev)
+{
+	/* FW can write out internal state, like the heap context, during CSG
+	 * suspend. It is therefore important that the scheduler has fully

drivers/gpu/drm/panthor/panthor_sched.c void panthor_sched_report_mmu_fault(struct panthor_device *ptdev) · line 2946

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10 -0
+	 * evicted any pending and related groups before VM destruction can
+	 * safely continue. Failure to do so can lead to GPU page faults.
+	 * A controlled termination of a Panthor instance involves destroying
+	 * the group(s) before the VM. This means any relevant group eviction
+	 * has already been initiated by this point, and we just need to
+	 * ensure that any pending tick_work() has been completed.
+	 */
+	if (ptdev->scheduler) {
+		flush_work(&ptdev->scheduler->tick_work.work);
+	}

NIT: braces not needed.

But I'm also struggling to understand in what situation ptdev->scheduler would be NULL?

Thanks,
Steve

Quoted 17 lines
drivers/gpu/drm/panthor/panthor_sched.c +2 -0
+}
+
 void panthor_sched_resume(struct panthor_device *ptdev)
 {
 	/* Force a tick to re-evaluate after a resume. */
drivers/gpu/drm/panthor/panthor_sched.h +1 -0
index f4a475aa34c0a..9a8692de8aded 100644
@@ -50,6 +50,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev);
 void panthor_sched_resume(struct panthor_device *ptdev);
 
 void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
 void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
 
 void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);
maintainer
#2 lore raw
Quoted 61 lines · On Thu, 18 Dec 2025 16:57:28 +0000 Steven Price <[email protected]> wrote:
Quoted 47 lines · Ketil Johnsen

Ensure all related groups are evicted and suspended before VM destruction takes place.

This fixes an issue where panthor_vm_destroy() destroys and unmaps the heap context while there are still on slot groups using this. The FW will do a write out to the heap context when a CSG (group) is suspended, so a premature unmap of the heap context will cause a GPU page fault.
This page fault is quite harmless, and do not affect the continued operation of the GPU.

Fixes 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
---
 drivers/gpu/drm/panthor/panthor_mmu.c   |  4 ++++
 drivers/gpu/drm/panthor/panthor_sched.c | 16 ++++++++++++++++
 drivers/gpu/drm/panthor/panthor_sched.h |  1 +
 3 files changed, 21 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +4 -0
index 74230f7199121..0e4b301a9c70e 100644
@@ -1537,6 +1537,10 @@ static void panthor_vm_destroy(struct panthor_vm *vm)
 
 	vm->destroyed = true;
 
+	/* Tell scheduler to stop all GPU work related to this VM */
+	if (refcount_read(&vm->as.active_cnt) > 0)
+		panthor_sched_prepare_for_vm_destruction(vm->ptdev);
+
 	mutex_lock(&vm->heaps.lock);
 	panthor_heap_pool_destroy(vm->heaps.pool);
 	vm->heaps.pool = NULL;
drivers/gpu/drm/panthor/panthor_sched.c +4 -0
index f680edcd40aad..fbbaab9b25efb 100644
@@ -2930,6 +2930,22 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev)
 		sched_queue_delayed_work(ptdev->scheduler, tick, 0);
 }
 
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev)
+{
+	/* FW can write out internal state, like the heap context, during CSG
+	 * suspend. It is therefore important that the scheduler has fully

drivers/gpu/drm/panthor/panthor_sched.c void panthor_sched_report_mmu_fault(struct panthor_device *ptdev) · line 2946

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10 -0
+	 * evicted any pending and related groups before VM destruction can
+	 * safely continue. Failure to do so can lead to GPU page faults.
+	 * A controlled termination of a Panthor instance involves destroying
+	 * the group(s) before the VM. This means any relevant group eviction
+	 * has already been initiated by this point, and we just need to
+	 * ensure that any pending tick_work() has been completed.
+	 */
+	if (ptdev->scheduler) {
+		flush_work(&ptdev->scheduler->tick_work.work);
+	}  

NIT: braces not needed.

Quoted 2 lines

But I'm also struggling to understand in what situation ptdev->scheduler would be NULL?

I thought it could happen if the FW initialization fails in the middle, and the FW VM is destroyed before the scheduler had a chance to initialize, but it turns out the FW logic never calls panthor_vm_destroy().

Quoted 22 lines

Thanks,
Steve

Quoted 17 lines
drivers/gpu/drm/panthor/panthor_sched.c +2 -0
+}
+
 void panthor_sched_resume(struct panthor_device *ptdev)
 {
 	/* Force a tick to re-evaluate after a resume. */
drivers/gpu/drm/panthor/panthor_sched.h +1 -0
index f4a475aa34c0a..9a8692de8aded 100644
@@ -50,6 +50,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev);
 void panthor_sched_resume(struct panthor_device *ptdev);
 
 void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
 void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
 
 void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);  
#3 lore raw
Quoted 33 lines · Boris Brezillon
Quoted 29 lines · On Thu, 18 Dec 2025 16:57:28 +0000 Steven Price <[email protected]> wrote:
Quoted 28 lines · Ketil Johnsen

Ensure all related groups are evicted and suspended before VM destruction takes place.

This fixes an issue where panthor_vm_destroy() destroys and unmaps the heap context while there are still on slot groups using this. The FW will do a write out to the heap context when a CSG (group) is suspended, so a premature unmap of the heap context will cause a GPU page fault.
This page fault is quite harmless, and do not affect the continued operation of the GPU.

Fixes 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
---
 drivers/gpu/drm/panthor/panthor_mmu.c   |  4 ++++
 drivers/gpu/drm/panthor/panthor_sched.c | 16 ++++++++++++++++
 drivers/gpu/drm/panthor/panthor_sched.h |  1 +
 3 files changed, 21 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +0 -0
index 74230f7199121..0e4b301a9c70e 100644
@@ -1537,6 +1537,10 @@ static void panthor_vm_destroy(struct panthor_vm *vm)
 
    vm->destroyed = true;
 
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/panthor/panthor_mmu.c static void panthor_vm_destroy(struct panthor_vm *vm) · line 1546

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_mmu.c +4 -0
+   /* Tell scheduler to stop all GPU work related to this VM */
+   if (refcount_read(&vm->as.active_cnt) > 0)
+           panthor_sched_prepare_for_vm_destruction(vm->ptdev);
+
    mutex_lock(&vm->heaps.lock);
    panthor_heap_pool_destroy(vm->heaps.pool);
    vm->heaps.pool = NULL;

Is it better to remove the panthor_heap_pool_destroy call here instead and let panthor_vm_free take care of it?

Quoted 56 lines
Quoted 25 lines
Quoted 12 lines
drivers/gpu/drm/panthor/panthor_sched.c +4 -0
index f680edcd40aad..fbbaab9b25efb 100644
@@ -2930,6 +2930,22 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev)
            sched_queue_delayed_work(ptdev->scheduler, tick, 0);
 }
 
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev)
+{
+   /* FW can write out internal state, like the heap context, during CSG
+    * suspend. It is therefore important that the scheduler has fully

drivers/gpu/drm/panthor/panthor_sched.c void panthor_sched_report_mmu_fault(struct panthor_device *ptdev) · line 2946

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10 -0
+    * evicted any pending and related groups before VM destruction can
+    * safely continue. Failure to do so can lead to GPU page faults.
+    * A controlled termination of a Panthor instance involves destroying
+    * the group(s) before the VM. This means any relevant group eviction
+    * has already been initiated by this point, and we just need to
+    * ensure that any pending tick_work() has been completed.
+    */
+   if (ptdev->scheduler) {
+           flush_work(&ptdev->scheduler->tick_work.work);
+   }

NIT: braces not needed.

Quoted 2 lines

But I'm also struggling to understand in what situation ptdev->scheduler would be NULL?

I thought it could happen if the FW initialization fails in the middle, and the FW VM is destroyed before the scheduler had a chance to initialize, but it turns out the FW logic never calls panthor_vm_destroy().

Quoted 22 lines

Thanks,
Steve

Quoted 17 lines
drivers/gpu/drm/panthor/panthor_sched.c +2 -0
+}
+
 void panthor_sched_resume(struct panthor_device *ptdev)
 {
    /* Force a tick to re-evaluate after a resume. */
drivers/gpu/drm/panthor/panthor_sched.h +1 -0
index f4a475aa34c0a..9a8692de8aded 100644
@@ -50,6 +50,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev);
 void panthor_sched_resume(struct panthor_device *ptdev);
 
 void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
 void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
 
 void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);
maintainer
#4 lore raw
Quoted 35 lines · On Thu, 18 Dec 2025 14:54:35 -0800 Chia-I Wu <[email protected]> wrote:
Quoted 33 lines · Boris Brezillon
Quoted 29 lines · On Thu, 18 Dec 2025 16:57:28 +0000 Steven Price <[email protected]> wrote:
Quoted 28 lines · Ketil Johnsen

Ensure all related groups are evicted and suspended before VM destruction takes place.

This fixes an issue where panthor_vm_destroy() destroys and unmaps the heap context while there are still on slot groups using this. The FW will do a write out to the heap context when a CSG (group) is suspended, so a premature unmap of the heap context will cause a GPU page fault.
This page fault is quite harmless, and do not affect the continued operation of the GPU.

Fixes 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
---
 drivers/gpu/drm/panthor/panthor_mmu.c   |  4 ++++
 drivers/gpu/drm/panthor/panthor_sched.c | 16 ++++++++++++++++
 drivers/gpu/drm/panthor/panthor_sched.h |  1 +
 3 files changed, 21 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +0 -0
index 74230f7199121..0e4b301a9c70e 100644
@@ -1537,6 +1537,10 @@ static void panthor_vm_destroy(struct panthor_vm *vm)
 
    vm->destroyed = true;
 
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/panthor/panthor_mmu.c static void panthor_vm_destroy(struct panthor_vm *vm) · line 1546

Quoted 7 lines
drivers/gpu/drm/panthor/panthor_mmu.c +4 -0
+   /* Tell scheduler to stop all GPU work related to this VM */
+   if (refcount_read(&vm->as.active_cnt) > 0)
+           panthor_sched_prepare_for_vm_destruction(vm->ptdev);
+
    mutex_lock(&vm->heaps.lock);
    panthor_heap_pool_destroy(vm->heaps.pool);
    vm->heaps.pool = NULL;  

Is it better to remove the panthor_heap_pool_destroy call here instead and let panthor_vm_free take care of it?

We can't because the heap_pool contains heap chunks (kernel BOs) that are mapped in the very same VM, thus creating a circular ref. The whole point of calling panthor_heap_pool_destroy() here is to kill this circular ref. We could introduce the concept of weak and hard VM refs, but I'm not sure it's worth it.

Quoted 57 lines
Quoted 57 lines
Quoted 26 lines
Quoted 13 lines
drivers/gpu/drm/panthor/panthor_sched.c +4 -0
index f680edcd40aad..fbbaab9b25efb 100644
@@ -2930,6 +2930,22 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev)
            sched_queue_delayed_work(ptdev->scheduler, tick, 0);
 }
 
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev)
+{
+   /* FW can write out internal state, like the heap context, during CSG
+    * suspend. It is therefore important that the scheduler has fully

drivers/gpu/drm/panthor/panthor_sched.c void panthor_sched_report_mmu_fault(struct panthor_device *ptdev) · line 2946

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10 -0
+    * evicted any pending and related groups before VM destruction can
+    * safely continue. Failure to do so can lead to GPU page faults.
+    * A controlled termination of a Panthor instance involves destroying
+    * the group(s) before the VM. This means any relevant group eviction
+    * has already been initiated by this point, and we just need to
+    * ensure that any pending tick_work() has been completed.
+    */
+   if (ptdev->scheduler) {
+           flush_work(&ptdev->scheduler->tick_work.work);
+   }  

NIT: braces not needed.

Quoted 2 lines

But I'm also struggling to understand in what situation ptdev->scheduler would be NULL?

I thought it could happen if the FW initialization fails in the middle, and the FW VM is destroyed before the scheduler had a chance to initialize, but it turns out the FW logic never calls panthor_vm_destroy().

Quoted 22 lines

Thanks,
Steve

Quoted 17 lines
drivers/gpu/drm/panthor/panthor_sched.c +2 -0
+}
+
 void panthor_sched_resume(struct panthor_device *ptdev)
 {
    /* Force a tick to re-evaluate after a resume. */
drivers/gpu/drm/panthor/panthor_sched.h +1 -0
index f4a475aa34c0a..9a8692de8aded 100644
@@ -50,6 +50,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev);
 void panthor_sched_resume(struct panthor_device *ptdev);
 
 void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
 void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
 
 void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);  
#5 lore raw
In reply to Boris Brezillon
Quoted 64 lines · Boris Brezillon
Quoted 61 lines · On Thu, 18 Dec 2025 16:57:28 +0000 Steven Price <[email protected]> wrote:
Quoted 47 lines · Ketil Johnsen

Ensure all related groups are evicted and suspended before VM destruction takes place.

This fixes an issue where panthor_vm_destroy() destroys and unmaps the heap context while there are still on slot groups using this. The FW will do a write out to the heap context when a CSG (group) is suspended, so a premature unmap of the heap context will cause a GPU page fault.
This page fault is quite harmless, and do not affect the continued operation of the GPU.

Fixes 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
---
  drivers/gpu/drm/panthor/panthor_mmu.c   |  4 ++++
  drivers/gpu/drm/panthor/panthor_sched.c | 16 ++++++++++++++++
  drivers/gpu/drm/panthor/panthor_sched.h |  1 +
  3 files changed, 21 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +4 -0
index 74230f7199121..0e4b301a9c70e 100644
@@ -1537,6 +1537,10 @@ static void panthor_vm_destroy(struct panthor_vm *vm)
 
  	vm->destroyed = true;
 
+	/* Tell scheduler to stop all GPU work related to this VM */
+	if (refcount_read(&vm->as.active_cnt) > 0)
+		panthor_sched_prepare_for_vm_destruction(vm->ptdev);
+
  	mutex_lock(&vm->heaps.lock);
  	panthor_heap_pool_destroy(vm->heaps.pool);
  	vm->heaps.pool = NULL;
drivers/gpu/drm/panthor/panthor_sched.c +4 -0
index f680edcd40aad..fbbaab9b25efb 100644
@@ -2930,6 +2930,22 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev)
  		sched_queue_delayed_work(ptdev->scheduler, tick, 0);
  }
 
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev)
+{
+	/* FW can write out internal state, like the heap context, during CSG
+	 * suspend. It is therefore important that the scheduler has fully

drivers/gpu/drm/panthor/panthor_sched.c void panthor_sched_report_mmu_fault(struct panthor_device *ptdev) · line 2946

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10 -0
+	 * evicted any pending and related groups before VM destruction can
+	 * safely continue. Failure to do so can lead to GPU page faults.
+	 * A controlled termination of a Panthor instance involves destroying
+	 * the group(s) before the VM. This means any relevant group eviction
+	 * has already been initiated by this point, and we just need to
+	 * ensure that any pending tick_work() has been completed.
+	 */
+	if (ptdev->scheduler) {
+		flush_work(&ptdev->scheduler->tick_work.work);
+	}

NIT: braces not needed.

Quoted 7 lines
Quoted 2 lines

But I'm also struggling to understand in what situation ptdev->scheduler would be NULL?

I thought it could happen if the FW initialization fails in the middle, and the FW VM is destroyed before the scheduler had a chance to initialize, but it turns out the FW logic never calls panthor_vm_destroy().

Yes, I also think we can safely drop the check. I even injected some probe errors to double check, and I see that we still terminate the FW VM successfully (as this is not executed in this case).

I will send a v2 shortly with this check (and braces) removed.

--
Thanks,
Ketil

Quoted 22 lines
Quoted 21 lines

Thanks,
Steve

Quoted 17 lines
drivers/gpu/drm/panthor/panthor_sched.c +2 -0
+}
+
  void panthor_sched_resume(struct panthor_device *ptdev)
  {
  	/* Force a tick to re-evaluate after a resume. */
drivers/gpu/drm/panthor/panthor_sched.h +1 -0
index f4a475aa34c0a..9a8692de8aded 100644
@@ -50,6 +50,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev);
  void panthor_sched_resume(struct panthor_device *ptdev);
 
  void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
  void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
 
  void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);
maintainer Reviewed-by on v1 1/1
#6 lore raw
In reply to Ketil Johnsen
Quoted 11 lines · On Thu, 18 Dec 2025 17:26:42 +0100 Ketil Johnsen <[email protected]> wrote:

Ensure all related groups are evicted and suspended before VM destruction takes place.

This fixes an issue where panthor_vm_destroy() destroys and unmaps the heap context while there are still on slot groups using this. The FW will do a write out to the heap context when a CSG (group) is suspended, so a premature unmap of the heap context will cause a GPU page fault.
This page fault is quite harmless, and do not affect the continued operation of the GPU.

Quoted 3 lines
Fixes 647810ec2476 ("drm/panthor: Add the MMU/VM logical block")
Quoted 33 lines
---
 drivers/gpu/drm/panthor/panthor_mmu.c   |  4 ++++
 drivers/gpu/drm/panthor/panthor_sched.c | 16 ++++++++++++++++
 drivers/gpu/drm/panthor/panthor_sched.h |  1 +
 3 files changed, 21 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +4 -0
index 74230f7199121..0e4b301a9c70e 100644
@@ -1537,6 +1537,10 @@ static void panthor_vm_destroy(struct panthor_vm *vm)
 
 	vm->destroyed = true;
 
+	/* Tell scheduler to stop all GPU work related to this VM */
+	if (refcount_read(&vm->as.active_cnt) > 0)
+		panthor_sched_prepare_for_vm_destruction(vm->ptdev);
+
 	mutex_lock(&vm->heaps.lock);
 	panthor_heap_pool_destroy(vm->heaps.pool);
 	vm->heaps.pool = NULL;
drivers/gpu/drm/panthor/panthor_sched.c +4 -0
index f680edcd40aad..fbbaab9b25efb 100644
@@ -2930,6 +2930,22 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev)
 		sched_queue_delayed_work(ptdev->scheduler, tick, 0);
 }
 
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev)
+{
+	/* FW can write out internal state, like the heap context, during CSG
+	 * suspend. It is therefore important that the scheduler has fully

drivers/gpu/drm/panthor/panthor_sched.c void panthor_sched_report_mmu_fault(struct panthor_device *ptdev) · line 2946

Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10 -0
+	 * evicted any pending and related groups before VM destruction can
+	 * safely continue. Failure to do so can lead to GPU page faults.
+	 * A controlled termination of a Panthor instance involves destroying
+	 * the group(s) before the VM. This means any relevant group eviction
+	 * has already been initiated by this point, and we just need to
+	 * ensure that any pending tick_work() has been completed.
+	 */
+	if (ptdev->scheduler) {
+		flush_work(&ptdev->scheduler->tick_work.work);
+	}

nit: you can drop the curly braces on single line conditionals. No need to send a v2, I can fix this up when applying.

Quoted 17 lines
drivers/gpu/drm/panthor/panthor_sched.c +2 -0
+}
+
 void panthor_sched_resume(struct panthor_device *ptdev)
 {
 	/* Force a tick to re-evaluate after a resume. */
drivers/gpu/drm/panthor/panthor_sched.h +1 -0
index f4a475aa34c0a..9a8692de8aded 100644
@@ -50,6 +50,7 @@ void panthor_sched_suspend(struct panthor_device *ptdev);
 void panthor_sched_resume(struct panthor_device *ptdev);
 
 void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
+void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
 void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
 
 void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);