<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 3, 2019 at 8:17 PM Dave Airlie <<a href="mailto:airlied@gmail.com">airlied@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, 4 Apr 2019 at 06:54, Chia-I Wu <<a href="mailto:olvaffe@gmail.com" target="_blank">olvaffe@gmail.com</a>> wrote:<br>
><br>
> You could end up having two virgl_hw_res with two different GEM handles pointing to the same kernel GEM object. That might break some assumptions about dependency tracking.<br>
><br>
> For example, when the cmdbuf being built uses a buffer and you want to transfer some more data into the buffer, you normally need to submit the cmdbuf first before starting the transfer. The current code detects that with virgl_drm_res_is_ref, which assumes each kernel GEM object has a unique virgl_hw_res.<br>
><br>
> On Mon, Apr 1, 2019 at 12:37 PM Lepton Wu <<a href="mailto:lepton@chromium.org" target="_blank">lepton@chromium.org</a>> wrote:<br>
>><br>
>><br>
>><br>
>><br>
>> On Wed, Mar 20, 2019 at 3:03 PM Chia-I Wu <<a href="mailto:olvaffe@gmail.com" target="_blank">olvaffe@gmail.com</a>> wrote:<br>
>>><br>
>>> On Mon, Mar 18, 2019 at 2:22 PM Lepton Wu <<a href="mailto:lepton@chromium.org" target="_blank">lepton@chromium.org</a>> wrote:<br>
>>>><br>
>>>> The old code could use gem name as key when inserting it to bo_handles<br>
>>>> hash table while trying to remove it from hash table with bo_handle as<br>
>>>> key in virgl_hw_res_destroy. This triggers use after free. Also, we<br>
>>>> should only reuse resource from bo_handle hash when the handle type is<br>
>>>> FD.<br>
>>><br>
>>> Reuse is not very accurate. Opening a shared handle (flink name) twice gives two GEM handles. Importing an fd handle (prime fd) twice gives the same GEM handle. In all cases, within a virgl_winsys, we want only one GEM handle and only one virgl_resource for each kernel GEM object.<br>
>>><br>
>>> I think the logic should go like:<br>
>>><br>
>>> if (HANDLE_TYPE_SHARED) {<br>
>>> if (bo_names.has(flink_name))<br>
>>> return bo_names[flink_name];<br>
>>> gem_handle = gem_open(flink_name);<br>
>>> } else {<br>
>>> gem_handle = drmPrimeFDToHandle(prime_fd);<br>
>>> }<br>
>>><br>
>>><br>
>>> if (bo_handles.has(gem_handle))<br>
>>> return bo_handles[gem_handle];<br>
>>> bo_handles[gem_handle] = create_new_resource();<br>
>>><br>
>> Hi, the current patch did most of what you said with only one difference: it didn't insert to bo_handles[] hash when the type is HANDLE_TYPE_SHARED.<br>
>> I think this is reasonable since opening a shared handle always get a new gem handle very time and I think it doesn't worth to insert it to bo_handles[] hash.<br>
>> What do you think?<br>
<br>
Just to reinforce this, we can only have one GEM handle for a kernel<br>
object, validation will go wrong and deadlock if we submit two handles<br>
pointing at the same bo.<br>
<br>
Opening a shared handle should not get a new gem handle, if should<br>
return any gem handle that already exists.<br></blockquote><div>I just tried and that is not the case. Sounds like a kernel bug?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Dave.<br>
</blockquote></div></div>