aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/linux-yocto-4.14.71/1519-drm-amdgpu-Add-eviction_valuable-TTM-callback.patch
blob: cbe227358a8cb0fb74f558229dd80c3344972e96 (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
72
73
74
75
76
From 837456ef48244bedacc4137ff7c62d0fdb58becf Mon Sep 17 00:00:00 2001
From: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Date: Fri, 2 Sep 2016 16:56:26 -0400
Subject: [PATCH 1519/4131] drm/amdgpu: Add eviction_valuable TTM callback

Change-Id: I6255ebffb7efa70fa4a1a17ff77e71e79145c502
Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>

 Conflicts:
	drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 34 ++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 512207e..b028f23 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -46,6 +46,7 @@
 #include "amdgpu.h"
 #include "amdgpu_trace.h"
 #include "bif/bif_4_1_d.h"
+#include "amdgpu_amdkfd.h"
 
 #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
 
@@ -208,6 +209,37 @@ static int amdgpu_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
 	return 0;
 }
 
+static bool amdgpu_bo_eviction_valuable(struct ttm_buffer_object *bo,
+					const struct ttm_place *place)
+{
+	struct reservation_object_list *flist;
+	struct fence *f;
+	int i;
+
+	/* Don't evict this BO if it's outside of the
+	 * requested placement range
+	 */
+	if (!ttm_bo_eviction_valuable(bo, place))
+		return false;
+
+	/* If bo is a KFD BO, check if the bo belongs to the current process.
+	 * If true, then return false as any KFD process needs all its BOs to
+	 * be resident to run successfully
+	 */
+	flist = reservation_object_get_list(bo->resv);
+	if (!flist)
+		return true;
+
+	for (i = 0; i < flist->shared_count; ++i) {
+		f = rcu_dereference_protected(flist->shared[i],
+			reservation_object_held(bo->resv));
+		if (amd_kfd_fence_check_mm(f, current->mm))
+			return false;
+	}
+
+	return true;
+}
+
 static void amdgpu_evict_flags(struct ttm_buffer_object *bo,
 				struct ttm_placement *placement)
 {
@@ -1292,7 +1324,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
 	.ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
 	.invalidate_caches = &amdgpu_invalidate_caches,
 	.init_mem_type = &amdgpu_init_mem_type,
-	.eviction_valuable = amdgpu_ttm_bo_eviction_valuable,
+	.eviction_valuable = amdgpu_bo_eviction_valuable,
 	.evict_flags = &amdgpu_evict_flags,
 	.move = &amdgpu_bo_move,
 	.verify_access = &amdgpu_verify_access,
-- 
2.7.4