diff options
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 66 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 |
2 files changed, 21 insertions, 49 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 1a8f4e0dd023..f0deedcaf1c9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | |||
@@ -119,9 +119,7 @@ static void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base, | |||
119 | * is currently evicted. add the bo to the evicted list to make sure it | 119 | * is currently evicted. add the bo to the evicted list to make sure it |
120 | * is validated on next vm use to avoid fault. | 120 | * is validated on next vm use to avoid fault. |
121 | * */ | 121 | * */ |
122 | spin_lock(&vm->status_lock); | ||
123 | list_move_tail(&base->vm_status, &vm->evicted); | 122 | list_move_tail(&base->vm_status, &vm->evicted); |
124 | spin_unlock(&vm->status_lock); | ||
125 | } | 123 | } |
126 | 124 | ||
127 | /** | 125 | /** |
@@ -228,7 +226,6 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, | |||
228 | struct ttm_bo_global *glob = adev->mman.bdev.glob; | 226 | struct ttm_bo_global *glob = adev->mman.bdev.glob; |
229 | int r; | 227 | int r; |
230 | 228 | ||
231 | spin_lock(&vm->status_lock); | ||
232 | while (!list_empty(&vm->evicted)) { | 229 | while (!list_empty(&vm->evicted)) { |
233 | struct amdgpu_vm_bo_base *bo_base; | 230 | struct amdgpu_vm_bo_base *bo_base; |
234 | struct amdgpu_bo *bo; | 231 | struct amdgpu_bo *bo; |
@@ -236,10 +233,8 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, | |||
236 | bo_base = list_first_entry(&vm->evicted, | 233 | bo_base = list_first_entry(&vm->evicted, |
237 | struct amdgpu_vm_bo_base, | 234 | struct amdgpu_vm_bo_base, |
238 | vm_status); | 235 | vm_status); |
239 | spin_unlock(&vm->status_lock); | ||
240 | 236 | ||
241 | bo = bo_base->bo; | 237 | bo = bo_base->bo; |
242 | BUG_ON(!bo); | ||
243 | if (bo->parent) { | 238 | if (bo->parent) { |
244 | r = validate(param, bo); | 239 | r = validate(param, bo); |
245 | if (r) | 240 | if (r) |
@@ -259,13 +254,14 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, | |||
259 | return r; | 254 | return r; |
260 | } | 255 | } |
261 | 256 | ||
262 | spin_lock(&vm->status_lock); | 257 | if (bo->tbo.type != ttm_bo_type_kernel) { |
263 | if (bo->tbo.type != ttm_bo_type_kernel) | 258 | spin_lock(&vm->moved_lock); |
264 | list_move(&bo_base->vm_status, &vm->moved); | 259 | list_move(&bo_base->vm_status, &vm->moved); |
265 | else | 260 | spin_unlock(&vm->moved_lock); |
261 | } else { | ||
266 | list_move(&bo_base->vm_status, &vm->relocated); | 262 | list_move(&bo_base->vm_status, &vm->relocated); |
263 | } | ||
267 | } | 264 | } |
268 | spin_unlock(&vm->status_lock); | ||
269 | 265 | ||
270 | return 0; | 266 | return 0; |
271 | } | 267 | } |
@@ -279,13 +275,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, | |||
279 | */ | 275 | */ |
280 | bool amdgpu_vm_ready(struct amdgpu_vm *vm) | 276 | bool amdgpu_vm_ready(struct amdgpu_vm *vm) |
281 | { | 277 | { |
282 | bool ready; | 278 | return list_empty(&vm->evicted); |
283 | |||
284 | spin_lock(&vm->status_lock); | ||
285 | ready = list_empty(&vm->evicted); | ||
286 | spin_unlock(&vm->status_lock); | ||
287 | |||
288 | return ready; | ||
289 | } | 279 | } |
290 | 280 | ||
291 | /** | 281 | /** |
@@ -477,9 +467,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, | |||
477 | pt->parent = amdgpu_bo_ref(parent->base.bo); | 467 | pt->parent = amdgpu_bo_ref(parent->base.bo); |
478 | 468 | ||
479 | amdgpu_vm_bo_base_init(&entry->base, vm, pt); | 469 | amdgpu_vm_bo_base_init(&entry->base, vm, pt); |
480 | spin_lock(&vm->status_lock); | ||
481 | list_move(&entry->base.vm_status, &vm->relocated); | 470 | list_move(&entry->base.vm_status, &vm->relocated); |
482 | spin_unlock(&vm->status_lock); | ||
483 | } | 471 | } |
484 | 472 | ||
485 | if (level < AMDGPU_VM_PTB) { | 473 | if (level < AMDGPU_VM_PTB) { |
@@ -926,10 +914,8 @@ static void amdgpu_vm_invalidate_level(struct amdgpu_device *adev, | |||
926 | if (!entry->base.bo) | 914 | if (!entry->base.bo) |
927 | continue; | 915 | continue; |
928 | 916 | ||
929 | spin_lock(&vm->status_lock); | ||
930 | if (list_empty(&entry->base.vm_status)) | 917 | if (list_empty(&entry->base.vm_status)) |
931 | list_add(&entry->base.vm_status, &vm->relocated); | 918 | list_add(&entry->base.vm_status, &vm->relocated); |
932 | spin_unlock(&vm->status_lock); | ||
933 | amdgpu_vm_invalidate_level(adev, vm, entry, level + 1); | 919 | amdgpu_vm_invalidate_level(adev, vm, entry, level + 1); |
934 | } | 920 | } |
935 | } | 921 | } |
@@ -974,7 +960,6 @@ restart: | |||
974 | params.func = amdgpu_vm_do_set_ptes; | 960 | params.func = amdgpu_vm_do_set_ptes; |
975 | } | 961 | } |
976 | 962 | ||
977 | spin_lock(&vm->status_lock); | ||
978 | while (!list_empty(&vm->relocated)) { | 963 | while (!list_empty(&vm->relocated)) { |
979 | struct amdgpu_vm_bo_base *bo_base, *parent; | 964 | struct amdgpu_vm_bo_base *bo_base, *parent; |
980 | struct amdgpu_vm_pt *pt, *entry; | 965 | struct amdgpu_vm_pt *pt, *entry; |
@@ -984,13 +969,10 @@ restart: | |||
984 | struct amdgpu_vm_bo_base, | 969 | struct amdgpu_vm_bo_base, |
985 | vm_status); | 970 | vm_status); |
986 | list_del_init(&bo_base->vm_status); | 971 | list_del_init(&bo_base->vm_status); |
987 | spin_unlock(&vm->status_lock); | ||
988 | 972 | ||
989 | bo = bo_base->bo->parent; | 973 | bo = bo_base->bo->parent; |
990 | if (!bo) { | 974 | if (!bo) |
991 | spin_lock(&vm->status_lock); | ||
992 | continue; | 975 | continue; |
993 | } | ||
994 | 976 | ||
995 | parent = list_first_entry(&bo->va, struct amdgpu_vm_bo_base, | 977 | parent = list_first_entry(&bo->va, struct amdgpu_vm_bo_base, |
996 | bo_list); | 978 | bo_list); |
@@ -999,12 +981,10 @@ restart: | |||
999 | 981 | ||
1000 | amdgpu_vm_update_pde(¶ms, vm, pt, entry); | 982 | amdgpu_vm_update_pde(¶ms, vm, pt, entry); |
1001 | 983 | ||
1002 | spin_lock(&vm->status_lock); | ||
1003 | if (!vm->use_cpu_for_update && | 984 | if (!vm->use_cpu_for_update && |
1004 | (ndw - params.ib->length_dw) < 32) | 985 | (ndw - params.ib->length_dw) < 32) |
1005 | break; | 986 | break; |
1006 | } | 987 | } |
1007 | spin_unlock(&vm->status_lock); | ||
1008 | 988 | ||
1009 | if (vm->use_cpu_for_update) { | 989 | if (vm->use_cpu_for_update) { |
1010 | /* Flush HDP */ | 990 | /* Flush HDP */ |
@@ -1107,9 +1087,7 @@ static void amdgpu_vm_handle_huge_pages(struct amdgpu_pte_update_params *p, | |||
1107 | if (entry->huge) { | 1087 | if (entry->huge) { |
1108 | /* Add the entry to the relocated list to update it. */ | 1088 | /* Add the entry to the relocated list to update it. */ |
1109 | entry->huge = false; | 1089 | entry->huge = false; |
1110 | spin_lock(&p->vm->status_lock); | ||
1111 | list_move(&entry->base.vm_status, &p->vm->relocated); | 1090 | list_move(&entry->base.vm_status, &p->vm->relocated); |
1112 | spin_unlock(&p->vm->status_lock); | ||
1113 | } | 1091 | } |
1114 | return; | 1092 | return; |
1115 | } | 1093 | } |
@@ -1588,8 +1566,9 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, | |||
1588 | amdgpu_asic_flush_hdp(adev, NULL); | 1566 | amdgpu_asic_flush_hdp(adev, NULL); |
1589 | } | 1567 | } |
1590 | 1568 | ||
1591 | spin_lock(&vm->status_lock); | 1569 | spin_lock(&vm->moved_lock); |
1592 | list_del_init(&bo_va->base.vm_status); | 1570 | list_del_init(&bo_va->base.vm_status); |
1571 | spin_unlock(&vm->moved_lock); | ||
1593 | 1572 | ||
1594 | /* If the BO is not in its preferred location add it back to | 1573 | /* If the BO is not in its preferred location add it back to |
1595 | * the evicted list so that it gets validated again on the | 1574 | * the evicted list so that it gets validated again on the |
@@ -1599,7 +1578,6 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, | |||
1599 | !(bo->preferred_domains & | 1578 | !(bo->preferred_domains & |
1600 | amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type))) | 1579 | amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type))) |
1601 | list_add_tail(&bo_va->base.vm_status, &vm->evicted); | 1580 | list_add_tail(&bo_va->base.vm_status, &vm->evicted); |
1602 | spin_unlock(&vm->status_lock); | ||
1603 | 1581 | ||
1604 | list_splice_init(&bo_va->invalids, &bo_va->valids); | 1582 | list_splice_init(&bo_va->invalids, &bo_va->valids); |
1605 | bo_va->cleared = clear; | 1583 | bo_va->cleared = clear; |
@@ -1811,14 +1789,14 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev, | |||
1811 | bool clear; | 1789 | bool clear; |
1812 | int r = 0; | 1790 | int r = 0; |
1813 | 1791 | ||
1814 | spin_lock(&vm->status_lock); | 1792 | spin_lock(&vm->moved_lock); |
1815 | while (!list_empty(&vm->moved)) { | 1793 | while (!list_empty(&vm->moved)) { |
1816 | struct amdgpu_bo_va *bo_va; | 1794 | struct amdgpu_bo_va *bo_va; |
1817 | struct reservation_object *resv; | 1795 | struct reservation_object *resv; |
1818 | 1796 | ||
1819 | bo_va = list_first_entry(&vm->moved, | 1797 | bo_va = list_first_entry(&vm->moved, |
1820 | struct amdgpu_bo_va, base.vm_status); | 1798 | struct amdgpu_bo_va, base.vm_status); |
1821 | spin_unlock(&vm->status_lock); | 1799 | spin_unlock(&vm->moved_lock); |
1822 | 1800 | ||
1823 | resv = bo_va->base.bo->tbo.resv; | 1801 | resv = bo_va->base.bo->tbo.resv; |
1824 | 1802 | ||
@@ -1839,9 +1817,9 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev, | |||
1839 | if (!clear && resv != vm->root.base.bo->tbo.resv) | 1817 | if (!clear && resv != vm->root.base.bo->tbo.resv) |
1840 | reservation_object_unlock(resv); | 1818 | reservation_object_unlock(resv); |
1841 | 1819 | ||
1842 | spin_lock(&vm->status_lock); | 1820 | spin_lock(&vm->moved_lock); |
1843 | } | 1821 | } |
1844 | spin_unlock(&vm->status_lock); | 1822 | spin_unlock(&vm->moved_lock); |
1845 | 1823 | ||
1846 | return r; | 1824 | return r; |
1847 | } | 1825 | } |
@@ -1903,10 +1881,10 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev, | |||
1903 | amdgpu_vm_prt_get(adev); | 1881 | amdgpu_vm_prt_get(adev); |
1904 | 1882 | ||
1905 | if (bo && bo->tbo.resv == vm->root.base.bo->tbo.resv) { | 1883 | if (bo && bo->tbo.resv == vm->root.base.bo->tbo.resv) { |
1906 | spin_lock(&vm->status_lock); | 1884 | spin_lock(&vm->moved_lock); |
1907 | if (list_empty(&bo_va->base.vm_status)) | 1885 | if (list_empty(&bo_va->base.vm_status)) |
1908 | list_add(&bo_va->base.vm_status, &vm->moved); | 1886 | list_add(&bo_va->base.vm_status, &vm->moved); |
1909 | spin_unlock(&vm->status_lock); | 1887 | spin_unlock(&vm->moved_lock); |
1910 | } | 1888 | } |
1911 | trace_amdgpu_vm_bo_map(bo_va, mapping); | 1889 | trace_amdgpu_vm_bo_map(bo_va, mapping); |
1912 | } | 1890 | } |
@@ -2216,9 +2194,9 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, | |||
2216 | 2194 | ||
2217 | list_del(&bo_va->base.bo_list); | 2195 | list_del(&bo_va->base.bo_list); |
2218 | 2196 | ||
2219 | spin_lock(&vm->status_lock); | 2197 | spin_lock(&vm->moved_lock); |
2220 | list_del(&bo_va->base.vm_status); | 2198 | list_del(&bo_va->base.vm_status); |
2221 | spin_unlock(&vm->status_lock); | 2199 | spin_unlock(&vm->moved_lock); |
2222 | 2200 | ||
2223 | list_for_each_entry_safe(mapping, next, &bo_va->valids, list) { | 2201 | list_for_each_entry_safe(mapping, next, &bo_va->valids, list) { |
2224 | list_del(&mapping->list); | 2202 | list_del(&mapping->list); |
@@ -2261,28 +2239,24 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev, | |||
2261 | 2239 | ||
2262 | bo_base->moved = true; | 2240 | bo_base->moved = true; |
2263 | if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { | 2241 | if (evicted && bo->tbo.resv == vm->root.base.bo->tbo.resv) { |
2264 | spin_lock(&bo_base->vm->status_lock); | ||
2265 | if (bo->tbo.type == ttm_bo_type_kernel) | 2242 | if (bo->tbo.type == ttm_bo_type_kernel) |
2266 | list_move(&bo_base->vm_status, &vm->evicted); | 2243 | list_move(&bo_base->vm_status, &vm->evicted); |
2267 | else | 2244 | else |
2268 | list_move_tail(&bo_base->vm_status, | 2245 | list_move_tail(&bo_base->vm_status, |
2269 | &vm->evicted); | 2246 | &vm->evicted); |
2270 | spin_unlock(&bo_base->vm->status_lock); | ||
2271 | continue; | 2247 | continue; |
2272 | } | 2248 | } |
2273 | 2249 | ||
2274 | if (bo->tbo.type == ttm_bo_type_kernel) { | 2250 | if (bo->tbo.type == ttm_bo_type_kernel) { |
2275 | spin_lock(&bo_base->vm->status_lock); | ||
2276 | if (list_empty(&bo_base->vm_status)) | 2251 | if (list_empty(&bo_base->vm_status)) |
2277 | list_add(&bo_base->vm_status, &vm->relocated); | 2252 | list_add(&bo_base->vm_status, &vm->relocated); |
2278 | spin_unlock(&bo_base->vm->status_lock); | ||
2279 | continue; | 2253 | continue; |
2280 | } | 2254 | } |
2281 | 2255 | ||
2282 | spin_lock(&bo_base->vm->status_lock); | 2256 | spin_lock(&bo_base->vm->moved_lock); |
2283 | if (list_empty(&bo_base->vm_status)) | 2257 | if (list_empty(&bo_base->vm_status)) |
2284 | list_add(&bo_base->vm_status, &vm->moved); | 2258 | list_add(&bo_base->vm_status, &vm->moved); |
2285 | spin_unlock(&bo_base->vm->status_lock); | 2259 | spin_unlock(&bo_base->vm->moved_lock); |
2286 | } | 2260 | } |
2287 | } | 2261 | } |
2288 | 2262 | ||
@@ -2391,9 +2365,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, | |||
2391 | vm->va = RB_ROOT_CACHED; | 2365 | vm->va = RB_ROOT_CACHED; |
2392 | for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) | 2366 | for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) |
2393 | vm->reserved_vmid[i] = NULL; | 2367 | vm->reserved_vmid[i] = NULL; |
2394 | spin_lock_init(&vm->status_lock); | ||
2395 | INIT_LIST_HEAD(&vm->evicted); | 2368 | INIT_LIST_HEAD(&vm->evicted); |
2396 | INIT_LIST_HEAD(&vm->relocated); | 2369 | INIT_LIST_HEAD(&vm->relocated); |
2370 | spin_lock_init(&vm->moved_lock); | ||
2397 | INIT_LIST_HEAD(&vm->moved); | 2371 | INIT_LIST_HEAD(&vm->moved); |
2398 | INIT_LIST_HEAD(&vm->freed); | 2372 | INIT_LIST_HEAD(&vm->freed); |
2399 | 2373 | ||
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index d6827083572a..0196b9a782f2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | |||
@@ -168,9 +168,6 @@ struct amdgpu_vm { | |||
168 | /* tree of virtual addresses mapped */ | 168 | /* tree of virtual addresses mapped */ |
169 | struct rb_root_cached va; | 169 | struct rb_root_cached va; |
170 | 170 | ||
171 | /* protecting invalidated */ | ||
172 | spinlock_t status_lock; | ||
173 | |||
174 | /* BOs who needs a validation */ | 171 | /* BOs who needs a validation */ |
175 | struct list_head evicted; | 172 | struct list_head evicted; |
176 | 173 | ||
@@ -179,6 +176,7 @@ struct amdgpu_vm { | |||
179 | 176 | ||
180 | /* BOs moved, but not yet updated in the PT */ | 177 | /* BOs moved, but not yet updated in the PT */ |
181 | struct list_head moved; | 178 | struct list_head moved; |
179 | spinlock_t moved_lock; | ||
182 | 180 | ||
183 | /* BO mappings freed, but not yet updated in the PT */ | 181 | /* BO mappings freed, but not yet updated in the PT */ |
184 | struct list_head freed; | 182 | struct list_head freed; |