From: sashiko-bot@kernel.org
To: Xiaogang.Chen <xiaogang.chen@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v5 2/3] drm/amdkfd: Do not migrate partial THP memory at CPU/GPU page fault handler
Date: Sun, 22 Nov 2026 20:42:34 +0000 [thread overview]
Message-ID: <sashiko-outbox-228334@kernel.org> (raw)
In-Reply-To: <20261122202653.274580-3-xiaogang.chen@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdkfd: infinite CPU fault loop on split prange in
svm_migrate_to_ram()
--
commit b149598769982ad1feb63c501a92a881118fdebd
Author: Xiaogang Chen <xiaogang.chen@amd.com>
drm/amdkfd: Do not migrate partial THP memory at CPU/GPU page fault handler
This commit adjusts the migration range size on CPU and GPU page faults so
that PMD-mapped THP folios fully covered by an svm_range are migrated at
folio order, while split ranges fall back to prange->granularity.
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> index 5ead98a604b1e..11cda92b88783 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
[ ... ]
> @@ -1142,8 +1145,40 @@ static vm_fault_t svm_migrate_to_ram(struct vm_fault *vmf)
> if (!prange->actual_loc)
> goto out_unlock_prange;
>
> - /* Align migration range start and size to granularity size */
> - size = 1UL << prange->granularity;
> + order = folio_order(folio);
> +
> + /*
> + * A PMD device-private fault always passes the folio head in
> + * vmf->page. If this prange still covers the whole folio, migrate
> + * at folio order so HMM can collect MIGRATE_PFN_COMPOUND.
> + *
> + * Do not want migrate partial THP device memory. If do HMM will split
> + * THP folio. If the compound folio has extra ref/pin the split will fail,
> + * then skip migration, leave without page restore, then cpu keep retry.
> + *
> + * If the prange was split and no longer covers the PMD, do not call
> + * split_folio() here: it is not exported to modules. Walk only this
> + * prange and let migrate_vma_setup() split the PMD inside mm.
> + *
> + * If the fault address has PTE mapping device-private memory use
> + * prange->granularity to decide migration size.
> + */
> + if (order && !vmf->pte) {
> + unsigned long folio_start = ALIGN_DOWN(addr, 1UL << order);
> + unsigned long folio_last = folio_start + (1UL << order) - 1;
> +
> + if (prange->start > folio_start || prange->last < folio_last) {
> + pr_debug("partial prange on device THP svms 0x%p prange [0x%lx 0x%lx] folio [0x%lx 0x%lx]\n",
> + prange->svms, prange->start, prange->last,
> + folio_start, folio_last);
> + size = 1UL << prange->granularity;
> + } else {
> + size = 1UL << max(prange->granularity, order);
> + }
> + } else {
> + size = 1UL << prange->granularity;
> + }
> +
> start = max(ALIGN_DOWN(addr, size), prange->start);
> last = min(ALIGN(addr + 1, size) - 1, prange->last);
[Severity: High]
Can a CPU fault on a PMD-mapped device-private folio enter an infinite
fault loop when prange has been split to a sub-PMD range?
On a PMD device-private fault, do_huge_pmd_device_private() holds an extra
reference on the fault folio across svm_migrate_to_ram(). When [start,
last] is clamped to a split prange smaller than the PMD,
migrate_vma_collect_huge_pmd() takes a second reference and falls back to
split_folio():
mm/migrate_device.c:migrate_vma_collect_huge_pmd() {
...
folio_get(folio);
...
fallback:
spin_unlock(ptl);
if (!folio_test_large(folio))
goto done;
ret = split_folio(folio);
if (fault_folio != folio)
folio_unlock(folio);
folio_put(folio);
if (ret)
return migrate_vma_collect_skip(start, end, walk);
...
}
Because two extra references are held on the folio, unmap_folio() inside
split_folio() fails the reference count check with -EAGAIN before
try_to_migrate() can split the PMD:
mm/huge_memory.c:unmap_folio() {
...
/* Racy check if we can split the page, before we split PMDs */
if (folio_expected_ref_count(folio) != folio_ref_count(folio) - 1)
return -EAGAIN;
...
}
migrate_vma_collect_huge_pmd() then skips the PMD without splitting it or
collecting any pages, and svm_migrate_to_ram() returns 0 with the
device-private PMD entry still in place, causing the CPU to fault on the
same instruction indefinitely.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122202653.274580-1-xiaogang.chen@amd.com?part=2
next prev parent reply other threads:[~2026-11-22 20:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 20:26 [PATCH v5 0/3] drm/amdkfd: Enable device private memory THP support in kfd svm driver Xiaogang.Chen
2026-11-22 20:26 ` [PATCH v5 1/3] drm/amdkfd: Add awareness of THP of device and system RAM " Xiaogang.Chen
2026-11-22 20:49 ` sashiko-bot
2026-11-24 20:32 ` Philip Yang
2026-11-30 7:31 ` Chen, Xiaogang
2026-11-27 21:34 ` Philip Yang
2026-11-30 7:36 ` Chen, Xiaogang
2026-11-30 22:06 ` Philip Yang
2026-11-22 20:26 ` [PATCH v5 2/3] drm/amdkfd: Do not migrate partial THP memory at CPU/GPU page fault handler Xiaogang.Chen
2026-11-22 20:42 ` sashiko-bot [this message]
2026-11-22 20:26 ` [PATCH v5 3/3] drm/amdkfd: Enable HMM device-private THP migration in KFD SVM driver Xiaogang.Chen
2026-11-22 20:51 ` sashiko-bot
2026-11-27 23:23 ` Philip Yang
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=sashiko-outbox-228334@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xiaogang.chen@amd.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 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.