Skip to contentSkip to conversation

drm/panthor: Fix regressions introduced recently

PATCH Superseded Boris Brezillon 4 participants 10 messages Dec 2, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Boris Brezillon

author maintainer
#0 lore raw

cover drm/panthor: Fix regressions introduced recently

Hello,

This is a set of fixes for regressions noticed while testing the drm-misc-next branch against mesa-ci.

Regards,

Boris

Boris Brezillon (3):
drm/panthor: Drop a WARN_ON() in group_free_queue() drm/panthor: Make sure caches are flushed/invalidated when an AS is
recycled
drm/panthor: Unlock the locked region before disabling an AS

 drivers/gpu/drm/panthor/panthor_mmu.c   | 37 +++++++++++++++++++++----
 drivers/gpu/drm/panthor/panthor_sched.c |  5 ++--
 2 files changed, 33 insertions(+), 9 deletions(-)
Signature · 1 line
2.51.1
author maintainer
#1 lore raw

PATCH 1/3 drm/panthor: Drop a WARN_ON() in group_free_queue()

It appears the timeout can still be enabled when we reach that point, because of the asynchronous progress check done on queues that resets the timer when jobs are still in-flight, but progress was made. We could add more checks to make sure the timer is not re-enabled when a group can't run anymore, but we don't have a group to pass to queue_check_job_completion() in some context.

It's just as safe (we just want to be sure the timer is stopped before we destroy the queue) and simpler to drop the WARN_ON() in group_free_queue().

---
 drivers/gpu/drm/panthor/panthor_sched.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +2 -3
index 389d508b3848..203f6a0a6b9a 100644
@@ -893,9 +893,8 @@ static void group_free_queue(struct panthor_group *group, struct panthor_queue *
 	if (IS_ERR_OR_NULL(queue))
 		return;
 
-	/* This should have been disabled before that point. */
-	drm_WARN_ON(&group->ptdev->base,
-		    disable_delayed_work_sync(&queue->timeout.work));
+	/* Disable the timeout before tearing down drm_sched components. */
+	disable_delayed_work_sync(&queue->timeout.work);
 
 	if (queue->entity.fence_context)
 		drm_sched_entity_destroy(&queue->entity);
Signature · 1 line
2.51.1
maintainer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH v1 1/3] drm/panthor: Drop a WARN_ON() in group_free_queue()

Quoted 7 lines · Boris Brezillon

It appears the timeout can still be enabled when we reach that point, because of the asynchronous progress check done on queues that resets the timer when jobs are still in-flight, but progress was made. We could add more checks to make sure the timer is not re-enabled when a group can't run anymore, but we don't have a group to pass to queue_check_job_completion() in some context.

Quoted 5 lines

It's just as safe (we just want to be sure the timer is stopped before we destroy the queue) and simpler to drop the WARN_ON() in group_free_queue().

Best regards,
Liviu

Quoted 23 lines
---
 drivers/gpu/drm/panthor/panthor_sched.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +2 -3
index 389d508b3848..203f6a0a6b9a 100644
@@ -893,9 +893,8 @@ static void group_free_queue(struct panthor_group *group, struct panthor_queue *
 	if (IS_ERR_OR_NULL(queue))
 		return;
 
-	/* This should have been disabled before that point. */
-	drm_WARN_ON(&group->ptdev->base,
-		    disable_delayed_work_sync(&queue->timeout.work));
+	/* Disable the timeout before tearing down drm_sched components. */
+	disable_delayed_work_sync(&queue->timeout.work);
 
 	if (queue->entity.fence_context)
 		drm_sched_entity_destroy(&queue->entity);
Signature · 1 line
2.51.1
author maintainer
#3 lore raw

PATCH 2/3 drm/panthor: Make sure caches are flushed/invalidated when an AS is recycled

In reply to Boris Brezillon

When we re-assign a slot to a different VM, we need to make sure the old VM caches are flushed before doing the switch. Specialize panthor_mmu_as_disable() so we can skip the slot programmation while still getting the cache flushing, and call this helper from panthor_vm_active() when an idle slot is recycled.

Fixes 6e2d3b3e8589 ("drm/panthor: Add support for atomic page table updates")
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/gpu/drm/panthor/panthor_mmu.c +20 -6
index 8ba5259e3d28..3644af1a8e56 100644
@@ -585,7 +585,8 @@ static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
 	return as_send_cmd_and_wait(ptdev, as_nr, AS_COMMAND_UPDATE);
 }
 
-static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr)
+static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
+				  bool recycle_slot)
 {
 	int ret;
 
@@ -595,6 +596,12 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr)
 	if (ret)
 		return ret;
 
+	/* If the slot is going to be used immediately, don't bother changing
+	 * the config.
+	 */
+	if (recycle_slot)
+		return 0;
+
 	gpu_write64(ptdev, AS_TRANSTAB(as_nr), 0);
 	gpu_write64(ptdev, AS_MEMATTR(as_nr), 0);
 	gpu_write64(ptdev, AS_TRANSCFG(as_nr), AS_TRANSCFG_ADRMODE_UNMAPPED);
@@ -714,6 +721,11 @@ int panthor_vm_active(struct panthor_vm *vm)
 
 		drm_WARN_ON(&ptdev->base, refcount_read(&lru_vm->as.active_cnt));
 		as = lru_vm->as.id;
+
+		ret = panthor_mmu_as_disable(ptdev, as, true);
+		if (ret)
+			goto out_unlock;
+
 		panthor_vm_release_as_locked(lru_vm);
 	}
 
@@ -853,7 +865,7 @@ static void panthor_vm_declare_unusable(struct panthor_vm *vm)
 	vm->unusable = true;
 	mutex_lock(&ptdev->mmu->as.slots_lock);
 	if (vm->as.id >= 0 && drm_dev_enter(&ptdev->base, &cookie)) {
-		panthor_mmu_as_disable(ptdev, vm->as.id);
+		panthor_mmu_as_disable(ptdev, vm->as.id, false);
 		drm_dev_exit(cookie);
 	}
 	mutex_unlock(&ptdev->mmu->as.slots_lock);
@@ -1780,7 +1792,7 @@ static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status)
 			ptdev->mmu->as.slots[as].vm->unhandled_fault = true;
 
 		/* Disable the MMU to kill jobs on this AS. */
-		panthor_mmu_as_disable(ptdev, as);
+		panthor_mmu_as_disable(ptdev, as, false);
 		mutex_unlock(&ptdev->mmu->as.slots_lock);
 
 		status &= ~mask;
@@ -1809,7 +1821,8 @@ void panthor_mmu_suspend(struct panthor_device *ptdev)
 		struct panthor_vm *vm = ptdev->mmu->as.slots[i].vm;
 
 		if (vm) {
-			drm_WARN_ON(&ptdev->base, panthor_mmu_as_disable(ptdev, i));
+			drm_WARN_ON(&ptdev->base,
+				    panthor_mmu_as_disable(ptdev, i, false));
 			panthor_vm_release_as_locked(vm);
 		}
 	}
@@ -1930,7 +1943,7 @@ static void panthor_vm_free(struct drm_gpuvm *gpuvm)
 		int cookie;
 
 		if (drm_dev_enter(&ptdev->base, &cookie)) {
-			panthor_mmu_as_disable(ptdev, vm->as.id);
+			panthor_mmu_as_disable(ptdev, vm->as.id, false);
 			drm_dev_exit(cookie);
 		}
 
@@ -2790,7 +2803,8 @@ void panthor_mmu_unplug(struct panthor_device *ptdev)
 		struct panthor_vm *vm = ptdev->mmu->as.slots[i].vm;
 
 		if (vm) {
-			drm_WARN_ON(&ptdev->base, panthor_mmu_as_disable(ptdev, i));
+			drm_WARN_ON(&ptdev->base,
+				    panthor_mmu_as_disable(ptdev, i, false));
 			panthor_vm_release_as_locked(vm);
 		}
 	}
Signature · 1 line
2.51.1
maintainer Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH v1 2/3] drm/panthor: Make sure caches are flushed/invalidated when an AS is recycled

Quoted 8 lines · Boris Brezillon

When we re-assign a slot to a different VM, we need to make sure the old VM caches are flushed before doing the switch. Specialize panthor_mmu_as_disable() so we can skip the slot programmation while still getting the cache flushing, and call this helper from panthor_vm_active() when an idle slot is recycled.

Fixes 6e2d3b3e8589 ("drm/panthor: Add support for atomic page table updates")

Best regards,
Liviu

Quoted 93 lines
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/gpu/drm/panthor/panthor_mmu.c +20 -6
index 8ba5259e3d28..3644af1a8e56 100644
@@ -585,7 +585,8 @@ static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
 	return as_send_cmd_and_wait(ptdev, as_nr, AS_COMMAND_UPDATE);
 }
 
-static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr)
+static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
+				  bool recycle_slot)
 {
 	int ret;
 
@@ -595,6 +596,12 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr)
 	if (ret)
 		return ret;
 
+	/* If the slot is going to be used immediately, don't bother changing
+	 * the config.
+	 */
+	if (recycle_slot)
+		return 0;
+
 	gpu_write64(ptdev, AS_TRANSTAB(as_nr), 0);
 	gpu_write64(ptdev, AS_MEMATTR(as_nr), 0);
 	gpu_write64(ptdev, AS_TRANSCFG(as_nr), AS_TRANSCFG_ADRMODE_UNMAPPED);
@@ -714,6 +721,11 @@ int panthor_vm_active(struct panthor_vm *vm)
 
 		drm_WARN_ON(&ptdev->base, refcount_read(&lru_vm->as.active_cnt));
 		as = lru_vm->as.id;
+
+		ret = panthor_mmu_as_disable(ptdev, as, true);
+		if (ret)
+			goto out_unlock;
+
 		panthor_vm_release_as_locked(lru_vm);
 	}
 
@@ -853,7 +865,7 @@ static void panthor_vm_declare_unusable(struct panthor_vm *vm)
 	vm->unusable = true;
 	mutex_lock(&ptdev->mmu->as.slots_lock);
 	if (vm->as.id >= 0 && drm_dev_enter(&ptdev->base, &cookie)) {
-		panthor_mmu_as_disable(ptdev, vm->as.id);
+		panthor_mmu_as_disable(ptdev, vm->as.id, false);
 		drm_dev_exit(cookie);
 	}
 	mutex_unlock(&ptdev->mmu->as.slots_lock);
@@ -1780,7 +1792,7 @@ static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status)
 			ptdev->mmu->as.slots[as].vm->unhandled_fault = true;
 
 		/* Disable the MMU to kill jobs on this AS. */
-		panthor_mmu_as_disable(ptdev, as);
+		panthor_mmu_as_disable(ptdev, as, false);
 		mutex_unlock(&ptdev->mmu->as.slots_lock);
 
 		status &= ~mask;
@@ -1809,7 +1821,8 @@ void panthor_mmu_suspend(struct panthor_device *ptdev)
 		struct panthor_vm *vm = ptdev->mmu->as.slots[i].vm;
 
 		if (vm) {
-			drm_WARN_ON(&ptdev->base, panthor_mmu_as_disable(ptdev, i));
+			drm_WARN_ON(&ptdev->base,
+				    panthor_mmu_as_disable(ptdev, i, false));
 			panthor_vm_release_as_locked(vm);
 		}
 	}
@@ -1930,7 +1943,7 @@ static void panthor_vm_free(struct drm_gpuvm *gpuvm)
 		int cookie;
 
 		if (drm_dev_enter(&ptdev->base, &cookie)) {
-			panthor_mmu_as_disable(ptdev, vm->as.id);
+			panthor_mmu_as_disable(ptdev, vm->as.id, false);
 			drm_dev_exit(cookie);
 		}
 
@@ -2790,7 +2803,8 @@ void panthor_mmu_unplug(struct panthor_device *ptdev)
 		struct panthor_vm *vm = ptdev->mmu->as.slots[i].vm;
 
 		if (vm) {
-			drm_WARN_ON(&ptdev->base, panthor_mmu_as_disable(ptdev, i));
+			drm_WARN_ON(&ptdev->base,
+				    panthor_mmu_as_disable(ptdev, i, false));
 			panthor_vm_release_as_locked(vm);
 		}
 	}
Signature · 1 line
2.51.1
author maintainer
#5 lore raw

PATCH 3/3 drm/panthor: Unlock the locked region before disabling an AS

In reply to Boris Brezillon

An AS can be disabled in the middle of a VM operation (VM being evicted from an AS slot, for instance). In that case, we need the locked section to be unlocked before releasing the slot.

Fixes 6e2d3b3e8589 ("drm/panthor: Add support for atomic page table updates")
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +11 -0
index 3644af1a8e56..4ed28bd1b8ec 100644
@@ -588,6 +588,7 @@ static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
 static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
 				  bool recycle_slot)
 {
+	struct panthor_vm *vm = ptdev->mmu->as.slots[as_nr].vm;
 	int ret;
 
 	/* Flush+invalidate RW caches, invalidate RO ones. */
@@ -596,6 +597,16 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
 	if (ret)
 		return ret;
 
+	if (vm && vm->locked_region.size) {
+		/* Unlock the region if there a lock pending. */
+		ret = as_send_cmd_and_wait(ptdev, vm->as.id, AS_COMMAND_UNLOCK);
+		if (ret)
+			return ret;
+
+		vm->locked_region.start = 0;
+		vm->locked_region.size = 0;
+	}
+
 	/* If the slot is going to be used immediately, don't bother changing
 	 * the config.
 	 */
Signature · 1 line
2.51.1
maintainer Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH v1 3/3] drm/panthor: Unlock the locked region before disabling an AS

Quoted 6 lines · Boris Brezillon

An AS can be disabled in the middle of a VM operation (VM being evicted from an AS slot, for instance). In that case, we need the locked section to be unlocked before releasing the slot.

Fixes 6e2d3b3e8589 ("drm/panthor: Add support for atomic page table updates")

Best regards,
Liviu

Quoted 36 lines
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +11 -0
index 3644af1a8e56..4ed28bd1b8ec 100644
@@ -588,6 +588,7 @@ static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
 static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
 				  bool recycle_slot)
 {
+	struct panthor_vm *vm = ptdev->mmu->as.slots[as_nr].vm;
 	int ret;
 
 	/* Flush+invalidate RW caches, invalidate RO ones. */
@@ -596,6 +597,16 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
 	if (ret)
 		return ret;
 
+	if (vm && vm->locked_region.size) {
+		/* Unlock the region if there a lock pending. */
+		ret = as_send_cmd_and_wait(ptdev, vm->as.id, AS_COMMAND_UNLOCK);
+		if (ret)
+			return ret;
+
+		vm->locked_region.start = 0;
+		vm->locked_region.size = 0;
+	}
+
 	/* If the slot is going to be used immediately, don't bother changing
 	 * the config.
 	 */
Signature · 1 line
2.51.1
#7 lore raw

Re: [PATCH v1 3/3] drm/panthor: Unlock the locked region before disabling an AS

In reply to Boris Brezillon

Hi Boris,

Quoted 15 lines · Boris Brezillon

An AS can be disabled in the middle of a VM operation (VM being evicted from an AS slot, for instance). In that case, we need the locked section to be unlocked before releasing the slot.

Fixes 6e2d3b3e8589 ("drm/panthor: Add support for atomic page table updates")
---
  drivers/gpu/drm/panthor/panthor_mmu.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +0 -0
index 3644af1a8e56..4ed28bd1b8ec 100644

drivers/gpu/drm/panthor/panthor_mmu.c static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr, · line 593

Quoted 6 lines
drivers/gpu/drm/panthor/panthor_mmu.c +1 -0
@@ -588,6 +588,7 @@ static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
  static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
  				  bool recycle_slot)
  {
+	struct panthor_vm *vm = ptdev->mmu->as.slots[as_nr].vm;
  	int ret;
 

Thanks for the fix.

Please can you consider adding a lockdep_assert_held for mmu->as.slots_lock. That would in a way make it explicit that it is safe to de-reference vm pointer here.

Best regards
Akash

Quoted 18 lines
drivers/gpu/drm/panthor/panthor_mmu.c +10 -0
  	/* Flush+invalidate RW caches, invalidate RO ones. */
@@ -596,6 +597,16 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
  	if (ret)
  		return ret;
 
+	if (vm && vm->locked_region.size) {
+		/* Unlock the region if there a lock pending. */
+		ret = as_send_cmd_and_wait(ptdev, vm->as.id, AS_COMMAND_UNLOCK);
+		if (ret)
+			return ret;
+
+		vm->locked_region.start = 0;
+		vm->locked_region.size = 0;
+	}
+
  	/* If the slot is going to be used immediately, don't bother changing
  	 * the config.
  	 */
author maintainer
#8 lore raw

Re: [PATCH v1 3/3] drm/panthor: Unlock the locked region before disabling an AS

Quoted 28 lines · On Tue, 2 Dec 2025 15:09:42 +0000 Akash Goel <[email protected]> wrote:

Hi Boris,

Quoted 15 lines · Boris Brezillon

An AS can be disabled in the middle of a VM operation (VM being evicted from an AS slot, for instance). In that case, we need the locked section to be unlocked before releasing the slot.

Fixes 6e2d3b3e8589 ("drm/panthor: Add support for atomic page table updates")
---
  drivers/gpu/drm/panthor/panthor_mmu.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
drivers/gpu/drm/panthor/panthor_mmu.c +0 -0
index 3644af1a8e56..4ed28bd1b8ec 100644

drivers/gpu/drm/panthor/panthor_mmu.c static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr, · line 593

Quoted 6 lines
drivers/gpu/drm/panthor/panthor_mmu.c +1 -0
@@ -588,6 +588,7 @@ static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
  static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
  				  bool recycle_slot)
  {
+	struct panthor_vm *vm = ptdev->mmu->as.slots[as_nr].vm;
  	int ret;
 

Thanks for the fix.

Quoted 3 lines

Please can you consider adding a lockdep_assert_held for mmu->as.slots_lock. That would in a way make it explicit that it is safe to de-reference vm pointer here.

Sure, I can do that.

Quoted 23 lines

Best regards
Akash

Quoted 18 lines
drivers/gpu/drm/panthor/panthor_mmu.c +10 -0
  	/* Flush+invalidate RW caches, invalidate RO ones. */
@@ -596,6 +597,16 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,
  	if (ret)
  		return ret;
 
+	if (vm && vm->locked_region.size) {
+		/* Unlock the region if there a lock pending. */
+		ret = as_send_cmd_and_wait(ptdev, vm->as.id, AS_COMMAND_UNLOCK);
+		if (ret)
+			return ret;
+
+		vm->locked_region.start = 0;
+		vm->locked_region.size = 0;
+	}
+
  	/* If the slot is going to be used immediately, don't bother changing
  	 * the config.
  	 */  
Reviewed-by on the v1 series
#9 lore raw
In reply to Boris Brezillon
Quoted 8 lines · Boris Brezillon

Hello,

This is a set of fixes for regressions noticed while testing the drm-misc-next branch against mesa-ci.

Regards,

Quoted 7 lines

Boris

Boris Brezillon (3):
drm/panthor: Drop a WARN_ON() in group_free_queue() drm/panthor: Make sure caches are flushed/invalidated when an AS is
recycled
drm/panthor: Unlock the locked region before disabling an AS

Series is

Quoted 8 lines
 drivers/gpu/drm/panthor/panthor_mmu.c   | 37 +++++++++++++++++++++----
 drivers/gpu/drm/panthor/panthor_sched.c |  5 ++--
 2 files changed, 33 insertions(+), 9 deletions(-)

--
2.51.1