From: "Mario Limonciello (AMD)" <superm1@kernel.org>
To: amd-gfx@lists.freedesktop.org
Cc: "Mario Limonciello (AMD)" <superm1@kernel.org>
Subject: [PATCH v2 3/3] amdkfd: Add device links between kfd device and amdgpu device
Date: Wed, 10 Dec 2025 14:15:10 -0600 [thread overview]
Message-ID: <20251210201510.3000-4-superm1@kernel.org> (raw)
In-Reply-To: <20251210201510.3000-1-superm1@kernel.org>
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.
Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
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(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index a2879d2b7c8ec..5d6cf3adfa7b8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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);
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index da4575676335f..fd92b227a674b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -272,6 +272,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
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 7a0213a07023d..44c9320d72a56 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -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)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index b65f29294e2d6..796fd411a7dcc 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -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;
@@ -571,6 +602,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) {
diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
index 9aba8596faa7e..f6db1dc634399 100644
--- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
@@ -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 */
--
2.43.0
next prev parent reply other threads:[~2025-12-10 20:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 20:15 [PATCH v2 0/3] Make device links between KFD and GPU device Mario Limonciello (AMD)
2025-12-10 20:15 ` [PATCH v2 1/3] amdkfd: Only ignore -ENOENT for KFD init failuires Mario Limonciello (AMD)
2025-12-10 20:15 ` [PATCH v2 2/3] amdkfd: Don't rebuild node tree when calling kfd_topology_update_sysfs() Mario Limonciello (AMD)
2025-12-10 20:40 ` Russell, Kent
2025-12-16 2:42 ` Kasiviswanathan, Harish
2025-12-10 20:15 ` Mario Limonciello (AMD) [this message]
2025-12-10 20:40 ` [PATCH v2 3/3] amdkfd: Add device links between kfd device and amdgpu device Russell, Kent
2025-12-16 2:45 ` Kasiviswanathan, Harish
2025-12-16 12:20 ` Mario Limonciello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251210201510.3000-4-superm1@kernel.org \
--to=superm1@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.