From: Xiaogang Chen <[email protected]> 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. Signed-off-by: Xiaogang Chen <[email protected]> --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index 8b96e1fe741a..9254d64588f0 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -716,6 +716,17 @@ 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. + */ + if (*mfence) { + dma_fence_wait(*mfence, false); + dma_fence_put(*mfence); + } + /* release previous allocated sys pages and unmap dma address */ while (i--) { @@ -824,11 +835,12 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange, mpages = svm_migrate_successful_pages(&migrate); pr_debug("migrated/collected/requested 0x%lx/0x%lx/0x%lx\n", mpages, cpages, migrate.npages); - - svm_migrate_copy_done(adev, mfence); + if (!r) + svm_migrate_copy_done(adev, mfence); migrate_vma_finalize(&migrate); - svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages); + if (!r) + svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages); out_free: kvfree(buf); -- 2.34.1
