<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Tested-by: Gang BA <Gang.Ba@amd.com></div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Gang BA <Gang.Ba@amd.com></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Kuehling, Felix <Felix.Kuehling@amd.com><br>
<b>Sent:</b> Wednesday, April 17, 2024 11:14 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Ba, Gang <Gang.Ba@amd.com>; Prosyak, Vitaly <Vitaly.Prosyak@amd.com><br>
<b>Subject:</b> [PATCH] drm/amdkfd: Fix eviction fence handling</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Handle case that dma_fence_get_rcu_safe returns NULL.<br>
<br>
If restore work is already scheduled, only update its timer. The same<br>
work item cannot be queued twice, so undo the extra queue eviction.<br>
<br>
Fixes: 9a1c1339abf9 ("drm/amdkfd: Run restore_workers on freezable WQs")<br>
Signed-off-by: Felix Kuehling <felix.kuehling@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 9 +++++----<br>
 1 file changed, 5 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
index b79986412cd8..aafdf064651f 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
@@ -1922,6 +1922,8 @@ static int signal_eviction_fence(struct kfd_process *p)<br>
         rcu_read_lock();<br>
         ef = dma_fence_get_rcu_safe(&p->ef);<br>
         rcu_read_unlock();<br>
+       if (!ef)<br>
+               return -EINVAL;<br>
 <br>
         ret = dma_fence_signal(ef);<br>
         dma_fence_put(ef);<br>
@@ -1949,10 +1951,9 @@ static void evict_process_worker(struct work_struct *work)<br>
                  * they are responsible stopping the queues and scheduling<br>
                  * the restore work.<br>
                  */<br>
-               if (!signal_eviction_fence(p))<br>
-                       queue_delayed_work(kfd_restore_wq, &p->restore_work,<br>
-                               msecs_to_jiffies(PROCESS_RESTORE_TIME_MS));<br>
-               else<br>
+               if (signal_eviction_fence(p) ||<br>
+                   mod_delayed_work(kfd_restore_wq, &p->restore_work,<br>
+                                    msecs_to_jiffies(PROCESS_RESTORE_TIME_MS)))<br>
                         kfd_process_restore_queues(p);<br>
 <br>
                 pr_debug("Finished evicting pasid 0x%x\n", p->pasid);<br>
-- <br>
2.34.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>