@@ -280,14 +280,13 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
280280 ret = 0 ;
281281 }
282282
283- if (ret || unlikely ( list_empty ( & bo -> ddestroy )) ) {
283+ if (ret ) {
284284 if (unlock_resv )
285285 dma_resv_unlock (bo -> base .resv );
286286 spin_unlock (& bo -> bdev -> lru_lock );
287287 return ret ;
288288 }
289289
290- list_del_init (& bo -> ddestroy );
291290 spin_unlock (& bo -> bdev -> lru_lock );
292291 ttm_bo_cleanup_memtype_use (bo );
293292
@@ -300,47 +299,21 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,
300299}
301300
302301/*
303- * Traverse the delayed list, and call ttm_bo_cleanup_refs on all
304- * encountered buffers .
302+ * Block for the dma_resv object to become idle, lock the buffer and clean up
303+ * the resource and tt object .
305304 */
306- bool ttm_bo_delayed_delete (struct ttm_device * bdev , bool remove_all )
305+ static void ttm_bo_delayed_delete (struct work_struct * work )
307306{
308- struct list_head removed ;
309- bool empty ;
310-
311- INIT_LIST_HEAD (& removed );
312-
313- spin_lock (& bdev -> lru_lock );
314- while (!list_empty (& bdev -> ddestroy )) {
315- struct ttm_buffer_object * bo ;
316-
317- bo = list_first_entry (& bdev -> ddestroy , struct ttm_buffer_object ,
318- ddestroy );
319- list_move_tail (& bo -> ddestroy , & removed );
320- if (!ttm_bo_get_unless_zero (bo ))
321- continue ;
322-
323- if (remove_all || bo -> base .resv != & bo -> base ._resv ) {
324- spin_unlock (& bdev -> lru_lock );
325- dma_resv_lock (bo -> base .resv , NULL );
326-
327- spin_lock (& bdev -> lru_lock );
328- ttm_bo_cleanup_refs (bo , false, !remove_all , true);
329-
330- } else if (dma_resv_trylock (bo -> base .resv )) {
331- ttm_bo_cleanup_refs (bo , false, !remove_all , true);
332- } else {
333- spin_unlock (& bdev -> lru_lock );
334- }
307+ struct ttm_buffer_object * bo ;
335308
336- ttm_bo_put (bo );
337- spin_lock (& bdev -> lru_lock );
338- }
339- list_splice_tail (& removed , & bdev -> ddestroy );
340- empty = list_empty (& bdev -> ddestroy );
341- spin_unlock (& bdev -> lru_lock );
309+ bo = container_of (work , typeof (* bo ), delayed_delete );
342310
343- return empty ;
311+ dma_resv_wait_timeout (bo -> base .resv , DMA_RESV_USAGE_BOOKKEEP , false,
312+ MAX_SCHEDULE_TIMEOUT );
313+ dma_resv_lock (bo -> base .resv , NULL );
314+ ttm_bo_cleanup_memtype_use (bo );
315+ dma_resv_unlock (bo -> base .resv );
316+ ttm_bo_put (bo );
344317}
345318
346319static void ttm_bo_release (struct kref * kref )
@@ -369,44 +342,40 @@ static void ttm_bo_release(struct kref *kref)
369342
370343 drm_vma_offset_remove (bdev -> vma_manager , & bo -> base .vma_node );
371344 ttm_mem_io_free (bdev , bo -> resource );
372- }
373-
374- if (!dma_resv_test_signaled (bo -> base .resv , DMA_RESV_USAGE_BOOKKEEP ) ||
375- !dma_resv_trylock (bo -> base .resv )) {
376- /* The BO is not idle, resurrect it for delayed destroy */
377- ttm_bo_flush_all_fences (bo );
378- bo -> deleted = true;
379345
380- spin_lock (& bo -> bdev -> lru_lock );
346+ if (!dma_resv_test_signaled (bo -> base .resv ,
347+ DMA_RESV_USAGE_BOOKKEEP ) ||
348+ !dma_resv_trylock (bo -> base .resv )) {
349+ /* The BO is not idle, resurrect it for delayed destroy */
350+ ttm_bo_flush_all_fences (bo );
351+ bo -> deleted = true;
381352
382- /*
383- * Make pinned bos immediately available to
384- * shrinkers, now that they are queued for
385- * destruction.
386- *
387- * FIXME: QXL is triggering this. Can be removed when the
388- * driver is fixed.
389- */
390- if (bo -> pin_count ) {
391- bo -> pin_count = 0 ;
392- ttm_resource_move_to_lru_tail (bo -> resource );
393- }
353+ spin_lock (& bo -> bdev -> lru_lock );
394354
395- kref_init (& bo -> kref );
396- list_add_tail (& bo -> ddestroy , & bdev -> ddestroy );
397- spin_unlock (& bo -> bdev -> lru_lock );
355+ /*
356+ * Make pinned bos immediately available to
357+ * shrinkers, now that they are queued for
358+ * destruction.
359+ *
360+ * FIXME: QXL is triggering this. Can be removed when the
361+ * driver is fixed.
362+ */
363+ if (bo -> pin_count ) {
364+ bo -> pin_count = 0 ;
365+ ttm_resource_move_to_lru_tail (bo -> resource );
366+ }
398367
399- schedule_delayed_work (& bdev -> wq ,
400- ((HZ / 100 ) < 1 ) ? 1 : HZ / 100 );
401- return ;
402- }
368+ kref_init (& bo -> kref );
369+ spin_unlock (& bo -> bdev -> lru_lock );
403370
404- spin_lock (& bo -> bdev -> lru_lock );
405- list_del (& bo -> ddestroy );
406- spin_unlock (& bo -> bdev -> lru_lock );
371+ INIT_WORK (& bo -> delayed_delete , ttm_bo_delayed_delete );
372+ queue_work (bdev -> wq , & bo -> delayed_delete );
373+ return ;
374+ }
407375
408- ttm_bo_cleanup_memtype_use (bo );
409- dma_resv_unlock (bo -> base .resv );
376+ ttm_bo_cleanup_memtype_use (bo );
377+ dma_resv_unlock (bo -> base .resv );
378+ }
410379
411380 atomic_dec (& ttm_glob .bo_count );
412381 bo -> destroy (bo );
@@ -946,7 +915,6 @@ int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo,
946915 int ret ;
947916
948917 kref_init (& bo -> kref );
949- INIT_LIST_HEAD (& bo -> ddestroy );
950918 bo -> bdev = bdev ;
951919 bo -> type = type ;
952920 bo -> page_alignment = alignment ;
0 commit comments