Skip to content

Commit 6edbd6a

Browse files
dma-buf: rename and cleanup dma_resv_get_excl v3
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. v2: improve kerneldoc as suggested by Daniel v3: use dma_resv_excl_fence as function name Signed-off-by: Christian König <[email protected]> Acked-by: Daniel Vetter <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 415f676 commit 6edbd6a

File tree

15 files changed

+26
-30
lines changed

15 files changed

+26
-30
lines changed

drivers/dma-buf/dma-buf.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)
234234
shared_count = fobj->shared_count;
235235
else
236236
shared_count = 0;
237-
fence_excl = rcu_dereference(resv->fence_excl);
237+
fence_excl = dma_resv_excl_fence(resv);
238238
if (read_seqcount_retry(&resv->seq, seq)) {
239239
rcu_read_unlock();
240240
goto retry;
@@ -1382,8 +1382,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)
13821382
buf_obj->name ?: "");
13831383

13841384
robj = buf_obj->resv;
1385-
fence = rcu_dereference_protected(robj->fence_excl,
1386-
dma_resv_held(robj));
1385+
fence = dma_resv_excl_fence(robj);
13871386
if (fence)
13881387
seq_printf(s, "\tExclusive fence: %s %s %ssignalled\n",
13891388
fence->ops->get_driver_name(fence),

drivers/dma-buf/dma-resv.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ EXPORT_SYMBOL(dma_resv_add_shared_fence);
284284
*/
285285
void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence)
286286
{
287-
struct dma_fence *old_fence = dma_resv_get_excl(obj);
287+
struct dma_fence *old_fence = dma_resv_excl_fence(obj);
288288
struct dma_resv_list *old;
289289
u32 i = 0;
290290

@@ -380,7 +380,7 @@ int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)
380380
rcu_read_unlock();
381381

382382
src_list = dma_resv_get_list(dst);
383-
old = dma_resv_get_excl(dst);
383+
old = dma_resv_excl_fence(dst);
384384

385385
write_seqcount_begin(&dst->seq);
386386
/* write_seqcount_begin provides the necessary memory barrier */
@@ -428,7 +428,7 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
428428
rcu_read_lock();
429429
seq = read_seqcount_begin(&obj->seq);
430430

431-
fence_excl = rcu_dereference(obj->fence_excl);
431+
fence_excl = dma_resv_excl_fence(obj);
432432
if (fence_excl && !dma_fence_get_rcu(fence_excl))
433433
goto unlock;
434434

@@ -523,7 +523,7 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,
523523
rcu_read_lock();
524524
i = -1;
525525

526-
fence = rcu_dereference(obj->fence_excl);
526+
fence = dma_resv_excl_fence(obj);
527527
if (fence && !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
528528
if (!dma_fence_get_rcu(fence))
529529
goto unlock_retry;
@@ -645,7 +645,7 @@ bool dma_resv_test_signaled_rcu(struct dma_resv *obj, bool test_all)
645645
}
646646

647647
if (!shared_count) {
648-
struct dma_fence *fence_excl = rcu_dereference(obj->fence_excl);
648+
struct dma_fence *fence_excl = dma_resv_excl_fence(obj);
649649

650650
if (fence_excl) {
651651
ret = dma_resv_test_signaled_single(fence_excl);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
226226
if (!amdgpu_vm_ready(vm))
227227
goto out_unlock;
228228

229-
fence = dma_resv_get_excl(bo->tbo.base.resv);
229+
fence = dma_resv_excl_fence(bo->tbo.base.resv);
230230
if (fence) {
231231
amdgpu_bo_fence(bo, fence, true);
232232
fence = NULL;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
210210
return -EINVAL;
211211

212212
/* always sync to the exclusive fence */
213-
f = dma_resv_get_excl(resv);
213+
f = dma_resv_excl_fence(resv);
214214
r = amdgpu_sync_fence(sync, f);
215215

216216
flist = dma_resv_get_list(resv);

drivers/gpu/drm/etnaviv/etnaviv_gem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ static void etnaviv_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
471471
}
472472
}
473473

474-
fence = rcu_dereference(robj->fence_excl);
474+
fence = dma_resv_excl_fence(robj);
475475
if (fence)
476476
etnaviv_gem_describe_fence(fence, "Exclusive", m);
477477
rcu_read_unlock();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
113113
seq = raw_read_seqcount(&obj->base.resv->seq);
114114

115115
/* Translate the exclusive fence to the READ *and* WRITE engine */
116-
args->busy =
117-
busy_check_writer(rcu_dereference(obj->base.resv->fence_excl));
116+
args->busy = busy_check_writer(dma_resv_excl_fence(obj->base.resv));
118117

119118
/* Translate shared fences to READ set of engines */
120119
list = rcu_dereference(obj->base.resv->fence);

drivers/gpu/drm/msm/msm_gem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ int msm_gem_sync_object(struct drm_gem_object *obj,
819819

820820
fobj = dma_resv_get_list(obj->resv);
821821
if (!fobj || (fobj->shared_count == 0)) {
822-
fence = dma_resv_get_excl(obj->resv);
822+
fence = dma_resv_excl_fence(obj->resv);
823823
/* don't need to wait on our own fences, since ring is fifo */
824824
if (fence && (fence->context != fctx->context)) {
825825
ret = dma_fence_wait(fence, true);
@@ -1035,7 +1035,7 @@ void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m,
10351035
}
10361036
}
10371037

1038-
fence = rcu_dereference(robj->fence_excl);
1038+
fence = dma_resv_excl_fence(robj);
10391039
if (fence)
10401040
describe_fence(fence, "Exclusive", m);
10411041
rcu_read_unlock();

drivers/gpu/drm/nouveau/nouveau_bo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo,
951951
{
952952
struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
953953
struct drm_device *dev = drm->dev;
954-
struct dma_fence *fence = dma_resv_get_excl(bo->base.resv);
954+
struct dma_fence *fence = dma_resv_excl_fence(bo->base.resv);
955955

956956
nv10_bo_put_tile_region(dev, *old_tile, fence);
957957
*old_tile = new_tile;

drivers/gpu/drm/nouveau/nouveau_fence.c

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

358358
fobj = dma_resv_get_list(resv);
359-
fence = dma_resv_get_excl(resv);
359+
fence = dma_resv_excl_fence(resv);
360360

361361
if (fence && (!exclusive || !fobj || !fobj->shared_count)) {
362362
struct nouveau_channel *prev = NULL;

drivers/gpu/drm/radeon/radeon_display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static int radeon_crtc_page_flip_target(struct drm_crtc *crtc,
533533
DRM_ERROR("failed to pin new rbo buffer before flip\n");
534534
goto cleanup;
535535
}
536-
work->fence = dma_fence_get(dma_resv_get_excl(new_rbo->tbo.base.resv));
536+
work->fence = dma_fence_get(dma_resv_excl_fence(new_rbo->tbo.base.resv));
537537
radeon_bo_get_tiling_flags(new_rbo, &tiling_flags, NULL);
538538
radeon_bo_unreserve(new_rbo);
539539

drivers/gpu/drm/radeon/radeon_sync.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ int radeon_sync_resv(struct radeon_device *rdev,
9898
int r = 0;
9999

100100
/* always sync to the exclusive fence */
101-
f = dma_resv_get_excl(resv);
101+
f = dma_resv_excl_fence(resv);
102102
fence = f ? to_radeon_fence(f) : NULL;
103103
if (fence && fence->rdev == rdev)
104104
radeon_sync_fence(sync, fence);

drivers/gpu/drm/radeon/radeon_uvd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static int radeon_uvd_cs_msg(struct radeon_cs_parser *p, struct radeon_bo *bo,
477477
return -EINVAL;
478478
}
479479

480-
f = dma_resv_get_excl(bo->tbo.base.resv);
480+
f = dma_resv_excl_fence(bo->tbo.base.resv);
481481
if (f) {
482482
r = radeon_fence_wait((struct radeon_fence *)f, false);
483483
if (r) {

drivers/gpu/drm/ttm/ttm_bo.c

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

263263
rcu_read_lock();
264264
fobj = rcu_dereference(resv->fence);
265-
fence = rcu_dereference(resv->fence_excl);
265+
fence = dma_resv_excl_fence(resv);
266266
if (fence && !fence->ops->signaled)
267267
dma_fence_enable_sw_signaling(fence);
268268

drivers/gpu/drm/vmwgfx/vmwgfx_resource.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
11661166
if (bo->moving)
11671167
dma_fence_put(bo->moving);
11681168
bo->moving = dma_fence_get
1169-
(dma_resv_get_excl(bo->base.resv));
1169+
(dma_resv_excl_fence(bo->base.resv));
11701170
}
11711171

11721172
return 0;

include/linux/dma-resv.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,20 @@ static inline void dma_resv_unlock(struct dma_resv *obj)
226226
}
227227

228228
/**
229-
* dma_resv_get_excl - get the reservation object's
230-
* exclusive fence, with update-side lock held
229+
* dma_resv_exclusive - return the object's exclusive fence
231230
* @obj: the reservation object
232231
*
233-
* Returns the exclusive fence (if any). Does NOT take a
234-
* reference. Writers must hold obj->lock, readers may only
235-
* hold a RCU read side lock.
232+
* Returns the exclusive fence (if any). Caller must either hold the objects
233+
* through dma_resv_lock() or the RCU read side lock through rcu_read_lock(),
234+
* or one of the variants of each
236235
*
237236
* RETURNS
238237
* The exclusive fence or NULL
239238
*/
240239
static inline struct dma_fence *
241-
dma_resv_get_excl(struct dma_resv *obj)
240+
dma_resv_excl_fence(struct dma_resv *obj)
242241
{
243-
return rcu_dereference_protected(obj->fence_excl,
244-
dma_resv_held(obj));
242+
return rcu_dereference_check(obj->fence_excl, dma_resv_held(obj));
245243
}
246244

247245
/**

0 commit comments

Comments
 (0)