@@ -809,11 +809,10 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
809809
810810/* Memory required to create Virtual CRAT.
811811 * Since there is no easy way to predict the amount of memory required, the
812- * following amount are allocated for CPU and GPU Virtual CRAT. This is
812+ * following amount is allocated for GPU Virtual CRAT. This is
813813 * expected to cover all known conditions. But to be safe additional check
814814 * is put in the code to ensure we don't overwrite.
815815 */
816- #define VCRAT_SIZE_FOR_CPU (2 * PAGE_SIZE)
817816#define VCRAT_SIZE_FOR_GPU (4 * PAGE_SIZE)
818817
819818/* kfd_fill_cu_for_cpu - Fill in Compute info for the given CPU NUMA node
@@ -964,7 +963,7 @@ static int kfd_create_vcrat_image_cpu(void *pcrat_image, size_t *size)
964963#endif
965964 int ret = 0 ;
966965
967- if (!pcrat_image || avail_size < VCRAT_SIZE_FOR_CPU )
966+ if (!pcrat_image )
968967 return - EINVAL ;
969968
970969 /* Fill in CRAT Header.
@@ -1364,24 +1363,31 @@ int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
13641363 uint32_t proximity_domain )
13651364{
13661365 void * pcrat_image = NULL ;
1367- int ret = 0 ;
1366+ int ret = 0 , num_nodes ;
1367+ size_t dyn_size ;
13681368
13691369 if (!crat_image )
13701370 return - EINVAL ;
13711371
13721372 * crat_image = NULL ;
13731373
1374- /* Allocate one VCRAT_SIZE_FOR_CPU for CPU virtual CRAT image and
1375- * VCRAT_SIZE_FOR_GPU for GPU virtual CRAT image. This should cover
1376- * all the current conditions. A check is put not to overwrite beyond
1377- * allocated size
1374+ /* Allocate the CPU Virtual CRAT size based on the number of online
1375+ * nodes. Allocate VCRAT_SIZE_FOR_GPU for GPU virtual CRAT image.
1376+ * This should cover all the current conditions. A check is put not
1377+ * to overwrite beyond allocated size for GPUs
13781378 */
13791379 switch (flags ) {
13801380 case COMPUTE_UNIT_CPU :
1381- pcrat_image = kmalloc (VCRAT_SIZE_FOR_CPU , GFP_KERNEL );
1381+ num_nodes = num_online_nodes ();
1382+ dyn_size = sizeof (struct crat_header ) +
1383+ num_nodes * (sizeof (struct crat_subtype_computeunit ) +
1384+ sizeof (struct crat_subtype_memory ) +
1385+ (num_nodes - 1 ) * sizeof (struct crat_subtype_iolink ));
1386+ pcrat_image = kmalloc (dyn_size , GFP_KERNEL );
13821387 if (!pcrat_image )
13831388 return - ENOMEM ;
1384- * size = VCRAT_SIZE_FOR_CPU ;
1389+ * size = dyn_size ;
1390+ pr_debug ("CRAT size is %ld" , dyn_size );
13851391 ret = kfd_create_vcrat_image_cpu (pcrat_image , size );
13861392 break ;
13871393 case COMPUTE_UNIT_GPU :
0 commit comments