[PATCH] drm/amdgpu fix incorrect sysfs remove behavior for xgmi

Zhang, Hawking Hawking.Zhang at amd.com
Thu May 21 08:50:59 UTC 2020

[AMD Official Use Only - Internal Distribution Only]

[AMD Official Use Only - Internal Distribution Only]

+       if (adev != hive->adev) {
+               sysfs_remove_link(&adev->dev->kobj,"xgmi_hive_info");
+       }

Please drop the braces in above code segment. Other than that, the patch is

Reviewed-by: Hawking Zhang <Hawking.Zhang at amd.com>

From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org> On Behalf Of Zhang, Jack (Jian)
Sent: Wednesday, May 20, 2020 08:14
To: amd-gfx at lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu fix incorrect sysfs remove behavior for xgmi

[AMD Official Use Only - Internal Distribution Only]

[AMD Official Use Only - Internal Distribution Only]


 Outlook for Android<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Faka.ms%2Fghei36&data=02%7C01%7Chawking.zhang%40amd.com%7Cae55d8dca7cb42c5a77408d7fc52bde4%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637255306473528001&sdata=JjFZsnqaTYv1ShkWrIpTi0QW500U0mNYolWfI1a6lX0%3D&reserved=0>
From: Jack Zhang <Jack.Zhang1 at amd.com<mailto:Jack.Zhang1 at amd.com>>
Sent: Monday, May 18, 2020 5:00:53 PM
To: amd-gfx at lists.freedesktop.org<mailto:amd-gfx at lists.freedesktop.org> <amd-gfx at lists.freedesktop.org<mailto:amd-gfx at lists.freedesktop.org>>
Cc: Zhang, Jack (Jian) <Jack.Zhang1 at amd.com<mailto:Jack.Zhang1 at amd.com>>
Subject: [PATCH] drm/amdgpu fix incorrect sysfs remove behavior for xgmi

Under xgmi setup,some sysfs fail to create for the second time of kmd
driver loading. It's due to sysfs nodes are not removed appropriately
in the last unlod time.

Changes of this patch:
1. remove sysfs for dev_attr_xgmi_error
2. remove sysfs_link adev->dev->kobj with target name.
   And it only needs to be removed once for a xgmi setup
3. remove sysfs_link hive->kobj with target name

In amdgpu_xgmi_remove_device:
1. amdgpu_xgmi_sysfs_rem_dev_info needs to be run per device
2. amdgpu_xgmi_sysfs_destroy needs to be run on the last node of

v2: initialize array with memset

Signed-off-by: Jack Zhang <Jack.Zhang1 at amd.com<mailto:Jack.Zhang1 at amd.com>>
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
index e9e59bc..3b46ea8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
@@ -325,9 +325,19 @@ static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
 static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
                                           struct amdgpu_hive_info *hive)
+       char node[10];
+       memset(node, 0, sizeof(node));
         device_remove_file(adev->dev, &dev_attr_xgmi_device_id);
-       sysfs_remove_link(&adev->dev->kobj, adev->ddev->unique);
-       sysfs_remove_link(hive->kobj, adev->ddev->unique);
+       device_remove_file(adev->dev, &dev_attr_xgmi_error);
+       if (adev != hive->adev) {
+               sysfs_remove_link(&adev->dev->kobj,"xgmi_hive_info");
+       }
+       sprintf(node, "node%d", hive->number_devices);
+       sysfs_remove_link(hive->kobj, node);

@@ -583,14 +593,14 @@ int amdgpu_xgmi_remove_device(struct amdgpu_device *adev)
         if (!hive)
                 return -EINVAL;

-       if (!(hive->number_devices--)) {
+       task_barrier_rem_task(&hive->tb);
+       amdgpu_xgmi_sysfs_rem_dev_info(adev, hive);
+       mutex_unlock(&hive->hive_lock);
+       if(!(--hive->number_devices)){
                 amdgpu_xgmi_sysfs_destroy(adev, hive);
-       } else {
-               task_barrier_rem_task(&hive->tb);
-               amdgpu_xgmi_sysfs_rem_dev_info(adev, hive);
-               mutex_unlock(&hive->hive_lock);

         return psp_xgmi_terminate(&adev->psp);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20200521/cd654de6/attachment.htm>

More information about the amd-gfx mailing list