Skip to contentSkip to conversation

drm/amdkfd: Fix the warning of array-index-out-of-bounds

PATCH Superseded Ma Jun 3 participants 3 messages Oct 8, 2022 – Oct 10, 2022

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ma Jun

author
#0 lore raw

PATCH 1/1 drm/amdkfd: Fix the warning of array-index-out-of-bounds

Increasing the simbling array size to fix the warning of array-index-out-of-bounds. The VCRAT_SIZE_FOR_GPU is also increased accrordingly.

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_crat.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -1
index 477a30981c1b..3ec425c3737d 100644
@@ -1683,7 +1683,7 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
  * expected to cover all known conditions. But to be safe additional check
  * is put in the code to ensure we don't overwrite.
  */
-#define VCRAT_SIZE_FOR_GPU	(4 * PAGE_SIZE)
+#define VCRAT_SIZE_FOR_GPU	(6 * PAGE_SIZE)
 
 /* kfd_fill_cu_for_cpu - Fill in Compute info for the given CPU NUMA node
  *
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +1 -1
index fbb5f6c32ef5..31a4bbc9f9cb 100644
@@ -80,7 +80,7 @@ struct crat_header {
 #define CRAT_SUBTYPE_IOLINK_AFFINITY		5
 #define CRAT_SUBTYPE_MAX			6
 
-#define CRAT_SIBLINGMAP_SIZE	32
+#define CRAT_SIBLINGMAP_SIZE	64
 
 /*
  * ComputeUnit Affinity structure and definitions
Signature · 1 line
2.25.1
maintainer
#1 lore raw

This breaks the CRAT table ABI, which will break APUs that use an actual CRAT table from ACPI.

I think to fix this, you'll need to populate kfd_cache_properties.sibling_map without using a VCRAT to support GPUs that have more CUs than fit into the CRAT sibling map. In other words, don't populate the sibling map in fill_in_*_pcache. Instead move this code into kfd_topology.c and populate the kfd_cache_properties.sibling_map in a new function called from kfd_topology_add_device. E.g. kfd_topology_fill_cache_non_crat_info. Maybe conditionally only when using a VCRAT.

In the long run, I think we should get rid of the VCRAT stuff entirely and fill in the topology for GPUs without a CRAT without the intermediate step of creating a CRAT table.

Regards,
  Felix

Am 2022-10-08 um 01:56 schrieb Ma Jun:

Quoted 36 lines

Increasing the simbling array size to fix the warning of array-index-out-of-bounds. The VCRAT_SIZE_FOR_GPU is also increased accrordingly.

---
  drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_crat.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -1
index 477a30981c1b..3ec425c3737d 100644
@@ -1683,7 +1683,7 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
   * expected to cover all known conditions. But to be safe additional check
   * is put in the code to ensure we don't overwrite.
   */
-#define VCRAT_SIZE_FOR_GPU	(4 * PAGE_SIZE)
+#define VCRAT_SIZE_FOR_GPU	(6 * PAGE_SIZE)
 
  /* kfd_fill_cu_for_cpu - Fill in Compute info for the given CPU NUMA node
   *
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +1 -1
index fbb5f6c32ef5..31a4bbc9f9cb 100644
@@ -80,7 +80,7 @@ struct crat_header {
  #define CRAT_SUBTYPE_IOLINK_AFFINITY		5
  #define CRAT_SUBTYPE_MAX			6
 
-#define CRAT_SIBLINGMAP_SIZE	32
+#define CRAT_SIBLINGMAP_SIZE	64
 
  /*
   * ComputeUnit Affinity structure and definitions
#2 lore raw

Hi Felix,

Thanks for this suggestion, I'll make a new patch to fix this.

Regards,
Ma Jun

Quoted 57 lines · Felix Kuehling

This breaks the CRAT table ABI, which will break APUs that use an actual CRAT table from ACPI.

I think to fix this, you'll need to populate kfd_cache_properties.sibling_map without using a VCRAT to support GPUs that have more CUs than fit into the CRAT sibling map. In other words, don't populate the sibling map in fill_in_*_pcache. Instead move this code into kfd_topology.c and populate the kfd_cache_properties.sibling_map in a new function called from kfd_topology_add_device. E.g. kfd_topology_fill_cache_non_crat_info. Maybe conditionally only when using a VCRAT.

In the long run, I think we should get rid of the VCRAT stuff entirely and fill in the topology for GPUs without a CRAT without the intermediate step of creating a CRAT table.

Regards,
  Felix

Am 2022-10-08 um 01:56 schrieb Ma Jun:

Quoted 36 lines

Increasing the simbling array size to fix the warning of array-index-out-of-bounds. The VCRAT_SIZE_FOR_GPU is also increased accrordingly.

---
  drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_crat.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -1
index 477a30981c1b..3ec425c3737d 100644
@@ -1683,7 +1683,7 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
   * expected to cover all known conditions. But to be safe additional check
   * is put in the code to ensure we don't overwrite.
   */
-#define VCRAT_SIZE_FOR_GPU	(4 * PAGE_SIZE)
+#define VCRAT_SIZE_FOR_GPU	(6 * PAGE_SIZE)
 
  /* kfd_fill_cu_for_cpu - Fill in Compute info for the given CPU NUMA node
   *
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +1 -1
index fbb5f6c32ef5..31a4bbc9f9cb 100644
@@ -80,7 +80,7 @@ struct crat_header {
  #define CRAT_SUBTYPE_IOLINK_AFFINITY		5
  #define CRAT_SUBTYPE_MAX			6
 
-#define CRAT_SIBLINGMAP_SIZE	32
+#define CRAT_SIBLINGMAP_SIZE	64
 
  /*
   * ComputeUnit Affinity structure and definitions