linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] drm/panfrost: fix ref count leak in panfrost_job_hw_submit
@ 2020-06-14 11:31 Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2020-06-14 11:31 UTC (permalink / raw)
  To: Navid Emamdoost, dri-devel
  Cc: Navid Emamdoost, Kangjie Lu, Stephen McCamant, Qiushi Wu,
	Alyssa Rosenzweig, Daniel Vetter, David Airlie, Rob Herring,
	Steven Price, Tomeu Vizoso, kernel-janitors, linux-kernel

> in panfrost_job_hw_submit, …

* Can the term “reference count” become relevant also for this commit message
  besides other possible adjustments?

* Would you like to add the tag “Fixes”?


…
> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c
> @@ -184,6 +183,9 @@  static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>  				job, js, jc_head);
>
>  	job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START);
> +out:
> +	pm_runtime_put_sync_autosuspend(pfdev->dev);
> +	return;
>  }
…

Perhaps use the label “put_sync” instead?

Regards,
Markus

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/panfrost: fix ref count leak in panfrost_job_hw_submit
  2020-07-09 15:44 ` Rob Herring
@ 2020-07-09 15:59   ` Steven Price
  0 siblings, 0 replies; 7+ messages in thread
From: Steven Price @ 2020-07-09 15:59 UTC (permalink / raw)
  To: Rob Herring, Navid Emamdoost
  Cc: Tomeu Vizoso, Alyssa Rosenzweig, David Airlie, Daniel Vetter,
	dri-devel, linux-kernel, Navid Emamdoost, wu000273, kjlu,
	Stephen McCamant

On 09/07/2020 16:44, Rob Herring wrote:
> On Sun, Jun 14, 2020 at 12:27 AM Navid Emamdoost
> <navid.emamdoost@gmail.com> wrote:
>>
>> in panfrost_job_hw_submit, pm_runtime_get_sync is called which
>> increments the counter even in case of failure, leading to incorrect
>> ref count. In case of failure, decrement the ref count before returning.
>>
>> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
>> ---
>>   drivers/gpu/drm/panfrost/panfrost_job.c | 8 +++++---
>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
>> index 7914b1570841..89ac84667eb1 100644
>> --- a/drivers/gpu/drm/panfrost/panfrost_job.c
>> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c
>> @@ -147,11 +147,10 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>>
>>          ret = pm_runtime_get_sync(pfdev->dev);
>>          if (ret < 0)
>> -               return;
>> +               goto out;
> 
> If the get failed, I don't think we want to do a put.

The pm_runtime_get_sync() does actually always increment the reference 
(even when returning a failure), but actually I don't think we want it 
here anyway, as I think I explained before[1].
  [1] 
https://lore.kernel.org/dri-devel/272650ba-2c44-9084-7829-b04023eba723@arm.com
> 
>>
>>          if (WARN_ON(job_read(pfdev, JS_COMMAND_NEXT(js)))) {
>> -               pm_runtime_put_sync_autosuspend(pfdev->dev);

This is a correct change - we don't want the put here. (Although this 
should never happen).

>> -               return;
>> +               goto out;
>>          }
>>
>>          cfg = panfrost_mmu_as_get(pfdev, &job->file_priv->mmu);
>> @@ -184,6 +183,9 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>>                                  job, js, jc_head);
>>
>>          job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START);
> 
> So we start the job here and then...
> 
>> +out:
>> +       pm_runtime_put_sync_autosuspend(pfdev->dev);
> 
> ...turn off clocks/power here. Typically, you'd be fine as autosuspend
> has a delay by default, but userspace is free to change the delay to
> 0.
> 
>> +       return;

A return at the end of the function with no argument is pointless.

Steve

>>   }
>>
>>   static void panfrost_acquire_object_fences(struct drm_gem_object **bos,
>> --
>> 2.17.1
>>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/panfrost: fix ref count leak in panfrost_job_hw_submit
  2020-06-14  6:27 Navid Emamdoost
  2020-07-07  2:31 ` Alyssa Rosenzweig
@ 2020-07-09 15:44 ` Rob Herring
  2020-07-09 15:59   ` Steven Price
  1 sibling, 1 reply; 7+ messages in thread
From: Rob Herring @ 2020-07-09 15:44 UTC (permalink / raw)
  To: Navid Emamdoost
  Cc: Tomeu Vizoso, Steven Price, Alyssa Rosenzweig, David Airlie,
	Daniel Vetter, dri-devel, linux-kernel, Navid Emamdoost,
	wu000273, kjlu, Stephen McCamant

On Sun, Jun 14, 2020 at 12:27 AM Navid Emamdoost
<navid.emamdoost@gmail.com> wrote:
>
> in panfrost_job_hw_submit, pm_runtime_get_sync is called which
> increments the counter even in case of failure, leading to incorrect
> ref count. In case of failure, decrement the ref count before returning.
>
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  drivers/gpu/drm/panfrost/panfrost_job.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
> index 7914b1570841..89ac84667eb1 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_job.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c
> @@ -147,11 +147,10 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>
>         ret = pm_runtime_get_sync(pfdev->dev);
>         if (ret < 0)
> -               return;
> +               goto out;

If the get failed, I don't think we want to do a put.

>
>         if (WARN_ON(job_read(pfdev, JS_COMMAND_NEXT(js)))) {
> -               pm_runtime_put_sync_autosuspend(pfdev->dev);
> -               return;
> +               goto out;
>         }
>
>         cfg = panfrost_mmu_as_get(pfdev, &job->file_priv->mmu);
> @@ -184,6 +183,9 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>                                 job, js, jc_head);
>
>         job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START);

So we start the job here and then...

> +out:
> +       pm_runtime_put_sync_autosuspend(pfdev->dev);

...turn off clocks/power here. Typically, you'd be fine as autosuspend
has a delay by default, but userspace is free to change the delay to
0.

> +       return;
>  }
>
>  static void panfrost_acquire_object_fences(struct drm_gem_object **bos,
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/panfrost: fix ref count leak in panfrost_job_hw_submit
  2020-06-14  6:27 Navid Emamdoost
@ 2020-07-07  2:31 ` Alyssa Rosenzweig
  2020-07-09 15:44 ` Rob Herring
  1 sibling, 0 replies; 7+ messages in thread
From: Alyssa Rosenzweig @ 2020-07-07  2:31 UTC (permalink / raw)
  To: Navid Emamdoost
  Cc: Rob Herring, Tomeu Vizoso, Steven Price, David Airlie,
	Daniel Vetter, dri-devel, linux-kernel, emamd001, wu000273, kjlu,
	smccaman

Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>

On Sun, Jun 14, 2020 at 01:27:30AM -0500, Navid Emamdoost wrote:
> in panfrost_job_hw_submit, pm_runtime_get_sync is called which
> increments the counter even in case of failure, leading to incorrect
> ref count. In case of failure, decrement the ref count before returning.
> 
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  drivers/gpu/drm/panfrost/panfrost_job.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
> index 7914b1570841..89ac84667eb1 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_job.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c
> @@ -147,11 +147,10 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>  
>  	ret = pm_runtime_get_sync(pfdev->dev);
>  	if (ret < 0)
> -		return;
> +		goto out;
>  
>  	if (WARN_ON(job_read(pfdev, JS_COMMAND_NEXT(js)))) {
> -		pm_runtime_put_sync_autosuspend(pfdev->dev);
> -		return;
> +		goto out;
>  	}
>  
>  	cfg = panfrost_mmu_as_get(pfdev, &job->file_priv->mmu);
> @@ -184,6 +183,9 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>  				job, js, jc_head);
>  
>  	job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START);
> +out:
> +	pm_runtime_put_sync_autosuspend(pfdev->dev);
> +	return;
>  }
>  
>  static void panfrost_acquire_object_fences(struct drm_gem_object **bos,
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/panfrost: fix ref count leak in panfrost_job_hw_submit
@ 2020-06-14 11:31 Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2020-06-14 11:31 UTC (permalink / raw)
  To: Navid Emamdoost, dri-devel
  Cc: Navid Emamdoost, Kangjie Lu, Stephen McCamant, Qiushi Wu,
	Alyssa Rosenzweig, Daniel Vetter, David Airlie, Rob Herring,
	Steven Price, Tomeu Vizoso, kernel-janitors, linux-kernel

> in panfrost_job_hw_submit, …

* Can the term “reference count” become relevant also for this commit message
  besides other possible adjustments?

* Would you like to add the tag “Fixes”?


…
> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c
> @@ -184,6 +183,9 @@  static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>  				job, js, jc_head);
>
>  	job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START);
> +out:
> +	pm_runtime_put_sync_autosuspend(pfdev->dev);
> +	return;
>  }
…

Perhaps use the label “put_sync” instead?

Regards,
Markus

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/panfrost: fix ref count leak in panfrost_job_hw_submit
@ 2020-06-14 11:31 Markus Elfring
  0 siblings, 0 replies; 7+ messages in thread
From: Markus Elfring @ 2020-06-14 11:31 UTC (permalink / raw)
  To: Navid Emamdoost, dri-devel
  Cc: Navid Emamdoost, Kangjie Lu, Stephen McCamant, Qiushi Wu,
	Alyssa Rosenzweig, Daniel Vetter, David Airlie, Rob Herring,
	Steven Price, Tomeu Vizoso, kernel-janitors, linux-kernel

> in panfrost_job_hw_submit, …

* Can the term “reference count” become relevant also for this commit message
  besides other possible adjustments?

* Would you like to add the tag “Fixes”?


…
> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c
> @@ -184,6 +183,9 @@  static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
>  				job, js, jc_head);
>
>  	job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START);
> +out:
> +	pm_runtime_put_sync_autosuspend(pfdev->dev);
> +	return;
>  }
…

Perhaps use the label “put_sync” instead?

Regards,
Markus

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] drm/panfrost: fix ref count leak in panfrost_job_hw_submit
@ 2020-06-14  6:27 Navid Emamdoost
  2020-07-07  2:31 ` Alyssa Rosenzweig
  2020-07-09 15:44 ` Rob Herring
  0 siblings, 2 replies; 7+ messages in thread
From: Navid Emamdoost @ 2020-06-14  6:27 UTC (permalink / raw)
  To: Rob Herring, Tomeu Vizoso, Steven Price, Alyssa Rosenzweig,
	David Airlie, Daniel Vetter, dri-devel, linux-kernel
  Cc: emamd001, wu000273, kjlu, smccaman, Navid Emamdoost

in panfrost_job_hw_submit, pm_runtime_get_sync is called which
increments the counter even in case of failure, leading to incorrect
ref count. In case of failure, decrement the ref count before returning.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/gpu/drm/panfrost/panfrost_job.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c
index 7914b1570841..89ac84667eb1 100644
--- a/drivers/gpu/drm/panfrost/panfrost_job.c
+++ b/drivers/gpu/drm/panfrost/panfrost_job.c
@@ -147,11 +147,10 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
 
 	ret = pm_runtime_get_sync(pfdev->dev);
 	if (ret < 0)
-		return;
+		goto out;
 
 	if (WARN_ON(job_read(pfdev, JS_COMMAND_NEXT(js)))) {
-		pm_runtime_put_sync_autosuspend(pfdev->dev);
-		return;
+		goto out;
 	}
 
 	cfg = panfrost_mmu_as_get(pfdev, &job->file_priv->mmu);
@@ -184,6 +183,9 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
 				job, js, jc_head);
 
 	job_write(pfdev, JS_COMMAND_NEXT(js), JS_COMMAND_START);
+out:
+	pm_runtime_put_sync_autosuspend(pfdev->dev);
+	return;
 }
 
 static void panfrost_acquire_object_fences(struct drm_gem_object **bos,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-07-09 15:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-14 11:31 [PATCH] drm/panfrost: fix ref count leak in panfrost_job_hw_submit Markus Elfring
  -- strict thread matches above, loose matches on Subject: below --
2020-06-14 11:31 Markus Elfring
2020-06-14 11:31 Markus Elfring
2020-06-14  6:27 Navid Emamdoost
2020-07-07  2:31 ` Alyssa Rosenzweig
2020-07-09 15:44 ` Rob Herring
2020-07-09 15:59   ` Steven Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).