All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gregory Price (Meta)" <gourry@gourry.net>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/nouveau/dmem: free migration arrays on early fault returns
Date: Fri, 13 Nov 2026 20:35:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-213653@kernel.org> (raw)
In-Reply-To: <20261113195436.2659094-1-gourry@gourry.net>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] drm/nouveau/dmem: uncopied folio mapped on error in
  nouveau_dmem_migrate_to_ram() [1]
--

commit 33edd5aee5de0eaebe288aeb01245d89558426c2
Author: Gregory Price (Meta) <gourry@gourry.net>

drm/nouveau/dmem: free migration arrays on early fault returns

This commit fixes memory leaks of the source and destination PFN arrays in
nouveau_dmem_migrate_to_ram() when migrate_vma_setup() fails or finds no
pages to migrate.

> diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c
> index eacac80558344..ae98e177a240b 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c
> @@ -233,10 +233,12 @@ static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm_fault *vmf)
>  	 * than just one page on CPU fault. When such fault happens it is very
>  	 * likely that more surrounding page will CPU fault too.
>  	 */
> -	if (migrate_vma_setup(&args) < 0)
> -		return VM_FAULT_SIGBUS;
> +	if (migrate_vma_setup(&args) < 0) {
> +		ret = VM_FAULT_SIGBUS;
> +		goto err;
> +	}
>  	if (!args.cpages)
> -		return 0;
> +		goto err;
>  
>  	if (order)
>  		dpage = folio_page(vma_alloc_folio(GFP_HIGHUSER | __GFP_ZERO,

[Severity: Critical]
This problem wasn't introduced by this patch, but if
nouveau_dmem_copy_folio() fails later in nouveau_dmem_migrate_to_ram()
[1], does jumping to done cause migrate_vma_finalize() to map the
uncopied destination folio into the process page tables?

drivers/gpu/drm/nouveau/nouveau_dmem.c:nouveau_dmem_migrate_to_ram() {
	...
	args.dst[0] = migrate_pfn(page_to_pfn(dpage));
	if (order)
		args.dst[0] |= MIGRATE_PFN_COMPOUND;
	dfolio = page_folio(dpage);

	svmm = folio_zone_device_data(sfolio);
	mutex_lock(&svmm->mutex);
	nouveau_svmm_invalidate(svmm, args.start, args.end);
	err = nouveau_dmem_copy_folio(drm, sfolio, dfolio, &dma_info);
	mutex_unlock(&svmm->mutex);
	if (err) {
		ret = VM_FAULT_SIGBUS;
		goto done;
	}

	nouveau_fence_new(&fence, dmem->migrate.chan);
	migrate_vma_pages(&args);
	...
done:
	migrate_vma_finalize(&args);
}

Because args.src[0] still has MIGRATE_PFN_MIGRATE set and args.dst[0]
holds a valid PFN, migrate_vma_finalize() -> __migrate_device_finalize()
treats the aborted migration as successful even though migrate_vma_pages()
never ran.  It installs the zeroed destination folio without initialized
mapping or rmap state and frees the source VRAM folio, corrupting
userspace memory and mm invariants when the folio is later unmapped or
reclaimed.

[1] https://sashiko.dev/#/bug/linux-1d44e729-3bbd-4dee-aa29-0b3e8aaa45ea

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113195436.2659094-1-gourry@gourry.net?part=1

      reply	other threads:[~2026-11-13 20:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 19:54 [PATCH] drm/nouveau/dmem: free migration arrays on early fault returns Gregory Price (Meta)
2026-11-13 20:35 ` sashiko-bot [this message]

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-213653@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gourry@gourry.net \
    --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.