Skip to content

Commit fb5ce73

Browse files
dma-buf: rename and cleanup dma_resv_get_list v2
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. v2: use dma_resv_shared_list as new name Signed-off-by: Christian König <[email protected]> Acked-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 6edbd6a commit fb5ce73

File tree

13 files changed

+41
-42
lines changed

13 files changed

+41
-42
lines changed

drivers/dma-buf/dma-resv.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)
149149

150150
dma_resv_assert_held(obj);
151151

152-
old = dma_resv_get_list(obj);
153-
152+
old = dma_resv_shared_list(obj);
154153
if (old && old->shared_max) {
155154
if ((old->shared_count + num_fences) <= old->shared_max)
156155
return 0;
@@ -219,12 +218,13 @@ EXPORT_SYMBOL(dma_resv_reserve_shared);
219218
*/
220219
void dma_resv_reset_shared_max(struct dma_resv *obj)
221220
{
222-
/* Test shared fence slot reservation */
223-
if (rcu_access_pointer(obj->fence)) {
224-
struct dma_resv_list *fence = dma_resv_get_list(obj);
221+
struct dma_resv_list *fences = dma_resv_shared_list(obj);
225222

226-
fence->shared_max = fence->shared_count;
227-
}
223+
dma_resv_assert_held(obj);
224+
225+
/* Test shared fence slot reservation */
226+
if (fences)
227+
fences->shared_max = fences->shared_count;
228228
}
229229
EXPORT_SYMBOL(dma_resv_reset_shared_max);
230230
#endif
@@ -247,7 +247,7 @@ void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence)
247247

248248
dma_resv_assert_held(obj);
249249

250-
fobj = dma_resv_get_list(obj);
250+
fobj = dma_resv_shared_list(obj);
251251
count = fobj->shared_count;
252252

253253
write_seqcount_begin(&obj->seq);
@@ -290,7 +290,7 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)
290290

291291
dma_resv_assert_held(obj);
292292

293-
old = dma_resv_get_list(obj);
293+
old = dma_resv_shared_list(obj);
294294
if (old)
295295
i = old->shared_count;
296296

@@ -329,7 +329,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)
329329
dma_resv_assert_held(dst);
330330

331331
rcu_read_lock();
332-
src_list = rcu_dereference(src->fence);
332+
src_list = dma_resv_shared_list(src);
333333

334334
retry:
335335
if (src_list) {
@@ -342,7 +342,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)
342342
return -ENOMEM;
343343

344344
rcu_read_lock();
345-
src_list = rcu_dereference(src->fence);
345+
src_list = dma_resv_shared_list(src);
346346
if (!src_list || src_list->shared_count > shared_count) {
347347
kfree(dst_list);
348348
goto retry;
@@ -360,7 +360,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)
360360

361361
if (!dma_fence_get_rcu(fence)) {
362362
dma_resv_list_free(dst_list);
363-
src_list = rcu_dereference(src->fence);
363+
src_list = dma_resv_shared_list(src);
364364
goto retry;
365365
}
366366

@@ -379,7 +379,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)
379379
new = dma_fence_get_rcu_safe(&src->fence_excl);
380380
rcu_read_unlock();
381381

382-
src_list = dma_resv_get_list(dst);
382+
src_list = dma_resv_shared_list(dst);
383383
old = dma_resv_excl_fence(dst);
384384

385385
write_seqcount_begin(&dst->seq);
@@ -432,7 +432,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
432432
if (fence_excl && !dma_fence_get_rcu(fence_excl))
433433
goto unlock;
434434

435-
fobj = rcu_dereference(obj->fence);
435+
fobj = dma_resv_shared_list(obj);
436436
if (fobj)
437437
sz += sizeof(*shared) * fobj->shared_max;
438438

@@ -538,7 +538,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,
538538
}
539539

540540
if (wait_all) {
541-
struct dma_resv_list *fobj = rcu_dereference(obj->fence);
541+
struct dma_resv_list *fobj = dma_resv_shared_list(obj);
542542

543543
if (fobj)
544544
shared_count = fobj->shared_count;
@@ -623,7 +623,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)
623623
seq = read_seqcount_begin(&obj->seq);
624624

625625
if (test_all) {
626-
struct dma_resv_list *fobj = rcu_dereference(obj->fence);
626+
struct dma_resv_list *fobj = dma_resv_shared_list(obj);
627627
unsigned int i;
628628

629629
if (fobj)

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,
247247
if (!ef)
248248
return -EINVAL;
249249

250-
old = dma_resv_get_list(resv);
250+
old = dma_resv_shared_list(resv);
251251
if (!old)
252252
return 0;
253253

drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ __dma_resv_make_exclusive(struct dma_resv *obj)
4949
unsigned int count;
5050
int r;
5151

52-
if (!dma_resv_get_list(obj)) /* no shared fences to convert */
52+
if (!dma_resv_shared_list(obj)) /* no shared fences to convert */
5353
return 0;
5454

5555
r = dma_resv_get_fences_rcu(obj, NULL, &count, &fences);

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
213213
f = dma_resv_excl_fence(resv);
214214
r = amdgpu_sync_fence(sync, f);
215215

216-
flist = dma_resv_get_list(resv);
216+
flist = dma_resv_shared_list(resv);
217217
if (!flist || r)
218218
return r;
219219

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
13391339
* If true, then return false as any KFD process needs all its BOs to
13401340
* be resident to run successfully
13411341
*/
1342-
flist = dma_resv_get_list(bo->base.resv);
1342+
flist = dma_resv_shared_list(bo->base.resv);
13431343
if (flist) {
13441344
for (i = 0; i < flist->shared_count; ++i) {
13451345
f = rcu_dereference_protected(flist->shared[i],

drivers/gpu/drm/etnaviv/etnaviv_gem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
461461
off, etnaviv_obj->vaddr, obj->size);
462462

463463
rcu_read_lock();
464-
fobj = rcu_dereference(robj->fence);
464+
fobj = dma_resv_shared_list(robj);
465465
if (fobj) {
466466
unsigned int i, shared_count = fobj->shared_count;
467467

drivers/gpu/drm/i915/gem/i915_gem_busy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
116116
args->busy = busy_check_writer(dma_resv_excl_fence(obj->base.resv));
117117

118118
/* Translate shared fences to READ set of engines */
119-
list = rcu_dereference(obj->base.resv->fence);
119+
list = dma_resv_shared_list(obj->base.resv);
120120
if (list) {
121121
unsigned int shared_count = list->shared_count, i;
122122

drivers/gpu/drm/msm/msm_gem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj,
817817
struct dma_fence *fence;
818818
int i, ret;
819819

820-
fobj = dma_resv_get_list(obj->resv);
820+
fobj = dma_resv_shared_list(obj->resv);
821821
if (!fobj || (fobj->shared_count == 0)) {
822822
fence = dma_resv_excl_fence(obj->resv);
823823
/* 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,
10251025
}
10261026

10271027
rcu_read_lock();
1028-
fobj = rcu_dereference(robj->fence);
1028+
fobj = dma_resv_shared_list(robj);
10291029
if (fobj) {
10301030
unsigned int i, shared_count = fobj->shared_count;
10311031

drivers/gpu/drm/nouveau/nouveau_fence.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e
355355
return ret;
356356
}
357357

358-
fobj = dma_resv_get_list(resv);
358+
fobj = dma_resv_shared_list(resv);
359359
fence = dma_resv_excl_fence(resv);
360360

361361
if (fence && (!exclusive || !fobj || !fobj->shared_count)) {

drivers/gpu/drm/qxl/qxl_debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ qxl_debugfs_buffers_info(struct seq_file *m, void *data)
6161
int rel;
6262

6363
rcu_read_lock();
64-
fobj = rcu_dereference(bo->tbo.base.resv->fence);
64+
fobj = dma_resv_shared_list(bo->tbo.base.resv);
6565
rel = fobj ? fobj->shared_count : 0;
6666
rcu_read_unlock();
6767

drivers/gpu/drm/radeon/radeon_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int radeon_sync_resv(struct radeon_device *rdev,
105105
else if (f)
106106
r = dma_fence_wait(f, true);
107107

108-
flist = dma_resv_get_list(resv);
108+
flist = dma_resv_shared_list(resv);
109109
if (shared || !flist || r)
110110
return r;
111111

drivers/gpu/drm/ttm/ttm_bo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static void ttm_bo_flush_all_fences(struct ttm_buffer_object *bo)
261261
int i;
262262

263263
rcu_read_lock();
264-
fobj = rcu_dereference(resv->fence);
264+
fobj = dma_resv_shared_list(resv);
265265
fence = dma_resv_excl_fence(resv);
266266
if (fence && !fence->ops->signaled)
267267
dma_fence_enable_sw_signaling(fence);

include/linux/dma-resv.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,6 @@ struct dma_resv {
7878
#define dma_resv_held(obj) lockdep_is_held(&(obj)->lock.base)
7979
#define dma_resv_assert_held(obj) lockdep_assert_held(&(obj)->lock.base)
8080

81-
/**
82-
* dma_resv_get_list - get the reservation object's
83-
* shared fence list, with update-side lock held
84-
* @obj: the reservation object
85-
*
86-
* Returns the shared fence list. Does NOT take references to
87-
* the fence. The obj->lock must be held.
88-
*/
89-
static inline struct dma_resv_list *dma_resv_get_list(struct dma_resv *obj)
90-
{
91-
return rcu_dereference_protected(obj->fence,
92-
dma_resv_held(obj));
93-
}
94-
9581
#ifdef CONFIG_DEBUG_MUTEXES
9682
void dma_resv_reset_shared_max(struct dma_resv *obj);
9783
#else
@@ -268,6 +254,19 @@ dma_resv_get_excl_rcu(struct dma_resv *obj)
268254
return fence;
269255
}
270256

257+
/**
258+
* dma_resv_shared_list - get the reservation object's shared fence list
259+
* @obj: the reservation object
260+
*
261+
* Returns the shared fence list. Caller must either hold the objects
262+
* through dma_resv_lock() or the RCU read side lock through rcu_read_lock(),
263+
* or one of the variants of each
264+
*/
265+
static inline struct dma_resv_list *dma_resv_shared_list(struct dma_resv *obj)
266+
{
267+
return rcu_dereference_check(obj->fence, dma_resv_held(obj));
268+
}
269+
271270
void dma_resv_init(struct dma_resv *obj);
272271
void dma_resv_fini(struct dma_resv *obj);
273272
int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences);

0 commit comments

Comments
 (0)