dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stanislav Kinsburskii" <skinsburskii@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 4/4] fixup! drm/gpusvm: use hmm_range_fault_unlocked_timeout() for range faults
Date: Tue, 14 Jul 2026 20:24:15 +0000	[thread overview]
Message-ID: <20260714202416.15D851F000E9@smtp.kernel.org> (raw)
In-Reply-To: <178406003318.1082778.16211328573488321338.stgit@skinsburskii>

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

Pre-existing issues:
- [High] drm_gpusvm passes uninitialized pfns arrays to hmm_range_fault, causing unintended page faults and write requests.
- [High] Memory leak of `mm_struct` in `drm_gpusvm_range_evict` on allocation failure.
--

--- Patch [4]: [PATCH 4/4] fixup! drm/gpusvm: use hmm_range_fault_unlocked_timeout() for range faults ---
commit afecb2c70fcbb0789fe0b4b948e05bb9f8070c63
Author: Stanislav Kinsburskii <skinsburskii@gmail.com>

fixup! drm/gpusvm: use hmm_range_fault_unlocked_timeout() for range faults

The patch removes the outer deadline tracking from hmm_range_fault loops
and passes msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT) directly to each
hmm_range_fault_unlocked_timeout() call. This avoids accounting for outer
driver retry logic inside the HMM retry budget.

> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index b8f2dd9982f53..76e8a0028c7fc 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -867,8 +866,7 @@ enum drm_gpusvm_scan_result drm_gpusvm_scan_mm(struct drm_gpusvm_range *range,
>  	hmm_range.hmm_pfns = pfns;
>  
>  retry:
> -	err = hmm_range_fault_unlocked_timeout(&hmm_range,
> -					       max(timeout - jiffies, 1L));
> +	err = hmm_range_fault_unlocked_timeout(&hmm_range, timeout);

[Severity: High]
This is a pre-existing issue, but does using kvmalloc_array() without
zeroing memory cause unintended page faults?

HMM reads hmm_pfns as input to determine per-page fault requests. The
uninitialized memory can contain random bits like HMM_PFN_REQ_FAULT or
HMM_PFN_REQ_WRITE, potentially triggering unintended faults or violating
read-only mapping constraints. 

Additionally, the retry loop reuses output flags (HMM_PFN_VALID), which
aliases with HMM_PFN_REQ_FAULT (both are the MSB), unintentionally forcing
faults on previously valid pages during a scan.

Should this allocate with kvcalloc() instead?

[ ... ]

> @@ -1495,8 +1489,7 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
>  	}
>  
>  	hmm_range.hmm_pfns = pfns;
> -	err = hmm_range_fault_unlocked_timeout(&hmm_range,
> -				max_t(long, timeout - jiffies, 1));
> +	err = hmm_range_fault_unlocked_timeout(&hmm_range, timeout);

[Severity: High]
This is also a pre-existing issue, but similar to drm_gpusvm_scan_mm(),
pfns is allocated with kvmalloc_array() earlier in drm_gpusvm_get_pages()
and passed to hmm_range_fault_unlocked_timeout() here.

Could this uninitialized memory cause unintended write requests or page
faults?

[ ... ]

> @@ -1734,8 +1726,7 @@ int drm_gpusvm_range_evict(struct drm_gpusvm *gpusvm,
>  		return -ENOMEM;

[Severity: High]
This isn't a bug introduced by this patch, but does returning -ENOMEM here
leak the mm_struct?

Earlier in drm_gpusvm_range_evict(), mmget_not_zero(mm) increments the
reference count:

	if (!mmget_not_zero(mm))
		return -EFAULT;

	pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL);
	if (!pfns)
		return -ENOMEM;

If the kvmalloc_array() allocation for pfns fails, it returns directly
without calling mmput(mm).

>  
>  	hmm_range.hmm_pfns = pfns;
> -	err = hmm_range_fault_unlocked_timeout(&hmm_range,
> -				max_t(long, timeout - jiffies, 1));
> +	err = hmm_range_fault_unlocked_timeout(&hmm_range, timeout);

[Severity: High]
This is a pre-existing issue, but again, pfns is allocated with
kvmalloc_array() and passed here. Does this need to be kvcalloc() to
prevent uninitialized memory from causing unintended page faults?

>  
>  	kvfree(pfns);
>  	mmput(mm);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/178405975214.1082778.5193079941156341151.stgit@skinsburskii?part=4

      reply	other threads:[~2026-07-14 20:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 20:13 [PATCH 0/4] mm/hmm: Clarify notifier retry state and scope HMM timeouts Stanislav Kinsburskii
2026-07-14 20:13 ` [PATCH 1/4] fixup! mm/hmm: add hmm_range_fault_unlocked_timeout() for mmap lock-drop support Stanislav Kinsburskii
2026-07-14 20:13 ` [PATCH 2/4] fixup! drm/nouveau: use hmm_range_fault_unlocked_timeout() for SVM faults Stanislav Kinsburskii
2026-07-14 20:30   ` sashiko-bot
2026-07-14 21:33   ` Stanislav Kinsburskii
2026-07-14 20:13 ` [PATCH 3/4] fixup! accel/amdxdna: use hmm_range_fault_unlocked_timeout() for range population Stanislav Kinsburskii
2026-07-14 20:27   ` sashiko-bot
2026-07-14 20:13 ` [PATCH 4/4] fixup! drm/gpusvm: use hmm_range_fault_unlocked_timeout() for range faults Stanislav Kinsburskii
2026-07-14 20:24   ` sashiko-bot [this message]

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=20260714202416.15D851F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skinsburskii@gmail.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