Skip to contentSkip to conversation

drm/amdgpu: skip xcp drm device allocation when out of drm resource

PATCH Superseded James Zhu 4 participants 9 messages Aug 11, 2023 – Aug 14, 2023

Subsystems (3)
lore
Share & tools
lore

James Zhu

author
#0 lore raw

PATCH v2 1/1 drm/amdgpu: skip xcp drm device allocation when out of drm resource

Return 0 when drm device alloc failed with -ENOSPC in order to allow amdgpu drive loading. But the xcp without drm device node assigned won't be visiable in user space. This helps amdgpu driver loading on system which has more than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/
libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

-v2: added warning message

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +12 -1
index 9c9cca129498..f0754d70da5c 100644
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct amdgpu_device *adev)
 
 	for (i = 1; i < MAX_XCP; i++) {
 		ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-		if (ret)
+		if (ret == -ENOSPC) {
+			dev_WARN(adev->dev,
+			"Skip xcp node #%d when out of drm node resource.", i);
+			return 0;
+		} else if (ret) {
 			return ret;
+		}
 
 		/* Redirect all IOCTLs to the primary device */
 		adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device *adev,
 		return 0;
 
 	for (i = 1; i < MAX_XCP; i++) {
+		if (!adev->xcp_mgr->xcp[i].ddev)
+			break;
+
 		ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
 		if (ret)
 			return ret;
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device *adev)
 		return;
 
 	for (i = 1; i < MAX_XCP; i++) {
+		if (!adev->xcp_mgr->xcp[i].ddev)
+			break;
+
 		p_ddev = adev->xcp_mgr->xcp[i].ddev;
 		drm_dev_unplug(p_ddev);
 		p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -1
index 3b0749390388..0f844151caaf 100644
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node *gpu)
 	int i;
 	const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
 	gpu_id = kfd_generate_gpu_id(gpu);
-	pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	if (!gpu->xcp->ddev) {
+		dev_WARN(gpu->adev->dev,
+		"Won't add GPU (ID: 0x%x) to topology since it has no drm node assigned.",
+		gpu_id);
+		return 0;
+	} else {
+		pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	}
 
 	/* Check to see if this gpu device exists in the topology_device_list.
 	 * If so, assign the gpu to that device,
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 27 lines · James Zhu

Return 0 when drm device alloc failed with -ENOSPC in order to allow amdgpu drive loading. But the xcp without drm device node assigned won't be visiable in user space. This helps amdgpu driver loading on system which has more than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/
libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

(quoted diff) +0 -2
-v2: added warning message
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++-
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-
  2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +0 -0
index 9c9cca129498..f0754d70da5c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c static int amdgpu_xcp_dev_alloc(struct amdgpu_device *adev) · line 244

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -1
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct amdgpu_device *adev)
 
  	for (i = 1; i < MAX_XCP; i++) {
  		ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-		if (ret)
+		if (ret == -ENOSPC) {
+			dev_WARN(adev->dev,
+			"Skip xcp node #%d when out of drm node resource.", i);

This prints a noisy backtrace. Maybe that's a bit too much. I'd just use dev_warn, so it only prints your message without a backtrace.

Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +9 -0
+			return 0;
+		} else if (ret) {
  			return ret;
+		}
 
  		/* Redirect all IOCTLs to the primary device */
  		adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device *adev,
  		return 0;
 
  	for (i = 1; i < MAX_XCP; i++) {
+		if (!adev->xcp_mgr->xcp[i].ddev)
+			break;
+
  		ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
  		if (ret)
  			return ret;
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device *adev)
  		return;
 
  	for (i = 1; i < MAX_XCP; i++) {
+		if (!adev->xcp_mgr->xcp[i].ddev)
+			break;
+
  		p_ddev = adev->xcp_mgr->xcp[i].ddev;
  		drm_dev_unplug(p_ddev);
  		p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
index 3b0749390388..0f844151caaf 100644

drivers/gpu/drm/amd/amdkfd/kfd_topology.c int kfd_topology_add_device(struct kfd_node *gpu) · line 1977

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +5 -1
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node *gpu)
  	int i;
  	const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
  	gpu_id = kfd_generate_gpu_id(gpu);
-	pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	if (!gpu->xcp->ddev) {
+		dev_WARN(gpu->adev->dev,
+		"Won't add GPU (ID: 0x%x) to topology since it has no drm node assigned.",
+		gpu_id);

Same as above.

Regards,
  Felix

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -0
+		return 0;
+	} else {
+		pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	}
 
  	/* Check to see if this gpu device exists in the topology_device_list.
  	 * If so, assign the gpu to that device,
author
#2 lore raw

PATCH v3 1/1 drm/amdgpu: skip xcp drm device allocation when out of drm resource

In reply to James Zhu

Return 0 when drm device alloc failed with -ENOSPC in order to allow amdgpu drive loading. But the xcp without drm device node assigned won't be visiable in user space. This helps amdgpu driver loading on system which has more than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/
libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

-v2: added warning message
-v3: use dev_warn

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +12 -1
index 9c9cca129498..565a1fa436d4 100644
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct amdgpu_device *adev)
 
 	for (i = 1; i < MAX_XCP; i++) {
 		ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-		if (ret)
+		if (ret == -ENOSPC) {
+			dev_warn(adev->dev,
+			"Skip xcp node #%d when out of drm node resource.", i);
+			return 0;
+		} else if (ret) {
 			return ret;
+		}
 
 		/* Redirect all IOCTLs to the primary device */
 		adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device *adev,
 		return 0;
 
 	for (i = 1; i < MAX_XCP; i++) {
+		if (!adev->xcp_mgr->xcp[i].ddev)
+			break;
+
 		ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
 		if (ret)
 			return ret;
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device *adev)
 		return;
 
 	for (i = 1; i < MAX_XCP; i++) {
+		if (!adev->xcp_mgr->xcp[i].ddev)
+			break;
+
 		p_ddev = adev->xcp_mgr->xcp[i].ddev;
 		drm_dev_unplug(p_ddev);
 		p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -1
index 3b0749390388..310df98ba46a 100644
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node *gpu)
 	int i;
 	const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
 	gpu_id = kfd_generate_gpu_id(gpu);
-	pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	if (!gpu->xcp->ddev) {
+		dev_warn(gpu->adev->dev,
+		"Won't add GPU (ID: 0x%x) to topology since it has no drm node assigned.",
+		gpu_id);
+		return 0;
+	} else {
+		pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	}
 
 	/* Check to see if this gpu device exists in the topology_device_list.
 	 * If so, assign the gpu to that device,
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 1/1
#3 lore raw
Quoted 13 lines · James Zhu

Return 0 when drm device alloc failed with -ENOSPC in order to allow amdgpu drive loading. But the xcp without drm device node assigned won't be visiable in user space. This helps amdgpu driver loading on system which has more than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/
libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

Quoted 2 lines
Quoted 69 lines
(quoted diff) +0 -3
-v2: added warning message
-v3: use dev_warn
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++-
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-
  2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +12 -1
index 9c9cca129498..565a1fa436d4 100644
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct amdgpu_device *adev)
 
  	for (i = 1; i < MAX_XCP; i++) {
  		ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-		if (ret)
+		if (ret == -ENOSPC) {
+			dev_warn(adev->dev,
+			"Skip xcp node #%d when out of drm node resource.", i);
+			return 0;
+		} else if (ret) {
  			return ret;
+		}
 
  		/* Redirect all IOCTLs to the primary device */
  		adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device *adev,
  		return 0;
 
  	for (i = 1; i < MAX_XCP; i++) {
+		if (!adev->xcp_mgr->xcp[i].ddev)
+			break;
+
  		ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
  		if (ret)
  			return ret;
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device *adev)
  		return;
 
  	for (i = 1; i < MAX_XCP; i++) {
+		if (!adev->xcp_mgr->xcp[i].ddev)
+			break;
+
  		p_ddev = adev->xcp_mgr->xcp[i].ddev;
  		drm_dev_unplug(p_ddev);
  		p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -1
index 3b0749390388..310df98ba46a 100644
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node *gpu)
  	int i;
  	const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
  	gpu_id = kfd_generate_gpu_id(gpu);
-	pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	if (!gpu->xcp->ddev) {
+		dev_warn(gpu->adev->dev,
+		"Won't add GPU (ID: 0x%x) to topology since it has no drm node assigned.",
+		gpu_id);
+		return 0;
+	} else {
+		pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	}
 
  	/* Check to see if this gpu device exists in the topology_device_list.
  	 * If so, assign the gpu to that device,
Acked-by Christian König on v3 1/1
#4 lore raw
In reply to James Zhu

[AMD Official Use Only - General]

A dynamic partition switch could happen later. The switch could still be successful in terms of hardware, and hence gives a false feeling of success even if there are no render nodes available for any app to make use of the partition.

Also, a kfd node is not expected to have a valid xcp pointer on devices without partition. This access could break then gpu->xcp->ddev.

Thanks,
Lijo
________________________________
From: amd-gfx <[email protected]> on behalf of James Zhu <[email protected]>
Sent: Saturday, August 12, 2023 2:36:27 AM
To: [email protected] <[email protected]>
Cc: Lin, Amber <[email protected]>; Zhu, James <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH v3] drm/amdgpu: skip xcp drm device allocation when out of drm resource

Return 0 when drm device alloc failed with -ENOSPC in order to allow amdgpu drive loading. But the xcp without drm device node assigned won't be visiable in user space. This helps amdgpu driver loading on system which has more than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/
libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

-v2: added warning message
-v3: use dev_warn

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +12 -1
index 9c9cca129498..565a1fa436d4 100644
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct amdgpu_device *adev)
 
         for (i = 1; i < MAX_XCP; i++) {
                 ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-               if (ret)
+               if (ret == -ENOSPC) {
+                       dev_warn(adev->dev,
+                       "Skip xcp node #%d when out of drm node resource.", i);
+                       return 0;
+               } else if (ret) {
                         return ret;
+               }
 
                 /* Redirect all IOCTLs to the primary device */
                 adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device *adev,
                 return 0;
 
         for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                 ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
                 if (ret)
                         return ret;
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device *adev)
                 return;
 
         for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                 p_ddev = adev->xcp_mgr->xcp[i].ddev;
                 drm_dev_unplug(p_ddev);
                 p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -1
index 3b0749390388..310df98ba46a 100644
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node *gpu)
         int i;
         const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
         gpu_id = kfd_generate_gpu_id(gpu);
-       pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+       if (!gpu->xcp->ddev) {
+               dev_warn(gpu->adev->dev,
+               "Won't add GPU (ID: 0x%x) to topology since it has no drm node assigned.",
+               gpu_id);
+               return 0;
+       } else {
+               pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+       }
 
         /* Check to see if this gpu device exists in the topology_device_list.
          * If so, assign the gpu to that device,

--
2.34.1

#5 lore raw
Quoted 5 lines · Lijo

[AMD Official Use Only - General]

A dynamic partition switch could happen later.  The switch could still be successful in terms of hardware,

[JZ] Only ignore render node assignment, and remove visibility in user space, xcp continues to be generated as usual. so switch should work as usual

Quoted 1 line

and hence gives a false feeling of success even if there are no render nodes available for any app to make use of the partition.

[JZ] from driver prospective, the switch is real success, treat the last one harvested in user space.. there is warning in kernel log, and final solution for more than 64 nodes is on-going

Quoted 2 lines

Also, a kfd node is not expected to have a valid xcp pointer on devices without partition.

[JZ] won't affect xcp pointer, only ddev.

Quoted 1 line

This access could break then gpu->xcp->ddev.

[JZ] added skip when ddev==NULL

Quoted 101 lines

Thanks,
Lijo
------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of James Zhu <[email protected]>
*Sent:* Saturday, August 12, 2023 2:36:27 AM
*To:* [email protected] <[email protected]>
*Cc:* Lin, Amber <[email protected]>; Zhu, James <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Koenig, Christian <[email protected]> *Subject:* [PATCH v3] drm/amdgpu: skip xcp drm device allocation when out of drm resource
Return 0 when drm device alloc failed with -ENOSPC in
order to  allow amdgpu drive loading. But the xcp without
drm device node assigned won't be visiable in user space.
This helps amdgpu driver loading on system which has more
than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/
libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

(quoted diff) +0 -3
-v2: added warning message
-v3: use dev_warn
---

 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-

 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +6 -1
index 9c9cca129498..565a1fa436d4 100644
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct 
 amdgpu_device *adev)
 
          for (i = 1; i < MAX_XCP; i++) {
                  ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-               if (ret)
+               if (ret == -ENOSPC) {
+                       dev_warn(adev->dev,
+                       "Skip xcp node #%d when out of drm node 
 resource.", i);
+                       return 0;
+               } else if (ret) {
                          return ret;
+               }
 

                 /* Redirect all IOCTLs to the primary device */ adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -0
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device 
 *adev,
                  return 0;
 
          for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                  ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
                  if (ret)

                         return ret;

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -0
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device *adev)
                  return;
 
          for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                  p_ddev = adev->xcp_mgr->xcp[i].ddev;
                  drm_dev_unplug(p_ddev);
                  p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -1
index 3b0749390388..310df98ba46a 100644
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node *gpu)
          int i;
          const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
          gpu_id = kfd_generate_gpu_id(gpu);
-       pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+       if (!gpu->xcp->ddev) {
+               dev_warn(gpu->adev->dev,
+               "Won't add GPU (ID: 0x%x) to topology since it has no 
 drm node assigned.",
+               gpu_id);
+               return 0;
+       } else {
+               pr_debug("Adding new GPU (ID: 0x%x) to topology\n", 
 gpu_id);
+       }
 

         /* Check to see if this gpu device exists in the topology_device_list.
          * If so, assign the gpu to that device,

Signature · 1 line
2.34.1
#6 lore raw
Quoted 8 lines · James Zhu
Quoted 5 lines · Lijo

[AMD Official Use Only - General]

A dynamic partition switch could happen later.  The switch could still be successful in terms of hardware,

[JZ] Only ignore render node assignment, and remove visibility in user space, xcp continues to be generated as usual. so switch should work as usual

Switch is not useful for the user unless the apps can make use of the render nodes. A 'success' from hardware perspective doesn't turn out to be a 'success' for users eventually to make use of the extra partition.

Quoted 2 lines
Quoted 1 line

and hence gives a false feeling of success even if there are no render nodes available for any app to make use of the partition.

[JZ] from driver prospective, the switch is real success, treat the last one harvested in user space.. there is warning in kernel log, and final solution for more than 64 nodes is on-going

The render nodes are allocated during driver load and the message will go unnoticed. We could still allow the switch, but the message should be there during a partition switch like 'only x/y (x out of y nodes) are usable'. The worst case is - only 1 out of N meaning no benefit - and in that case user may switch back to normal mode to make use of full compute power.

Quoted 5 lines
Quoted 2 lines

Also, a kfd node is not expected to have a valid xcp pointer on devices without partition.

[JZ] won't affect xcp pointer, only ddev.

Quoted 1 line

This access could break then gpu->xcp->ddev.

[JZ] added skip when ddev==NULL

What I meant is xcp in kfd node could be NULL on SOCs like NV series. There should be a check for xcp before accessing ddev -
https://elixir.bootlin.com/linux/v6.5-rc5/source/drivers/gpu/drm/amd/amdkfd/kfd_device.c#L794

Thanks,
Lijo

Quoted 101 lines
Quoted 101 lines

Thanks,
Lijo
------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of James Zhu <[email protected]>
*Sent:* Saturday, August 12, 2023 2:36:27 AM
*To:* [email protected] <[email protected]>
*Cc:* Lin, Amber <[email protected]>; Zhu, James <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Koenig, Christian <[email protected]> *Subject:* [PATCH v3] drm/amdgpu: skip xcp drm device allocation when out of drm resource
Return 0 when drm device alloc failed with -ENOSPC in
order to  allow amdgpu drive loading. But the xcp without
drm device node assigned won't be visiable in user space.
This helps amdgpu driver loading on system which has more
than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/
libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

(quoted diff) +0 -3
-v2: added warning message
-v3: use dev_warn
---

 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-

 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +6 -1
index 9c9cca129498..565a1fa436d4 100644
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct 
 amdgpu_device *adev)
 
          for (i = 1; i < MAX_XCP; i++) {
                  ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-               if (ret)
+               if (ret == -ENOSPC) {
+                       dev_warn(adev->dev,
+                       "Skip xcp node #%d when out of drm node 
 resource.", i);
+                       return 0;
+               } else if (ret) {
                          return ret;
+               }
 

                 /* Redirect all IOCTLs to the primary device */ adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -0
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device 
 *adev,
                  return 0;
 
          for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                  ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
                  if (ret)

                         return ret;

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -0
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device *adev)
                  return;
 
          for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                  p_ddev = adev->xcp_mgr->xcp[i].ddev;
                  drm_dev_unplug(p_ddev);
                  p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -1
index 3b0749390388..310df98ba46a 100644
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node *gpu)
          int i;
          const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
          gpu_id = kfd_generate_gpu_id(gpu);
-       pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+       if (!gpu->xcp->ddev) {
+               dev_warn(gpu->adev->dev,
+               "Won't add GPU (ID: 0x%x) to topology since it has no 
 drm node assigned.",
+               gpu_id);
+               return 0;
+       } else {
+               pr_debug("Adding new GPU (ID: 0x%x) to topology\n", 
 gpu_id);
+       }
 

         /* Check to see if this gpu device exists in the topology_device_list.
          * If so, assign the gpu to that device,

Signature · 1 line
2.34.1
#7 lore raw
Quoted 6 lines · Lijo
Quoted 3 lines · James Zhu
Quoted 1 line · Lijo
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

[AMD Official Use Only - General]

A dynamic partition switch could happen later.  The switch could still be successful in terms of hardware,

[JZ] Only ignore render node assignment, and remove visibility in user space, xcp continues to be generated as usual. so switch should work as usual

Switch is not useful for the user unless the apps can make use of the render nodes. A 'success' from hardware perspective doesn't turn out to be a 'success' for users eventually to make use of the extra partition.

[JZ] Yes, After switch, app can use the render nodes (no more than 64 nodes in one system), Like 8P MI300X CPX mode,  with no external VGA device,all 64 nodes can be used. with one  external VGA device, 63 nodes can be used.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

and hence gives a false feeling of success even if there are no render nodes available for any app to make use of the partition.

[JZ] from driver prospective, the switch is real success, treat the last one harvested in user space.. there is warning in kernel log, and final solution for more than 64 nodes is on-going

The render nodes are allocated during driver load and the message will go unnoticed. We could still allow the switch, but the message should be there during a partition switch like 'only x/y (x out of y nodes) are usable'. The worst case is - only 1 out of N meaning no benefit - and in that case user may switch back to normal mode to make use of full compute power.

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Also, a kfd node is not expected to have a valid xcp pointer on devices without partition.

[JZ] won't affect xcp pointer, only ddev.

Quoted 1 line

This access could break then gpu->xcp->ddev.

[JZ] added skip when ddev==NULL

What I meant is xcp in kfd node could be NULL on SOCs like NV series. There should be a check for xcp before accessing ddev -
https://elixir.bootlin.com/linux/v6.5-rc5/source/drivers/gpu/drm/amd/amdkfd/kfd_device.c#L794

[JZ] So it is potential bug before this patch. then we need review current code to add all necessary xcp check.

Quoted 109 lines

Thanks,
Lijo

Quoted 105 lines
Quoted 105 lines

Thanks,
Lijo
------------------------------------------------------------------------

*From:* amd-gfx <[email protected]> on behalf of James Zhu <[email protected]>
*Sent:* Saturday, August 12, 2023 2:36:27 AM
*To:* [email protected] <[email protected]>
*Cc:* Lin, Amber <[email protected]>; Zhu, James <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Koenig, Christian <[email protected]> *Subject:* [PATCH v3] drm/amdgpu: skip xcp drm device allocation when out of drm resource
Return 0 when drm device alloc failed with -ENOSPC in
order to  allow amdgpu drive loading. But the xcp without
drm device node assigned won't be visiable in user space.
This helps amdgpu driver loading on system which has more
than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/

libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

(quoted diff) +0 -3
-v2: added warning message
-v3: use dev_warn
---

 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-

 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +6 -1
index 9c9cca129498..565a1fa436d4 100644
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct 
 amdgpu_device *adev)
 
          for (i = 1; i < MAX_XCP; i++) {
                  ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-               if (ret)
+               if (ret == -ENOSPC) {
+                       dev_warn(adev->dev,
+                       "Skip xcp node #%d when out of drm node 
 resource.", i);
+                       return 0;
+               } else if (ret) {
                          return ret;
+               }
 

                 /* Redirect all IOCTLs to the primary device */ adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -0
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device 
 *adev,
                  return 0;
 
          for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                  ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
                  if (ret)

                         return ret;

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -0
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device 
 *adev)
                  return;
 
          for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                  p_ddev = adev->xcp_mgr->xcp[i].ddev;
                  drm_dev_unplug(p_ddev);

                 p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;

drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -1
index 3b0749390388..310df98ba46a 100644
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node 
 *gpu)
          int i;
          const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
          gpu_id = kfd_generate_gpu_id(gpu);
-       pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+       if (!gpu->xcp->ddev) {
+               dev_warn(gpu->adev->dev,
+               "Won't add GPU (ID: 0x%x) to topology since it has 
 no drm node assigned.",
+               gpu_id);
+               return 0;
+       } else {
+               pr_debug("Adding new GPU (ID: 0x%x) to topology\n", 
 gpu_id);
+       }

         /* Check to see if this gpu device exists in the topology_device_list.
          * If so, assign the gpu to that device,

Signature · 1 line
2.34.1
#8 lore raw
Quoted 8 lines · James Zhu
Quoted 6 lines · Lijo
Quoted 3 lines · James Zhu
Quoted 1 line · Lijo
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

[AMD Official Use Only - General]

A dynamic partition switch could happen later.  The switch could still be successful in terms of hardware,

[JZ] Only ignore render node assignment, and remove visibility in user space, xcp continues to be generated as usual. so switch should work as usual

Switch is not useful for the user unless the apps can make use of the render nodes. A 'success' from hardware perspective doesn't turn out to be a 'success' for users eventually to make use of the extra partition.

[JZ] Yes, After switch, app can use the render nodes (no more than 64 nodes in one system), Like 8P MI300X CPX mode,  with no external VGA device,all 64 nodes can be used. with one  external VGA device, 63 nodes can be used.

Understood. What I meant is we should be having the 'warn message' with partition switch (when user really wants to make use of partitions) rather than on driver load (as with this patch). Technically, some of those nodes are usable only after a partition switch.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

and hence gives a false feeling of success even if there are no render nodes available for any app to make use of the partition.

[JZ] from driver prospective, the switch is real success, treat the last one harvested in user space.. there is warning in kernel log, and final solution for more than 64 nodes is on-going

The render nodes are allocated during driver load and the message will go unnoticed. We could still allow the switch, but the message should be there during a partition switch like 'only x/y (x out of y nodes) are usable'. The worst case is - only 1 out of N meaning no benefit - and in that case user may switch back to normal mode to make use of full compute power.

Quoted 2 lines
Quoted 2 lines

Also, a kfd node is not expected to have a valid xcp pointer on devices without partition.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

[JZ] won't affect xcp pointer, only ddev.

Quoted 1 line

This access could break then gpu->xcp->ddev.

[JZ] added skip when ddev==NULL

What I meant is xcp in kfd node could be NULL on SOCs like NV series. There should be a check for xcp before accessing ddev -
https://elixir.bootlin.com/linux/v6.5-rc5/source/drivers/gpu/drm/amd/amdkfd/kfd_device.c#L794

[JZ] So it is potential bug before this patch. then we need review current code to add all necessary xcp check.

We already have checks - https://elixir.bootlin.com/linux/v6.5-rc5/source/drivers/gpu/drm/amd/amdkfd/kfd_topology.c#L2027

Thanks,
Lijo

Quoted 109 lines
Quoted 109 lines

Thanks,
Lijo

Quoted 105 lines
Quoted 105 lines

Thanks,
Lijo
------------------------------------------------------------------------

*From:* amd-gfx <[email protected]> on behalf of James Zhu <[email protected]>
*Sent:* Saturday, August 12, 2023 2:36:27 AM
*To:* [email protected] <[email protected]>
*Cc:* Lin, Amber <[email protected]>; Zhu, James <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Koenig, Christian <[email protected]> *Subject:* [PATCH v3] drm/amdgpu: skip xcp drm device allocation when out of drm resource
Return 0 when drm device alloc failed with -ENOSPC in
order to  allow amdgpu drive loading. But the xcp without
drm device node assigned won't be visiable in user space.
This helps amdgpu driver loading on system which has more
than 64 nodes, the current limitation.

The proposal to add more drm nodes is discussed in public, which will support up to 2^20 nodes totally. kernel drm:
https://lore.kernel.org/lkml/[email protected]/T/

libdrm:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/305

(quoted diff) +0 -3
-v2: added warning message
-v3: use dev_warn
---

 drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c   | 13 ++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 10 +++++++++-

 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +6 -1
index 9c9cca129498..565a1fa436d4 100644
@@ -239,8 +239,13 @@ static int amdgpu_xcp_dev_alloc(struct 
 amdgpu_device *adev)
 
          for (i = 1; i < MAX_XCP; i++) {
                  ret = amdgpu_xcp_drm_dev_alloc(&p_ddev);
-               if (ret)
+               if (ret == -ENOSPC) {
+                       dev_warn(adev->dev,
+                       "Skip xcp node #%d when out of drm node 
 resource.", i);
+                       return 0;
+               } else if (ret) {
                          return ret;
+               }
 

                 /* Redirect all IOCTLs to the primary device */ adev->xcp_mgr->xcp[i].rdev = p_ddev->render->dev;

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -0
@@ -328,6 +333,9 @@ int amdgpu_xcp_dev_register(struct amdgpu_device 
 *adev,
                  return 0;
 
          for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                  ret = drm_dev_register(adev->xcp_mgr->xcp[i].ddev, ent->driver_data);
                  if (ret)

                         return ret;

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +3 -0
@@ -345,6 +353,9 @@ void amdgpu_xcp_dev_unplug(struct amdgpu_device 
 *adev)
                  return;
 
          for (i = 1; i < MAX_XCP; i++) {
+               if (!adev->xcp_mgr->xcp[i].ddev)
+                       break;
+
                  p_ddev = adev->xcp_mgr->xcp[i].ddev;
                  drm_dev_unplug(p_ddev);

                 p_ddev->render->dev = adev->xcp_mgr->xcp[i].rdev;

drivers/gpu/drm/amd/amdkfd/kfd_topology.c +9 -1
index 3b0749390388..310df98ba46a 100644
@@ -1969,8 +1969,16 @@ int kfd_topology_add_device(struct kfd_node 
 *gpu)
          int i;
          const char *asic_name = amdgpu_asic_name[gpu->adev->asic_type];
 
+
          gpu_id = kfd_generate_gpu_id(gpu);
-       pr_debug("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+       if (!gpu->xcp->ddev) {
+               dev_warn(gpu->adev->dev,
+               "Won't add GPU (ID: 0x%x) to topology since it has 
 no drm node assigned.",
+               gpu_id);
+               return 0;
+       } else {
+               pr_debug("Adding new GPU (ID: 0x%x) to topology\n", 
 gpu_id);
+       }

         /* Check to see if this gpu device exists in the topology_device_list.
          * If so, assign the gpu to that device,

Signature · 1 line
2.34.1