From: sashiko-bot@kernel.org
To: mpenttil@redhat.com, linux-mm@kvack.org
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
"David Hildenbrand" <david@kernel.org>,
"Jason Gunthorpe" <jgg@nvidia.com>,
"Leon Romanovsky" <leonro@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Balbir Singh" <balbirs@nvidia.com>, "Zi Yan" <ziy@nvidia.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Michal Hocko" <mhocko@suse.com>, "Lyude Paul" <lyude@redhat.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <shuah@kernel.org>,
"Madhavan Srinivasan" <maddy@linux.ibm.com>
Subject: Re: [PATCH v18 14/14] drm/nouveau/svm: add support for migrate on fault
Date: Wed, 02 Dec 2026 04:57:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-244879@kernel.org> (raw)
In-Reply-To: <20261201045531.3622535-15-mpenttil@redhat.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/nouveau/dmem: unserialized shared channel access with TTM
moves
- [High] drm/nouveau/dmem: unpinned DMA-mapped source in
nouveau_dmem_migrate_abort()
- [Medium] drm/nouveau/dmem: self-invalidation on PTE-mapped large folio
split
- [Low] drm/nouveau/svm: missing kernel-parameters.txt entry for
svm_migrate_on_fault
--
commit 07015472583ba355493e1f5be29cf446dab4bad1
Author: Mika Penttilä <mpenttil@redhat.com>
drm/nouveau/svm: add support for migrate on fault
This commit adds migrate-on-fault support for Nouveau SVM using
HMM_PFN_REQ_MIGRATE and nouveau_dmem_migrate_fault(), gated by the
svm_migrate_on_fault module parameter.
> diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c
> index 36c44d3a3c8fe..ecb8397951c1d 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c
> @@ -79,7 +80,7 @@ struct nouveau_dmem_migrate {
> struct nouveau_channel *chan;
> /*
> * Serializes the dmem users of chan (CPU faults in migrate_to_ram(),
> - * bulk migration, eviction): the copy and clear
> + * migrate on fault, bulk migration, eviction): the copy and clear
> * commands they write to its push buffer and the fences they emit.
> * Held only around those writes, never across memory allocation
> * (fences are allocated before taking it).
[Severity: High]
Can nouveau_dmem_migrate_fault() race with TTM buffer moves on the shared
copy channel?
nouveau_dmem_migrate_init() sets drm->dmem->migrate.chan to drm->ttm.chan.
While nouveau_dmem_migrate_fault() serializes its pushbuffer writes and
nouveau_dmem_fence_new() emissions with drm->dmem->migrate.lock,
nouveau_bo_move_m2mf() accesses drm->ttm.chan under cli->mutex without
taking migrate.lock:
kworker (nouveau_svm_fault) TTM move (nouveau_bo_move_m2mf)
nouveau_dmem_migrate_fault() mutex_lock(&cli->mutex)
nouveau_dmem_copy() drm->ttm.move(chan, ...)
mutex_lock(&migrate.lock) nve0_bo_move_copy()
nvc0b5_migrate_copy() PUSH_MTHD(push, NVA0B5, ...)
PUSH_MTHD(push, NVA0B5, ...) nouveau_fence_new(&fence, chan)
mutex_unlock(&migrate.lock) nouveau_fence_emit()
nouveau_dmem_fence_new() ++fctx->sequence
mutex_lock(&migrate.lock)
nouveau_fence_emit()
++fctx->sequence <-- concurrent pushbuffer and sequence corruption
Concurrent GPU fault migrations and TTM moves can corrupt push->cur,
interleave stateful NVA0B5 copy engine methods on the same subchannel, and
race on the unlocked ++fctx->sequence increment in nouveau_fence_emit().
[ ... ]
> @@ -984,6 +1001,262 @@ static void nouveau_dmem_migrate_chunk(struct nouveau_drm *drm,
> migrate_vma_finalize(args);
> }
>
> +/*
> + * Encode an hmm_range_fault() pfn for @start into the nouveau PFNMAP format,
> + * shared by nouveau_hmm_convert_pfn() and the in-place map in
> + * nouveau_dmem_migrate_fault().
> + */
[ ... ]
> + /*Without a fence (fret set) the copy can't be confirmed. */
> + if (migrated && !fret)
> + fret = nouveau_dmem_fence_poll(&fence);
> +
> + /* Commit the migration only once the copy is confirmed. */
> + if (fret)
> + nouveau_dmem_migrate_abort(drm, &migrate);
> + migrate_vma_pages(&migrate);
[ ... ]
> + /* After an aborted copy the engine may still use the mappings */
> + while (!fret && nr_dma--) {
> + dma_unmap_page(drm->dev->dev, dma_info[nr_dma].dma_addr,
> + dma_info[nr_dma].size, DMA_BIDIRECTIONAL);
> + }
> + migrate_vma_finalize(&migrate);
[Severity: High]
When fret is non-zero, does aborting the migration leave the DMA-mapped
source system RAM folio unpinned while the copy engine may still be
reading from it?
Unlike nouveau_dmem_migrate_to_ram() (where args.dst[0] is the DMA-mapped
system RAM page), nouveau_dmem_migrate_copy_one() DMA-maps the source
system RAM page spage (migrate.src[i]) into dma_info->dma_addr. On abort,
nouveau_dmem_migrate_abort() unlocks and zeroes migrate.dst[i] without
pinning migrate.src[i], the loop above skips dma_unmap_page(), and
migrate_vma_finalize() drops the migration reference on migrate.src[i] and
restores its PTE. If the process then unmaps the page or exits (or
reclaim evicts it), the system RAM page can be freed back to the page
allocator while its DMA mapping is still active.
In addition, leaking the unmapped VRAM destination folio in migrate.dst[i]
leaves chunk->callocated and pgmap->ref elevated without any PTE pointing
to it, so nouveau_dmem_evict_chunk() cannot migrate it out during
nouveau_dmem_fini(), triggering WARN_ON(chunk->callocated) and hanging in
memunmap_pages().
> diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c
> index c519c28164fa0..a673952070324 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_svm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c
> @@ -78,6 +79,17 @@ struct nouveau_svm {
> #define SVM_DBG(s,f,a...) NV_DEBUG((s)->drm, "svm: "f"\n", ##a)
> #define SVM_ERR(s,f,a...) NV_WARN((s)->drm, "svm: "f"\n", ##a)
>
> +/*
> + * When set, migrate the faulting range to VRAM on GPU fault (default off).
> + * Like the other nouveau parameters, it is documented by MODULE_PARM_DESC
> + * only, and it matters only with the experimental SVM support.
> + */
> +static bool nouveau_svm_migrate_on_fault;
> +module_param_named(svm_migrate_on_fault, nouveau_svm_migrate_on_fault, bool,
> + 0644);
> +MODULE_PARM_DESC(svm_migrate_on_fault,
> + "migrate system memory to VRAM on GPU fault (default off)");
[Severity: Low]
This adds the nouveau.svm_migrate_on_fault module parameter without an
entry in Documentation/admin-guide/kernel-parameters.txt (or
Documentation/gpu/nouveau.rst); noting this for maintainer awareness since
it is gated by the experimental CONFIG_DRM_NOUVEAU_SVM option.
[ ... ]
> @@ -527,6 +547,17 @@ static bool nouveau_svm_range_invalidate(struct mmu_interval_notifier *mni,
> range->owner == sn->svmm->vmm->cli->drm->dev)
> return true;
>
> + /*
> + * Ignore the invalidation of this fault's own migrate-on-fault walk,
> + * which runs in the walking task; otherwise its MMU_NOTIFY_MIGRATE
> + * bumps the seq and read_retry() spins to timeout. Other migrations
> + * on the device (CPU faults, bind) must still invalidate.
> + */
> + if (range->event == MMU_NOTIFY_MIGRATE &&
> + range->owner == sn->svmm->vmm->cli->drm->dev &&
> + READ_ONCE(sn->migrating) == current)
> + return true;
[Severity: Medium]
Does a migrate-on-fault walk that splits a PTE-mapped large folio
self-invalidate its own mmu_interval_notifier?
When a GPU fault lands on a PTE-mapped large anonymous folio (such as an
mTHP or an already PMD-split THP), hmm_range_fault() splits the folio via
hmm_vma_handle_migrate_prepare() -> hmm_migrate_split_folio() ->
split_folio(), which emits an MMU_NOTIFY_CLEAR invalidation. Because
nouveau_svm_range_invalidate() only ignores MMU_NOTIFY_MIGRATE for
sn->migrating == current, MMU_NOTIFY_CLEAR updates mni->invalidate_seq.
Unlike the PMD split path (which returns -EBUSY so
hmm_range_fault_locked() checks mmu_interval_check_retry() before
collecting), hmm_vma_handle_migrate_prepare() returns HMM_MIGRATE_REWALK
and hmm_vma_walk_pmd() re-walks internally and returns 0 with a stale
range.notifier_seq. nouveau_dmem_migrate_fault() then completes the VRAM
copy, fault replay, fence wait, and migrate_vma_pages(), only for
mmu_interval_read_retry() to fail with -EBUSY, forcing
nouveau_svmm_invalidate() and an unnecessary retry loop iteration.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201045531.3622535-1-mpenttil@redhat.com?part=14
next prev parent reply other threads:[~2026-12-02 4:57 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 4:55 [PATCH v18 00/14] migrate on fault for device pages mpenttil
2026-12-01 4:55 ` [PATCH v18 01/14] mm/Kconfig: changes for " mpenttil
2026-12-01 4:55 ` [PATCH v18 02/14] mm: add helper to convert HMM pfn to migrate pfn mpenttil
2026-12-01 4:55 ` [PATCH v18 03/14] mm/hmm: preparations for HMM to participate in migration mpenttil
2026-12-01 4:55 ` [PATCH v18 04/14] mm/hmm: do the plumbing " mpenttil
2026-12-01 4:55 ` [PATCH v18 05/14] mm/hmm: implement rollback for device page migration in HMM pagewalk mpenttil
2026-12-01 4:55 ` [PATCH v18 06/14] mm/hmm: migrate collection in HMM pagewalk - pte level mpenttil
2026-12-01 4:55 ` [PATCH v18 07/14] mm/hmm: migrate collection in HMM pagewalk - pmd level mpenttil
2026-12-01 4:55 ` [PATCH v18 08/14] mm/hmm: add lazy MMU mode support for migration in HMM pagewalk mpenttil
2026-12-01 4:55 ` [PATCH v18 09/14] mm: enable device page migration from " mpenttil
2026-12-02 4:57 ` sashiko-bot
2026-12-01 4:55 ` [PATCH v18 10/14] lib/test_hmm: add a new testcase for the migrate on fault mpenttil
2026-12-01 4:55 ` [PATCH v18 11/14] Documentation/mm/hmm: document migration through hmm_range_fault() mpenttil
2026-12-01 4:55 ` [PATCH v18 12/14] drm/nouveau/dmem: serialize the copy channel users mpenttil
2026-12-01 4:55 ` [PATCH v18 13/14] drm/nouveau/dmem: commit migrate_to_ram() only after the copy is confirmed mpenttil
2026-12-01 4:55 ` [PATCH v18 14/14] drm/nouveau/svm: add support for migrate on fault mpenttil
2026-12-02 4:57 ` sashiko-bot [this message]
2026-12-01 5:03 ` ✗ CI.checkpatch: warning for Migrate on fault for device pages (rev10) Patchwork
2026-12-01 5:05 ` ✓ CI.KUnit: success " Patchwork
2026-12-01 5:22 ` ✗ CI.checksparse: warning " Patchwork
2026-12-01 5:49 ` ✓ Xe.CI.BAT: success " Patchwork
2026-12-01 17:48 ` ✗ 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=sashiko-outbox-244879@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=balbirs@nvidia.com \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=david@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jgg@nvidia.com \
--cc=leonro@nvidia.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=lyude@redhat.com \
--cc=maddy@linux.ibm.com \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=mpenttil@redhat.com \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shuah@kernel.org \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox