<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 2025-01-07 22:08, Deng, Emily wrote:<br>
</div>
<blockquote type="cite" cite="mid:PH0PR12MB5417561D4BF4379DAFF7CF698F122@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.EmailStyle23
{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">Hi
Philip,<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">It
still has the deadlock, maybe the best way is trying to
remove the delayed free pt work.<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000000>] INFO: task
kfdtest:5827 blocked for more than 122 seconds.<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000290>] Tainted:
G OE K 5.10.134-17.2.al8.x86_64 #1<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000243>] "echo 0 >
/proc/sys/kernel/hung_task_timeout_secs" disables this
message.<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000317>]
task:kfdtest state:D stack: 0 pid: 5827 ppid:
5756 flags:0x00004080<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>] Call Trace:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000006>]
__schedule+0x1ba/0x490<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>] ?
usleep_range+0x90/0x90<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>]
schedule+0x46/0xb0<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000001>]
schedule_timeout+0x12a/0x140<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000003>] ?
__prepare_to_swait+0x4f/0x70<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>]
__wait_for_common+0xb1/0x160<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000004>]
flush_workqueue+0x12f/0x410<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000126>]
svm_range_map_to_gpu+0x1b8/0x730 [amdgpu]<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000078>]
svm_range_validate_and_map+0x978/0xd30 [amdgpu]<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000065>]
svm_range_set_attr+0x55f/0xb20 [amdgpu]<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000060>]
kfd_ioctl+0x208/0x540 [amdgpu]<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000058>] ?
kfd_ioctl_set_xnack_mode+0xd0/0xd0 [amdgpu]<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000004>] ?
vm_mmap_pgoff+0xf2/0x120<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>]
__x64_sys_ioctl+0x88/0xc0<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000003>]
do_syscall_64+0x2e/0x50<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>]
entry_SYSCALL_64_after_hwframe+0x62/0xc7<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000008>] RIP:
0033:0x7f8c472617db<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000001>] RSP:
002b:00007ffd2908a688 EFLAGS: 00000246 ORIG_RAX:
0000000000000010<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>] RAX:
ffffffffffffffda RBX: 00007ffd2908a6fc RCX:
00007f8c472617db<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>] RDX:
00007ffd2908a6c0 RSI: 00000000c0384b20 RDI:
0000000000000003<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000000>] RBP:
00007ffd2908a6c0 R08: 0000000000000000 R09:
0000000000000000<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000001>] R10:
00007f70f467f000 R11: 0000000000000246 R12:
00000000c0384b20<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000000>] R13:
0000000000000003 R14: 0000000000200000 R15:
00007ffd2908a770<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000003>] INFO: task
kworker/u129:7:5942 blocked for more than 122 seconds.<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.001897>] Tainted:
G OE K 5.10.134-17.2.al8.x86_64 #1<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000247>] "echo 0 >
/proc/sys/kernel/hung_task_timeout_secs" disables this
message.<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000315>]
task:kworker/u129:7 state:D stack: 0 pid: 5942
ppid: 2 flags:0x00004080<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000067>] Workqueue:
amdgpu_recycle amdgpu_vm_pt_free_work [amdgpu]<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>] Call Trace:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000003>]
__schedule+0x1ba/0x490<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>] ?
newidle_balance+0x16a/0x3b0<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000001>]
schedule+0x46/0xb0<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>]
schedule_preempt_disabled+0xa/0x10<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000001>]
__ww_mutex_lock.constprop.0+0x390/0x6e0<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000045>]
amdgpu_vm_pt_free_work+0x97/0x160 [amdgpu]<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000003>]
process_one_work+0x1ad/0x380<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000001>]
worker_thread+0x49/0x310<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000001>] ?
process_one_work+0x380/0x380<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000001>]
kthread+0x118/0x140<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:12.0pt"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>] ?
__kthread_bind_mask+0x60/0x60<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Wed
Jan 8 10:35:44 2025 < 0.000002>]
ret_from_fork+0x1f/0x30<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>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
</div>
</blockquote>
<p>Move <span style="font-size:11.0pt;font-family:"Arial",sans-serif">
flush_workqueue to the beginning of svm_range_validate_and_map
should fix the deadlock, deadlock is because it is after
svm_range_reserve_bos. Also there is no concurrent unmap mmu
notifier callback to free pt bo as mmap read lock is taken
outside </span><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">svm_range_validate_and_map</span>.<br>
</span></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif">Ideally
it is enough to flush work </span><span style="font-size:11.0pt;font-family:"Arial",sans-serif">amdgpu_vm_pt_free_work
(not flush queue system_wq), but </span><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">svm_range_validate_and_map
cannot get the correct vm to flush.<br>
</span></span></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif">adev->wq
is shared by all processes and all xcp partitions, maybe better
to add wq to KFD process info, but right now
amdgpu_vm_update_range cannot access KFD process info.</span></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif">Regards,</span></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif">Philip<br>
</span><span style="font-size:11.0pt;font-family:"Arial",sans-serif"></span></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><br>
</span></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif"></span></p>
<blockquote type="cite" cite="mid:PH0PR12MB5417561D4BF4379DAFF7CF698F122@PH0PR12MB5417.namprd12.prod.outlook.com">
<div>
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;mso-ligatures:standardcontextual">Emily
Deng<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-ligatures:standardcontextual">Best
Wishes<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">
amd-gfx
<a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx-bounces@lists.freedesktop.org"><amd-gfx-bounces@lists.freedesktop.org></a>
<b>On Behalf Of </b>Deng, Emily<br>
<b>Sent:</b> Wednesday, January 8, 2025 8:34 AM<br>
<b>To:</b> Yang, Philip <a class="moz-txt-link-rfc2396E" href="mailto:Philip.Yang@amd.com"><Philip.Yang@amd.com></a>;
Kuehling, Felix <a class="moz-txt-link-rfc2396E" href="mailto:Felix.Kuehling@amd.com"><Felix.Kuehling@amd.com></a>;
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>; Koenig, Christian
<a class="moz-txt-link-rfc2396E" href="mailto:Christian.Koenig@amd.com"><Christian.Koenig@amd.com></a><br>
<b>Subject:</b> RE: [PATCH v2] drm/amdgpu: Fix the
looply call svm_range_restore_pages issue<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p style="margin:5.0pt"><span style="font-size:10.0pt;font-family:"Calibri",sans-serif;color:blue">[AMD
Official Use Only - AMD Internal Distribution Only]<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p style="margin:5.0pt"><span style="font-size:10.0pt;font-family:"Calibri",sans-serif;color:blue">[AMD
Official Use Only - AMD Internal Distribution Only]<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<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">
Yang, Philip <<a href="mailto:Philip.Yang@amd.com" moz-do-not-send="true" class="moz-txt-link-freetext">Philip.Yang@amd.com</a>>
<br>
<b>Sent:</b> Tuesday, January 7, 2025 11:19 PM<br>
<b>To:</b> Deng, Emily <<a href="mailto:Emily.Deng@amd.com" moz-do-not-send="true" class="moz-txt-link-freetext">Emily.Deng@amd.com</a>>;
Kuehling, Felix <<a href="mailto:Felix.Kuehling@amd.com" moz-do-not-send="true" class="moz-txt-link-freetext">Felix.Kuehling@amd.com</a>>;
<a href="mailto:amd-gfx@lists.freedesktop.org" moz-do-not-send="true" class="moz-txt-link-freetext">amd-gfx@lists.freedesktop.org</a>;
Yang, Philip <<a href="mailto:Philip.Yang@amd.com" moz-do-not-send="true" class="moz-txt-link-freetext">Philip.Yang@amd.com</a>>;
Koenig, Christian <<a href="mailto:Christian.Koenig@amd.com" moz-do-not-send="true" class="moz-txt-link-freetext">Christian.Koenig@amd.com</a>><br>
<b>Subject:</b> Re: [PATCH v2] drm/amdgpu: Fix
the looply call svm_range_restore_pages 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 2025-01-07 07:30, Deng,
Emily wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>[AMD Official Use Only - AMD Internal Distribution Only]<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Hi Felix,<o:p></o:p></pre>
<pre> You are right, it is easily to hit deadlock, don't know why LOCKDEP doesn't catch this. Need to find another solution.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Hi Philip,<o:p></o:p></pre>
<pre> Do you have a solution for this delay free pt?<o:p></o:p></pre>
</blockquote>
<p>Thanks for debugging this case, I had a patch to
not free PTB bo when unmapping from GPU, but it will
waste VRAM memory. My test case also passed with the
tlb flush fence fix, I don't see the no-retry fault
generated any more.<o:p></o:p></p>
<p>The deadlock is probably from
svm_range_unmap_from_gpu ->
flush_workqueue(adev->wq), this is from mmu
notifier callback, actually we only need flush
pt_free_work before mapping to gpu, please remove
the flush_workqueue in unmap from gpu. If deadlock
still happens, please post the backtrace.<o:p></o:p></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Emily]Yes,
you are right, will try to remove
</span>flush_workqueue in unmap from gpu to have a
try. Will send a v3.<span style="font-size:11.0pt;font-family:"Arial",sans-serif"><o:p></o:p></span></p>
<p>I think you don't need add new adev->wq, use
default system_wq and flush_work.<o:p></o:p></p>
<p><span style="font-size:11.0pt;font-family:"Arial",sans-serif">[Emily]No,
it doesn’t allow to flush a system_wq in driver,
it will trigger a kernel warning, as lots of other
work will be put in system_wq. I have tried this.<o:p></o:p></span></p>
<p>Regards,<o:p></o:p></p>
<p>Philip<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>Emily Deng<o:p></o:p></pre>
<pre>Best Wishes<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>-----Original Message-----<o:p></o:p></pre>
<pre>From: Deng, Emily <a href="mailto:Emily.Deng@amd.com" moz-do-not-send="true"><Emily.Deng@amd.com></a><o:p></o:p></pre>
<pre>Sent: Tuesday, January 7, 2025 10:34 AM<o:p></o:p></pre>
<pre>To: Deng, Emily <a href="mailto:Emily.Deng@amd.com" moz-do-not-send="true"><Emily.Deng@amd.com></a>; Kuehling, Felix<o:p></o:p></pre>
<pre><a href="mailto:Felix.Kuehling@amd.com" moz-do-not-send="true"><Felix.Kuehling@amd.com></a>; <a href="mailto:amd-gfx@lists.freedesktop.org" moz-do-not-send="true" class="moz-txt-link-freetext">amd-gfx@lists.freedesktop.org</a>; Yang, Philip<o:p></o:p></pre>
<pre><a href="mailto:Philip.Yang@amd.com" moz-do-not-send="true"><Philip.Yang@amd.com></a>; Koenig, Christian <a href="mailto:Christian.Koenig@amd.com" moz-do-not-send="true"><Christian.Koenig@amd.com></a><o:p></o:p></pre>
<pre>Subject: RE: [PATCH v2] drm/amdgpu: Fix the looply call svm_range_restore_pages<o:p></o:p></pre>
<pre>issue<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>[AMD Official Use Only - AMD Internal Distribution Only]<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Ping....<o:p></o:p></pre>
<pre>How about this? Currently it is easily to reproduce the issue on our environment. We<o:p></o:p></pre>
<pre>need this change to fix it.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Emily Deng<o:p></o:p></pre>
<pre>Best Wishes<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre><o:p> </o:p></pre>
<pre><o:p> </o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>-----Original Message-----<o:p></o:p></pre>
<pre>From: amd-gfx <a href="mailto:amd-gfx-bounces@lists.freedesktop.org" moz-do-not-send="true"><amd-gfx-bounces@lists.freedesktop.org></a> On Behalf Of<o:p></o:p></pre>
<pre>Deng, Emily<o:p></o:p></pre>
<pre>Sent: Monday, January 6, 2025 9:52 AM<o:p></o:p></pre>
<pre>To: Kuehling, Felix <a href="mailto:Felix.Kuehling@amd.com" moz-do-not-send="true"><Felix.Kuehling@amd.com></a>;<o:p></o:p></pre>
<pre><a href="mailto:amd-gfx@lists.freedesktop.org" moz-do-not-send="true" class="moz-txt-link-freetext">amd-gfx@lists.freedesktop.org</a>; Yang, Philip <a href="mailto:Philip.Yang@amd.com" moz-do-not-send="true"><Philip.Yang@amd.com></a>;<o:p></o:p></pre>
<pre>Koenig, Christian <a href="mailto:Christian.Koenig@amd.com" moz-do-not-send="true"><Christian.Koenig@amd.com></a><o:p></o:p></pre>
<pre>Subject: RE: [PATCH v2] drm/amdgpu: Fix the looply call<o:p></o:p></pre>
<pre>svm_range_restore_pages issue<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>[AMD Official Use Only - AMD Internal Distribution Only]<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>[AMD Official Use Only - AMD Internal Distribution Only]<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>-----Original Message-----<o:p></o:p></pre>
<pre>From: Kuehling, Felix <a href="mailto:Felix.Kuehling@amd.com" moz-do-not-send="true"><Felix.Kuehling@amd.com></a><o:p></o:p></pre>
<pre>Sent: Saturday, January 4, 2025 7:18 AM<o:p></o:p></pre>
<pre>To: Deng, Emily <a href="mailto:Emily.Deng@amd.com" moz-do-not-send="true"><Emily.Deng@amd.com></a>; <a href="mailto:amd-gfx@lists.freedesktop.org" moz-do-not-send="true" class="moz-txt-link-freetext">amd-gfx@lists.freedesktop.org</a>;<o:p></o:p></pre>
<pre>Yang, Philip <a href="mailto:Philip.Yang@amd.com" moz-do-not-send="true"><Philip.Yang@amd.com></a>; Koenig, Christian<o:p></o:p></pre>
<pre><a href="mailto:Christian.Koenig@amd.com" moz-do-not-send="true"><Christian.Koenig@amd.com></a><o:p></o:p></pre>
<pre>Subject: Re: [PATCH v2] drm/amdgpu: Fix the looply call<o:p></o:p></pre>
<pre>svm_range_restore_pages issue<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre><o:p> </o:p></pre>
<pre>On 2025-01-02 21:26, Emily Deng wrote:<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>As the delayed free pt, the wanted freed bo has been reused which<o:p></o:p></pre>
<pre>will cause unexpected page fault, and then call svm_range_restore_pages.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Detail as below:<o:p></o:p></pre>
<pre>1.It wants to free the pt in follow code, but it is not freed<o:p></o:p></pre>
<pre>immediately and used “schedule_work(&vm->pt_free_work);”.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>[ 92.276838] Call Trace:<o:p></o:p></pre>
<pre>[ 92.276841] dump_stack+0x63/0xa0<o:p></o:p></pre>
<pre>[ 92.276887] amdgpu_vm_pt_free_list+0xfb/0x120 [amdgpu]<o:p></o:p></pre>
<pre>[ 92.276932] amdgpu_vm_update_range+0x69c/0x8e0 [amdgpu]<o:p></o:p></pre>
<pre>[ 92.276990] svm_range_unmap_from_gpus+0x112/0x310 [amdgpu]<o:p></o:p></pre>
<pre>[ 92.277046] svm_range_cpu_invalidate_pagetables+0x725/0x780 [amdgpu]<o:p></o:p></pre>
<pre>[ 92.277050] ? __alloc_pages_nodemask+0x19f/0x3e0<o:p></o:p></pre>
<pre>[ 92.277051] mn_itree_invalidate+0x72/0xc0<o:p></o:p></pre>
<pre>[ 92.277052] __mmu_notifier_invalidate_range_start+0x48/0x60<o:p></o:p></pre>
<pre>[ 92.277054] migrate_vma_collect+0xf6/0x100<o:p></o:p></pre>
<pre>[ 92.277055] migrate_vma_setup+0xcf/0x120<o:p></o:p></pre>
<pre>[ 92.277109] svm_migrate_ram_to_vram+0x256/0x6b0 [amdgpu]<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>2.Call svm_range_map_to_gpu->amdgpu_vm_update_range to update the<o:p></o:p></pre>
<pre>page table, at this time it will use the same entry bo which is the<o:p></o:p></pre>
<pre>want free bo in step1.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>3.Then it executes the pt_free_work to free the bo. At this time,<o:p></o:p></pre>
<pre>the GPU access memory will cause page fault as pt bo has been freed.<o:p></o:p></pre>
<pre>And then it will call svm_range_restore_pages again.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>How to fix?<o:p></o:p></pre>
<pre>Add a workqueue, and flush the workqueue each time before updating page<o:p></o:p></pre>
</blockquote>
</blockquote>
</blockquote>
<pre>table.<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>I think this is kind of a known issue in the GPUVM code. Philip was<o:p></o:p></pre>
<pre>looking at it before.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Just flushing a workqueue may seem like a simple and elegant solution,<o:p></o:p></pre>
<pre>but I'm afraid it introduces lock dependency issues. By flushing the<o:p></o:p></pre>
<pre>workqueue, you're effectively creating a lock dependency of the MMU<o:p></o:p></pre>
<pre>notifier on any locks held inside the worker function. You now get a<o:p></o:p></pre>
<pre>circular lock dependency with any of those locks and memory reclaim. I<o:p></o:p></pre>
<pre>think LOCKDEP would be able to catch that if you compile your kernel<o:p></o:p></pre>
<pre>with that<o:p></o:p></pre>
</blockquote>
<pre>feature enabled.<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>The proper solution is to prevent delayed freeing of page tables if<o:p></o:p></pre>
<pre>they happened to get reused, or prevent reuse of page tables if they<o:p></o:p></pre>
<pre>are flagged for<o:p></o:p></pre>
</blockquote>
<pre>delayed freeing.<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<pre>Regards,<o:p></o:p></pre>
<pre> Felix<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
</blockquote>
<pre>Thanks, already enabled LOCKDEP while compiling the kernel. The delay<o:p></o:p></pre>
<pre>work seems for other reasons, I am not sure whether it could be deleted completely.<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Emily Deng<o:p></o:p></pre>
<pre>Best Wishes<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><o:p> </o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<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/amdgpu/amdgpu.h | 1 +<o:p></o:p></pre>
<pre> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 1 +<o:p></o:p></pre>
<pre> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++--<o:p></o:p></pre>
<pre> drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 6 +++++-<o:p></o:p></pre>
<pre> drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 3 +++<o:p></o:p></pre>
<pre> 5 files changed, 15 insertions(+), 3 deletions(-)<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<o:p></o:p></pre>
<pre>b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<o:p></o:p></pre>
<pre>index 93c352b08969..cbf68ad1c8d0 100644<o:p></o:p></pre>
<pre>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<o:p></o:p></pre>
<pre>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<o:p></o:p></pre>
<pre>@@ -1188,6 +1188,7 @@ struct amdgpu_device {<o:p></o:p></pre>
<pre> struct mutex enforce_isolation_mutex;<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> struct amdgpu_init_level *init_lvl;<o:p></o:p></pre>
<pre>+ struct workqueue_struct *wq;<o:p></o:p></pre>
<pre> };<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> static inline uint32_t amdgpu_ip_version(const struct<o:p></o:p></pre>
<pre>amdgpu_device *adev, diff --git<o:p></o:p></pre>
<pre>a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<o:p></o:p></pre>
<pre>b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<o:p></o:p></pre>
<pre>index f30548f4c3b3..5b4835bc81b3 100644<o:p></o:p></pre>
<pre>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<o:p></o:p></pre>
<pre>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<o:p></o:p></pre>
<pre>@@ -2069,6 +2069,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(<o:p></o:p></pre>
<pre> if (ret)<o:p></o:p></pre>
<pre> goto out;<o:p></o:p></pre>
<pre> }<o:p></o:p></pre>
<pre>+ flush_workqueue(adev->wq);<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> ret = reserve_bo_and_vm(mem, avm, &ctx);<o:p></o:p></pre>
<pre> if (unlikely(ret))<o:p></o:p></pre>
<pre>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<o:p></o:p></pre>
<pre>b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<o:p></o:p></pre>
<pre>index 9d6ffe38b48a..500d97cd9114 100644<o:p></o:p></pre>
<pre>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<o:p></o:p></pre>
<pre>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<o:p></o:p></pre>
<pre>@@ -2607,7 +2607,7 @@ void amdgpu_vm_fini(struct amdgpu_device<o:p></o:p></pre>
<pre>*adev,<o:p></o:p></pre>
</blockquote>
<pre>struct amdgpu_vm *vm)<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre> amdgpu_amdkfd_gpuvm_destroy_cb(adev, vm);<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> flush_work(&vm->pt_free_work);<o:p></o:p></pre>
<pre>-<o:p></o:p></pre>
<pre>+ cancel_work_sync(&vm->pt_free_work);<o:p></o:p></pre>
<pre> root = amdgpu_bo_ref(vm->root.bo);<o:p></o:p></pre>
<pre> amdgpu_bo_reserve(root, true);<o:p></o:p></pre>
<pre> amdgpu_vm_put_task_info(vm->task_info);<o:p></o:p></pre>
<pre>@@ -2708,6 +2708,8 @@ void amdgpu_vm_manager_init(struct<o:p></o:p></pre>
<pre>amdgpu_device<o:p></o:p></pre>
</blockquote>
<pre>*adev)<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre> #endif<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> xa_init_flags(&adev->vm_manager.pasids, XA_FLAGS_LOCK_IRQ);<o:p></o:p></pre>
<pre>+ adev->wq = alloc_workqueue("amdgpu_recycle",<o:p></o:p></pre>
<pre>+ WQ_MEM_RECLAIM | WQ_HIGHPRI |<o:p></o:p></pre>
</blockquote>
<pre>WQ_UNBOUND, 16);<o:p></o:p></pre>
<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>@@ -2721,7 +2723,8 @@ void amdgpu_vm_manager_fini(struct<o:p></o:p></pre>
<pre>amdgpu_device<o:p></o:p></pre>
</blockquote>
<pre>*adev)<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre> {<o:p></o:p></pre>
<pre> WARN_ON(!xa_empty(&adev->vm_manager.pasids));<o:p></o:p></pre>
<pre> xa_destroy(&adev->vm_manager.pasids);<o:p></o:p></pre>
<pre>-<o:p></o:p></pre>
<pre>+ flush_workqueue(adev->wq);<o:p></o:p></pre>
<pre>+ destroy_workqueue(adev->wq);<o:p></o:p></pre>
<pre> amdgpu_vmid_mgr_fini(adev);<o:p></o:p></pre>
<pre> }<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c<o:p></o:p></pre>
<pre>b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c<o:p></o:p></pre>
<pre>index f78a0434a48f..1204406215ee 100644<o:p></o:p></pre>
<pre>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c<o:p></o:p></pre>
<pre>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c<o:p></o:p></pre>
<pre>@@ -554,15 +554,19 @@ void amdgpu_vm_pt_free_work(struct work_struct<o:p></o:p></pre>
<pre>*work)<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> vm = container_of(work, struct amdgpu_vm, pt_free_work);<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>+ printk("Emily:%s\n", __func__);<o:p></o:p></pre>
<pre> spin_lock(&vm->status_lock);<o:p></o:p></pre>
<pre> list_splice_init(&vm->pt_freed, &pt_freed);<o:p></o:p></pre>
<pre> spin_unlock(&vm->status_lock);<o:p></o:p></pre>
<pre>+ printk("Emily:%s 1\n", __func__);<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> /* flush_work in amdgpu_vm_fini ensure vm->root.bo is valid. */<o:p></o:p></pre>
<pre> amdgpu_bo_reserve(vm->root.bo, true);<o:p></o:p></pre>
<pre>+ printk("Emily:%s 2\n", __func__);<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> list_for_each_entry_safe(entry, next, &pt_freed, vm_status)<o:p></o:p></pre>
<pre> amdgpu_vm_pt_free(entry);<o:p></o:p></pre>
<pre>+ printk("Emily:%s 3\n", __func__);<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> amdgpu_bo_unreserve(vm->root.bo);<o:p></o:p></pre>
<pre> }<o:p></o:p></pre>
<pre>@@ -589,7 +593,7 @@ void amdgpu_vm_pt_free_list(struct amdgpu_device<o:p></o:p></pre>
</blockquote>
<pre>*adev,<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre> spin_lock(&vm->status_lock);<o:p></o:p></pre>
<pre> list_splice_init(¶ms->tlb_flush_waitlist, &vm->pt_freed);<o:p></o:p></pre>
<pre> spin_unlock(&vm->status_lock);<o:p></o:p></pre>
<pre>- schedule_work(&vm->pt_free_work);<o:p></o:p></pre>
<pre>+ queue_work(adev->wq, &vm->pt_free_work);<o:p></o:p></pre>
<pre> return;<o:p></o:p></pre>
<pre> }<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<o:p></o:p></pre>
<pre>b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<o:p></o:p></pre>
<pre>index 3e2911895c74..55edf96d5a95 100644<o:p></o:p></pre>
<pre>--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<o:p></o:p></pre>
<pre>+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<o:p></o:p></pre>
<pre>@@ -1314,6 +1314,7 @@ svm_range_unmap_from_gpu(struct amdgpu_device<o:p></o:p></pre>
</blockquote>
<pre>*adev, struct amdgpu_vm *vm,<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre> uint64_t init_pte_value = 0;<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> pr_debug("[0x%llx 0x%llx]\n", start, last);<o:p></o:p></pre>
<pre>+ flush_workqueue(adev->wq);<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre> return amdgpu_vm_update_range(adev, vm, false, true, true,<o:p></o:p></pre>
<pre>false, NULL,<o:p></o:p></pre>
</blockquote>
<pre>start,<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre> last, init_pte_value, 0, 0, NULL,<o:p></o:p></pre>
<pre>NULL, @@ -1422,6<o:p></o:p></pre>
</blockquote>
<pre>+1423,8<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre>@@ svm_range_map_to_gpu(struct kfd_process_device *pdd, struct<o:p></o:p></pre>
<pre>svm_range<o:p></o:p></pre>
</blockquote>
<pre>*prange,<o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre> * different memory partition based on fpfn/lpfn, we should use<o:p></o:p></pre>
<pre> * same vm_manager.vram_base_offset regardless memory partition.<o:p></o:p></pre>
<pre> */<o:p></o:p></pre>
<pre>+ flush_workqueue(adev->wq);<o:p></o:p></pre>
<pre>+<o:p></o:p></pre>
<pre> r = amdgpu_vm_update_range(adev, vm, false, false, flush_tlb, true,<o:p></o:p></pre>
<pre> NULL, last_start, prange->start + i,<o:p></o:p></pre>
<pre> pte_flags,<o:p></o:p></pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre><o:p> </o:p></pre>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</body>
</html>