On Mon, Nov 09, 2026 at 11:53:37AM -0800, Lizhi Hou wrote: > Hi Matthew, > > > How do we converge on this? Both 2 patches are reviewed, is it good to > merge them to drm-misc-next? >
I also gave an RB, feel free to merge or if you need help merging, let me know and I can merge them. Matt > Honglei, Thanks a lot for reviewing the code. > > > Lizhi > > On 11/9/26 00:56, Huang, Honglei1 wrote: > > AMD General > > > > Reviewed-by: Honglei Huang <[email protected]> > > > > -----Original Message----- > > From: Lizhi Hou <[email protected]> > > Sent: Saturday, November 7, 2026 2:42 AM > > To: [email protected]; [email protected]; > > [email protected]; Limonciello, Mario > > <[email protected]>; [email protected]; Zhen, Max > > <[email protected]>; [email protected]; > > [email protected]; Huang, Honglei1 <[email protected]> > > Cc: Matthew Brost <[email protected]>; [email protected]; > > Santan, Sonal <[email protected]>; Hou, Lizhi <[email protected]> > > Subject: [PATCH V1 1/2] drm/gpusvm: add drm_gpusvm_pages unmapped and retry > > helpers > > > > From: Matthew Brost <[email protected]> > > > > 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 <[email protected]> > > Signed-off-by: Lizhi Hou <[email protected]> > > --- > > 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 > >
