<br><br><div class="gmail_quote">2012/12/1 Daniel Vetter <span dir="ltr"><<a href="mailto:daniel@ffwll.ch" target="_blank">daniel@ffwll.ch</a>></span><br><blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">
<div class="im">On Sat, Dec 1, 2012 at 1:11 PM, Daniel Vetter <<a href="mailto:daniel@ffwll.ch">daniel@ffwll.ch</a>> wrote:<br>
> I've quickly implemented a testcase for what I believe is your<br>
> use-case (i.e. sharing between 3 different open drm files, where we<br>
> close the gem handle in the first fd before we open the flink name<br>
> again using the 3rd drm fd handle). It seems to work.<br>
<br>
</div>Now with link to testcase ....<br>
<a href="http://cgit.freedesktop.org/xorg/app/intel-gpu-tools/commit/?id=6daae8bcb6b4a930c9677f87fa24675581b69072" target="_blank">http://cgit.freedesktop.org/xorg/app/intel-gpu-tools/commit/?id=6daae8bcb6b4a930c9677f87fa24675581b69072</a><br>

<br>
Cheers, Daniel<br></blockquote><div> </div><div> </div><div>I have checked the above testcase and I found out there was my missing point.</div><div>The missing point is that when drm_gem_handle_create() is called by drm_gem_open_ioctl(), obj->handle_count also is increased.</div>
<div>As you mentioned, it seems like that our user side has some bug somewhere. Actually we had tested this on Xorg so this is complicated a little bit.</div><div> </div><div>Thanks for your checking. :)</div><div> </div>
<div>Thanks,</div><div>Inki Dae</div><div> </div><div> </div><div>And below addes my comments on your codes.</div><div> </div><div> /* obj->handle_count = 1, obj->refcount = 1 */<br> ret = ioctl(fd2, DRM_IOCTL_I915_GEM_CREATE, &create);<br>
 assert(ret == 0);</div><div> </div><div> flink.handle = create.handle;<br> /* obj->handle_count = 1, obj->refcount = 2, flink name is allocated */<br> /* flink_ioctl just increases only obj->refcount. */<br> ret = ioctl(fd2, DRM_IOCTL_GEM_FLINK, &flink);<br>
 assert(ret == 0);</div><div> </div><div> <a href="http://gem_open.name">gem_open.name</a> = <a href="http://flink.name">flink.name</a>;<br> /* obj->handle_count = 2, obj->refcount = 3 */<br> /* drm_gem_handle_create() increases obj->handle_count and obj->refcount. This was my missing point. */<br>
 ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &gem_open);<br> assert(ret == 0);<br> assert(gem_open.handle != 0);</div><div> </div><div> /* obj->handle_count = 1, obj->refcount = 2 */<br> /* obj->handle_count = 1 so flink name isn't released */<br>
 close(fd2);<br> fd2 = drm_open_any();</div><div> </div><div> <a href="http://gem_open.name">gem_open.name</a> = <a href="http://flink.name">flink.name</a>;<br> /* obj->handle_count = 2, obj->refcount = 3 */<br> ret = ioctl(fd2, DRM_IOCTL_GEM_OPEN, &gem_open);<br>
 assert(ret == 0);<br> assert(gem_open.handle != 0);<br>}</div><div> </div><div>And codes I added to release gem like below,<br> /* obj->handle_count = 1, obj->refcount = 2 */<br> ioctl(fd2, XXX_GEM_CLOSE, handle)<br>
 /* obj->handle_count = 0, obj->refcount = 1 when flink name is released and then obj->refcount = 0 so gem object can be released */<br> ioctl(fd, XXX_GEM_CLOSE, handle)<br></div><div> </div><div> </div><div> </div>
<div> </div><blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">
<div class="HOEnZb"><div class="h5">--<br>
Daniel Vetter<br>
Software Engineer, Intel Corporation<br>
+41 (0) 79 365 57 48 - <a href="http://blog.ffwll.ch" target="_blank">http://blog.ffwll.ch</a><br>
_______________________________________________<br>
dri-devel mailing list<br>
<a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/dri-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
</div></div></blockquote></div><br>