Skip to contentSkip to conversation

drm/amdkfd: avoid double alloc by ioctl_alloc and svm

PATCH In review Alex Sierra 2 participants 2 messages Jun 11, 2021 – Jun 14, 2021

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

PATCH 1/1 drm/amdkfd: avoid double alloc by ioctl_alloc and svm

[Why]
Avoid duplicated memory allocation for address ranges that have been already allocated by either ioctl_alloc_memory_of_gpu or SVM mechanisms first.

[How]
For SVM first allocations
Check if the address range passed into ioctl memory alloc does not exist already in the kfd_process svms->objects interval tree.

For ioctl_alloc_memory_of_gpu first allocations Look for the address range into the interval tree VA from the VM inside of each pdds used in a kfd_process.

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 11 +++++
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 63 ++++++++++++++++++------
 2 files changed, 59 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +11 -0
index 5788a4656fa1..0cfa685d9b8a 100644
@@ -1259,6 +1259,17 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
 	if (args->size == 0)
 		return -EINVAL;
 
+#if IS_ENABLED(CONFIG_HSA_AMD_SVM)
+	struct svm_range_list *svms = &p->svms;
+
+	if (interval_tree_iter_first(&svms->objects,
+				     args->va_addr >> PAGE_SHIFT,
+				     (args->va_addr + args->size - 1) >> PAGE_SHIFT)) {
+		pr_info("Address: 0x%llx already allocated by SVM\n",
+			args->va_addr);
+		return -EADDRINUSE;
+	}
+#endif
 	dev = kfd_device_by_id(args->gpu_id);
 	if (!dev)
 		return -EINVAL;
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +48 -15

109 lines not on this page · raw message

Signature · 6 lines
2.17.1

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