All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/amdkfd: Fix a race issue at svm_migrate_copy_to_ram() error path
@ 2026-11-18 15:10 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
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Xiaogang.Chen @ 2026-11-18 15:10 UTC (permalink / raw)
  To: amd-gfx; +Cc: Xiaogang Chen

From: Xiaogang Chen <xiaogang.chen@amd.com>

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>
---
 drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
index 8b96e1fe741a..78a2aab81c17 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
@@ -716,6 +716,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--) {
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-18 18:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [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

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.