From: Matthew Brost <matthew.brost@intel.com>
To: Honglei Huang <honghuan@amd.com>
Cc: <rodrigo.vivi@intel.com>, <thomas.hellstrom@linux.intel.com>,
<dakr@kernel.org>, <intel-xe@lists.freedesktop.org>,
<Ray.Huang@amd.com>, <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v3 3/3] drm/gpusvm: publish dpagemap early to avoid device mapping leak on error
Date: Tue, 30 Jun 2026 17:46:26 -0700 [thread overview]
Message-ID: <akRjYiONnxxaBjA7@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20260630070859.372954-4-honghuan@amd.com>
On Tue, Jun 30, 2026 at 03:08:59PM +0800, Honglei Huang wrote:
> drm_gpusvm_get_pages() only stored the local dpagemap into
> svm_pages->dpagemap on the success path. If a later page failed (e.g.
> -EOPNOTSUPP when ctx->allow_mixed is false) and jumped to err_unmap,
> svm_pages->dpagemap was still NULL, so __drm_gpusvm_unmap_pages() skipped
> device_unmap() and leaked the device mappings already created.
>
> Assign svm_pages->dpagemap when the first device page is mapped so the
> err_unmap path can device_unmap() those mappings.
>
> This issue was found by Sashiko AI review.
>
> Fixes: f70da6f99d4f ("drm/gpusvm: pull out drm_gpusvm_pages substructure")
> Cc: stable@vger.kernel.org
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> Signed-off-by: Honglei Huang <honghuan@amd.com>
> ---
> drivers/gpu/drm/drm_gpusvm.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index 44bb19658dd..9a06ff7d260 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -1544,6 +1544,16 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
> err = -EAGAIN;
> goto err_unmap;
> }
> +
> + /*
> + * Set the dpagemap as soon as the first
> + * device page is mapped so the err_unmap path
> + * can device_unmap() the device mappings that
> + * have already been created.
> + */
> + drm_pagemap_get(dpagemap);
> + drm_pagemap_put(svm_pages->dpagemap);
> + svm_pages->dpagemap = dpagemap;
> }
> svm_pages->dma_addr[j] =
> dpagemap->ops->device_map(dpagemap,
> @@ -1611,12 +1621,8 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
> goto err_unmap;
> }
>
> - if (pagemap) {
> + if (pagemap)
> flags.has_devmem_pages = true;
> - drm_pagemap_get(dpagemap);
> - drm_pagemap_put(svm_pages->dpagemap);
> - svm_pages->dpagemap = dpagemap;
> - }
>
> /* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */
> WRITE_ONCE(svm_pages->flags.__flags, flags.__flags);
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-07-01 0:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 7:08 [PATCH v3 0/3] drm/gpusvm: fix IOVA/DMA unmap leaks in __drm_gpusvm_unmap_pages() Honglei Huang
2026-06-30 7:08 ` [PATCH v3 1/3] drm/gpusvm: free the whole IOVA reservation on unmap Honglei Huang
2026-06-30 7:08 ` [PATCH v3 2/3] drm/gpusvm: do not route system pages to device_unmap() on IOVA unmap Honglei Huang
2026-07-01 0:47 ` Matthew Brost
2026-06-30 7:08 ` [PATCH v3 3/3] drm/gpusvm: publish dpagemap early to avoid device mapping leak on error Honglei Huang
2026-07-01 0:46 ` Matthew Brost [this message]
2026-06-30 7:17 ` ✓ CI.KUnit: success for drm/gpusvm: fix IOVA/DMA unmap leaks in __drm_gpusvm_unmap_pages() (rev2) Patchwork
2026-06-30 8:05 ` ✓ Xe.CI.BAT: " Patchwork
2026-06-30 20:43 ` ✓ Xe.CI.FULL: " Patchwork
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=akRjYiONnxxaBjA7@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=Ray.Huang@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=honghuan@amd.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=rodrigo.vivi@intel.com \
--cc=thomas.hellstrom@linux.intel.com \
/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