drm/amdgpu: Ensure that harvest information gets set
Subsystems (2)
PATCH 1/1 drm/amdgpu: Ensure that harvest information gets set
After the earlier patch exported IP discovery on probe failure, there was an unexpected consequence where harvest info was not populated. The early-exit in amdgpu_discovery_sysfs_init meant that we never called amdgpu_discovery_get_harvest_info, which is where we set the actual harvest value. The first time we call amdgpu_discovery_sysfs_recurse with NULL instead of adev, most values can get set. The 2nd time amdgpu_discovery_sysfs_recurse is called, we bail early.
To keep the logic of the first patch intact, ensuring that older kernels can still discover the IP blocks, add a separate call in the early-exit section that sets the harvest information.
This should be the only functionality that is missed in this flow, as the rest of the calls either work fine with adev=NULL, or use the discovery_bin directly.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +40 -4
@@ -1469,6 +1469,40 @@ static int amdgpu_discovery_sysfs_recurse(struct amdgpu_device *adev,return 0 ; } +#define list_to_kobj (el) container_of(el, struct kobject, entry) + +static void amdgpu_discovery_sysfs_update_harvest (struct amdgpu_device *adev) +{ +struct ip_discovery_top *ip_top = adev->discovery.ip_top; +struct ip_die_entry *ip_die_entry; +struct list_head *el_die, *el_hw_id, *el_hw_inst; +struct ip_hw_id *hw_id; +struct kset *die_kset; +struct ip_hw_instance *ip_inst; + +if (!ip_top) +return ; + + die_kset = &ip_top->die_kset; + +guard (spinlock)(&die_kset->list_lock); +list_for_each (el_die, &die_kset->list) { + ip_die_entry =to_ip_die_entry (list_to_kobj (el_die)); + +list_for_each (el_hw_id, &ip_die_entry->ip_kset.list) { + hw_id =to_ip_hw_id (list_to_kobj (el_hw_id)); + +list_for_each (el_hw_inst, &hw_id->hw_id_kset.list) { + ip_inst =to_ip_hw_instance (list_to_kobj (el_hw_inst)); + ip_inst->harvest = +amdgpu_discovery_get_harvest_info ( + adev, ip_inst->hw_id, + ip_inst->num_instance); + } + } + } +} +static int amdgpu_discovery_sysfs_init (struct amdgpu_device *adev) {uint8_t *discovery_bin = adev->discovery.bin;
@@ -1479,9 +1513,13 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev)if (!discovery_bin)return -EINVAL ; -/* If early init already created sysfs in standalone mode, skip normal init */ -if (adev->discovery.ip_top && adev->discovery.ip_top->standalone_mode) +/* If early init already created sysfs in standalone mode, update harvest info +* now that adev is fully initialized, then skip the rest of normal init. +*/ +if (adev->discovery.ip_top && adev->discovery.ip_top->standalone_mode) { +amdgpu_discovery_sysfs_update_harvest (adev);return 0 ; + } ip_top =kzalloc_obj (*ip_top);if (!ip_top)
@@ -1536,8 +1574,6 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev)/* -------------------------------------------------- */ -#define list_to_kobj (el) container_of(el, struct kobject, entry) -static void amdgpu_discovery_sysfs_ip_hw_free (struct ip_hw_id *ip_hw_id) {struct list_head *el, *tmp;
Signature · 1 line
2.43.0
Quoted 12 lines · Kent Russell
After the earlier patch exported IP discovery on probe failure, there was an unexpected consequence where harvest info was not populated. The early-exit in
amdgpu_discovery_sysfs_initmeant that we never calledamdgpu_discovery_get_harvest_info, which is where we set the actual harvest value. The first time we callamdgpu_discovery_sysfs_recursewith NULL instead of adev, most values can get set. The 2nd timeamdgpu_discovery_sysfs_recurseis called, we bail early.To keep the logic of the first patch intact, ensuring that older kernels can still discover the IP blocks, add a separate call in the early-exit section that sets the harvest information.
Quoted 7 lines
This should be the only functionality that is missed in this flow, as the rest of the calls either work fine with adev=NULL, or use the
discovery_bindirectly.Fixes 3ee1065e9830 ("drm/amdgpu: Export ip_discovery sysfs on probe failure")Assisted-by LLM ClaudeSigned-off-by Kent Russell <[email protected]>
Quoted 74 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +40
-4@@ -1469,6 +1469,40 @@ static int amdgpu_discovery_sysfs_recurse(struct amdgpu_device *adev,return 0 ; } +#define list_to_kobj (el) container_of(el, struct kobject, entry) + +static void amdgpu_discovery_sysfs_update_harvest (struct amdgpu_device *adev) +{ +struct ip_discovery_top *ip_top = adev->discovery.ip_top; +struct ip_die_entry *ip_die_entry; +struct list_head *el_die, *el_hw_id, *el_hw_inst; +struct ip_hw_id *hw_id; +struct kset *die_kset; +struct ip_hw_instance *ip_inst; + +if (!ip_top) +return ; + + die_kset = &ip_top->die_kset; + +guard (spinlock)(&die_kset->list_lock); +list_for_each (el_die, &die_kset->list) { + ip_die_entry =to_ip_die_entry (list_to_kobj (el_die)); + +list_for_each (el_hw_id, &ip_die_entry->ip_kset.list) { + hw_id =to_ip_hw_id (list_to_kobj (el_hw_id)); + +list_for_each (el_hw_inst, &hw_id->hw_id_kset.list) { + ip_inst =to_ip_hw_instance (list_to_kobj (el_hw_inst)); + ip_inst->harvest = +amdgpu_discovery_get_harvest_info ( + adev, ip_inst->hw_id, + ip_inst->num_instance); + } + } + } +} +static int amdgpu_discovery_sysfs_init (struct amdgpu_device *adev) {uint8_t *discovery_bin = adev->discovery.bin;@@ -1479,9 +1513,13 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev)if (!discovery_bin)return -EINVAL ; -/* If early init already created sysfs in standalone mode, skip normal init */ -if (adev->discovery.ip_top && adev->discovery.ip_top->standalone_mode) +/* If early init already created sysfs in standalone mode, update harvest info +* now that adev is fully initialized, then skip the rest of normal init. +*/ +if (adev->discovery.ip_top && adev->discovery.ip_top->standalone_mode) { +amdgpu_discovery_sysfs_update_harvest (adev);return 0 ; + } ip_top =kzalloc_obj (*ip_top);if (!ip_top)@@ -1536,8 +1574,6 @@ static int amdgpu_discovery_sysfs_init(struct amdgpu_device *adev)/* -------------------------------------------------- */ -#define list_to_kobj (el) container_of(el, struct kobject, entry) -static void amdgpu_discovery_sysfs_ip_hw_free (struct ip_hw_id *ip_hw_id) {struct list_head *el, *tmp;