<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<p style="font-family:Arial;font-size:10pt;color:#0078D7;margin:15pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255); text-align: left;" dir="auto">
ping</div>
<div id="ms-outlook-mobile-signature">
<div><br>
</div>
 <a href="https://aka.ms/ghei36">Outlook for Android</a></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> Jack Zhang <Jack.Zhang1@amd.com><br>
<b>Sent:</b> Monday, May 18, 2020 5:00:53 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Zhang, Jack (Jian) <Jack.Zhang1@amd.com><br>
<b>Subject:</b> [PATCH] drm/amdgpu fix incorrect sysfs remove behavior for xgmi</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Under xgmi setup,some sysfs fail to create for the second time of kmd<br>
driver loading. It's due to sysfs nodes are not removed appropriately<br>
in the last unlod time.<br>
<br>
Changes of this patch:<br>
1. remove sysfs for dev_attr_xgmi_error<br>
2. remove sysfs_link adev->dev->kobj with target name.<br>
   And it only needs to be removed once for a xgmi setup<br>
3. remove sysfs_link hive->kobj with target name<br>
<br>
In amdgpu_xgmi_remove_device:<br>
1. amdgpu_xgmi_sysfs_rem_dev_info needs to be run per device<br>
2. amdgpu_xgmi_sysfs_destroy needs to be run on the last node of<br>
device.<br>
<br>
v2: initialize array with memset<br>
<br>
Signed-off-by: Jack Zhang <Jack.Zhang1@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 24 +++++++++++++++++-------<br>
 1 file changed, 17 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c<br>
index e9e59bc..3b46ea8 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c<br>
@@ -325,9 +325,19 @@ static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,<br>
 static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,<br>
                                           struct amdgpu_hive_info *hive)<br>
 {<br>
+       char node[10];<br>
+       memset(node, 0, sizeof(node));<br>
+<br>
         device_remove_file(adev->dev, &dev_attr_xgmi_device_id);<br>
-       sysfs_remove_link(&adev->dev->kobj, adev->ddev->unique);<br>
-       sysfs_remove_link(hive->kobj, adev->ddev->unique);<br>
+       device_remove_file(adev->dev, &dev_attr_xgmi_error);<br>
+<br>
+       if (adev != hive->adev) {<br>
+               sysfs_remove_link(&adev->dev->kobj,"xgmi_hive_info");<br>
+       }<br>
+<br>
+       sprintf(node, "node%d", hive->number_devices);<br>
+       sysfs_remove_link(hive->kobj, node);<br>
+<br>
 }<br>
 <br>
 <br>
@@ -583,14 +593,14 @@ int amdgpu_xgmi_remove_device(struct amdgpu_device *adev)<br>
         if (!hive)<br>
                 return -EINVAL;<br>
 <br>
-       if (!(hive->number_devices--)) {<br>
+       task_barrier_rem_task(&hive->tb);<br>
+       amdgpu_xgmi_sysfs_rem_dev_info(adev, hive);<br>
+       mutex_unlock(&hive->hive_lock);<br>
+<br>
+       if(!(--hive->number_devices)){<br>
                 amdgpu_xgmi_sysfs_destroy(adev, hive);<br>
                 mutex_destroy(&hive->hive_lock);<br>
                 mutex_destroy(&hive->reset_lock);<br>
-       } else {<br>
-               task_barrier_rem_task(&hive->tb);<br>
-               amdgpu_xgmi_sysfs_rem_dev_info(adev, hive);<br>
-               mutex_unlock(&hive->hive_lock);<br>
         }<br>
 <br>
         return psp_xgmi_terminate(&adev->psp);<br>
-- <br>
2.7.4<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>