All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Honglei Huang" <honghuan@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v9 3/5] drm/xe: have xe_svm_range embed one drm_gpusvm_pages
Date: Tue, 30 Jun 2026 08:54:33 +0000	[thread overview]
Message-ID: <20260630085434.462441F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260630083307.381909-4-honghuan@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The framework's cleanup function `drm_gpusvm_fini` violates the newly established contract for `drm_gpusvm_range_remove` by not DMA unmapping pages before removal, creating a potential IOMMU use-after-free vulnerability.
--

commit ce3cfca046dfb562114ff18565b9dc3974af3c6b
Author: Honglei Huang <honghuan@amd.com>
Subject: drm/xe: have xe_svm_range embed one drm_gpusvm_pages

With drm_gpusvm_pages now self contained, make xe stop relying
on the drm_gpusvm_range pages and take responsibility for the page
lifecycle on the driver side.

> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -1228,12 +1228,17 @@ EXPORT_SYMBOL_GPL(drm_gpusvm_free_pages);
>   * This function removes the specified GPU SVM range and also removes the parent
>   * GPU SVM notifier if no more ranges remain in the notifier. The caller must
>   * hold a lock to protect range and notifier removal.
> + *
> + * This function does not unmap or free the drm_gpusvm_pages, the driver owns
> + * that lifecycle. The caller must DMA unmap the range's pages before calling
> + * this function, so a range is never removed from the MMU interval tree while
> + * still DMA mapped. Typically the driver calls drm_gpusvm_unmap_pages() first.
> + * And the range_free callback's drm_gpusvm_free_pages() is a final fallback safe
> + * net.
>   */
>  void drm_gpusvm_range_remove(struct drm_gpusvm *gpusvm,
>  			     struct drm_gpusvm_range *range)
>  {

[Severity: High]
Does this new contract break the framework's cleanup function?

Looking at drm_gpusvm_fini() in drm_gpusvm.c, it calls drm_gpusvm_range_remove()
directly on remaining ranges after unregistering the MMU notifier:

		mmu_interval_notifier_remove(&notifier->notifier);
		notifier->flags.removed = true;

		drm_gpusvm_for_each_range_safe(range, __next, notifier, 0,
					       LONG_MAX)
			drm_gpusvm_range_remove(gpusvm, range);

Since drm_gpusvm_range_remove() no longer synchronously unmaps the pages, and
instead relies on the final kref_put() to execute the DMA unmap, could an
elevated refcount on a range indefinitely delay the DMA unmap? 

This would mean the pages remain DMA mapped even though the MMU notifier has
been destroyed. If the OS frees or repurposes these physical pages, the GPU
IOMMU mapping would still point to them, creating a potential use-after-free
regression.

Can we ensure pages are unmapped here, or is there another way to close this
window?

> -	unsigned long npages = npages_in_range(drm_gpusvm_range_start(range),
> -					       drm_gpusvm_range_end(range));
>  	struct drm_gpusvm_notifier *notifier;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260630083307.381909-1-honghuan@amd.com?part=3

  reply	other threads:[~2026-06-30  8:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30  8:33 [PATCH v9 0/5] drm/gpusvm: split MM and device state across gpusvm/range/pages Honglei Huang
2026-06-30  8:33 ` [PATCH v9 1/5] drm/gpusvm: split MM state flags out of drm_gpusvm_pages_flags Honglei Huang
2026-06-30  8:46   ` sashiko-bot
2026-06-30  8:33 ` [PATCH v9 2/5] drm/gpusvm: embed struct drm_device into drm_gpusvm_pages Honglei Huang
2026-06-30  8:33 ` [PATCH v9 3/5] drm/xe: have xe_svm_range embed one drm_gpusvm_pages Honglei Huang
2026-06-30  8:54   ` sashiko-bot [this message]
2026-06-30  8:33 ` [PATCH v9 4/5] drm/gpusvm: move struct drm_gpusvm_pages out of struct drm_gpusvm_range Honglei Huang
2026-06-30 10:48   ` sashiko-bot
2026-06-30  8:33 ` [PATCH v9 5/5] drm/gpusvm: let the drm_gpusvm core context purely MM level Honglei Huang
2026-06-30  8:48 ` ✓ CI.KUnit: success for drm/gpusvm: split MM and device state across gpusvm/range/pages (rev6) Patchwork
2026-06-30  9:28 ` ✓ Xe.CI.BAT: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-06-30  7:34 [PATCH v9 0/5] drm/gpusvm: split MM and device state across gpusvm/range/pages Honglei Huang
2026-06-30  7:34 ` [PATCH v9 3/5] drm/xe: have xe_svm_range embed one drm_gpusvm_pages Honglei Huang

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=20260630085434.462441F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=honghuan@amd.com \
    --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.