Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Francois Dugast <francois.dugast@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v2 4/5] DONOTMERGE drm/pagemap: Add drm_pagemap_cpages
Date: Tue, 6 Jan 2026 18:32:01 -0800	[thread overview]
Message-ID: <aV3FoQYYLGtJGkj+@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <20260105111945.73292-5-francois.dugast@intel.com>

On Mon, Jan 05, 2026 at 12:18:27PM +0100, Francois Dugast wrote:
> This code was written by Matt Brost. This is a placeholder until his
> patch is available.
> 
> Cc: Matthew Brost <matthew.brost@intel.com>
> Signed-off-by: Francois Dugast <francois.dugast@intel.com>
> ---
>  drivers/gpu/drm/drm_pagemap.c | 36 ++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c
> index db3795f03aca..05e708730132 100644
> --- a/drivers/gpu/drm/drm_pagemap.c
> +++ b/drivers/gpu/drm/drm_pagemap.c
> @@ -452,6 +452,39 @@ static int drm_pagemap_migrate_range(struct drm_pagemap_devmem *devmem,
>  	return ret;
>  }
>  
> +/**
> + * drm_pagemap_cpages() - Count collected pages
> + * @migrate_pfn: Array of migrate_pfn entries to account
> + * @npages: Number of entries in @migrate_pfn
> + *
> + * Compute the total number of minimum-sized pages represented by the
> + * collected entries in @migrate_pfn. The total is derived from the
> + * order encoded in each entry.
> + *
> + * Return: Total number of minimum-sized pages.
> + */
> +static int drm_pagemap_cpages(unsigned long *migrate_pfn, unsigned long npages)
> +{
> +	unsigned long i, cpages = 0;
> +
> +	for (i = 0; i < npages;) {
> +		struct page *page = migrate_pfn_to_page(migrate_pfn[i]);
> +		struct folio *folio;
> +		unsigned int order = 0;
> +
> +		if (!page)
> +			goto next;

Actually I think on a NULL page we can check compond bit in the mpfn set
and increment by 512 too.

Matt

> +
> +		folio = page_folio(page);
> +		order = folio_order(folio);
> +		cpages += NR_PAGES(order);
> +next:
> +		i += NR_PAGES(order);
> +	}
> +
> +	return cpages;
> +}
> +
>  /**
>   * drm_pagemap_migrate_to_devmem() - Migrate a struct mm_struct range to device memory
>   * @devmem_allocation: The device memory allocation to migrate to.
> @@ -554,7 +587,8 @@ int drm_pagemap_migrate_to_devmem(struct drm_pagemap_devmem *devmem_allocation,
>  		goto err_free;
>  	}
>  
> -	if (migrate.cpages != npages) {
> +	if (migrate.cpages != npages &&
> +	    drm_pagemap_cpages(migrate.src, npages) != npages) {
>  		/*
>  		 * Some pages to migrate. But we want to migrate all or
>  		 * nothing. Raced or unknown device pages.
> -- 
> 2.43.0
> 

  parent reply	other threads:[~2026-01-07  2:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 11:18 [PATCH v2 0/5] Enable THP support in drm_pagemap Francois Dugast
2026-01-05 11:18 ` [PATCH v2 1/5] mm/migrate: Add migrate_device_split_page Francois Dugast
2026-01-05 11:18 ` [PATCH v2 2/5] drm/pagemap: Unlock and put folios when possible Francois Dugast
2026-01-05 11:18 ` [PATCH v2 3/5] drm/pagemap: Add helper to access zone_device_data Francois Dugast
2026-01-05 15:53   ` Matthew Brost
2026-01-05 11:18 ` [PATCH v2 4/5] DONOTMERGE drm/pagemap: Add drm_pagemap_cpages Francois Dugast
2026-01-05 16:51   ` Matthew Brost
2026-01-07  2:32   ` Matthew Brost [this message]
2026-01-05 11:18 ` [PATCH v2 5/5] drm/pagemap: Enable THP support for GPU memory migration Francois Dugast
2026-01-05 16:09   ` Matthew Brost
2026-01-06 12:47     ` Francois Dugast
2026-01-05 11:38 ` ✗ CI.checkpatch: warning for Enable THP support in drm_pagemap (rev2) Patchwork
2026-01-05 11:39 ` ✓ CI.KUnit: success " Patchwork
2026-01-05 11:58 ` ✗ CI.checksparse: warning " Patchwork
2026-01-05 12:19 ` ✓ Xe.CI.BAT: success " Patchwork
2026-01-05 14:04 ` ✗ 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=aV3FoQYYLGtJGkj+@lstrano-desk.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=francois.dugast@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /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