Intel-XE Archive on 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, intel-xe@lists.freedesktop.org
Subject: Re: [RFC PATCH v1 3/5] drm/gpusvm: extract drm_gpusvm_dma_map_pages() helper
Date: Thu, 27 Aug 2026 07:26:23 +0000	[thread overview]
Message-ID: <20260827072623.E5FFA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827071449.520398-4-honghuan@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Device memory mappings are permanently leaked on the error path due to deferred assignment of svm_pages->dpagemap
--

commit 09830ce1d99e5366614becf544e5d523ceeb461d
Author: Honglei Huang <honghuan@amd.com>

drm/gpusvm: extract drm_gpusvm_dma_map_pages() helper

This commit moves the per-device DMA mapping loop of drm_gpusvm_get_pages()
into a helper drm_gpusvm_dma_map_pages(). The mapping logic is only moved,
not changed, so there is no functional change.

> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index 3496cb5688365..753361b965cf9 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
[ ... ]
> @@ -1695,17 +1631,114 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
>  	/* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */
>  	WRITE_ONCE(svm_pages->flags.__flags, flags.__flags);
>  
> +	return 0;
> +
> +err_unmap:
> +	svm_pages->flags.has_dma_mapping = true;
> +	__drm_gpusvm_unmap_pages(gpusvm, svm_pages, num_dma_mapped);

[Severity: High]
This is a pre-existing issue, but does this code permanently leak device
memory mappings on the error path?

When a device page is successfully mapped in drm_gpusvm_dma_map_pages(),
dpagemap->ops->device_map() is used. However, svm_pages->dpagemap is only
updated at the end of the function upon complete success.

If an error occurs on a subsequent page (such as returning -EOPNOTSUPP
due to encountering a mixed device memory mapping), the code jumps to
err_unmap and calls __drm_gpusvm_unmap_pages(). 

Because svm_pages->dpagemap is still NULL at this point, the unmap helper
will skip the cleanup callback:

drivers/gpu/drm/drm_gpusvm.c:__drm_gpusvm_unmap_pages() {
    ...
    struct drm_pagemap *dpagemap = svm_pages->dpagemap; 
    ...
    else if (dpagemap && dpagemap->ops->device_unmap)
        dpagemap->ops->device_unmap(...)
    ...
}

Should the local dpagemap be temporarily assigned to svm_pages->dpagemap
before calling the unmap helper, or is there another way to ensure these
partially mapped pages are properly cleaned up?

> +	return err;
> +}

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

  reply	other threads:[~2026-08-27  7:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27  7:14 [RFC PATCH v1 0/5] drm/gpusvm: share one HMM fault across per-device DMA mappings Honglei Huang
2026-08-27  7:14 ` [RFC PATCH v1 1/5] drm/gpusvm: extract drm_gpusvm_hmm_fault() helper Honglei Huang
2026-08-27  7:30   ` Matthew Brost
2026-08-27  9:02     ` Huang, Honglei
2026-08-27  7:14 ` [RFC PATCH v1 2/5] drm/gpusvm: move dma_addr allocation before the notifier lock Honglei Huang
2026-08-27  7:29   ` sashiko-bot
2026-08-27  7:14 ` [RFC PATCH v1 3/5] drm/gpusvm: extract drm_gpusvm_dma_map_pages() helper Honglei Huang
2026-08-27  7:26   ` sashiko-bot [this message]
2026-08-27  7:14 ` [RFC PATCH v1 4/5] drm/gpusvm: let drm_gpusvm_get_pages() map an array of pages Honglei Huang
2026-08-27  7:29   ` sashiko-bot
2026-08-27  7:14 ` [RFC PATCH v1 5/5] drm/gpusvm: make the DMA mapping step in get_pages() optional 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=20260827072623.E5FFA1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=honghuan@amd.com \
    --cc=intel-xe@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox