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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
From 8637acebd289a4db479ca1d4bd0389e3520c6776 Mon Sep 17 00:00:00 2001
From: Yong Zhao <yong.zhao@amd.com>
Date: Tue, 9 Aug 2016 13:00:49 -0400
Subject: [PATCH 1170/4131] drm/amdkfd: Reorganize functions involving process
exit
Change-Id: Id077e26a6cf9f29f62fd08f3b2f9c1ca320bc2ee
Signed-off-by: Yong Zhao <yong.zhao@amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 64 ++++++++++++++++++++------------
1 file changed, 40 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index 098787a..65099bb 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -412,40 +412,21 @@ int restore(struct kfd_dev *kfd)
return 0;
}
-/* No process locking is needed in this function, because the process
- * is not findable any more. We must assume that no other thread is
- * using it any more, otherwise we couldn't safely free the process
- * stucture in the end. */
-static void kfd_process_ref_release(struct kref *ref)
+static void kfd_process_free_outstanding_kfd_bos(struct kfd_process *p)
{
- struct kfd_process *p = container_of(ref, struct kfd_process, ref);
- struct kfd_process_device *pdd, *temp, *peer_pdd;
+ struct kfd_process_device *pdd, *peer_pdd;
struct kfd_bo *buf_obj;
int id;
- pr_debug("Releasing process (pasid %d)\n",
- p->pasid);
-
list_for_each_entry(pdd, &p->per_device_data, per_device_list) {
- pr_debug("Releasing pdd (topology id %d) for process (pasid %d)\n",
- pdd->dev->id, p->pasid);
-
- if (pdd->dev->device_info->is_need_iommu_device) {
- if (pdd->bound == PDD_BOUND) {
- amd_iommu_unbind_pasid(pdd->dev->pdev,
- p->pasid);
- pdd->bound = PDD_UNBOUND;
- }
- }
-
/*
* Remove all handles from idr and release appropriate
* local memory object
*/
idr_for_each_entry(&pdd->alloc_idr, buf_obj, id) {
- list_for_each_entry(peer_pdd,
- &p->per_device_data, per_device_list) {
- pdd->dev->kfd2kgd->unmap_memory_to_gpu(
+ list_for_each_entry(peer_pdd, &p->per_device_data,
+ per_device_list) {
+ peer_pdd->dev->kfd2kgd->unmap_memory_to_gpu(
peer_pdd->dev->kgd,
buf_obj->mem, peer_pdd->vm);
}
@@ -456,6 +437,11 @@ static void kfd_process_ref_release(struct kref *ref)
kfd_process_device_remove_obj_handle(pdd, id);
}
}
+}
+
+static void kfd_process_destroy_pdds(struct kfd_process *p)
+{
+ struct kfd_process_device *pdd, *temp;
list_for_each_entry_safe(pdd, temp, &p->per_device_data,
per_device_list) {
@@ -467,6 +453,36 @@ static void kfd_process_ref_release(struct kref *ref)
list_del(&pdd->per_device_list);
kfree(pdd);
}
+}
+
+/* No process locking is needed in this function, because the process
+ * is not findable any more. We must assume that no other thread is
+ * using it any more, otherwise we couldn't safely free the process
+ * stucture in the end. */
+static void kfd_process_ref_release(struct kref *ref)
+{
+ struct kfd_process *p = container_of(ref, struct kfd_process, ref);
+ struct kfd_process_device *pdd;
+
+ pr_debug("Releasing process (pasid %d)\n",
+ p->pasid);
+
+ list_for_each_entry(pdd, &p->per_device_data, per_device_list) {
+ pr_debug("Releasing pdd (topology id %d) for process (pasid %d)\n",
+ pdd->dev->id, p->pasid);
+
+ if (pdd->dev->device_info->is_need_iommu_device) {
+ if (pdd->bound == PDD_BOUND) {
+ amd_iommu_unbind_pasid(pdd->dev->pdev,
+ p->pasid);
+ pdd->bound = PDD_UNBOUND;
+ }
+ }
+ }
+
+ kfd_process_free_outstanding_kfd_bos(p);
+
+ kfd_process_destroy_pdds(p);
kfd_event_free_process(p);
--
2.7.4
|