All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Boris Brezillon" <boris.brezillon@collabora.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 12/17] drm/panthor: Make the VM cleanup path more robust against UAF
Date: Thu, 13 Aug 2026 11:20:59 +0000	[thread overview]
Message-ID: <20260813112100.68B701F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260813-panthor-unplug-fixes-v3-12-3ed4e961bbe7@collabora.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Self-deadlock and lockdep violation in panthor_mmu_pre_suspend when AS disable fails.
- [High] Unconditional removal of PANTHOR_AS_FORBID_UNMAP leads to Use-After-Free if soft reset fails.
--

--- Patch [12]: [PATCH v3 12/17] drm/panthor: Make the VM cleanup path more robust against UAF ---
commit 5812e6e60c1cdbc7bb20a9803d7bf5a58663d7d2
Author: Boris Brezillon <boris.brezillon@collabora.com>
Subject: drm/panthor: Make the VM cleanup path more robust against UAF

The commit defers the cleanup of VMs when a hardware hang prevents eviction
of a page table from its AS slot, waiting for the next post_reset. It
introduces a cleanup list for VMs and schedules a workqueue to process it
once the hardware is confirmed idle.

> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index acdc0dd04f8be..5f4aab5813d52 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
[ ... ]
> @@ -1985,23 +2002,67 @@ static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status)
>   *
>   * We also suspend the MMU IRQ.
>   */
> -void panthor_mmu_suspend(struct panthor_device *ptdev)
> +void panthor_mmu_pre_suspend(struct panthor_device *ptdev)
>  {
>  	mutex_lock(&ptdev->mmu->as.slots_lock);
>  	for (u32 i = 0; i < ARRAY_SIZE(ptdev->mmu->as.slots); i++) {
>  		struct panthor_as *as = ptdev->mmu->as.slots[i].as;
> +		int ret;
>  
> -		if (as) {
> -			drm_WARN_ON(&ptdev->base,
> -				    panthor_mmu_as_disable(ptdev, i, false));
> +		if (!as)
> +			continue;
> +
> +		/* If the disable fails, leave the AS on its slot so we can
> +		 * properly evict it when we're sure the GPU is off.
> +		 */
> +		ret = panthor_mmu_as_disable(ptdev, i, false);
> +		if (!ret)
>  			panthor_as_release_hw_slot_locked(as);
> -		}
> +		else
> +			panthor_as_restrict_usage_locked(as,
> +							 PANTHOR_AS_FORBID_USE |
> +							 PANTHOR_AS_FORBID_MAP |
> +							 PANTHOR_AS_FORBID_UNMAP);
>  	}
>  	mutex_unlock(&ptdev->mmu->as.slots_lock);

[Severity: High]
Does this code cause a lockdep violation and self-deadlock if the hardware
hangs and panthor_mmu_as_disable() fails?

The panthor_mmu_pre_suspend() function acquires ptdev->mmu->as.slots_lock
before the loop. When calling panthor_as_restrict_usage_locked(), that
function asserts lockdep_assert_held(&as->op_lock) which doesn't appear
to be held here.

Furthermore, panthor_as_restrict_usage_locked() immediately tries to
acquire the slots_lock again:

static void panthor_as_restrict_usage_locked(...)
{
	...
	if (new_restrictions & PANTHOR_AS_FORBID_USE) {
		guard(mutex)(&ptdev->mmu->as.slots_lock);

Since standard mutexes are non-recursive, won't this self-deadlock the
thread performing the suspend?

>  
>  	panthor_mmu_irq_suspend(&ptdev->mmu->irq);
>  }
>  
> +static void mmu_post_reset_cleanup(struct panthor_device *ptdev)
> +{
> +	guard(mutex)(&ptdev->mmu->as.slots_lock);
> +
> +	/* Now that the reset is effective, we can assume that none of the
> +	 * AS slots are setup, and clear the faulty flags too.
> +	 */
> +	ptdev->mmu->as.alloc_mask = 0;
> +	ptdev->mmu->as.faulty_mask = 0;
> +
> +	for (u32 i = 0; i < ARRAY_SIZE(ptdev->mmu->as.slots); i++) {
> +		struct panthor_as *as = ptdev->mmu->as.slots[i].as;
> +
> +		if (!as)
> +			continue;
> +
> +		panthor_as_release_hw_slot_locked(as);
> +
> +		/* FIXME: We shouldn't drop the no-unmap restriction if
> +		 * we're in the unplug path and the device wasn't properly
> +		 * stopped with a SOFT_RESET.
> +		 */
> +		atomic_and(~PANTHOR_AS_FORBID_UNMAP, &as->restrictions);

[Severity: High]
Can this unconditional clearing lead to a use-after-free if a soft reset
fails to halt the GPU?

As noted in the FIXME comment, dropping this restriction might be dangerous.
If the device wasn't properly stopped, the hardware could still be actively
performing DMA. Dropping PANTHOR_AS_FORBID_UNMAP here will allow
vm_cleanup() to execute panthor_vm_unmap_range() and
panthor_heap_pool_destroy(), potentially freeing memory that the active
GPU can still access.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260813-panthor-unplug-fixes-v3-0-3ed4e961bbe7@collabora.com?part=12

  reply	other threads:[~2026-08-13 11:21 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13 10:56 [PATCH v3 00/17] drm/panthor: Fix the unplug logic Boris Brezillon
2026-08-13 10:56 ` [PATCH v3 01/17] drm/panthor: Disable reset work before unplug Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 02/17] drm/panthor: Further delay reset work enablement Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 03/17] drm/panthor: Make sure reset requests in the resume path are not lost Boris Brezillon
2026-08-13 11:09   ` sashiko-bot
2026-08-13 10:57 ` [PATCH v3 04/17] drm/panthor: Make sure reset requests in the post reset " Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 05/17] drm/panthor: Flush the cleanup_wq in the unplug path Boris Brezillon
2026-08-13 11:18   ` sashiko-bot
2026-08-13 10:57 ` [PATCH v3 06/17] drm/panthor: Drop unused vm argument passed to panthor_vm_prepare_sync_only_op_ctx() Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 07/17] drm/panthor: Move the debugfs initialization to panthor_device.c Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 08/17] drm/panthor: Split panthor_vm Boris Brezillon
2026-08-13 11:37   ` sashiko-bot
2026-08-13 10:57 ` [PATCH v3 09/17] drm/panthor: Add fine-grained restrictions on VMs Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 10/17] drm/panthor: Check AS state before disabling Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 11/17] drm/panthor: Don't pre-allocate VMAs or page tables when preparing a full VM unmap Boris Brezillon
2026-08-13 11:12   ` sashiko-bot
2026-08-13 10:57 ` [PATCH v3 12/17] drm/panthor: Make the VM cleanup path more robust against UAF Boris Brezillon
2026-08-13 11:20   ` sashiko-bot [this message]
2026-08-13 10:57 ` [PATCH v3 13/17] drm/panthor: Track user owned VMs Boris Brezillon
2026-08-13 11:18   ` sashiko-bot
2026-08-13 10:57 ` [PATCH v3 14/17] drm/panthor: Track user owned groups Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 15/17] drm/panthor: Fix the unplug logic Boris Brezillon
2026-08-13 11:25   ` sashiko-bot
2026-08-13 10:57 ` [PATCH v3 16/17] drm/panthor: Add a debugfs knob to simulate unplug failures Boris Brezillon
2026-08-13 10:57 ` [PATCH v3 17/17] drm/panthor: Add a debugfs knobs to simulate reset failures Boris Brezillon
2026-08-13 11:23 ` [PATCH v3 00/17] drm/panthor: Fix the unplug logic Boris Brezillon
2026-08-13 15:11   ` Liviu Dudau
2026-08-13 15:55     ` Boris Brezillon
2026-08-13 17:06       ` Liviu Dudau
2026-08-13 18:50   ` Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260813112100.68B701F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=boris.brezillon@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.