Skip to content

Commit f2d8e15

Browse files
committed
drm/i915: Prepare to dynamic dma-buf locking specification
Prepare i915 driver to the common dynamic dma-buf locking convention by starting to use the unlocked versions of dma-buf API functions and handling cases where importer now holds the reservation lock. Acked-by: Christian König <[email protected]> Reviewed-by: Michael J. Ruhl <[email protected]> Signed-off-by: Dmitry Osipenko <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e4ea542 commit f2d8e15

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int i915_gem_dmabuf_vmap(struct dma_buf *dma_buf,
7272
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
7373
void *vaddr;
7474

75-
vaddr = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB);
75+
vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
7676
if (IS_ERR(vaddr))
7777
return PTR_ERR(vaddr);
7878

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,21 @@ void __i915_gem_object_pages_fini(struct drm_i915_gem_object *obj)
290290
__i915_gem_object_free_mmaps(obj);
291291

292292
atomic_set(&obj->mm.pages_pin_count, 0);
293+
294+
/*
295+
* dma_buf_unmap_attachment() requires reservation to be
296+
* locked. The imported GEM shouldn't share reservation lock
297+
* and ttm_bo_cleanup_memtype_use() shouldn't be invoked for
298+
* dma-buf, so it's safe to take the lock.
299+
*/
300+
if (obj->base.import_attach)
301+
i915_gem_object_lock(obj, NULL);
302+
293303
__i915_gem_object_put_pages(obj);
304+
305+
if (obj->base.import_attach)
306+
i915_gem_object_unlock(obj);
307+
294308
GEM_BUG_ON(i915_gem_object_has_pages(obj));
295309
}
296310

drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int igt_dmabuf_import_same_driver(struct drm_i915_private *i915,
213213
goto out_import;
214214
}
215215

216-
st = dma_buf_map_attachment(import_attach, DMA_BIDIRECTIONAL);
216+
st = dma_buf_map_attachment_unlocked(import_attach, DMA_BIDIRECTIONAL);
217217
if (IS_ERR(st)) {
218218
err = PTR_ERR(st);
219219
goto out_detach;
@@ -226,7 +226,7 @@ static int igt_dmabuf_import_same_driver(struct drm_i915_private *i915,
226226
timeout = -ETIME;
227227
}
228228
err = timeout > 0 ? 0 : timeout;
229-
dma_buf_unmap_attachment(import_attach, st, DMA_BIDIRECTIONAL);
229+
dma_buf_unmap_attachment_unlocked(import_attach, st, DMA_BIDIRECTIONAL);
230230
out_detach:
231231
dma_buf_detach(dmabuf, import_attach);
232232
out_import:
@@ -296,7 +296,7 @@ static int igt_dmabuf_import(void *arg)
296296
goto out_obj;
297297
}
298298

299-
err = dma_buf_vmap(dmabuf, &map);
299+
err = dma_buf_vmap_unlocked(dmabuf, &map);
300300
dma_map = err ? NULL : map.vaddr;
301301
if (!dma_map) {
302302
pr_err("dma_buf_vmap failed\n");
@@ -337,7 +337,7 @@ static int igt_dmabuf_import(void *arg)
337337

338338
err = 0;
339339
out_dma_map:
340-
dma_buf_vunmap(dmabuf, &map);
340+
dma_buf_vunmap_unlocked(dmabuf, &map);
341341
out_obj:
342342
i915_gem_object_put(obj);
343343
out_dmabuf:
@@ -358,7 +358,7 @@ static int igt_dmabuf_import_ownership(void *arg)
358358
if (IS_ERR(dmabuf))
359359
return PTR_ERR(dmabuf);
360360

361-
err = dma_buf_vmap(dmabuf, &map);
361+
err = dma_buf_vmap_unlocked(dmabuf, &map);
362362
ptr = err ? NULL : map.vaddr;
363363
if (!ptr) {
364364
pr_err("dma_buf_vmap failed\n");
@@ -367,7 +367,7 @@ static int igt_dmabuf_import_ownership(void *arg)
367367
}
368368

369369
memset(ptr, 0xc5, PAGE_SIZE);
370-
dma_buf_vunmap(dmabuf, &map);
370+
dma_buf_vunmap_unlocked(dmabuf, &map);
371371

372372
obj = to_intel_bo(i915_gem_prime_import(&i915->drm, dmabuf));
373373
if (IS_ERR(obj)) {
@@ -418,7 +418,7 @@ static int igt_dmabuf_export_vmap(void *arg)
418418
}
419419
i915_gem_object_put(obj);
420420

421-
err = dma_buf_vmap(dmabuf, &map);
421+
err = dma_buf_vmap_unlocked(dmabuf, &map);
422422
ptr = err ? NULL : map.vaddr;
423423
if (!ptr) {
424424
pr_err("dma_buf_vmap failed\n");
@@ -435,7 +435,7 @@ static int igt_dmabuf_export_vmap(void *arg)
435435
memset(ptr, 0xc5, dmabuf->size);
436436

437437
err = 0;
438-
dma_buf_vunmap(dmabuf, &map);
438+
dma_buf_vunmap_unlocked(dmabuf, &map);
439439
out:
440440
dma_buf_put(dmabuf);
441441
return err;

0 commit comments

Comments
 (0)