aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/1399-Reserve-all-PD-BOs-from-VMs-along-with-a-BO-when-it-.patch
blob: 49cf81d9917df3ad7e83f8b3d61d97c5c6f2ec84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
From 83a1bec8c5ac6a51f983cf028824038df2ab5b43 Mon Sep 17 00:00:00 2001
From: Yong Zhao <yong.zhao@amd.com>
Date: Thu, 21 Apr 2016 15:27:12 -0400
Subject: [PATCH 1399/4131] Reserve all PD BOs from VMs along with a BO when it
 is freed

Change-Id: Ic1fe7affb9427cf8530296ed54617454988aa74f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index e1e83b4..0db8980 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -135,11 +135,11 @@ static int add_bo_to_vm(struct amdgpu_device *adev, struct kgd_mem *mem,
 }
 
 static void remove_bo_from_vm(struct amdgpu_device *adev,
-		struct amdgpu_bo *bo, struct amdgpu_bo_va *bo_va)
+		struct kfd_bo_va_list *entry)
 {
-	amdgpu_bo_reserve(bo, true);
-	amdgpu_vm_bo_rmv(adev, bo_va);
-	amdgpu_bo_unreserve(bo);
+	amdgpu_vm_bo_rmv(adev, entry->bo_va);
+	list_del(&entry->bo_list);
+	kfree(entry);
 }
 
 
@@ -758,6 +758,8 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
 {
 	struct amdgpu_device *adev;
 	struct kfd_bo_va_list *entry, *tmp;
+	struct bo_vm_reservation_context ctx;
+	int ret;
 
 	BUG_ON(kgd == NULL);
 	BUG_ON(mem == NULL);
@@ -781,19 +783,21 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
 	if (mem->data2.work.work.func)
 		cancel_delayed_work_sync(&mem->data2.work);
 
+	ret = reserve_bo_and_vms(mem, NULL, false, &ctx);
+	if (unlikely(ret != 0))
+		return ret;
+
 	/* Remove from VM internal data structures */
 	list_for_each_entry_safe(entry, tmp, &mem->data2.bo_va_list, bo_list) {
 		pr_debug("Releasing BO with VA %p, size %lu bytes\n",
 				entry->bo_va,
 				mem->data2.bo->tbo.mem.size);
-		if (entry->bo_va->vm != NULL)
-			remove_bo_from_vm(
-				(struct amdgpu_device *)entry->kgd_dev,
-				mem->data2.bo, entry->bo_va);
-		list_del(&entry->bo_list);
-		kfree(entry);
+		remove_bo_from_vm((struct amdgpu_device *)entry->kgd_dev,
+				entry);
 	}
 
+	unreserve_bo_and_vms(&ctx, true);
+
 	/* Free the BO*/
 	amdgpu_bo_unref(&mem->data2.bo);
 	kfree(mem);
-- 
2.7.4