From: sashiko-bot@kernel.org
To: Xiaogang.Chen <xiaogang.chen@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/amdkfd: Fix a race issue at svm_migrate_copy_to_ram() error path
Date: Wed, 18 Nov 2026 15:22:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-221313@kernel.org> (raw)
In-Reply-To: <20261118151045.134908-1-xiaogang.chen@amd.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] drm/amdkfd: redundant DMA unmap in svm_migrate_copy_to_ram()
error path
- [Low] drm/amdkfd: missing Fixes trailer on svm_migrate_copy_to_ram()
fix
--
commit 04e6170d8b5365de5f3b17fda44a17daca9153e9
Author: Xiaogang Chen <xiaogang.chen@amd.com>
> drm/amdkfd: Fix a race issue at svm_migrate_copy_to_ram() error path
>
> The destination pages were freed while SDMA copies queued earlier
> could still be writing into them, and while they were still DMA
> mapped. The mappings were only removed later by the caller's
> svm_range_dma_unmap_dev().
>
> With swiotlb, the BIDIRECTIONAL unmap copies the bounce buffer back into
> a page that may already be reused.
>
> With an IOMM, the GPU still has a valid bus address that points at a page
> now maybe owned by another user. Any SDMA write still in flight, corrupts
> that page.
>
> So, wait on the fence first, then dma unmap before release buffer.
>
> svm_range_dma_unmap_dev() sets each entry to 0 after unmapping it,
> so the caller's later svm_range_dma_unmap_dev call skips them.
>
> Not drop the fence there. *mfence still belongs to the caller. Later
> svm_migrate_copy_done() puts it and second wait there returns immediately.
>
> Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
[Severity: Low]
Should this bug fix include Fixes tags for the commits that introduced and
updated the error cleanup path in svm_migrate_copy_to_ram()?
Fixes: 48ff079b28d8 ("drm/amdkfd: HMM migrate vram to ram")
Fixes: 960c4a8069bf ("drm/amdkfd: Fix error path at svm_migrate_copy_to_ram")
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> index 1eb92ac6eb058..481091ae30947 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> @@ -726,6 +726,18 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange,
> put_page(dpage);
> }
>
> + /*
> + * Copies queued before the failure may still be writing into
> + * the destination pages. Wait for the last SDMA fence (copies
> + * on the entity complete in order), then remove the device DMA
> + * mappings, before the pages go back to the allocator. The
> + * caller's svm_migrate_copy_done() still puts the fence, and
> + * its svm_range_dma_unmap_dev() skips the entries zeroed here.
> + */
> + if (*mfence)
> + dma_fence_wait(*mfence, false);
> + svm_range_dma_unmap_dev(dev, dst, 0, npages);
> +
> /* release previous allocated sys pages and unmap dma address */
> while (i--) {
[Severity: Low]
This isn't a bug, but commit 960c4a8069bf ("drm/amdkfd: Fix error path at
svm_migrate_copy_to_ram") already added dma_unmap_page() and zeroed dst[i]
inside the while (i--) loop right below this:
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c:svm_migrate_copy_to_ram() {
...
while (i--) {
if (dst[i]) {
dma_unmap_page(dev, dst[i], PAGE_SIZE,
DMA_BIDIRECTIONAL);
dst[i] = 0;
}
...
}
Because dst is zero-initialized and dst[i] is cleared on dma_map_page()
failure before jumping to out_oom, only entries below i hold mappings.
Calling svm_range_dma_unmap_dev(dev, dst, 0, npages) beforehand unmaps and
zeroes all of dst[], leaving the dma_unmap_page() block in the while (i--)
loop dead code, and the commit message's statement that mappings were only
removed later by the caller's svm_range_dma_unmap_dev() no longer matches
the code.
Wait on *mfence before the while (i--) loop and either drop the new
svm_range_dma_unmap_dev() call or remove the duplicate dma_unmap_page()
block inside the loop.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118151045.134908-1-xiaogang.chen@amd.com?part=1
next prev parent reply other threads:[~2026-11-18 15:22 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
2026-11-18 17:48 ` Philip Yang
2026-11-18 18:02 ` Chen, Xiaogang
2026-11-18 15:22 ` sashiko-bot [this message]
2026-11-18 17:43 ` [PATCH 1/2] drm/amdkfd: Fix a race issue at svm_migrate_copy_to_ram() error path 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-221313@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.