AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: "Huang, Honglei" <honghuan@amd.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: Mon, 31 Aug 2026 18:23:27 -0700	[thread overview]
Message-ID: <apYpDwBsczVHXGik@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <bcdc465f-2f83-4fc0-93e6-ed94b076989c@amd.com>

On Thu, Aug 27, 2026 at 05:02:43PM +0800, Huang, Honglei wrote:
> 
> 
> 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.
> 

It looks like the core MM helpers have landed in drm-tip [2] but not
gpusvm bits.

If it isn't too much trouble can you pull in version of [3] at the base
of this series, credit Stanislav as the author, and then rebase this
series on top?

We can then merge all of this together into drm-tip.

Matt

[2] 121170831228 mm/hmm: add hmm_range_fault_unlocked_timeout() for mmap lock-drop support
[3] https://lore.freedesktop.org/nouveau/20260722-hmm-v10-v1-6-606464dd601a@gmail.com/T/#m68f663ce3e802d7692363c70e6364569134cd6c7

> 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
> > > 
> 

  reply	other threads:[~2026-09-01  1:23 UTC|newest]

Thread overview: 10+ 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-09-01  1:23       ` Matthew Brost [this message]
2026-09-01  9:15         ` 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:14 ` [RFC PATCH v1 3/5] drm/gpusvm: extract drm_gpusvm_dma_map_pages() helper Honglei Huang
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: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=apYpDwBsczVHXGik@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.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=honghuan@amd.com \
    --cc=intel-xe@lists.freedesktop.org \
    --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