drm/amdkfd: Fix the warning of array-index-out-of-bounds
Subsystems (3)
PATCH v3 1/1 drm/amdkfd: Fix the warning of array-index-out-of-bounds
For some GPUs with more CUs, the original sibling_map[32]
in struct crat_subtype_cache is not enough
to save the cache information when create the VCRAT table,
so skip filling the struct crat_subtype_cache info instead
fill struct kfd_cache_properties directly to fix this problem.
v3:
- Drop processor id calc function
v2:
- Remove unnecessary sys interface "cache_ext"
--- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 307 +++------------------- drivers/gpu/drm/amd/amdkfd/kfd_crat.h | 12 + drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 238 ++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_topology.h | 5 +- 4 files changed, 278 insertions(+), 284 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +33 -274
@@ -50,16 +50,6 @@ static inline unsigned int get_and_inc_gpu_processor_id(return current_id; } -/* Static table to describe GPU Cache information */ -struct kfd_gpu_cache_info { -uint32_t cache_size; -uint32_t cache_level; -uint32_t flags; -/* Indicates how many Compute Units share this cache -* within a SA. Value = 1 indicates the cache is not shared -*/ -uint32_t num_cu_shared; -};static struct kfd_gpu_cache_info kaveri_cache_info[] = { {
@@ -1023,9 +1013,13 @@ static int kfd_parse_subtype_cache(struct crat_subtype_cache *cache, props->cachelines_per_tag = cache->lines_per_tag; props->cache_assoc = cache->associativity; props->cache_latency = cache->cache_latency; +memcpy (props->sibling_map, cache->sibling_map,sizeof (props->sibling_map)); +/* set the sibling_map_size as 32 for CRAT from ACPI */ + props->sibling_map_size =CRAT_SIBLINGMAP_SIZE ; +if (cache->flags &CRAT_CACHE_FLAGS_DATA_CACHE ) props->cache_type |=HSA_CACHE_TYPE_DATA ;if (cache->flags &CRAT_CACHE_FLAGS_INST_CACHE )
@@ -1243,124 +1237,6 @@ int kfd_parse_crat_table(void *crat_image, struct list_head *device_list,return ret; } -/* Helper function. See kfd_fill_gpu_cache_info for parameter description */ -static int fill_in_l1_pcache (struct crat_subtype_cache *pcache, -struct kfd_gpu_cache_info *pcache_info, -struct kfd_cu_info *cu_info, -int mem_available, -int cu_bitmask, -int cache_type,unsigned int cu_processor_id, -int cu_block) -{ -unsigned int cu_sibling_map_mask; -int first_active_cu; - -/* First check if enough memory is available */ -if (sizeof (struct crat_subtype_cache ) > mem_available) -return -ENOMEM ; - - cu_sibling_map_mask = cu_bitmask; - cu_sibling_map_mask >>= cu_block; - cu_sibling_map_mask &= - ((1 << pcache_info[cache_type].num_cu_shared) -1 ); - first_active_cu =ffs (cu_sibling_map_mask); - -/* CU could be inactive. In case of shared cache find the first active -* CU. and incase of non-shared cache check if the CU is inactive. If -* inactive active skip it -*/ -if (first_active_cu) { -memset (pcache,0 ,sizeof (struct crat_subtype_cache )); - pcache->type =CRAT_SUBTYPE_CACHE_AFFINITY ; - pcache->length =sizeof (struct crat_subtype_cache ); - pcache->flags = pcache_info[cache_type].flags; - pcache->processor_id_low = cu_processor_id - + (first_active_cu -1 ); - pcache->cache_level = pcache_info[cache_type].cache_level; - pcache->cache_size = pcache_info[cache_type].cache_size; - -/* Sibling map is w.r.t processor_id_low, so shift out -* inactive CU -*/ - cu_sibling_map_mask = - cu_sibling_map_mask >> (first_active_cu -1 ); - - pcache->sibling_map[0 ] = (uint8_t )(cu_sibling_map_mask &0xFF ); - pcache->sibling_map[1 ] = - (uint8_t )((cu_sibling_map_mask >>8 ) &0xFF ); - pcache->sibling_map[2 ] = - (uint8_t )((cu_sibling_map_mask >>16 ) &0xFF ); - pcache->sibling_map[3 ] = - (uint8_t )((cu_sibling_map_mask >>24 ) &0xFF ); -return 0 ; - } -return 1 ; -} - -/* Helper function. See kfd_fill_gpu_cache_info for parameter description */ -static int fill_in_l2_l3_pcache (struct crat_subtype_cache *pcache, -struct kfd_gpu_cache_info *pcache_info, -struct kfd_cu_info *cu_info, -int mem_available, -int cache_type,unsigned int cu_processor_id) -{ -unsigned int cu_sibling_map_mask; -int first_active_cu; -int i, j, k; - -/* First check if enough memory is available */ -if (sizeof (struct crat_subtype_cache ) > mem_available) -return -ENOMEM ; - - cu_sibling_map_mask = cu_info->cu_bitmap[0 ][0 ]; - cu_sibling_map_mask &= - ((1 << pcache_info[cache_type].num_cu_shared) -1 ); - first_active_cu =ffs (cu_sibling_map_mask); - -/* CU could be inactive. In case of shared cache find the first active -* CU. and incase of non-shared cache check if the CU is inactive. If -* inactive active skip it -*/ -if (first_active_cu) { -memset (pcache,0 ,sizeof (struct crat_subtype_cache )); - pcache->type =CRAT_SUBTYPE_CACHE_AFFINITY ; - pcache->length =sizeof (struct crat_subtype_cache ); - pcache->flags = pcache_info[cache_type].flags; - pcache->processor_id_low = cu_processor_id - + (first_active_cu -1 ); - pcache->cache_level = pcache_info[cache_type].cache_level; - pcache->cache_size = pcache_info[cache_type].cache_size; - -/* Sibling map is w.r.t processor_id_low, so shift out -* inactive CU -*/ - cu_sibling_map_mask = - cu_sibling_map_mask >> (first_active_cu -1 ); - k =0 ; -for (i =0 ; i < cu_info->num_shader_engines; i++) { -for (j =0 ; j < cu_info->num_shader_arrays_per_engine; - j++) { - pcache->sibling_map[k] = - (uint8_t )(cu_sibling_map_mask &0xFF ); - pcache->sibling_map[k+1 ] = - (uint8_t )((cu_sibling_map_mask >>8 ) &0xFF ); - pcache->sibling_map[k+2 ] = - (uint8_t )((cu_sibling_map_mask >>16 ) &0xFF ); - pcache->sibling_map[k+3 ] = - (uint8_t )((cu_sibling_map_mask >>24 ) &0xFF ); - k +=4 ; - cu_sibling_map_mask = - cu_info->cu_bitmap[i %4 ][j + i /4 ]; - cu_sibling_map_mask &= ( - (1 << pcache_info[cache_type].num_cu_shared) - -1 ); - } - } -return 0 ; - } -return 1 ; -} -#define KFD_MAX_CACHE_TYPES 6 static int kfd_fill_gpu_cache_info_from_gfx_config(struct kfd_dev *kdev,
@@ -1435,225 +1311,129 @@ static int kfd_fill_gpu_cache_info_from_gfx_config(struct kfd_dev *kdev,return i; } -/* kfd_fill_gpu_cache_info - Fill GPU cache info using kfd_gpu_cache_info -* tables -* -* @kdev - [IN] GPU device -* @gpu_processor_id - [IN] GPU processor ID to which these caches -* associate -* @available_size - [IN] Amount of memory available in pcache -* @cu_info - [IN] Compute Unit info obtained from KGD -* @pcache - [OUT] memory into which cache data is to be filled in. -* @size_filled - [OUT] amount of data used up in pcache. -* @num_of_entries - [OUT] number of caches added -*/ -static int kfd_fill_gpu_cache_info (struct kfd_dev *kdev, -int gpu_processor_id, -int available_size, -struct kfd_cu_info *cu_info, -struct crat_subtype_cache *pcache, -int *size_filled, -int *num_of_entries) +int get_gpu_cache_info (struct kfd_dev *kdev,struct kfd_gpu_cache_info **pcache_info) { -struct kfd_gpu_cache_info *pcache_info;struct kfd_gpu_cache_info cache_info[KFD_MAX_CACHE_TYPES ];int num_of_cache_types =0 ; -int i, j, k; -int ct =0 ; -int mem_available = available_size; -unsigned int cu_processor_id; -int ret; -unsigned int num_cu_shared;switch (kdev->adev->asic_type) {case CHIP_KAVERI : - pcache_info = kaveri_cache_info; + *pcache_info = kaveri_cache_info; num_of_cache_types =ARRAY_SIZE (kaveri_cache_info);break ;case CHIP_HAWAII : - pcache_info = hawaii_cache_info; + *pcache_info = hawaii_cache_info; num_of_cache_types =ARRAY_SIZE (hawaii_cache_info);break ;case CHIP_CARRIZO : - pcache_info = carrizo_cache_info; + *pcache_info = carrizo_cache_info; num_of_cache_types =ARRAY_SIZE (carrizo_cache_info);break ;case CHIP_TONGA : - pcache_info = tonga_cache_info; + *pcache_info = tonga_cache_info; num_of_cache_types =ARRAY_SIZE (tonga_cache_info);break ;case CHIP_FIJI : - pcache_info = fiji_cache_info; + *pcache_info = fiji_cache_info; num_of_cache_types =ARRAY_SIZE (fiji_cache_info);break ;case CHIP_POLARIS10 : - pcache_info = polaris10_cache_info; + *pcache_info = polaris10_cache_info; num_of_cache_types =ARRAY_SIZE (polaris10_cache_info);break ;case CHIP_POLARIS11 : - pcache_info = polaris11_cache_info; + *pcache_info = polaris11_cache_info; num_of_cache_types =ARRAY_SIZE (polaris11_cache_info);break ;case CHIP_POLARIS12 : - pcache_info = polaris12_cache_info; + *pcache_info = polaris12_cache_info; num_of_cache_types =ARRAY_SIZE (polaris12_cache_info);break ;case CHIP_VEGAM : - pcache_info = vegam_cache_info; + *pcache_info = vegam_cache_info; num_of_cache_types =ARRAY_SIZE (vegam_cache_info);break ;default :switch (KFD_GC_VERSION (kdev)) {case IP_VERSION (9 ,0 ,1 ): - pcache_info = vega10_cache_info; + *pcache_info = vega10_cache_info; num_of_cache_types =ARRAY_SIZE (vega10_cache_info);break ;case IP_VERSION (9 ,2 ,1 ): - pcache_info = vega12_cache_info; + *pcache_info = vega12_cache_info; num_of_cache_types =ARRAY_SIZE (vega12_cache_info);break ;case IP_VERSION (9 ,4 ,0 ):case IP_VERSION (9 ,4 ,1 ): - pcache_info = vega20_cache_info; + *pcache_info = vega20_cache_info; num_of_cache_types =ARRAY_SIZE (vega20_cache_info);break ;case IP_VERSION (9 ,4 ,2 ): - pcache_info = aldebaran_cache_info; + *pcache_info = aldebaran_cache_info; num_of_cache_types =ARRAY_SIZE (aldebaran_cache_info);break ;case IP_VERSION (9 ,1 ,0 ):case IP_VERSION (9 ,2 ,2 ): - pcache_info = raven_cache_info; + *pcache_info = raven_cache_info; num_of_cache_types =ARRAY_SIZE (raven_cache_info);break ;case IP_VERSION (9 ,3 ,0 ): - pcache_info = renoir_cache_info; + *pcache_info = renoir_cache_info; num_of_cache_types =ARRAY_SIZE (renoir_cache_info);break ;case IP_VERSION (10 ,1 ,10 ):case IP_VERSION (10 ,1 ,2 ):case IP_VERSION (10 ,1 ,3 ):case IP_VERSION (10 ,1 ,4 ): - pcache_info = navi10_cache_info; + *pcache_info = navi10_cache_info; num_of_cache_types =ARRAY_SIZE (navi10_cache_info);break ;case IP_VERSION (10 ,1 ,1 ): - pcache_info = navi14_cache_info; + *pcache_info = navi14_cache_info; num_of_cache_types =ARRAY_SIZE (navi14_cache_info);break ;case IP_VERSION (10 ,3 ,0 ): - pcache_info = sienna_cichlid_cache_info; + *pcache_info = sienna_cichlid_cache_info; num_of_cache_types =ARRAY_SIZE (sienna_cichlid_cache_info);break ;case IP_VERSION (10 ,3 ,2 ): - pcache_info = navy_flounder_cache_info; + *pcache_info = navy_flounder_cache_info; num_of_cache_types =ARRAY_SIZE (navy_flounder_cache_info);break ;case IP_VERSION (10 ,3 ,4 ): - pcache_info = dimgrey_cavefish_cache_info; + *pcache_info = dimgrey_cavefish_cache_info; num_of_cache_types =ARRAY_SIZE (dimgrey_cavefish_cache_info);break ;case IP_VERSION (10 ,3 ,1 ): - pcache_info = vangogh_cache_info; + *pcache_info = vangogh_cache_info; num_of_cache_types =ARRAY_SIZE (vangogh_cache_info);break ;case IP_VERSION (10 ,3 ,5 ): - pcache_info = beige_goby_cache_info; + *pcache_info = beige_goby_cache_info; num_of_cache_types =ARRAY_SIZE (beige_goby_cache_info);break ;case IP_VERSION (10 ,3 ,3 ):case IP_VERSION (10 ,3 ,7 ):/* TODO: Double check these on production silicon */ - pcache_info = yellow_carp_cache_info; + *pcache_info = yellow_carp_cache_info; num_of_cache_types =ARRAY_SIZE (yellow_carp_cache_info);break ;case IP_VERSION (10 ,3 ,6 ): - pcache_info = gc_10_3_6_cache_info; + *pcache_info = gc_10_3_6_cache_info; num_of_cache_types =ARRAY_SIZE (gc_10_3_6_cache_info);break ;case IP_VERSION (11 ,0 ,0 ):case IP_VERSION (11 ,0 ,1 ):case IP_VERSION (11 ,0 ,2 ):case IP_VERSION (11 ,0 ,3 ): - pcache_info = cache_info; + *pcache_info = cache_info; num_of_cache_types = -kfd_fill_gpu_cache_info_from_gfx_config (kdev, pcache_info); +kfd_fill_gpu_cache_info_from_gfx_config (kdev, *pcache_info);break ;default :return -EINVAL ; } } - - *size_filled =0 ; - *num_of_entries =0 ; - -/* For each type of cache listed in the kfd_gpu_cache_info table, -* go through all available Compute Units. -* The [i,j,k] loop will -* if kfd_gpu_cache_info.num_cu_shared = 1 -* will parse through all available CU -* If (kfd_gpu_cache_info.num_cu_shared != 1) -* then it will consider only one CU from -* the shared unit -*/ - -for (ct =0 ; ct < num_of_cache_types; ct++) { - cu_processor_id = gpu_processor_id; -if (pcache_info[ct].cache_level ==1 ) { -for (i =0 ; i < cu_info->num_shader_engines; i++) { -for (j =0 ; j < cu_info->num_shader_arrays_per_engine; j++) { -for (k =0 ; k < cu_info->num_cu_per_sh; - k += pcache_info[ct].num_cu_shared) { - ret =fill_in_l1_pcache (pcache, - pcache_info, - cu_info, - mem_available, - cu_info->cu_bitmap[i %4 ][j + i /4 ], - ct, - cu_processor_id, - k); - -if (ret <0 ) -break ; - -if (!ret) { - pcache++; - (*num_of_entries)++; - mem_available -=sizeof (*pcache); - (*size_filled) +=sizeof (*pcache); - } - -/* Move to next CU block */ - num_cu_shared = ((k + pcache_info[ct].num_cu_shared) <= - cu_info->num_cu_per_sh) ? - pcache_info[ct].num_cu_shared : - (cu_info->num_cu_per_sh - k); - cu_processor_id += num_cu_shared; - } - } - } - }else { - ret =fill_in_l2_l3_pcache (pcache, - pcache_info, - cu_info, - mem_available, - ct, - cu_processor_id); - -if (ret <0 ) -break ; - -if (!ret) { - pcache++; - (*num_of_entries)++; - mem_available -=sizeof (*pcache); - (*size_filled) +=sizeof (*pcache); - } - } - } - -pr_debug ("Added [%d] GPU cache entries\n" , *num_of_entries); - -return 0 ; +return num_of_cache_types; }static bool kfd_ignore_crat (void )
@@ -2224,8 +2004,6 @@ static int kfd_create_vcrat_image_gpu(void *pcrat_image,struct kfd_cu_info cu_info;int avail_size = *size;uint32_t total_num_of_cu; -int num_of_cache_entries =0 ; -int cache_mem_filled =0 ;uint32_t nid =0 ;int ret =0 ;
@@ -2326,31 +2104,12 @@ static int kfd_create_vcrat_image_gpu(void *pcrat_image, crat_table->length +=sizeof (struct crat_subtype_memory ); crat_table->total_entries++; -/* TODO: Fill in cache information. This information is NOT readily -* available in KGD -*/ - sub_type_hdr = (typeof (sub_type_hdr))((char *)sub_type_hdr + - sub_type_hdr->length); - ret =kfd_fill_gpu_cache_info (kdev, cu->processor_id_low, - avail_size, - &cu_info, - (struct crat_subtype_cache *)sub_type_hdr, - &cache_mem_filled, - &num_of_cache_entries); - -if (ret <0 ) -return ret; - - crat_table->length += cache_mem_filled; - crat_table->total_entries += num_of_cache_entries; - avail_size -= cache_mem_filled; -/* Fill in Subtype: IO_LINKS * Only direct links are added here which is Link from GPU to * its NUMA node. Indirect links are added by userspace. */ sub_type_hdr = (typeof (sub_type_hdr))((char *)sub_type_hdr + - cache_mem_filled); + sub_type_hdr->length); ret =kfd_fill_gpu_direct_io_link_to_cpu (&avail_size, kdev, (struct crat_subtype_iolink *)sub_type_hdr, proximity_domain);
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +12 -0
@@ -317,6 +317,18 @@ struct cdit_header {struct kfd_dev ; +/* Static table to describe GPU Cache information */ +struct kfd_gpu_cache_info { +uint32_t cache_size; +uint32_t cache_level; +uint32_t flags; +/* Indicates how many Compute Units share this cache +* within a SA. Value = 1 indicates the cache is not shared +*/ +uint32_t num_cu_shared; +}; +int get_gpu_cache_info (struct kfd_dev *kdev,struct kfd_gpu_cache_info **pcache_info); +#ifdef CONFIG_ACPI int kfd_create_crat_image_acpi (void **crat_image,size_t *size);#endif
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +229 -9
283 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_topology.h +4 -1
@@ -87,6 +87,8 @@ struct kfd_mem_properties {struct attribute attr_used; }; +#define CACHE_SIBLINGMAP_SIZE 64 +struct kfd_cache_properties {struct list_head list;uint32_t processor_id_low;
@@ -97,10 +99,11 @@ struct kfd_cache_properties {uint32_t cache_assoc;uint32_t cache_latency;uint32_t cache_type; -uint8_t sibling_map[CRAT_SIBLINGMAP_SIZE ]; +uint8_t sibling_map[CACHE_SIBLINGMAP_SIZE ];struct kfd_dev *gpu;struct kobject *kobj;struct attribute attr; +uint32_t sibling_map_size; };struct kfd_iolink_properties {
Signature · 1 line
2.25.1
PATCH 1/1 drm/amdkfd: Remove unused variable
The kfd_topology_device->cache_count is not used by other fucntions, so remove it.
--- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 1 - drivers/gpu/drm/amd/amdkfd/kfd_topology.h | 1 - 2 files changed, 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0 -1
@@ -1029,7 +1029,6 @@ static int kfd_parse_subtype_cache(struct crat_subtype_cache *cache,if (cache->flags &CRAT_CACHE_FLAGS_SIMD_CACHE ) props->cache_type |=HSA_CACHE_TYPE_HSACU ; - dev->cache_count++; dev->node_props.caches_count++;list_add_tail (&props->list, &dev->cache_props);
drivers/gpu/drm/amd/amdkfd/kfd_topology.h +0 -1
@@ -140,7 +140,6 @@ struct kfd_topology_device {uint32_t proximity_domain;struct kfd_node_properties node_props;struct list_head mem_props; -uint32_t cache_count;struct list_head cache_props;struct list_head io_link_props;struct list_head p2p_link_props;
Signature · 1 line
2.25.1
Felix Kuehling
maintainerQuoted 27 lines · Ma Jun
For some GPUs with more CUs, the original sibling_map[32]
in struct
crat_subtype_cacheis not enoughto save the cache information when create the VCRAT table,
so skip filling the struct
crat_subtype_cacheinfo insteadfill struct
kfd_cache_propertiesdirectly to fix this problem.v3:
- Drop processor id calc function
v2:
- Remove unnecessary sys interface "cache_ext"Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 307 +++------------------- drivers/gpu/drm/amd/amdkfd/kfd_crat.h | 12 + drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 238 ++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_topology.h | 5 +- 4 files changed, 278 insertions(+), 284 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0
-0
[snip]
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1
-7+int get_gpu_cache_info (struct kfd_dev *kdev,struct kfd_gpu_cache_info **pcache_info) { -struct kfd_gpu_cache_info *pcache_info;struct kfd_gpu_cache_info cache_info[KFD_MAX_CACHE_TYPES ];int num_of_cache_types =0 ; -int i, j, k; -int ct =0 ; -int mem_available = available_size; -unsigned int cu_processor_id; -int ret; -unsigned int num_cu_shared;switch (kdev->adev->asic_type) {
[snip]
Quoted 3 lines
default:
switch (KFD_GC_VERSION(kdev)) {[snip]
drivers/gpu/drm/amd/amdkfd/kfd_crat.c static int kfd_fill_gpu_cache_info_from_gfx_config(struct kfd_dev *kdev, · line 1428
Quoted 6 lines
case
IP_VERSION(11, 0, 0):
caseIP_VERSION(11, 0, 1):
caseIP_VERSION(11, 0, 2):
caseIP_VERSION(11, 0, 3):drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1
-1- pcache_info = cache_info; + *pcache_info = cache_info;
This won't work. cache_info is a local variable. It will be out of scope as soon as this function returns. You'll need to allocate this in some data structure that will persist after the function returns. Maybe expect the caller to pass in a pointer to an array in their own stack frame.
Quoted 3 lines
num_of_cache_types=drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1
-1-kfd_fill_gpu_cache_info_from_gfx_config (kdev, pcache_info); +kfd_fill_gpu_cache_info_from_gfx_config (kdev, *pcache_info);
[snip]
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0
-0
[snip]
Quoted 12 lines
int
kfd_topology_add_device(struct kfd_dev *gpu)
{
uint32_tgpu_id;drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-0@@ -1759,6 +1970,7 @@ int kfd_topology_add_device(struct kfd_dev *gpu) topology_crat_proximity_domain--;return res; } + res =kfd_parse_crat_table (crat_image, &temp_topology_device_list, proximity_domain);
drivers/gpu/drm/amd/amdkfd/kfd_topology.c int kfd_topology_add_device(struct kfd_dev *gpu) · line 1986
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-0@@ -1771,23 +1983,31 @@ int kfd_topology_add_device(struct kfd_dev *gpu)kfd_topology_update_device_list (&temp_topology_device_list, &topology_device_list); +up_write (&topology_lock);
I'm not sure if dropping and re-taking the topology lock here could lead to race conditions. But this could be avoided, if you moved the responsibility for topology locking out of kfd_assign_gpu and into the caller (kfd_topology_add_device).
Regards,
Felix
Quoted 59 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +13
-6+ + dev =kfd_assign_gpu (gpu); +if (WARN_ON (!dev)) { + res = -ENODEV ; + goto err; + } + +down_write (&topology_lock); + +/* Fill the cache affinity information here for the GPUs +* using VCRAT +*/ +kfd_fill_cache_non_crat_info (dev, gpu);/* Update the SYSFS tree, since we added another topology * device */ res =kfd_topology_update_sysfs ();up_write (&topology_lock); -if (!res) sys_props.generation_count++;else pr_err ("Failed to update GPU (ID: 0x%x) to sysfs topology. res=%d\n" , gpu_id, res); - dev =kfd_assign_gpu (gpu); -if (WARN_ON (!dev)) { - res = -ENODEV ; - goto err; - } } dev->gpu_id = gpu_id;drivers/gpu/drm/amd/amdkfd/kfd_topology.h +4
-1@@ -87,6 +87,8 @@ struct kfd_mem_properties {struct attribute attr_used; }; +#define CACHE_SIBLINGMAP_SIZE 64 +struct kfd_cache_properties {struct list_head list;uint32_t processor_id_low;@@ -97,10 +99,11 @@ struct kfd_cache_properties {uint32_t cache_assoc;uint32_t cache_latency;uint32_t cache_type; -uint8_t sibling_map[CRAT_SIBLINGMAP_SIZE ]; +uint8_t sibling_map[CACHE_SIBLINGMAP_SIZE ];struct kfd_dev *gpu;struct kobject *kobj;struct attribute attr; +uint32_t sibling_map_size; };struct kfd_iolink_properties {
Re: [PATCH] drm/amdkfd: Remove unused variable
In reply to Ma JunQuoted 4 lines · Ma Jun
The
kfd_topology_device->cache_countis not used by other fucntions, so remove it.Signed-off-by Ma Jun <[email protected]>
Quoted 29 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 1 - drivers/gpu/drm/amd/amdkfd/kfd_topology.h | 1 - 2 files changed, 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0
-1@@ -1029,7 +1029,6 @@ static int kfd_parse_subtype_cache(struct crat_subtype_cache *cache,if (cache->flags &CRAT_CACHE_FLAGS_SIMD_CACHE ) props->cache_type |=HSA_CACHE_TYPE_HSACU ; - dev->cache_count++; dev->node_props.caches_count++;list_add_tail (&props->list, &dev->cache_props);drivers/gpu/drm/amd/amdkfd/kfd_topology.h +0
-1@@ -140,7 +140,6 @@ struct kfd_topology_device {uint32_t proximity_domain;struct kfd_node_properties node_props;struct list_head mem_props; -uint32_t cache_count;struct list_head cache_props;struct list_head io_link_props;struct list_head p2p_link_props;
Quoted 47 lines · Felix Kuehling
Quoted 27 lines · Ma Jun
For some GPUs with more CUs, the original sibling_map[32]
in struct
crat_subtype_cacheis not enoughto save the cache information when create the VCRAT table,
so skip filling the struct
crat_subtype_cacheinfo insteadfill struct
kfd_cache_propertiesdirectly to fix this problem.v3:
- Drop processor id calc function
v2:
- Remove unnecessary sys interface "cache_ext"Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 307 +++------------------- drivers/gpu/drm/amd/amdkfd/kfd_crat.h | 12 + drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 238 ++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_topology.h | 5 +- 4 files changed, 278 insertions(+), 284 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0
-0[snip]
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1
-7+int get_gpu_cache_info (struct kfd_dev *kdev,struct kfd_gpu_cache_info **pcache_info) { -struct kfd_gpu_cache_info *pcache_info;struct kfd_gpu_cache_info cache_info[KFD_MAX_CACHE_TYPES ];int num_of_cache_types =0 ; -int i, j, k; -int ct =0 ; -int mem_available = available_size; -unsigned int cu_processor_id; -int ret; -unsigned int num_cu_shared;switch (kdev->adev->asic_type) {[snip]
Quoted 3 lines
default: switch (KFD_GC_VERSION(kdev)) {[snip]
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c static int kfd_fill_gpu_cache_info_from_gfx_config(struct kfd_dev *kdev, · line 1428
Quoted 6 lines
case
IP_VERSION(11, 0, 0):
caseIP_VERSION(11, 0, 1):
caseIP_VERSION(11, 0, 2):
caseIP_VERSION(11, 0, 3):drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1
-1- pcache_info = cache_info; + *pcache_info = cache_info;This won't work.
cache_infois a local variable. It will be out of scope as soon as this function returns. You'll need to allocate this in some data structure that will persist after the function returns. Maybe expect the caller to pass in a pointer to an array in their own stack frame.
Yes, this is my mistake. Will fix in next version
Quoted 26 lines
Quoted 5 lines
num_of_cache_types=drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1
-1-kfd_fill_gpu_cache_info_from_gfx_config (kdev, pcache_info); +kfd_fill_gpu_cache_info_from_gfx_config (kdev, *pcache_info);[snip]
Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0
-0[snip]
Quoted 13 lines
int
kfd_topology_add_device(struct kfd_dev *gpu)
{
uint32_tgpu_id;drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-0@@ -1759,6 +1970,7 @@ int kfd_topology_add_device(struct kfd_dev *gpu) topology_crat_proximity_domain--;return res; } + res =kfd_parse_crat_table (crat_image, &temp_topology_device_list, proximity_domain);@@ -1771,23 +1983,31 @@ int kfd_topology_add_device(struct kfd_dev *gpu)
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c int kfd_topology_add_device(struct kfd_dev *gpu) · line 1986
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1
-0kfd_topology_update_device_list (&temp_topology_device_list, &topology_device_list); +up_write (&topology_lock);I'm not sure if dropping and re-taking the topology lock here could lead to race conditions. But this could be avoided, if you moved the responsibility for topology locking out of
kfd_assign_gpuand into the caller (kfd_topology_add_device).
Thanks for review.Will fix in next version.
Regards,
Ma Jun
Quoted 64 lines
Regards,
FelixQuoted 59 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +13
-6+ + dev =kfd_assign_gpu (gpu); +if (WARN_ON (!dev)) { + res = -ENODEV ; + goto err; + } + +down_write (&topology_lock); + +/* Fill the cache affinity information here for the GPUs +* using VCRAT +*/ +kfd_fill_cache_non_crat_info (dev, gpu);/* Update the SYSFS tree, since we added another topology * device */ res =kfd_topology_update_sysfs ();up_write (&topology_lock); -if (!res) sys_props.generation_count++;else pr_err ("Failed to update GPU (ID: 0x%x) to sysfs topology. res=%d\n" , gpu_id, res); - dev =kfd_assign_gpu (gpu); -if (WARN_ON (!dev)) { - res = -ENODEV ; - goto err; - } } dev->gpu_id = gpu_id;drivers/gpu/drm/amd/amdkfd/kfd_topology.h +4
-1@@ -87,6 +87,8 @@ struct kfd_mem_properties {struct attribute attr_used; }; +#define CACHE_SIBLINGMAP_SIZE 64 +struct kfd_cache_properties {struct list_head list;uint32_t processor_id_low;@@ -97,10 +99,11 @@ struct kfd_cache_properties {uint32_t cache_assoc;uint32_t cache_latency;uint32_t cache_type; -uint8_t sibling_map[CRAT_SIBLINGMAP_SIZE ]; +uint8_t sibling_map[CACHE_SIBLINGMAP_SIZE ];struct kfd_dev *gpu;struct kobject *kobj;struct attribute attr; +uint32_t sibling_map_size; };struct kfd_iolink_properties {