All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Xiaogang.Chen <xiaogang.chen@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/2] drm/amdkfd: Swap order of svm_range_dma_unmap_dev and migrate_vma_finalize
Date: Wed, 18 Nov 2026 15:25:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-221316@kernel.org> (raw)
In-Reply-To: <20261118151045.134908-2-xiaogang.chen@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/amdkfd: missing Fixes: trailers for DMA unmap ordering bug
  fix
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] drm/amdkfd: unhandled SDMA fence error in
  svm_migrate_copy_done() [1]
--

commit ccdfb551849cc8856e631a5865cff36ff2c4ceb7
Author: Xiaogang Chen <xiaogang.chen@amd.com>

> drm/amdkfd: Swap order of svm_range_dma_unmap_dev and migrate_vma_finalize
>
> svm_migrate_vma_to_vram() on success: migrate_vma_finalize() releases the old
> system-RAM source pages. Only after that they are DMA-unmapped.
>
> svm_migrate_vma_to_ram() for slots that failed to migrate: finalize frees the
> newly allocated dpages, and the unmap comes afterwards.
>
> Every mapping uses DMA_BIDIRECTIONAL. With swiotlb, that kind of unmap copies
> the bounce buffer back into the original page, and by then the page may belong
> to someone else. With an IOMMU, the IOVA stays valid for a short window after
> the page is freed. During the window GPU may write into the pages that may
> belong to someone else.
>
> So, swap svm_range_dma_unmap_dev and migrate_vma_finalize at both migration
> direction to make dma unmap happen before sys ram pages got released.
>
> Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>

[Severity: Low]
Should this bug fix include Fixes: tags for the commits that introduced
the unmap ordering in both migration directions?

  Fixes: 0b0e518d61af ("drm/amdkfd: HMM migrate ram to vram")
  Fixes: 48ff079b28d8 ("drm/amdkfd: HMM migrate vram to ram")

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> index 481091ae30947..b1e457851a5df 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> @@ -504,14 +504,13 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange,
>  	migrate_vma_pages(&migrate);
>  
>  	svm_migrate_copy_done(adev, mfence);
> +	svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages);
>  	migrate_vma_finalize(&migrate);

[Severity: Critical]
This problem wasn't introduced by this patch, but can
svm_migrate_vma_to_vram() and svm_migrate_vma_to_ram() commit uninitialized
destination pages when the SDMA copy job fails [1]?

drivers/gpu/drm/amd/amdkfd/kfd_migrate.c:svm_migrate_copy_done() {
	if (mfence) {
		r = dma_fence_wait(mfence, false);
		dma_fence_put(mfence);
		pr_debug("sdma copy memory fence done\n");
	}
}

dma_fence_wait() returns 0 whenever the fence signals, even if the SDMA job
aborted with mfence->error set (for example during a GPU reset), and
neither svm_migrate_copy_done() nor its callers inspect the fence error or
return value before migrate_vma_finalize() installs the new page table
entries, exposing stale or uninitialized memory to userspace.

[1] https://sashiko.dev/#/bug/linux-bdb6e388-a490-42f9-a491-9e9b540c6920

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118151045.134908-1-xiaogang.chen@amd.com?part=2

  reply	other threads:[~2026-11-18 15:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 15:10 [PATCH 1/2] drm/amdkfd: Fix a race issue at svm_migrate_copy_to_ram() error path Xiaogang.Chen
2026-11-18 15:10 ` [PATCH 2/2] drm/amdkfd: Swap order of svm_range_dma_unmap_dev and migrate_vma_finalize Xiaogang.Chen
2026-11-18 15:25   ` sashiko-bot [this message]
2026-11-18 17:48   ` Philip Yang
2026-11-18 18:02     ` Chen, Xiaogang
2026-11-18 15:22 ` [PATCH 1/2] drm/amdkfd: Fix a race issue at svm_migrate_copy_to_ram() error path sashiko-bot
2026-11-18 17:43 ` 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-221316@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.