[PATCH 4/4] drm/nouveau: Check dma_fence in canonical way

Philipp Stanner posted 4 patches 9 months, 2 weeks ago
[PATCH 4/4] drm/nouveau: Check dma_fence in canonical way
Posted by Philipp Stanner 9 months, 2 weeks ago
In nouveau_fence_done(), a fence is checked for being signaled by
manually evaluating the base fence's bits. This can be done in a
canonical manner through dma_fence_is_signaled().

Replace the bit-check with dma_fence_is_signaled().

Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
 drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
index fb9811938c82..d5654e26d5bc 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
@@ -253,7 +253,7 @@ nouveau_fence_done(struct nouveau_fence *fence)
 	struct nouveau_channel *chan;
 	unsigned long flags;
 
-	if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->base.flags))
+	if (dma_fence_is_signaled(&fence->base))
 		return true;
 
 	spin_lock_irqsave(&fctx->lock, flags);
-- 
2.48.1
Re: [PATCH 4/4] drm/nouveau: Check dma_fence in canonical way
Posted by Christian König 9 months, 2 weeks ago
On 4/24/25 15:02, Philipp Stanner wrote:
> In nouveau_fence_done(), a fence is checked for being signaled by
> manually evaluating the base fence's bits. This can be done in a
> canonical manner through dma_fence_is_signaled().
> 
> Replace the bit-check with dma_fence_is_signaled().
> 
> Signed-off-by: Philipp Stanner <phasta@kernel.org>


I think the bit check was used here as fast path optimization because we later call dma_fence_is_signaled() anyway.

Feel free to add my acked-by, but honestly what nouveau does here looks rather suspicious to me.

Regards,
Christian.

> ---
>  drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
> index fb9811938c82..d5654e26d5bc 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
> @@ -253,7 +253,7 @@ nouveau_fence_done(struct nouveau_fence *fence)
>  	struct nouveau_channel *chan;
>  	unsigned long flags;
>  
> -	if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->base.flags))
> +	if (dma_fence_is_signaled(&fence->base))
>  		return true;
>  
>  	spin_lock_irqsave(&fctx->lock, flags);
Re: [PATCH 4/4] drm/nouveau: Check dma_fence in canonical way
Posted by Philipp Stanner 9 months ago
On Mon, 2025-04-28 at 16:45 +0200, Christian König wrote:
> On 4/24/25 15:02, Philipp Stanner wrote:
> > In nouveau_fence_done(), a fence is checked for being signaled by
> > manually evaluating the base fence's bits. This can be done in a
> > canonical manner through dma_fence_is_signaled().
> > 
> > Replace the bit-check with dma_fence_is_signaled().
> > 
> > Signed-off-by: Philipp Stanner <phasta@kernel.org>
> 
> 
> I think the bit check was used here as fast path optimization because
> we later call dma_fence_is_signaled() anyway.

That fast path optimization effectively saves one JMP instruction to
the function.

I'm increasingly of the opinion that we shall work towards all DRM
users only ever using infrastructure through officially documented API
functions, without touching internal data structures.

> Feel free to add my acked-by, but honestly what nouveau does here
> looks rather suspicious to me.

:)


P.

> 
> Regards,
> Christian.
> 
> > ---
> >  drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c
> > b/drivers/gpu/drm/nouveau/nouveau_fence.c
> > index fb9811938c82..d5654e26d5bc 100644
> > --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
> > +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
> > @@ -253,7 +253,7 @@ nouveau_fence_done(struct nouveau_fence *fence)
> >  	struct nouveau_channel *chan;
> >  	unsigned long flags;
> >  
> > -	if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence-
> > >base.flags))
> > +	if (dma_fence_is_signaled(&fence->base))
> >  		return true;
> >  
> >  	spin_lock_irqsave(&fctx->lock, flags);
> 
Re: [PATCH 4/4] drm/nouveau: Check dma_fence in canonical way
Posted by Christian König 9 months ago
On 5/8/25 11:13, Philipp Stanner wrote:
> On Mon, 2025-04-28 at 16:45 +0200, Christian König wrote:
>> On 4/24/25 15:02, Philipp Stanner wrote:
>>> In nouveau_fence_done(), a fence is checked for being signaled by
>>> manually evaluating the base fence's bits. This can be done in a
>>> canonical manner through dma_fence_is_signaled().
>>>
>>> Replace the bit-check with dma_fence_is_signaled().
>>>
>>> Signed-off-by: Philipp Stanner <phasta@kernel.org>
>>
>>
>> I think the bit check was used here as fast path optimization because
>> we later call dma_fence_is_signaled() anyway.
> 
> That fast path optimization effectively saves one JMP instruction to
> the function.


What I meant was that we might completely drop that optimization. It looks like overkill and potentially hides bugs.

Regards,
Christian.

> 
> I'm increasingly of the opinion that we shall work towards all DRM
> users only ever using infrastructure through officially documented API
> functions, without touching internal data structures.
> 
>> Feel free to add my acked-by, but honestly what nouveau does here
>> looks rather suspicious to me.
> 
> :)
> 
> 
> P.
> 
>>
>> Regards,
>> Christian.
>>
>>> ---
>>>  drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c
>>> b/drivers/gpu/drm/nouveau/nouveau_fence.c
>>> index fb9811938c82..d5654e26d5bc 100644
>>> --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
>>> +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
>>> @@ -253,7 +253,7 @@ nouveau_fence_done(struct nouveau_fence *fence)
>>>  	struct nouveau_channel *chan;
>>>  	unsigned long flags;
>>>  
>>> -	if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence-
>>>> base.flags))
>>> +	if (dma_fence_is_signaled(&fence->base))
>>>  		return true;
>>>  
>>>  	spin_lock_irqsave(&fctx->lock, flags);
>>
> 

Re: [PATCH 4/4] drm/nouveau: Check dma_fence in canonical way
Posted by Danilo Krummrich 9 months, 2 weeks ago
On 4/24/25 3:02 PM, Philipp Stanner wrote:
> In nouveau_fence_done(), a fence is checked for being signaled by
> manually evaluating the base fence's bits. This can be done in a
> canonical manner through dma_fence_is_signaled().
> 
> Replace the bit-check with dma_fence_is_signaled().
> 
> Signed-off-by: Philipp Stanner <phasta@kernel.org>
> ---
>   drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
> index fb9811938c82..d5654e26d5bc 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
> @@ -253,7 +253,7 @@ nouveau_fence_done(struct nouveau_fence *fence)
>   	struct nouveau_channel *chan;
>   	unsigned long flags;
>   
> -	if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->base.flags))
> +	if (dma_fence_is_signaled(&fence->base))

This is only correct with commit bbe5679f30d7 ("drm/nouveau: Fix WARN_ON in
nouveau_fence_context_kill()") from drm-misc-fixes, correct?
Re: [PATCH 4/4] drm/nouveau: Check dma_fence in canonical way
Posted by Philipp Stanner 9 months, 2 weeks ago
On Thu, 2025-04-24 at 15:24 +0200, Danilo Krummrich wrote:
> On 4/24/25 3:02 PM, Philipp Stanner wrote:
> > In nouveau_fence_done(), a fence is checked for being signaled by
> > manually evaluating the base fence's bits. This can be done in a
> > canonical manner through dma_fence_is_signaled().
> > 
> > Replace the bit-check with dma_fence_is_signaled().
> > 
> > Signed-off-by: Philipp Stanner <phasta@kernel.org>
> > ---
> >   drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c
> > b/drivers/gpu/drm/nouveau/nouveau_fence.c
> > index fb9811938c82..d5654e26d5bc 100644
> > --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
> > +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
> > @@ -253,7 +253,7 @@ nouveau_fence_done(struct nouveau_fence *fence)
> >   	struct nouveau_channel *chan;
> >   	unsigned long flags;
> >   
> > -	if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence-
> > >base.flags))
> > +	if (dma_fence_is_signaled(&fence->base))
> 
> This is only correct with commit bbe5679f30d7 ("drm/nouveau: Fix
> WARN_ON in
> nouveau_fence_context_kill()") from drm-misc-fixes, correct?

Yup. Otherwise, this series can't be merged anyways, because patch 1
depends on it.

The cover letter says so: "This series is based on this partially
merged series: [1]"

P.
Re: [PATCH 4/4] drm/nouveau: Check dma_fence in canonical way
Posted by Danilo Krummrich 9 months, 2 weeks ago
(+ drm-misc maintainers)

On Thu, Apr 24, 2025 at 03:25:55PM +0200, Philipp Stanner wrote:
> On Thu, 2025-04-24 at 15:24 +0200, Danilo Krummrich wrote:
> > On 4/24/25 3:02 PM, Philipp Stanner wrote:
> > > In nouveau_fence_done(), a fence is checked for being signaled by
> > > manually evaluating the base fence's bits. This can be done in a
> > > canonical manner through dma_fence_is_signaled().
> > > 
> > > Replace the bit-check with dma_fence_is_signaled().
> > > 
> > > Signed-off-by: Philipp Stanner <phasta@kernel.org>
> > > ---
> > >   drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c
> > > b/drivers/gpu/drm/nouveau/nouveau_fence.c
> > > index fb9811938c82..d5654e26d5bc 100644
> > > --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
> > > +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
> > > @@ -253,7 +253,7 @@ nouveau_fence_done(struct nouveau_fence *fence)
> > >   	struct nouveau_channel *chan;
> > >   	unsigned long flags;
> > >   
> > > -	if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence-
> > > >base.flags))
> > > +	if (dma_fence_is_signaled(&fence->base))
> > 
> > This is only correct with commit bbe5679f30d7 ("drm/nouveau: Fix
> > WARN_ON in
> > nouveau_fence_context_kill()") from drm-misc-fixes, correct?
> 
> Yup. Otherwise, this series can't be merged anyways, because patch 1
> depends on it.
> 
> The cover letter says so: "This series is based on this partially
> merged series: [1]"

Well, the series may be based on commit bbe5679f30d7, but all patches from the
series can still be applied independently.

Only patch 4 depends on this commit in terms of correctness.

But that's fine, I think we can get drm-misc-fixes (or the next -rc) backmerged
into drm-misc-next.