From: sashiko-bot@kernel.org
To: mpenttil@redhat.com
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v14 11/12] lib/test_hmm: add a new testcase for the migrate on fault
Date: Tue, 22 Sep 2026 06:09:37 +0000 [thread overview]
Message-ID: <20260922060938.2B9771F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922053421.4092027-12-mpenttil@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm: test_hmm: UAF due to concurrent unmaps during migration
--
commit 561fbddf4a910a84fca4e2648f745dbccb247398
Author: Mika Penttilä <mpenttil@redhat.com>
lib/test_hmm: add a new testcase for the migrate on fault
This commit enhances the hmm test driver (lib/test_hmm) with a new test
case for migrate on fault. It adds a new ioctl and test code to fault and
migrate anonymous memory to device private memory.
> diff --git a/lib/test_hmm.c b/lib/test_hmm.c
> index cd88e8177d0ab..b39522c05d832 100644
> --- a/lib/test_hmm.c
> +++ b/lib/test_hmm.c
[ ... ]
> @@ -382,7 +390,9 @@ static int dmirror_range_fault(struct dmirror *dmirror,
> break;
> }
>
> - ret = dmirror_do_fault(dmirror, range);
> + /* update device page table after migration */
> + if (!migrate)
> + ret = dmirror_do_fault(dmirror, range);
>
> mutex_unlock(&dmirror->mutex);
> out:
[Severity: High]
Does skipping the page table update here leave us vulnerable to concurrent
unmaps during migration?
When migrate is true, the dmirror->mutex is dropped here without verifying
the final sequence or updating the device page table. This opens a race
window.
[ ... ]
> @@ -1377,6 +1387,114 @@ static int dmirror_migrate_to_device(struct dmirror *dmirror,
> return ret;
> }
>
> +static int do_fault_and_migrate(struct dmirror *dmirror, struct hmm_range *range)
> +{
> + struct migrate_vma *migrate = range->migrate;
> + int ret;
> +
> + mmap_read_lock(dmirror->notifier.mm);
> +
> + /* Fault-in pages for migration */
> + ret = dmirror_range_fault(dmirror, range);
[ ... ]
> + pr_debug("Migrating from sys mem to device mem\n");
> +
> + dmirror_migrate_alloc_and_copy(migrate, dmirror);
> + migrate_vma_pages(migrate);
> + dmirror_migrate_finalize_and_map(migrate, dmirror);
> + migrate_vma_finalize(migrate);
[Severity: High]
Can this sequence lead to a use-after-free of device pages if a concurrent
unmap occurs after we dropped the mutex in dmirror_range_fault()?
While mmap_read_lock() is held here, a concurrent madvise(MADV_DONTNEED)
could still execute (since it only requires the read lock or per-VMA lock)
and clear the newly installed migration PTEs, triggering the MMU interval
notifier.
Since the interval notifier invalidation would see an empty dmirror->pt (as
we haven't mapped the pages yet), it would take no action.
Then, dmirror_migrate_finalize_and_map() inserts the newly allocated device
pages into dmirror->pt blindly, without re-checking
mmu_interval_read_retry().
When migrate_vma_finalize() runs, it would fail to map the device page into
the CPU page table because the migration PTE is gone, dropping the final
reference and freeing the page while it is still mapped in the device
page table.
> +out:
> + mmap_read_unlock(dmirror->notifier.mm);
> + return ret;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260922053421.4092027-1-mpenttil@redhat.com?part=11
next prev parent reply other threads:[~2026-09-22 6:09 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 5:34 [PATCH 00/12] [PATCH v14 00/12] migrate on fault for device pages mpenttil
2026-09-22 5:34 ` [PATCH v14 01/12] mm/Kconfig: changes for " mpenttil
2026-09-22 5:44 ` sashiko-bot
2026-09-22 22:27 ` Balbir Singh
2026-09-23 5:42 ` Mika Penttilä
2026-09-22 5:34 ` [PATCH v14 02/12] mm: add helper to convert HMM pfn to migrate pfn mpenttil
2026-09-22 5:34 ` [PATCH v14 03/12] mm/hmm: preparations for HMM to participate in migration mpenttil
2026-09-22 5:49 ` sashiko-bot
2026-09-22 5:34 ` [PATCH v14 04/12] mm/hmm: do the plumbing " mpenttil
2026-09-22 5:50 ` sashiko-bot
2026-09-22 5:34 ` [PATCH v14 05/12] mm/hmm: implement folio split for migrate needs in HMM pagewalk mpenttil
2026-09-22 5:47 ` sashiko-bot
2026-09-22 5:34 ` [PATCH v14 06/12] mm/hmm: migrate collection in HMM pagewalk - pte level mpenttil
2026-09-22 5:47 ` sashiko-bot
2026-09-22 5:34 ` [PATCH v14 07/12] mm/hmm: migrate collection in HMM pagewalk - pmd level mpenttil
2026-09-22 5:50 ` sashiko-bot
2026-09-22 5:34 ` [PATCH v14 08/12] mm/hmm: add lazy MMU mode support for migration in HMM pagewalk mpenttil
2026-09-22 5:51 ` sashiko-bot
2026-09-22 5:34 ` [PATCH v14 09/12] mm/hmm: implement rollback for device page " mpenttil
2026-09-22 5:34 ` [PATCH v14 10/12] mm: enable device page migration from " mpenttil
2026-09-22 5:58 ` sashiko-bot
2026-09-22 5:34 ` [PATCH v14 11/12] lib/test_hmm: add a new testcase for the migrate on fault mpenttil
2026-09-22 6:09 ` sashiko-bot [this message]
2026-09-22 5:34 ` [PATCH v14 12/12] Documentation/mm/hmm: document migration through hmm_range_fault() mpenttil
2026-09-22 5:41 ` ✗ CI.checkpatch: warning for Migrate on fault for device pages (rev6) Patchwork
2026-09-22 5:43 ` ✓ CI.KUnit: success " Patchwork
2026-09-22 6:00 ` ✗ CI.checksparse: warning " Patchwork
2026-09-22 7:08 ` ✓ Xe.CI.BAT: success " Patchwork
2026-09-22 15:03 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-09-23 2:27 ` [PATCH 00/12] [PATCH v14 00/12] migrate on fault for device pages Andrew Morton
2026-09-23 5:29 ` Mika Penttilä
2026-09-23 21:19 ` Andrew Morton
2026-09-23 23:24 ` Jason Gunthorpe
2026-09-24 0:14 ` Mika Penttilä
2026-09-24 0:10 ` Mika Penttilä
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=20260922060938.2B9771F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=mpenttil@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox