Skip to contentSkip to conversation

drm/amdgpu: cleanup amdgpu_xgmi_sysfs_add_dev_info

PATCH In review Christian König 3 participants 6 messages Jan 26, 2022 – Feb 9, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: cleanup amdgpu_xgmi_sysfs_add_dev_info

Don't initialize variables if it isn't absolutely necessary.

Use amdgpu_xgmi_sysfs_rem_dev_info to cleanup when something goes wrong.

Drop the explicit warnings since the sysfs core warns about things like duplicate files itself.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 85 +++++++++---------------
 1 file changed, 33 insertions(+), 52 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +33 -52
index 5929d6f528c9..68509f619ba3 100644
@@ -289,61 +289,10 @@ static ssize_t amdgpu_xgmi_show_error(struct device *dev,
 static DEVICE_ATTR(xgmi_device_id, S_IRUGO, amdgpu_xgmi_show_device_id, NULL);
 static DEVICE_ATTR(xgmi_error, S_IRUGO, amdgpu_xgmi_show_error, NULL);
 
-static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
-					 struct amdgpu_hive_info *hive)
-{
-	int ret = 0;
-	char node[10] = { 0 };
-
-	/* Create xgmi device id file */
-	ret = device_create_file(adev->dev, &dev_attr_xgmi_device_id);
-	if (ret) {
-		dev_err(adev->dev, "XGMI: Failed to create device file xgmi_device_id\n");
-		return ret;
-	}
-
-	/* Create xgmi error file */
-	ret = device_create_file(adev->dev, &dev_attr_xgmi_error);
-	if (ret)
-		pr_err("failed to create xgmi_error\n");
-
-
-	/* Create sysfs link to hive info folder on the first device */
-	if (hive->kobj.parent != (&adev->dev->kobj)) {
-		ret = sysfs_create_link(&adev->dev->kobj, &hive->kobj,
-					"xgmi_hive_info");
-		if (ret) {
-			dev_err(adev->dev, "XGMI: Failed to create link to hive info");
-			goto remove_file;
-		}
-	}
-
-	sprintf(node, "node%d", atomic_read(&hive->number_devices));
-	/* Create sysfs link form the hive folder to yourself */
-	ret = sysfs_create_link(&hive->kobj, &adev->dev->kobj, node);
-	if (ret) {
-		dev_err(adev->dev, "XGMI: Failed to create link from hive info");
-		goto remove_link;
-	}
-
-	goto success;
-
-
-remove_link:
-	sysfs_remove_link(&adev->dev->kobj, adev_to_drm(adev)->unique);
-
-remove_file:
-	device_remove_file(adev->dev, &dev_attr_xgmi_device_id);
-
-success:
-	return ret;
-}
-
 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);
 	device_remove_file(adev->dev, &dev_attr_xgmi_error);
@@ -353,10 +302,42 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
 
 	sprintf(node, "node%d", atomic_read(&hive->number_devices));
 	sysfs_remove_link(&hive->kobj, node);
-
 }
 
+static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
+					 struct amdgpu_hive_info *hive)
+{
+	char node[10];
+	int r;
+
+	r = device_create_file(adev->dev, &dev_attr_xgmi_device_id);
+	if (r)
+		return r;
+
+	r = device_create_file(adev->dev, &dev_attr_xgmi_error);
+	if (r)
+		goto error;
 
+	/* Create sysfs link to hive info folder on the first device */
+	if (hive->kobj.parent != (&adev->dev->kobj)) {
+		r = sysfs_create_link(&adev->dev->kobj, &hive->kobj,
+				      "xgmi_hive_info");
+		if (r)
+			goto error;
+	}
+
+	/* Create sysfs link form the hive folder to yourself */
+	sprintf(node, "node%d", atomic_read(&hive->number_devices));
+	r = sysfs_create_link(&hive->kobj, &adev->dev->kobj, node);
+	if (r)
+		goto error;
+
+	return 0;
+
+error:
+	amdgpu_xgmi_sysfs_rem_dev_info(adev, hive);
+	return r;
+}
 
 struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 {
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 drm/amdgpu: add sysfs files for XGMI segment size and physical node id

umr needs that to correctly calculate the VRAM base address inside the MC address space.

Only compile tested!

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 34 ++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +34 -0
index 68509f619ba3..21a5d07a1abf 100644
@@ -252,6 +252,26 @@ static ssize_t amdgpu_xgmi_show_device_id(struct device *dev,
 
 }
 
+static ssize_t amdgpu_xgmi_show_node_segment_size(struct device *dev,
+						  struct device_attribute *attr,
+						  char *buf)
+{
+	struct drm_device *ddev = dev_get_drvdata(dev);
+	struct amdgpu_device *adev = drm_to_adev(ddev);
+
+	return sysfs_emit(buf, "%llu\n", adev->gmc.xgmi.node_segment_size);
+}
+
+static ssize_t amdgpu_xgmi_show_physical_node_id(struct device *dev,
+						 struct device_attribute *attr,
+						 char *buf)
+{
+	struct drm_device *ddev = dev_get_drvdata(dev);
+	struct amdgpu_device *adev = drm_to_adev(ddev);
+
+	return sysfs_emit(buf, "%u\n", adev->gmc.xgmi.physical_node_id);
+}
+
 #define AMDGPU_XGMI_SET_FICAA(o)	((o) | 0x456801)
 static ssize_t amdgpu_xgmi_show_error(struct device *dev,
 				      struct device_attribute *attr,
@@ -287,6 +307,10 @@ static ssize_t amdgpu_xgmi_show_error(struct device *dev,
 
 
 static DEVICE_ATTR(xgmi_device_id, S_IRUGO, amdgpu_xgmi_show_device_id, NULL);
+static DEVICE_ATTR(xgmi_node_segment_size, S_IRUGO,
+		   amdgpu_xgmi_show_node_segment_size, NULL);
+static DEVICE_ATTR(xgmi_physical_node_id, S_IRUGO,
+		   amdgpu_xgmi_show_physical_node_id, NULL);
 static DEVICE_ATTR(xgmi_error, S_IRUGO, amdgpu_xgmi_show_error, NULL);
 
 static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
@@ -295,6 +319,8 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
 	char node[10];
 
 	device_remove_file(adev->dev, &dev_attr_xgmi_device_id);
+	device_remove_file(adev->dev, &dev_attr_xgmi_node_segment_size);
+	device_remove_file(adev->dev, &dev_attr_xgmi_physical_node_id);
 	device_remove_file(adev->dev, &dev_attr_xgmi_error);
 
 	if (hive->kobj.parent != (&adev->dev->kobj))
@@ -318,6 +344,14 @@ static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
 	if (r)
 		goto error;
 
+	r = device_create_file(adev->dev, &dev_attr_xgmi_node_segment_size);
+	if (r)
+		goto error;
+
+	r = device_create_file(adev->dev, &dev_attr_xgmi_physical_node_id);
+	if (r)
+		goto error;
+
 	/* Create sysfs link to hive info folder on the first device */
 	if (hive->kobj.parent != (&adev->dev->kobj)) {
 		r = sysfs_create_link(&adev->dev->kobj, &hive->kobj,
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: add sysfs files for XGMI segment size and physical node id

This seems reasonable. Hope it works out for umr.

Regards,
Luben

Quoted 66 lines · Christian König

umr needs that to correctly calculate the VRAM base address inside the MC address space.

Only compile tested!

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 34 ++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +27 -0
index 68509f619ba3..21a5d07a1abf 100644
@@ -252,6 +252,26 @@ static ssize_t amdgpu_xgmi_show_device_id(struct device *dev,
 
 }
 
+static ssize_t amdgpu_xgmi_show_node_segment_size(struct device *dev,
+						  struct device_attribute *attr,
+						  char *buf)
+{
+	struct drm_device *ddev = dev_get_drvdata(dev);
+	struct amdgpu_device *adev = drm_to_adev(ddev);
+
+	return sysfs_emit(buf, "%llu\n", adev->gmc.xgmi.node_segment_size);
+}
+
+static ssize_t amdgpu_xgmi_show_physical_node_id(struct device *dev,
+						 struct device_attribute *attr,
+						 char *buf)
+{
+	struct drm_device *ddev = dev_get_drvdata(dev);
+	struct amdgpu_device *adev = drm_to_adev(ddev);
+
+	return sysfs_emit(buf, "%u\n", adev->gmc.xgmi.physical_node_id);
+}
+
 #define AMDGPU_XGMI_SET_FICAA(o)	((o) | 0x456801)
 static ssize_t amdgpu_xgmi_show_error(struct device *dev,
 				      struct device_attribute *attr,
@@ -287,6 +307,10 @@ static ssize_t amdgpu_xgmi_show_error(struct device *dev,
 
 
 static DEVICE_ATTR(xgmi_device_id, S_IRUGO, amdgpu_xgmi_show_device_id, NULL);
+static DEVICE_ATTR(xgmi_node_segment_size, S_IRUGO,
+		   amdgpu_xgmi_show_node_segment_size, NULL);
+static DEVICE_ATTR(xgmi_physical_node_id, S_IRUGO,
+		   amdgpu_xgmi_show_physical_node_id, NULL);
 static DEVICE_ATTR(xgmi_error, S_IRUGO, amdgpu_xgmi_show_error, NULL);
 
 static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
@@ -295,6 +319,8 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
 	char node[10];
 
 	device_remove_file(adev->dev, &dev_attr_xgmi_device_id);
+	device_remove_file(adev->dev, &dev_attr_xgmi_node_segment_size);
+	device_remove_file(adev->dev, &dev_attr_xgmi_physical_node_id);
 	device_remove_file(adev->dev, &dev_attr_xgmi_error);
 
 	if (hive->kobj.parent != (&adev->dev->kobj))
@@ -318,6 +344,14 @@ static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
 	if (r)
 		goto error;
 
+	r = device_create_file(adev->dev, &dev_attr_xgmi_node_segment_size);

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev, · line 357

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +7 -0
+	if (r)
+		goto error;
+
+	r = device_create_file(adev->dev, &dev_attr_xgmi_physical_node_id);
+	if (r)
+		goto error;
+
 	/* Create sysfs link to hive info folder on the first device */
 	if (hive->kobj.parent != (&adev->dev->kobj)) {
 		r = sysfs_create_link(&adev->dev->kobj, &hive->kobj,

Regards,

Signature · 1 line
Luben
Reviewed-by Luben Tuikov
#3 lore raw

Re: [PATCH 2/2] drm/amdgpu: add sysfs files for XGMI segment size and physical node id

[AMD Official Use Only]

Sadly I don't control any XGMI hosts to try it out. So if they pick it up in their builds I can but otherwise we'll have to wait.

Tom

________________________________________
From: Tuikov, Luben <[email protected]>
Sent: Wednesday, January 26, 2022 07:55
To: Christian König; StDenis, Tom
Cc: [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: add sysfs files for XGMI segment size and physical node id

This seems reasonable. Hope it works out for umr.

Regards,
Luben

Quoted 66 lines · Christian König

umr needs that to correctly calculate the VRAM base address inside the MC address space.

Only compile tested!

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 34 ++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +27 -0
index 68509f619ba3..21a5d07a1abf 100644
@@ -252,6 +252,26 @@ static ssize_t amdgpu_xgmi_show_device_id(struct device *dev,
 
 }
 
+static ssize_t amdgpu_xgmi_show_node_segment_size(struct device *dev,
+                                               struct device_attribute *attr,
+                                               char *buf)
+{
+     struct drm_device *ddev = dev_get_drvdata(dev);
+     struct amdgpu_device *adev = drm_to_adev(ddev);
+
+     return sysfs_emit(buf, "%llu\n", adev->gmc.xgmi.node_segment_size);
+}
+
+static ssize_t amdgpu_xgmi_show_physical_node_id(struct device *dev,
+                                              struct device_attribute *attr,
+                                              char *buf)
+{
+     struct drm_device *ddev = dev_get_drvdata(dev);
+     struct amdgpu_device *adev = drm_to_adev(ddev);
+
+     return sysfs_emit(buf, "%u\n", adev->gmc.xgmi.physical_node_id);
+}
+
 #define AMDGPU_XGMI_SET_FICAA(o)     ((o) | 0x456801)
 static ssize_t amdgpu_xgmi_show_error(struct device *dev,
                                    struct device_attribute *attr,
@@ -287,6 +307,10 @@ static ssize_t amdgpu_xgmi_show_error(struct device *dev,
 
 
 static DEVICE_ATTR(xgmi_device_id, S_IRUGO, amdgpu_xgmi_show_device_id, NULL);
+static DEVICE_ATTR(xgmi_node_segment_size, S_IRUGO,
+                amdgpu_xgmi_show_node_segment_size, NULL);
+static DEVICE_ATTR(xgmi_physical_node_id, S_IRUGO,
+                amdgpu_xgmi_show_physical_node_id, NULL);
 static DEVICE_ATTR(xgmi_error, S_IRUGO, amdgpu_xgmi_show_error, NULL);
 
 static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
@@ -295,6 +319,8 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
      char node[10];
 
      device_remove_file(adev->dev, &dev_attr_xgmi_device_id);
+     device_remove_file(adev->dev, &dev_attr_xgmi_node_segment_size);
+     device_remove_file(adev->dev, &dev_attr_xgmi_physical_node_id);
      device_remove_file(adev->dev, &dev_attr_xgmi_error);
 
      if (hive->kobj.parent != (&adev->dev->kobj))
@@ -318,6 +344,14 @@ static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
      if (r)
              goto error;
 
+     r = device_create_file(adev->dev, &dev_attr_xgmi_node_segment_size);

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev, · line 357

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +7 -0
+     if (r)
+             goto error;
+
+     r = device_create_file(adev->dev, &dev_attr_xgmi_physical_node_id);
+     if (r)
+             goto error;
+
      /* Create sysfs link to hive info folder on the first device */
      if (hive->kobj.parent != (&adev->dev->kobj)) {
              r = sysfs_create_link(&adev->dev->kobj, &hive->kobj,

Regards,
--
Luben

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: add sysfs files for XGMI segment size and physical node id

Can anybody give me a Tested-by for this set?

I would really like to push it, but it would be nice to have at least somebody with access to an xgmi system tries it first.

Christian.

Am 26.01.22 um 13:57 schrieb StDenis, Tom:

Quoted 101 lines

[AMD Official Use Only]

Sadly I don't control any XGMI hosts to try it out. So if they pick it up in their builds I can but otherwise we'll have to wait.

Tom

________________________________________
From: Tuikov, Luben <[email protected]>
Sent: Wednesday, January 26, 2022 07:55
To: Christian König; StDenis, Tom
Cc: [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: add sysfs files for XGMI segment size and physical node id

This seems reasonable. Hope it works out for umr.

Regards,
Luben

Quoted 66 lines · Christian König

umr needs that to correctly calculate the VRAM base address inside the MC address space.

Only compile tested!

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 34 ++++++++++++++++++++++++
  1 file changed, 34 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +27 -0
index 68509f619ba3..21a5d07a1abf 100644
@@ -252,6 +252,26 @@ static ssize_t amdgpu_xgmi_show_device_id(struct device *dev,
 
  }
 
+static ssize_t amdgpu_xgmi_show_node_segment_size(struct device *dev,
+                                               struct device_attribute *attr,
+                                               char *buf)
+{
+     struct drm_device *ddev = dev_get_drvdata(dev);
+     struct amdgpu_device *adev = drm_to_adev(ddev);
+
+     return sysfs_emit(buf, "%llu\n", adev->gmc.xgmi.node_segment_size);
+}
+
+static ssize_t amdgpu_xgmi_show_physical_node_id(struct device *dev,
+                                              struct device_attribute *attr,
+                                              char *buf)
+{
+     struct drm_device *ddev = dev_get_drvdata(dev);
+     struct amdgpu_device *adev = drm_to_adev(ddev);
+
+     return sysfs_emit(buf, "%u\n", adev->gmc.xgmi.physical_node_id);
+}
+
  #define AMDGPU_XGMI_SET_FICAA(o)     ((o) | 0x456801)
  static ssize_t amdgpu_xgmi_show_error(struct device *dev,
                                     struct device_attribute *attr,
@@ -287,6 +307,10 @@ static ssize_t amdgpu_xgmi_show_error(struct device *dev,
 
 
  static DEVICE_ATTR(xgmi_device_id, S_IRUGO, amdgpu_xgmi_show_device_id, NULL);
+static DEVICE_ATTR(xgmi_node_segment_size, S_IRUGO,
+                amdgpu_xgmi_show_node_segment_size, NULL);
+static DEVICE_ATTR(xgmi_physical_node_id, S_IRUGO,
+                amdgpu_xgmi_show_physical_node_id, NULL);
  static DEVICE_ATTR(xgmi_error, S_IRUGO, amdgpu_xgmi_show_error, NULL);
 
  static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
@@ -295,6 +319,8 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
       char node[10];
 
       device_remove_file(adev->dev, &dev_attr_xgmi_device_id);
+     device_remove_file(adev->dev, &dev_attr_xgmi_node_segment_size);
+     device_remove_file(adev->dev, &dev_attr_xgmi_physical_node_id);
       device_remove_file(adev->dev, &dev_attr_xgmi_error);
 
       if (hive->kobj.parent != (&adev->dev->kobj))
@@ -318,6 +344,14 @@ static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
       if (r)
               goto error;
 
+     r = device_create_file(adev->dev, &dev_attr_xgmi_node_segment_size);

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev, · line 357

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +7 -0
+     if (r)
+             goto error;
+
+     r = device_create_file(adev->dev, &dev_attr_xgmi_physical_node_id);
+     if (r)
+             goto error;
+
       /* Create sysfs link to hive info folder on the first device */
       if (hive->kobj.parent != (&adev->dev->kobj)) {
               r = sysfs_create_link(&adev->dev->kobj, &hive->kobj,

Regards,
--
Luben

Reviewed-by on v1 1/2
#5 lore raw
In reply to Christian König

Yeah, that's cleaner.

Regards,
Luben

Quoted 112 lines · Christian König

Don't initialize variables if it isn't absolutely necessary.

Use amdgpu_xgmi_sysfs_rem_dev_info to cleanup when something goes wrong.

Drop the explicit warnings since the sysfs core warns about things like duplicate files itself.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 85 +++++++++---------------
 1 file changed, 33 insertions(+), 52 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +26 -52
index 5929d6f528c9..68509f619ba3 100644
@@ -289,61 +289,10 @@ static ssize_t amdgpu_xgmi_show_error(struct device *dev,
 static DEVICE_ATTR(xgmi_device_id, S_IRUGO, amdgpu_xgmi_show_device_id, NULL);
 static DEVICE_ATTR(xgmi_error, S_IRUGO, amdgpu_xgmi_show_error, NULL);
 
-static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
-					 struct amdgpu_hive_info *hive)
-{
-	int ret = 0;
-	char node[10] = { 0 };
-
-	/* Create xgmi device id file */
-	ret = device_create_file(adev->dev, &dev_attr_xgmi_device_id);
-	if (ret) {
-		dev_err(adev->dev, "XGMI: Failed to create device file xgmi_device_id\n");
-		return ret;
-	}
-
-	/* Create xgmi error file */
-	ret = device_create_file(adev->dev, &dev_attr_xgmi_error);
-	if (ret)
-		pr_err("failed to create xgmi_error\n");
-
-
-	/* Create sysfs link to hive info folder on the first device */
-	if (hive->kobj.parent != (&adev->dev->kobj)) {
-		ret = sysfs_create_link(&adev->dev->kobj, &hive->kobj,
-					"xgmi_hive_info");
-		if (ret) {
-			dev_err(adev->dev, "XGMI: Failed to create link to hive info");
-			goto remove_file;
-		}
-	}
-
-	sprintf(node, "node%d", atomic_read(&hive->number_devices));
-	/* Create sysfs link form the hive folder to yourself */
-	ret = sysfs_create_link(&hive->kobj, &adev->dev->kobj, node);
-	if (ret) {
-		dev_err(adev->dev, "XGMI: Failed to create link from hive info");
-		goto remove_link;
-	}
-
-	goto success;
-
-
-remove_link:
-	sysfs_remove_link(&adev->dev->kobj, adev_to_drm(adev)->unique);
-
-remove_file:
-	device_remove_file(adev->dev, &dev_attr_xgmi_device_id);
-
-success:
-	return ret;
-}
-
 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);
 	device_remove_file(adev->dev, &dev_attr_xgmi_error);
@@ -353,10 +302,42 @@ static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev,
 
 	sprintf(node, "node%d", atomic_read(&hive->number_devices));
 	sysfs_remove_link(&hive->kobj, node);
-
 }
 
+static int amdgpu_xgmi_sysfs_add_dev_info(struct amdgpu_device *adev,
+					 struct amdgpu_hive_info *hive)
+{
+	char node[10];
+	int r;
+
+	r = device_create_file(adev->dev, &dev_attr_xgmi_device_id);
+	if (r)
+		return r;
+
+	r = device_create_file(adev->dev, &dev_attr_xgmi_error);
+	if (r)
+		goto error;
 
+	/* Create sysfs link to hive info folder on the first device */
+	if (hive->kobj.parent != (&adev->dev->kobj)) {
+		r = sysfs_create_link(&adev->dev->kobj, &hive->kobj,
+				      "xgmi_hive_info");
+		if (r)
+			goto error;
+	}
+
+	/* Create sysfs link form the hive folder to yourself */
+	sprintf(node, "node%d", atomic_read(&hive->number_devices));
+	r = sysfs_create_link(&hive->kobj, &adev->dev->kobj, node);
+	if (r)
+		goto error;

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c static void amdgpu_xgmi_sysfs_rem_dev_info(struct amdgpu_device *adev, · line 343

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +7 -0
+
+	return 0;
+
+error:
+	amdgpu_xgmi_sysfs_rem_dev_info(adev, hive);
+	return r;
+}
 
 struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 {

Regards,

Signature · 1 line
Luben