<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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:11pt;color:#0078D7;margin:5pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Wednesday, October 28, 2020 9:49 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> [PATCH] drm/amdgpu: cleanup gmc_v9_0_process_interrupt</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">First of all don't snprintf into a char buffer allocated on the stack with<br>
a constant hubname.<br>
<br>
Then cleanup to exit the function early in case of a ratelimit or SRIOV.<br>
<br>
Signed-off-by: Christian König <christian.koenig@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 183 +++++++++++++-------------<br>
 1 file changed, 91 insertions(+), 92 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
index a9929d1b6b3d..0c3421d587e8 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
@@ -510,15 +510,16 @@ static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,<br>
 }<br>
 <br>
 static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,<br>
-                               struct amdgpu_irq_src *source,<br>
-                               struct amdgpu_iv_entry *entry)<br>
+                                     struct amdgpu_irq_src *source,<br>
+                                     struct amdgpu_iv_entry *entry)<br>
 {<br>
-       struct amdgpu_vmhub *hub;<br>
         bool retry_fault = !!(entry->src_data[1] & 0x80);<br>
         uint32_t status = 0, cid = 0, rw = 0;<br>
-       u64 addr;<br>
-       char hub_name[10];<br>
+       struct amdgpu_task_info task_info;<br>
+       struct amdgpu_vmhub *hub;<br>
         const char *mmhub_cid;<br>
+       const char *hub_name;<br>
+       u64 addr;<br>
 <br>
         addr = (u64)entry->src_data[0] << 12;<br>
         addr |= ((u64)entry->src_data[1] & 0xf) << 44;<br>
@@ -527,105 +528,103 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,<br>
                                                     entry->timestamp))<br>
                 return 1; /* This also prevents sending it to KFD */<br>
 <br>
+       /* If it's the first fault for this address, process it normally */<br>
+       if (retry_fault && !in_interrupt() &&<br>
+           amdgpu_vm_handle_fault(adev, entry->pasid, addr))<br>
+               return 1; /* This also prevents sending it to KFD */<br>
+<br>
+       if (!printk_ratelimit())<br>
+               return 0;<br>
+<br>
         if (entry->client_id == SOC15_IH_CLIENTID_VMC) {<br>
-               snprintf(hub_name, sizeof(hub_name), "mmhub0");<br>
+               hub_name = "mmhub0";<br>
                 hub = &adev->vmhub[AMDGPU_MMHUB_0];<br>
         } else if (entry->client_id == SOC15_IH_CLIENTID_VMC1) {<br>
-               snprintf(hub_name, sizeof(hub_name), "mmhub1");<br>
+               hub_name = "mmhub1";<br>
                 hub = &adev->vmhub[AMDGPU_MMHUB_1];<br>
         } else {<br>
-               snprintf(hub_name, sizeof(hub_name), "gfxhub0");<br>
+               hub_name = "gfxhub0";<br>
                 hub = &adev->vmhub[AMDGPU_GFXHUB_0];<br>
         }<br>
 <br>
-       /* If it's the first fault for this address, process it normally */<br>
-       if (retry_fault && !in_interrupt() &&<br>
-           amdgpu_vm_handle_fault(adev, entry->pasid, addr))<br>
-               return 1; /* This also prevents sending it to KFD */<br>
+       memset(&task_info, 0, sizeof(struct amdgpu_task_info));<br>
+       amdgpu_vm_get_task_info(adev, entry->pasid, &task_info);<br>
 <br>
-       if (!amdgpu_sriov_vf(adev)) {<br>
-               /*<br>
-                * Issue a dummy read to wait for the status register to<br>
-                * be updated to avoid reading an incorrect value due to<br>
-                * the new fast GRBM interface.<br>
-                */<br>
-               if (entry->vmid_src == AMDGPU_GFXHUB_0)<br>
-                       RREG32(hub->vm_l2_pro_fault_status);<br>
-<br>
-               status = RREG32(hub->vm_l2_pro_fault_status);<br>
-               cid = REG_GET_FIELD(status,<br>
-                                   VM_L2_PROTECTION_FAULT_STATUS, CID);<br>
-               rw = REG_GET_FIELD(status,<br>
-                                  VM_L2_PROTECTION_FAULT_STATUS, RW);<br>
-               WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);<br>
-       }<br>
+       dev_err(adev->dev,<br>
+               "[%s] %s page fault (src_id:%u ring:%u vmid:%u "<br>
+               "pasid:%u, for process %s pid %d thread %s pid %d)\n",<br>
+               hub_name, retry_fault ? "retry" : "no-retry",<br>
+               entry->src_id, entry->ring_id, entry->vmid,<br>
+               entry->pasid, task_info.process_name, task_info.tgid,<br>
+               task_info.task_name, task_info.pid);<br>
+       dev_err(adev->dev, "  in page starting at address 0x%016llx from client %d\n",<br>
+               addr, entry->client_id);<br>
 <br>
-       if (printk_ratelimit()) {<br>
-               struct amdgpu_task_info task_info;<br>
-<br>
-               memset(&task_info, 0, sizeof(struct amdgpu_task_info));<br>
-               amdgpu_vm_get_task_info(adev, entry->pasid, &task_info);<br>
-<br>
-               dev_err(adev->dev,<br>
-                       "[%s] %s page fault (src_id:%u ring:%u vmid:%u "<br>
-                       "pasid:%u, for process %s pid %d thread %s pid %d)\n",<br>
-                       hub_name, retry_fault ? "retry" : "no-retry",<br>
-                       entry->src_id, entry->ring_id, entry->vmid,<br>
-                       entry->pasid, task_info.process_name, task_info.tgid,<br>
-                       task_info.task_name, task_info.pid);<br>
-               dev_err(adev->dev, "  in page starting at address 0x%016llx from client %d\n",<br>
-                       addr, entry->client_id);<br>
-               if (!amdgpu_sriov_vf(adev)) {<br>
-                       dev_err(adev->dev,<br>
-                               "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",<br>
-                               status);<br>
-                       if (hub == &adev->vmhub[AMDGPU_GFXHUB_0]) {<br>
-                               dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",<br>
-                                       cid >= ARRAY_SIZE(gfxhub_client_ids) ? "unknown" : gfxhub_client_ids[cid],<br>
-                                       cid);<br>
-                       } else {<br>
-                               switch (adev->asic_type) {<br>
-                               case CHIP_VEGA10:<br>
-                                       mmhub_cid = mmhub_client_ids_vega10[cid][rw];<br>
-                                       break;<br>
-                               case CHIP_VEGA12:<br>
-                                       mmhub_cid = mmhub_client_ids_vega12[cid][rw];<br>
-                                       break;<br>
-                               case CHIP_VEGA20:<br>
-                                       mmhub_cid = mmhub_client_ids_vega20[cid][rw];<br>
-                                       break;<br>
-                               case CHIP_ARCTURUS:<br>
-                                       mmhub_cid = mmhub_client_ids_arcturus[cid][rw];<br>
-                                       break;<br>
-                               case CHIP_RAVEN:<br>
-                                       mmhub_cid = mmhub_client_ids_raven[cid][rw];<br>
-                                       break;<br>
-                               case CHIP_RENOIR:<br>
-                                       mmhub_cid = mmhub_client_ids_renoir[cid][rw];<br>
-                                       break;<br>
-                               default:<br>
-                                       mmhub_cid = NULL;<br>
-                                       break;<br>
-                               }<br>
-                               dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",<br>
-                                       mmhub_cid ? mmhub_cid : "unknown", cid);<br>
-                       }<br>
-                       dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",<br>
-                               REG_GET_FIELD(status,<br>
-                               VM_L2_PROTECTION_FAULT_STATUS, MORE_FAULTS));<br>
-                       dev_err(adev->dev, "\t WALKER_ERROR: 0x%lx\n",<br>
-                               REG_GET_FIELD(status,<br>
-                               VM_L2_PROTECTION_FAULT_STATUS, WALKER_ERROR));<br>
-                       dev_err(adev->dev, "\t PERMISSION_FAULTS: 0x%lx\n",<br>
-                               REG_GET_FIELD(status,<br>
-                               VM_L2_PROTECTION_FAULT_STATUS, PERMISSION_FAULTS));<br>
-                       dev_err(adev->dev, "\t MAPPING_ERROR: 0x%lx\n",<br>
-                               REG_GET_FIELD(status,<br>
-                               VM_L2_PROTECTION_FAULT_STATUS, MAPPING_ERROR));<br>
-                       dev_err(adev->dev, "\t RW: 0x%x\n", rw);<br>
+       if (amdgpu_sriov_vf(adev))<br>
+               return 0;<br>
+<br>
+       /*<br>
+        * Issue a dummy read to wait for the status register to<br>
+        * be updated to avoid reading an incorrect value due to<br>
+        * the new fast GRBM interface.<br>
+        */<br>
+       if (entry->vmid_src == AMDGPU_GFXHUB_0)<br>
+               RREG32(hub->vm_l2_pro_fault_status);<br>
+<br>
+       status = RREG32(hub->vm_l2_pro_fault_status);<br>
+       cid = REG_GET_FIELD(status, VM_L2_PROTECTION_FAULT_STATUS, CID);<br>
+       rw = REG_GET_FIELD(status, VM_L2_PROTECTION_FAULT_STATUS, RW);<br>
+       WREG32_P(hub->vm_l2_pro_fault_cntl, 1, ~1);<br>
+<br>
+<br>
+       dev_err(adev->dev,<br>
+               "VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",<br>
+               status);<br>
+       if (hub == &adev->vmhub[AMDGPU_GFXHUB_0]) {<br>
+               dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",<br>
+                       cid >= ARRAY_SIZE(gfxhub_client_ids) ? "unknown" :<br>
+                       gfxhub_client_ids[cid],<br>
+                       cid);<br>
+       } else {<br>
+               switch (adev->asic_type) {<br>
+               case CHIP_VEGA10:<br>
+                       mmhub_cid = mmhub_client_ids_vega10[cid][rw];<br>
+                       break;<br>
+               case CHIP_VEGA12:<br>
+                       mmhub_cid = mmhub_client_ids_vega12[cid][rw];<br>
+                       break;<br>
+               case CHIP_VEGA20:<br>
+                       mmhub_cid = mmhub_client_ids_vega20[cid][rw];<br>
+                       break;<br>
+               case CHIP_ARCTURUS:<br>
+                       mmhub_cid = mmhub_client_ids_arcturus[cid][rw];<br>
+                       break;<br>
+               case CHIP_RAVEN:<br>
+                       mmhub_cid = mmhub_client_ids_raven[cid][rw];<br>
+                       break;<br>
+               case CHIP_RENOIR:<br>
+                       mmhub_cid = mmhub_client_ids_renoir[cid][rw];<br>
+                       break;<br>
+               default:<br>
+                       mmhub_cid = NULL;<br>
+                       break;<br>
                 }<br>
+               dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",<br>
+                       mmhub_cid ? mmhub_cid : "unknown", cid);<br>
         }<br>
-<br>
+       dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",<br>
+               REG_GET_FIELD(status,<br>
+               VM_L2_PROTECTION_FAULT_STATUS, MORE_FAULTS));<br>
+       dev_err(adev->dev, "\t WALKER_ERROR: 0x%lx\n",<br>
+               REG_GET_FIELD(status,<br>
+               VM_L2_PROTECTION_FAULT_STATUS, WALKER_ERROR));<br>
+       dev_err(adev->dev, "\t PERMISSION_FAULTS: 0x%lx\n",<br>
+               REG_GET_FIELD(status,<br>
+               VM_L2_PROTECTION_FAULT_STATUS, PERMISSION_FAULTS));<br>
+       dev_err(adev->dev, "\t MAPPING_ERROR: 0x%lx\n",<br>
+               REG_GET_FIELD(status,<br>
+               VM_L2_PROTECTION_FAULT_STATUS, MAPPING_ERROR));<br>
+       dev_err(adev->dev, "\t RW: 0x%x\n", rw);<br>
         return 0;<br>
 }<br>
 <br>
-- <br>
2.17.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Calexander.deucher%40amd.com%7C655fb63177a249515dc508d87b4845c0%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637394897660510596%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=OpQ%2F9rJZASpLtPvqr4J4IzA4KphHzl2%2Fb1oqz5hLIyA%3D&amp;reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Calexander.deucher%40amd.com%7C655fb63177a249515dc508d87b4845c0%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637394897660510596%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=OpQ%2F9rJZASpLtPvqr4J4IzA4KphHzl2%2Fb1oqz5hLIyA%3D&amp;reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>