From: "Chen, Xiaogang" <xiaogang.chen@amd.com>
To: Philip Yang <yangp@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 12:02:10 -0600 [thread overview]
Message-ID: <46f92a74-e83b-4025-98d1-d94f1678a418@amd.com> (raw)
In-Reply-To: <3adb82f7-7e82-4695-bbb3-4adc95787a11@amd.com>
On 11/18/2026 11:48 AM, Philip Yang wrote:
>
>
> On 2026-11-18 10:10, Xiaogang.Chen wrote:
>> From: Xiaogang Chen<xiaogang.chen@amd.com>
>>
>> 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>
>> ---
>> drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 6 ++----
>> 1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
>> b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
>> index 78a2aab81c17..4bcdedd91d2e 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
>> @@ -494,14 +494,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);
>> mpages = svm_migrate_successful_pages(&migrate);
>> pr_debug("migrated/collected/requested 0x%lx/0x%lx/0x%lx\n",
>> mpages, cpages, migrate.npages);
>> - svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages);
>> -
>> out_free:
>> kvfree(buf);
>> kfd_smi_event_migration_end(node, p->lead_thread,
>> @@ -838,9 +837,8 @@ svm_migrate_vma_to_ram(struct kfd_node *node,
>> struct svm_range *prange,
>> mpages, cpages, migrate.npages);
>> svm_migrate_copy_done(adev, mfence);
>> - migrate_vma_finalize(&migrate);
>> -
>> svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages);
>> + migrate_vma_finalize(&migrate);
> With the suggested change in patch 1, this will be
>
> if (!r) {
> svm_migrate_copy_done(adev, mfence);
> svm_range_dma_unmap_dev(adev->dev, scratch, 0, npages);
> }
>
It is sys->vram path. There is no dma_wait at error path.
Regards
Xiaogang
> migrate_vma_finalize(&migrate);
>
> Regards,
> Philip
>> out_free:
>> kvfree(buf);
>
next prev parent reply other threads:[~2026-11-18 18:02 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 [this message]
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=46f92a74-e83b-4025-98d1-d94f1678a418@amd.com \
--to=xiaogang.chen@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=yangp@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.