<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 1/7/2025 2:44 PM, Philip Yang wrote:<br>
</div>
<blockquote type="cite" cite="mid:64af2e0d-c3ee-9a51-70aa-215bc128a55d@amd.com">
<p><br>
</p>
<div class="moz-cite-prefix">On 2025-01-07 10:50, Chen, Xiaogang
wrote:<br>
</div>
<blockquote type="cite" cite="mid:19fac85c-0110-4a3d-a3ee-c539afd518c5@amd.com">
<p><br>
</p>
<div class="moz-cite-prefix">On 1/6/2025 8:02 PM, Deng, Emily
wrote:<br>
</div>
<blockquote type="cite" cite="mid:PH0PR12MB5417A0CED996D52E33D234B98F112@PH0PR12MB5417.namprd12.prod.outlook.com">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Aptos;}@font-face
{font-family:"\@DengXian";
panose-1:2 1 6 0 3 1 1 1 1 1;}@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
font-size:10.0pt;
font-family:"Courier New";}span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Arial",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}div.WordSection1
{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<p style="font-family:Calibri;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left"> [AMD Official Use Only - AMD Internal
Distribution Only]<br>
</p>
<br>
<div>
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue
1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
Chen, Xiaogang <a class="moz-txt-link-rfc2396E" href="mailto:Xiaogang.Chen@amd.com" moz-do-not-send="true"><Xiaogang.Chen@amd.com></a>
<br>
<b>Sent:</b> Monday, January 6, 2025 11:27 PM<br>
<b>To:</b> Deng, Emily <a class="moz-txt-link-rfc2396E" href="mailto:Emily.Deng@amd.com" moz-do-not-send="true"><Emily.Deng@amd.com></a>;
<a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:amd-gfx@lists.freedesktop.org" moz-do-not-send="true">amd-gfx@lists.freedesktop.org</a><br>
<b>Subject:</b> Re: [PATCH] drm/amdkfd: Fix
partial migrate issue<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 1/2/2025 6:06 PM, Emily Deng
wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>For partial migrate from ram to vram, the migrate->cpages is not<o:p></o:p></pre>
<pre>equal to migrate->npages, should use migrate->npages to check all needed<o:p></o:p></pre>
<pre>migrate pages which could be copied or not.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>And only need to set those pages could be migrated to migrate->dst[i], or<o:p></o:p></pre>
<pre>the migrate_vma_pages will migrate the wrong pages based on the migrate->dst[i].<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Signed-off-by: Emily Deng <a href="mailto:Emily.Deng@amd.com" moz-do-not-send="true"><Emily.Deng@amd.com></a><o:p></o:p></pre>
<pre>---<o:p></o:p></pre>
<pre> drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 8 ++++----<o:p></o:p></pre>
<pre> 1 file changed, 4 insertions(+), 4 deletions(-)<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<o:p></o:p></pre>
<pre>index 4b275937d05e..5c96c2d425e3 100644<o:p></o:p></pre>
<pre>--- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<o:p></o:p></pre>
<pre>+++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c<o:p></o:p></pre>
<pre>@@ -278,7 +278,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,<o:p></o:p></pre>
<pre> struct migrate_vma *migrate, struct dma_fence **mfence,<o:p></o:p></pre>
<pre> dma_addr_t *scratch, uint64_t ttm_res_offset)<o:p></o:p></pre>
<pre> {<o:p></o:p></pre>
<pre>- uint64_t npages = migrate->cpages;<o:p></o:p></pre>
<pre>+ uint64_t npages = migrate->npages;<o:p></o:p></pre>
</blockquote>
<p class="MsoNormal">I agree this part.<br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre> struct amdgpu_device *adev = node->adev;<o:p></o:p></pre>
<pre> struct device *dev = adev->dev;<o:p></o:p></pre>
<pre> struct amdgpu_res_cursor cursor;<o:p></o:p></pre>
<pre>@@ -299,9 +299,6 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,<o:p></o:p></pre>
<pre> struct page *spage;<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<pre> dst[i] = cursor.start + (j << PAGE_SHIFT);<o:p></o:p></pre>
<pre>- migrate->dst[i] = svm_migrate_addr_to_pfn(adev, dst[i]);<o:p></o:p></pre>
<pre>- svm_migrate_get_vram_page(prange, migrate->dst[i]);<o:p></o:p></pre>
<pre>- migrate->dst[i] = migrate_pfn(migrate->dst[i]);<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<pre> spage = migrate_pfn_to_page(migrate->src[i]);<o:p></o:p></pre>
<pre> if (spage && !is_zone_device_page(spage)) {<o:p></o:p></pre>
<pre>@@ -345,6 +342,9 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,<o:p></o:p></pre>
<pre> } else {<o:p></o:p></pre>
<pre> j++;<o:p></o:p></pre>
<pre> }<o:p></o:p></pre>
<pre>+ migrate->dst[i] = svm_migrate_addr_to_pfn(adev, dst[i]);<o:p></o:p></pre>
<pre>+ svm_migrate_get_vram_page(prange, migrate->dst[i]);<o:p></o:p></pre>
<pre>+ migrate->dst[i] = migrate_pfn(migrate->dst[i]);<o:p></o:p></pre>
</blockquote>
<p>I think what current code misses here is that
migrate->dst[i] should match migrate->src[i]:
migrate->dst[i](vram page) got set for page that
will be migrated from system ram, otherwise
migrate->dst[i] should be zero. Your change makes
migrates->dst[i] not set though its page has been
migrated by svm_migrate_copy_memory_gart for the case
that cpages != npages, because you set
migrate->dst[i] at end of loop and use 'continue'
after migration.<o:p></o:p></p>
<p>The page migration happens at
svm_migrate_copy_memory_gart, not migrate_vma_pages
that migrates struct page meta-data from source struct
page to destination struct page and has mmu
notification.<o:p></o:p></p>
<p>Regards<o:p></o:p></p>
<p>Xiaogang<o:p></o:p></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif">The </span>migrate->dst[i]
default value is 0. The purpose of the change is to
match the migrate->dst[i] and migrate->src[i].
And for svm_migrate_copy_to_vram, it only will call
svm_migrate_copy_memory_gart to copy those pages which
need to be migrated, for those don’t need migrate
pages, it won’t call svm_migrate_copy_memory_gart.</p>
</div>
</div>
</div>
</blockquote>
<p>Yes, the issue here is we need match migrate->dst[i] and
migrate->src[i]: migrate->dst[i] need be set only when
its correspondent migrate->src[i] page will be migrated or
the src page has dma address setup by dma_map_page. Then why
not set migrate->dst[i] at same time when have dma_map_page
for src page?</p>
</blockquote>
yes, agree, I will reply the v2 patch with this change.<br>
<blockquote type="cite" cite="mid:19fac85c-0110-4a3d-a3ee-c539afd518c5@amd.com">
<p> That way will simplify the logic and not need use
amdgpu_res_next to jump vram cursor. <br>
</p>
</blockquote>
<p>if spage is not contiguous or dst is the last page of cursor
(vram address is not contiguous), we need setup sdma copy and
then call amdgpu_res_next to update cursor->start.</p>
</blockquote>
<p>I think we only need use amdgpu_res_nex at one place where update
migrate->dst[i] together with dma_map_page for src page, but
need to remember the jump between two dma_map_page to adapt to
cursor->start update.</p>
<p>Regards</p>
<p>Xiaogang<br>
</p>
<blockquote type="cite" cite="mid:64af2e0d-c3ee-9a51-70aa-215bc128a55d@amd.com">
<p>Regards,</p>
<p>Philip<br>
</p>
<blockquote type="cite" cite="mid:19fac85c-0110-4a3d-a3ee-c539afd518c5@amd.com">
<p> </p>
<p>Regards</p>
<p>Xiaogang<br>
</p>
<blockquote type="cite" cite="mid:PH0PR12MB5417A0CED996D52E33D234B98F112@PH0PR12MB5417.namprd12.prod.outlook.com">
<div>
<div class="WordSection1">
<div style="border:none;border-left:solid blue
1.5pt;padding:0in 0in 0in 4.0pt">
<p><o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre> }<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<pre> r = svm_migrate_copy_memory_gart(adev, src + i - j, dst + i - j, j,<o:p></o:p></pre>
</blockquote>
</div>
</div>
</div>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>