Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Francois Dugast <francois.dugast@intel.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 3/4] drm/pagemap: Add helper to access zone_device_data
Date: Fri, 19 Dec 2025 16:29:40 +0100	[thread overview]
Message-ID: <aUVvZIhuQu5L_I8O@fdugast-desk> (raw)
In-Reply-To: <aUR97HW9UGMHObuf@lstrano-desk.jf.intel.com>

On Thu, Dec 18, 2025 at 02:19:24PM -0800, Matthew Brost wrote:
> On Tue, Dec 16, 2025 at 09:10:13PM +0100, Francois Dugast wrote:
> > This new helper helps ensure all accesses to zone_device_data use the
> > correct API whether the page is part of a folio or not.
> > 
> > Suggested-by: Matthew Brost <matthew.brost@intel.com>
> > Signed-off-by: Francois Dugast <francois.dugast@intel.com>
> > ---
> >  drivers/gpu/drm/drm_gpusvm.c  |  7 +++++--
> >  drivers/gpu/drm/drm_pagemap.c | 32 +++++++++++++++++++++++++-------
> >  include/drm/drm_pagemap.h     |  2 ++
> >  3 files changed, 32 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> > index 39c8c50401dd..d0ff6b65e543 100644
> > --- a/drivers/gpu/drm/drm_gpusvm.c
> > +++ b/drivers/gpu/drm/drm_gpusvm.c
> > @@ -1366,12 +1366,15 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
> >  		order = drm_gpusvm_hmm_pfn_to_order(pfns[i], i, npages);
> >  		if (is_device_private_page(page) ||
> >  		    is_device_coherent_page(page)) {
> > +			struct drm_pagemap_zdd *__zdd =
> > +				drm_pagemap_page_zone_device_data(page);
> > +
> >  			if (!ctx->allow_mixed &&
> > -			    zdd != page->zone_device_data && i > 0) {
> > +			    zdd != __zdd && i > 0) {
> >  				err = -EOPNOTSUPP;
> >  				goto err_unmap;
> >  			}
> > -			zdd = page->zone_device_data;
> > +			zdd = __zdd;
> >  			if (pagemap != page_pgmap(page)) {
> >  				if (i > 0) {
> >  					err = -EOPNOTSUPP;
> > diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c
> > index 491de9275add..b71e47136112 100644
> > --- a/drivers/gpu/drm/drm_pagemap.c
> > +++ b/drivers/gpu/drm/drm_pagemap.c
> > @@ -192,6 +192,22 @@ static void drm_pagemap_migration_unlock_put_pages(unsigned long npages,
> >  	}
> >  }
> >  
> > +/**
> > + * drm_pagemap_page_zone_device_data() - Page to zone_device_data
> > + * @page: Pointer to the page
> > + *
> > + * Return: Page's zone_device_data
> > + */
> > +void *drm_pagemap_page_zone_device_data(struct page *page)
> > +{
> > +	struct folio *folio = page_folio(page);
> > +
> 
> I think we can actually just do:
> 
> return folio_zone_device_data(folio)

Agreed.

> 
> We still need the helper as if page is part of a folio the individual
> page->zone_device_data could be NULL.
> 
> Also since this called from GPU SVM maybe make this an inline in
> drm_pagemap.h too. We'd have to include 'linux/memremap.h' in
> drm_pagemap.h but I don't that is a huge deal. 

Yes that is better, will do.

Francois

> 
> Matt
> 
> > +	if (folio_order(folio))
> > +		return folio_zone_device_data(folio);
> > +
> > +	return page->zone_device_data;
> > +}
> > +
> >  /**
> >   * drm_pagemap_get_devmem_page() - Get a reference to a device memory page
> >   * @page: Pointer to the page
> > @@ -481,8 +497,8 @@ static int drm_pagemap_migrate_populate_ram_pfn(struct vm_area_struct *vas,
> >  			goto next;
> >  
> >  		if (fault_page) {
> > -			if (src_page->zone_device_data !=
> > -			    fault_page->zone_device_data)
> > +			if (drm_pagemap_page_zone_device_data(src_page) !=
> > +			    drm_pagemap_page_zone_device_data(fault_page))
> >  				goto next;
> >  		}
> >  
> > @@ -670,7 +686,7 @@ static int __drm_pagemap_migrate_to_ram(struct vm_area_struct *vas,
> >  	int i, err = 0;
> >  
> >  	if (page) {
> > -		zdd = page->zone_device_data;
> > +		zdd = drm_pagemap_page_zone_device_data(page);
> >  		if (time_before64(get_jiffies_64(),
> >  				  zdd->devmem_allocation->timeslice_expiration))
> >  			return 0;
> > @@ -722,7 +738,7 @@ static int __drm_pagemap_migrate_to_ram(struct vm_area_struct *vas,
> >  		if (!page)
> >  			goto err_finalize;
> >  	}
> > -	zdd = page->zone_device_data;
> > +	zdd = drm_pagemap_page_zone_device_data(page);
> >  	ops = zdd->devmem_allocation->ops;
> >  	dev = zdd->devmem_allocation->dev;
> >  
> > @@ -768,7 +784,9 @@ static int __drm_pagemap_migrate_to_ram(struct vm_area_struct *vas,
> >   */
> >  static void drm_pagemap_folio_free(struct folio *folio)
> >  {
> > -	drm_pagemap_zdd_put(folio->page.zone_device_data);
> > +	struct page *page = folio_page(folio, 0);
> > +
> > +	drm_pagemap_zdd_put(drm_pagemap_page_zone_device_data(page));
> >  }
> >  
> >  /**
> > @@ -784,7 +802,7 @@ static void drm_pagemap_folio_free(struct folio *folio)
> >   */
> >  static vm_fault_t drm_pagemap_migrate_to_ram(struct vm_fault *vmf)
> >  {
> > -	struct drm_pagemap_zdd *zdd = vmf->page->zone_device_data;
> > +	struct drm_pagemap_zdd *zdd = drm_pagemap_page_zone_device_data(vmf->page);
> >  	int err;
> >  
> >  	err = __drm_pagemap_migrate_to_ram(vmf->vma,
> > @@ -847,7 +865,7 @@ EXPORT_SYMBOL_GPL(drm_pagemap_devmem_init);
> >   */
> >  struct drm_pagemap *drm_pagemap_page_to_dpagemap(struct page *page)
> >  {
> > -	struct drm_pagemap_zdd *zdd = page->zone_device_data;
> > +	struct drm_pagemap_zdd *zdd = drm_pagemap_page_zone_device_data(page);
> >  
> >  	return zdd->devmem_allocation->dpagemap;
> >  }
> > diff --git a/include/drm/drm_pagemap.h b/include/drm/drm_pagemap.h
> > index f6e7e234c089..3a8d0e1cef43 100644
> > --- a/include/drm/drm_pagemap.h
> > +++ b/include/drm/drm_pagemap.h
> > @@ -245,4 +245,6 @@ int drm_pagemap_populate_mm(struct drm_pagemap *dpagemap,
> >  			    struct mm_struct *mm,
> >  			    unsigned long timeslice_ms);
> >  
> > +void *drm_pagemap_page_zone_device_data(struct page *page);
> > +
> >  #endif
> > -- 
> > 2.43.0
> > 

  reply	other threads:[~2025-12-19 15:29 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-16 20:10 [PATCH 0/4] Enable THP support in drm_pagemap Francois Dugast
2025-12-16 20:10 ` [PATCH 1/4] mm/migrate: Add migrate_device_split_page Francois Dugast
2025-12-16 20:34   ` Matthew Wilcox
2025-12-16 21:39     ` Matthew Brost
2026-01-06  2:39       ` Matthew Brost
2026-01-07 20:15         ` Zi Yan
2026-01-07 20:20   ` Zi Yan
2026-01-07 20:38     ` Zi Yan
2026-01-07 21:15       ` Matthew Brost
2026-01-07 22:03         ` Zi Yan
2026-01-08  0:56           ` Balbir Singh
2026-01-08  2:17             ` Matthew Brost
2026-01-08  2:53               ` Zi Yan
2026-01-08  3:14                 ` Alistair Popple
2026-01-08  3:42                   ` Matthew Brost
2026-01-08  4:47                     ` Balbir Singh
2025-12-16 20:10 ` [PATCH 2/4] drm/pagemap: Unlock and put folios when possible Francois Dugast
2025-12-18 21:59   ` Matthew Brost
2025-12-16 20:10 ` [PATCH 3/4] drm/pagemap: Add helper to access zone_device_data Francois Dugast
2025-12-18 22:19   ` Matthew Brost
2025-12-19 15:29     ` Francois Dugast [this message]
2025-12-19 20:13   ` Matthew Brost
2025-12-16 20:10 ` [PATCH 4/4] drm/pagemap: Enable THP support for GPU memory migration Francois Dugast
2025-12-18 22:24   ` Matthew Brost
2025-12-17  0:14 ` ✗ CI.checkpatch: warning for Enable THP support in drm_pagemap Patchwork
2025-12-17  0:16 ` ✓ CI.KUnit: success " Patchwork
2025-12-17  0:31 ` ✗ CI.checksparse: warning " Patchwork
2025-12-17  0:55 ` ✓ Xe.CI.BAT: success " Patchwork
2025-12-17 23:22 ` ✗ Xe.CI.Full: failure " Patchwork

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=aUVvZIhuQu5L_I8O@fdugast-desk \
    --to=francois.dugast@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@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