mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lizhi Hou <lizhi.hou@amd.com>
To: "Huang, Honglei1" <Honglei1.Huang@amd.com>,
	Matthew Brost <matthew.brost@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Santan, Sonal" <sonal.santan@amd.com>,
	"ogabbay@kernel.org" <ogabbay@kernel.org>,
	"quic_jhugo@quicinc.com" <quic_jhugo@quicinc.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Limonciello, Mario" <Mario.Limonciello@amd.com>,
	"karol.wachowski@linux.intel.com"
	<karol.wachowski@linux.intel.com>, "Zhen, Max" <Max.Zhen@amd.com>,
	"thomas.hellstrom@linux.intel.com"
	<thomas.hellstrom@linux.intel.com>,
	"himal.prasad.ghimiray@intel.com"
	<himal.prasad.ghimiray@intel.com>
Subject: Re: [PATCH V1 1/2] drm/gpusvm: add drm_gpusvm_pages unmapped and retry helpers
Date: Mon, 9 Nov 2026 11:53:37 -0800	[thread overview]
Message-ID: <283f184b-eefd-2402-3ed7-a08a96dce382@amd.com> (raw)
In-Reply-To: <CY8PR12MB71707223ED3F56E5894FF353D9732@CY8PR12MB7170.namprd12.prod.outlook.com>

Hi Matthew,


How do we converge on this?  Both 2 patches are reviewed, is it good to 
merge them to drm-misc-next?

Honglei, Thanks a lot for reviewing the code.


Lizhi

On 11/9/26 00:56, Huang, Honglei1 wrote:
> AMD General
>
> Reviewed-by: Honglei Huang <honghuan@amd.com>
>
> -----Original Message-----
> From: Lizhi Hou <lizhi.hou@amd.com>
> Sent: Saturday, November 7, 2026 2:42 AM
> To: ogabbay@kernel.org; quic_jhugo@quicinc.com; dri-devel@lists.freedesktop.org; Limonciello, Mario <Mario.Limonciello@amd.com>; karol.wachowski@linux.intel.com; Zhen, Max <Max.Zhen@amd.com>; thomas.hellstrom@linux.intel.com; himal.prasad.ghimiray@intel.com; Huang, Honglei1 <Honglei1.Huang@amd.com>
> Cc: Matthew Brost <matthew.brost@intel.com>; linux-kernel@vger.kernel.org; Santan, Sonal <sonal.santan@amd.com>; Hou, Lizhi <lizhi.hou@amd.com>
> Subject: [PATCH V1 1/2] drm/gpusvm: add drm_gpusvm_pages unmapped and retry helpers
>
> From: Matthew Brost <matthew.brost@intel.com>
>
> Drivers which only use the drm_gpusvm_pages API (no drm_gpusvm_range) have no way to mark pages unmapped from their MMU notifier, as
> drm_gpusvm_range_set_unmapped() requires a range. They also have to open code the mmu_interval_read_retry() check on the recorded notifier_seq to commit pages faulted with &drm_gpusvm_ctx.no_dma_map.
>
> Split the pages part of drm_gpusvm_range_set_unmapped() into drm_gpusvm_pages_set_unmapped(), and add drm_gpusvm_pages_read_retry() which performs the commit side check with a lockdep assert on the notifier lock.
>
> Assisted-by: LLM
> Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
> ---
>   drivers/gpu/drm/drm_gpusvm.c | 49 +++++++++++++++++++++++++-----------
>   include/drm/drm_gpusvm.h     | 29 +++++++++++++++++++++
>   2 files changed, 64 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c index 03dbe304e4b8f..63a26919f59db 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -1761,9 +1761,8 @@ static int drm_gpusvm_dma_map_pages(struct drm_gpusvm *gpusvm,
>    *
>    * With &drm_gpusvm_ctx.no_dma_map no mapping state is recorded, so
>    * drm_gpusvm_pages_valid() never returns true and success is only a snapshot:
> - * the caller must recheck mmu_interval_read_retry() against the recorded
> - * &drm_gpusvm_pages.notifier_seq under the notifier lock, and hold it until
> - * its work is visible to invalidation.
> + * the caller must recheck drm_gpusvm_pages_read_retry() under the
> + notifier
> + * lock, and hold it until its work is visible to invalidation.
>    *
>    * Return: 0 on success, negative error code on failure.
>    */
> @@ -2021,6 +2020,38 @@ bool drm_gpusvm_has_mapping(struct drm_gpusvm *gpusvm, unsigned long start,  }  EXPORT_SYMBOL_GPL(drm_gpusvm_has_mapping);
>
> +/**
> + * drm_gpusvm_pages_set_unmapped() - Mark GPU SVM pages as unmapped
> + * @gpusvm: Pointer to the GPU SVM structure.
> + * @pages: Pointer to the GPU SVM pages structure(s).
> + * @pages_count: Number of GPU SVM pages structure(s) passed in.
> + *
> + * Mark @pages as unmapped, after which drm_gpusvm_get_pages() fails
> +with
> + * -EFAULT for them. Intended to be called from the driver's MMU
> +notifier on
> + * MMU_NOTIFY_UNMAP, and usable without a &drm_gpusvm_range by drivers
> +that
> + * only use the drm_gpusvm_pages API. The caller must hold the notifier
> +lock
> + * in write mode.
> + */
> +void drm_gpusvm_pages_set_unmapped(struct drm_gpusvm *gpusvm,
> +                                  struct drm_gpusvm_pages *pages,
> +                                  unsigned int pages_count)
> +{
> +       unsigned int i;
> +
> +       lockdep_assert_held_write(&gpusvm->notifier_lock);
> +
> +       for (i = 0; i < pages_count; ++i) {
> +               struct drm_gpusvm_pages_flags flags = {
> +                       .__flags = pages[i].flags.__flags,
> +               };
> +
> +               flags.unmapped = true;
> +               /* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */
> +               WRITE_ONCE(pages[i].flags.__flags, flags.__flags);
> +       }
> +}
> +EXPORT_SYMBOL_GPL(drm_gpusvm_pages_set_unmapped);
> +
>   /**
>    * drm_gpusvm_range_set_unmapped() - Mark a GPU SVM range as unmapped
>    * @range: Pointer to the GPU SVM range structure.
> @@ -2039,20 +2070,10 @@ void drm_gpusvm_range_set_unmapped(struct drm_gpusvm_range *range,
>          struct drm_gpusvm_range_flags range_flags = {
>                  .__flags = range->flags.__flags,
>          };
> -       unsigned int i;
>
> -       lockdep_assert_held_write(&range->gpusvm->notifier_lock);
> +       drm_gpusvm_pages_set_unmapped(range->gpusvm, pages, pages_count);
>
>          range_flags.unmapped = true;
> -       for (i = 0; i < pages_count; ++i) {
> -               struct drm_gpusvm_pages_flags flags = {
> -                       .__flags = pages[i].flags.__flags,
> -               };
> -
> -               flags.unmapped = true;
> -               /* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */
> -               WRITE_ONCE(pages[i].flags.__flags, flags.__flags);
> -       }
>          if (drm_gpusvm_range_start(range) < mmu_range->start ||
>              drm_gpusvm_range_end(range) > mmu_range->end)
>                  range_flags.partial_unmap = true;
> diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h index 4d31c6bba7455..b43432af56377 100644
> --- a/include/drm/drm_gpusvm.h
> +++ b/include/drm/drm_gpusvm.h
> @@ -349,6 +349,10 @@ void drm_gpusvm_range_set_unmapped(struct drm_gpusvm_range *range,
>                                     unsigned int pages_count,
>                                     const struct mmu_notifier_range *mmu_range);
>
> +void drm_gpusvm_pages_set_unmapped(struct drm_gpusvm *gpusvm,
> +                                  struct drm_gpusvm_pages *pages,
> +                                  unsigned int pages_count);
> +
>   int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
>                           struct drm_gpusvm_pages *svm_pages,
>                           unsigned int num_pages,
> @@ -383,6 +387,31 @@ static inline void drm_gpusvm_init_pages(struct drm_gpusvm_pages *svm_pages,
>          svm_pages->notifier_seq = LONG_MAX;
>   }
>
> +/**
> + * drm_gpusvm_pages_read_retry() - Check whether GPU SVM pages went
> +stale
> + * @gpusvm: Pointer to the GPU SVM structure.
> + * @svm_pages: Pointer to the drm_gpusvm_pages.
> + * @notifier: The notifier passed to drm_gpusvm_get_pages() for @svm_pages.
> + *
> + * Check whether @notifier was invalidated since the last successful
> + * drm_gpusvm_get_pages() for @svm_pages. This is the commit side check
> +for
> + * pages faulted with &drm_gpusvm_ctx.no_dma_map, where no mapping
> +state is
> + * tracked. Pages that were never faulted always report as stale. The
> +caller
> + * must hold the notifier lock and keep holding it until its use of the
> +pages
> + * is visible to the invalidation path.
> + *
> + * Return: True if the pages must be faulted again, false otherwise.
> + */
> +static inline bool
> +drm_gpusvm_pages_read_retry(struct drm_gpusvm *gpusvm,
> +                           struct drm_gpusvm_pages *svm_pages,
> +                           struct mmu_interval_notifier *notifier) {
> +       lockdep_assert_held(&gpusvm->notifier_lock);
> +
> +       return mmu_interval_read_retry(notifier, svm_pages->notifier_seq); }
> +
>   /**
>    * drm_gpusvm_pages_first_dma() - Resolve the device address array
>    * @svm_pages: Pointer to the drm_gpusvm_pages.
>
> base-commit: d2a8cee91bfa8616f713c7c8f539a81e8e3554ea
> --
> 2.34.1
>

      reply	other threads:[~2026-11-09 19:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 18:42 Lizhi Hou
2026-11-06 18:42 ` [PATCH V1 2/2] accel/amdxdna: use drm_gpusvm_pages for user mapping tracking Lizhi Hou
2026-11-09 19:44   ` Max Zhen
2026-11-09  8:56 ` [PATCH V1 1/2] drm/gpusvm: add drm_gpusvm_pages unmapped and retry helpers Huang, Honglei1
2026-11-09 19:53   ` Lizhi Hou [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=283f184b-eefd-2402-3ed7-a08a96dce382@amd.com \
    --to=lizhi.hou@amd.com \
    --cc=Honglei1.Huang@amd.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=Max.Zhen@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=karol.wachowski@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=ogabbay@kernel.org \
    --cc=quic_jhugo@quicinc.com \
    --cc=sonal.santan@amd.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

all inboxes | Powered by JetHome®