diff mbox series

drm/etnaviv: avoid cleaning up sched_job when submit succeeded

Message ID 20220429191731.2187339-1-l.stach@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series drm/etnaviv: avoid cleaning up sched_job when submit succeeded | expand

Commit Message

Lucas Stach April 29, 2022, 7:17 p.m. UTC
While the labels may mislead the casual reader, the tail of the function
etnaviv_ioctl_gem_submit is always executed, as a lot of the structures
set up in this function need to be cleaned up regardless of whether the
submit succeeded or failed.

An exception is the newly added drm_sched_job_cleanup, which must only
be called when the submit failed before handing the job to the
scheduler.

Fixes: b827c84f5e84 ("drm/etnaviv: Use scheduler dependency handling")
Reported-by: Michael Walle <michael@walle.cc>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
Daniel, please apply to the appropriate drm-misc branch to make sure
this ends up in the same pullrequest as the offending commit.
---
 drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Daniel Vetter May 4, 2022, 8:14 a.m. UTC | #1
On Fri, Apr 29, 2022 at 09:17:31PM +0200, Lucas Stach wrote:
> While the labels may mislead the casual reader, the tail of the function
> etnaviv_ioctl_gem_submit is always executed, as a lot of the structures
> set up in this function need to be cleaned up regardless of whether the
> submit succeeded or failed.
> 
> An exception is the newly added drm_sched_job_cleanup, which must only
> be called when the submit failed before handing the job to the
> scheduler.
> 
> Fixes: b827c84f5e84 ("drm/etnaviv: Use scheduler dependency handling")
> Reported-by: Michael Walle <michael@walle.cc>
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
> Daniel, please apply to the appropriate drm-misc branch to make sure
> this ends up in the same pullrequest as the offending commit.

Apologies on being behind on emails, I just came to the same conclusion.

Except there's one issue, the error path for sync_file_create is after a
successful call to drm_sched_entity_push_job(), so in that case we must
again _not_ call drm_sched_job_cleanup. So we need to change that goto
err_submit_job to goto err_submit_put and maybe add a comment about why.

Can you pls respin?

Thanks, Daniel

> ---
>  drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> index 98bb5c9239de..bf2a400f59c9 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> @@ -607,7 +607,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
>  	args->fence = submit->out_fence_id;
>  
>  err_submit_job:
> -	drm_sched_job_cleanup(&submit->sched_job);
> +	if (ret)
> +		drm_sched_job_cleanup(&submit->sched_job);
>  err_submit_put:
>  	etnaviv_submit_put(submit);
>  
> -- 
> 2.30.2
>
Lucas Stach May 4, 2022, 9:06 a.m. UTC | #2
Am Mittwoch, dem 04.05.2022 um 10:14 +0200 schrieb Daniel Vetter:
> On Fri, Apr 29, 2022 at 09:17:31PM +0200, Lucas Stach wrote:
> > While the labels may mislead the casual reader, the tail of the function
> > etnaviv_ioctl_gem_submit is always executed, as a lot of the structures
> > set up in this function need to be cleaned up regardless of whether the
> > submit succeeded or failed.
> > 
> > An exception is the newly added drm_sched_job_cleanup, which must only
> > be called when the submit failed before handing the job to the
> > scheduler.
> > 
> > Fixes: b827c84f5e84 ("drm/etnaviv: Use scheduler dependency handling")
> > Reported-by: Michael Walle <michael@walle.cc>
> > Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> > ---
> > Daniel, please apply to the appropriate drm-misc branch to make sure
> > this ends up in the same pullrequest as the offending commit.
> 
> Apologies on being behind on emails, I just came to the same conclusion.
> 
> Except there's one issue, the error path for sync_file_create is after a
> successful call to drm_sched_entity_push_job(), so in that case we must
> again _not_ call drm_sched_job_cleanup. So we need to change that goto
> err_submit_job to goto err_submit_put and maybe add a comment about why.
> 
> Can you pls respin?
> 
Just did that.

In general I don't like this freestanding and quite non-obvious error
handling for the sched_job and would like to move this into the etnaviv
submit_cleanup routine, but to do so I would need a reliable way to
detect if drm_sched_job_init was successfully called on the job. This
seems like a bit more change than I would like to add on top of the
current patches at this point. I'll take a note to clean this up later,
once the regression is fixed.

Regards,
Lucas

> Thanks, Daniel
> 
> > ---
> >  drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> > index 98bb5c9239de..bf2a400f59c9 100644
> > --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> > +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> > @@ -607,7 +607,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
> >  	args->fence = submit->out_fence_id;
> >  
> >  err_submit_job:
> > -	drm_sched_job_cleanup(&submit->sched_job);
> > +	if (ret)
> > +		drm_sched_job_cleanup(&submit->sched_job);
> >  err_submit_put:
> >  	etnaviv_submit_put(submit);
> >  
> > -- 
> > 2.30.2
> > 
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
index 98bb5c9239de..bf2a400f59c9 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
@@ -607,7 +607,8 @@  int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 	args->fence = submit->out_fence_id;
 
 err_submit_job:
-	drm_sched_job_cleanup(&submit->sched_job);
+	if (ret)
+		drm_sched_job_cleanup(&submit->sched_job);
 err_submit_put:
 	etnaviv_submit_put(submit);