Skip to content

Commit c19083c

Browse files
gfxstrandChristianKoenigAMD
authored andcommitted
dma-buf: Use dma_fence_unwrap_for_each when importing fences
Ever since 68129f4 ("dma-buf: warn about containers in dma_resv object"), dma_resv_add_shared_fence will warn if you attempt to add a container fence. While most drivers were fine, fences can also be added to a dma_resv via the recently added DMA_BUF_IOCTL_IMPORT_SYNC_FILE. Use dma_fence_unwrap_for_each to add each fence one at a time. Fixes: 5947404 ("dma-buf: Add an API for importing sync files (v10)") Signed-off-by: Jason Ekstrand <[email protected]> Reported-by: Sarah Walker <[email protected]> Reviewed-by: Christian König <[email protected]> CC: [email protected] Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Christian König <[email protected]>
1 parent b09d6ac commit c19083c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

drivers/dma-buf/dma-buf.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/slab.h>
1616
#include <linux/dma-buf.h>
1717
#include <linux/dma-fence.h>
18+
#include <linux/dma-fence-unwrap.h>
1819
#include <linux/anon_inodes.h>
1920
#include <linux/export.h>
2021
#include <linux/debugfs.h>
@@ -391,8 +392,10 @@ static long dma_buf_import_sync_file(struct dma_buf *dmabuf,
391392
const void __user *user_data)
392393
{
393394
struct dma_buf_import_sync_file arg;
394-
struct dma_fence *fence;
395+
struct dma_fence *fence, *f;
395396
enum dma_resv_usage usage;
397+
struct dma_fence_unwrap iter;
398+
unsigned int num_fences;
396399
int ret = 0;
397400

398401
if (copy_from_user(&arg, user_data, sizeof(arg)))
@@ -411,13 +414,21 @@ static long dma_buf_import_sync_file(struct dma_buf *dmabuf,
411414
usage = (arg.flags & DMA_BUF_SYNC_WRITE) ? DMA_RESV_USAGE_WRITE :
412415
DMA_RESV_USAGE_READ;
413416

414-
dma_resv_lock(dmabuf->resv, NULL);
417+
num_fences = 0;
418+
dma_fence_unwrap_for_each(f, &iter, fence)
419+
++num_fences;
415420

416-
ret = dma_resv_reserve_fences(dmabuf->resv, 1);
417-
if (!ret)
418-
dma_resv_add_fence(dmabuf->resv, fence, usage);
421+
if (num_fences > 0) {
422+
dma_resv_lock(dmabuf->resv, NULL);
419423

420-
dma_resv_unlock(dmabuf->resv);
424+
ret = dma_resv_reserve_fences(dmabuf->resv, num_fences);
425+
if (!ret) {
426+
dma_fence_unwrap_for_each(f, &iter, fence)
427+
dma_resv_add_fence(dmabuf->resv, f, usage);
428+
}
429+
430+
dma_resv_unlock(dmabuf->resv);
431+
}
421432

422433
dma_fence_put(fence);
423434

0 commit comments

Comments
 (0)