dma-buf: fix inconsistent debug print
Subsystems (16)
PATCH 1/7 dma-buf: fix inconsistent debug print
The code tries to acquire the rcu protected fence list, but then ignores individual fences which have been modified while holding the rcu.
Stop that madness and just note cleanly that the list was concurrently modified.
--- drivers/dma-buf/dma-buf.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/dma-buf/dma-buf.c +8 -11
@@ -1383,22 +1383,17 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) buf_obj->name ?: ""); robj = buf_obj->resv; -while (true) { - seq =read_seqcount_begin (&robj->seq); -rcu_read_lock (); - fobj =rcu_dereference (robj->fence); - shared_count = fobj ? fobj->shared_count :0 ; - fence =rcu_dereference (robj->fence_excl); -if (!read_seqcount_retry (&robj->seq, seq)) -break ; -rcu_read_unlock (); - } - + seq =read_seqcount_begin (&robj->seq); +rcu_read_lock (); + fence =rcu_dereference (robj->fence_excl);if (fence)seq_printf (s,"\tExclusive fence: %s %s %ssignalled\n" , fence->ops->get_driver_name (fence), fence->ops->get_timeline_name (fence),dma_fence_is_signaled (fence) ?"" :"un" ); + + fobj =rcu_dereference (robj->fence); + shared_count = fobj ? fobj->shared_count :0 ;for (i =0 ; i < shared_count; i++) { fence =rcu_dereference (fobj->shared[i]);if (!dma_fence_get_rcu (fence))
@@ -1410,6 +1405,8 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)dma_fence_put (fence); }rcu_read_unlock (); +if (read_seqcount_retry (&robj->seq, seq)) +seq_printf (s,"\tFences concurrently modified\n" );seq_puts (s,"\tAttached Devices:\n" ); attach_count =0 ;
Signature · 1 line
2.25.1
PATCH 2/7 dma-buf: add SPDX header and fix style in dma-resv.c
No functional change.
--- drivers/dma-buf/dma-resv.c | 128 +++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 63 deletions(-)
drivers/dma-buf/dma-resv.c +65 -63
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: MIT /* * Copyright (C) 2012-2014 Canonical Ltd (Maarten Lankhorst) *
@@ -92,49 +93,6 @@ static void dma_resv_list_free(struct dma_resv_list *list)kfree_rcu (list, rcu); } -#if IS_ENABLED (CONFIG_LOCKDEP ) -static int __init dma_resv_lockdep (void ) -{ -struct mm_struct *mm =mm_alloc (); -struct ww_acquire_ctx ctx; -struct dma_resv obj; -struct address_space mapping; -int ret; - -if (!mm) -return -ENOMEM ; - -dma_resv_init (&obj); -address_space_init_once (&mapping); - -mmap_read_lock (mm); -ww_acquire_init (&ctx, &reservation_ww_class); - ret =dma_resv_lock (&obj, &ctx); -if (ret == -EDEADLK ) -dma_resv_lock_slow (&obj, &ctx); -fs_reclaim_acquire (GFP_KERNEL ); -/* for unmap_mapping_range on trylocked buffer objects in shrinkers */ -i_mmap_lock_write (&mapping); -i_mmap_unlock_write (&mapping); -#ifdef CONFIG_MMU_NOTIFIER -lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); -__dma_fence_might_wait (); -lock_map_release (&__mmu_notifier_invalidate_range_start_map); -#else -__dma_fence_might_wait (); -#endif -fs_reclaim_release (GFP_KERNEL ); -ww_mutex_unlock (&obj.lock); -ww_acquire_fini (&ctx); -mmap_read_unlock (mm); - -mmput (mm); - -return 0 ; -} -subsys_initcall (dma_resv_lockdep); -#endif -/** * dma_resv_init - initialize a reservation object * @obj: the reservation object
@@ -196,9 +154,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ; -else - max =max (old->shared_count + num_fences, - old->shared_max *2 ); + max =max (old->shared_count + num_fences, old->shared_max *2 ); }else { max =max (4ul ,roundup_pow_of_two (num_fences)); }
@@ -337,17 +293,17 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)EXPORT_SYMBOL (dma_resv_add_excl_fence);/** -* dma_resv_copy_fences - Copy all fences from src to dst. -* @dst: the destination reservation object -* @src: the source reservation object -* -* Copy all fences from src to dst. dst-lock must be held. -*/ +* dma_resv_copy_fences - Copy all fences from src to dst. +* @dst: the destination reservation object +* @src: the source reservation object +* +* Copy all fences from src to dst. dst-lock must be held. +*/ int dma_resv_copy_fences (struct dma_resv *dst,struct dma_resv *src) {struct dma_resv_list *src_list, *dst_list;struct dma_fence *old, *new; -unsigned i; +unsigned int i;dma_resv_assert_held (dst);
@@ -356,7 +312,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) retry:if (src_list) { -unsigned shared_count = src_list->shared_count; +unsigned int shared_count = src_list->shared_count;rcu_read_unlock ();
@@ -373,6 +329,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) dst_list->shared_count =0 ;for (i =0 ; i < src_list->shared_count; ++i) { +struct dma_fence __rcu **dst;struct dma_fence *fence; fence =rcu_dereference (src_list->shared[i]);
@@ -391,7 +348,8 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)continue ; } -rcu_assign_pointer (dst_list->shared[dst_list->shared_count++], fence); + dst = &dst_list->shared[dst_list->shared_count++]; +rcu_assign_pointer (*dst, fence); } }else { dst_list =NULL ;
@@ -431,7 +389,7 @@ EXPORT_SYMBOL(dma_resv_copy_fences);*/ int dma_resv_get_fences_rcu (struct dma_resv *obj,struct dma_fence **pfence_excl, -unsigned *pshared_count, +unsigned int *pshared_count,struct dma_fence ***pshared) {struct dma_fence **shared =NULL ;
@@ -533,9 +491,9 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, bool wait_all, bool intr, unsigned long timeout) { - struct dma_fence *fence; -unsigned seq, shared_count; long ret = timeout ? timeout : 1; +unsigned int seq, shared_count; +struct dma_fence *fence;int i; retry:
@@ -565,8 +523,9 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, shared_count = fobj->shared_count;for (i =0 ; !fence && i < shared_count; ++i) { -struct dma_fence *lfence =rcu_dereference (fobj->shared[i]); +struct dma_fence *lfence; + lfence =rcu_dereference (fobj->shared[i]);if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &lfence->flags))continue ;
@@ -633,7 +592,7 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)*/ bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all) { -unsigned seq, shared_count; +unsigned int seq, shared_count;int ret;rcu_read_lock ();
@@ -643,16 +602,16 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -unsigned i; -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +unsigned int i;if (fobj) shared_count = fobj->shared_count;for (i =0 ; i < shared_count; ++i) { -struct dma_fence *fence =rcu_dereference (fobj->shared[i]); +struct dma_fence *fence; + fence =rcu_dereference (fobj->shared[i]); ret =dma_resv_test_signaled_single (fence);if (ret <0 ) goto retry;
@@ -681,3 +640,46 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)return ret; }EXPORT_SYMBOL_GPL (dma_resv_test_signaled_rcu); + +#if IS_ENABLED (CONFIG_LOCKDEP ) +static int __init dma_resv_lockdep (void ) +{ +struct mm_struct *mm =mm_alloc (); +struct ww_acquire_ctx ctx; +struct dma_resv obj; +struct address_space mapping; +int ret; + +if (!mm) +return -ENOMEM ; + +dma_resv_init (&obj); +address_space_init_once (&mapping); + +mmap_read_lock (mm); +ww_acquire_init (&ctx, &reservation_ww_class); + ret =dma_resv_lock (&obj, &ctx); +if (ret == -EDEADLK ) +dma_resv_lock_slow (&obj, &ctx); +fs_reclaim_acquire (GFP_KERNEL ); +/* for unmap_mapping_range on trylocked buffer objects in shrinkers */ +i_mmap_lock_write (&mapping); +i_mmap_unlock_write (&mapping); +#ifdef CONFIG_MMU_NOTIFIER +lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); +__dma_fence_might_wait (); +lock_map_release (&__mmu_notifier_invalidate_range_start_map); +#else +__dma_fence_might_wait (); +#endif +fs_reclaim_release (GFP_KERNEL ); +ww_mutex_unlock (&obj.lock); +ww_acquire_fini (&ctx); +mmap_read_unlock (mm); + +mmput (mm); + +return 0 ; +} +subsys_initcall (dma_resv_lockdep); +#endif
Signature · 1 line
2.25.1
Re: [PATCH 2/7] dma-buf: add SPDX header and fix style in dma-resv.c
Quoted 3 lines · Christian König
No functional change.
Signed-off-by Christian König <[email protected]>
Maybe add the checkpatch warnings you're fixing here to the commit message. I didn't know that initcalls should be at the bottom ... -Daniel
Quoted 237 lines
--- drivers/dma-buf/dma-resv.c | 128 +++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 63 deletions(-)drivers/dma-buf/dma-resv.c +65
-63@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: MIT /* * Copyright (C) 2012-2014 Canonical Ltd (Maarten Lankhorst) * @@ -92,49 +93,6 @@ static void dma_resv_list_free(struct dma_resv_list *list)kfree_rcu (list, rcu); } -#if IS_ENABLED (CONFIG_LOCKDEP ) -static int __init dma_resv_lockdep (void ) -{ -struct mm_struct *mm =mm_alloc (); -struct ww_acquire_ctx ctx; -struct dma_resv obj; -struct address_space mapping; -int ret; - -if (!mm) -return -ENOMEM ; - -dma_resv_init (&obj); -address_space_init_once (&mapping); - -mmap_read_lock (mm); -ww_acquire_init (&ctx, &reservation_ww_class); - ret =dma_resv_lock (&obj, &ctx); -if (ret == -EDEADLK ) -dma_resv_lock_slow (&obj, &ctx); -fs_reclaim_acquire (GFP_KERNEL ); -/* for unmap_mapping_range on trylocked buffer objects in shrinkers */ -i_mmap_lock_write (&mapping); -i_mmap_unlock_write (&mapping); -#ifdef CONFIG_MMU_NOTIFIER -lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); -__dma_fence_might_wait (); -lock_map_release (&__mmu_notifier_invalidate_range_start_map); -#else -__dma_fence_might_wait (); -#endif -fs_reclaim_release (GFP_KERNEL ); -ww_mutex_unlock (&obj.lock); -ww_acquire_fini (&ctx); -mmap_read_unlock (mm); - -mmput (mm); - -return 0 ; -} -subsys_initcall (dma_resv_lockdep); -#endif -/** * dma_resv_init - initialize a reservation object * @obj: the reservation object @@ -196,9 +154,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ; -else - max =max (old->shared_count + num_fences, - old->shared_max *2 ); + max =max (old->shared_count + num_fences, old->shared_max *2 ); }else { max =max (4ul ,roundup_pow_of_two (num_fences)); }@@ -337,17 +293,17 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)EXPORT_SYMBOL (dma_resv_add_excl_fence);/** -* dma_resv_copy_fences - Copy all fences from src to dst. -* @dst: the destination reservation object -* @src: the source reservation object -* -* Copy all fences from src to dst. dst-lock must be held. -*/ +* dma_resv_copy_fences - Copy all fences from src to dst. +* @dst: the destination reservation object +* @src: the source reservation object +* +* Copy all fences from src to dst. dst-lock must be held. +*/ int dma_resv_copy_fences (struct dma_resv *dst,struct dma_resv *src) {struct dma_resv_list *src_list, *dst_list;struct dma_fence *old, *new; -unsigned i; +unsigned int i;dma_resv_assert_held (dst);@@ -356,7 +312,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) retry:if (src_list) { -unsigned shared_count = src_list->shared_count; +unsigned int shared_count = src_list->shared_count;rcu_read_unlock ();@@ -373,6 +329,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) dst_list->shared_count =0 ;for (i =0 ; i < src_list->shared_count; ++i) { +struct dma_fence __rcu **dst;struct dma_fence *fence; fence =rcu_dereference (src_list->shared[i]);@@ -391,7 +348,8 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)continue ; } -rcu_assign_pointer (dst_list->shared[dst_list->shared_count++], fence); + dst = &dst_list->shared[dst_list->shared_count++]; +rcu_assign_pointer (*dst, fence); } }else { dst_list =NULL ;@@ -431,7 +389,7 @@ EXPORT_SYMBOL(dma_resv_copy_fences);*/ int dma_resv_get_fences_rcu (struct dma_resv *obj,struct dma_fence **pfence_excl, -unsigned *pshared_count, +unsigned int *pshared_count,struct dma_fence ***pshared) {struct dma_fence **shared =NULL ;@@ -533,9 +491,9 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, bool wait_all, bool intr, unsigned long timeout) { - struct dma_fence *fence; -unsigned seq, shared_count; long ret = timeout ? timeout : 1; +unsigned int seq, shared_count; +struct dma_fence *fence;int i; retry:@@ -565,8 +523,9 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, shared_count = fobj->shared_count;for (i =0 ; !fence && i < shared_count; ++i) { -struct dma_fence *lfence =rcu_dereference (fobj->shared[i]); +struct dma_fence *lfence; + lfence =rcu_dereference (fobj->shared[i]);if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &lfence->flags))continue ;@@ -633,7 +592,7 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)*/ bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all) { -unsigned seq, shared_count; +unsigned int seq, shared_count;int ret;rcu_read_lock ();@@ -643,16 +602,16 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -unsigned i; -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +unsigned int i;if (fobj) shared_count = fobj->shared_count;for (i =0 ; i < shared_count; ++i) { -struct dma_fence *fence =rcu_dereference (fobj->shared[i]); +struct dma_fence *fence; + fence =rcu_dereference (fobj->shared[i]); ret =dma_resv_test_signaled_single (fence);if (ret <0 ) goto retry;@@ -681,3 +640,46 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)return ret; }EXPORT_SYMBOL_GPL (dma_resv_test_signaled_rcu); + +#if IS_ENABLED (CONFIG_LOCKDEP ) +static int __init dma_resv_lockdep (void ) +{ +struct mm_struct *mm =mm_alloc (); +struct ww_acquire_ctx ctx; +struct dma_resv obj; +struct address_space mapping; +int ret; + +if (!mm) +return -ENOMEM ; + +dma_resv_init (&obj); +address_space_init_once (&mapping); + +mmap_read_lock (mm); +ww_acquire_init (&ctx, &reservation_ww_class); + ret =dma_resv_lock (&obj, &ctx); +if (ret == -EDEADLK ) +dma_resv_lock_slow (&obj, &ctx); +fs_reclaim_acquire (GFP_KERNEL ); +/* for unmap_mapping_range on trylocked buffer objects in shrinkers */ +i_mmap_lock_write (&mapping); +i_mmap_unlock_write (&mapping); +#ifdef CONFIG_MMU_NOTIFIER +lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); +__dma_fence_might_wait (); +lock_map_release (&__mmu_notifier_invalidate_range_start_map); +#else +__dma_fence_might_wait (); +#endif +fs_reclaim_release (GFP_KERNEL ); +ww_mutex_unlock (&obj.lock); +ww_acquire_fini (&ctx); +mmap_read_unlock (mm); + +mmput (mm); + +return 0 ; +} +subsys_initcall (dma_resv_lockdep); +#endif Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 2/7] dma-buf: add SPDX header and fix style in dma-resv.c
Am 02.06.21 um 14:34 schrieb Daniel Vetter:
Quoted 8 lines · Christian König
Quoted 3 lines
No functional change.
Signed-off-by Christian König <[email protected]>Acked-by Daniel Vetter <[email protected]>Maybe add the checkpatch warnings you're fixing here to the commit message. I didn't know that initcalls should be at the bottom ...
Well dma_resv_lockdep() had some tab/space mixup and moving it around was the easiest way to fix that in the editor :)
Moving it to the end seemed logical to me.
Christian.
Quoted 240 lines
-Daniel
Quoted 237 lines
--- drivers/dma-buf/dma-resv.c | 128 +++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 63 deletions(-)drivers/dma-buf/dma-resv.c +65
-63@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: MIT /* * Copyright (C) 2012-2014 Canonical Ltd (Maarten Lankhorst) * @@ -92,49 +93,6 @@ static void dma_resv_list_free(struct dma_resv_list *list)kfree_rcu (list, rcu); } -#if IS_ENABLED (CONFIG_LOCKDEP ) -static int __init dma_resv_lockdep (void ) -{ -struct mm_struct *mm =mm_alloc (); -struct ww_acquire_ctx ctx; -struct dma_resv obj; -struct address_space mapping; -int ret; - -if (!mm) -return -ENOMEM ; - -dma_resv_init (&obj); -address_space_init_once (&mapping); - -mmap_read_lock (mm); -ww_acquire_init (&ctx, &reservation_ww_class); - ret =dma_resv_lock (&obj, &ctx); -if (ret == -EDEADLK ) -dma_resv_lock_slow (&obj, &ctx); -fs_reclaim_acquire (GFP_KERNEL ); -/* for unmap_mapping_range on trylocked buffer objects in shrinkers */ -i_mmap_lock_write (&mapping); -i_mmap_unlock_write (&mapping); -#ifdef CONFIG_MMU_NOTIFIER -lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); -__dma_fence_might_wait (); -lock_map_release (&__mmu_notifier_invalidate_range_start_map); -#else -__dma_fence_might_wait (); -#endif -fs_reclaim_release (GFP_KERNEL ); -ww_mutex_unlock (&obj.lock); -ww_acquire_fini (&ctx); -mmap_read_unlock (mm); - -mmput (mm); - -return 0 ; -} -subsys_initcall (dma_resv_lockdep); -#endif -/** * dma_resv_init - initialize a reservation object * @obj: the reservation object @@ -196,9 +154,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ; -else - max =max (old->shared_count + num_fences, - old->shared_max *2 ); + max =max (old->shared_count + num_fences, old->shared_max *2 ); }else { max =max (4ul ,roundup_pow_of_two (num_fences)); }@@ -337,17 +293,17 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)EXPORT_SYMBOL (dma_resv_add_excl_fence);/** -* dma_resv_copy_fences - Copy all fences from src to dst. -* @dst: the destination reservation object -* @src: the source reservation object -* -* Copy all fences from src to dst. dst-lock must be held. -*/ +* dma_resv_copy_fences - Copy all fences from src to dst. +* @dst: the destination reservation object +* @src: the source reservation object +* +* Copy all fences from src to dst. dst-lock must be held. +*/ int dma_resv_copy_fences (struct dma_resv *dst,struct dma_resv *src) {struct dma_resv_list *src_list, *dst_list;struct dma_fence *old, *new; -unsigned i; +unsigned int i;dma_resv_assert_held (dst);@@ -356,7 +312,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) retry:if (src_list) { -unsigned shared_count = src_list->shared_count; +unsigned int shared_count = src_list->shared_count;rcu_read_unlock ();@@ -373,6 +329,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) dst_list->shared_count =0 ;for (i =0 ; i < src_list->shared_count; ++i) { +struct dma_fence __rcu **dst;struct dma_fence *fence; fence =rcu_dereference (src_list->shared[i]);@@ -391,7 +348,8 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)continue ; } -rcu_assign_pointer (dst_list->shared[dst_list->shared_count++], fence); + dst = &dst_list->shared[dst_list->shared_count++]; +rcu_assign_pointer (*dst, fence); } }else { dst_list =NULL ;@@ -431,7 +389,7 @@ EXPORT_SYMBOL(dma_resv_copy_fences);*/ int dma_resv_get_fences_rcu (struct dma_resv *obj,struct dma_fence **pfence_excl, -unsigned *pshared_count, +unsigned int *pshared_count,struct dma_fence ***pshared) {struct dma_fence **shared =NULL ;@@ -533,9 +491,9 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, bool wait_all, bool intr, unsigned long timeout) { - struct dma_fence *fence; -unsigned seq, shared_count; long ret = timeout ? timeout : 1; +unsigned int seq, shared_count; +struct dma_fence *fence;int i; retry:@@ -565,8 +523,9 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, shared_count = fobj->shared_count;for (i =0 ; !fence && i < shared_count; ++i) { -struct dma_fence *lfence =rcu_dereference (fobj->shared[i]); +struct dma_fence *lfence; + lfence =rcu_dereference (fobj->shared[i]);if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &lfence->flags))continue ;@@ -633,7 +592,7 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)*/ bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all) { -unsigned seq, shared_count; +unsigned int seq, shared_count;int ret;rcu_read_lock ();@@ -643,16 +602,16 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -unsigned i; -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +unsigned int i;if (fobj) shared_count = fobj->shared_count;for (i =0 ; i < shared_count; ++i) { -struct dma_fence *fence =rcu_dereference (fobj->shared[i]); +struct dma_fence *fence; + fence =rcu_dereference (fobj->shared[i]); ret =dma_resv_test_signaled_single (fence);if (ret <0 ) goto retry;@@ -681,3 +640,46 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)return ret; }EXPORT_SYMBOL_GPL (dma_resv_test_signaled_rcu); + +#if IS_ENABLED (CONFIG_LOCKDEP ) +static int __init dma_resv_lockdep (void ) +{ +struct mm_struct *mm =mm_alloc (); +struct ww_acquire_ctx ctx; +struct dma_resv obj; +struct address_space mapping; +int ret; + +if (!mm) +return -ENOMEM ; + +dma_resv_init (&obj); +address_space_init_once (&mapping); + +mmap_read_lock (mm); +ww_acquire_init (&ctx, &reservation_ww_class); + ret =dma_resv_lock (&obj, &ctx); +if (ret == -EDEADLK ) +dma_resv_lock_slow (&obj, &ctx); +fs_reclaim_acquire (GFP_KERNEL ); +/* for unmap_mapping_range on trylocked buffer objects in shrinkers */ +i_mmap_lock_write (&mapping); +i_mmap_unlock_write (&mapping); +#ifdef CONFIG_MMU_NOTIFIER +lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); +__dma_fence_might_wait (); +lock_map_release (&__mmu_notifier_invalidate_range_start_map); +#else +__dma_fence_might_wait (); +#endif +fs_reclaim_release (GFP_KERNEL ); +ww_mutex_unlock (&obj.lock); +ww_acquire_fini (&ctx); +mmap_read_unlock (mm); + +mmput (mm); + +return 0 ; +} +subsys_initcall (dma_resv_lockdep); +#endif Signature · 1 line
2.25.1
Re: [PATCH 2/7] dma-buf: add SPDX header and fix style in dma-resv.c
Quoted 9 lines · Christian König
Am 02.06.21 um 14:34 schrieb Daniel Vetter:
Quoted 6 lines · Christian König
Quoted 3 lines
No functional change.
Signed-off-by Christian König <[email protected]>Acked-by Daniel Vetter <[email protected]>
Quoted 7 lines
Quoted 2 lines
Maybe add the checkpatch warnings you're fixing here to the commit message. I didn't know that initcalls should be at the bottom ...
Well
dma_resv_lockdep()had some tab/space mixup and moving it around was the easiest way to fix that in the editor :)Moving it to the end seemed logical to me.
Ah whack that into the commit message then, I was confused for a bit :-) -Daniel
Quoted 226 lines
Christian.
Quoted 222 lines
-Daniel
Quoted 219 lines
--- drivers/dma-buf/dma-resv.c | 128 +++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 63 deletions(-)drivers/dma-buf/dma-resv.c +65
-63@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: MIT /* * Copyright (C) 2012-2014 Canonical Ltd (Maarten Lankhorst) * @@ -92,49 +93,6 @@ static void dma_resv_list_free(struct dma_resv_list *list)kfree_rcu (list, rcu); } -#if IS_ENABLED (CONFIG_LOCKDEP ) -static int __init dma_resv_lockdep (void ) -{ -struct mm_struct *mm =mm_alloc (); -struct ww_acquire_ctx ctx; -struct dma_resv obj; -struct address_space mapping; -int ret; - -if (!mm) -return -ENOMEM ; - -dma_resv_init (&obj); -address_space_init_once (&mapping); - -mmap_read_lock (mm); -ww_acquire_init (&ctx, &reservation_ww_class); - ret =dma_resv_lock (&obj, &ctx); -if (ret == -EDEADLK ) -dma_resv_lock_slow (&obj, &ctx); -fs_reclaim_acquire (GFP_KERNEL ); -/* for unmap_mapping_range on trylocked buffer objects in shrinkers */ -i_mmap_lock_write (&mapping); -i_mmap_unlock_write (&mapping); -#ifdef CONFIG_MMU_NOTIFIER -lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); -__dma_fence_might_wait (); -lock_map_release (&__mmu_notifier_invalidate_range_start_map); -#else -__dma_fence_might_wait (); -#endif -fs_reclaim_release (GFP_KERNEL ); -ww_mutex_unlock (&obj.lock); -ww_acquire_fini (&ctx); -mmap_read_unlock (mm); - -mmput (mm); - -return 0 ; -} -subsys_initcall (dma_resv_lockdep); -#endif -/** * dma_resv_init - initialize a reservation object * @obj: the reservation object @@ -196,9 +154,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ; -else - max =max (old->shared_count + num_fences, - old->shared_max *2 ); + max =max (old->shared_count + num_fences, old->shared_max *2 ); }else { max =max (4ul ,roundup_pow_of_two (num_fences)); }@@ -337,17 +293,17 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)EXPORT_SYMBOL (dma_resv_add_excl_fence);/** -* dma_resv_copy_fences - Copy all fences from src to dst. -* @dst: the destination reservation object -* @src: the source reservation object -* -* Copy all fences from src to dst. dst-lock must be held. -*/ +* dma_resv_copy_fences - Copy all fences from src to dst. +* @dst: the destination reservation object +* @src: the source reservation object +* +* Copy all fences from src to dst. dst-lock must be held. +*/ int dma_resv_copy_fences (struct dma_resv *dst,struct dma_resv *src) {struct dma_resv_list *src_list, *dst_list;struct dma_fence *old, *new; -unsigned i; +unsigned int i;dma_resv_assert_held (dst);@@ -356,7 +312,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) retry:if (src_list) { -unsigned shared_count = src_list->shared_count; +unsigned int shared_count = src_list->shared_count;rcu_read_unlock ();@@ -373,6 +329,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) dst_list->shared_count =0 ;for (i =0 ; i < src_list->shared_count; ++i) { +struct dma_fence __rcu **dst;struct dma_fence *fence; fence =rcu_dereference (src_list->shared[i]);@@ -391,7 +348,8 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)continue ; } -rcu_assign_pointer (dst_list->shared[dst_list->shared_count++], fence); + dst = &dst_list->shared[dst_list->shared_count++]; +rcu_assign_pointer (*dst, fence); } }else { dst_list =NULL ;@@ -431,7 +389,7 @@ EXPORT_SYMBOL(dma_resv_copy_fences);*/ int dma_resv_get_fences_rcu (struct dma_resv *obj,struct dma_fence **pfence_excl, -unsigned *pshared_count, +unsigned int *pshared_count,struct dma_fence ***pshared) {struct dma_fence **shared =NULL ;@@ -533,9 +491,9 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, bool wait_all, bool intr, unsigned long timeout) { - struct dma_fence *fence; -unsigned seq, shared_count; long ret = timeout ? timeout : 1; +unsigned int seq, shared_count; +struct dma_fence *fence;int i; retry:@@ -565,8 +523,9 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, shared_count = fobj->shared_count;for (i =0 ; !fence && i < shared_count; ++i) { -struct dma_fence *lfence =rcu_dereference (fobj->shared[i]); +struct dma_fence *lfence; + lfence =rcu_dereference (fobj->shared[i]);if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &lfence->flags))continue ;@@ -633,7 +592,7 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)*/ bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all) { -unsigned seq, shared_count; +unsigned int seq, shared_count;int ret;rcu_read_lock ();@@ -643,16 +602,16 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -unsigned i; -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +unsigned int i;if (fobj) shared_count = fobj->shared_count;for (i =0 ; i < shared_count; ++i) { -struct dma_fence *fence =rcu_dereference (fobj->shared[i]); +struct dma_fence *fence; + fence =rcu_dereference (fobj->shared[i]); ret =dma_resv_test_signaled_single (fence);if (ret <0 ) goto retry;@@ -681,3 +640,46 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)return ret; }EXPORT_SYMBOL_GPL (dma_resv_test_signaled_rcu); + +#if IS_ENABLED (CONFIG_LOCKDEP ) +static int __init dma_resv_lockdep (void ) +{ +struct mm_struct *mm =mm_alloc (); +struct ww_acquire_ctx ctx; +struct dma_resv obj; +struct address_space mapping; +int ret; + +if (!mm) +return -ENOMEM ; + +dma_resv_init (&obj); +address_space_init_once (&mapping); + +mmap_read_lock (mm); +ww_acquire_init (&ctx, &reservation_ww_class); + ret =dma_resv_lock (&obj, &ctx); +if (ret == -EDEADLK ) +dma_resv_lock_slow (&obj, &ctx); +fs_reclaim_acquire (GFP_KERNEL ); +/* for unmap_mapping_range on trylocked buffer objects in shrinkers */ +i_mmap_lock_write (&mapping); +i_mmap_unlock_write (&mapping); +#ifdef CONFIG_MMU_NOTIFIER +lock_map_acquire (&__mmu_notifier_invalidate_range_start_map); +__dma_fence_might_wait (); +lock_map_release (&__mmu_notifier_invalidate_range_start_map); +#else +__dma_fence_might_wait (); +#endif +fs_reclaim_release (GFP_KERNEL ); +ww_mutex_unlock (&obj.lock); +ww_acquire_fini (&ctx); +mmap_read_unlock (mm); + +mmput (mm); + +return 0 ; +} +subsys_initcall (dma_resv_lockdep); +#endif Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 3/7 dma-buf: cleanup dma-resv shared fence debugging a bit
In reply to Christian KönigMake that a function instead of inline.
--- drivers/dma-buf/dma-resv.c | 18 ++++++++++++++++++ include/linux/dma-resv.h | 15 +++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-)
drivers/dma-buf/dma-resv.c +18 -0
@@ -208,6 +208,24 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences) }EXPORT_SYMBOL (dma_resv_reserve_shared); +#ifdef CONFIG_DEBUG_MUTEXES +/** +* dma_resv_reset_shared_max - reset shared fences for debugging +* @obj: the dma_resv object to reset +* +* Reset the shared_max to test if drivers do correct slot allocation. +*/ +void dma_resv_reset_shared_max (struct dma_resv *obj) +{ +/* Test shared fence slot reservation */ +if (rcu_access_pointer (obj->fence)) { +struct dma_resv_list *fence =dma_resv_get_list (obj); + + fence->shared_max = fence->shared_count; + } +} +#endif +/** * dma_resv_add_shared_fence - Add a fence to a shared slot * @obj: the reservation object
include/linux/dma-resv.h +7 -8
@@ -92,6 +92,12 @@ static inline struct dma_resv_list *dma_resv_get_list(struct dma_resv *obj) dma_resv_held(obj)); } +#ifdef CONFIG_DEBUG_MUTEXES +void dma_resv_reset_shared_max (struct dma_resv *obj); +#else +static inline void dma_resv_reset_shared_max (struct dma_resv *obj) {} +#endif +/** * dma_resv_lock - lock the reservation object * @obj: the reservation object
@@ -215,14 +221,7 @@ static inline struct ww_acquire_ctx *dma_resv_locking_ctx(struct dma_resv *obj)*/ static inline void dma_resv_unlock (struct dma_resv *obj) { -#ifdef CONFIG_DEBUG_MUTEXES -/* Test shared fence slot reservation */ -if (rcu_access_pointer (obj->fence)) { -struct dma_resv_list *fence =dma_resv_get_list (obj); - - fence->shared_max = fence->shared_count; - } -#endif +dma_resv_reset_shared_max (obj);ww_mutex_unlock (&obj->lock); }
Signature · 1 line
2.25.1
Re: [PATCH 3/7] dma-buf: cleanup dma-resv shared fence debugging a bit
Quoted 3 lines · Christian König
Make that a function instead of inline.
Signed-off-by Christian König <[email protected]>
Hm yeah pulling that out makes some sense.
Quoted 10 lines
--- drivers/dma-buf/dma-resv.c | 18 ++++++++++++++++++ include/linux/dma-resv.h | 15 +++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-)drivers/dma-buf/dma-resv.c +0
-0
drivers/dma-buf/dma-resv.c int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences) · line 216
Quoted 9 lines
drivers/dma-buf/dma-resv.c +6
-0@@ -208,6 +208,24 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences) }EXPORT_SYMBOL (dma_resv_reserve_shared); +#ifdef CONFIG_DEBUG_MUTEXES +/** +* dma_resv_reset_shared_max - reset shared fences for debugging +* @obj: the dma_resv object to reset +* +* Reset the shared_max to test if drivers do correct slot allocation.
I'd phrase this as
"Reset the number of pre-reserved shared slots to test that drivers do correct slot allocation using dma_resv_reserve_shared(). See also &dma_resv_list.shared_max."
That way it's a bit clearer how it all ties together.
The kerneldoc for dma_resv_list is also a bit thin, but another patch for that. With the kerneldoc polish:
Quoted 51 lines
drivers/dma-buf/dma-resv.c +12
-0+*/ +void dma_resv_reset_shared_max (struct dma_resv *obj) +{ +/* Test shared fence slot reservation */ +if (rcu_access_pointer (obj->fence)) { +struct dma_resv_list *fence =dma_resv_get_list (obj); + + fence->shared_max = fence->shared_count; + } +} +#endif +/** * dma_resv_add_shared_fence - Add a fence to a shared slot * @obj: the reservation object include/linux/dma-resv.h +7
-8@@ -92,6 +92,12 @@ static inline struct dma_resv_list *dma_resv_get_list(struct dma_resv *obj) dma_resv_held(obj)); } +#ifdef CONFIG_DEBUG_MUTEXES +void dma_resv_reset_shared_max (struct dma_resv *obj); +#else +static inline void dma_resv_reset_shared_max (struct dma_resv *obj) {} +#endif +/** * dma_resv_lock - lock the reservation object * @obj: the reservation object @@ -215,14 +221,7 @@ static inline struct ww_acquire_ctx *dma_resv_locking_ctx(struct dma_resv *obj)*/ static inline void dma_resv_unlock (struct dma_resv *obj) { -#ifdef CONFIG_DEBUG_MUTEXES -/* Test shared fence slot reservation */ -if (rcu_access_pointer (obj->fence)) { -struct dma_resv_list *fence =dma_resv_get_list (obj); - - fence->shared_max = fence->shared_count; - } -#endif +dma_resv_reset_shared_max (obj);ww_mutex_unlock (&obj->lock); }Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 4/7 dma-buf: rename and cleanup dma_resv_get_excl
In reply to Christian KönigWhen the comment needs to state explicitly that this doesn't get a reference to the object then the function is named rather badly.
Rename the function and use rcu_dereference_check(), this way it can be used from both rcu as well as lock protected critical sections.
--- drivers/dma-buf/dma-buf.c | 4 ++-- drivers/dma-buf/dma-resv.c | 10 +++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 3 +-- drivers/gpu/drm/msm/msm_gem.c | 4 ++-- drivers/gpu/drm/nouveau/nouveau_bo.c | 2 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/radeon/radeon_display.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/radeon/radeon_uvd.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 2 +- include/linux/dma-resv.h | 13 +++++-------- 15 files changed, 25 insertions(+), 29 deletions(-)
drivers/dma-buf/dma-buf.c +2 -2
@@ -234,7 +234,7 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) shared_count = fobj->shared_count; else shared_count =0 ; - fence_excl =rcu_dereference (resv->fence_excl); + fence_excl =dma_resv_exclusive (resv);if (read_seqcount_retry (&resv->seq, seq)) {rcu_read_unlock (); goto retry;
@@ -1385,7 +1385,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) robj = buf_obj->resv; seq =read_seqcount_begin (&robj->seq);rcu_read_lock (); - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence) seq_printf(s, "\tExclusive fence: %s %s %ssignalled\n", fence->ops->get_driver_name(fence),
drivers/dma-buf/dma-resv.c +5 -5
@@ -281,7 +281,7 @@ EXPORT_SYMBOL(dma_resv_add_shared_fence);*/ void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence) { -struct dma_fence *old_fence =dma_resv_get_excl (obj); +struct dma_fence *old_fence =dma_resv_exclusive (obj);struct dma_resv_list *old;u32 i =0 ;
@@ -377,7 +377,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)rcu_read_unlock (); src_list =dma_resv_get_list (dst); - old =dma_resv_get_excl (dst); + old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);/* write_seqcount_begin provides the necessary memory barrier */
@@ -425,7 +425,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,rcu_read_lock (); seq =read_seqcount_begin (&obj->seq); - fence_excl =rcu_dereference (obj->fence_excl); + fence_excl =dma_resv_exclusive (obj);if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock;
@@ -520,7 +520,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,rcu_read_lock (); i =-1 ; - fence =rcu_dereference (obj->fence_excl); + fence =dma_resv_exclusive (obj);if (fence && !test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) {if (!dma_fence_get_rcu (fence)) goto unlock_retry;
@@ -642,7 +642,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) }if (!shared_count) { -struct dma_fence *fence_excl =rcu_dereference (obj->fence_excl); +struct dma_fence *fence_excl =dma_resv_exclusive (obj);if (fence_excl) { ret =dma_resv_test_signaled_single (fence_excl);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -1
@@ -226,7 +226,7 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,if (!amdgpu_vm_ready (vm)) goto out_unlock; - fence =dma_resv_get_excl (bo->tbo.base.resv); + fence =dma_resv_exclusive (bo->tbo.base.resv);if (fence) {amdgpu_bo_fence (bo, fence, true); fence =NULL ;
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -1
@@ -210,7 +210,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,return -EINVAL ;/* always sync to the exclusive fence */ - f =dma_resv_get_excl (resv); + f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); flist =dma_resv_get_list (resv);
drivers/gpu/drm/etnaviv/etnaviv_gem.c +1 -1
@@ -471,7 +471,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) } } - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence)etnaviv_gem_describe_fence (fence,"Exclusive" , m);rcu_read_unlock ();
drivers/gpu/drm/i915/gem/i915_gem_busy.c +1 -2
@@ -113,8 +113,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, seq =raw_read_seqcount (&obj->base.resv->seq);/* Translate the exclusive fence to the READ *and* WRITE engine */ - args->busy = -busy_check_writer (rcu_dereference (obj->base.resv->fence_excl)); + args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ list =rcu_dereference (obj->base.resv->fence);
drivers/gpu/drm/msm/msm_gem.c +2 -2
@@ -819,7 +819,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj, fobj =dma_resv_get_list (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { - fence =dma_resv_get_excl (obj->resv); + fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */ if (fence && (fence->context != fctx->context)) { ret =dma_fence_wait (fence, true);
@@ -1035,7 +1035,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, } } - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence)describe_fence (fence,"Exclusive" , m);rcu_read_unlock ();
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -1
@@ -955,7 +955,7 @@ nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo, {struct nouveau_drm *drm =nouveau_bdev (bo->bdev);struct drm_device *dev = drm->dev; -struct dma_fence *fence =dma_resv_get_excl (bo->base.resv); +struct dma_fence *fence =dma_resv_exclusive (bo->base.resv);nv10_bo_put_tile_region (dev, *old_tile, fence); *old_tile = new_tile;
drivers/gpu/drm/nouveau/nouveau_fence.c +1 -1
@@ -356,7 +356,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e } fobj =dma_resv_get_list (resv); - fence =dma_resv_get_excl (resv); + fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {struct nouveau_channel *prev =NULL ;
drivers/gpu/drm/radeon/radeon_display.c +1 -1
@@ -533,7 +533,7 @@ static int radeon_crtc_page_flip_target(struct drm_crtc *crtc,DRM_ERROR ("failed to pin new rbo buffer before flip\n" ); goto cleanup; } - work->fence =dma_fence_get (dma_resv_get_excl (new_rbo->tbo.base.resv)); + work->fence =dma_fence_get (dma_resv_exclusive (new_rbo->tbo.base.resv));radeon_bo_get_tiling_flags (new_rbo, &tiling_flags,NULL );radeon_bo_unreserve (new_rbo);
drivers/gpu/drm/radeon/radeon_sync.c +1 -1
@@ -98,7 +98,7 @@ int radeon_sync_resv(struct radeon_device *rdev,int r =0 ;/* always sync to the exclusive fence */ - f =dma_resv_get_excl (resv); + f =dma_resv_exclusive (resv); fence = f ?to_radeon_fence (f) :NULL ;if (fence && fence->rdev == rdev)radeon_sync_fence (sync, fence);
drivers/gpu/drm/radeon/radeon_uvd.c +1 -1
@@ -477,7 +477,7 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,return -EINVAL ; } - f =dma_resv_get_excl (bo->tbo.base.resv); + f =dma_resv_exclusive (bo->tbo.base.resv);if (f) { r =radeon_fence_wait ((struct radeon_fence *)f, false);if (r) {
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -262,7 +262,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)rcu_read_lock (); fobj =rcu_dereference (resv->fence); - fence =rcu_dereference (resv->fence_excl); + fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +1 -1
@@ -1166,7 +1166,7 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,if (bo->moving)dma_fence_put (bo->moving); bo->moving =dma_fence_get - (dma_resv_get_excl (bo->base.resv)); + (dma_resv_exclusive (bo->base.resv)); }return 0 ;
include/linux/dma-resv.h +5 -8
@@ -226,22 +226,19 @@ static inline void dma_resv_unlock(struct dma_resv *obj) }/** -* dma_resv_get_excl - get the reservation object's -* exclusive fence, with update-side lock held +* dma_resv_exclusive - return the object's exclusive fence * @obj: the reservation object * -* Returns the exclusive fence (if any). Does NOT take a -* reference. Writers must hold obj->lock, readers may only -* hold a RCU read side lock. +* Returns the exclusive fence (if any). Caller must either hold the objects +* lock or the rcu read side lock. * * RETURNS * The exclusive fence or NULL */ static inline struct dma_fence * -dma_resv_get_excl (struct dma_resv *obj) +dma_resv_exclusive (struct dma_resv *obj) { -return rcu_dereference_protected (obj->fence_excl, -dma_resv_held (obj)); +return rcu_dereference_check (obj->fence_excl,dma_resv_held (obj)); }/**
Signature · 1 line
2.25.1
Re: [PATCH 4/7] dma-buf: rename and cleanup dma_resv_get_excl
Quoted 9 lines · Christian König
When the comment needs to state explicitly that this doesn't get a reference to the object then the function is named rather badly.
Rename the function and use
rcu_dereference_check(), this way it can be used from both rcu as well as lock protected critical sections.Signed-off-by Christian König <[email protected]>
I'd call this dma_resv_exlusive_fence, since without that it's a bit close to dma_resv_make_exclusive or something like that. But this is definitely better than the previous pointer deref in a "I'm totally getting you a full reference" trenchcoat thing.
Quoted 290 lines
--- drivers/dma-buf/dma-buf.c | 4 ++-- drivers/dma-buf/dma-resv.c | 10 +++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 3 +-- drivers/gpu/drm/msm/msm_gem.c | 4 ++-- drivers/gpu/drm/nouveau/nouveau_bo.c | 2 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/radeon/radeon_display.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/radeon/radeon_uvd.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 2 +- include/linux/dma-resv.h | 13 +++++-------- 15 files changed, 25 insertions(+), 29 deletions(-)drivers/dma-buf/dma-buf.c +2
-2@@ -234,7 +234,7 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) shared_count = fobj->shared_count; else shared_count =0 ; - fence_excl =rcu_dereference (resv->fence_excl); + fence_excl =dma_resv_exclusive (resv);if (read_seqcount_retry (&resv->seq, seq)) {rcu_read_unlock (); goto retry;@@ -1385,7 +1385,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) robj = buf_obj->resv; seq =read_seqcount_begin (&robj->seq);rcu_read_lock (); - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence) seq_printf(s, "\tExclusive fence: %s %s %ssignalled\n", fence->ops->get_driver_name(fence),drivers/dma-buf/dma-resv.c +5
-5@@ -281,7 +281,7 @@ EXPORT_SYMBOL(dma_resv_add_shared_fence);*/ void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence) { -struct dma_fence *old_fence =dma_resv_get_excl (obj); +struct dma_fence *old_fence =dma_resv_exclusive (obj);struct dma_resv_list *old;u32 i =0 ;@@ -377,7 +377,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)rcu_read_unlock (); src_list =dma_resv_get_list (dst); - old =dma_resv_get_excl (dst); + old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);/* write_seqcount_begin provides the necessary memory barrier */ @@ -425,7 +425,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,rcu_read_lock (); seq =read_seqcount_begin (&obj->seq); - fence_excl =rcu_dereference (obj->fence_excl); + fence_excl =dma_resv_exclusive (obj);if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock;@@ -520,7 +520,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,rcu_read_lock (); i =-1 ; - fence =rcu_dereference (obj->fence_excl); + fence =dma_resv_exclusive (obj);if (fence && !test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) {if (!dma_fence_get_rcu (fence)) goto unlock_retry;@@ -642,7 +642,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) }if (!shared_count) { -struct dma_fence *fence_excl =rcu_dereference (obj->fence_excl); +struct dma_fence *fence_excl =dma_resv_exclusive (obj);if (fence_excl) { ret =dma_resv_test_signaled_single (fence_excl);drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -226,7 +226,7 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,if (!amdgpu_vm_ready (vm)) goto out_unlock; - fence =dma_resv_get_excl (bo->tbo.base.resv); + fence =dma_resv_exclusive (bo->tbo.base.resv);if (fence) {amdgpu_bo_fence (bo, fence, true); fence =NULL ;drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1
-1@@ -210,7 +210,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,return -EINVAL ;/* always sync to the exclusive fence */ - f =dma_resv_get_excl (resv); + f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); flist =dma_resv_get_list (resv);drivers/gpu/drm/etnaviv/etnaviv_gem.c +1
-1@@ -471,7 +471,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) } } - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence)etnaviv_gem_describe_fence (fence,"Exclusive" , m);rcu_read_unlock ();drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-2@@ -113,8 +113,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, seq =raw_read_seqcount (&obj->base.resv->seq);/* Translate the exclusive fence to the READ *and* WRITE engine */ - args->busy = -busy_check_writer (rcu_dereference (obj->base.resv->fence_excl)); + args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ list =rcu_dereference (obj->base.resv->fence);drivers/gpu/drm/msm/msm_gem.c +2
-2@@ -819,7 +819,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj, fobj =dma_resv_get_list (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { - fence =dma_resv_get_excl (obj->resv); + fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */ if (fence && (fence->context != fctx->context)) { ret =dma_fence_wait (fence, true);@@ -1035,7 +1035,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, } } - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence)describe_fence (fence,"Exclusive" , m);rcu_read_unlock ();drivers/gpu/drm/nouveau/nouveau_bo.c +1
-1@@ -955,7 +955,7 @@ nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo, {struct nouveau_drm *drm =nouveau_bdev (bo->bdev);struct drm_device *dev = drm->dev; -struct dma_fence *fence =dma_resv_get_excl (bo->base.resv); +struct dma_fence *fence =dma_resv_exclusive (bo->base.resv);nv10_bo_put_tile_region (dev, *old_tile, fence); *old_tile = new_tile;drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -356,7 +356,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e } fobj =dma_resv_get_list (resv); - fence =dma_resv_get_excl (resv); + fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {struct nouveau_channel *prev =NULL ;drivers/gpu/drm/radeon/radeon_display.c +1
-1@@ -533,7 +533,7 @@ static int radeon_crtc_page_flip_target(struct drm_crtc *crtc,DRM_ERROR ("failed to pin new rbo buffer before flip\n" ); goto cleanup; } - work->fence =dma_fence_get (dma_resv_get_excl (new_rbo->tbo.base.resv)); + work->fence =dma_fence_get (dma_resv_exclusive (new_rbo->tbo.base.resv));radeon_bo_get_tiling_flags (new_rbo, &tiling_flags,NULL );radeon_bo_unreserve (new_rbo);drivers/gpu/drm/radeon/radeon_sync.c +1
-1@@ -98,7 +98,7 @@ int radeon_sync_resv(struct radeon_device *rdev,int r =0 ;/* always sync to the exclusive fence */ - f =dma_resv_get_excl (resv); + f =dma_resv_exclusive (resv); fence = f ?to_radeon_fence (f) :NULL ;if (fence && fence->rdev == rdev)radeon_sync_fence (sync, fence);drivers/gpu/drm/radeon/radeon_uvd.c +1
-1@@ -477,7 +477,7 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,return -EINVAL ; } - f =dma_resv_get_excl (bo->tbo.base.resv); + f =dma_resv_exclusive (bo->tbo.base.resv);if (f) { r =radeon_fence_wait ((struct radeon_fence *)f, false);if (r) {drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -262,7 +262,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)rcu_read_lock (); fobj =rcu_dereference (resv->fence); - fence =rcu_dereference (resv->fence_excl); + fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +1
-1@@ -1166,7 +1166,7 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,if (bo->moving)dma_fence_put (bo->moving); bo->moving =dma_fence_get - (dma_resv_get_excl (bo->base.resv)); + (dma_resv_exclusive (bo->base.resv)); }return 0 ;include/linux/dma-resv.h +5
-8@@ -226,22 +226,19 @@ static inline void dma_resv_unlock(struct dma_resv *obj) }/** -* dma_resv_get_excl - get the reservation object's -* exclusive fence, with update-side lock held +* dma_resv_exclusive - return the object's exclusive fence * @obj: the reservation object * -* Returns the exclusive fence (if any). Does NOT take a -* reference. Writers must hold obj->lock, readers may only -* hold a RCU read side lock. +* Returns the exclusive fence (if any). Caller must either hold the objects +* lock or the rcu read side lock. * * RETURNS * The exclusive fence or NULL */ static inline struct dma_fence * -dma_resv_get_excl (struct dma_resv *obj) +dma_resv_exclusive (struct dma_resv *obj) { -return rcu_dereference_protected (obj->fence_excl, -dma_resv_held (obj)); +return rcu_dereference_check (obj->fence_excl,dma_resv_held (obj)); }/** Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Jason Ekstrand
Reviewed-byRe: [PATCH 4/7] dma-buf: rename and cleanup dma_resv_get_excl
Quoted 6 lines · Daniel Vetter
Quoted 4 lines · Christian König
When the comment needs to state explicitly that this doesn't get a reference to the object then the function is named rather badly.
Quoted 7 lines
Quoted 5 lines
Rename the function and use
rcu_dereference_check(), this way it can be used from both rcu as well as lock protected critical sections.Signed-off-by Christian König <[email protected]>I'd call this
dma_resv_exlusive_fence, since without that it's a bit close
Or, if we want to keep it shorter, dma_resv_excl_fence(). I don't care much either way
Quoted 301 lines
to
dma_resv_make_exclusiveor something like that. But this is definitely better than the previous pointer deref in a "I'm totally getting you a full reference" trenchcoat thing.Acked-by Daniel Vetter <[email protected]>Quoted 288 lines
--- drivers/dma-buf/dma-buf.c | 4 ++-- drivers/dma-buf/dma-resv.c | 10 +++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 3 +-- drivers/gpu/drm/msm/msm_gem.c | 4 ++-- drivers/gpu/drm/nouveau/nouveau_bo.c | 2 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/radeon/radeon_display.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/radeon/radeon_uvd.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 2 +- include/linux/dma-resv.h | 13 +++++-------- 15 files changed, 25 insertions(+), 29 deletions(-)drivers/dma-buf/dma-buf.c +2
-2@@ -234,7 +234,7 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) shared_count = fobj->shared_count; else shared_count =0 ; - fence_excl =rcu_dereference (resv->fence_excl); + fence_excl =dma_resv_exclusive (resv);if (read_seqcount_retry (&resv->seq, seq)) {rcu_read_unlock (); goto retry;@@ -1385,7 +1385,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) robj = buf_obj->resv; seq =read_seqcount_begin (&robj->seq);rcu_read_lock (); - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence) seq_printf(s, "\tExclusive fence: %s %s %ssignalled\n", fence->ops->get_driver_name(fence),drivers/dma-buf/dma-resv.c +5
-5@@ -281,7 +281,7 @@ EXPORT_SYMBOL(dma_resv_add_shared_fence);*/ void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence) { -struct dma_fence *old_fence =dma_resv_get_excl (obj); +struct dma_fence *old_fence =dma_resv_exclusive (obj);struct dma_resv_list *old;u32 i =0 ;@@ -377,7 +377,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)rcu_read_unlock (); src_list =dma_resv_get_list (dst); - old =dma_resv_get_excl (dst); + old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);/* write_seqcount_begin provides the necessary memory barrier */ @@ -425,7 +425,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,rcu_read_lock (); seq =read_seqcount_begin (&obj->seq); - fence_excl =rcu_dereference (obj->fence_excl); + fence_excl =dma_resv_exclusive (obj);if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock;@@ -520,7 +520,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,rcu_read_lock (); i =-1 ; - fence =rcu_dereference (obj->fence_excl); + fence =dma_resv_exclusive (obj);if (fence && !test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) {if (!dma_fence_get_rcu (fence)) goto unlock_retry;@@ -642,7 +642,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) }if (!shared_count) { -struct dma_fence *fence_excl =rcu_dereference (obj->fence_excl); +struct dma_fence *fence_excl =dma_resv_exclusive (obj);if (fence_excl) { ret =dma_resv_test_signaled_single (fence_excl);drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -226,7 +226,7 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,if (!amdgpu_vm_ready (vm)) goto out_unlock; - fence =dma_resv_get_excl (bo->tbo.base.resv); + fence =dma_resv_exclusive (bo->tbo.base.resv);if (fence) {amdgpu_bo_fence (bo, fence, true); fence =NULL ;drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1
-1@@ -210,7 +210,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,return -EINVAL ;/* always sync to the exclusive fence */ - f =dma_resv_get_excl (resv); + f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); flist =dma_resv_get_list (resv);drivers/gpu/drm/etnaviv/etnaviv_gem.c +1
-1@@ -471,7 +471,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) } } - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence)etnaviv_gem_describe_fence (fence,"Exclusive" , m);rcu_read_unlock ();drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-2@@ -113,8 +113,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, seq =raw_read_seqcount (&obj->base.resv->seq);/* Translate the exclusive fence to the READ *and* WRITE engine */ - args->busy = -busy_check_writer (rcu_dereference (obj->base.resv->fence_excl)); + args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ list =rcu_dereference (obj->base.resv->fence);drivers/gpu/drm/msm/msm_gem.c +2
-2@@ -819,7 +819,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj, fobj =dma_resv_get_list (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { - fence =dma_resv_get_excl (obj->resv); + fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */ if (fence && (fence->context != fctx->context)) { ret =dma_fence_wait (fence, true);@@ -1035,7 +1035,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, } } - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence)describe_fence (fence,"Exclusive" , m);rcu_read_unlock ();drivers/gpu/drm/nouveau/nouveau_bo.c +1
-1@@ -955,7 +955,7 @@ nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo, {struct nouveau_drm *drm =nouveau_bdev (bo->bdev);struct drm_device *dev = drm->dev; -struct dma_fence *fence =dma_resv_get_excl (bo->base.resv); +struct dma_fence *fence =dma_resv_exclusive (bo->base.resv);nv10_bo_put_tile_region (dev, *old_tile, fence); *old_tile = new_tile;drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -356,7 +356,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e } fobj =dma_resv_get_list (resv); - fence =dma_resv_get_excl (resv); + fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {struct nouveau_channel *prev =NULL ;drivers/gpu/drm/radeon/radeon_display.c +1
-1@@ -533,7 +533,7 @@ static int radeon_crtc_page_flip_target(struct drm_crtc *crtc,DRM_ERROR ("failed to pin new rbo buffer before flip\n" ); goto cleanup; } - work->fence =dma_fence_get (dma_resv_get_excl (new_rbo->tbo.base.resv)); + work->fence =dma_fence_get (dma_resv_exclusive (new_rbo->tbo.base.resv));radeon_bo_get_tiling_flags (new_rbo, &tiling_flags,NULL );radeon_bo_unreserve (new_rbo);drivers/gpu/drm/radeon/radeon_sync.c +1
-1@@ -98,7 +98,7 @@ int radeon_sync_resv(struct radeon_device *rdev,int r =0 ;/* always sync to the exclusive fence */ - f =dma_resv_get_excl (resv); + f =dma_resv_exclusive (resv); fence = f ?to_radeon_fence (f) :NULL ;if (fence && fence->rdev == rdev)radeon_sync_fence (sync, fence);drivers/gpu/drm/radeon/radeon_uvd.c +1
-1@@ -477,7 +477,7 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,return -EINVAL ; } - f =dma_resv_get_excl (bo->tbo.base.resv); + f =dma_resv_exclusive (bo->tbo.base.resv);if (f) { r =radeon_fence_wait ((struct radeon_fence *)f, false);if (r) {drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -262,7 +262,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)rcu_read_lock (); fobj =rcu_dereference (resv->fence); - fence =rcu_dereference (resv->fence_excl); + fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +1
-1@@ -1166,7 +1166,7 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,if (bo->moving)dma_fence_put (bo->moving); bo->moving =dma_fence_get - (dma_resv_get_excl (bo->base.resv)); + (dma_resv_exclusive (bo->base.resv)); }return 0 ;include/linux/dma-resv.h +5
-9@@ -226,22 +226,19 @@ static inline void dma_resv_unlock(struct dma_resv *obj) }/** -* dma_resv_get_excl - get the reservation object's -* exclusive fence, with update-side lock held +* dma_resv_exclusive - return the object's exclusive fence * @obj: the reservation object * -* Returns the exclusive fence (if any). Does NOT take a -* reference. Writers must hold obj->lock, readers may only -* hold a RCU read side lock. +* Returns the exclusive fence (if any). Caller must either hold the objects +* lock or the rcu read side lock. * * RETURNS * The exclusive fence or NULL */ static inline struct dma_fence * -dma_resv_get_excl (struct dma_resv *obj) +dma_resv_exclusive (struct dma_resv *obj) { -return rcu_dereference_protected (obj->fence_excl, -dma_resv_held (obj)); +return rcu_dereference_check (obj->fence_excl,dma_resv_held (obj)); }/** -- Quoted 2 lines
2.25.1
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Re: [PATCH 4/7] dma-buf: rename and cleanup dma_resv_get_excl
In reply to Christian KönigQuoted 272 lines · Christian König
When the comment needs to state explicitly that this doesn't get a reference to the object then the function is named rather badly.
Rename the function and use
rcu_dereference_check(), this way it can be used from both rcu as well as lock protected critical sections.Signed-off-by Christian König <[email protected]>--- drivers/dma-buf/dma-buf.c | 4 ++-- drivers/dma-buf/dma-resv.c | 10 +++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 3 +-- drivers/gpu/drm/msm/msm_gem.c | 4 ++-- drivers/gpu/drm/nouveau/nouveau_bo.c | 2 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/radeon/radeon_display.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/radeon/radeon_uvd.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 2 +- include/linux/dma-resv.h | 13 +++++-------- 15 files changed, 25 insertions(+), 29 deletions(-)drivers/dma-buf/dma-buf.c +2
-2@@ -234,7 +234,7 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll) shared_count = fobj->shared_count; else shared_count =0 ; - fence_excl =rcu_dereference (resv->fence_excl); + fence_excl =dma_resv_exclusive (resv);if (read_seqcount_retry (&resv->seq, seq)) {rcu_read_unlock (); goto retry;@@ -1385,7 +1385,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) robj = buf_obj->resv; seq =read_seqcount_begin (&robj->seq);rcu_read_lock (); - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence) seq_printf(s, "\tExclusive fence: %s %s %ssignalled\n", fence->ops->get_driver_name(fence),drivers/dma-buf/dma-resv.c +5
-5@@ -281,7 +281,7 @@ EXPORT_SYMBOL(dma_resv_add_shared_fence);*/ void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence) { -struct dma_fence *old_fence =dma_resv_get_excl (obj); +struct dma_fence *old_fence =dma_resv_exclusive (obj);struct dma_resv_list *old;u32 i =0 ;@@ -377,7 +377,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)rcu_read_unlock (); src_list =dma_resv_get_list (dst); - old =dma_resv_get_excl (dst); + old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);/* write_seqcount_begin provides the necessary memory barrier */ @@ -425,7 +425,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,rcu_read_lock (); seq =read_seqcount_begin (&obj->seq); - fence_excl =rcu_dereference (obj->fence_excl); + fence_excl =dma_resv_exclusive (obj);if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock;@@ -520,7 +520,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,rcu_read_lock (); i =-1 ; - fence =rcu_dereference (obj->fence_excl); + fence =dma_resv_exclusive (obj);if (fence && !test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) {if (!dma_fence_get_rcu (fence)) goto unlock_retry;@@ -642,7 +642,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) }if (!shared_count) { -struct dma_fence *fence_excl =rcu_dereference (obj->fence_excl); +struct dma_fence *fence_excl =dma_resv_exclusive (obj);if (fence_excl) { ret =dma_resv_test_signaled_single (fence_excl);drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -226,7 +226,7 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,if (!amdgpu_vm_ready (vm)) goto out_unlock; - fence =dma_resv_get_excl (bo->tbo.base.resv); + fence =dma_resv_exclusive (bo->tbo.base.resv);if (fence) {amdgpu_bo_fence (bo, fence, true); fence =NULL ;drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1
-1@@ -210,7 +210,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,return -EINVAL ;/* always sync to the exclusive fence */ - f =dma_resv_get_excl (resv); + f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); flist =dma_resv_get_list (resv);drivers/gpu/drm/etnaviv/etnaviv_gem.c +1
-1@@ -471,7 +471,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) } } - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence)etnaviv_gem_describe_fence (fence,"Exclusive" , m);rcu_read_unlock ();drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-2@@ -113,8 +113,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, seq =raw_read_seqcount (&obj->base.resv->seq);/* Translate the exclusive fence to the READ *and* WRITE engine */ - args->busy = -busy_check_writer (rcu_dereference (obj->base.resv->fence_excl)); + args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ list =rcu_dereference (obj->base.resv->fence);drivers/gpu/drm/msm/msm_gem.c +2
-2@@ -819,7 +819,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj, fobj =dma_resv_get_list (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { - fence =dma_resv_get_excl (obj->resv); + fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */ if (fence && (fence->context != fctx->context)) { ret =dma_fence_wait (fence, true);@@ -1035,7 +1035,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, } } - fence =rcu_dereference (robj->fence_excl); + fence =dma_resv_exclusive (robj);if (fence)describe_fence (fence,"Exclusive" , m);rcu_read_unlock ();drivers/gpu/drm/nouveau/nouveau_bo.c +1
-1@@ -955,7 +955,7 @@ nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo, {struct nouveau_drm *drm =nouveau_bdev (bo->bdev);struct drm_device *dev = drm->dev; -struct dma_fence *fence =dma_resv_get_excl (bo->base.resv); +struct dma_fence *fence =dma_resv_exclusive (bo->base.resv);nv10_bo_put_tile_region (dev, *old_tile, fence); *old_tile = new_tile;drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -356,7 +356,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e } fobj =dma_resv_get_list (resv); - fence =dma_resv_get_excl (resv); + fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {struct nouveau_channel *prev =NULL ;drivers/gpu/drm/radeon/radeon_display.c +1
-1@@ -533,7 +533,7 @@ static int radeon_crtc_page_flip_target(struct drm_crtc *crtc,DRM_ERROR ("failed to pin new rbo buffer before flip\n" ); goto cleanup; } - work->fence =dma_fence_get (dma_resv_get_excl (new_rbo->tbo.base.resv)); + work->fence =dma_fence_get (dma_resv_exclusive (new_rbo->tbo.base.resv));radeon_bo_get_tiling_flags (new_rbo, &tiling_flags,NULL );radeon_bo_unreserve (new_rbo);drivers/gpu/drm/radeon/radeon_sync.c +1
-1@@ -98,7 +98,7 @@ int radeon_sync_resv(struct radeon_device *rdev,int r =0 ;/* always sync to the exclusive fence */ - f =dma_resv_get_excl (resv); + f =dma_resv_exclusive (resv); fence = f ?to_radeon_fence (f) :NULL ;if (fence && fence->rdev == rdev)radeon_sync_fence (sync, fence);drivers/gpu/drm/radeon/radeon_uvd.c +1
-1@@ -477,7 +477,7 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,return -EINVAL ; } - f =dma_resv_get_excl (bo->tbo.base.resv); + f =dma_resv_exclusive (bo->tbo.base.resv);if (f) { r =radeon_fence_wait ((struct radeon_fence *)f, false);if (r) {drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -262,7 +262,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)rcu_read_lock (); fobj =rcu_dereference (resv->fence); - fence =rcu_dereference (resv->fence_excl); + fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +1
-1@@ -1166,7 +1166,7 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,if (bo->moving)dma_fence_put (bo->moving); bo->moving =dma_fence_get - (dma_resv_get_excl (bo->base.resv)); + (dma_resv_exclusive (bo->base.resv)); }return 0 ;include/linux/dma-resv.h +0
-0@@ -226,22 +226,19 @@ static inline void dma_resv_unlock(struct dma_resv *obj) }/**
include/linux/dma-resv.h static inline void dma_resv_unlock(struct dma_resv *obj) · line 233
Quoted 10 lines
include/linux/dma-resv.h +3
-5-* dma_resv_get_excl - get the reservation object's -* exclusive fence, with update-side lock held +* dma_resv_exclusive - return the object's exclusive fence * @obj: the reservation object * -* Returns the exclusive fence (if any). Does NOT take a -* reference. Writers must hold obj->lock, readers may only -* hold a RCU read side lock. +* Returns the exclusive fence (if any). Caller must either hold the objects +* lock or the rcu read side lock.
For some kerneldoc goodies, please spell this out with "object lock through dma_resv_lock() or the RCU read side lock through rcu_read_lock(), or one of the variants of each".
I just like a to throw around a lot of hyperlinks around to let people who read docs navigate to all the pieces easily.
-Daniel
Quoted 17 lines
include/linux/dma-resv.h +2
-3* * RETURNS * The exclusive fence or NULL */ static inline struct dma_fence * -dma_resv_get_excl (struct dma_resv *obj) +dma_resv_exclusive (struct dma_resv *obj) { -return rcu_dereference_protected (obj->fence_excl, -dma_resv_held (obj)); +return rcu_dereference_check (obj->fence_excl,dma_resv_held (obj)); }/** Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 5/7 dma-buf: rename and cleanup dma_resv_get_list
In reply to Christian KönigWhen the comment needs to state explicitly that this is doesn't get a reference to the object then the function is named rather badly.
Rename the function and use it in even more places.
--- drivers/dma-buf/dma-resv.c | 32 +++++++++---------- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 4 +-- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/qxl/qxl_debugfs.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- include/linux/dma-resv.h | 25 +++++++-------- 13 files changed, 39 insertions(+), 42 deletions(-)
drivers/dma-buf/dma-resv.c +16 -16
@@ -149,8 +149,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); - + old =dma_resv_shared (obj);if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ;
@@ -217,12 +216,13 @@ EXPORT_SYMBOL(dma_resv_reserve_shared);*/ void dma_resv_reset_shared_max (struct dma_resv *obj) { -/* Test shared fence slot reservation */ -if (rcu_access_pointer (obj->fence)) { -struct dma_resv_list *fence =dma_resv_get_list (obj); +struct dma_resv_list *fences =dma_resv_shared (obj); - fence->shared_max = fence->shared_count; - } +dma_resv_assert_held (obj); + +/* Test shared fence slot reservation */ +if (fences) + fences->shared_max = fences->shared_count; }#endif
@@ -244,7 +244,7 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - fobj =dma_resv_get_list (obj); + fobj =dma_resv_shared (obj); count = fobj->shared_count;write_seqcount_begin (&obj->seq);
@@ -287,7 +287,7 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); + old =dma_resv_shared (obj);if (old) i = old->shared_count;
@@ -326,7 +326,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)dma_resv_assert_held (dst);rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); retry:if (src_list) {
@@ -339,7 +339,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)return -ENOMEM ;rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src);if (!src_list || src_list->shared_count > shared_count) {kfree (dst_list); goto retry;
@@ -357,7 +357,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)if (!dma_fence_get_rcu (fence)) {dma_resv_list_free (dst_list); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); goto retry; }
@@ -376,7 +376,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) new =dma_fence_get_rcu_safe (&src->fence_excl);rcu_read_unlock (); - src_list =dma_resv_get_list (dst); + src_list =dma_resv_shared (dst); old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);
@@ -429,7 +429,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock; - fobj =rcu_dereference (obj->fence); + fobj =dma_resv_shared (obj);if (fobj) sz +=sizeof (*shared) * fobj->shared_max;
@@ -535,7 +535,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, }if (wait_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);if (fobj) shared_count = fobj->shared_count;
@@ -620,7 +620,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);unsigned int i;if (fobj)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
@@ -247,7 +247,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,if (!ef)return -EINVAL ; - old =dma_resv_get_list (resv); + old =dma_resv_shared (resv);if (!old)return 0 ;
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
@@ -49,7 +49,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)unsigned int count;int r; -if (!dma_resv_get_list (obj))/* no shared fences to convert */ +if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences);
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1 -1
@@ -213,7 +213,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync, f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (!flist || r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
@@ -1338,7 +1338,7 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,* If true, then return false as any KFD process needs all its BOs to * be resident to run successfully */ - flist =dma_resv_get_list (bo->base.resv); + flist =dma_resv_shared (bo->base.resv);if (flist) {for (i =0 ; i < flist->shared_count; ++i) { f = rcu_dereference_protected(flist->shared[i],
drivers/gpu/drm/etnaviv/etnaviv_gem.c +1 -1
@@ -461,7 +461,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) off, etnaviv_obj->vaddr, obj->size);rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;
drivers/gpu/drm/i915/gem/i915_gem_busy.c +1 -1
@@ -116,7 +116,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ - list =rcu_dereference (obj->base.resv->fence); + list =dma_resv_shared (obj->base.resv);if (list) {unsigned int shared_count = list->shared_count, i;
drivers/gpu/drm/msm/msm_gem.c +2 -2
@@ -817,7 +817,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj,struct dma_fence *fence;int i, ret; - fobj =dma_resv_get_list (obj->resv); + fobj =dma_resv_shared (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */
@@ -1025,7 +1025,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, }rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;
drivers/gpu/drm/nouveau/nouveau_fence.c +1 -1
@@ -355,7 +355,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool ereturn ret; } - fobj =dma_resv_get_list (resv); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {
drivers/gpu/drm/qxl/qxl_debugfs.c +1 -1
@@ -61,7 +61,7 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data)int rel;rcu_read_lock (); - fobj =rcu_dereference (bo->tbo.base.resv->fence); + fobj =dma_resv_shared (bo->tbo.base.resv); rel = fobj ? fobj->shared_count :0 ;rcu_read_unlock ();
drivers/gpu/drm/radeon/radeon_sync.c +1 -1
@@ -105,7 +105,7 @@ int radeon_sync_resv(struct radeon_device *rdev,else if (f) r =dma_fence_wait (f, true); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (shared || !flist || r)return r;
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -261,7 +261,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)int i;rcu_read_lock (); - fobj =rcu_dereference (resv->fence); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);
include/linux/dma-resv.h +11 -14
@@ -78,20 +78,6 @@ struct dma_resv {#define dma_resv_held (obj) lockdep_is_held(&(obj)->lock.base)#define dma_resv_assert_held (obj) lockdep_assert_held(&(obj)->lock.base) -/** -* dma_resv_get_list - get the reservation object's -* shared fence list, with update-side lock held -* @obj: the reservation object -* -* Returns the shared fence list. Does NOT take references to -* the fence. The obj->lock must be held. -*/ -static inline struct dma_resv_list *dma_resv_get_list (struct dma_resv *obj) -{ -return rcu_dereference_protected (obj->fence, -dma_resv_held (obj)); -} -#ifdef CONFIG_DEBUG_MUTEXES void dma_resv_reset_shared_max (struct dma_resv *obj);#else
@@ -267,6 +253,17 @@ dma_resv_get_excl_rcu(struct dma_resv *obj)return fence; } +/** +* dma_resv_shared - get the reservation object's shared fence list +* @obj: the reservation object +* +* Returns the shared fence list. The obj->lock or rcu read side must be held. +*/ +static inline struct dma_resv_list *dma_resv_shared (struct dma_resv *obj) +{ +return rcu_dereference_check (obj->fence,dma_resv_held (obj)); +} +void dma_resv_init (struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences);
Signature · 1 line
2.25.1
Re: [PATCH 5/7] dma-buf: rename and cleanup dma_resv_get_list
Quoted 314 lines · Christian König
When the comment needs to state explicitly that this is doesn't get a reference to the object then the function is named rather badly.
Rename the function and use it in even more places.
Signed-off-by Christian König <[email protected]>--- drivers/dma-buf/dma-resv.c | 32 +++++++++---------- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 4 +-- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/qxl/qxl_debugfs.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- include/linux/dma-resv.h | 25 +++++++-------- 13 files changed, 39 insertions(+), 42 deletions(-)drivers/dma-buf/dma-resv.c +16
-16@@ -149,8 +149,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); - + old =dma_resv_shared (obj);if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ;@@ -217,12 +216,13 @@ EXPORT_SYMBOL(dma_resv_reserve_shared);*/ void dma_resv_reset_shared_max (struct dma_resv *obj) { -/* Test shared fence slot reservation */ -if (rcu_access_pointer (obj->fence)) { -struct dma_resv_list *fence =dma_resv_get_list (obj); +struct dma_resv_list *fences =dma_resv_shared (obj); - fence->shared_max = fence->shared_count; - } +dma_resv_assert_held (obj); + +/* Test shared fence slot reservation */ +if (fences) + fences->shared_max = fences->shared_count; }#endif @@ -244,7 +244,7 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - fobj =dma_resv_get_list (obj); + fobj =dma_resv_shared (obj); count = fobj->shared_count;write_seqcount_begin (&obj->seq);@@ -287,7 +287,7 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); + old =dma_resv_shared (obj);if (old) i = old->shared_count;@@ -326,7 +326,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)dma_resv_assert_held (dst);rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); retry:if (src_list) {@@ -339,7 +339,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)return -ENOMEM ;rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src);if (!src_list || src_list->shared_count > shared_count) {kfree (dst_list); goto retry;@@ -357,7 +357,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)if (!dma_fence_get_rcu (fence)) {dma_resv_list_free (dst_list); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); goto retry; }@@ -376,7 +376,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) new =dma_fence_get_rcu_safe (&src->fence_excl);rcu_read_unlock (); - src_list =dma_resv_get_list (dst); + src_list =dma_resv_shared (dst); old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);@@ -429,7 +429,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock; - fobj =rcu_dereference (obj->fence); + fobj =dma_resv_shared (obj);if (fobj) sz +=sizeof (*shared) * fobj->shared_max;@@ -535,7 +535,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, }if (wait_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);if (fobj) shared_count = fobj->shared_count;@@ -620,7 +620,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);unsigned int i;if (fobj)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -247,7 +247,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,if (!ef)return -EINVAL ; - old =dma_resv_get_list (resv); + old =dma_resv_shared (resv);if (!old)return 0 ;drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-1@@ -49,7 +49,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)unsigned int count;int r; -if (!dma_resv_get_list (obj))/* no shared fences to convert */ +if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences);drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1
-1@@ -213,7 +213,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync, f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (!flist || r)return r;drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -1338,7 +1338,7 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,* If true, then return false as any KFD process needs all its BOs to * be resident to run successfully */ - flist =dma_resv_get_list (bo->base.resv); + flist =dma_resv_shared (bo->base.resv);if (flist) {for (i =0 ; i < flist->shared_count; ++i) { f = rcu_dereference_protected(flist->shared[i],drivers/gpu/drm/etnaviv/etnaviv_gem.c +1
-1@@ -461,7 +461,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) off, etnaviv_obj->vaddr, obj->size);rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-1@@ -116,7 +116,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ - list =rcu_dereference (obj->base.resv->fence); + list =dma_resv_shared (obj->base.resv);if (list) {unsigned int shared_count = list->shared_count, i;drivers/gpu/drm/msm/msm_gem.c +2
-2@@ -817,7 +817,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj,struct dma_fence *fence;int i, ret; - fobj =dma_resv_get_list (obj->resv); + fobj =dma_resv_shared (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */ @@ -1025,7 +1025,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, }rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -355,7 +355,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool ereturn ret; } - fobj =dma_resv_get_list (resv); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {drivers/gpu/drm/qxl/qxl_debugfs.c +1
-1@@ -61,7 +61,7 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data)int rel;rcu_read_lock (); - fobj =rcu_dereference (bo->tbo.base.resv->fence); + fobj =dma_resv_shared (bo->tbo.base.resv); rel = fobj ? fobj->shared_count :0 ;rcu_read_unlock ();drivers/gpu/drm/radeon/radeon_sync.c +1
-1@@ -105,7 +105,7 @@ int radeon_sync_resv(struct radeon_device *rdev,else if (f) r =dma_fence_wait (f, true); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (shared || !flist || r)return r;drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -261,7 +261,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)int i;rcu_read_lock (); - fobj =rcu_dereference (resv->fence); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);include/linux/dma-resv.h +0
-14@@ -78,20 +78,6 @@ struct dma_resv {#define dma_resv_held (obj) lockdep_is_held(&(obj)->lock.base)#define dma_resv_assert_held (obj) lockdep_assert_held(&(obj)->lock.base) -/** -* dma_resv_get_list - get the reservation object's -* shared fence list, with update-side lock held -* @obj: the reservation object -* -* Returns the shared fence list. Does NOT take references to -* the fence. The obj->lock must be held. -*/ -static inline struct dma_resv_list *dma_resv_get_list (struct dma_resv *obj) -{ -return rcu_dereference_protected (obj->fence, -dma_resv_held (obj)); -} -#ifdef CONFIG_DEBUG_MUTEXES void dma_resv_reset_shared_max (struct dma_resv *obj);#else
include/linux/dma-resv.h dma_resv_get_excl_rcu(struct dma_resv *obj) · line 260
Quoted 8 lines
include/linux/dma-resv.h +5
-0@@ -267,6 +253,17 @@ dma_resv_get_excl_rcu(struct dma_resv *obj)return fence; } +/** +* dma_resv_shared - get the reservation object's shared fence list +* @obj: the reservation object +* +* Returns the shared fence list. The obj->lock or rcu read side must be held.
Please copypaste the same wording from dma_resv_exclusive with all the links to dma_resv_lock() and rcu_read_lock() here to make the kerneldoc more useful.
Quoted 12 lines
include/linux/dma-resv.h +6
-0+*/ +static inline struct dma_resv_list *dma_resv_shared (struct dma_resv *obj) +{ +return rcu_dereference_check (obj->fence,dma_resv_held (obj)); +} +void dma_resv_init (struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences);Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 5/7] dma-buf: rename and cleanup dma_resv_get_list
In reply to Christian KönigQuoted 39 lines · Christian König
When the comment needs to state explicitly that this is doesn't get a reference to the object then the function is named rather badly.
Rename the function and use it in even more places.
Signed-off-by Christian König <[email protected]>--- drivers/dma-buf/dma-resv.c | 32 +++++++++---------- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 4 +-- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/qxl/qxl_debugfs.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- include/linux/dma-resv.h | 25 +++++++-------- 13 files changed, 39 insertions(+), 42 deletions(-)drivers/dma-buf/dma-resv.c +1
-2@@ -149,8 +149,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); - + old =dma_resv_shared (obj);if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ;@@ -217,12 +216,13 @@ EXPORT_SYMBOL(dma_resv_reserve_shared);*/
drivers/dma-buf/dma-resv.c EXPORT_SYMBOL(dma_resv_reserve_shared); · line 221
Quoted 10 lines
drivers/dma-buf/dma-resv.c +2
-5void dma_resv_reset_shared_max (struct dma_resv *obj) { -/* Test shared fence slot reservation */ -if (rcu_access_pointer (obj->fence)) { -struct dma_resv_list *fence =dma_resv_get_list (obj); +struct dma_resv_list *fences =dma_resv_shared (obj); - fence->shared_max = fence->shared_count; - } +dma_resv_assert_held (obj);
Does it make sense to assert we hold the lock *before* we touch it with something that requires that we do? Maybe it doesn't matter?
Quoted 266 lines
drivers/dma-buf/dma-resv.c +13
-9+ +/* Test shared fence slot reservation */ +if (fences) + fences->shared_max = fences->shared_count; }#endif @@ -244,7 +244,7 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - fobj =dma_resv_get_list (obj); + fobj =dma_resv_shared (obj); count = fobj->shared_count;write_seqcount_begin (&obj->seq);@@ -287,7 +287,7 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); + old =dma_resv_shared (obj);if (old) i = old->shared_count;@@ -326,7 +326,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)dma_resv_assert_held (dst);rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); retry:if (src_list) {@@ -339,7 +339,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)return -ENOMEM ;rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src);if (!src_list || src_list->shared_count > shared_count) {kfree (dst_list); goto retry;@@ -357,7 +357,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)if (!dma_fence_get_rcu (fence)) {dma_resv_list_free (dst_list); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); goto retry; }@@ -376,7 +376,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) new =dma_fence_get_rcu_safe (&src->fence_excl);rcu_read_unlock (); - src_list =dma_resv_get_list (dst); + src_list =dma_resv_shared (dst); old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);@@ -429,7 +429,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock; - fobj =rcu_dereference (obj->fence); + fobj =dma_resv_shared (obj);if (fobj) sz +=sizeof (*shared) * fobj->shared_max;@@ -535,7 +535,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, }if (wait_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);if (fobj) shared_count = fobj->shared_count;@@ -620,7 +620,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);unsigned int i;if (fobj)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -247,7 +247,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,if (!ef)return -EINVAL ; - old =dma_resv_get_list (resv); + old =dma_resv_shared (resv);if (!old)return 0 ;drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-1@@ -49,7 +49,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)unsigned int count;int r; -if (!dma_resv_get_list (obj))/* no shared fences to convert */ +if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences);drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1
-1@@ -213,7 +213,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync, f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (!flist || r)return r;drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -1338,7 +1338,7 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,* If true, then return false as any KFD process needs all its BOs to * be resident to run successfully */ - flist =dma_resv_get_list (bo->base.resv); + flist =dma_resv_shared (bo->base.resv);if (flist) {for (i =0 ; i < flist->shared_count; ++i) { f = rcu_dereference_protected(flist->shared[i],drivers/gpu/drm/etnaviv/etnaviv_gem.c +1
-1@@ -461,7 +461,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) off, etnaviv_obj->vaddr, obj->size);rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-1@@ -116,7 +116,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ - list =rcu_dereference (obj->base.resv->fence); + list =dma_resv_shared (obj->base.resv);if (list) {unsigned int shared_count = list->shared_count, i;drivers/gpu/drm/msm/msm_gem.c +2
-2@@ -817,7 +817,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj,struct dma_fence *fence;int i, ret; - fobj =dma_resv_get_list (obj->resv); + fobj =dma_resv_shared (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */ @@ -1025,7 +1025,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, }rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -355,7 +355,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool ereturn ret; } - fobj =dma_resv_get_list (resv); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {drivers/gpu/drm/qxl/qxl_debugfs.c +1
-1@@ -61,7 +61,7 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data)int rel;rcu_read_lock (); - fobj =rcu_dereference (bo->tbo.base.resv->fence); + fobj =dma_resv_shared (bo->tbo.base.resv); rel = fobj ? fobj->shared_count :0 ;rcu_read_unlock ();drivers/gpu/drm/radeon/radeon_sync.c +1
-1@@ -105,7 +105,7 @@ int radeon_sync_resv(struct radeon_device *rdev,else if (f) r =dma_fence_wait (f, true); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (shared || !flist || r)return r;drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -261,7 +261,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)int i;rcu_read_lock (); - fobj =rcu_dereference (resv->fence); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);include/linux/dma-resv.h +0
-14@@ -78,20 +78,6 @@ struct dma_resv {#define dma_resv_held (obj) lockdep_is_held(&(obj)->lock.base)#define dma_resv_assert_held (obj) lockdep_assert_held(&(obj)->lock.base) -/** -* dma_resv_get_list - get the reservation object's -* shared fence list, with update-side lock held -* @obj: the reservation object -* -* Returns the shared fence list. Does NOT take references to -* the fence. The obj->lock must be held. -*/ -static inline struct dma_resv_list *dma_resv_get_list (struct dma_resv *obj) -{ -return rcu_dereference_protected (obj->fence, -dma_resv_held (obj)); -} -#ifdef CONFIG_DEBUG_MUTEXES void dma_resv_reset_shared_max (struct dma_resv *obj);#else
include/linux/dma-resv.h dma_resv_get_excl_rcu(struct dma_resv *obj) · line 262
Quoted 10 lines
include/linux/dma-resv.h +7
-0@@ -267,6 +253,17 @@ dma_resv_get_excl_rcu(struct dma_resv *obj)return fence; } +/** +* dma_resv_shared - get the reservation object's shared fence list +* @obj: the reservation object +* +* Returns the shared fence list. The obj->lock or rcu read side must be held. +*/ +static inline struct dma_resv_list *dma_resv_shared (struct dma_resv *obj)
Maybe dma_resv_shared_list() just to be a little more clear what's being returned?
--Jason
Quoted 10 lines
include/linux/dma-resv.h +4
-1+{ +return rcu_dereference_check (obj->fence,dma_resv_held (obj)); +} +void dma_resv_init (struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences); --2.25.1
Re: [PATCH 5/7] dma-buf: rename and cleanup dma_resv_get_list
Am 02.06.21 um 22:22 schrieb Jason Ekstrand:
Quoted 47 lines
Quoted 45 lines · Christian König
When the comment needs to state explicitly that this is doesn't get a reference to the object then the function is named rather badly.
Rename the function and use it in even more places.
Signed-off-by Christian König <[email protected]>--- drivers/dma-buf/dma-resv.c | 32 +++++++++---------- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 4 +-- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/qxl/qxl_debugfs.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- include/linux/dma-resv.h | 25 +++++++-------- 13 files changed, 39 insertions(+), 42 deletions(-)drivers/dma-buf/dma-resv.c +2
-5@@ -149,8 +149,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); - + old =dma_resv_shared (obj);if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ;@@ -217,12 +216,13 @@ EXPORT_SYMBOL(dma_resv_reserve_shared);*/ void dma_resv_reset_shared_max (struct dma_resv *obj) { -/* Test shared fence slot reservation */ -if (rcu_access_pointer (obj->fence)) { -struct dma_resv_list *fence =dma_resv_get_list (obj); +struct dma_resv_list *fences =dma_resv_shared (obj);
Quoted 5 lines
drivers/dma-buf/dma-resv.c EXPORT_SYMBOL(dma_resv_reserve_shared); · line 221
Quoted 3 lines
drivers/dma-buf/dma-resv.c +1
-2- fence->shared_max = fence->shared_count; - } +dma_resv_assert_held (obj);Does it make sense to assert we hold the lock *before* we touch it with something that requires that we do? Maybe it doesn't matter?
As far as I can see that shouldn't matter.
Quoted 270 lines
Quoted 270 lines
drivers/dma-buf/dma-resv.c +13
-9+ +/* Test shared fence slot reservation */ +if (fences) + fences->shared_max = fences->shared_count; }#endif @@ -244,7 +244,7 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - fobj =dma_resv_get_list (obj); + fobj =dma_resv_shared (obj); count = fobj->shared_count;write_seqcount_begin (&obj->seq);@@ -287,7 +287,7 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); + old =dma_resv_shared (obj);if (old) i = old->shared_count;@@ -326,7 +326,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)dma_resv_assert_held (dst);rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); retry:if (src_list) {@@ -339,7 +339,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)return -ENOMEM ;rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src);if (!src_list || src_list->shared_count > shared_count) {kfree (dst_list); goto retry;@@ -357,7 +357,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)if (!dma_fence_get_rcu (fence)) {dma_resv_list_free (dst_list); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); goto retry; }@@ -376,7 +376,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) new =dma_fence_get_rcu_safe (&src->fence_excl);rcu_read_unlock (); - src_list =dma_resv_get_list (dst); + src_list =dma_resv_shared (dst); old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);@@ -429,7 +429,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock; - fobj =rcu_dereference (obj->fence); + fobj =dma_resv_shared (obj);if (fobj) sz +=sizeof (*shared) * fobj->shared_max;@@ -535,7 +535,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, }if (wait_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);if (fobj) shared_count = fobj->shared_count;@@ -620,7 +620,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);unsigned int i;if (fobj)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -247,7 +247,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,if (!ef)return -EINVAL ; - old =dma_resv_get_list (resv); + old =dma_resv_shared (resv);if (!old)return 0 ;drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-1@@ -49,7 +49,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)unsigned int count;int r; -if (!dma_resv_get_list (obj))/* no shared fences to convert */ +if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences);drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1
-1@@ -213,7 +213,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync, f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (!flist || r)return r;drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -1338,7 +1338,7 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,* If true, then return false as any KFD process needs all its BOs to * be resident to run successfully */ - flist =dma_resv_get_list (bo->base.resv); + flist =dma_resv_shared (bo->base.resv);if (flist) {for (i =0 ; i < flist->shared_count; ++i) { f = rcu_dereference_protected(flist->shared[i],drivers/gpu/drm/etnaviv/etnaviv_gem.c +1
-1@@ -461,7 +461,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) off, etnaviv_obj->vaddr, obj->size);rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-1@@ -116,7 +116,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ - list =rcu_dereference (obj->base.resv->fence); + list =dma_resv_shared (obj->base.resv);if (list) {unsigned int shared_count = list->shared_count, i;drivers/gpu/drm/msm/msm_gem.c +2
-2@@ -817,7 +817,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj,struct dma_fence *fence;int i, ret; - fobj =dma_resv_get_list (obj->resv); + fobj =dma_resv_shared (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */ @@ -1025,7 +1025,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, }rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -355,7 +355,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool ereturn ret; } - fobj =dma_resv_get_list (resv); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {drivers/gpu/drm/qxl/qxl_debugfs.c +1
-1@@ -61,7 +61,7 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data)int rel;rcu_read_lock (); - fobj =rcu_dereference (bo->tbo.base.resv->fence); + fobj =dma_resv_shared (bo->tbo.base.resv); rel = fobj ? fobj->shared_count :0 ;rcu_read_unlock ();drivers/gpu/drm/radeon/radeon_sync.c +1
-1@@ -105,7 +105,7 @@ int radeon_sync_resv(struct radeon_device *rdev,else if (f) r =dma_fence_wait (f, true); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (shared || !flist || r)return r;drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -261,7 +261,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)int i;rcu_read_lock (); - fobj =rcu_dereference (resv->fence); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);include/linux/dma-resv.h +0
-14@@ -78,20 +78,6 @@ struct dma_resv {#define dma_resv_held (obj) lockdep_is_held(&(obj)->lock.base)#define dma_resv_assert_held (obj) lockdep_assert_held(&(obj)->lock.base) -/** -* dma_resv_get_list - get the reservation object's -* shared fence list, with update-side lock held -* @obj: the reservation object -* -* Returns the shared fence list. Does NOT take references to -* the fence. The obj->lock must be held. -*/ -static inline struct dma_resv_list *dma_resv_get_list (struct dma_resv *obj) -{ -return rcu_dereference_protected (obj->fence, -dma_resv_held (obj)); -} -#ifdef CONFIG_DEBUG_MUTEXES void dma_resv_reset_shared_max (struct dma_resv *obj);#else @@ -267,6 +253,17 @@ dma_resv_get_excl_rcu(struct dma_resv *obj)return fence; }
Quoted 9 lines
include/linux/dma-resv.h dma_resv_get_excl_rcu(struct dma_resv *obj) · line 262
Quoted 7 lines
include/linux/dma-resv.h +7
-0+/** +* dma_resv_shared - get the reservation object's shared fence list +* @obj: the reservation object +* +* Returns the shared fence list. The obj->lock or rcu read side must be held. +*/ +static inline struct dma_resv_list *dma_resv_shared (struct dma_resv *obj)Maybe
dma_resv_shared_list()just to be a little more clear what's being returned?
Ok, renamed this one and dma_resv_exclusive into dma_resv_excl_fence as well.
Christian.
Quoted 13 lines
--Jason
Quoted 10 lines
include/linux/dma-resv.h +4
-1+{ +return rcu_dereference_check (obj->fence,dma_resv_held (obj)); +} +void dma_resv_init (struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences); --2.25.1
Jason Ekstrand
Reviewed-byRe: [PATCH 5/7] dma-buf: rename and cleanup dma_resv_get_list
Quoted 337 lines · Christian König
Am 02.06.21 um 22:22 schrieb Jason Ekstrand:
Quoted 47 lines
Quoted 45 lines · Christian König
When the comment needs to state explicitly that this is doesn't get a reference to the object then the function is named rather badly.
Rename the function and use it in even more places.
Signed-off-by Christian König <[email protected]>--- drivers/dma-buf/dma-resv.c | 32 +++++++++---------- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 4 +-- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/qxl/qxl_debugfs.c | 2 +- drivers/gpu/drm/radeon/radeon_sync.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- include/linux/dma-resv.h | 25 +++++++-------- 13 files changed, 39 insertions(+), 42 deletions(-)drivers/dma-buf/dma-resv.c +2
-5@@ -149,8 +149,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); - + old =dma_resv_shared (obj);if (old && old->shared_max) {if ((old->shared_count + num_fences) <= old->shared_max)return 0 ;@@ -217,12 +216,13 @@ EXPORT_SYMBOL(dma_resv_reserve_shared);*/ void dma_resv_reset_shared_max (struct dma_resv *obj) { -/* Test shared fence slot reservation */ -if (rcu_access_pointer (obj->fence)) { -struct dma_resv_list *fence =dma_resv_get_list (obj); +struct dma_resv_list *fences =dma_resv_shared (obj);Quoted 5 lines
drivers/dma-buf/dma-resv.c EXPORT_SYMBOL(dma_resv_reserve_shared); · line 221
Quoted 3 lines
drivers/dma-buf/dma-resv.c +1
-2- fence->shared_max = fence->shared_count; - } +dma_resv_assert_held (obj);Does it make sense to assert we hold the lock *before* we touch it with something that requires that we do? Maybe it doesn't matter?
As far as I can see that shouldn't matter.
Quoted 270 lines
Quoted 270 lines
drivers/dma-buf/dma-resv.c +13
-9+ +/* Test shared fence slot reservation */ +if (fences) + fences->shared_max = fences->shared_count; }#endif @@ -244,7 +244,7 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - fobj =dma_resv_get_list (obj); + fobj =dma_resv_shared (obj); count = fobj->shared_count;write_seqcount_begin (&obj->seq);@@ -287,7 +287,7 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)dma_resv_assert_held (obj); - old =dma_resv_get_list (obj); + old =dma_resv_shared (obj);if (old) i = old->shared_count;@@ -326,7 +326,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)dma_resv_assert_held (dst);rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); retry:if (src_list) {@@ -339,7 +339,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)return -ENOMEM ;rcu_read_lock (); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src);if (!src_list || src_list->shared_count > shared_count) {kfree (dst_list); goto retry;@@ -357,7 +357,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)if (!dma_fence_get_rcu (fence)) {dma_resv_list_free (dst_list); - src_list =rcu_dereference (src->fence); + src_list =dma_resv_shared (src); goto retry; }@@ -376,7 +376,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src) new =dma_fence_get_rcu_safe (&src->fence_excl);rcu_read_unlock (); - src_list =dma_resv_get_list (dst); + src_list =dma_resv_shared (dst); old =dma_resv_exclusive (dst);write_seqcount_begin (&dst->seq);@@ -429,7 +429,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,if (fence_excl && !dma_fence_get_rcu (fence_excl)) goto unlock; - fobj =rcu_dereference (obj->fence); + fobj =dma_resv_shared (obj);if (fobj) sz +=sizeof (*shared) * fobj->shared_max;@@ -535,7 +535,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj, }if (wait_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);if (fobj) shared_count = fobj->shared_count;@@ -620,7 +620,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all) seq =read_seqcount_begin (&obj->seq);if (test_all) { -struct dma_resv_list *fobj =rcu_dereference (obj->fence); +struct dma_resv_list *fobj =dma_resv_shared (obj);unsigned int i;if (fobj)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -247,7 +247,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,if (!ef)return -EINVAL ; - old =dma_resv_get_list (resv); + old =dma_resv_shared (resv);if (!old)return 0 ;drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-1@@ -49,7 +49,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)unsigned int count;int r; -if (!dma_resv_get_list (obj))/* no shared fences to convert */ +if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences);drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +1
-1@@ -213,7 +213,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync, f =dma_resv_exclusive (resv); r =amdgpu_sync_fence (sync, f); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (!flist || r)return r;drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -1338,7 +1338,7 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,* If true, then return false as any KFD process needs all its BOs to * be resident to run successfully */ - flist =dma_resv_get_list (bo->base.resv); + flist =dma_resv_shared (bo->base.resv);if (flist) {for (i =0 ; i < flist->shared_count; ++i) { f = rcu_dereference_protected(flist->shared[i],drivers/gpu/drm/etnaviv/etnaviv_gem.c +1
-1@@ -461,7 +461,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m) off, etnaviv_obj->vaddr, obj->size);rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-1@@ -116,7 +116,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, args->busy =busy_check_writer (dma_resv_exclusive (obj->base.resv));/* Translate shared fences to READ set of engines */ - list =rcu_dereference (obj->base.resv->fence); + list =dma_resv_shared (obj->base.resv);if (list) {unsigned int shared_count = list->shared_count, i;drivers/gpu/drm/msm/msm_gem.c +2
-2@@ -817,7 +817,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj,struct dma_fence *fence;int i, ret; - fobj =dma_resv_get_list (obj->resv); + fobj =dma_resv_shared (obj->resv);if (!fobj || (fobj->shared_count ==0 )) { fence =dma_resv_exclusive (obj->resv);/* don't need to wait on our own fences, since ring is fifo */ @@ -1025,7 +1025,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m, }rcu_read_lock (); - fobj =rcu_dereference (robj->fence); + fobj =dma_resv_shared (robj);if (fobj) {unsigned int i, shared_count = fobj->shared_count;drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -355,7 +355,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool ereturn ret; } - fobj =dma_resv_get_list (resv); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && (!exclusive || !fobj || !fobj->shared_count)) {drivers/gpu/drm/qxl/qxl_debugfs.c +1
-1@@ -61,7 +61,7 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data)int rel;rcu_read_lock (); - fobj =rcu_dereference (bo->tbo.base.resv->fence); + fobj =dma_resv_shared (bo->tbo.base.resv); rel = fobj ? fobj->shared_count :0 ;rcu_read_unlock ();drivers/gpu/drm/radeon/radeon_sync.c +1
-1@@ -105,7 +105,7 @@ int radeon_sync_resv(struct radeon_device *rdev,else if (f) r =dma_fence_wait (f, true); - flist =dma_resv_get_list (resv); + flist =dma_resv_shared (resv);if (shared || !flist || r)return r;drivers/gpu/drm/ttm/ttm_bo.c +1
-1@@ -261,7 +261,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)int i;rcu_read_lock (); - fobj =rcu_dereference (resv->fence); + fobj =dma_resv_shared (resv); fence =dma_resv_exclusive (resv);if (fence && !fence->ops->signaled)dma_fence_enable_sw_signaling (fence);include/linux/dma-resv.h +0
-14@@ -78,20 +78,6 @@ struct dma_resv {#define dma_resv_held (obj) lockdep_is_held(&(obj)->lock.base)#define dma_resv_assert_held (obj) lockdep_assert_held(&(obj)->lock.base) -/** -* dma_resv_get_list - get the reservation object's -* shared fence list, with update-side lock held -* @obj: the reservation object -* -* Returns the shared fence list. Does NOT take references to -* the fence. The obj->lock must be held. -*/ -static inline struct dma_resv_list *dma_resv_get_list (struct dma_resv *obj) -{ -return rcu_dereference_protected (obj->fence, -dma_resv_held (obj)); -} -#ifdef CONFIG_DEBUG_MUTEXES void dma_resv_reset_shared_max (struct dma_resv *obj);#else @@ -267,6 +253,17 @@ dma_resv_get_excl_rcu(struct dma_resv *obj)return fence; }Quoted 9 lines
include/linux/dma-resv.h dma_resv_get_excl_rcu(struct dma_resv *obj) · line 262
Quoted 7 lines
include/linux/dma-resv.h +7
-0+/** +* dma_resv_shared - get the reservation object's shared fence list +* @obj: the reservation object +* +* Returns the shared fence list. The obj->lock or rcu read side must be held. +*/ +static inline struct dma_resv_list *dma_resv_shared (struct dma_resv *obj)Maybe
dma_resv_shared_list()just to be a little more clear what's being returned?
Quoted 2 lines
Ok, renamed this one and
dma_resv_exclusiveintodma_resv_excl_fenceas well.
Cool
then. Any more left needing review?
--Jason
Quoted 16 lines
Christian.
Quoted 13 lines
--Jason
Quoted 10 lines
include/linux/dma-resv.h +4
-1+{ +return rcu_dereference_check (obj->fence,dma_resv_held (obj)); +} +void dma_resv_init (struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences); --2.25.1
PATCH 6/7 dma-buf: rename dma_resv_get_excl_rcu to _unlocked
In reply to Christian KönigThat describes much better what the function is doing here.
--- drivers/gpu/drm/drm_gem.c | 2 +- drivers/gpu/drm/drm_gem_atomic_helper.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/display/intel_display.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 2 +- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 ++-- drivers/gpu/drm/i915/i915_request.c | 2 +- drivers/gpu/drm/i915/i915_sw_fence.c | 2 +- drivers/gpu/drm/nouveau/dispnv50/wndw.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- include/linux/dma-resv.h | 4 ++-- 11 files changed, 13 insertions(+), 13 deletions(-)
drivers/gpu/drm/drm_gem.c +1 -1
@@ -1375,7 +1375,7 @@ int drm_gem_fence_array_add_implicit(struct xarray *fence_array,if (!write) {struct dma_fence *fence = -dma_resv_get_excl_rcu (obj->resv); +dma_resv_get_excl_unlocked (obj->resv);return drm_gem_fence_array_add (fence_array, fence); }
drivers/gpu/drm/drm_gem_atomic_helper.c +1 -1
@@ -147,7 +147,7 @@ int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_streturn 0 ; obj =drm_gem_fb_get_obj (state->fb,0 ); - fence =dma_resv_get_excl_rcu (obj->resv); + fence =dma_resv_get_excl_unlocked (obj->resv);drm_atomic_set_fence_for_plane (state, fence);return 0 ;
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
@@ -195,7 +195,7 @@ static int submit_fence_sync(struct etnaviv_gem_submit *submit)if (ret)return ret; }else { - bo->excl =dma_resv_get_excl_rcu (robj); + bo->excl =dma_resv_get_excl_unlocked (robj); } }
drivers/gpu/drm/i915/display/intel_display.c +1 -1
@@ -11040,7 +11040,7 @@ intel_prepare_plane_fb(struct drm_plane *_plane,if (ret <0 ) goto unpin_fb; - fence =dma_resv_get_excl_rcu (obj->base.resv); + fence =dma_resv_get_excl_unlocked (obj->base.resv);if (fence) {add_rps_boost_after_vblank (new_plane_state->hw.crtc, fence);
drivers/gpu/drm/i915/gem/i915_gem_object.h +1 -1
@@ -500,7 +500,7 @@ i915_gem_object_last_write_engine(struct drm_i915_gem_object *obj)struct dma_fence *fence;rcu_read_lock (); - fence =dma_resv_get_excl_rcu (obj->base.resv); + fence =dma_resv_get_excl_unlocked (obj->base.resv);rcu_read_unlock ();if (fence &&dma_fence_is_i915 (fence) && !dma_fence_is_signaled (fence))
drivers/gpu/drm/i915/gem/i915_gem_wait.c +2 -2
@@ -73,7 +73,7 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,*/ prune_fences = count && timeout >=0 ; }else { - excl =dma_resv_get_excl_rcu (resv); + excl =dma_resv_get_excl_unlocked (resv); }if (excl && timeout >=0 )
@@ -170,7 +170,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,kfree (shared); }else { - excl =dma_resv_get_excl_rcu (obj->base.resv); + excl =dma_resv_get_excl_unlocked (obj->base.resv); }if (excl) {
drivers/gpu/drm/i915/i915_request.c +1 -1
@@ -1611,7 +1611,7 @@ i915_request_await_object(struct i915_request *to,dma_fence_put (shared[i]);kfree (shared); }else { - excl =dma_resv_get_excl_rcu (obj->base.resv); + excl =dma_resv_get_excl_unlocked (obj->base.resv); }if (excl) {
drivers/gpu/drm/i915/i915_sw_fence.c +1 -1
@@ -606,7 +606,7 @@ int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,dma_fence_put (shared[i]);kfree (shared); }else { - excl =dma_resv_get_excl_rcu (resv); + excl =dma_resv_get_excl_unlocked (resv); }if (ret >=0 && excl && excl->ops != exclude) {
drivers/gpu/drm/nouveau/dispnv50/wndw.c +1 -1
@@ -561,7 +561,7 @@ nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state) asyw->image.handle[0 ] = ctxdma->object.handle; } - asyw->state.fence =dma_resv_get_excl_rcu (nvbo->bo.base.resv); + asyw->state.fence =dma_resv_get_excl_unlocked (nvbo->bo.base.resv); asyw->image.offset[0 ] = nvbo->offset;if (wndw->func->prepare) {
drivers/gpu/drm/panfrost/panfrost_job.c +1 -1
@@ -203,7 +203,7 @@ static void panfrost_acquire_object_fences(struct drm_gem_object **bos,int i;for (i =0 ; i < bo_count; i++) - implicit_fences[i] =dma_resv_get_excl_rcu (bos[i]->resv); + implicit_fences[i] =dma_resv_get_excl_unlocked (bos[i]->resv); } static void panfrost_attach_object_fences(struct drm_gem_object **bos,
include/linux/dma-resv.h +2 -2
@@ -228,7 +228,7 @@ dma_resv_exclusive(struct dma_resv *obj) }/** -* dma_resv_get_excl_rcu - get the reservation object's +* dma_resv_get_excl_unlocked - get the reservation object's * exclusive fence, without lock held. * @obj: the reservation object *
@@ -239,7 +239,7 @@ dma_resv_exclusive(struct dma_resv *obj)* The exclusive fence or NULL if none */ static inline struct dma_fence * -dma_resv_get_excl_rcu (struct dma_resv *obj) +dma_resv_get_excl_unlocked (struct dma_resv *obj) {struct dma_fence *fence;
Signature · 1 line
2.25.1
Re: [PATCH 6/7] dma-buf: rename dma_resv_get_excl_rcu to _unlocked
Quoted 3 lines · Christian König
That describes much better what the function is doing here.
Signed-off-by Christian König <[email protected]>
Quoted 178 lines
--- drivers/gpu/drm/drm_gem.c | 2 +- drivers/gpu/drm/drm_gem_atomic_helper.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/display/intel_display.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 2 +- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 ++-- drivers/gpu/drm/i915/i915_request.c | 2 +- drivers/gpu/drm/i915/i915_sw_fence.c | 2 +- drivers/gpu/drm/nouveau/dispnv50/wndw.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- include/linux/dma-resv.h | 4 ++-- 11 files changed, 13 insertions(+), 13 deletions(-)drivers/gpu/drm/drm_gem.c +1
-1@@ -1375,7 +1375,7 @@ int drm_gem_fence_array_add_implicit(struct xarray *fence_array,if (!write) {struct dma_fence *fence = -dma_resv_get_excl_rcu (obj->resv); +dma_resv_get_excl_unlocked (obj->resv);return drm_gem_fence_array_add (fence_array, fence); }drivers/gpu/drm/drm_gem_atomic_helper.c +1
-1@@ -147,7 +147,7 @@ int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_streturn 0 ; obj =drm_gem_fb_get_obj (state->fb,0 ); - fence =dma_resv_get_excl_rcu (obj->resv); + fence =dma_resv_get_excl_unlocked (obj->resv);drm_atomic_set_fence_for_plane (state, fence);return 0 ;drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1
-1@@ -195,7 +195,7 @@ static int submit_fence_sync(struct etnaviv_gem_submit *submit)if (ret)return ret; }else { - bo->excl =dma_resv_get_excl_rcu (robj); + bo->excl =dma_resv_get_excl_unlocked (robj); } }drivers/gpu/drm/i915/display/intel_display.c +1
-1@@ -11040,7 +11040,7 @@ intel_prepare_plane_fb(struct drm_plane *_plane,if (ret <0 ) goto unpin_fb; - fence =dma_resv_get_excl_rcu (obj->base.resv); + fence =dma_resv_get_excl_unlocked (obj->base.resv);if (fence) {add_rps_boost_after_vblank (new_plane_state->hw.crtc, fence);drivers/gpu/drm/i915/gem/i915_gem_object.h +1
-1@@ -500,7 +500,7 @@ i915_gem_object_last_write_engine(struct drm_i915_gem_object *obj)struct dma_fence *fence;rcu_read_lock (); - fence =dma_resv_get_excl_rcu (obj->base.resv); + fence =dma_resv_get_excl_unlocked (obj->base.resv);rcu_read_unlock ();if (fence &&dma_fence_is_i915 (fence) && !dma_fence_is_signaled (fence))drivers/gpu/drm/i915/gem/i915_gem_wait.c +2
-2@@ -73,7 +73,7 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,*/ prune_fences = count && timeout >=0 ; }else { - excl =dma_resv_get_excl_rcu (resv); + excl =dma_resv_get_excl_unlocked (resv); }if (excl && timeout >=0 )@@ -170,7 +170,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,kfree (shared); }else { - excl =dma_resv_get_excl_rcu (obj->base.resv); + excl =dma_resv_get_excl_unlocked (obj->base.resv); }if (excl) {drivers/gpu/drm/i915/i915_request.c +1
-1@@ -1611,7 +1611,7 @@ i915_request_await_object(struct i915_request *to,dma_fence_put (shared[i]);kfree (shared); }else { - excl =dma_resv_get_excl_rcu (obj->base.resv); + excl =dma_resv_get_excl_unlocked (obj->base.resv); }if (excl) {drivers/gpu/drm/i915/i915_sw_fence.c +1
-1@@ -606,7 +606,7 @@ int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,dma_fence_put (shared[i]);kfree (shared); }else { - excl =dma_resv_get_excl_rcu (resv); + excl =dma_resv_get_excl_unlocked (resv); }if (ret >=0 && excl && excl->ops != exclude) {drivers/gpu/drm/nouveau/dispnv50/wndw.c +1
-1@@ -561,7 +561,7 @@ nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state) asyw->image.handle[0 ] = ctxdma->object.handle; } - asyw->state.fence =dma_resv_get_excl_rcu (nvbo->bo.base.resv); + asyw->state.fence =dma_resv_get_excl_unlocked (nvbo->bo.base.resv); asyw->image.offset[0 ] = nvbo->offset;if (wndw->func->prepare) {drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -203,7 +203,7 @@ static void panfrost_acquire_object_fences(struct drm_gem_object **bos,int i;for (i =0 ; i < bo_count; i++) - implicit_fences[i] =dma_resv_get_excl_rcu (bos[i]->resv); + implicit_fences[i] =dma_resv_get_excl_unlocked (bos[i]->resv); } static void panfrost_attach_object_fences(struct drm_gem_object **bos,include/linux/dma-resv.h +2
-2@@ -228,7 +228,7 @@ dma_resv_exclusive(struct dma_resv *obj) }/** -* dma_resv_get_excl_rcu - get the reservation object's +* dma_resv_get_excl_unlocked - get the reservation object's * exclusive fence, without lock held. * @obj: the reservation object * @@ -239,7 +239,7 @@ dma_resv_exclusive(struct dma_resv *obj)* The exclusive fence or NULL if none */ static inline struct dma_fence * -dma_resv_get_excl_rcu (struct dma_resv *obj) +dma_resv_get_excl_unlocked (struct dma_resv *obj) {struct dma_fence *fence;Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 6/7] dma-buf: rename dma_resv_get_excl_rcu to _unlocked
In reply to Christian KönigQuoted 182 lines · Christian König
That describes much better what the function is doing here.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/drm_gem.c | 2 +- drivers/gpu/drm/drm_gem_atomic_helper.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/display/intel_display.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 2 +- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 ++-- drivers/gpu/drm/i915/i915_request.c | 2 +- drivers/gpu/drm/i915/i915_sw_fence.c | 2 +- drivers/gpu/drm/nouveau/dispnv50/wndw.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- include/linux/dma-resv.h | 4 ++-- 11 files changed, 13 insertions(+), 13 deletions(-)drivers/gpu/drm/drm_gem.c +1
-1@@ -1375,7 +1375,7 @@ int drm_gem_fence_array_add_implicit(struct xarray *fence_array,if (!write) {struct dma_fence *fence = -dma_resv_get_excl_rcu (obj->resv); +dma_resv_get_excl_unlocked (obj->resv);return drm_gem_fence_array_add (fence_array, fence); }drivers/gpu/drm/drm_gem_atomic_helper.c +1
-1@@ -147,7 +147,7 @@ int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_streturn 0 ; obj =drm_gem_fb_get_obj (state->fb,0 ); - fence =dma_resv_get_excl_rcu (obj->resv); + fence =dma_resv_get_excl_unlocked (obj->resv);drm_atomic_set_fence_for_plane (state, fence);return 0 ;drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1
-1@@ -195,7 +195,7 @@ static int submit_fence_sync(struct etnaviv_gem_submit *submit)if (ret)return ret; }else { - bo->excl =dma_resv_get_excl_rcu (robj); + bo->excl =dma_resv_get_excl_unlocked (robj); } }drivers/gpu/drm/i915/display/intel_display.c +1
-1@@ -11040,7 +11040,7 @@ intel_prepare_plane_fb(struct drm_plane *_plane,if (ret <0 ) goto unpin_fb; - fence =dma_resv_get_excl_rcu (obj->base.resv); + fence =dma_resv_get_excl_unlocked (obj->base.resv);if (fence) {add_rps_boost_after_vblank (new_plane_state->hw.crtc, fence);drivers/gpu/drm/i915/gem/i915_gem_object.h +1
-1@@ -500,7 +500,7 @@ i915_gem_object_last_write_engine(struct drm_i915_gem_object *obj)struct dma_fence *fence;rcu_read_lock (); - fence =dma_resv_get_excl_rcu (obj->base.resv); + fence =dma_resv_get_excl_unlocked (obj->base.resv);rcu_read_unlock ();if (fence &&dma_fence_is_i915 (fence) && !dma_fence_is_signaled (fence))drivers/gpu/drm/i915/gem/i915_gem_wait.c +2
-2@@ -73,7 +73,7 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,*/ prune_fences = count && timeout >=0 ; }else { - excl =dma_resv_get_excl_rcu (resv); + excl =dma_resv_get_excl_unlocked (resv); }if (excl && timeout >=0 )@@ -170,7 +170,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,kfree (shared); }else { - excl =dma_resv_get_excl_rcu (obj->base.resv); + excl =dma_resv_get_excl_unlocked (obj->base.resv); }if (excl) {drivers/gpu/drm/i915/i915_request.c +1
-1@@ -1611,7 +1611,7 @@ i915_request_await_object(struct i915_request *to,dma_fence_put (shared[i]);kfree (shared); }else { - excl =dma_resv_get_excl_rcu (obj->base.resv); + excl =dma_resv_get_excl_unlocked (obj->base.resv); }if (excl) {drivers/gpu/drm/i915/i915_sw_fence.c +1
-1@@ -606,7 +606,7 @@ int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,dma_fence_put (shared[i]);kfree (shared); }else { - excl =dma_resv_get_excl_rcu (resv); + excl =dma_resv_get_excl_unlocked (resv); }if (ret >=0 && excl && excl->ops != exclude) {drivers/gpu/drm/nouveau/dispnv50/wndw.c +1
-1@@ -561,7 +561,7 @@ nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state) asyw->image.handle[0 ] = ctxdma->object.handle; } - asyw->state.fence =dma_resv_get_excl_rcu (nvbo->bo.base.resv); + asyw->state.fence =dma_resv_get_excl_unlocked (nvbo->bo.base.resv); asyw->image.offset[0 ] = nvbo->offset;if (wndw->func->prepare) {drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -203,7 +203,7 @@ static void panfrost_acquire_object_fences(struct drm_gem_object **bos,int i;for (i =0 ; i < bo_count; i++) - implicit_fences[i] =dma_resv_get_excl_rcu (bos[i]->resv); + implicit_fences[i] =dma_resv_get_excl_unlocked (bos[i]->resv); } static void panfrost_attach_object_fences(struct drm_gem_object **bos,include/linux/dma-resv.h +2
-3@@ -228,7 +228,7 @@ dma_resv_exclusive(struct dma_resv *obj) }/** -* dma_resv_get_excl_rcu - get the reservation object's +* dma_resv_get_excl_unlocked - get the reservation object's * exclusive fence, without lock held. * @obj: the reservation object * @@ -239,7 +239,7 @@ dma_resv_exclusive(struct dma_resv *obj)* The exclusive fence or NULL if none */ static inline struct dma_fence * -dma_resv_get_excl_rcu (struct dma_resv *obj) +dma_resv_get_excl_unlocked (struct dma_resv *obj) {struct dma_fence *fence; --2.25.1
PATCH 7/7 dma-buf: drop the _rcu postfix on function names
In reply to Christian KönigThe functions can be called both in _rcu context as well as while holding the lock.
--- drivers/dma-buf/dma-buf.c | 3 +-- drivers/dma-buf/dma-resv.c | 24 +++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +++---- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- drivers/gpu/drm/drm_gem.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/dma_resv_utils.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 ++-- drivers/gpu/drm/i915/i915_request.c | 2 +- drivers/gpu/drm/i915/i915_sw_fence.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 2 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 2 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +- drivers/gpu/drm/radeon/radeon_gem.c | 6 ++--- drivers/gpu/drm/radeon/radeon_mn.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 12 +++++----- drivers/gpu/drm/vgem/vgem_fence.c | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 2 +- include/linux/dma-resv.h | 17 ++++--------- 31 files changed, 60 insertions(+), 70 deletions(-)
drivers/dma-buf/dma-buf.c +1 -2
@@ -1147,8 +1147,7 @@ static int __dma_buf_begin_cpu_access(struct dma_buf *dmabuf,long ret;/* Wait on any implicit rendering fences */ - ret =dma_resv_wait_timeout_rcu (resv, write, true, -MAX_SCHEDULE_TIMEOUT ); + ret =dma_resv_wait_timeout (resv, write, true,MAX_SCHEDULE_TIMEOUT );if (ret <0 )return ret;
drivers/dma-buf/dma-resv.c +11 -13
@@ -393,7 +393,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)EXPORT_SYMBOL (dma_resv_copy_fences);/** -* dma_resv_get_fences_rcu - Get an object's shared and exclusive +* dma_resv_get_fences - Get an object's shared and exclusive * fences without update side lock held * @obj: the reservation object * @pfence_excl: the returned exclusive fence (or NULL)
@@ -405,10 +405,9 @@ EXPORT_SYMBOL(dma_resv_copy_fences);* exclusive fence is not specified the fence is put into the array of the * shared fences as well. Returns either zero or -ENOMEM. */ -int dma_resv_get_fences_rcu (struct dma_resv *obj, -struct dma_fence **pfence_excl, -unsigned int *pshared_count, -struct dma_fence ***pshared) +int dma_resv_get_fences (struct dma_resv *obj,struct dma_fence **pfence_excl, +unsigned int *pshared_count, +struct dma_fence ***pshared) {struct dma_fence **shared =NULL ;struct dma_fence *fence_excl;
@@ -491,10 +490,10 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj, *pshared = shared;return ret; } -EXPORT_SYMBOL_GPL (dma_resv_get_fences_rcu); +EXPORT_SYMBOL_GPL (dma_resv_get_fences);/** -* dma_resv_wait_timeout_rcu - Wait on reservation's objects +* dma_resv_wait_timeout - Wait on reservation's objects * shared and/or exclusive fences. * @obj: the reservation object * @wait_all: if true, wait on all fences, else wait on just exclusive fence
@@ -505,9 +504,8 @@ EXPORT_SYMBOL_GPL(dma_resv_get_fences_rcu);* Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or * greater than zer on success. */ -long dma_resv_wait_timeout_rcu (struct dma_resv *obj, -bool wait_all,bool intr, -unsigned long timeout) +long dma_resv_wait_timeout (struct dma_resv *obj,bool wait_all,bool intr, +unsigned long timeout) {long ret = timeout ? timeout :1 ;unsigned int seq, shared_count;
@@ -579,7 +577,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,rcu_read_unlock (); goto retry; } -EXPORT_SYMBOL_GPL (dma_resv_wait_timeout_rcu); +EXPORT_SYMBOL_GPL (dma_resv_wait_timeout);static inline int dma_resv_test_signaled_single (struct dma_fence *passed_fence)
@@ -608,7 +606,7 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)* RETURNS * true if all fences signaled, else false */ -bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all) +bool dma_resv_test_signaled (struct dma_resv *obj,bool test_all) {unsigned int seq, shared_count;int ret;
@@ -657,7 +655,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)rcu_read_unlock ();return ret; } -EXPORT_SYMBOL_GPL (dma_resv_test_signaled_rcu); +EXPORT_SYMBOL_GPL (dma_resv_test_signaled);#if IS_ENABLED (CONFIG_LOCKDEP )static int __init dma_resv_lockdep (void )
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -1
@@ -203,7 +203,7 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc, goto unpin; } - r =dma_resv_get_fences_rcu (new_abo->tbo.base.resv, &work->excl, + r =dma_resv_get_fences (new_abo->tbo.base.resv, &work->excl, &work->shared_count, &work->shared);if (unlikely (r !=0 )) {
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
@@ -52,7 +52,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; - r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences); + r =dma_resv_get_fences (obj,NULL , &count, &fences);if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -1
@@ -526,7 +526,7 @@ int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,return -ENOENT ; } robj =gem_to_amdgpu_bo (gobj); - ret =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true, + ret =dma_resv_wait_timeout (robj->tbo.base.resv, true, true, timeout);/* ret == 0 means not signaled,
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +2 -2
@@ -112,7 +112,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,unsigned count;int r; - r =dma_resv_get_fences_rcu (resv,NULL , &count, &fences); + r =dma_resv_get_fences (resv,NULL , &count, &fences);if (r) goto fallback;
@@ -156,7 +156,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,/* Not enough memory for the delayed delete, as last resort * block for all the fences to complete. */ -dma_resv_wait_timeout_rcu (resv, true, false, +dma_resv_wait_timeout (resv, true, false,MAX_SCHEDULE_TIMEOUT );amdgpu_pasid_free (pasid); }
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +1 -1
@@ -75,7 +75,7 @@ static bool amdgpu_mn_invalidate_gfx(struct mmu_interval_notifier *mni,mmu_interval_set_seq (mni, cur_seq); - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, true, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,MAX_SCHEDULE_TIMEOUT );mutex_unlock (&adev->notifier_lock);if (r <=0 )
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
@@ -756,7 +756,7 @@ int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)return 0 ; } - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, false, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, false, false,MAX_SCHEDULE_TIMEOUT );if (r <0 )return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +1 -1
@@ -1126,7 +1126,7 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, ib->length_dw =16 ;if (direct) { - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,msecs_to_jiffies (10 ));if (r ==0 )
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -4
@@ -2022,13 +2022,13 @@ static void amdgpu_vm_prt_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)unsigned i, shared_count;int r; - r =dma_resv_get_fences_rcu (resv, &excl, + r =dma_resv_get_fences (resv, &excl, &shared_count, &shared);if (r) {/* Not enough memory to grab the fence list, as last resort * block for all the fences to complete. */ -dma_resv_wait_timeout_rcu (resv, true, false, +dma_resv_wait_timeout (resv, true, false,MAX_SCHEDULE_TIMEOUT );return ; }
@@ -2640,7 +2640,7 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo)return true;/* Don't evict VM page tables while they are busy */ -if (!dma_resv_test_signaled_rcu (bo->tbo.base.resv, true)) +if (!dma_resv_test_signaled (bo->tbo.base.resv, true))return false;/* Try to block ongoing updates */
@@ -2820,7 +2820,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,*/ long amdgpu_vm_wait_idle (struct amdgpu_vm *vm,long timeout) { - timeout =dma_resv_wait_timeout_rcu (vm->root.base.bo->tbo.base.resv, + timeout =dma_resv_wait_timeout (vm->root.base.bo->tbo.base.resv, true, true, timeout);if (timeout <=0 )return timeout;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
@@ -8400,7 +8400,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,* deadlock during GPU reset when this fence will not signal * but we hold reservation lock for the BO. */ - r =dma_resv_wait_timeout_rcu (abo->tbo.base.resv, true, + r =dma_resv_wait_timeout (abo->tbo.base.resv, true, false,msecs_to_jiffies (5000 ));if (unlikely (r <=0 ))
drivers/gpu/drm/drm_gem.c +2 -2
@@ -770,7 +770,7 @@ long drm_gem_dma_resv_wait(struct drm_file *filep, u32 handle,return -EINVAL ; } - ret =dma_resv_wait_timeout_rcu (obj->resv, wait_all, + ret =dma_resv_wait_timeout (obj->resv, wait_all, true, timeout);if (ret ==0 ) ret = -ETIME ;
@@ -1380,7 +1380,7 @@ int drm_gem_fence_array_add_implicit(struct xarray *fence_array,return drm_gem_fence_array_add (fence_array, fence); } - ret =dma_resv_get_fences_rcu (obj->resv,NULL , + ret =dma_resv_get_fences (obj->resv,NULL , &fence_count, &fences);if (ret || !fence_count)return ret;
drivers/gpu/drm/etnaviv/etnaviv_gem.c +2 -2
@@ -390,13 +390,13 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op, }if (op &ETNA_PREP_NOSYNC ) { -if (!dma_resv_test_signaled_rcu (obj->resv, +if (!dma_resv_test_signaled (obj->resv, write))return -EBUSY ; }else {unsigned long remain =etnaviv_timeout_to_jiffies (timeout); - ret =dma_resv_wait_timeout_rcu (obj->resv, + ret =dma_resv_wait_timeout (obj->resv, write, true, remain);if (ret <=0 )return ret ==0 ? -ETIMEDOUT : ret;
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
@@ -189,7 +189,7 @@ static int submit_fence_sync(struct etnaviv_gem_submit *submit)continue ;if (bo->flags &ETNA_SUBMIT_BO_WRITE ) { - ret =dma_resv_get_fences_rcu (robj, &bo->excl, + ret =dma_resv_get_fences (robj, &bo->excl, &bo->nr_shared, &bo->shared);if (ret)
drivers/gpu/drm/i915/dma_resv_utils.c +1 -1
@@ -10,7 +10,7 @@void dma_resv_prune (struct dma_resv *resv) {if (dma_resv_trylock (resv)) { -if (dma_resv_test_signaled_rcu (resv, true)) +if (dma_resv_test_signaled (resv, true))dma_resv_add_excl_fence (resv,NULL );dma_resv_unlock (resv); }
drivers/gpu/drm/i915/gem/i915_gem_busy.c +1 -1
@@ -105,7 +105,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,* Alternatively, we can trade that extra information on read/write * activity with * args->busy = -* !dma_resv_test_signaled_rcu(obj->resv, true); +* !dma_resv_test_signaled(obj->resv, true); * to report the overall busyness. This is what the wait-ioctl does. * */
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1 -1
@@ -1481,7 +1481,7 @@ static inline bool use_reloc_gpu(struct i915_vma *vma)if (DBG_FORCE_RELOC )return false; -return !dma_resv_test_signaled_rcu (vma->resv, true); +return !dma_resv_test_signaled (vma->resv, true); }static unsigned long vma_phys_addr (struct i915_vma *vma,u32 offset)
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1 -1
@@ -85,7 +85,7 @@ static bool i915_gem_userptr_invalidate(struct mmu_interval_notifier *mni,return true;/* we will unbind on next submission, still have userptr pins */ - r =dma_resv_wait_timeout_rcu (obj->base.resv, true, false, + r =dma_resv_wait_timeout (obj->base.resv, true, false,MAX_SCHEDULE_TIMEOUT );if (r <=0 )drm_err (&i915->drm,"(%ld) failed to wait for idle\n" , r);
drivers/gpu/drm/i915/gem/i915_gem_wait.c +2 -2
@@ -45,7 +45,7 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,unsigned int count, i;int ret; - ret =dma_resv_get_fences_rcu (resv, &excl, &count, &shared); + ret =dma_resv_get_fences (resv, &excl, &count, &shared);if (ret)return ret;
@@ -158,7 +158,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,unsigned int count, i;int ret; - ret =dma_resv_get_fences_rcu (obj->base.resv, + ret =dma_resv_get_fences (obj->base.resv, &excl, &count, &shared);if (ret)return ret;
drivers/gpu/drm/i915/i915_request.c +1 -1
@@ -1594,7 +1594,7 @@ i915_request_await_object(struct i915_request *to,struct dma_fence **shared;unsigned int count, i; - ret =dma_resv_get_fences_rcu (obj->base.resv, + ret =dma_resv_get_fences (obj->base.resv, &excl, &count, &shared);if (ret)return ret;
drivers/gpu/drm/i915/i915_sw_fence.c +1 -1
@@ -582,7 +582,7 @@ int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,struct dma_fence **shared;unsigned int count, i; - ret =dma_resv_get_fences_rcu (resv, &excl, &count, &shared); + ret =dma_resv_get_fences (resv, &excl, &count, &shared);if (ret)return ret;
drivers/gpu/drm/msm/msm_gem.c +1 -1
@@ -915,7 +915,7 @@ int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout) op &MSM_PREP_NOSYNC ?0 :timeout_to_jiffies (timeout);long ret; - ret =dma_resv_wait_timeout_rcu (obj->resv, write, + ret =dma_resv_wait_timeout (obj->resv, write, true, remain);if (ret ==0 )return remain ==0 ? -EBUSY : -ETIMEDOUT ;
drivers/gpu/drm/nouveau/nouveau_gem.c +1 -1
@@ -964,7 +964,7 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,return -ENOENT ; nvbo =nouveau_gem_object (gem); - lret =dma_resv_wait_timeout_rcu (nvbo->bo.base.resv, write, true, + lret =dma_resv_wait_timeout (nvbo->bo.base.resv, write, true, no_wait ?0 :30 *HZ );if (!lret) ret = -EBUSY ;
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
@@ -311,7 +311,7 @@ panfrost_ioctl_wait_bo(struct drm_device *dev, void *data,if (!gem_obj)return -ENOENT ; - ret =dma_resv_wait_timeout_rcu (gem_obj->resv, true, + ret =dma_resv_wait_timeout (gem_obj->resv, true, true, timeout);if (!ret) ret = timeout ? -ETIMEDOUT : -EBUSY ;
drivers/gpu/drm/radeon/radeon_gem.c +3 -3
@@ -161,7 +161,7 @@ static int radeon_gem_set_domain(struct drm_gem_object *gobj, }if (domain ==RADEON_GEM_DOMAIN_CPU ) {/* Asking for cpu access wait for object idle */ - r =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true,30 *HZ ); + r =dma_resv_wait_timeout (robj->tbo.base.resv, true, true,30 *HZ );if (!r) r = -EBUSY ;
@@ -523,7 +523,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data, } robj =gem_to_radeon_bo (gobj); - r =dma_resv_test_signaled_rcu (robj->tbo.base.resv, true); + r =dma_resv_test_signaled (robj->tbo.base.resv, true);if (r ==0 ) r = -EBUSY ;else
@@ -552,7 +552,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, } robj =gem_to_radeon_bo (gobj); - ret =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true,30 *HZ ); + ret =dma_resv_wait_timeout (robj->tbo.base.resv, true, true,30 *HZ );if (ret ==0 ) r = -EBUSY ;else if (ret <0 )
drivers/gpu/drm/radeon/radeon_mn.c +1 -1
@@ -66,7 +66,7 @@ static bool radeon_mn_invalidate(struct mmu_interval_notifier *mn,return true; } - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, true, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,MAX_SCHEDULE_TIMEOUT );if (r <=0 )DRM_ERROR ("(%ld) failed to wait for user bo\n" , r);
drivers/gpu/drm/ttm/ttm_bo.c +6 -6
@@ -296,7 +296,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,struct dma_resv *resv = &bo->base._resv;int ret; -if (dma_resv_test_signaled_rcu (resv, true)) +if (dma_resv_test_signaled (resv, true)) ret =0 ;else ret = -EBUSY ;
@@ -308,7 +308,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,dma_resv_unlock (bo->base.resv);spin_unlock (&bo->bdev->lru_lock); - lret =dma_resv_wait_timeout_rcu (resv, true, interruptible, + lret =dma_resv_wait_timeout (resv, true, interruptible,30 *HZ );if (lret <0 )
@@ -411,7 +411,7 @@ static void ttm_bo_release(struct kref *kref)/* Last resort, if we fail to allocate memory for the * fences block for the BO to become idle */ -dma_resv_wait_timeout_rcu (bo->base.resv, true, false, +dma_resv_wait_timeout (bo->base.resv, true, false,30 *HZ ); }
@@ -422,7 +422,7 @@ static void ttm_bo_release(struct kref *kref)ttm_mem_io_free (bdev, bo->resource); } -if (!dma_resv_test_signaled_rcu (bo->base.resv, true) || +if (!dma_resv_test_signaled (bo->base.resv, true) || !dma_resv_trylock (bo->base.resv)) {/* The BO is not idle, resurrect it for delayed destroy */ ttm_bo_flush_all_fences (bo);
@@ -1121,13 +1121,13 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,long timeout =15 *HZ ;if (no_wait) { -if (dma_resv_test_signaled_rcu (bo->base.resv, true)) +if (dma_resv_test_signaled (bo->base.resv, true))return 0 ;else return -EBUSY ; } - timeout =dma_resv_wait_timeout_rcu (bo->base.resv, true, + timeout =dma_resv_wait_timeout (bo->base.resv, true, interruptible, timeout);if (timeout <0 )return timeout;
drivers/gpu/drm/vgem/vgem_fence.c +1 -1
@@ -151,7 +151,7 @@ int vgem_fence_attach_ioctl(struct drm_device *dev,/* Check for a conflicting fence */ resv = obj->resv; -if (!dma_resv_test_signaled_rcu (resv, +if (!dma_resv_test_signaled (resv, arg->flags &VGEM_FENCE_WRITE )) { ret = -EBUSY ; goto err_fence;
drivers/gpu/drm/virtio/virtgpu_ioctl.c +2 -2
@@ -451,9 +451,9 @@ static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,return -ENOENT ;if (args->flags &VIRTGPU_WAIT_NOWAIT ) { - ret =dma_resv_test_signaled_rcu (obj->resv, true); + ret =dma_resv_test_signaled (obj->resv, true); }else { - ret =dma_resv_wait_timeout_rcu (obj->resv, true, true, + ret =dma_resv_wait_timeout (obj->resv, true, true, timeout); }if (ret ==0 )
drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1 -1
@@ -743,7 +743,7 @@ static int vmw_user_bo_synccpu_grab(struct vmw_user_buffer_object *user_bo,if (flags & drm_vmw_synccpu_allow_cs) {long lret; - lret =dma_resv_wait_timeout_rcu + lret =dma_resv_wait_timeout (bo->base.resv, true, true, nonblock ?0 :MAX_SCHEDULE_TIMEOUT );if (!lret)
include/linux/dma-resv.h +5 -12
@@ -268,19 +268,12 @@ void dma_resv_init(struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences);void dma_resv_add_shared_fence (struct dma_resv *obj,struct dma_fence *fence); -void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence); - -int dma_resv_get_fences_rcu (struct dma_resv *obj, -struct dma_fence **pfence_excl, -unsigned *pshared_count, -struct dma_fence ***pshared); - +int dma_resv_get_fences (struct dma_resv *obj,struct dma_fence **pfence_excl, +unsigned *pshared_count,struct dma_fence ***pshared);int dma_resv_copy_fences (struct dma_resv *dst,struct dma_resv *src); - -long dma_resv_wait_timeout_rcu (struct dma_resv *obj,bool wait_all,bool intr, -unsigned long timeout); - -bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all); +long dma_resv_wait_timeout (struct dma_resv *obj,bool wait_all,bool intr, +unsigned long timeout); +bool dma_resv_test_signaled (struct dma_resv *obj,bool test_all);#endif /* _LINUX_RESERVATION_H */
Signature · 1 line
2.25.1
Re: [PATCH 7/7] dma-buf: drop the _rcu postfix on function names
Quoted 4 lines · Christian König
The functions can be called both in
_rcucontext as well as while holding the lock.Signed-off-by Christian König <[email protected]>
Please add to both functions some kerneldoc like "Callers are not required to hold specific locks, but maybe hold dma_resv_lock() already". Or something like that.
Btw on the mass changes only an ack because I'm too lazy to check whether you caught all the drivers myself, I'm trusting gcc and compile-checking on x86/arm/arm64 for this to be enough :-)
-Daniel
Quoted 646 lines
--- drivers/dma-buf/dma-buf.c | 3 +-- drivers/dma-buf/dma-resv.c | 24 +++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +++---- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- drivers/gpu/drm/drm_gem.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/dma_resv_utils.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 ++-- drivers/gpu/drm/i915/i915_request.c | 2 +- drivers/gpu/drm/i915/i915_sw_fence.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 2 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 2 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +- drivers/gpu/drm/radeon/radeon_gem.c | 6 ++--- drivers/gpu/drm/radeon/radeon_mn.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 12 +++++----- drivers/gpu/drm/vgem/vgem_fence.c | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 2 +- include/linux/dma-resv.h | 17 ++++--------- 31 files changed, 60 insertions(+), 70 deletions(-)drivers/dma-buf/dma-buf.c +1
-2@@ -1147,8 +1147,7 @@ static int __dma_buf_begin_cpu_access(struct dma_buf *dmabuf,long ret;/* Wait on any implicit rendering fences */ - ret =dma_resv_wait_timeout_rcu (resv, write, true, -MAX_SCHEDULE_TIMEOUT ); + ret =dma_resv_wait_timeout (resv, write, true,MAX_SCHEDULE_TIMEOUT );if (ret <0 )return ret;drivers/dma-buf/dma-resv.c +11
-13@@ -393,7 +393,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)EXPORT_SYMBOL (dma_resv_copy_fences);/** -* dma_resv_get_fences_rcu - Get an object's shared and exclusive +* dma_resv_get_fences - Get an object's shared and exclusive * fences without update side lock held * @obj: the reservation object * @pfence_excl: the returned exclusive fence (or NULL) @@ -405,10 +405,9 @@ EXPORT_SYMBOL(dma_resv_copy_fences);* exclusive fence is not specified the fence is put into the array of the * shared fences as well. Returns either zero or -ENOMEM. */ -int dma_resv_get_fences_rcu (struct dma_resv *obj, -struct dma_fence **pfence_excl, -unsigned int *pshared_count, -struct dma_fence ***pshared) +int dma_resv_get_fences (struct dma_resv *obj,struct dma_fence **pfence_excl, +unsigned int *pshared_count, +struct dma_fence ***pshared) {struct dma_fence **shared =NULL ;struct dma_fence *fence_excl;@@ -491,10 +490,10 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj, *pshared = shared;return ret; } -EXPORT_SYMBOL_GPL (dma_resv_get_fences_rcu); +EXPORT_SYMBOL_GPL (dma_resv_get_fences);/** -* dma_resv_wait_timeout_rcu - Wait on reservation's objects +* dma_resv_wait_timeout - Wait on reservation's objects * shared and/or exclusive fences. * @obj: the reservation object * @wait_all: if true, wait on all fences, else wait on just exclusive fence @@ -505,9 +504,8 @@ EXPORT_SYMBOL_GPL(dma_resv_get_fences_rcu);* Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or * greater than zer on success. */ -long dma_resv_wait_timeout_rcu (struct dma_resv *obj, -bool wait_all,bool intr, -unsigned long timeout) +long dma_resv_wait_timeout (struct dma_resv *obj,bool wait_all,bool intr, +unsigned long timeout) {long ret = timeout ? timeout :1 ;unsigned int seq, shared_count;@@ -579,7 +577,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,rcu_read_unlock (); goto retry; } -EXPORT_SYMBOL_GPL (dma_resv_wait_timeout_rcu); +EXPORT_SYMBOL_GPL (dma_resv_wait_timeout);static inline int dma_resv_test_signaled_single (struct dma_fence *passed_fence)@@ -608,7 +606,7 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)* RETURNS * true if all fences signaled, else false */ -bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all) +bool dma_resv_test_signaled (struct dma_resv *obj,bool test_all) {unsigned int seq, shared_count;int ret;@@ -657,7 +655,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)rcu_read_unlock ();return ret; } -EXPORT_SYMBOL_GPL (dma_resv_test_signaled_rcu); +EXPORT_SYMBOL_GPL (dma_resv_test_signaled);#if IS_ENABLED (CONFIG_LOCKDEP )static int __init dma_resv_lockdep (void )drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1
-1@@ -203,7 +203,7 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc, goto unpin; } - r =dma_resv_get_fences_rcu (new_abo->tbo.base.resv, &work->excl, + r =dma_resv_get_fences (new_abo->tbo.base.resv, &work->excl, &work->shared_count, &work->shared);if (unlikely (r !=0 )) {drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-1@@ -52,7 +52,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; - r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences); + r =dma_resv_get_fences (obj,NULL , &count, &fences);if (r)return r;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -526,7 +526,7 @@ int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,return -ENOENT ; } robj =gem_to_amdgpu_bo (gobj); - ret =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true, + ret =dma_resv_wait_timeout (robj->tbo.base.resv, true, true, timeout);/* ret == 0 means not signaled, drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +2
-2@@ -112,7 +112,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,unsigned count;int r; - r =dma_resv_get_fences_rcu (resv,NULL , &count, &fences); + r =dma_resv_get_fences (resv,NULL , &count, &fences);if (r) goto fallback;@@ -156,7 +156,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,/* Not enough memory for the delayed delete, as last resort * block for all the fences to complete. */ -dma_resv_wait_timeout_rcu (resv, true, false, +dma_resv_wait_timeout (resv, true, false,MAX_SCHEDULE_TIMEOUT );amdgpu_pasid_free (pasid); }drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +1
-1@@ -75,7 +75,7 @@ static bool amdgpu_mn_invalidate_gfx(struct mmu_interval_notifier *mni,mmu_interval_set_seq (mni, cur_seq); - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, true, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,MAX_SCHEDULE_TIMEOUT );mutex_unlock (&adev->notifier_lock);if (r <=0 )drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1@@ -756,7 +756,7 @@ int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)return 0 ; } - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, false, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, false, false,MAX_SCHEDULE_TIMEOUT );if (r <0 )return r;drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +1
-1@@ -1126,7 +1126,7 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, ib->length_dw =16 ;if (direct) { - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,msecs_to_jiffies (10 ));if (r ==0 )drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-4@@ -2022,13 +2022,13 @@ static void amdgpu_vm_prt_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)unsigned i, shared_count;int r; - r =dma_resv_get_fences_rcu (resv, &excl, + r =dma_resv_get_fences (resv, &excl, &shared_count, &shared);if (r) {/* Not enough memory to grab the fence list, as last resort * block for all the fences to complete. */ -dma_resv_wait_timeout_rcu (resv, true, false, +dma_resv_wait_timeout (resv, true, false,MAX_SCHEDULE_TIMEOUT );return ; }@@ -2640,7 +2640,7 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo)return true;/* Don't evict VM page tables while they are busy */ -if (!dma_resv_test_signaled_rcu (bo->tbo.base.resv, true)) +if (!dma_resv_test_signaled (bo->tbo.base.resv, true))return false;/* Try to block ongoing updates */ @@ -2820,7 +2820,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,*/ long amdgpu_vm_wait_idle (struct amdgpu_vm *vm,long timeout) { - timeout =dma_resv_wait_timeout_rcu (vm->root.base.bo->tbo.base.resv, + timeout =dma_resv_wait_timeout (vm->root.base.bo->tbo.base.resv, true, true, timeout);if (timeout <=0 )return timeout;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1
-1@@ -8400,7 +8400,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,* deadlock during GPU reset when this fence will not signal * but we hold reservation lock for the BO. */ - r =dma_resv_wait_timeout_rcu (abo->tbo.base.resv, true, + r =dma_resv_wait_timeout (abo->tbo.base.resv, true, false,msecs_to_jiffies (5000 ));if (unlikely (r <=0 ))drivers/gpu/drm/drm_gem.c +2
-2@@ -770,7 +770,7 @@ long drm_gem_dma_resv_wait(struct drm_file *filep, u32 handle,return -EINVAL ; } - ret =dma_resv_wait_timeout_rcu (obj->resv, wait_all, + ret =dma_resv_wait_timeout (obj->resv, wait_all, true, timeout);if (ret ==0 ) ret = -ETIME ;@@ -1380,7 +1380,7 @@ int drm_gem_fence_array_add_implicit(struct xarray *fence_array,return drm_gem_fence_array_add (fence_array, fence); } - ret =dma_resv_get_fences_rcu (obj->resv,NULL , + ret =dma_resv_get_fences (obj->resv,NULL , &fence_count, &fences);if (ret || !fence_count)return ret;drivers/gpu/drm/etnaviv/etnaviv_gem.c +2
-2@@ -390,13 +390,13 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op, }if (op &ETNA_PREP_NOSYNC ) { -if (!dma_resv_test_signaled_rcu (obj->resv, +if (!dma_resv_test_signaled (obj->resv, write))return -EBUSY ; }else {unsigned long remain =etnaviv_timeout_to_jiffies (timeout); - ret =dma_resv_wait_timeout_rcu (obj->resv, + ret =dma_resv_wait_timeout (obj->resv, write, true, remain);if (ret <=0 )return ret ==0 ? -ETIMEDOUT : ret;drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1
-1@@ -189,7 +189,7 @@ static int submit_fence_sync(struct etnaviv_gem_submit *submit)continue ;if (bo->flags &ETNA_SUBMIT_BO_WRITE ) { - ret =dma_resv_get_fences_rcu (robj, &bo->excl, + ret =dma_resv_get_fences (robj, &bo->excl, &bo->nr_shared, &bo->shared);if (ret)drivers/gpu/drm/i915/dma_resv_utils.c +1
-1@@ -10,7 +10,7 @@void dma_resv_prune (struct dma_resv *resv) {if (dma_resv_trylock (resv)) { -if (dma_resv_test_signaled_rcu (resv, true)) +if (dma_resv_test_signaled (resv, true))dma_resv_add_excl_fence (resv,NULL );dma_resv_unlock (resv); }drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-1@@ -105,7 +105,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,* Alternatively, we can trade that extra information on read/write * activity with * args->busy = -* !dma_resv_test_signaled_rcu(obj->resv, true); +* !dma_resv_test_signaled(obj->resv, true); * to report the overall busyness. This is what the wait-ioctl does. * */ drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-1@@ -1481,7 +1481,7 @@ static inline bool use_reloc_gpu(struct i915_vma *vma)if (DBG_FORCE_RELOC )return false; -return !dma_resv_test_signaled_rcu (vma->resv, true); +return !dma_resv_test_signaled (vma->resv, true); }static unsigned long vma_phys_addr (struct i915_vma *vma,u32 offset)drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1
-1@@ -85,7 +85,7 @@ static bool i915_gem_userptr_invalidate(struct mmu_interval_notifier *mni,return true;/* we will unbind on next submission, still have userptr pins */ - r =dma_resv_wait_timeout_rcu (obj->base.resv, true, false, + r =dma_resv_wait_timeout (obj->base.resv, true, false,MAX_SCHEDULE_TIMEOUT );if (r <=0 )drm_err (&i915->drm,"(%ld) failed to wait for idle\n" , r);drivers/gpu/drm/i915/gem/i915_gem_wait.c +2
-2@@ -45,7 +45,7 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,unsigned int count, i;int ret; - ret =dma_resv_get_fences_rcu (resv, &excl, &count, &shared); + ret =dma_resv_get_fences (resv, &excl, &count, &shared);if (ret)return ret;@@ -158,7 +158,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,unsigned int count, i;int ret; - ret =dma_resv_get_fences_rcu (obj->base.resv, + ret =dma_resv_get_fences (obj->base.resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/i915/i915_request.c +1
-1@@ -1594,7 +1594,7 @@ i915_request_await_object(struct i915_request *to,struct dma_fence **shared;unsigned int count, i; - ret =dma_resv_get_fences_rcu (obj->base.resv, + ret =dma_resv_get_fences (obj->base.resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/i915/i915_sw_fence.c +1
-1@@ -582,7 +582,7 @@ int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,struct dma_fence **shared;unsigned int count, i; - ret =dma_resv_get_fences_rcu (resv, &excl, &count, &shared); + ret =dma_resv_get_fences (resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/msm/msm_gem.c +1
-1@@ -915,7 +915,7 @@ int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout) op &MSM_PREP_NOSYNC ?0 :timeout_to_jiffies (timeout);long ret; - ret =dma_resv_wait_timeout_rcu (obj->resv, write, + ret =dma_resv_wait_timeout (obj->resv, write, true, remain);if (ret ==0 )return remain ==0 ? -EBUSY : -ETIMEDOUT ;drivers/gpu/drm/nouveau/nouveau_gem.c +1
-1@@ -964,7 +964,7 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,return -ENOENT ; nvbo =nouveau_gem_object (gem); - lret =dma_resv_wait_timeout_rcu (nvbo->bo.base.resv, write, true, + lret =dma_resv_wait_timeout (nvbo->bo.base.resv, write, true, no_wait ?0 :30 *HZ );if (!lret) ret = -EBUSY ;drivers/gpu/drm/panfrost/panfrost_drv.c +1
-1@@ -311,7 +311,7 @@ panfrost_ioctl_wait_bo(struct drm_device *dev, void *data,if (!gem_obj)return -ENOENT ; - ret =dma_resv_wait_timeout_rcu (gem_obj->resv, true, + ret =dma_resv_wait_timeout (gem_obj->resv, true, true, timeout);if (!ret) ret = timeout ? -ETIMEDOUT : -EBUSY ;drivers/gpu/drm/radeon/radeon_gem.c +3
-3@@ -161,7 +161,7 @@ static int radeon_gem_set_domain(struct drm_gem_object *gobj, }if (domain ==RADEON_GEM_DOMAIN_CPU ) {/* Asking for cpu access wait for object idle */ - r =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true,30 *HZ ); + r =dma_resv_wait_timeout (robj->tbo.base.resv, true, true,30 *HZ );if (!r) r = -EBUSY ;@@ -523,7 +523,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data, } robj =gem_to_radeon_bo (gobj); - r =dma_resv_test_signaled_rcu (robj->tbo.base.resv, true); + r =dma_resv_test_signaled (robj->tbo.base.resv, true);if (r ==0 ) r = -EBUSY ;else @@ -552,7 +552,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, } robj =gem_to_radeon_bo (gobj); - ret =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true,30 *HZ ); + ret =dma_resv_wait_timeout (robj->tbo.base.resv, true, true,30 *HZ );if (ret ==0 ) r = -EBUSY ;else if (ret <0 )drivers/gpu/drm/radeon/radeon_mn.c +1
-1@@ -66,7 +66,7 @@ static bool radeon_mn_invalidate(struct mmu_interval_notifier *mn,return true; } - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, true, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,MAX_SCHEDULE_TIMEOUT );if (r <=0 )DRM_ERROR ("(%ld) failed to wait for user bo\n" , r);drivers/gpu/drm/ttm/ttm_bo.c +6
-6@@ -296,7 +296,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,struct dma_resv *resv = &bo->base._resv;int ret; -if (dma_resv_test_signaled_rcu (resv, true)) +if (dma_resv_test_signaled (resv, true)) ret =0 ;else ret = -EBUSY ;@@ -308,7 +308,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,dma_resv_unlock (bo->base.resv);spin_unlock (&bo->bdev->lru_lock); - lret =dma_resv_wait_timeout_rcu (resv, true, interruptible, + lret =dma_resv_wait_timeout (resv, true, interruptible,30 *HZ );if (lret <0 )@@ -411,7 +411,7 @@ static void ttm_bo_release(struct kref *kref)/* Last resort, if we fail to allocate memory for the * fences block for the BO to become idle */ -dma_resv_wait_timeout_rcu (bo->base.resv, true, false, +dma_resv_wait_timeout (bo->base.resv, true, false,30 *HZ ); }@@ -422,7 +422,7 @@ static void ttm_bo_release(struct kref *kref)ttm_mem_io_free (bdev, bo->resource); } -if (!dma_resv_test_signaled_rcu (bo->base.resv, true) || +if (!dma_resv_test_signaled (bo->base.resv, true) || !dma_resv_trylock (bo->base.resv)) {/* The BO is not idle, resurrect it for delayed destroy */ ttm_bo_flush_all_fences (bo);@@ -1121,13 +1121,13 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,long timeout =15 *HZ ;if (no_wait) { -if (dma_resv_test_signaled_rcu (bo->base.resv, true)) +if (dma_resv_test_signaled (bo->base.resv, true))return 0 ;else return -EBUSY ; } - timeout =dma_resv_wait_timeout_rcu (bo->base.resv, true, + timeout =dma_resv_wait_timeout (bo->base.resv, true, interruptible, timeout);if (timeout <0 )return timeout;drivers/gpu/drm/vgem/vgem_fence.c +1
-1@@ -151,7 +151,7 @@ int vgem_fence_attach_ioctl(struct drm_device *dev,/* Check for a conflicting fence */ resv = obj->resv; -if (!dma_resv_test_signaled_rcu (resv, +if (!dma_resv_test_signaled (resv, arg->flags &VGEM_FENCE_WRITE )) { ret = -EBUSY ; goto err_fence;drivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-2@@ -451,9 +451,9 @@ static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,return -ENOENT ;if (args->flags &VIRTGPU_WAIT_NOWAIT ) { - ret =dma_resv_test_signaled_rcu (obj->resv, true); + ret =dma_resv_test_signaled (obj->resv, true); }else { - ret =dma_resv_wait_timeout_rcu (obj->resv, true, true, + ret =dma_resv_wait_timeout (obj->resv, true, true, timeout); }if (ret ==0 )drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1
-1@@ -743,7 +743,7 @@ static int vmw_user_bo_synccpu_grab(struct vmw_user_buffer_object *user_bo,if (flags & drm_vmw_synccpu_allow_cs) {long lret; - lret =dma_resv_wait_timeout_rcu + lret =dma_resv_wait_timeout (bo->base.resv, true, true, nonblock ?0 :MAX_SCHEDULE_TIMEOUT );if (!lret)include/linux/dma-resv.h +5
-12@@ -268,19 +268,12 @@ void dma_resv_init(struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences);void dma_resv_add_shared_fence (struct dma_resv *obj,struct dma_fence *fence); -void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence); - -int dma_resv_get_fences_rcu (struct dma_resv *obj, -struct dma_fence **pfence_excl, -unsigned *pshared_count, -struct dma_fence ***pshared); - +int dma_resv_get_fences (struct dma_resv *obj,struct dma_fence **pfence_excl, +unsigned *pshared_count,struct dma_fence ***pshared);int dma_resv_copy_fences (struct dma_resv *dst,struct dma_resv *src); - -long dma_resv_wait_timeout_rcu (struct dma_resv *obj,bool wait_all,bool intr, -unsigned long timeout); - -bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all); +long dma_resv_wait_timeout (struct dma_resv *obj,bool wait_all,bool intr, +unsigned long timeout); +bool dma_resv_test_signaled (struct dma_resv *obj,bool test_all);#endif /* _LINUX_RESERVATION_H */ Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 7/7] dma-buf: drop the _rcu postfix on function names
In reply to Christian KönigQuoted 224 lines · Christian König
The functions can be called both in
_rcucontext as well as while holding the lock.Signed-off-by Christian König <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 +-- drivers/dma-buf/dma-resv.c | 24 +++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +++---- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- drivers/gpu/drm/drm_gem.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/dma_resv_utils.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 ++-- drivers/gpu/drm/i915/i915_request.c | 2 +- drivers/gpu/drm/i915/i915_sw_fence.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 2 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 2 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +- drivers/gpu/drm/radeon/radeon_gem.c | 6 ++--- drivers/gpu/drm/radeon/radeon_mn.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 12 +++++----- drivers/gpu/drm/vgem/vgem_fence.c | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 2 +- include/linux/dma-resv.h | 17 ++++--------- 31 files changed, 60 insertions(+), 70 deletions(-)drivers/dma-buf/dma-buf.c +1
-2@@ -1147,8 +1147,7 @@ static int __dma_buf_begin_cpu_access(struct dma_buf *dmabuf,long ret;/* Wait on any implicit rendering fences */ - ret =dma_resv_wait_timeout_rcu (resv, write, true, -MAX_SCHEDULE_TIMEOUT ); + ret =dma_resv_wait_timeout (resv, write, true,MAX_SCHEDULE_TIMEOUT );if (ret <0 )return ret;drivers/dma-buf/dma-resv.c +11
-13@@ -393,7 +393,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)EXPORT_SYMBOL (dma_resv_copy_fences);/** -* dma_resv_get_fences_rcu - Get an object's shared and exclusive +* dma_resv_get_fences - Get an object's shared and exclusive * fences without update side lock held * @obj: the reservation object * @pfence_excl: the returned exclusive fence (or NULL) @@ -405,10 +405,9 @@ EXPORT_SYMBOL(dma_resv_copy_fences);* exclusive fence is not specified the fence is put into the array of the * shared fences as well. Returns either zero or -ENOMEM. */ -int dma_resv_get_fences_rcu (struct dma_resv *obj, -struct dma_fence **pfence_excl, -unsigned int *pshared_count, -struct dma_fence ***pshared) +int dma_resv_get_fences (struct dma_resv *obj,struct dma_fence **pfence_excl, +unsigned int *pshared_count, +struct dma_fence ***pshared) {struct dma_fence **shared =NULL ;struct dma_fence *fence_excl;@@ -491,10 +490,10 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj, *pshared = shared;return ret; } -EXPORT_SYMBOL_GPL (dma_resv_get_fences_rcu); +EXPORT_SYMBOL_GPL (dma_resv_get_fences);/** -* dma_resv_wait_timeout_rcu - Wait on reservation's objects +* dma_resv_wait_timeout - Wait on reservation's objects * shared and/or exclusive fences. * @obj: the reservation object * @wait_all: if true, wait on all fences, else wait on just exclusive fence @@ -505,9 +504,8 @@ EXPORT_SYMBOL_GPL(dma_resv_get_fences_rcu);* Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or * greater than zer on success. */ -long dma_resv_wait_timeout_rcu (struct dma_resv *obj, -bool wait_all,bool intr, -unsigned long timeout) +long dma_resv_wait_timeout (struct dma_resv *obj,bool wait_all,bool intr, +unsigned long timeout) {long ret = timeout ? timeout :1 ;unsigned int seq, shared_count;@@ -579,7 +577,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,rcu_read_unlock (); goto retry; } -EXPORT_SYMBOL_GPL (dma_resv_wait_timeout_rcu); +EXPORT_SYMBOL_GPL (dma_resv_wait_timeout);static inline int dma_resv_test_signaled_single (struct dma_fence *passed_fence)@@ -608,7 +606,7 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)* RETURNS * true if all fences signaled, else false */ -bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all) +bool dma_resv_test_signaled (struct dma_resv *obj,bool test_all) {unsigned int seq, shared_count;int ret;@@ -657,7 +655,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)rcu_read_unlock ();return ret; } -EXPORT_SYMBOL_GPL (dma_resv_test_signaled_rcu); +EXPORT_SYMBOL_GPL (dma_resv_test_signaled);#if IS_ENABLED (CONFIG_LOCKDEP )static int __init dma_resv_lockdep (void )drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1
-1@@ -203,7 +203,7 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc, goto unpin; } - r =dma_resv_get_fences_rcu (new_abo->tbo.base.resv, &work->excl, + r =dma_resv_get_fences (new_abo->tbo.base.resv, &work->excl, &work->shared_count, &work->shared);if (unlikely (r !=0 )) {drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-1@@ -52,7 +52,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; - r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences); + r =dma_resv_get_fences (obj,NULL , &count, &fences);if (r)return r;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -526,7 +526,7 @@ int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,return -ENOENT ; } robj =gem_to_amdgpu_bo (gobj); - ret =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true, + ret =dma_resv_wait_timeout (robj->tbo.base.resv, true, true, timeout);/* ret == 0 means not signaled, drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +2
-2@@ -112,7 +112,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,unsigned count;int r; - r =dma_resv_get_fences_rcu (resv,NULL , &count, &fences); + r =dma_resv_get_fences (resv,NULL , &count, &fences);if (r) goto fallback;@@ -156,7 +156,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,/* Not enough memory for the delayed delete, as last resort * block for all the fences to complete. */ -dma_resv_wait_timeout_rcu (resv, true, false, +dma_resv_wait_timeout (resv, true, false,MAX_SCHEDULE_TIMEOUT );amdgpu_pasid_free (pasid); }drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +1
-1@@ -75,7 +75,7 @@ static bool amdgpu_mn_invalidate_gfx(struct mmu_interval_notifier *mni,mmu_interval_set_seq (mni, cur_seq); - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, true, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,MAX_SCHEDULE_TIMEOUT );mutex_unlock (&adev->notifier_lock);if (r <=0 )drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1@@ -756,7 +756,7 @@ int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)return 0 ; } - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, false, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, false, false,MAX_SCHEDULE_TIMEOUT );if (r <0 )return r;drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, · line 1131
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +1
-1@@ -1126,7 +1126,7 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, ib->length_dw =16 ;if (direct) { - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,msecs_to_jiffies (10 ));
Some kernel CI thing (not sure who runs it) is likely going to complain at you about messing up indentation. I don't know how much you care. I went ahead and fixed it all in my version of this change but it's annoying and half of them were indented wrong before this change so I'm a bit Meh.
Either way, assuming you've done a grep for the _rcu versions to ensure you haven't missed any and assuming it all compiles,
Quoted 420 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +0
-0if (r ==0 )drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-4@@ -2022,13 +2022,13 @@ static void amdgpu_vm_prt_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)unsigned i, shared_count;int r; - r =dma_resv_get_fences_rcu (resv, &excl, + r =dma_resv_get_fences (resv, &excl, &shared_count, &shared);if (r) {/* Not enough memory to grab the fence list, as last resort * block for all the fences to complete. */ -dma_resv_wait_timeout_rcu (resv, true, false, +dma_resv_wait_timeout (resv, true, false,MAX_SCHEDULE_TIMEOUT );return ; }@@ -2640,7 +2640,7 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo)return true;/* Don't evict VM page tables while they are busy */ -if (!dma_resv_test_signaled_rcu (bo->tbo.base.resv, true)) +if (!dma_resv_test_signaled (bo->tbo.base.resv, true))return false;/* Try to block ongoing updates */ @@ -2820,7 +2820,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,*/ long amdgpu_vm_wait_idle (struct amdgpu_vm *vm,long timeout) { - timeout =dma_resv_wait_timeout_rcu (vm->root.base.bo->tbo.base.resv, + timeout =dma_resv_wait_timeout (vm->root.base.bo->tbo.base.resv, true, true, timeout);if (timeout <=0 )return timeout;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1
-1@@ -8400,7 +8400,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,* deadlock during GPU reset when this fence will not signal * but we hold reservation lock for the BO. */ - r =dma_resv_wait_timeout_rcu (abo->tbo.base.resv, true, + r =dma_resv_wait_timeout (abo->tbo.base.resv, true, false,msecs_to_jiffies (5000 ));if (unlikely (r <=0 ))drivers/gpu/drm/drm_gem.c +2
-2@@ -770,7 +770,7 @@ long drm_gem_dma_resv_wait(struct drm_file *filep, u32 handle,return -EINVAL ; } - ret =dma_resv_wait_timeout_rcu (obj->resv, wait_all, + ret =dma_resv_wait_timeout (obj->resv, wait_all, true, timeout);if (ret ==0 ) ret = -ETIME ;@@ -1380,7 +1380,7 @@ int drm_gem_fence_array_add_implicit(struct xarray *fence_array,return drm_gem_fence_array_add (fence_array, fence); } - ret =dma_resv_get_fences_rcu (obj->resv,NULL , + ret =dma_resv_get_fences (obj->resv,NULL , &fence_count, &fences);if (ret || !fence_count)return ret;drivers/gpu/drm/etnaviv/etnaviv_gem.c +2
-2@@ -390,13 +390,13 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op, }if (op &ETNA_PREP_NOSYNC ) { -if (!dma_resv_test_signaled_rcu (obj->resv, +if (!dma_resv_test_signaled (obj->resv, write))return -EBUSY ; }else {unsigned long remain =etnaviv_timeout_to_jiffies (timeout); - ret =dma_resv_wait_timeout_rcu (obj->resv, + ret =dma_resv_wait_timeout (obj->resv, write, true, remain);if (ret <=0 )return ret ==0 ? -ETIMEDOUT : ret;drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1
-1@@ -189,7 +189,7 @@ static int submit_fence_sync(struct etnaviv_gem_submit *submit)continue ;if (bo->flags &ETNA_SUBMIT_BO_WRITE ) { - ret =dma_resv_get_fences_rcu (robj, &bo->excl, + ret =dma_resv_get_fences (robj, &bo->excl, &bo->nr_shared, &bo->shared);if (ret)drivers/gpu/drm/i915/dma_resv_utils.c +1
-1@@ -10,7 +10,7 @@void dma_resv_prune (struct dma_resv *resv) {if (dma_resv_trylock (resv)) { -if (dma_resv_test_signaled_rcu (resv, true)) +if (dma_resv_test_signaled (resv, true))dma_resv_add_excl_fence (resv,NULL );dma_resv_unlock (resv); }drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-1@@ -105,7 +105,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,* Alternatively, we can trade that extra information on read/write * activity with * args->busy = -* !dma_resv_test_signaled_rcu(obj->resv, true); +* !dma_resv_test_signaled(obj->resv, true); * to report the overall busyness. This is what the wait-ioctl does. * */ drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-1@@ -1481,7 +1481,7 @@ static inline bool use_reloc_gpu(struct i915_vma *vma)if (DBG_FORCE_RELOC )return false; -return !dma_resv_test_signaled_rcu (vma->resv, true); +return !dma_resv_test_signaled (vma->resv, true); }static unsigned long vma_phys_addr (struct i915_vma *vma,u32 offset)drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1
-1@@ -85,7 +85,7 @@ static bool i915_gem_userptr_invalidate(struct mmu_interval_notifier *mni,return true;/* we will unbind on next submission, still have userptr pins */ - r =dma_resv_wait_timeout_rcu (obj->base.resv, true, false, + r =dma_resv_wait_timeout (obj->base.resv, true, false,MAX_SCHEDULE_TIMEOUT );if (r <=0 )drm_err (&i915->drm,"(%ld) failed to wait for idle\n" , r);drivers/gpu/drm/i915/gem/i915_gem_wait.c +2
-2@@ -45,7 +45,7 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,unsigned int count, i;int ret; - ret =dma_resv_get_fences_rcu (resv, &excl, &count, &shared); + ret =dma_resv_get_fences (resv, &excl, &count, &shared);if (ret)return ret;@@ -158,7 +158,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,unsigned int count, i;int ret; - ret =dma_resv_get_fences_rcu (obj->base.resv, + ret =dma_resv_get_fences (obj->base.resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/i915/i915_request.c +1
-1@@ -1594,7 +1594,7 @@ i915_request_await_object(struct i915_request *to,struct dma_fence **shared;unsigned int count, i; - ret =dma_resv_get_fences_rcu (obj->base.resv, + ret =dma_resv_get_fences (obj->base.resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/i915/i915_sw_fence.c +1
-1@@ -582,7 +582,7 @@ int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,struct dma_fence **shared;unsigned int count, i; - ret =dma_resv_get_fences_rcu (resv, &excl, &count, &shared); + ret =dma_resv_get_fences (resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/msm/msm_gem.c +1
-1@@ -915,7 +915,7 @@ int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout) op &MSM_PREP_NOSYNC ?0 :timeout_to_jiffies (timeout);long ret; - ret =dma_resv_wait_timeout_rcu (obj->resv, write, + ret =dma_resv_wait_timeout (obj->resv, write, true, remain);if (ret ==0 )return remain ==0 ? -EBUSY : -ETIMEDOUT ;drivers/gpu/drm/nouveau/nouveau_gem.c +1
-1@@ -964,7 +964,7 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,return -ENOENT ; nvbo =nouveau_gem_object (gem); - lret =dma_resv_wait_timeout_rcu (nvbo->bo.base.resv, write, true, + lret =dma_resv_wait_timeout (nvbo->bo.base.resv, write, true, no_wait ?0 :30 *HZ );if (!lret) ret = -EBUSY ;drivers/gpu/drm/panfrost/panfrost_drv.c +1
-1@@ -311,7 +311,7 @@ panfrost_ioctl_wait_bo(struct drm_device *dev, void *data,if (!gem_obj)return -ENOENT ; - ret =dma_resv_wait_timeout_rcu (gem_obj->resv, true, + ret =dma_resv_wait_timeout (gem_obj->resv, true, true, timeout);if (!ret) ret = timeout ? -ETIMEDOUT : -EBUSY ;drivers/gpu/drm/radeon/radeon_gem.c +3
-3@@ -161,7 +161,7 @@ static int radeon_gem_set_domain(struct drm_gem_object *gobj, }if (domain ==RADEON_GEM_DOMAIN_CPU ) {/* Asking for cpu access wait for object idle */ - r =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true,30 *HZ ); + r =dma_resv_wait_timeout (robj->tbo.base.resv, true, true,30 *HZ );if (!r) r = -EBUSY ;@@ -523,7 +523,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data, } robj =gem_to_radeon_bo (gobj); - r =dma_resv_test_signaled_rcu (robj->tbo.base.resv, true); + r =dma_resv_test_signaled (robj->tbo.base.resv, true);if (r ==0 ) r = -EBUSY ;else @@ -552,7 +552,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, } robj =gem_to_radeon_bo (gobj); - ret =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true,30 *HZ ); + ret =dma_resv_wait_timeout (robj->tbo.base.resv, true, true,30 *HZ );if (ret ==0 ) r = -EBUSY ;else if (ret <0 )drivers/gpu/drm/radeon/radeon_mn.c +1
-1@@ -66,7 +66,7 @@ static bool radeon_mn_invalidate(struct mmu_interval_notifier *mn,return true; } - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, true, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,MAX_SCHEDULE_TIMEOUT );if (r <=0 )DRM_ERROR ("(%ld) failed to wait for user bo\n" , r);drivers/gpu/drm/ttm/ttm_bo.c +6
-6@@ -296,7 +296,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,struct dma_resv *resv = &bo->base._resv;int ret; -if (dma_resv_test_signaled_rcu (resv, true)) +if (dma_resv_test_signaled (resv, true)) ret =0 ;else ret = -EBUSY ;@@ -308,7 +308,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,dma_resv_unlock (bo->base.resv);spin_unlock (&bo->bdev->lru_lock); - lret =dma_resv_wait_timeout_rcu (resv, true, interruptible, + lret =dma_resv_wait_timeout (resv, true, interruptible,30 *HZ );if (lret <0 )@@ -411,7 +411,7 @@ static void ttm_bo_release(struct kref *kref)/* Last resort, if we fail to allocate memory for the * fences block for the BO to become idle */ -dma_resv_wait_timeout_rcu (bo->base.resv, true, false, +dma_resv_wait_timeout (bo->base.resv, true, false,30 *HZ ); }@@ -422,7 +422,7 @@ static void ttm_bo_release(struct kref *kref)ttm_mem_io_free (bdev, bo->resource); } -if (!dma_resv_test_signaled_rcu (bo->base.resv, true) || +if (!dma_resv_test_signaled (bo->base.resv, true) || !dma_resv_trylock (bo->base.resv)) {/* The BO is not idle, resurrect it for delayed destroy */ ttm_bo_flush_all_fences (bo);@@ -1121,13 +1121,13 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,long timeout =15 *HZ ;if (no_wait) { -if (dma_resv_test_signaled_rcu (bo->base.resv, true)) +if (dma_resv_test_signaled (bo->base.resv, true))return 0 ;else return -EBUSY ; } - timeout =dma_resv_wait_timeout_rcu (bo->base.resv, true, + timeout =dma_resv_wait_timeout (bo->base.resv, true, interruptible, timeout);if (timeout <0 )return timeout;drivers/gpu/drm/vgem/vgem_fence.c +1
-1@@ -151,7 +151,7 @@ int vgem_fence_attach_ioctl(struct drm_device *dev,/* Check for a conflicting fence */ resv = obj->resv; -if (!dma_resv_test_signaled_rcu (resv, +if (!dma_resv_test_signaled (resv, arg->flags &VGEM_FENCE_WRITE )) { ret = -EBUSY ; goto err_fence;drivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-2@@ -451,9 +451,9 @@ static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,return -ENOENT ;if (args->flags &VIRTGPU_WAIT_NOWAIT ) { - ret =dma_resv_test_signaled_rcu (obj->resv, true); + ret =dma_resv_test_signaled (obj->resv, true); }else { - ret =dma_resv_wait_timeout_rcu (obj->resv, true, true, + ret =dma_resv_wait_timeout (obj->resv, true, true, timeout); }if (ret ==0 )drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1
-1@@ -743,7 +743,7 @@ static int vmw_user_bo_synccpu_grab(struct vmw_user_buffer_object *user_bo,if (flags & drm_vmw_synccpu_allow_cs) {long lret; - lret =dma_resv_wait_timeout_rcu + lret =dma_resv_wait_timeout (bo->base.resv, true, true, nonblock ?0 :MAX_SCHEDULE_TIMEOUT );if (!lret)include/linux/dma-resv.h +5
-13@@ -268,19 +268,12 @@ void dma_resv_init(struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences);void dma_resv_add_shared_fence (struct dma_resv *obj,struct dma_fence *fence); -void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence); - -int dma_resv_get_fences_rcu (struct dma_resv *obj, -struct dma_fence **pfence_excl, -unsigned *pshared_count, -struct dma_fence ***pshared); - +int dma_resv_get_fences (struct dma_resv *obj,struct dma_fence **pfence_excl, +unsigned *pshared_count,struct dma_fence ***pshared);int dma_resv_copy_fences (struct dma_resv *dst,struct dma_resv *src); - -long dma_resv_wait_timeout_rcu (struct dma_resv *obj,bool wait_all,bool intr, -unsigned long timeout); - -bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all); +long dma_resv_wait_timeout (struct dma_resv *obj,bool wait_all,bool intr, +unsigned long timeout); +bool dma_resv_test_signaled (struct dma_resv *obj,bool test_all);#endif /* _LINUX_RESERVATION_H */ --2.25.1
Re: [PATCH 7/7] dma-buf: drop the _rcu postfix on function names
Am 02.06.21 um 22:34 schrieb Jason Ekstrand:
Quoted 227 lines
Quoted 225 lines · Christian König
The functions can be called both in
_rcucontext as well as while holding the lock.Signed-off-by Christian König <[email protected]>--- drivers/dma-buf/dma-buf.c | 3 +-- drivers/dma-buf/dma-resv.c | 24 +++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +++---- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- drivers/gpu/drm/drm_gem.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/dma_resv_utils.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_busy.c | 2 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 ++-- drivers/gpu/drm/i915/i915_request.c | 2 +- drivers/gpu/drm/i915/i915_sw_fence.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 2 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 2 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 2 +- drivers/gpu/drm/radeon/radeon_gem.c | 6 ++--- drivers/gpu/drm/radeon/radeon_mn.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 12 +++++----- drivers/gpu/drm/vgem/vgem_fence.c | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_bo.c | 2 +- include/linux/dma-resv.h | 17 ++++--------- 31 files changed, 60 insertions(+), 70 deletions(-)drivers/dma-buf/dma-buf.c +1
-2@@ -1147,8 +1147,7 @@ static int __dma_buf_begin_cpu_access(struct dma_buf *dmabuf,long ret;/* Wait on any implicit rendering fences */ - ret =dma_resv_wait_timeout_rcu (resv, write, true, -MAX_SCHEDULE_TIMEOUT ); + ret =dma_resv_wait_timeout (resv, write, true,MAX_SCHEDULE_TIMEOUT );if (ret <0 )return ret;drivers/dma-buf/dma-resv.c +11
-13@@ -393,7 +393,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)EXPORT_SYMBOL (dma_resv_copy_fences);/** -* dma_resv_get_fences_rcu - Get an object's shared and exclusive +* dma_resv_get_fences - Get an object's shared and exclusive * fences without update side lock held * @obj: the reservation object * @pfence_excl: the returned exclusive fence (or NULL) @@ -405,10 +405,9 @@ EXPORT_SYMBOL(dma_resv_copy_fences);* exclusive fence is not specified the fence is put into the array of the * shared fences as well. Returns either zero or -ENOMEM. */ -int dma_resv_get_fences_rcu (struct dma_resv *obj, -struct dma_fence **pfence_excl, -unsigned int *pshared_count, -struct dma_fence ***pshared) +int dma_resv_get_fences (struct dma_resv *obj,struct dma_fence **pfence_excl, +unsigned int *pshared_count, +struct dma_fence ***pshared) {struct dma_fence **shared =NULL ;struct dma_fence *fence_excl;@@ -491,10 +490,10 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj, *pshared = shared;return ret; } -EXPORT_SYMBOL_GPL (dma_resv_get_fences_rcu); +EXPORT_SYMBOL_GPL (dma_resv_get_fences);/** -* dma_resv_wait_timeout_rcu - Wait on reservation's objects +* dma_resv_wait_timeout - Wait on reservation's objects * shared and/or exclusive fences. * @obj: the reservation object * @wait_all: if true, wait on all fences, else wait on just exclusive fence @@ -505,9 +504,8 @@ EXPORT_SYMBOL_GPL(dma_resv_get_fences_rcu);* Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or * greater than zer on success. */ -long dma_resv_wait_timeout_rcu (struct dma_resv *obj, -bool wait_all,bool intr, -unsigned long timeout) +long dma_resv_wait_timeout (struct dma_resv *obj,bool wait_all,bool intr, +unsigned long timeout) {long ret = timeout ? timeout :1 ;unsigned int seq, shared_count;@@ -579,7 +577,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,rcu_read_unlock (); goto retry; } -EXPORT_SYMBOL_GPL (dma_resv_wait_timeout_rcu); +EXPORT_SYMBOL_GPL (dma_resv_wait_timeout);static inline int dma_resv_test_signaled_single (struct dma_fence *passed_fence)@@ -608,7 +606,7 @@ static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)* RETURNS * true if all fences signaled, else false */ -bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all) +bool dma_resv_test_signaled (struct dma_resv *obj,bool test_all) {unsigned int seq, shared_count;int ret;@@ -657,7 +655,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)rcu_read_unlock ();return ret; } -EXPORT_SYMBOL_GPL (dma_resv_test_signaled_rcu); +EXPORT_SYMBOL_GPL (dma_resv_test_signaled);#if IS_ENABLED (CONFIG_LOCKDEP )static int __init dma_resv_lockdep (void )drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1
-1@@ -203,7 +203,7 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc, goto unpin; } - r =dma_resv_get_fences_rcu (new_abo->tbo.base.resv, &work->excl, + r =dma_resv_get_fences (new_abo->tbo.base.resv, &work->excl, &work->shared_count, &work->shared);if (unlikely (r !=0 )) {drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-1@@ -52,7 +52,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)if (!dma_resv_shared (obj))/* no shared fences to convert */ return 0 ; - r =dma_resv_get_fences_rcu (obj,NULL , &count, &fences); + r =dma_resv_get_fences (obj,NULL , &count, &fences);if (r)return r;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -526,7 +526,7 @@ int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,return -ENOENT ; } robj =gem_to_amdgpu_bo (gobj); - ret =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true, + ret =dma_resv_wait_timeout (robj->tbo.base.resv, true, true, timeout);/* ret == 0 means not signaled, drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +2
-2@@ -112,7 +112,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,unsigned count;int r; - r =dma_resv_get_fences_rcu (resv,NULL , &count, &fences); + r =dma_resv_get_fences (resv,NULL , &count, &fences);if (r) goto fallback;@@ -156,7 +156,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,/* Not enough memory for the delayed delete, as last resort * block for all the fences to complete. */ -dma_resv_wait_timeout_rcu (resv, true, false, +dma_resv_wait_timeout (resv, true, false,MAX_SCHEDULE_TIMEOUT );amdgpu_pasid_free (pasid); }drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +1
-1@@ -75,7 +75,7 @@ static bool amdgpu_mn_invalidate_gfx(struct mmu_interval_notifier *mni,mmu_interval_set_seq (mni, cur_seq); - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, true, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,MAX_SCHEDULE_TIMEOUT );mutex_unlock (&adev->notifier_lock);if (r <=0 )drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1@@ -756,7 +756,7 @@ int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)return 0 ; } - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, false, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, false, false,MAX_SCHEDULE_TIMEOUT );if (r <0 )return r;drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +0
-0@@ -1126,7 +1126,7 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, ib->length_dw =16 ;
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, · line 1131
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +1
-1if (direct) { - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,msecs_to_jiffies (10 ));Some kernel CI thing (not sure who runs it) is likely going to complain at you about messing up indentation. I don't know how much you care. I went ahead and fixed it all in my version of this change but it's annoying and half of them were indented wrong before this change so I'm a bit Meh.
Yeah, we messed those up in the reservation_object -> dma_resv rename already.
I've just gone over them and fixed the indentation halve automated once more.
Quoted 2 lines
Either way, assuming you've done a grep for the
_rcuversions to ensure you haven't missed any and assuming it all compiles,
That was a completely automated rename anyway. Could be that I didn't catch all the subdirs where dma_resv object is used, but that is rather unlikely.
Quoted 1 line
Reviewed-by Jason Ekstrand <[email protected]>
Thanks going to push that now,
Christian.
Quoted 421 lines
Quoted 421 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +0
-0if (r ==0 )drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-4@@ -2022,13 +2022,13 @@ static void amdgpu_vm_prt_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)unsigned i, shared_count;int r; - r =dma_resv_get_fences_rcu (resv, &excl, + r =dma_resv_get_fences (resv, &excl, &shared_count, &shared);if (r) {/* Not enough memory to grab the fence list, as last resort * block for all the fences to complete. */ -dma_resv_wait_timeout_rcu (resv, true, false, +dma_resv_wait_timeout (resv, true, false,MAX_SCHEDULE_TIMEOUT );return ; }@@ -2640,7 +2640,7 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo)return true;/* Don't evict VM page tables while they are busy */ -if (!dma_resv_test_signaled_rcu (bo->tbo.base.resv, true)) +if (!dma_resv_test_signaled (bo->tbo.base.resv, true))return false;/* Try to block ongoing updates */ @@ -2820,7 +2820,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,*/ long amdgpu_vm_wait_idle (struct amdgpu_vm *vm,long timeout) { - timeout =dma_resv_wait_timeout_rcu (vm->root.base.bo->tbo.base.resv, + timeout =dma_resv_wait_timeout (vm->root.base.bo->tbo.base.resv, true, true, timeout);if (timeout <=0 )return timeout;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1
-1@@ -8400,7 +8400,7 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,* deadlock during GPU reset when this fence will not signal * but we hold reservation lock for the BO. */ - r =dma_resv_wait_timeout_rcu (abo->tbo.base.resv, true, + r =dma_resv_wait_timeout (abo->tbo.base.resv, true, false,msecs_to_jiffies (5000 ));if (unlikely (r <=0 ))drivers/gpu/drm/drm_gem.c +2
-2@@ -770,7 +770,7 @@ long drm_gem_dma_resv_wait(struct drm_file *filep, u32 handle,return -EINVAL ; } - ret =dma_resv_wait_timeout_rcu (obj->resv, wait_all, + ret =dma_resv_wait_timeout (obj->resv, wait_all, true, timeout);if (ret ==0 ) ret = -ETIME ;@@ -1380,7 +1380,7 @@ int drm_gem_fence_array_add_implicit(struct xarray *fence_array,return drm_gem_fence_array_add (fence_array, fence); } - ret =dma_resv_get_fences_rcu (obj->resv,NULL , + ret =dma_resv_get_fences (obj->resv,NULL , &fence_count, &fences);if (ret || !fence_count)return ret;drivers/gpu/drm/etnaviv/etnaviv_gem.c +2
-2@@ -390,13 +390,13 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op, }if (op &ETNA_PREP_NOSYNC ) { -if (!dma_resv_test_signaled_rcu (obj->resv, +if (!dma_resv_test_signaled (obj->resv, write))return -EBUSY ; }else {unsigned long remain =etnaviv_timeout_to_jiffies (timeout); - ret =dma_resv_wait_timeout_rcu (obj->resv, + ret =dma_resv_wait_timeout (obj->resv, write, true, remain);if (ret <=0 )return ret ==0 ? -ETIMEDOUT : ret;drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1
-1@@ -189,7 +189,7 @@ static int submit_fence_sync(struct etnaviv_gem_submit *submit)continue ;if (bo->flags &ETNA_SUBMIT_BO_WRITE ) { - ret =dma_resv_get_fences_rcu (robj, &bo->excl, + ret =dma_resv_get_fences (robj, &bo->excl, &bo->nr_shared, &bo->shared);if (ret)drivers/gpu/drm/i915/dma_resv_utils.c +1
-1@@ -10,7 +10,7 @@void dma_resv_prune (struct dma_resv *resv) {if (dma_resv_trylock (resv)) { -if (dma_resv_test_signaled_rcu (resv, true)) +if (dma_resv_test_signaled (resv, true))dma_resv_add_excl_fence (resv,NULL );dma_resv_unlock (resv); }drivers/gpu/drm/i915/gem/i915_gem_busy.c +1
-1@@ -105,7 +105,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,* Alternatively, we can trade that extra information on read/write * activity with * args->busy = -* !dma_resv_test_signaled_rcu(obj->resv, true); +* !dma_resv_test_signaled(obj->resv, true); * to report the overall busyness. This is what the wait-ioctl does. * */ drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +1
-1@@ -1481,7 +1481,7 @@ static inline bool use_reloc_gpu(struct i915_vma *vma)if (DBG_FORCE_RELOC )return false; -return !dma_resv_test_signaled_rcu (vma->resv, true); +return !dma_resv_test_signaled (vma->resv, true); }static unsigned long vma_phys_addr (struct i915_vma *vma,u32 offset)drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1
-1@@ -85,7 +85,7 @@ static bool i915_gem_userptr_invalidate(struct mmu_interval_notifier *mni,return true;/* we will unbind on next submission, still have userptr pins */ - r =dma_resv_wait_timeout_rcu (obj->base.resv, true, false, + r =dma_resv_wait_timeout (obj->base.resv, true, false,MAX_SCHEDULE_TIMEOUT );if (r <=0 )drm_err (&i915->drm,"(%ld) failed to wait for idle\n" , r);drivers/gpu/drm/i915/gem/i915_gem_wait.c +2
-2@@ -45,7 +45,7 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,unsigned int count, i;int ret; - ret =dma_resv_get_fences_rcu (resv, &excl, &count, &shared); + ret =dma_resv_get_fences (resv, &excl, &count, &shared);if (ret)return ret;@@ -158,7 +158,7 @@ i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,unsigned int count, i;int ret; - ret =dma_resv_get_fences_rcu (obj->base.resv, + ret =dma_resv_get_fences (obj->base.resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/i915/i915_request.c +1
-1@@ -1594,7 +1594,7 @@ i915_request_await_object(struct i915_request *to,struct dma_fence **shared;unsigned int count, i; - ret =dma_resv_get_fences_rcu (obj->base.resv, + ret =dma_resv_get_fences (obj->base.resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/i915/i915_sw_fence.c +1
-1@@ -582,7 +582,7 @@ int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,struct dma_fence **shared;unsigned int count, i; - ret =dma_resv_get_fences_rcu (resv, &excl, &count, &shared); + ret =dma_resv_get_fences (resv, &excl, &count, &shared);if (ret)return ret;drivers/gpu/drm/msm/msm_gem.c +1
-1@@ -915,7 +915,7 @@ int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout) op &MSM_PREP_NOSYNC ?0 :timeout_to_jiffies (timeout);long ret; - ret =dma_resv_wait_timeout_rcu (obj->resv, write, + ret =dma_resv_wait_timeout (obj->resv, write, true, remain);if (ret ==0 )return remain ==0 ? -EBUSY : -ETIMEDOUT ;drivers/gpu/drm/nouveau/nouveau_gem.c +1
-1@@ -964,7 +964,7 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,return -ENOENT ; nvbo =nouveau_gem_object (gem); - lret =dma_resv_wait_timeout_rcu (nvbo->bo.base.resv, write, true, + lret =dma_resv_wait_timeout (nvbo->bo.base.resv, write, true, no_wait ?0 :30 *HZ );if (!lret) ret = -EBUSY ;drivers/gpu/drm/panfrost/panfrost_drv.c +1
-1@@ -311,7 +311,7 @@ panfrost_ioctl_wait_bo(struct drm_device *dev, void *data,if (!gem_obj)return -ENOENT ; - ret =dma_resv_wait_timeout_rcu (gem_obj->resv, true, + ret =dma_resv_wait_timeout (gem_obj->resv, true, true, timeout);if (!ret) ret = timeout ? -ETIMEDOUT : -EBUSY ;drivers/gpu/drm/radeon/radeon_gem.c +3
-3@@ -161,7 +161,7 @@ static int radeon_gem_set_domain(struct drm_gem_object *gobj, }if (domain ==RADEON_GEM_DOMAIN_CPU ) {/* Asking for cpu access wait for object idle */ - r =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true,30 *HZ ); + r =dma_resv_wait_timeout (robj->tbo.base.resv, true, true,30 *HZ );if (!r) r = -EBUSY ;@@ -523,7 +523,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data, } robj =gem_to_radeon_bo (gobj); - r =dma_resv_test_signaled_rcu (robj->tbo.base.resv, true); + r =dma_resv_test_signaled (robj->tbo.base.resv, true);if (r ==0 ) r = -EBUSY ;else @@ -552,7 +552,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, } robj =gem_to_radeon_bo (gobj); - ret =dma_resv_wait_timeout_rcu (robj->tbo.base.resv, true, true,30 *HZ ); + ret =dma_resv_wait_timeout (robj->tbo.base.resv, true, true,30 *HZ );if (ret ==0 ) r = -EBUSY ;else if (ret <0 )drivers/gpu/drm/radeon/radeon_mn.c +1
-1@@ -66,7 +66,7 @@ static bool radeon_mn_invalidate(struct mmu_interval_notifier *mn,return true; } - r =dma_resv_wait_timeout_rcu (bo->tbo.base.resv, true, false, + r =dma_resv_wait_timeout (bo->tbo.base.resv, true, false,MAX_SCHEDULE_TIMEOUT );if (r <=0 )DRM_ERROR ("(%ld) failed to wait for user bo\n" , r);drivers/gpu/drm/ttm/ttm_bo.c +6
-6@@ -296,7 +296,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,struct dma_resv *resv = &bo->base._resv;int ret; -if (dma_resv_test_signaled_rcu (resv, true)) +if (dma_resv_test_signaled (resv, true)) ret =0 ;else ret = -EBUSY ;@@ -308,7 +308,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,dma_resv_unlock (bo->base.resv);spin_unlock (&bo->bdev->lru_lock); - lret =dma_resv_wait_timeout_rcu (resv, true, interruptible, + lret =dma_resv_wait_timeout (resv, true, interruptible,30 *HZ );if (lret <0 )@@ -411,7 +411,7 @@ static void ttm_bo_release(struct kref *kref)/* Last resort, if we fail to allocate memory for the * fences block for the BO to become idle */ -dma_resv_wait_timeout_rcu (bo->base.resv, true, false, +dma_resv_wait_timeout (bo->base.resv, true, false,30 *HZ ); }@@ -422,7 +422,7 @@ static void ttm_bo_release(struct kref *kref)ttm_mem_io_free (bdev, bo->resource); } -if (!dma_resv_test_signaled_rcu (bo->base.resv, true) || +if (!dma_resv_test_signaled (bo->base.resv, true) || !dma_resv_trylock (bo->base.resv)) {/* The BO is not idle, resurrect it for delayed destroy */ ttm_bo_flush_all_fences (bo);@@ -1121,13 +1121,13 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,long timeout =15 *HZ ;if (no_wait) { -if (dma_resv_test_signaled_rcu (bo->base.resv, true)) +if (dma_resv_test_signaled (bo->base.resv, true))return 0 ;else return -EBUSY ; } - timeout =dma_resv_wait_timeout_rcu (bo->base.resv, true, + timeout =dma_resv_wait_timeout (bo->base.resv, true, interruptible, timeout);if (timeout <0 )return timeout;drivers/gpu/drm/vgem/vgem_fence.c +1
-1@@ -151,7 +151,7 @@ int vgem_fence_attach_ioctl(struct drm_device *dev,/* Check for a conflicting fence */ resv = obj->resv; -if (!dma_resv_test_signaled_rcu (resv, +if (!dma_resv_test_signaled (resv, arg->flags &VGEM_FENCE_WRITE )) { ret = -EBUSY ; goto err_fence;drivers/gpu/drm/virtio/virtgpu_ioctl.c +2
-2@@ -451,9 +451,9 @@ static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,return -ENOENT ;if (args->flags &VIRTGPU_WAIT_NOWAIT ) { - ret =dma_resv_test_signaled_rcu (obj->resv, true); + ret =dma_resv_test_signaled (obj->resv, true); }else { - ret =dma_resv_wait_timeout_rcu (obj->resv, true, true, + ret =dma_resv_wait_timeout (obj->resv, true, true, timeout); }if (ret ==0 )drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +1
-1@@ -743,7 +743,7 @@ static int vmw_user_bo_synccpu_grab(struct vmw_user_buffer_object *user_bo,if (flags & drm_vmw_synccpu_allow_cs) {long lret; - lret =dma_resv_wait_timeout_rcu + lret =dma_resv_wait_timeout (bo->base.resv, true, true, nonblock ?0 :MAX_SCHEDULE_TIMEOUT );if (!lret)include/linux/dma-resv.h +5
-13@@ -268,19 +268,12 @@ void dma_resv_init(struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj);int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences);void dma_resv_add_shared_fence (struct dma_resv *obj,struct dma_fence *fence); -void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence); - -int dma_resv_get_fences_rcu (struct dma_resv *obj, -struct dma_fence **pfence_excl, -unsigned *pshared_count, -struct dma_fence ***pshared); - +int dma_resv_get_fences (struct dma_resv *obj,struct dma_fence **pfence_excl, +unsigned *pshared_count,struct dma_fence ***pshared);int dma_resv_copy_fences (struct dma_resv *dst,struct dma_resv *src); - -long dma_resv_wait_timeout_rcu (struct dma_resv *obj,bool wait_all,bool intr, -unsigned long timeout); - -bool dma_resv_test_signaled_rcu (struct dma_resv *obj,bool test_all); +long dma_resv_wait_timeout (struct dma_resv *obj,bool wait_all,bool intr, +unsigned long timeout); +bool dma_resv_test_signaled (struct dma_resv *obj,bool test_all);#endif /* _LINUX_RESERVATION_H */ --2.25.1
Quoted 6 lines · Christian König
The code tries to acquire the rcu protected fence list, but then ignores individual fences which have been modified while holding the rcu.
Stop that madness and just note cleanly that the list was concurrently modified.
Signed-off-by Christian König <[email protected]>
Yeah it's debugfs, it's better not to be fancy here and if you race you can just re-grab it all.
What's worse, we do grab the dma_resv_lock, which means no one should be able to race with us. I think 100% right thing here is actually to drop the rcu_read_lock too, and switch over to rcu_dereference_protected().
And also drop the seqcount check, that would be a bug. seqcount is only to get a consistent snapshot of all fences on the read (i.e. protected by rcu only) section. We hold the write lock with dma_resv_lock here.
Cheers, Daniel
Quoted 49 lines
--- drivers/dma-buf/dma-buf.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/dma-buf/dma-buf.c +8
-11@@ -1383,22 +1383,17 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) buf_obj->name ?: ""); robj = buf_obj->resv; -while (true) { - seq =read_seqcount_begin (&robj->seq); -rcu_read_lock (); - fobj =rcu_dereference (robj->fence); - shared_count = fobj ? fobj->shared_count :0 ; - fence =rcu_dereference (robj->fence_excl); -if (!read_seqcount_retry (&robj->seq, seq)) -break ; -rcu_read_unlock (); - } - + seq =read_seqcount_begin (&robj->seq); +rcu_read_lock (); + fence =rcu_dereference (robj->fence_excl);if (fence)seq_printf (s,"\tExclusive fence: %s %s %ssignalled\n" , fence->ops->get_driver_name (fence), fence->ops->get_timeline_name (fence),dma_fence_is_signaled (fence) ?"" :"un" ); + + fobj =rcu_dereference (robj->fence); + shared_count = fobj ? fobj->shared_count :0 ;for (i =0 ; i < shared_count; i++) { fence =rcu_dereference (fobj->shared[i]);if (!dma_fence_get_rcu (fence))@@ -1410,6 +1405,8 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)dma_fence_put (fence); }rcu_read_unlock (); +if (read_seqcount_retry (&robj->seq, seq)) +seq_printf (s,"\tFences concurrently modified\n" );seq_puts (s,"\tAttached Devices:\n" ); attach_count =0 ;Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Am 02.06.21 um 14:33 schrieb Daniel Vetter:
Quoted 10 lines · Christian König
Quoted 6 lines
The code tries to acquire the rcu protected fence list, but then ignores individual fences which have been modified while holding the rcu.
Stop that madness and just note cleanly that the list was concurrently modified.
Signed-off-by Christian König <[email protected]>Yeah it's debugfs, it's better not to be fancy here and if you race you can just re-grab it all.
Quoted 7 lines
What's worse, we do grab the
dma_resv_lock, which means no one should be able to race with us. I think 100% right thing here is actually to drop thercu_read_locktoo, and switch over torcu_dereference_protected().And also drop the seqcount check, that would be a bug. seqcount is only to get a consistent snapshot of all fences on the read (i.e. protected by rcu only) section. We hold the write lock with
dma_resv_lockhere.
Yes that what I had in mind as alternative as well.
Just wasn't 100% sure which way to go here.
Going to adjust that,
Christian.
Quoted 52 lines
Cheers, Daniel
Quoted 49 lines
--- drivers/dma-buf/dma-buf.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/dma-buf/dma-buf.c +8
-11@@ -1383,22 +1383,17 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) buf_obj->name ?: ""); robj = buf_obj->resv; -while (true) { - seq =read_seqcount_begin (&robj->seq); -rcu_read_lock (); - fobj =rcu_dereference (robj->fence); - shared_count = fobj ? fobj->shared_count :0 ; - fence =rcu_dereference (robj->fence_excl); -if (!read_seqcount_retry (&robj->seq, seq)) -break ; -rcu_read_unlock (); - } - + seq =read_seqcount_begin (&robj->seq); +rcu_read_lock (); + fence =rcu_dereference (robj->fence_excl);if (fence)seq_printf (s,"\tExclusive fence: %s %s %ssignalled\n" , fence->ops->get_driver_name (fence), fence->ops->get_timeline_name (fence),dma_fence_is_signaled (fence) ?"" :"un" ); + + fobj =rcu_dereference (robj->fence); + shared_count = fobj ? fobj->shared_count :0 ;for (i =0 ; i < shared_count; i++) { fence =rcu_dereference (fobj->shared[i]);if (!dma_fence_get_rcu (fence))@@ -1410,6 +1405,8 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)dma_fence_put (fence); }rcu_read_unlock (); +if (read_seqcount_retry (&robj->seq, seq)) +seq_printf (s,"\tFences concurrently modified\n" );seq_puts (s,"\tAttached Devices:\n" ); attach_count =0 ;Signature · 1 line
2.25.1
Quoted 17 lines · Christian König
Am 02.06.21 um 14:33 schrieb Daniel Vetter:
Quoted 14 lines · Christian König
Quoted 6 lines
The code tries to acquire the rcu protected fence list, but then ignores individual fences which have been modified while holding the rcu.
Stop that madness and just note cleanly that the list was concurrently modified.
Signed-off-by Christian König <[email protected]>Yeah it's debugfs, it's better not to be fancy here and if you race you can just re-grab it all.
What's worse, we do grab the
dma_resv_lock, which means no one should be able to race with us. I think 100% right thing here is actually to drop thercu_read_locktoo, and switch over torcu_dereference_protected().
Quoted 7 lines
Quoted 3 lines
And also drop the seqcount check, that would be a bug. seqcount is only to get a consistent snapshot of all fences on the read (i.e. protected by rcu only) section. We hold the write lock with
dma_resv_lockhere.Yes that what I had in mind as alternative as well.
Just wasn't 100% sure which way to go here.
I think for paranoia we could read the seqcount and do a WARN_ON if it ever increments while we hold dma_resv_lock ourselves. But I think this one here is the only one where this applies, and it's debugfs only, so meh?
-Daniel
Quoted 54 lines
Going to adjust that,
Christian.Quoted 50 lines
Cheers, Daniel
Quoted 47 lines
--- drivers/dma-buf/dma-buf.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/dma-buf/dma-buf.c +8
-11@@ -1383,22 +1383,17 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) buf_obj->name ?: ""); robj = buf_obj->resv; -while (true) { - seq =read_seqcount_begin (&robj->seq); -rcu_read_lock (); - fobj =rcu_dereference (robj->fence); - shared_count = fobj ? fobj->shared_count :0 ; - fence =rcu_dereference (robj->fence_excl); -if (!read_seqcount_retry (&robj->seq, seq)) -break ; -rcu_read_unlock (); - } - + seq =read_seqcount_begin (&robj->seq); +rcu_read_lock (); + fence =rcu_dereference (robj->fence_excl);if (fence)seq_printf (s,"\tExclusive fence: %s %s %ssignalled\n" , fence->ops->get_driver_name (fence), fence->ops->get_timeline_name (fence),dma_fence_is_signaled (fence) ?"" :"un" ); + + fobj =rcu_dereference (robj->fence); + shared_count = fobj ? fobj->shared_count :0 ;for (i =0 ; i < shared_count; i++) { fence =rcu_dereference (fobj->shared[i]);if (!dma_fence_get_rcu (fence))@@ -1410,6 +1405,8 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)dma_fence_put (fence); }rcu_read_unlock (); +if (read_seqcount_retry (&robj->seq, seq)) +seq_printf (s,"\tFences concurrently modified\n" );seq_puts (s,"\tAttached Devices:\n" ); attach_count =0 ;Signature · 1 line
2.25.1
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch