diff mbox series

[2/9] dma-buf: warn about dma_fence_array container rules

Message ID 20220120132747.2348-3-christian.koenig@amd.com
State Superseded
Headers show
Series [1/9] dma-buf: consolidate dma_fence subclass checking | expand

Commit Message

Christian König Jan. 20, 2022, 1:27 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.

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 | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Thomas Hellström Jan. 21, 2022, 7:31 a.m. UTC | #1
On 1/20/22 14:27, 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.
>
> 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 | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c
> index 3e07f961e2f3..4bfbcb885bbc 100644
> --- a/drivers/dma-buf/dma-fence-array.c
> +++ b/drivers/dma-buf/dma-fence-array.c
> @@ -176,6 +176,19 @@ 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
Nit: First comment line of multi-line comments shouldn't contain text.
> +	 * 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 (seqno--)
> +		WARN_ON(dma_fence_is_container(fences[seqno]));
> +

s/seqno/num_fences/g ?

Thanks,

Thomas



>   	return array;
>   }
>   EXPORT_SYMBOL(dma_fence_array_create);
Christian König Jan. 21, 2022, 11 a.m. UTC | #2
Am 21.01.22 um 08:31 schrieb Thomas Hellström:
>
> On 1/20/22 14:27, 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.
>>
>> 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 | 13 +++++++++++++
>>   1 file changed, 13 insertions(+)
>>
>> diff --git a/drivers/dma-buf/dma-fence-array.c 
>> b/drivers/dma-buf/dma-fence-array.c
>> index 3e07f961e2f3..4bfbcb885bbc 100644
>> --- a/drivers/dma-buf/dma-fence-array.c
>> +++ b/drivers/dma-buf/dma-fence-array.c
>> @@ -176,6 +176,19 @@ 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
> Nit: First comment line of multi-line comments shouldn't contain text.
>> +     * 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 (seqno--)
>> +        WARN_ON(dma_fence_is_container(fences[seqno]));
>> +
>
> s/seqno/num_fences/g ?

Ah, of course! Typing to fast.

Thanks,
Christian.

>
> Thanks,
>
> Thomas
>
>
>
>>       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..4bfbcb885bbc 100644
--- a/drivers/dma-buf/dma-fence-array.c
+++ b/drivers/dma-buf/dma-fence-array.c
@@ -176,6 +176,19 @@  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 (seqno--)
+		WARN_ON(dma_fence_is_container(fences[seqno]));
+
 	return array;
 }
 EXPORT_SYMBOL(dma_fence_array_create);