Make device links between KFD and GPU device
Subsystems (3)
v3 cover Make device links between KFD and GPU device
Discovering which GPU device is associated with a KFD node is relatively awkward right now in userspace.
This series creates a link from KFD to GPU 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 | 17 ++++++++++++++++- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 2 ++ 6 files changed, 35 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 2/2 amdkfd: Add device links between kfd device and amdgpu device
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 a link to the GPU node.
---
Cc: [email protected]>
v3:
* Create link when topology created
* Only call update topology when amdgpu is called
--- 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 | 17 ++++++++++++++++- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 2 ++ 5 files changed, 31 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8 -0
@@ -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 kfd_topology_update_sysfs (); +}
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
@@ -268,6 +268,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
@@ -5123,6 +5123,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 +16 -1
@@ -571,6 +571,9 @@ 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" ); +if (dev->kobj_iolink) {list_for_each_entry (iolink, &dev->io_link_props, list)if (iolink->kobj) {
@@ -819,6 +822,18 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,return ret; } +/* +* create a link to the GPU node, but don't do a reverse one since it might +* not match after spatial partitioning +*/ +if (dev->gpu) { +struct kobject *amdgpu_kobj = &dev->gpu->adev->dev->kobj; + + ret =sysfs_create_link (dev->kobj_node, amdgpu_kobj,"device" ); +if (ret) +return ret; + } +return 0 ; }
@@ -848,7 +863,7 @@ static void kfd_remove_sysfs_node_tree(void)kfd_remove_sysfs_node_entry (dev); } -static int kfd_topology_update_sysfs (void ) +int kfd_topology_update_sysfs (void ) {int ret;
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +2 -0
@@ -335,4 +335,6 @@ struct kfd2kgd_calls { int engine, int queue); }; +int kfd_topology_update_sysfs (void ); +#endif /* KGD_KFD_INTERFACE_H_INCLUDED */
Signature · 1 line
2.43.0
PATCH v3 1/2 amdkfd: Only ignore -ENOENT for KFD init failuires
In reply to Mario Limonciello (AMD)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
@@ -3177,8 +3177,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
Re: [PATCH v3 2/2] amdkfd: Add device links between kfd device and amdgpu device
In reply to Mario Limonciello (AMD)Quoted 4 lines · 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 a link to the GPU node.
Access to the full device is not desirable in container environments where it is restricted to the particular partition's properties.
Thanks,
Lijo
Quoted 110 lines
Signed-off-by Mario Limonciello (AMD) <[email protected]>---
Cc: [email protected]>
v3:
* Create link when topology created
* Only call update topology when amdgpu is called--- 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 | 17 ++++++++++++++++- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 2 ++ 5 files changed, 31 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0@@ -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 kfd_topology_update_sysfs (); +}drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-0@@ -268,6 +268,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@@ -5123,6 +5123,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 +16
-1@@ -571,6 +571,9 @@ 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" ); +if (dev->kobj_iolink) {list_for_each_entry (iolink, &dev->io_link_props, list)if (iolink->kobj) {@@ -819,6 +822,18 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev,return ret; } +/* +* create a link to the GPU node, but don't do a reverse one since it might +* not match after spatial partitioning +*/ +if (dev->gpu) { +struct kobject *amdgpu_kobj = &dev->gpu->adev->dev->kobj; + + ret =sysfs_create_link (dev->kobj_node, amdgpu_kobj,"device" ); +if (ret) +return ret; + } +return 0 ; }@@ -848,7 +863,7 @@ static void kfd_remove_sysfs_node_tree(void)kfd_remove_sysfs_node_entry (dev); } -static int kfd_topology_update_sysfs (void ) +int kfd_topology_update_sysfs (void ) {int ret;drivers/gpu/drm/amd/include/kgd_kfd_interface.h +2
-0@@ -335,4 +335,6 @@ struct kfd2kgd_calls { int engine, int queue); }; +int kfd_topology_update_sysfs (void ); +#endif /* KGD_KFD_INTERFACE_H_INCLUDED */
Re: [PATCH v3 2/2] amdkfd: Add device links between kfd device and amdgpu device
Quoted 10 lines · Lijo
Quoted 4 lines · 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 a link to the GPU node.
Access to the full device is not desirable in container environments where it is restricted to the particular partition's properties.
Container environments don't typically bind mount the whole sysfs tree do they?
Nonetheless; even if they did this information is already discoverable, it's just a PIA to get to.
Quoted 109 lines
Thanks,
LijoQuoted 105 lines
Signed-off-by Mario Limonciello (AMD) <[email protected]>---
Cc: [email protected]>
v3:
* Create link when topology created
* Only call update topology when amdgpu is called
---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 | 17 ++++++++++++++++- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 2 ++ 5 files changed, 31 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0@@ -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 kfd_topology_update_sysfs(); +}drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-0@@ -268,6 +268,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 faultdrivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0@@ -5123,6 +5123,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 +5
-0@@ -571,6 +571,9 @@ 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"); + if (dev->kobj_iolink) { list_for_each_entry(iolink, &dev->io_link_props, list) if (iolink->kobj) {@@ -819,6 +822,18 @@ static int kfd_build_sysfs_node_entry(structkfd_topology_device *dev, return ret; } + /* +* create a link to the GPU node, but don't do a reverse one since it might
+ * not match after spatial partitioning
+ */
+ if (dev->gpu) {
+ struct kobject*amdgpu_kobj=&dev->gpu->adev->dev->kobj;drivers/gpu/drm/amd/amdkfd/kfd_topology.c +6
-0+ + ret = sysfs_create_link(dev->kobj_node, amdgpu_kobj, "device"); + if (ret) + return ret; + } +return 0;
}drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-1@@ -848,7 +863,7 @@ static void kfd_remove_sysfs_node_tree(void) kfd_remove_sysfs_node_entry(dev); } -static int kfd_topology_update_sysfs (void ) +int kfd_topology_update_sysfs (void ) { int ret;drivers/gpu/drm/amd/include/kgd_kfd_interface.h +2
-0@@ -335,4 +335,6 @@ struct kfd2kgd_calls { int engine, int queue); }; +int kfd_topology_update_sysfs (void ); + #endif /* KGD_KFD_INTERFACE_H_INCLUDED */
Re: [PATCH v3 2/2] amdkfd: Add device links between kfd device and amdgpu device
Quoted 11 lines · Mario Limonciello
Quoted 8 lines · Lijo
Quoted 4 lines · 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 a link to the GPU node.
Quoted 5 lines
Quoted 2 lines
Access to the full device is not desirable in container environments where it is restricted to the particular partition's properties.
Container environments don't typically bind mount the whole sysfs tree do they?
AFAIK, only selected ones and access restricted through cgroups.
Thanks,
Lijo
Quoted 113 lines
Nonetheless; even if they did this information is already discoverable, it's just a PIA to get to.
Quoted 110 lines
Thanks,
LijoQuoted 106 lines
Signed-off-by Mario Limonciello (AMD) <[email protected]>---
Cc: [email protected]>
v3:
* Create link when topology created
* Only call update topology when amdgpu is called
---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 | 17 ++++++++++++++++- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 2 ++ 5 files changed, 31 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0@@ -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 kfd_topology_update_sysfs(); +}drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-0@@ -268,6 +268,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 faultdrivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0@@ -5123,6 +5123,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 +5
-0@@ -571,6 +571,9 @@ 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"); + if (dev->kobj_iolink) { list_for_each_entry(iolink, &dev->io_link_props, list) if (iolink->kobj) {@@ -819,6 +822,18 @@ static int kfd_build_sysfs_node_entry(structkfd_topology_device *dev, return ret; } + /* +* create a link to the GPU node, but don't do a reverse one since it might
+ * not match after spatial partitioning
+ */
+ if (dev->gpu) {
+ struct kobject*amdgpu_kobj=&dev->gpu->adev->dev->kobj;drivers/gpu/drm/amd/amdkfd/kfd_topology.c +6
-0+ + ret = sysfs_create_link(dev->kobj_node, amdgpu_kobj, "device"); + if (ret) + return ret; + } +return 0;
}drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-1@@ -848,7 +863,7 @@ static void kfd_remove_sysfs_node_tree(void) kfd_remove_sysfs_node_entry(dev); } -static int kfd_topology_update_sysfs (void ) +int kfd_topology_update_sysfs (void ) { int ret;drivers/gpu/drm/amd/include/kgd_kfd_interface.h +2
-0@@ -335,4 +335,6 @@ struct kfd2kgd_calls { int engine, int queue); }; +int kfd_topology_update_sysfs (void ); + #endif /* KGD_KFD_INTERFACE_H_INCLUDED */
Re: [PATCH v3 2/2] amdkfd: Add device links between kfd device and amdgpu device
Quoted 14 lines · Lijo
Quoted 11 lines · Mario Limonciello
Quoted 8 lines · Lijo
Quoted 4 lines · 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 a link to the GPU node.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Access to the full device is not desirable in container environments where it is restricted to the particular partition's properties.
Container environments don't typically bind mount the whole sysfs tree do they?
AFAIK, only selected ones and access restricted through cgroups.
The information needed to discover is definitely already exposed.
❯ cat /sys/class/kfd/kfd/topology/nodes/1/properties | grep "domain\|location_id\|vendor_id\|device_id" vendor_id 4098device_id 5510location_id 49664
domain 0
But so what's going to happen with the new symlink then? Would cgroups export it if the device it points to wasn't exported?
I'm not sure how to try this myself.
Quoted 121 lines
Thanks,
LijoQuoted 116 lines
Nonetheless; even if they did this information is already discoverable, it's just a PIA to get to.
Quoted 113 lines
Thanks,
LijoQuoted 109 lines
Signed-off-by Mario Limonciello (AMD) <[email protected]>---
Cc: [email protected]>
v3:
* Create link when topology created
* Only call update topology when amdgpu is called
---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 | 17 +++++++++++++ +++- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 2 ++ 5 files changed, 31 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0@@ -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 kfd_topology_update_sysfs(); +}drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-0@@ -268,6 +268,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 faultdrivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0@@ -5123,6 +5123,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 +5
-0@@ -571,6 +571,9 @@ 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"); + if (dev->kobj_iolink) { list_for_each_entry(iolink, &dev->io_link_props, list) if (iolink->kobj) {@@ -819,6 +822,18 @@ static int kfd_build_sysfs_node_entry(structkfd_topology_device *dev, return ret; } + /* +* create a link to the GPU node, but don't do a reverse one since it might
+ * not match after spatial partitioning
+ */
+ if (dev->gpu) {
+ struct kobject*amdgpu_kobj=&dev->gpu->adev->dev->kobj; +
+ ret =sysfs_create_link(dev->kobj_node, amdgpu_kobj, "device");
+ if (ret)
+ return ret;
+ }
+
return 0;
}drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-1@@ -848,7 +863,7 @@ static void kfd_remove_sysfs_node_tree(void) kfd_remove_sysfs_node_entry(dev); } -static int kfd_topology_update_sysfs (void ) +int kfd_topology_update_sysfs (void ) { int ret;drivers/gpu/drm/amd/include/kgd_kfd_interface.h +2
-0@@ -335,4 +335,6 @@ struct kfd2kgd_calls { int engine, int queue); }; +int kfd_topology_update_sysfs (void ); + #endif /* KGD_KFD_INTERFACE_H_INCLUDED */
Re: [PATCH v3 2/2] amdkfd: Add device links between kfd device and amdgpu device
To try this scenario, you can do the following.
$ set partition mode to QPX $ run docker but instead of /dev/dri use /dev/dri/renderD128 --> this way the container can access only one single partition of QPX. # inside docker ## run rocminfo --> you should only see one device ## In /sys/class/kfd/kfd/topology/nodes --> you could see the all 4 nodes but only /sys/class/kfd/kfd/topology/nodes/1/ will be accessible
This was designed this way as hiding the nodes was hard to architecture. Hence, from the container the nodes list is visible but access is based on cgroups. So, with /dev/dri/renderDXXX only one of the /sys/class/kfd/kfd/topology/nodes/X/ will be visible and usable.
________________________________________
From: Mario Limonciello <[email protected]>
Sent: Tuesday, December 16, 2025 9:01 AM
To: Lazar, Lijo <[email protected]>; [email protected] <[email protected]> Cc: Kasiviswanathan, Harish <[email protected]>
Subject: Re: [PATCH v3 2/2] amdkfd: Add device links between kfd device and amdgpu device
Quoted 40 lines · Lijo
Quoted 33 lines · Mario Limonciello
Quoted 18 lines · Lijo
Quoted 9 lines · 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 a link to the GPU node.
Quoted 5 lines
Access to the full device is not desirable in container environments
where it is restricted to the particular partition's properties.
Container environments don't typically bind mount the whole sysfs tree
Quoted 7 lines
Quoted 3 lines
do they?
AFAIK, only selected ones and access restricted through cgroups.
The information needed to discover is definitely already exposed.
❯ cat /sys/class/kfd/kfd/topology/nodes/1/properties | grep
"domain\|location_id\|vendor_id\|device_id"
vendor_id 4098
device_id 5510
location_id 49664
domain 0
But so what's going to happen with the new symlink then? Would cgroups
export it if the device it points to wasn't exported?
I'm not sure how to try this myself.
Quoted 259 lines
Thanks,
Lijo
Quoted 249 lines
Nonetheless; even if they did this information is already
discoverable, it's just a PIA to get to.
Quoted 241 lines
Thanks,
Lijo
Quoted 233 lines
Signed-off-by Mario Limonciello (AMD) <[email protected]>---
v3:
* Create link when topology created
* Only call update topology when amdgpu is called
---
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 | 17 +++++++++++++
+++-
drivers/gpu/drm/amd/include/kgd_kfd_interface.h| 2 ++5 files changed, 31 insertions(+), 1 deletion(-)drivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-0gpu/
drm/amd/amdgpu/amdgpu_amdkfd.cindex
67a01c4f38855..870a727d6e938100644---
a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c+++
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.cdrivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-0@@ -910,3 +910,11 @@ int amdgpu_amdkfd_config_sq_perfmon(struct amdgpu_device *adev, uint32_t xcp_id,return r;
}
drivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0+ +int amdgpu_amdkfd_create_sysfs_links(struct amdgpu_device *adev) +{ + if (!adev->kfd.init_complete || !adev->kfd.dev) + return 0; + + return kfd_topology_update_sysfs(); +}drivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0
-0gpu/
drm/amd/amdgpu/amdgpu_amdkfd.hindex
8bdfcde2029b5..07aa519b28d45100644---
a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h+++
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.hdrivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0
-0@@ -268,6 +268,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, boolreg_override_enable, bool
perfmon_override_enable);bool amdgpu_amdkfd_compute_active(struct
amdgpu_device*adev,
uint32_tnode_id);+int
amdgpu_amdkfd_create_sysfs_links(struct amdgpu_device *adev);/* Read user wptr from a specified user address space with page fault
drivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0gpu/
drm/amd/amdgpu/amdgpu_device.cindex
467326871a81e..d4c8b03b6bf57100644---
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c+++
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cdrivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -5123,6 +5123,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/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0
-0gpu/
drm/amd/amdkfd/kfd_topology.cindex
a95be23fd0397..5f14c66902f9d100644---
a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c+++
b/drivers/gpu/drm/amd/amdkfd/kfd_topology.cdrivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3
-0@@ -571,6 +571,9 @@ 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"); +if (
dev->kobj_iolink) {
list_for_each_entry(iolink, &dev->io_link_props, list)if (
iolink->kobj) {drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2
-0@@ -819,6 +822,18 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev, return ret; } + /* + * create a link to the GPU node, but don't do a reverse onesince it might
+ * not match after spatial partitioning
+ */
+ if (
dev->gpu) {+ struct kobject
*amdgpu_kobj=&dev->gpu->adev->dev->kobj;+
+ ret = sysfs_create_link(dev->kobj_node,
amdgpu_kobj,"device");
+ if (ret)
+ return ret;
+ }
+
return 0;
}
drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-1@@ -848,7 +863,7 @@ static void kfd_remove_sysfs_node_tree(void) kfd_remove_sysfs_node_entry(dev); } -static int kfd_topology_update_sysfs(void) +int kfd_topology_update_sysfs(void){
int ret;
(quoted diff) renamed from drivers/gpu/drm/amd/include/kgd_kfd_interface.h +0
-0
drivers/gpu/drm/amd/include/kgd_kfd_interface.hindex
9aba8596faa7e..0ee1a7d3a73f5100644---
a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h+++
b/drivers/gpu/drm/amd/include/kgd_kfd_interface.hdrivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2
-0@@ -335,4 +335,6 @@ struct kfd2kgd_calls { int engine, int queue); }; +int kfd_topology_update_sysfs(void); +#endif /*
KGD_KFD_INTERFACE_H_INCLUDED*/
Re: [PATCH v3 2/2] amdkfd: Add device links between kfd device and amdgpu device
Quoted 1 line · Harish
To try this scenario, you can do the following.
Ah I don't have an Instinct on my side to try this, only multiple radeon cards.
Quoted 9 lines
$ set partition mode to QPX $ run docker but instead of /dev/dri use /dev/dri/renderD128 --> this way the container can access only one single partition of QPX. # inside docker ## run rocminfo --> you should only see one device ## In /sys/class/kfd/kfd/topology/nodes --> you could see the all 4 nodes but only /sys/class/kfd/kfd/topology/nodes/1/ will be accessibleThis was designed this way as hiding the nodes was hard to architecture. Hence, from the container the nodes list is visible but access is based on cgroups. So, with
/dev/dri/renderDXXXonly one of the/sys/class/kfd/kfd/topology/nodes/X/will be visible and usable.
But so shouldn't /sys/class/drm/renderD128 also be exposed too then? This has a device sub-link too which should match what this change does.
I would expect this also exposes.
❯ ls -alh /sys/class/drm/renderD128/ | grep device
lrwxrwxrwx - root 16 Dec 08:40 device -> ../../../0000:c2:00.0
Quoted 351 lines
________________________________________
From: Mario Limonciello <[email protected]>
Sent: Tuesday, December 16, 2025 9:01 AM
To: Lazar, Lijo <[email protected]>; [email protected] <[email protected]> Cc: Kasiviswanathan, Harish <[email protected]>
Subject: Re: [PATCH v3 2/2] amdkfd: Add device links between kfd device and amdgpu deviceQuoted 40 lines · Lijo
Quoted 33 lines · Mario Limonciello
Quoted 18 lines · Lijo
Quoted 9 lines · 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 a link to the GPU node.
Quoted 5 lines
Access to the full device is not desirable in container environments
where it is restricted to the particular partition's properties.
Container environments don't typically bind mount the whole sysfs tree
Quoted 7 lines
Quoted 3 lines
do they?
AFAIK, only selected ones and access restricted through cgroups.
The information needed to discover is definitely already exposed.
❯ cat
/sys/class/kfd/kfd/topology/nodes/1/properties| grep"domain\|location_id\|vendor_id\|device_id"
vendor_id4098
device_id5510
location_id49664domain 0
But so what's going to happen with the new symlink then? Would cgroups
export it if the device it points to wasn't exported?
I'm not sure how to try this myself.
Quoted 259 lines
Thanks,
Lijo
Quoted 249 lines
Nonetheless; even if they did this information is already
discoverable, it's just a PIA to get to.
Quoted 241 lines
Thanks,
Lijo
Quoted 233 lines
Signed-off-by Mario Limonciello (AMD) <[email protected]>---
v3:
* Create link when topology created
* Only call update topology when amdgpu is called
---
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 | 17 ++++++++++++++++-
drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 2 ++5 files changed, 31 insertions(+), 1 deletion(-)drivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-0gpu/
drm/amd/amdgpu/amdgpu_amdkfd.cindex
67a01c4f38855..870a727d6e938100644---
a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c+++
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.cdrivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0@@ -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 kfd_topology_update_sysfs(); +}drivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0
-0gpu/
drm/amd/amdgpu/amdgpu_amdkfd.hindex
8bdfcde2029b5..07aa519b28d45100644---
a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h+++
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.hdrivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +0
-0@@ -268,6 +268,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_tnode_id);drivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-0+int amdgpu_amdkfd_create_sysfs_links(struct amdgpu_device *adev); /* Read user wptr from a specified user address space with page faultdrivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0gpu/
drm/amd/amdgpu/amdgpu_device.cindex
467326871a81e..d4c8b03b6bf57100644---
a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c+++
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.cdrivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -5123,6 +5123,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);
drivers/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0+ if (IS_ENABLED(CONFIG_PERF_EVENTS)) r = amdgpu_pmu_init(adev); if (r)drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0
-0gpu/
drm/amd/amdkfd/kfd_topology.cindex
a95be23fd0397..5f14c66902f9d100644---
a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c+++
b/drivers/gpu/drm/amd/amdkfd/kfd_topology.cdrivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +5
-0@@ -571,6 +571,9 @@ 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"); + if (dev->kobj_iolink) { list_for_each_entry(iolink, &dev->io_link_props, list) if (iolink->kobj) {@@ -819,6 +822,18 @@ static int kfd_build_sysfs_node_entry(struct kfd_topology_device *dev, return ret; } + /* + * create a link to the GPU node, but don't do a reverse onesince it might
+ * not match after spatial partitioning
+ */
+ if (
dev->gpu) {+ struct kobject
*amdgpu_kobj=&dev->gpu->adev->dev->kobj;+
+ ret = sysfs_create_link(dev->kobj_node,
amdgpu_kobj,"device");
+ if (ret)
+ return ret;
+ }
drivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2
-1+ return 0; }@@ -848,7 +863,7 @@ static void kfd_remove_sysfs_node_tree(void) kfd_remove_sysfs_node_entry(dev); } -static int kfd_topology_update_sysfs(void) +int kfd_topology_update_sysfs(void){
int ret;
(quoted diff) renamed from drivers/gpu/drm/amd/include/kgd_kfd_interface.h +0
-0
drivers/gpu/drm/amd/include/kgd_kfd_interface.hindex
9aba8596faa7e..0ee1a7d3a73f5100644---
a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h+++
b/drivers/gpu/drm/amd/include/kgd_kfd_interface.hdrivers/ renamed from drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2
-0@@ -335,4 +335,6 @@ struct kfd2kgd_calls { int engine, int queue); }; +int kfd_topology_update_sysfs(void); + #endif /* KGD_KFD_INTERFACE_H_INCLUDED */