From: Matthew Brost <matthew.brost@intel.com>
To: Stanislav Kinsburskii <skinsburskii@gmail.com>
Cc: <maarten.lankhorst@linux.intel.com>, <mripard@kernel.org>,
<tzimmermann@suse.de>, <airlied@gmail.com>, <simona@ffwll.ch>,
<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>,
<intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH] drm/gpusvm: Fix mm reference leak in range eviction
Date: Mon, 20 Jul 2026 11:42:19 -0700 [thread overview]
Message-ID: <al5sC3iUUDq9X/Ku@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <178406551216.1092539.5238081578161393168.stgit@skinsburskii>
On Tue, Jul 14, 2026 at 02:45:14PM -0700, Stanislav Kinsburskii wrote:
> drm_gpusvm_range_evict() pins gpusvm->mm with mmget_not_zero() before
> allocating the temporary HMM PFN array. If that allocation fails, the
> function returns -ENOMEM directly and leaks the mm reference.
>
> Route the allocation failure through the common mmput() path after
> initializing err to -ENOMEM. This preserves the returned error while
> balancing the mm reference acquired by mmget_not_zero().
>
> Fixes: 99624bdff8670 ("drm/gpusvm: Add support for GPU Shared Virtual Memory")
> Cc: stable@vger.kernel.org
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@gmail.com>
Yes, this is a bug... I also have pending patch to fix this here:
https://patchwork.freedesktop.org/patch/740193/?series=170433&rev=1
I think I prefer mine.
Matt
> ---
> drivers/gpu/drm/drm_gpusvm.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index 76e8a0028c7f..1a8bb83bd28d 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -1715,7 +1715,7 @@ int drm_gpusvm_range_evict(struct drm_gpusvm *gpusvm,
> unsigned long *pfns;
> unsigned long npages = npages_in_range(drm_gpusvm_range_start(range),
> drm_gpusvm_range_end(range));
> - int err = 0;
> + int err = -ENOMEM;
> struct mm_struct *mm = gpusvm->mm;
>
> if (!mmget_not_zero(mm))
> @@ -1723,12 +1723,13 @@ int drm_gpusvm_range_evict(struct drm_gpusvm *gpusvm,
>
> pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL);
> if (!pfns)
> - return -ENOMEM;
> + goto put_mm;
>
> hmm_range.hmm_pfns = pfns;
> err = hmm_range_fault_unlocked_timeout(&hmm_range, timeout);
>
> kvfree(pfns);
> +put_mm:
> mmput(mm);
>
> return err == -EBUSY ? -ETIME : err;
>
>
next prev parent reply other threads:[~2026-07-20 18:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 21:45 Stanislav Kinsburskii
2026-07-20 18:42 ` Matthew Brost [this message]
2026-07-20 18:49 ` Stanislav Kinsburskii
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=al5sC3iUUDq9X/Ku@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=skinsburskii@gmail.com \
--cc=tzimmermann@suse.de \
/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
all inboxes | Powered by JetHome®