mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Lizhi Hou <lizhi.hou@amd.com>
Cc: <ogabbay@kernel.org>, <quic_jhugo@quicinc.com>,
	<dri-devel@lists.freedesktop.org>, <mario.limonciello@amd.com>,
	<karol.wachowski@linux.intel.com>, <max.zhen@amd.com>,
	<thomas.hellstrom@linux.intel.com>,
	<himal.prasad.ghimiray@intel.com>, <honghuan@amd.com>,
	<linux-kernel@vger.kernel.org>, <sonal.santan@amd.com>
Subject: Re: [PATCH V1 1/2] drm/gpusvm: add drm_gpusvm_pages unmapped and retry helpers
Date: Mon, 9 Nov 2026 14:34:08 -0800	[thread overview]
Message-ID: <avJKYLGpfjPGGRsb@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20261106184217.2720718-1-lizhi.hou@amd.com>

On Fri, Nov 06, 2026 at 10:42:16AM -0800, Lizhi Hou wrote:
> 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>

Reviewed-by: Matthew Brost <matthew.brost@intel.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
> 

      parent reply	other threads:[~2026-11-09 22:34 UTC|newest]

Thread overview: 7+ 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
2026-11-09 22:35     ` Matthew Brost
2026-11-09 22:34 ` Matthew Brost [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=avJKYLGpfjPGGRsb@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=honghuan@amd.com \
    --cc=karol.wachowski@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.hou@amd.com \
    --cc=mario.limonciello@amd.com \
    --cc=max.zhen@amd.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®