diff mbox series

[04/11] dma-buf: warn about dma_fence_array container rules v2

Message ID 20220124130328.2376-5-christian.koenig@amd.com (mailing list archive)
State New, archived
Headers show
Series [01/11] drm/radeon: use ttm_resource_manager_debug | expand

Commit Message

Christian König Jan. 24, 2022, 1:03 p.m. UTC
It's not allowed to nest another dma_fence container into a dma_fence_array
or otherwise we can run into recursion.

Warn about that when we create a dma_fence_array.

v2: fix comment style and typo in the warning pointed out by Thomas

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/dma-buf/dma-fence-array.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Thomas Hellstrom Jan. 24, 2022, 4:32 p.m. UTC | #1
On Mon, 2022-01-24 at 14:03 +0100, Christian König wrote:
> It's not allowed to nest another dma_fence container into a
> dma_fence_array
> or otherwise we can run into recursion.
> 
> Warn about that when we create a dma_fence_array.
> 
> v2: fix comment style and typo in the warning pointed out by Thomas
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>

> ---
>  drivers/dma-buf/dma-fence-array.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-
> fence-array.c
> index 3e07f961e2f3..cb1bacb5a42b 100644
> --- a/drivers/dma-buf/dma-fence-array.c
> +++ b/drivers/dma-buf/dma-fence-array.c
> @@ -176,6 +176,20 @@ struct dma_fence_array
> *dma_fence_array_create(int num_fences,
>  
>         array->base.error = PENDING_ERROR;
>  
> +       /*
> +        * dma_fence_array objects should never contain any other
> fence
> +        * containers or otherwise we run into recursion and
> potential kernel
> +        * stack overflow on operations on the dma_fence_array.
> +        *
> +        * The correct way of handling this is to flatten out the
> array by the
> +        * caller instead.
> +        *
> +        * Enforce this here by checking that we don't create a
> dma_fence_array
> +        * with any container inside.
> +        */
> +       while (num_fences--)
> +               WARN_ON(dma_fence_is_container(fences[num_fences]));
> +
>         return array;
>  }
>  EXPORT_SYMBOL(dma_fence_array_create);
diff mbox series

Patch

diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c
index 3e07f961e2f3..cb1bacb5a42b 100644
--- a/drivers/dma-buf/dma-fence-array.c
+++ b/drivers/dma-buf/dma-fence-array.c
@@ -176,6 +176,20 @@  struct dma_fence_array *dma_fence_array_create(int num_fences,
 
 	array->base.error = PENDING_ERROR;
 
+	/*
+	 * dma_fence_array objects should never contain any other fence
+	 * containers or otherwise we run into recursion and potential kernel
+	 * stack overflow on operations on the dma_fence_array.
+	 *
+	 * The correct way of handling this is to flatten out the array by the
+	 * caller instead.
+	 *
+	 * Enforce this here by checking that we don't create a dma_fence_array
+	 * with any container inside.
+	 */
+	while (num_fences--)
+		WARN_ON(dma_fence_is_container(fences[num_fences]));
+
 	return array;
 }
 EXPORT_SYMBOL(dma_fence_array_create);