All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arvind Yadav" <arvind.yadav@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/pagemap: Reset migration page count on eviction retry
Date: Tue, 28 Jul 2026 09:15:47 +0000	[thread overview]
Message-ID: <20260728091548.0392E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728090304.1264759-1-arvind.yadav@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] DMA mappings are leaked in migration error paths because the destination page array is zeroed before unmapping.
- [High] DMA unmapping occurs after pages are exposed to the CPU, violating cache coherency rules.
--

--- Patch [1]: [PATCH] drm/pagemap: Reset migration page count on eviction retry ---
commit f4a68acf50f418cad59d91b95424edfe21778ec5
Author: Arvind Yadav <arvind.yadav@intel.com>

drm/pagemap: Reset migration page count on eviction retry

This commit updates drm_pagemap_evict_to_ram() to reset the mpages
counter to 0 at the retry label. This ensures that retried eviction
attempts do not incorrectly proceed using the page count from the
previous attempt.

> diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c
> index 15c78eca180b7..695401cb2da24 100644
> --- a/drivers/gpu/drm/drm_pagemap.c
> +++ b/drivers/gpu/drm/drm_pagemap.c
[ ... ]
> @@ -1121,6 +1121,7 @@ int drm_pagemap_evict_to_ram(struct drm_pagemap_devmem *devmem_allocation)
>  	npages = devmem_allocation->size >> PAGE_SHIFT;
>  
>  retry:
> +	mpages = 0;
>  	if (!mmget_not_zero(devmem_allocation->mm))
>  		return -EFAULT;
>  

Further down in drm_pagemap_evict_to_ram():

> err_finalize:
> 	if (err)
> 		drm_pagemap_migration_unlock_put_pages(npages, dst);

[Severity: High]
This isn't a bug introduced by this patch, but does this error path leak
DMA mappings?

If an error occurs (such as a failure to copy to RAM),
drm_pagemap_migration_unlock_put_pages() is called, which zeroes the
destination page array entries in dst.

Subsequently, when drm_pagemap_migrate_unmap_pages() iterates over these
entries, it skips unmapping because the page evaluates to NULL:

drm_pagemap_migrate_unmap_pages() {
    ...
    struct page *page = migrate_pfn_to_page(migrate_pfn[i]);

    if (!page || !pagemap_addr[i].addr || dma_mapping_error(dev, pagemap_addr[i].addr))
        goto next;
    ...
}

Could this cause the DMA addresses to remain permanently mapped in the IOMMU
or SWIOTLB?

> 	migrate_device_pages(src, dst, npages);
> 	migrate_device_finalize(src, dst, npages);
> 	drm_pagemap_migrate_unmap_pages(devmem_allocation->dev, pagemap_addr, dst, npages,
> 					DMA_FROM_DEVICE, &state);

[Severity: High]
This is also a pre-existing issue, but is the ordering of CPU exposure and
DMA unmapping safe here?

migrate_device_finalize() is called before drm_pagemap_migrate_unmap_pages().

The finalize function removes migration PTEs and restores normal CPU page
table entries, allowing userspace to immediately access the migrated pages.

However, the DMA API requires that dma_unmap_page() completes before the
CPU accesses the memory. Because dma_unmap_page() for DMA_FROM_DEVICE
mappings invalidates the CPU cache on non-coherent architectures, executing
it after the CPU has been granted access could destroy recent CPU writes or
cause the CPU to read stale speculative cache lines.

The identical unsafe ordering appears to be present in
__drm_pagemap_migrate_to_ram() where migrate_vma_finalize() is called.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728090304.1264759-1-arvind.yadav@intel.com?part=1

  parent reply	other threads:[~2026-07-28  9:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  9:03 [PATCH] drm/pagemap: Reset migration page count on eviction retry Arvind Yadav
2026-07-28  9:10 ` ✓ CI.KUnit: success for " Patchwork
2026-07-28  9:15 ` sashiko-bot [this message]
2026-07-28  9:45 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-28 12:30 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-28 22:05 ` [PATCH] " Matthew Brost

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=20260728091548.0392E1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arvind.yadav@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.