<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 2022-04-28 09:51, Felix Kuehling
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:a214a2f2-c790-a76d-5b67-0712341ce69a@amd.com">Am
      2022-04-27 um 19:07 schrieb Philip Yang:
      <br>
      <blockquote type="cite">Otherwise userspace resubmit the BOs again
        will trigger kernel WARNING
        <br>
        and fail the command submission.
        <br>
        <br>
        Signed-off-by: Philip Yang <a class="moz-txt-link-rfc2396E" href="mailto:Philip.Yang@amd.com"><Philip.Yang@amd.com></a>
        <br>
        ---
        <br>
          drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 18 +++++++++++++++---
        <br>
          1 file changed, 15 insertions(+), 3 deletions(-)
        <br>
        <br>
        diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
        b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
        <br>
        index ea28942b0ede..44dcbef80229 100644
        <br>
        --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
        <br>
        +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
        <br>
        @@ -550,7 +550,7 @@ static int amdgpu_cs_parser_bos(struct
        amdgpu_cs_parser *p,
        <br>
      </blockquote>
      <br>
      There is another error case a few lines up, if kvmalloc_array
      fails. I think that needs to be handled with a goto
      out_free_user_pages as well.
      <br>
      <br>
    </blockquote>
    yes, thanks for catching this, I will send another patch to fix this
    as I have merged this patch.<br>
    <blockquote type="cite" cite="mid:a214a2f2-c790-a76d-5b67-0712341ce69a@amd.com">
      <br>
      <blockquote type="cite">          if (r) {
        <br>
                      kvfree(e->user_pages);
        <br>
                      e->user_pages = NULL;
        <br>
      </blockquote>
      <br>
      The above two lines can be removed. The loop under
      out_free_user_pages should handle this.
      <br>
    </blockquote>
    <p>No, out_free_user_pages will call
      amdgpu_ttm_tt_get_user_pages_done with gtt->range is NULL for
      this BO, and trigger kernel WARNING.<br>
    </p>
    <p>Thanks,</p>
    <p>Philip<br>
    </p>
    <blockquote type="cite" cite="mid:a214a2f2-c790-a76d-5b67-0712341ce69a@amd.com">
      <br>
      Regards,
      <br>
        Felix
      <br>
      <br>
      <br>
      <blockquote type="cite">-            return r;
        <br>
        +            goto out_free_user_pages;
        <br>
                  }
        <br>
                    for (i = 0; i < bo->tbo.ttm->num_pages;
        i++) {
        <br>
        @@ -567,7 +567,7 @@ static int amdgpu_cs_parser_bos(struct
        amdgpu_cs_parser *p,
        <br>
              if (unlikely(r != 0)) {
        <br>
                  if (r != -ERESTARTSYS)
        <br>
                      DRM_ERROR("ttm_eu_reserve_buffers failed.\n");
        <br>
        -        goto out;
        <br>
        +        goto out_free_user_pages;
        <br>
              }
        <br>
                amdgpu_bo_list_for_each_entry(e, p->bo_list) {
        <br>
        @@ -649,7 +649,19 @@ static int amdgpu_cs_parser_bos(struct
        amdgpu_cs_parser *p,
        <br>
                  }
        <br>
                  ttm_eu_backoff_reservation(&p->ticket,
        &p->validated);
        <br>
              }
        <br>
        -out:
        <br>
        +
        <br>
        +out_free_user_pages:
        <br>
        +    if (r) {
        <br>
        +        amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list)
        {
        <br>
        +            struct amdgpu_bo *bo =
        ttm_to_amdgpu_bo(e->tv.bo);
        <br>
        +
        <br>
        +            if (!e->user_pages)
        <br>
        +                continue;
        <br>
        +            amdgpu_ttm_tt_get_user_pages_done(bo->tbo.ttm);
        <br>
        +            kvfree(e->user_pages);
        <br>
        +            e->user_pages = NULL;
        <br>
        +        }
        <br>
        +    }
        <br>
              return r;
        <br>
          }
        <br>
          </blockquote>
    </blockquote>
  </body>
</html>