[PATCH 5/6] RFC: dma-buf: Add an extra fence to dma_resv_get_singleton_unlocked
Christian König
christian.koenig at amd.com
Fri Jun 11 07:44:26 UTC 2021
Am 10.06.21 um 23:09 schrieb Jason Ekstrand:
> For dma-buf sync_file import, we want to get all the fences on a
> dma_resv plus one more. We could wrap the fence we get back in an array
> fence or we could make dma_resv_get_singleton_unlocked take "one more"
> to make this case easier.
>
> Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
> Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>
Reviewed-by: Christian König <christian.koenig at amd.com>
> Cc: Christian König <christian.koenig at amd.com>
> Cc: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
> ---
> drivers/dma-buf/dma-buf.c | 2 +-
> drivers/dma-buf/dma-resv.c | 23 +++++++++++++++++++++--
> include/linux/dma-resv.h | 3 ++-
> 3 files changed, 24 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 41b14b53cdda3..831828d71b646 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -389,7 +389,7 @@ static long dma_buf_export_sync_file(struct dma_buf *dmabuf,
> return fd;
>
> if (arg.flags & DMA_BUF_SYNC_WRITE) {
> - fence = dma_resv_get_singleton(dmabuf->resv);
> + fence = dma_resv_get_singleton(dmabuf->resv, NULL);
> if (IS_ERR(fence)) {
> ret = PTR_ERR(fence);
> goto err_put_fd;
> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> index 1b26aa7e5d81c..7c48c23239b4b 100644
> --- a/drivers/dma-buf/dma-resv.c
> +++ b/drivers/dma-buf/dma-resv.c
> @@ -504,6 +504,7 @@ EXPORT_SYMBOL_GPL(dma_resv_get_fences);
> /**
> * dma_resv_get_singleton - get a single fence for the dma_resv object
> * @obj: the reservation object
> + * @extra: extra fence to add to the resulting array
> *
> * Get a single fence representing all unsignaled fences in the dma_resv object
> * plus the given extra fence. If we got only one fence return a new
> @@ -512,7 +513,8 @@ EXPORT_SYMBOL_GPL(dma_resv_get_fences);
> * RETURNS
> * The singleton dma_fence on success or an ERR_PTR on failure
> */
> -struct dma_fence *dma_resv_get_singleton(struct dma_resv *obj)
> +struct dma_fence *dma_resv_get_singleton(struct dma_resv *obj,
> + struct dma_fence *extra)
> {
> struct dma_fence *result, **resv_fences, *fence, *chain, **fences;
> struct dma_fence_array *array;
> @@ -523,7 +525,7 @@ struct dma_fence *dma_resv_get_singleton(struct dma_resv *obj)
> if (err)
> return ERR_PTR(err);
>
> - if (num_resv_fences == 0)
> + if (num_resv_fences == 0 && !extra)
> return NULL;
>
> num_fences = 0;
> @@ -539,6 +541,16 @@ struct dma_fence *dma_resv_get_singleton(struct dma_resv *obj)
> }
> }
>
> + if (extra) {
> + dma_fence_deep_dive_for_each(fence, chain, j, extra) {
> + if (dma_fence_is_signaled(fence))
> + continue;
> +
> + result = fence;
> + ++num_fences;
> + }
> + }
> +
> if (num_fences <= 1) {
> result = dma_fence_get(result);
> goto put_resv_fences;
> @@ -559,6 +571,13 @@ struct dma_fence *dma_resv_get_singleton(struct dma_resv *obj)
> }
> }
>
> + if (extra) {
> + dma_fence_deep_dive_for_each(fence, chain, j, extra) {
> + if (dma_fence_is_signaled(fence))
> + fences[num_fences++] = dma_fence_get(fence);
> + }
> + }
> +
> if (num_fences <= 1) {
> result = num_fences ? fences[0] : NULL;
> kfree(fences);
> diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h
> index d60982975a786..f970e03fc1a08 100644
> --- a/include/linux/dma-resv.h
> +++ b/include/linux/dma-resv.h
> @@ -275,7 +275,8 @@ void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence);
> 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);
> -struct dma_fence *dma_resv_get_singleton(struct dma_resv *obj);
> +struct dma_fence *dma_resv_get_singleton(struct dma_resv *obj,
> + struct dma_fence *extra);
> 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);
More information about the dri-devel
mailing list