drm/amdgpu: Do not access members of xcp w/o check (v2)
authorHawking Zhang <Hawking.Zhang@amd.com>
Fri, 12 May 2023 05:22:57 +0000 (13:22 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 9 Jun 2023 14:37:24 +0000 (10:37 -0400)
Not all the asic needs xcp. ensure check xcp availabity
before accessing its member.

v2: add missing change in kfd_topology.c

Signed-off-by: Hawking Zhang <Hawking.Zhang@amd.com>
Reviewed-by: Le Ma <le.ma@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
drivers/gpu/drm/amd/amdkfd/kfd_device.c
drivers/gpu/drm/amd/amdkfd/kfd_topology.c

index 85df73f..739eb7c 100644 (file)
@@ -429,17 +429,17 @@ uint32_t amdgpu_amdkfd_get_fw_version(struct amdgpu_device *adev,
 
 void amdgpu_amdkfd_get_local_mem_info(struct amdgpu_device *adev,
                                      struct kfd_local_mem_info *mem_info,
-                                     uint8_t xcp_id)
+                                     struct amdgpu_xcp *xcp)
 {
        memset(mem_info, 0, sizeof(*mem_info));
 
-       if (adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 3)) {
+       if (xcp) {
                if (adev->gmc.real_vram_size == adev->gmc.visible_vram_size)
                        mem_info->local_mem_size_public =
-                                       KFD_XCP_MEMORY_SIZE(adev, xcp_id);
+                                       KFD_XCP_MEMORY_SIZE(adev, xcp->id);
                else
                        mem_info->local_mem_size_private =
-                                       KFD_XCP_MEMORY_SIZE(adev, xcp_id);
+                                       KFD_XCP_MEMORY_SIZE(adev, xcp->id);
        } else {
                mem_info->local_mem_size_public = adev->gmc.visible_vram_size;
                mem_info->local_mem_size_private = adev->gmc.real_vram_size -
index 48d12db..be43d71 100644 (file)
@@ -233,7 +233,7 @@ uint32_t amdgpu_amdkfd_get_fw_version(struct amdgpu_device *adev,
                                      enum kgd_engine_type type);
 void amdgpu_amdkfd_get_local_mem_info(struct amdgpu_device *adev,
                                      struct kfd_local_mem_info *mem_info,
-                                     uint8_t xcp_id);
+                                     struct amdgpu_xcp *xcp);
 uint64_t amdgpu_amdkfd_get_gpu_clock_counter(struct amdgpu_device *adev);
 
 uint32_t amdgpu_amdkfd_get_max_engine_clock_in_mhz(struct amdgpu_device *adev);
index 2cfef3f..986543a 100644 (file)
@@ -784,7 +784,7 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
                atomic_set(&node->sram_ecc_flag, 0);
 
                amdgpu_amdkfd_get_local_mem_info(kfd->adev,
-                                       &node->local_mem_info, node->xcp->id);
+                                       &node->local_mem_info, node->xcp);
 
                /* Initialize the KFD node */
                if (kfd_init_node(node)) {
index e0bacf0..8302d89 100644 (file)
@@ -1235,7 +1235,7 @@ static void kfd_fill_mem_clk_max_info(struct kfd_topology_device *dev)
         *      all the banks will report the same mem_clk_max information
         */
        amdgpu_amdkfd_get_local_mem_info(dev->gpu->adev, &local_mem_info,
-                                        dev->gpu->xcp->id);
+                                        dev->gpu->xcp);
 
        list_for_each_entry(mem, &dev->mem_props, list)
                mem->mem_clk_max = local_mem_info.mem_clk_max;