From: sashiko-bot@kernel.org
To: "Arvind Yadav" <arvind.yadav@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5] drm/pagemap: Prevent double migration of device pages
Date: Mon, 10 Aug 2026 07:21:00 +0000 [thread overview]
Message-ID: <20260810072100.C46581F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260810070240.2721317-1-arvind.yadav@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Incorrect PFN array iteration when encountering large folios causes unrelated folios to be skipped, and leaves tail pages improperly processed.
Pre-existing issues:
- [High] Out-of-bounds array write in `migrate_device_pfns()` when processing compound pages.
--
--- Patch [1]: [PATCH v5] drm/pagemap: Prevent double migration of device pages ---
commit e82d028d2739c02084b327b5c44a4c4cb949a76c
Author: Arvind Yadav <arvind.yadav@intel.com>
Subject: drm/pagemap: Prevent double migration of device pages
This patch aims to prevent soft lockups caused by double migration of
device-private folios. It marks successfully migrated folios in their
zone_device_data and makes both CPU-fault and raw-PFN migration paths
skip folios carrying this flag.
> diff --git a/drivers/gpu/drm/drm_pagemap.c b/drivers/gpu/drm/drm_pagemap.c
> --- a/drivers/gpu/drm/drm_pagemap.c
> +++ b/drivers/gpu/drm/drm_pagemap.c
[ ... ]
> +static void drm_pagemap_skip_retired_pages(unsigned long *src_pfns,
> + unsigned long npages)
> +{
> + unsigned long i = 0;
> +
> + while (i < npages) {
> + struct page *page = migrate_pfn_to_page(src_pfns[i]);
> +
> + if (!page) {
> + i++;
> + continue;
> + }
> +
> + if ((src_pfns[i] & MIGRATE_PFN_MIGRATE) &&
> + is_device_private_page(page) &&
> + (drm_pagemap_page_get_flags(page) &
> + DRM_PAGEMAP_ZDD_FLAG_MIGRATED))
> + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
> +
[Severity: High]
Does advancing by folio_nr_pages() here leave tail pages improperly
processed?
By only clearing the MIGRATE_PFN_MIGRATE bit for src_pfns[i] (the head page)
and then skipping ahead, any subsequent tail pages in the src_pfns array
will remain flagged.
Downstream functions like migrate_vma_pages() process every array entry, so
they might see the un-cleared tail pages and attempt to migrate them
individually. Could this defeat the fix and trigger the double migration
lockups again?
Also, if the PFN array starts on a tail page due to VMA boundary clamping,
will advancing by the full folio_nr_pages() overshoot the folio's actual
footprint in the array and skip completely unrelated folios?
This same pattern appears in drm_pagemap_retire_migrated_pages() just above.
There are also pre-existing loops in drm_pagemap_evict_to_ram(),
__drm_pagemap_migrate_to_ram(), and drm_pagemap_migrate_populate_ram_pfn()
that advance using i += NR_PAGES(order) and might suffer from this same
tail-page stepping issue.
> + i += folio_nr_pages(page_folio(page));
> + }
> +}
[ ... ]
> @@ -1143,6 +1240,8 @@ int drm_pagemap_evict_to_ram(struct drm_pagemap_devmem *devmem_allocation)
> if (err)
> goto err_free;
>
> + drm_pagemap_skip_retired_pages(src, npages);
> +
[Severity: High]
This is a pre-existing issue, but does migrate_device_pfns() (called just
above this in drm_pagemap_evict_to_ram) lack bounds checking when processing
compound pages?
When the following loop in mm/migrate_device.c:migrate_device_pfns()
encounters a compound page, it zeroes out subsequent entries in the src_pfns
array up to the full size of the compound page:
mm/migrate_device.c:migrate_device_pfns() {
...
for (j = 1; j < nr; j++)
src_pfns[i+j] = 0;
...
}
If a large folio extends beyond the npages limit, such as when the caller
passes a clamped range or an unaligned array size, this loop will write
zeros past the end of the src_pfns allocation.
Could this corrupt adjacent memory, like the uninitialized dst array
allocated concurrently?
> err = drm_pagemap_migrate_populate_ram_pfn(NULL, NULL, npages, &mpages,
> src, dst, 0);
> if (err || !mpages)
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260810070240.2721317-1-arvind.yadav@intel.com?part=1
next prev parent reply other threads:[~2026-08-10 7:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 7:02 [PATCH v5] drm/pagemap: Prevent double migration of device pages Arvind Yadav
2026-08-10 7:21 ` sashiko-bot [this message]
2026-08-10 7:30 ` ✓ CI.KUnit: success for drm/pagemap: Prevent double migration of device pages (rev6) Patchwork
2026-08-10 8:06 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-10 10:03 ` ✓ Xe.CI.FULL: " 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=20260810072100.C46581F000E9@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.