mbox series

[v2,0/4] dma-buf: To check enable signaling before signaled

Message ID 20220905163502.4032-1-Arvind.Yadav@amd.com
Headers show
Series dma-buf: To check enable signaling before signaled | expand

Message

Arvind Yadav Sept. 5, 2022, 4:34 p.m. UTC
TTM, GEM, DRM or the core DMA-buf framework are needs
to enable software signaling before the fence is signaled.
The core DMA-buf framework software can forget to call
enable_signaling before the fence is signaled. It means
framework code can forget to call dma_fence_enable_sw_signaling()
before calling dma_fence_is_signaled(). To avoid this scenario
on debug kernel, check the DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT bit
status before checking the MA_FENCE_FLAG_SIGNALED_BIT bit status
to confirm that software signaling is enabled.


Arvind Yadav (4):
  [PATCH v2 1/4] drm/sched: Enable signaling for finished fence
  [PATCH v2 2/4] dma-buf: enable signaling for the stub fence on debug
  [PATCH v2 3/4] dma-buf: enable signaling for selftest fence on debug
  [PATCH v2 4/4] dma-buf: Check status of enable-signaling bit on debug

 drivers/dma-buf/dma-fence.c            |  7 ++++
 drivers/dma-buf/st-dma-fence-chain.c   |  8 +++++
 drivers/dma-buf/st-dma-fence-unwrap.c  | 44 ++++++++++++++++++++++++++
 drivers/dma-buf/st-dma-fence.c         | 25 ++++++++++++++-
 drivers/dma-buf/st-dma-resv.c          | 20 ++++++++++++
 drivers/gpu/drm/scheduler/sched_main.c |  2 ++
 include/linux/dma-fence.h              |  5 +++
 7 files changed, 110 insertions(+), 1 deletion(-)

Comments

Christian König Sept. 6, 2022, 7:11 a.m. UTC | #1
Am 05.09.22 um 18:35 schrieb Arvind Yadav:
> Here's on debug enabling software signaling for selftest.

Please drop all the #ifdefs, apart from that looks pretty good to me.

Christian.

>
> Signed-off-by: Arvind Yadav <Arvind.Yadav@amd.com>
> ---
>
> Changes in v1 :
> 1- Addressing Christian's comment to remove unnecessary callback.
> 2- Replacing CONFIG_DEBUG_WW_MUTEX_SLOWPATH instead of CONFIG_DEBUG_FS.
> 3- The version of this patch is also changed and previously
> it was [PATCH 4/4]
>
> ---
>   drivers/dma-buf/st-dma-fence-chain.c  |  8 +++++
>   drivers/dma-buf/st-dma-fence-unwrap.c | 44 +++++++++++++++++++++++++++
>   drivers/dma-buf/st-dma-fence.c        | 25 ++++++++++++++-
>   drivers/dma-buf/st-dma-resv.c         | 20 ++++++++++++
>   4 files changed, 96 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma-buf/st-dma-fence-chain.c b/drivers/dma-buf/st-dma-fence-chain.c
> index 8ce1ea59d31b..d3070f8a393c 100644
> --- a/drivers/dma-buf/st-dma-fence-chain.c
> +++ b/drivers/dma-buf/st-dma-fence-chain.c
> @@ -87,6 +87,10 @@ static int sanitycheck(void *arg)
>   	if (!chain)
>   		err = -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(chain);
> +#endif
> +
>   	dma_fence_signal(f);
>   	dma_fence_put(f);
>   
> @@ -143,6 +147,10 @@ static int fence_chains_init(struct fence_chains *fc, unsigned int count,
>   		}
>   
>   		fc->tail = fc->chains[i];
> +
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +		dma_fence_enable_sw_signaling(fc->chains[i]);
> +#endif
>   	}
>   
>   	fc->chain_length = i;
> diff --git a/drivers/dma-buf/st-dma-fence-unwrap.c b/drivers/dma-buf/st-dma-fence-unwrap.c
> index 4105d5ea8dde..b76cdd9ee0c7 100644
> --- a/drivers/dma-buf/st-dma-fence-unwrap.c
> +++ b/drivers/dma-buf/st-dma-fence-unwrap.c
> @@ -102,6 +102,10 @@ static int sanitycheck(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
> +
>   	array = mock_array(1, f);
>   	if (!array)
>   		return -ENOMEM;
> @@ -124,12 +128,20 @@ static int unwrap_array(void *arg)
>   	if (!f1)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f1);
> +#endif
> +
>   	f2 = mock_fence();
>   	if (!f2) {
>   		dma_fence_put(f1);
>   		return -ENOMEM;
>   	}
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f2);
> +#endif
> +
>   	array = mock_array(2, f1, f2);
>   	if (!array)
>   		return -ENOMEM;
> @@ -164,12 +176,20 @@ static int unwrap_chain(void *arg)
>   	if (!f1)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f1);
> +#endif
> +
>   	f2 = mock_fence();
>   	if (!f2) {
>   		dma_fence_put(f1);
>   		return -ENOMEM;
>   	}
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f2);
> +#endif
> +
>   	chain = mock_chain(f1, f2);
>   	if (!chain)
>   		return -ENOMEM;
> @@ -204,12 +224,20 @@ static int unwrap_chain_array(void *arg)
>   	if (!f1)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f1);
> +#endif
> +
>   	f2 = mock_fence();
>   	if (!f2) {
>   		dma_fence_put(f1);
>   		return -ENOMEM;
>   	}
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f2);
> +#endif
> +
>   	array = mock_array(2, f1, f2);
>   	if (!array)
>   		return -ENOMEM;
> @@ -248,12 +276,20 @@ static int unwrap_merge(void *arg)
>   	if (!f1)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f1);
> +#endif
> +
>   	f2 = mock_fence();
>   	if (!f2) {
>   		err = -ENOMEM;
>   		goto error_put_f1;
>   	}
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f2);
> +#endif
> +
>   	f3 = dma_fence_unwrap_merge(f1, f2);
>   	if (!f3) {
>   		err = -ENOMEM;
> @@ -296,10 +332,18 @@ static int unwrap_merge_complex(void *arg)
>   	if (!f1)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f1);
> +#endif
> +
>   	f2 = mock_fence();
>   	if (!f2)
>   		goto error_put_f1;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f2);
> +#endif
> +
>   	f3 = dma_fence_unwrap_merge(f1, f2);
>   	if (!f3)
>   		goto error_put_f2;
> diff --git a/drivers/dma-buf/st-dma-fence.c b/drivers/dma-buf/st-dma-fence.c
> index c8a12d7ad71a..b7880d8374db 100644
> --- a/drivers/dma-buf/st-dma-fence.c
> +++ b/drivers/dma-buf/st-dma-fence.c
> @@ -101,7 +101,9 @@ static int sanitycheck(void *arg)
>   	f = mock_fence();
>   	if (!f)
>   		return -ENOMEM;
> -
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
>   	dma_fence_signal(f);
>   	dma_fence_put(f);
>   
> @@ -117,6 +119,9 @@ static int test_signaling(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
>   	if (dma_fence_is_signaled(f)) {
>   		pr_err("Fence unexpectedly signaled on creation\n");
>   		goto err_free;
> @@ -190,6 +195,9 @@ static int test_late_add_callback(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
>   	dma_fence_signal(f);
>   
>   	if (!dma_fence_add_callback(f, &cb.cb, simple_callback)) {
> @@ -282,6 +290,9 @@ static int test_status(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
>   	if (dma_fence_get_status(f)) {
>   		pr_err("Fence unexpectedly has signaled status on creation\n");
>   		goto err_free;
> @@ -308,6 +319,9 @@ static int test_error(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
>   	dma_fence_set_error(f, -EIO);
>   
>   	if (dma_fence_get_status(f)) {
> @@ -337,6 +351,9 @@ static int test_wait(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
>   	if (dma_fence_wait_timeout(f, false, 0) != -ETIME) {
>   		pr_err("Wait reported complete before being signaled\n");
>   		goto err_free;
> @@ -379,6 +396,9 @@ static int test_wait_timeout(void *arg)
>   	if (!wt.f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(wt.f);
> +#endif
>   	if (dma_fence_wait_timeout(wt.f, false, 1) != -ETIME) {
>   		pr_err("Wait reported complete before being signaled\n");
>   		goto err_free;
> @@ -458,6 +478,9 @@ static int thread_signal_callback(void *arg)
>   			break;
>   		}
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +		dma_fence_enable_sw_signaling(f1);
> +#endif
>   		rcu_assign_pointer(t->fences[t->id], f1);
>   		smp_wmb();
>   
> diff --git a/drivers/dma-buf/st-dma-resv.c b/drivers/dma-buf/st-dma-resv.c
> index 813779e3c9be..bd7ef58f8b24 100644
> --- a/drivers/dma-buf/st-dma-resv.c
> +++ b/drivers/dma-buf/st-dma-resv.c
> @@ -45,6 +45,10 @@ static int sanitycheck(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
> +
>   	dma_fence_signal(f);
>   	dma_fence_put(f);
>   
> @@ -69,6 +73,10 @@ static int test_signaling(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
> +
>   	dma_resv_init(&resv);
>   	r = dma_resv_lock(&resv, NULL);
>   	if (r) {
> @@ -114,6 +122,10 @@ static int test_for_each(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
> +
>   	dma_resv_init(&resv);
>   	r = dma_resv_lock(&resv, NULL);
>   	if (r) {
> @@ -173,6 +185,10 @@ static int test_for_each_unlocked(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
> +
>   	dma_resv_init(&resv);
>   	r = dma_resv_lock(&resv, NULL);
>   	if (r) {
> @@ -244,6 +260,10 @@ static int test_get_fences(void *arg)
>   	if (!f)
>   		return -ENOMEM;
>   
> +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> +	dma_fence_enable_sw_signaling(f);
> +#endif
> +
>   	dma_resv_init(&resv);
>   	r = dma_resv_lock(&resv, NULL);
>   	if (r) {
Andrey Grodzovsky Sept. 6, 2022, 7:55 p.m. UTC | #2
On 2022-09-06 02:34, Christian König wrote:
> Am 05.09.22 um 18:34 schrieb Arvind Yadav:
>> Here's enabling software signaling for finished fence.
>>
>> Signed-off-by: Arvind Yadav <Arvind.Yadav@amd.com>
>> ---
>>
>> Changes in v1 :
>> 1- Addressing Christian's comment to remove CONFIG_DEBUG_FS check from
>> this patch.
>> 2- The version of this patch is also changed and previously
>> it was [PATCH 2/4]
>>
>> ---
>>   drivers/gpu/drm/scheduler/sched_main.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
>> b/drivers/gpu/drm/scheduler/sched_main.c
>> index e0ab14e0fb6b..fe72de0e2911 100644
>> --- a/drivers/gpu/drm/scheduler/sched_main.c
>> +++ b/drivers/gpu/drm/scheduler/sched_main.c
>> @@ -962,6 +962,8 @@ static int drm_sched_main(void *param)
>>               /* Drop for original kref_init of the fence */
>>               dma_fence_put(fence);
>>   + dma_fence_enable_sw_signaling(&s_fence->finished);
>
> Ok, this makes it a lot clearer. Previously I though that we have some 
> bug in dma_fence_add_callback().
>
> This is essentially the wrong place to call this, the finished fence 
> should be enabled by the caller and not here.
>
> There is also another problem in dma_fence_enable_sw_signaling(), it 
> returns early when the fence is already signaled:
>
>         if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
>                 return;
>
> Please remove that one first.


Why we even need this explicit call if dma_fence_add_callback calls 
__dma_fence_enable_signaling anyway ?

Andrey


>
> Thanks,
> Christian.
>
>
>> +
>>               r = dma_fence_add_callback(fence, &sched_job->cb,
>>                              drm_sched_job_done_cb);
>>               if (r == -ENOENT)
>