@@ -204,38 +204,25 @@ void amdgpu_amdkfd_unreserve_memory_limit(struct amdgpu_bo *bo)
204
204
}
205
205
206
206
207
- /* amdgpu_amdkfd_remove_eviction_fence - Removes eviction fence(s) from BO's
207
+ /* amdgpu_amdkfd_remove_eviction_fence - Removes eviction fence from BO's
208
208
* reservation object.
209
209
*
210
210
* @bo: [IN] Remove eviction fence(s) from this BO
211
- * @ef: [IN] If ef is specified, then this eviction fence is removed if it
211
+ * @ef: [IN] This eviction fence is removed if it
212
212
* is present in the shared list.
213
- * @ef_list: [OUT] Returns list of eviction fences. These fences are removed
214
- * from BO's reservation object shared list.
215
- * @ef_count: [OUT] Number of fences in ef_list.
216
213
*
217
- * NOTE: If called with ef_list, then amdgpu_amdkfd_add_eviction_fence must be
218
- * called to restore the eviction fences and to avoid memory leak. This is
219
- * useful for shared BOs.
220
214
* NOTE: Must be called with BO reserved i.e. bo->tbo.resv->lock held.
221
215
*/
222
216
static int amdgpu_amdkfd_remove_eviction_fence (struct amdgpu_bo * bo ,
223
- struct amdgpu_amdkfd_fence * ef ,
224
- struct amdgpu_amdkfd_fence * * * ef_list ,
225
- unsigned int * ef_count )
217
+ struct amdgpu_amdkfd_fence * ef )
226
218
{
227
219
struct reservation_object * resv = bo -> tbo .resv ;
228
220
struct reservation_object_list * old , * new ;
229
221
unsigned int i , j , k ;
230
222
231
- if (!ef && ! ef_list )
223
+ if (!ef )
232
224
return - EINVAL ;
233
225
234
- if (ef_list ) {
235
- * ef_list = NULL ;
236
- * ef_count = 0 ;
237
- }
238
-
239
226
old = reservation_object_get_list (resv );
240
227
if (!old )
241
228
return 0 ;
@@ -254,30 +241,14 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
254
241
f = rcu_dereference_protected (old -> shared [i ],
255
242
reservation_object_held (resv ));
256
243
257
- if ((ef && f -> context == ef -> base .context ) ||
258
- (!ef && to_amdgpu_amdkfd_fence (f )))
244
+ if (f -> context == ef -> base .context )
259
245
RCU_INIT_POINTER (new -> shared [-- j ], f );
260
246
else
261
247
RCU_INIT_POINTER (new -> shared [k ++ ], f );
262
248
}
263
249
new -> shared_max = old -> shared_max ;
264
250
new -> shared_count = k ;
265
251
266
- if (!ef ) {
267
- unsigned int count = old -> shared_count - j ;
268
-
269
- /* Alloc memory for count number of eviction fence pointers.
270
- * Fill the ef_list array and ef_count
271
- */
272
- * ef_list = kcalloc (count , sizeof (* * ef_list ), GFP_KERNEL );
273
- * ef_count = count ;
274
-
275
- if (!* ef_list ) {
276
- kfree (new );
277
- return - ENOMEM ;
278
- }
279
- }
280
-
281
252
/* Install the new fence list, seqcount provides the barriers */
282
253
preempt_disable ();
283
254
write_seqcount_begin (& resv -> seq );
@@ -291,46 +262,13 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
291
262
292
263
f = rcu_dereference_protected (new -> shared [i ],
293
264
reservation_object_held (resv ));
294
- if (!ef )
295
- (* ef_list )[k ++ ] = to_amdgpu_amdkfd_fence (f );
296
- else
297
- dma_fence_put (f );
265
+ dma_fence_put (f );
298
266
}
299
267
kfree_rcu (old , rcu );
300
268
301
269
return 0 ;
302
270
}
303
271
304
- /* amdgpu_amdkfd_add_eviction_fence - Adds eviction fence(s) back into BO's
305
- * reservation object.
306
- *
307
- * @bo: [IN] Add eviction fences to this BO
308
- * @ef_list: [IN] List of eviction fences to be added
309
- * @ef_count: [IN] Number of fences in ef_list.
310
- *
311
- * NOTE: Must call amdgpu_amdkfd_remove_eviction_fence before calling this
312
- * function.
313
- */
314
- static void amdgpu_amdkfd_add_eviction_fence (struct amdgpu_bo * bo ,
315
- struct amdgpu_amdkfd_fence * * ef_list ,
316
- unsigned int ef_count )
317
- {
318
- int i ;
319
-
320
- if (!ef_list || !ef_count )
321
- return ;
322
-
323
- for (i = 0 ; i < ef_count ; i ++ ) {
324
- amdgpu_bo_fence (bo , & ef_list [i ]-> base , true);
325
- /* Re-adding the fence takes an additional reference. Drop that
326
- * reference.
327
- */
328
- dma_fence_put (& ef_list [i ]-> base );
329
- }
330
-
331
- kfree (ef_list );
332
- }
333
-
334
272
static int amdgpu_amdkfd_bo_validate (struct amdgpu_bo * bo , uint32_t domain ,
335
273
bool wait )
336
274
{
@@ -346,18 +284,8 @@ static int amdgpu_amdkfd_bo_validate(struct amdgpu_bo *bo, uint32_t domain,
346
284
ret = ttm_bo_validate (& bo -> tbo , & bo -> placement , & ctx );
347
285
if (ret )
348
286
goto validate_fail ;
349
- if (wait ) {
350
- struct amdgpu_amdkfd_fence * * ef_list ;
351
- unsigned int ef_count ;
352
-
353
- ret = amdgpu_amdkfd_remove_eviction_fence (bo , NULL , & ef_list ,
354
- & ef_count );
355
- if (ret )
356
- goto validate_fail ;
357
-
358
- ttm_bo_wait (& bo -> tbo , false, false);
359
- amdgpu_amdkfd_add_eviction_fence (bo , ef_list , ef_count );
360
- }
287
+ if (wait )
288
+ amdgpu_bo_sync_wait (bo , AMDGPU_FENCE_OWNER_KFD , false);
361
289
362
290
validate_fail :
363
291
return ret ;
@@ -444,7 +372,6 @@ static int add_bo_to_vm(struct amdgpu_device *adev, struct kgd_mem *mem,
444
372
{
445
373
int ret ;
446
374
struct kfd_bo_va_list * bo_va_entry ;
447
- struct amdgpu_bo * pd = vm -> root .base .bo ;
448
375
struct amdgpu_bo * bo = mem -> bo ;
449
376
uint64_t va = mem -> va ;
450
377
struct list_head * list_bo_va = & mem -> bo_va_list ;
@@ -484,14 +411,8 @@ static int add_bo_to_vm(struct amdgpu_device *adev, struct kgd_mem *mem,
484
411
* p_bo_va_entry = bo_va_entry ;
485
412
486
413
/* Allocate new page tables if needed and validate
487
- * them. Clearing of new page tables and validate need to wait
488
- * on move fences. We don't want that to trigger the eviction
489
- * fence, so remove it temporarily.
414
+ * them.
490
415
*/
491
- amdgpu_amdkfd_remove_eviction_fence (pd ,
492
- vm -> process_info -> eviction_fence ,
493
- NULL , NULL );
494
-
495
416
ret = amdgpu_vm_alloc_pts (adev , vm , va , amdgpu_bo_size (bo ));
496
417
if (ret ) {
497
418
pr_err ("Failed to allocate pts, err=%d\n" , ret );
@@ -504,13 +425,9 @@ static int add_bo_to_vm(struct amdgpu_device *adev, struct kgd_mem *mem,
504
425
goto err_alloc_pts ;
505
426
}
506
427
507
- /* Add the eviction fence back */
508
- amdgpu_bo_fence (pd , & vm -> process_info -> eviction_fence -> base , true);
509
-
510
428
return 0 ;
511
429
512
430
err_alloc_pts :
513
- amdgpu_bo_fence (pd , & vm -> process_info -> eviction_fence -> base , true);
514
431
amdgpu_vm_bo_rmv (adev , bo_va_entry -> bo_va );
515
432
list_del (& bo_va_entry -> bo_list );
516
433
err_vmadd :
@@ -809,24 +726,11 @@ static int unmap_bo_from_gpuvm(struct amdgpu_device *adev,
809
726
{
810
727
struct amdgpu_bo_va * bo_va = entry -> bo_va ;
811
728
struct amdgpu_vm * vm = bo_va -> base .vm ;
812
- struct amdgpu_bo * pd = vm -> root .base .bo ;
813
729
814
- /* Remove eviction fence from PD (and thereby from PTs too as
815
- * they share the resv. object). Otherwise during PT update
816
- * job (see amdgpu_vm_bo_update_mapping), eviction fence would
817
- * get added to job->sync object and job execution would
818
- * trigger the eviction fence.
819
- */
820
- amdgpu_amdkfd_remove_eviction_fence (pd ,
821
- vm -> process_info -> eviction_fence ,
822
- NULL , NULL );
823
730
amdgpu_vm_bo_unmap (adev , bo_va , entry -> va );
824
731
825
732
amdgpu_vm_clear_freed (adev , vm , & bo_va -> last_pt_update );
826
733
827
- /* Add the eviction fence back */
828
- amdgpu_bo_fence (pd , & vm -> process_info -> eviction_fence -> base , true);
829
-
830
734
amdgpu_sync_fence (NULL , sync , bo_va -> last_pt_update , false);
831
735
832
736
return 0 ;
@@ -1002,7 +906,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
1002
906
pr_err ("validate_pt_pd_bos() failed\n" );
1003
907
goto validate_pd_fail ;
1004
908
}
1005
- ret = ttm_bo_wait ( & vm -> root .base .bo -> tbo , false , false);
909
+ amdgpu_bo_sync_wait ( vm -> root .base .bo , AMDGPU_FENCE_OWNER_KFD , false);
1006
910
if (ret )
1007
911
goto wait_pd_fail ;
1008
912
amdgpu_bo_fence (vm -> root .base .bo ,
@@ -1389,8 +1293,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
1389
1293
* attached
1390
1294
*/
1391
1295
amdgpu_amdkfd_remove_eviction_fence (mem -> bo ,
1392
- process_info -> eviction_fence ,
1393
- NULL , NULL );
1296
+ process_info -> eviction_fence );
1394
1297
pr_debug ("Release VA 0x%llx - 0x%llx\n" , mem -> va ,
1395
1298
mem -> va + bo_size * (1 + mem -> aql_queue ));
1396
1299
@@ -1617,8 +1520,7 @@ int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(
1617
1520
if (mem -> mapped_to_gpu_memory == 0 &&
1618
1521
!amdgpu_ttm_tt_get_usermm (mem -> bo -> tbo .ttm ) && !mem -> bo -> pin_count )
1619
1522
amdgpu_amdkfd_remove_eviction_fence (mem -> bo ,
1620
- process_info -> eviction_fence ,
1621
- NULL , NULL );
1523
+ process_info -> eviction_fence );
1622
1524
1623
1525
unreserve_out :
1624
1526
unreserve_bo_and_vms (& ctx , false, false);
@@ -1679,7 +1581,7 @@ int amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel(struct kgd_dev *kgd,
1679
1581
}
1680
1582
1681
1583
amdgpu_amdkfd_remove_eviction_fence (
1682
- bo , mem -> process_info -> eviction_fence , NULL , NULL );
1584
+ bo , mem -> process_info -> eviction_fence );
1683
1585
list_del_init (& mem -> validate_list .head );
1684
1586
1685
1587
if (size )
@@ -1945,16 +1847,6 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
1945
1847
1946
1848
amdgpu_sync_create (& sync );
1947
1849
1948
- /* Avoid triggering eviction fences when unmapping invalid
1949
- * userptr BOs (waits for all fences, doesn't use
1950
- * FENCE_OWNER_VM)
1951
- */
1952
- list_for_each_entry (peer_vm , & process_info -> vm_list_head ,
1953
- vm_list_node )
1954
- amdgpu_amdkfd_remove_eviction_fence (peer_vm -> root .base .bo ,
1955
- process_info -> eviction_fence ,
1956
- NULL , NULL );
1957
-
1958
1850
ret = process_validate_vms (process_info );
1959
1851
if (ret )
1960
1852
goto unreserve_out ;
@@ -2015,10 +1907,6 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
2015
1907
ret = process_update_pds (process_info , & sync );
2016
1908
2017
1909
unreserve_out :
2018
- list_for_each_entry (peer_vm , & process_info -> vm_list_head ,
2019
- vm_list_node )
2020
- amdgpu_bo_fence (peer_vm -> root .base .bo ,
2021
- & process_info -> eviction_fence -> base , true);
2022
1910
ttm_eu_backoff_reservation (& ticket , & resv_list );
2023
1911
amdgpu_sync_wait (& sync , false);
2024
1912
amdgpu_sync_free (& sync );
0 commit comments