Skip to contentSkip to conversation

drm/amdkfd: Use kvmalloc instead of kmalloc for VCRAT

PATCH In review Kent Russell 2 participants 2 messages Sep 21, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: Use kvmalloc instead of kmalloc for VCRAT

Since we're dynamically allocating the CPU VCRAT, use kvmalloc in case the allocation size is huge.

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +5 -4
index 99182b8e9152..c50e9f634d6c 100644
@@ -797,7 +797,8 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
 		return -ENODATA;
 	}
 
-	pcrat_image = kmemdup(crat_table, crat_table->length, GFP_KERNEL);
+	pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL);
+	memcpy(pcrat_image, crat_table, crat_table->length);
 	if (!pcrat_image)
 		return -ENOMEM;
 
@@ -1383,7 +1384,7 @@ int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
 			num_nodes * (sizeof(struct crat_subtype_computeunit) +
 			sizeof(struct crat_subtype_memory) +
 			(num_nodes - 1) * sizeof(struct crat_subtype_iolink));
-		pcrat_image = kmalloc(dyn_size, GFP_KERNEL);
+		pcrat_image = kvmalloc(dyn_size, GFP_KERNEL);
 		if (!pcrat_image)
 			return -ENOMEM;
 		*size = dyn_size;
@@ -1393,7 +1394,7 @@ int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
 	case COMPUTE_UNIT_GPU:
 		if (!kdev)
 			return -EINVAL;
-		pcrat_image = kmalloc(VCRAT_SIZE_FOR_GPU, GFP_KERNEL);
+		pcrat_image = kvmalloc(VCRAT_SIZE_FOR_GPU, GFP_KERNEL);
 		if (!pcrat_image)
 			return -ENOMEM;
 		*size = VCRAT_SIZE_FOR_GPU;
@@ -1412,7 +1413,7 @@ int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
 	if (!ret)
 		*crat_image = pcrat_image;
 	else
-		kfree(pcrat_image);
+		kvfree(pcrat_image);
 
 	return ret;
 }
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer Reviewed-by on v1 1/1
#1 lore raw

[AMD Public Use]

________________________________
From: amd-gfx <[email protected]> on behalf of Kent Russell <[email protected]>
Sent: Monday, September 21, 2020 10:27 AM
To: [email protected] <[email protected]>
Cc: Russell, Kent <[email protected]>
Subject: [PATCH] drm/amdkfd: Use kvmalloc instead of kmalloc for VCRAT

Since we're dynamically allocating the CPU VCRAT, use kvmalloc in case the allocation size is huge.

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +5 -4
index 99182b8e9152..c50e9f634d6c 100644
@@ -797,7 +797,8 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
                 return -ENODATA;
         }
 
-       pcrat_image = kmemdup(crat_table, crat_table->length, GFP_KERNEL);
+       pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL);
+       memcpy(pcrat_image, crat_table, crat_table->length);
         if (!pcrat_image)
                 return -ENOMEM;
 
@@ -1383,7 +1384,7 @@ int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
                         num_nodes * (sizeof(struct crat_subtype_computeunit) +
                         sizeof(struct crat_subtype_memory) +
                         (num_nodes - 1) * sizeof(struct crat_subtype_iolink));
-               pcrat_image = kmalloc(dyn_size, GFP_KERNEL);
+               pcrat_image = kvmalloc(dyn_size, GFP_KERNEL);
                 if (!pcrat_image)
                         return -ENOMEM;
                 *size = dyn_size;
@@ -1393,7 +1394,7 @@ int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
         case COMPUTE_UNIT_GPU:
                 if (!kdev)
                         return -EINVAL;
-               pcrat_image = kmalloc(VCRAT_SIZE_FOR_GPU, GFP_KERNEL);
+               pcrat_image = kvmalloc(VCRAT_SIZE_FOR_GPU, GFP_KERNEL);
                 if (!pcrat_image)
                         return -ENOMEM;
                 *size = VCRAT_SIZE_FOR_GPU;
@@ -1412,7 +1413,7 @@ int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
         if (!ret)
                 *crat_image = pcrat_image;
         else
-               kfree(pcrat_image);
+               kvfree(pcrat_image);
 
         return ret;
 }

--
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Calexander.deucher%40amd.com%7C2c0550686c55482e784108d85e3a79b9%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637362952855598708&amp;sdata=juwKVfB3gvGU5TkLKf9KYPdy90sgT80810dh91hpZSw%3D&amp;reserved=0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx