diff mbox series

drm/syncobj: Don't leak fences when WAIT_FOR_SUBMIT is set

Message ID 20180926071703.15257-1-jason.ekstrand@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/syncobj: Don't leak fences when WAIT_FOR_SUBMIT is set | expand

Commit Message

Jason Ekstrand Sept. 26, 2018, 7:17 a.m. UTC
We attempt to get fences earlier in the hopes that everything will
already have fences and no callbacks will be needed.  If we do succeed
in getting a fence, getting one a second time will result in a duplicate
ref with no unref.  This is causing memory leaks in Vulkan applications
that create a lot of fences; playing for a few hours can, apparently,
bring down the system.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107899
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Cc: stable@vger.kernel.org
---
 drivers/gpu/drm/drm_syncobj.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Chris Wilson Sept. 26, 2018, 8:18 a.m. UTC | #1
Quoting Jason Ekstrand (2018-09-26 08:17:03)
> We attempt to get fences earlier in the hopes that everything will
> already have fences and no callbacks will be needed.  If we do succeed
> in getting a fence, getting one a second time will result in a duplicate
> ref with no unref.  This is causing memory leaks in Vulkan applications
> that create a lot of fences; playing for a few hours can, apparently,
> bring down the system.
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107899
> Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
> Cc: stable@vger.kernel.org
> ---
>  drivers/gpu/drm/drm_syncobj.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index adb3cb27d31e..759278fef35a 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -97,6 +97,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
>  {
>         int ret;
>  
> +       WARN_ON(*fence);

I would have just put if (*fence) return; since the function is tied to
the array_wait implementation.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
Jason Ekstrand Sept. 26, 2018, 9:43 a.m. UTC | #2
On Wed, Sep 26, 2018 at 3:18 AM Chris Wilson <chris@chris-wilson.co.uk>
wrote:

> Quoting Jason Ekstrand (2018-09-26 08:17:03)
> > We attempt to get fences earlier in the hopes that everything will
> > already have fences and no callbacks will be needed.  If we do succeed
> > in getting a fence, getting one a second time will result in a duplicate
> > ref with no unref.  This is causing memory leaks in Vulkan applications
> > that create a lot of fences; playing for a few hours can, apparently,
> > bring down the system.
> >
> > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107899
> > Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
> > Cc: stable@vger.kernel.org
> > ---
> >  drivers/gpu/drm/drm_syncobj.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_syncobj.c
> b/drivers/gpu/drm/drm_syncobj.c
> > index adb3cb27d31e..759278fef35a 100644
> > --- a/drivers/gpu/drm/drm_syncobj.c
> > +++ b/drivers/gpu/drm/drm_syncobj.c
> > @@ -97,6 +97,8 @@ static int
> drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
> >  {
> >         int ret;
> >
> > +       WARN_ON(*fence);
>
> I would have just put if (*fence) return; since the function is tied to
> the array_wait implementation.
>

I considered doing that but marginally liked this better.  If you have a
preference, I'm happy to change itl.

--Jason


> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> -Chris
>
<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Sep 26, 2018 at 3:18 AM Chris Wilson &lt;<a href="mailto:chris@chris-wilson.co.uk">chris@chris-wilson.co.uk</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Quoting Jason Ekstrand (2018-09-26 08:17:03)<br>
&gt; We attempt to get fences earlier in the hopes that everything will<br>
&gt; already have fences and no callbacks will be needed.  If we do succeed<br>
&gt; in getting a fence, getting one a second time will result in a duplicate<br>
&gt; ref with no unref.  This is causing memory leaks in Vulkan applications<br>
&gt; that create a lot of fences; playing for a few hours can, apparently,<br>
&gt; bring down the system.<br>
&gt; <br>
&gt; Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=107899" rel="noreferrer" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=107899</a><br>
&gt; Signed-off-by: Jason Ekstrand &lt;<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>&gt;<br>
&gt; Cc: <a href="mailto:stable@vger.kernel.org" target="_blank">stable@vger.kernel.org</a><br>
&gt; ---<br>
&gt;  drivers/gpu/drm/drm_syncobj.c | 5 +++++<br>
&gt;  1 file changed, 5 insertions(+)<br>
&gt; <br>
&gt; diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c<br>
&gt; index adb3cb27d31e..759278fef35a 100644<br>
&gt; --- a/drivers/gpu/drm/drm_syncobj.c<br>
&gt; +++ b/drivers/gpu/drm/drm_syncobj.c<br>
&gt; @@ -97,6 +97,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,<br>
&gt;  {<br>
&gt;         int ret;<br>
&gt;  <br>
&gt; +       WARN_ON(*fence);<br>
<br>
I would have just put if (*fence) return; since the function is tied to<br>
the array_wait implementation.<br></blockquote><div><br></div><div>I considered doing that but marginally liked this better.  If you have a preference, I&#39;m happy to change itl.</div><div><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Reviewed-by: Chris Wilson &lt;<a href="mailto:chris@chris-wilson.co.uk" target="_blank">chris@chris-wilson.co.uk</a>&gt;<br>
-Chris<br>
</blockquote></div></div>
Chris Wilson Sept. 26, 2018, 9:50 a.m. UTC | #3
Quoting Jason Ekstrand (2018-09-26 10:43:59)
> On Wed, Sep 26, 2018 at 3:18 AM Chris Wilson <chris@chris-wilson.co.uk> wrote:
> 
>     Quoting Jason Ekstrand (2018-09-26 08:17:03)
>     > We attempt to get fences earlier in the hopes that everything will
>     > already have fences and no callbacks will be needed.  If we do succeed
>     > in getting a fence, getting one a second time will result in a duplicate
>     > ref with no unref.  This is causing memory leaks in Vulkan applications
>     > that create a lot of fences; playing for a few hours can, apparently,
>     > bring down the system.
>     >
>     > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107899
>     > Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
>     > Cc: stable@vger.kernel.org
>     > ---
>     >  drivers/gpu/drm/drm_syncobj.c | 5 +++++
>     >  1 file changed, 5 insertions(+)
>     >
>     > diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/
>     drm_syncobj.c
>     > index adb3cb27d31e..759278fef35a 100644
>     > --- a/drivers/gpu/drm/drm_syncobj.c
>     > +++ b/drivers/gpu/drm/drm_syncobj.c
>     > @@ -97,6 +97,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct
>     drm_syncobj *syncobj,
>     >  {
>     >         int ret;
>     > 
>     > +       WARN_ON(*fence);
> 
>     I would have just put if (*fence) return; since the function is tied to
>     the array_wait implementation.
> 
> 
> I considered doing that but marginally liked this better.  If you have a
> preference, I'm happy to change itl.

Patch works, the difference is insignificant, land the patch and close
the bug.
-Chris
Sean Paul Sept. 26, 2018, 2:55 p.m. UTC | #4
On Wed, Sep 26, 2018 at 02:17:03AM -0500, Jason Ekstrand wrote:
> We attempt to get fences earlier in the hopes that everything will
> already have fences and no callbacks will be needed.  If we do succeed
> in getting a fence, getting one a second time will result in a duplicate
> ref with no unref.  This is causing memory leaks in Vulkan applications
> that create a lot of fences; playing for a few hours can, apparently,
> bring down the system.
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107899
> Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>

Pushed to drm-misc-fixes, thanks!

Sean

> Cc: stable@vger.kernel.org
> ---
>  drivers/gpu/drm/drm_syncobj.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index adb3cb27d31e..759278fef35a 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -97,6 +97,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
>  {
>  	int ret;
>  
> +	WARN_ON(*fence);
> +
>  	*fence = drm_syncobj_fence_get(syncobj);
>  	if (*fence)
>  		return 1;
> @@ -743,6 +745,9 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
>  
>  	if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
>  		for (i = 0; i < count; ++i) {
> +			if (entries[i].fence)
> +				continue;
> +
>  			drm_syncobj_fence_get_or_add_callback(syncobjs[i],
>  							      &entries[i].fence,
>  							      &entries[i].syncobj_cb,
> -- 
> 2.17.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index adb3cb27d31e..759278fef35a 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -97,6 +97,8 @@  static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
 {
 	int ret;
 
+	WARN_ON(*fence);
+
 	*fence = drm_syncobj_fence_get(syncobj);
 	if (*fence)
 		return 1;
@@ -743,6 +745,9 @@  static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
 
 	if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
 		for (i = 0; i < count; ++i) {
+			if (entries[i].fence)
+				continue;
+
 			drm_syncobj_fence_get_or_add_callback(syncobjs[i],
 							      &entries[i].fence,
 							      &entries[i].syncobj_cb,