Skip to content

Commit b7b6c38

Browse files
kentrussellalexdeucher
authored andcommitted
drm/amdkfd: Calculate CPU VCRAT size dynamically (v2)
Instead of guessing at a sufficient size for the CPU VCRAT, base the size on the number of online NUMA nodes. v2: fix warning Signed-off-by: Kent Russell <kent.russell@amd.com> Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent c7651b7 commit b7b6c38

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_crat.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)