Skip to contentSkip to conversation

Make device links between KFD and GPU device

PATCH Superseded Mario Limonciello (AMD) 2 participants 4 messages Dec 7, 2025 – Dec 10, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Make device links between KFD and GPU device

Discovering which KFD device is associated with a GPU is relatively awkward right now in userspace.

This series creates sysfs links between the devices to simplify it for userspace.

Mario Limonciello (AMD) (2):
amdkfd: Only ignore -ENOENT for KFD init failuires
amdkfd: Add device links between kfd device and amdgpu device

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |  8 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  4 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  6 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c     | 36 +++++++++++++++++++
 .../gpu/drm/amd/include/kgd_kfd_interface.h   |  2 ++
 6 files changed, 55 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 amdkfd: Only ignore -ENOENT for KFD init failuires

When compiled without CONFIG_HSA_AMD KFD will return -ENOENT. As other errors will cause KFD functionality issues this is the only error code that should be ignored at init.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -2
index 16adeba4d7e68..e804461e5f272 100644
@@ -3169,8 +3169,10 @@ static int __init amdgpu_init(void)
 	amdgpu_register_atpx_handler();
 	amdgpu_acpi_detect();
 
-	/* Ignore KFD init failures. Normal when CONFIG_HSA_AMD is not set. */
-	amdgpu_amdkfd_init();
+	/* Ignore KFD init failures when CONFIG_HSA_AMD is not set. */
+	r = amdgpu_amdkfd_init();
+	if (r && r != -ENOENT)
+		goto error_fence;
 
 	if (amdgpu_pp_feature_mask & PP_OVERDRIVE_MASK) {
 		add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

RE: [PATCH 1/2] amdkfd: Only ignore -ENOENT for KFD init failuires

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 37 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello (AMD)
Sent: Sunday, December 7, 2025 9:04 AM
To: [email protected]
Cc: Mario Limonciello (AMD) <[email protected]>
Subject: [PATCH 1/2] amdkfd: Only ignore -ENOENT for KFD init failuires

When compiled without CONFIG_HSA_AMD KFD will return -ENOENT. As other errors will cause KFD functionality issues this is the only error code that should be ignored at init.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -3
index 16adeba4d7e68..e804461e5f272 100644
@@ -3169,8 +3169,10 @@ static int __init amdgpu_init(void)
      amdgpu_register_atpx_handler();
      amdgpu_acpi_detect();
 
-     /* Ignore KFD init failures. Normal when CONFIG_HSA_AMD is not set. */
-     amdgpu_amdkfd_init();
+     /* Ignore KFD init failures when CONFIG_HSA_AMD is not set. */
+     r = amdgpu_amdkfd_init();
+     if (r && r != -ENOENT)
+             goto error_fence;
 
      if (amdgpu_pp_feature_mask & PP_OVERDRIVE_MASK) {
              add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
--

2.43.0

#3 lore raw

PATCH 2/2 amdkfd: Add device links between kfd device and amdgpu device

In reply to Mario Limonciello (AMD)

Mapping out a KFD device to a GPU can be done manually by looking at the domain and location properties. To make it easier to discover which KFD device goes with what GPU add bidirectional links.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |  8 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  4 +++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c     | 36 +++++++++++++++++++
 .../gpu/drm/amd/include/kgd_kfd_interface.h   |  2 ++
 5 files changed, 51 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8 -0
index a2879d2b7c8ec..5d6cf3adfa7b8 100644
@@ -910,3 +910,11 @@ int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id,
 
 	return r;
 }
+
+int amdgpu_amdkfd_create_sysfs_links(struct amdgpu_device *adev)
+{
+	if (!adev->kfd.init_complete || !adev->kfd.dev)
+		return 0;
+
+	return kgd2kfd_create_sysfs_links(adev->kfd.dev);
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index 2fa5f1925f5a3..542f5bc2dd189 100644
@@ -270,6 +270,7 @@ int amdgpu_amdkfd_stop_sched(struct amdgpu_device *adev, uint32_t node_id);
 int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id,
 	bool core_override_enable, bool reg_override_enable, bool perfmon_override_enable);
 bool amdgpu_amdkfd_compute_active(struct amdgpu_device *adev, uint32_t node_id);
+int amdgpu_amdkfd_create_sysfs_links(struct amdgpu_device *adev);
 
 
 /* Read user wptr from a specified user address space with page fault
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -0
index 7a0213a07023d..44c9320d72a56 100644
@@ -4947,6 +4947,10 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	 */
 	r = amdgpu_device_sys_interface_init(adev);
 
+	r = amdgpu_amdkfd_create_sysfs_links(adev);
+	if (r)
+		dev_err(adev->dev, "Failed to create KFD sysfs link: %d\n", r);
+
 	if (IS_ENABLED(CONFIG_PERF_EVENTS))
 		r = amdgpu_pmu_init(adev);
 	if (r)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +36 -0
index 9c3e8f946a3d5..be673e35978eb 100644
@@ -79,6 +79,37 @@ struct kfd_topology_device *kfd_topology_device_by_proximity_domain(
 	return device;
 }
 
+int kgd2kfd_create_sysfs_links(struct kfd_dev *kfd)
+{
+	struct kfd_topology_device *top_dev;
+	int ret = -ENODEV;
+
+	if (!kfd)
+		return -EINVAL;
+
+	down_read(&topology_lock);
+
+	list_for_each_entry(top_dev, &topology_device_list, list) {
+		struct kobject *amdgpu_kobj;
+
+		if (!top_dev->gpu || top_dev->gpu->kfd != kfd || !top_dev->kobj_node)
+			continue;
+
+		amdgpu_kobj = &top_dev->gpu->adev->dev->kobj;
+		ret = sysfs_create_link(top_dev->kobj_node, amdgpu_kobj, "device");
+		if (ret)
+			break;
+
+		ret = sysfs_create_link(amdgpu_kobj, top_dev->kobj_node, "kfd");
+		if (ret)
+			sysfs_remove_link(top_dev->kobj_node, "device");
+		break;
+	}
+
+	up_read(&topology_lock);
+	return ret;
+}
+
 struct kfd_topology_device *kfd_topology_device_by_id(uint32_t gpu_id)
 {
 	struct kfd_topology_device *top_dev = NULL;
@@ -567,6 +598,11 @@ static void kfd_remove_sysfs_node_entry(struct kfd_topology_device *dev)
 	struct kfd_mem_properties *mem;
 	struct kfd_perf_properties *perf;
 
+	if (dev->gpu) {
+		sysfs_remove_link(dev->kobj_node, "device");
+		sysfs_remove_link(&dev->gpu->adev->dev->kobj, "kfd");
+	}
+
 	if (dev->kobj_iolink) {
 		list_for_each_entry(iolink, &dev->io_link_props, list)
 			if (iolink->kobj) {
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +2 -0
index 9aba8596faa7e..f6db1dc634399 100644
@@ -335,4 +335,6 @@ struct kfd2kgd_calls {
 					  int engine, int queue);
 };
 
+int kgd2kfd_create_sysfs_links(struct kfd_dev *kfd);
+
 #endif	/* KGD_KFD_INTERFACE_H_INCLUDED */
Signature · 1 line
2.43.0