From: "Huang, Honglei" <honghuan@amd.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: sima@ffwll.ch, rodrigo.vivi@intel.com,
thomas.hellstrom@linux.intel.com, dakr@kernel.org,
intel-xe@lists.freedesktop.org, aliceryhl@google.com,
Alexander.Deucher@amd.com, Felix.Kuehling@amd.com,
Christian.Koenig@amd.com, Ray.Huang@amd.com,
Lingshan.Zhu@amd.com, Junhua.Shen@amd.com, Yiru.Ma@amd.com,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [RFC PATCH v1 1/5] drm/gpusvm: extract drm_gpusvm_hmm_fault() helper
Date: Thu, 27 Aug 2026 17:02:43 +0800 [thread overview]
Message-ID: <bcdc465f-2f83-4fc0-93e6-ed94b076989c@amd.com> (raw)
In-Reply-To: <ao/nrkOMOllUKqyG@gsse-cloud1.jf.intel.com>
On 8/27/2026 3:30 PM, Matthew Brost wrote:
> On Thu, Aug 27, 2026 at 03:14:45PM +0800, Honglei Huang wrote:
>> Make the HMM fault step of drm_gpusvm_get_pages(), including its -EBUSY
>> retry loop, into a helper drm_gpusvm_hmm_fault(). The existing logic of
>> the public drm_gpusvm_get_pages() is not changed, only relocated, so
>> there is no functional change. Keeping the retry loop in common code
>> also means drivers never have to open-code their own fault/retry loop.
>>
>> A single fault can later be shared by several drm_gpusvm_pages instances
>> that mirror the same CPU range. This prepares get_pages() to split the
>> shared MM-level fault from the per-device DMA mapping. No functional
>> change intended.
>>
>
> I think you might want to just wait on this until Sunday for this
> series. I think this patch [1] is in the core MM tree so when drm-tip
> moves to 7.3.rc1, Sunday, we will have a version of this helper to core
> MM used in gpusvm.
Got it, will wait until Sunday. Thanks for the information.
Regards,
Honglei
>
> Matt
>
> [1] https://lore.freedesktop.org/nouveau/20260722-hmm-v10-v1-6-606464dd601a@gmail.com/T/#m68f663ce3e802d7692363c70e6364569134cd6c7
>
>> Suggested-by: Matthew Brost <matthew.brost@intel.com>
>> Signed-off-by: Honglei Huang <honghuan@amd.com>
>> ---
>> drivers/gpu/drm/drm_gpusvm.c | 67 ++++++++++++++++++++++++------------
>> 1 file changed, 45 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
>> index fcfe635bc195..507ef6f0a60e 100644
>> --- a/drivers/gpu/drm/drm_gpusvm.c
>> +++ b/drivers/gpu/drm/drm_gpusvm.c
>> @@ -1442,6 +1442,50 @@ static bool drm_gpusvm_pages_valid_unlocked(struct drm_gpusvm *gpusvm,
>> return pages_valid;
>> }
>>
>> +/**
>> + * drm_gpusvm_hmm_fault() - Run the shared HMM fault for a CPU range
>> + * @gpusvm: Pointer to the GPU SVM structure
>> + * @mm: The mm corresponding to the CPU range
>> + * @hmm_range: The hmm_range to fault.
>> + * @pfns: The pfn array to populate (size @npages)
>> + * @timeout: jiffies deadline for the -EBUSY retry loop
>> + *
>> + * Fault the CPU pages of the range into @pfns. This is the MM level step.
>> + *
>> + * Return: 0 on success, negative error code on failure.
>> + */
>> +static int drm_gpusvm_hmm_fault(struct drm_gpusvm *gpusvm,
>> + struct mm_struct *mm,
>> + struct hmm_range *hmm_range,
>> + unsigned long *pfns,
>> + unsigned long timeout)
>> +{
>> + int err;
>> +
>> + if (!mmget_not_zero(mm))
>> + return -EFAULT;
>> +
>> + hmm_range->hmm_pfns = pfns;
>> + while (true) {
>> + mmap_read_lock(mm);
>> + err = hmm_range_fault(hmm_range);
>> + mmap_read_unlock(mm);
>> +
>> + if (err == -EBUSY) {
>> + if (time_after(jiffies, timeout))
>> + break;
>> +
>> + hmm_range->notifier_seq =
>> + mmu_interval_read_begin(hmm_range->notifier);
>> + continue;
>> + }
>> + break;
>> + }
>> + mmput(mm);
>> +
>> + return err;
>> +}
>> +
>> /**
>> * drm_gpusvm_get_pages() - Get pages and populate GPU SVM pages struct
>> * @gpusvm: Pointer to the GPU SVM structure
>> @@ -1503,28 +1547,7 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
>> if (!pfns)
>> return -ENOMEM;
>>
>> - if (!mmget_not_zero(mm)) {
>> - err = -EFAULT;
>> - goto err_free;
>> - }
>> -
>> - hmm_range.hmm_pfns = pfns;
>> - while (true) {
>> - mmap_read_lock(mm);
>> - err = hmm_range_fault(&hmm_range);
>> - mmap_read_unlock(mm);
>> -
>> - if (err == -EBUSY) {
>> - if (time_after(jiffies, timeout))
>> - break;
>> -
>> - hmm_range.notifier_seq =
>> - mmu_interval_read_begin(notifier);
>> - continue;
>> - }
>> - break;
>> - }
>> - mmput(mm);
>> + err = drm_gpusvm_hmm_fault(gpusvm, mm, &hmm_range, pfns, timeout);
>> if (err)
>> goto err_free;
>>
>> --
>> 2.34.1
>>
next prev parent reply other threads:[~2026-08-27 9:02 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 [this message]
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
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=bcdc465f-2f83-4fc0-93e6-ed94b076989c@amd.com \
--to=honghuan@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=Christian.Koenig@amd.com \
--cc=Felix.Kuehling@amd.com \
--cc=Junhua.Shen@amd.com \
--cc=Lingshan.Zhu@amd.com \
--cc=Ray.Huang@amd.com \
--cc=Yiru.Ma@amd.com \
--cc=aliceryhl@google.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=sima@ffwll.ch \
--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