<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p style="font-family:Arial;font-size:10pt;color:#0078D7;margin:15pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div dir="auto" style="direction: ltr; margin: 0; padding: 0; font-family: sans-serif; font-size: 11pt; color: black; ">
yes, adding excl fence again as shared one is more reliable<br>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Wednesday, March 18, 2020 4:03:14 PM<br>
<b>To:</b> Pan, Xinhui <Xinhui.Pan@amd.com><br>
<b>Cc:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Liu, Monk <Monk.Liu@amd.com><br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu: fix and cleanup amdgpu_gem_object_close v2</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">The key point is that 10ms should be sufficient that either the move or
<br>
the update is finished.<br>
<br>
One alternative which came to my mind would be to add the exclusive <br>
fence as shared as well in this case.<br>
<br>
This way we won't need to block at all.<br>
<br>
Christian.<br>
<br>
Am 18.03.20 um 09:00 schrieb Pan, Xinhui:<br>
> I wonder if it really fix anything with such small delay. but it should be no harm anyway.<br>
><br>
> Reviewed-by: xinhui pan <xinhui.pan@amd.com><br>
><br>
>> 2020年3月18日 15:51,Christian König <ckoenig.leichtzumerken@gmail.com> 写道:<br>
>><br>
>> Ping? Xinhui can I get an rb for this?<br>
>><br>
>> Thanks,<br>
>> Christian.<br>
>><br>
>> Am 16.03.20 um 14:22 schrieb Christian König:<br>
>>> The problem is that we can't add the clear fence to the BO<br>
>>> when there is an exclusive fence on it since we can't<br>
>>> guarantee the the clear fence will complete after the<br>
>>> exclusive one.<br>
>>><br>
>>> To fix this refactor the function and wait for any potential<br>
>>> exclusive fence with a small timeout before adding the<br>
>>> shared clear fence.<br>
>>><br>
>>> v2: fix warning<br>
>>><br>
>>> Signed-off-by: Christian König <christian.koenig@amd.com><br>
>>> ---<br>
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 43 +++++++++++++++----------<br>
>>>   1 file changed, 26 insertions(+), 17 deletions(-)<br>
>>><br>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
>>> index 5bec66e6b1f8..49c91dac35a0 100644<br>
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
>>> @@ -161,10 +161,11 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj,<br>
>>>      struct amdgpu_bo_list_entry vm_pd;<br>
>>>      struct list_head list, duplicates;<br>
>>> +   struct dma_fence *fence = NULL;<br>
>>>      struct ttm_validate_buffer tv;<br>
>>>      struct ww_acquire_ctx ticket;<br>
>>>      struct amdgpu_bo_va *bo_va;<br>
>>> -   int r;<br>
>>> +   long r;<br>
>>>      INIT_LIST_HEAD(&list);<br>
>>>      INIT_LIST_HEAD(&duplicates);<br>
>>> @@ -178,28 +179,36 @@ void amdgpu_gem_object_close(struct drm_gem_object *obj,<br>
>>>      r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates);<br>
>>>      if (r) {<br>
>>>              dev_err(adev->dev, "leaking bo va because "<br>
>>> -                   "we fail to reserve bo (%d)\n", r);<br>
>>> +                   "we fail to reserve bo (%ld)\n", r);<br>
>>>              return;<br>
>>>      }<br>
>>>      bo_va = amdgpu_vm_bo_find(vm, bo);<br>
>>> -   if (bo_va && --bo_va->ref_count == 0) {<br>
>>> -           amdgpu_vm_bo_rmv(adev, bo_va);<br>
>>> +   if (!bo_va || --bo_va->ref_count)<br>
>>> +           goto out_unlock;<br>
>>>   -         if (amdgpu_vm_ready(vm)) {<br>
>>> -                   struct dma_fence *fence = NULL;<br>
>>> +   amdgpu_vm_bo_rmv(adev, bo_va);<br>
>>> +   if (!amdgpu_vm_ready(vm))<br>
>>> +           goto out_unlock;<br>
>>>   -                 r = amdgpu_vm_clear_freed(adev, vm, &fence);<br>
>>> -                   if (unlikely(r)) {<br>
>>> -                           dev_err(adev->dev, "failed to clear page "<br>
>>> -                                   "tables on GEM object close (%d)\n", r);<br>
>>> -                   }<br>
>>>   -                 if (fence) {<br>
>>> -                           amdgpu_bo_fence(bo, fence, true);<br>
>>> -                           dma_fence_put(fence);<br>
>>> -                   }<br>
>>> -           }<br>
>>> -   }<br>
>>> +   r = amdgpu_vm_clear_freed(adev, vm, &fence);<br>
>>> +   if (r || !fence)<br>
>>> +           goto out_unlock;<br>
>>> +<br>
>>> +   r = dma_resv_wait_timeout_rcu(bo->tbo.base.resv, false, false,<br>
>>> +                                 msecs_to_jiffies(10));<br>
>>> +   if (r == 0)<br>
>>> +           r = -ETIMEDOUT;<br>
>>> +   if (r)<br>
>>> +           goto out_unlock;<br>
>>> +<br>
>>> +   amdgpu_bo_fence(bo, fence, true);<br>
>>> +   dma_fence_put(fence);<br>
>>> +<br>
>>> +out_unlock:<br>
>>> +   if (unlikely(r < 0))<br>
>>> +           dev_err(adev->dev, "failed to clear page "<br>
>>> +                   "tables on GEM object close (%ld)\n", r);<br>
>>>      ttm_eu_backoff_reservation(&ticket, &list);<br>
>>>   }<br>
>>>   <br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>