<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 6/22/2021 12:36 PM, Christian König
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:c28d9c08-0ab8-780a-ae44-e444ae49500e@gmail.com">
      
      Am 22.06.21 um 12:30 schrieb Das, Nirmoy:<br>
      <blockquote type="cite" cite="mid:564b4de5-b1fd-283e-85b8-7819c24bca10@amd.com">
        <p>On 6/22/2021 10:36 AM, Christian König wrote:<br>
        </p>
        <blockquote type="cite" cite="mid:9ff705c2-a4e4-dc37-041a-66c490d8f7ad@gmail.com">Am
          22.06.21 um 09:39 schrieb Das, Nirmoy: <br>
          <blockquote type="cite"> <br>
            On 6/22/2021 9:03 AM, Christian König wrote: <br>
            <blockquote type="cite"> <br>
              <br>
              Am 22.06.21 um 08:57 schrieb Nirmoy Das: <br>
              <blockquote type="cite">Cleanup code related to vm pasid
                by adding helper functions. <br>
                <br>
                Signed-off-by: Nirmoy Das <a class="moz-txt-link-rfc2396E" href="mailto:nirmoy.das@amd.com" moz-do-not-send="true"><nirmoy.das@amd.com></a>
                <br>
                --- <br>
                  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 105
                ++++++++++++------------- <br>
                  1 file changed, 50 insertions(+), 55 deletions(-) <br>
                <br>
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c <br>
                index 63975bda8e76..6e476b173cbb 100644 <br>
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c <br>
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c <br>
                @@ -87,6 +87,46 @@ struct amdgpu_prt_cb { <br>
                      struct dma_fence_cb cb; <br>
                  }; <br>
                <br>
                +static int amdgpu_vm_pasid_alloc(struct amdgpu_device
                *adev, <br>
                +                 struct amdgpu_vm *vm, <br>
                +                 unsigned int pasid, <br>
                +                 unsigned int *vm_pasid) <br>
                +{ <br>
                +    unsigned long flags; <br>
                +    int r; <br>
                + <br>
                +    if (!pasid) <br>
                +        return 0; <br>
                + <br>
                +   
                spin_lock_irqsave(&adev->vm_manager.pasid_lock,
                flags); <br>
                +    r = idr_alloc(&adev->vm_manager.pasid_idr,
                vm, pasid, pasid + 1, <br>
                +              GFP_ATOMIC); <br>
                +
                spin_unlock_irqrestore(&adev->vm_manager.pasid_lock,
                flags); <br>
                +    if (r < 0) <br>
                +        return r; <br>
                +    if (vm_pasid) <br>
                +        *vm_pasid = pasid; <br>
                + <br>
              </blockquote>
              <br>
              Ok the more I read from this patch the less it makes
              sense. <br>
              <br>
              We don't allocate the passid here, we just set it up in
              the idr. <br>
              <br>
              What we could do is to replace the idr with an xarray,
              that would certainly make more sense than this here. <br>
            </blockquote>
            <br>
            <br>
            xarray looks great, with that we don't need pasid_lock
            either. <br>
          </blockquote>
          <br>
          You still need the lock to protect against VM destruction
          while looking things up, but you could switch to RCU for this
          instead. <br>
        </blockquote>
        <p><br>
        </p>
        <font face="Helvetica, Arial, sans-serif">xarray has <span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
            normal; font-variant-ligatures: normal; font-variant-caps:
            normal; font-weight: 400; letter-spacing: normal;
            text-align: start; text-indent: 0px; text-transform: none;
            white-space: normal; word-spacing: 0px;
            -webkit-text-stroke-width: 0px; background-color: rgb(252,
            252, 252); text-decoration-thickness: initial;
            text-decoration-style: initial; text-decoration-color:
            initial; display: inline !important; float: none;">xa_{lock|unloack}_irqsave()
            and </span><span style="color: rgb(0, 0, 0); font-size:
            16px; font-style: normal; font-variant-ligatures: normal;
            font-variant-caps: normal; font-weight: 400; letter-spacing:
            normal; text-align: start; text-indent: 0px; text-transform:
            none; white-space: normal; word-spacing: 0px;
            -webkit-text-stroke-width: 0px; background-color: rgb(252,
            252, 252); text-decoration-thickness: initial;
            text-decoration-style: initial; text-decoration-color:
            initial; display: inline !important; float: none;">adev->vm_manager.pasid_xa
            will exist till devices's lifetime.</span></font></blockquote>
      <br>
      That's just a wrapper around the lock.<br>
      <br>
      <blockquote type="cite" cite="mid:564b4de5-b1fd-283e-85b8-7819c24bca10@amd.com"><font face="Helvetica, Arial, sans-serif"><span style="color: rgb(0,
            0, 0); font-size: 16px; font-style: normal;
            font-variant-ligatures: normal; font-variant-caps: normal;
            font-weight: 400; letter-spacing: normal; text-align: start;
            text-indent: 0px; text-transform: none; white-space: normal;
            word-spacing: 0px; -webkit-text-stroke-width: 0px;
            background-color: rgb(252, 252, 252);
            text-decoration-thickness: initial; text-decoration-style:
            initial; text-decoration-color: initial; display: inline
            !important; float: none;">So I am thinking something like:<br>
          </span><br>
        </font>
        <p><font face="Helvetica, Arial, sans-serif">amdgpu_vm_pasid_insert()
            <br>
          </font></p>
        <p><font face="Helvetica, Arial, sans-serif">{</font></p>
        <p><font face="Helvetica, Arial, sans-serif">...<br>
          </font></p>
        <font face="Helvetica, Arial, sans-serif"><span style="color:
            rgb(0, 0, 0); font-size: 16px; font-style: normal;
            font-variant-ligatures: normal; font-variant-caps: normal;
            font-weight: 400; letter-spacing: normal; text-align: start;
            text-indent: 0px; text-transform: none; white-space: normal;
            word-spacing: 0px; -webkit-text-stroke-width: 0px;
            background-color: rgb(252, 252, 252);
            text-decoration-thickness: initial; text-decoration-style:
            initial; text-decoration-color: initial; display: inline
            !important; float: none;"> <span style="color: rgb(0, 0,
              0); font-size: 16px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: 400; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;">xa_lock_irqsave(</span></span><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
            normal; font-variant-ligatures: normal; font-variant-caps:
            normal; font-weight: 400; letter-spacing: normal;
            text-align: start; text-indent: 0px; text-transform: none;
            white-space: normal; word-spacing: 0px;
            -webkit-text-stroke-width: 0px; background-color: rgb(252,
            252, 252); text-decoration-thickness: initial;
            text-decoration-style: initial; text-decoration-color:
            initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
              normal; font-variant-ligatures: normal; font-variant-caps:
              normal; font-weight: 400; letter-spacing: normal;
              text-align: start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;">adev->vm_manager.pasids,
              flags)</span></span><br>
          <span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
            normal; font-variant-ligatures: normal; font-variant-caps:
            normal; font-weight: 400; letter-spacing: normal;
            text-align: start; text-indent: 0px; text-transform: none;
            white-space: normal; word-spacing: 0px;
            -webkit-text-stroke-width: 0px; background-color: rgb(252,
            252, 252); text-decoration-thickness: initial;
            text-decoration-style: initial; text-decoration-color:
            initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
              normal; font-variant-ligatures: normal; font-variant-caps:
              normal; font-weight: 400; letter-spacing: normal;
              text-align: start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;">r =
              xa_store(&adev->vm_manager.pasids, pasid, vm,
              GFP_ATOMIC);</span></span><br>
          <span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
            normal; font-variant-ligatures: normal; font-variant-caps:
            normal; font-weight: 400; letter-spacing: normal;
            text-align: start; text-indent: 0px; text-transform: none;
            white-space: normal; word-spacing: 0px;
            -webkit-text-stroke-width: 0px; background-color: rgb(252,
            252, 252); text-decoration-thickness: initial;
            text-decoration-style: initial; text-decoration-color:
            initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
              normal; font-variant-ligatures: normal; font-variant-caps:
              normal; font-weight: 400; letter-spacing: normal;
              text-align: start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"> <span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;"></span></span></span></span><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
            normal; font-variant-ligatures: normal; font-variant-caps:
            normal; font-weight: 400; letter-spacing: normal;
            text-align: start; text-indent: 0px; text-transform: none;
            white-space: normal; word-spacing: 0px;
            -webkit-text-stroke-width: 0px; background-color: rgb(252,
            252, 252); text-decoration-thickness: initial;
            text-decoration-style: initial; text-decoration-color:
            initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
              normal; font-variant-ligatures: normal; font-variant-caps:
              normal; font-weight: 400; letter-spacing: normal;
              text-align: start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;">xa_unlock_irqsave(</span></span><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;">adev->vm_manager.pasids,
                  flags)</span></span></span></span></font></blockquote>
      <br>
      It would be really nice if we could avoid the GFP_ATOMIC here, but
      not much of a problem since we had that before.<br>
    </blockquote>
    <p><br>
    </p>
    <p>I think it is possible as I think  only amdgpu_vm_handle_fault()
      runs in interrupt context which tries to find a vm ptr not store
      it.</p>
    <p><br>
    </p>
    <blockquote type="cite" cite="mid:c28d9c08-0ab8-780a-ae44-e444ae49500e@gmail.com"> <br>
      <blockquote type="cite" cite="mid:564b4de5-b1fd-283e-85b8-7819c24bca10@amd.com">
        <p><font face="Helvetica, Arial, sans-serif"><span style="color:
              rgb(0, 0, 0); font-size: 16px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: 400; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;"></span>}</font></p>
        <p><font face="Helvetica, Arial, sans-serif"><span style="color:
              rgb(0, 0, 0); font-size: 16px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: 400; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;">amdgpu_vm_pasid_remove()</span></span></span></font></p>
        <p><font face="Helvetica, Arial, sans-serif"><span style="color:
              rgb(0, 0, 0); font-size: 16px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: 400; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;">{</span></span></span></font></p>
        <p><font face="Helvetica, Arial, sans-serif"><span style="color:
              rgb(0, 0, 0); font-size: 16px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: 400; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;">....<br>
                </span></span></span></font></p>
        <p><font face="Helvetica, Arial, sans-serif"><span style="color:
              rgb(0, 0, 0); font-size: 16px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: 400; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;">xa_lock_irqsave(</span></span><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;">adev->vm_manager.pasids,
                  flags)</span></span><br>
              <span style="color: rgb(0, 0, 0); font-size: 16px;
                font-style: normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;">xa_erase(&adev->vm_manager.pasids,
                  pasid);</span></span><br>
              <span style="color: rgb(0, 0, 0); font-size: 16px;
                font-style: normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                    font-style: normal; font-variant-ligatures: normal;
                    font-variant-caps: normal; font-weight: 400;
                    letter-spacing: normal; text-align: start;
                    text-indent: 0px; text-transform: none; white-space:
                    normal; word-spacing: 0px;
                    -webkit-text-stroke-width: 0px; background-color:
                    rgb(252, 252, 252); text-decoration-thickness:
                    initial; text-decoration-style: initial;
                    text-decoration-color: initial; display: inline
                    !important; float: none;"> <span style="color:
                      rgb(0, 0, 0); font-size: 16px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: 400; letter-spacing: normal;
                      text-align: start; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; -webkit-text-stroke-width: 0px;
                      background-color: rgb(252, 252, 252);
                      text-decoration-thickness: initial;
                      text-decoration-style: initial;
                      text-decoration-color: initial; display: inline
                      !important; float: none;"></span></span></span></span><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                  font-style: normal; font-variant-ligatures: normal;
                  font-variant-caps: normal; font-weight: 400;
                  letter-spacing: normal; text-align: start;
                  text-indent: 0px; text-transform: none; white-space:
                  normal; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; background-color: rgb(252, 252, 252);
                  text-decoration-thickness: initial;
                  text-decoration-style: initial; text-decoration-color:
                  initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px;
                    font-style: normal; font-variant-ligatures: normal;
                    font-variant-caps: normal; font-weight: 400;
                    letter-spacing: normal; text-align: start;
                    text-indent: 0px; text-transform: none; white-space:
                    normal; word-spacing: 0px;
                    -webkit-text-stroke-width: 0px; background-color:
                    rgb(252, 252, 252); text-decoration-thickness:
                    initial; text-decoration-style: initial;
                    text-decoration-color: initial; display: inline
                    !important; float: none;"><span style="color: rgb(0,
                      0, 0); font-size: 16px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: 400; letter-spacing: normal;
                      text-align: start; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; -webkit-text-stroke-width: 0px;
                      background-color: rgb(252, 252, 252);
                      text-decoration-thickness: initial;
                      text-decoration-style: initial;
                      text-decoration-color: initial; display: inline
                      !important; float: none;">xa_unlock_irqsave(</span></span><span style="color: rgb(0, 0, 0); font-size: 16px;
                    font-style: normal; font-variant-ligatures: normal;
                    font-variant-caps: normal; font-weight: 400;
                    letter-spacing: normal; text-align: start;
                    text-indent: 0px; text-transform: none; white-space:
                    normal; word-spacing: 0px;
                    -webkit-text-stroke-width: 0px; background-color:
                    rgb(252, 252, 252); text-decoration-thickness:
                    initial; text-decoration-style: initial;
                    text-decoration-color: initial; display: inline
                    !important; float: none;"><span style="color: rgb(0,
                      0, 0); font-size: 16px; font-style: normal;
                      font-variant-ligatures: normal; font-variant-caps:
                      normal; font-weight: 400; letter-spacing: normal;
                      text-align: start; text-indent: 0px;
                      text-transform: none; white-space: normal;
                      word-spacing: 0px; -webkit-text-stroke-width: 0px;
                      background-color: rgb(252, 252, 252);
                      text-decoration-thickness: initial;
                      text-decoration-style: initial;
                      text-decoration-color: initial; display: inline
                      !important; float: none;">adev->vm_manager.pasids,
                      flags)</span></span></span></span> </span></font></p>
        <p><font face="Helvetica, Arial, sans-serif"><span style="color:
              rgb(0, 0, 0); font-size: 16px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: 400; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;">}</span></font></p>
        <p><font face="Helvetica, Arial, sans-serif"><br>
            <span style="color: rgb(0, 0, 0); font-size: 16px;
              font-style: normal; font-variant-ligatures: normal;
              font-variant-caps: normal; font-weight: 400;
              letter-spacing: normal; text-align: start; text-indent:
              0px; text-transform: none; white-space: normal;
              word-spacing: 0px; -webkit-text-stroke-width: 0px;
              background-color: rgb(252, 252, 252);
              text-decoration-thickness: initial; text-decoration-style:
              initial; text-decoration-color: initial; display: inline
              !important; float: none;"> <span style="color: rgb(0, 0,
                0); font-size: 16px; font-style: normal;
                font-variant-ligatures: normal; font-variant-caps:
                normal; font-weight: 400; letter-spacing: normal;
                text-align: start; text-indent: 0px; text-transform:
                none; white-space: normal; word-spacing: 0px;
                -webkit-text-stroke-width: 0px; background-color:
                rgb(252, 252, 252); text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;">xa_{lock|unloack}_irqsave()
                can be use while looking up vm ptr for a pasid.</span></span></font></p>
        <p><font face="Helvetica, Arial, sans-serif"><span style="color:
              rgb(0, 0, 0); font-size: 16px; font-style: normal;
              font-variant-ligatures: normal; font-variant-caps: normal;
              font-weight: 400; letter-spacing: normal; text-align:
              start; text-indent: 0px; text-transform: none;
              white-space: normal; word-spacing: 0px;
              -webkit-text-stroke-width: 0px; background-color: rgb(252,
              252, 252); text-decoration-thickness: initial;
              text-decoration-style: initial; text-decoration-color:
              initial; display: inline !important; float: none;"><span style="color: rgb(0, 0, 0); font-size: 16px; font-style:
                normal; font-variant-ligatures: normal;
                font-variant-caps: normal; font-weight: 400;
                letter-spacing: normal; text-align: start; text-indent:
                0px; text-transform: none; white-space: normal;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                background-color: rgb(252, 252, 252);
                text-decoration-thickness: initial;
                text-decoration-style: initial; text-decoration-color:
                initial; display: inline !important; float: none;"><br>
              </span> </span></font></p>
        <font face="Helvetica, Arial, sans-serif"> </font>
        <p><font face="Helvetica, Arial, sans-serif">Shouldn't this be
            enough ?</font></p>
      </blockquote>
      <br>
      Yeah I think so.<br>
    </blockquote>
    <p><br>
    </p>
    <p>Great.<br>
    </p>
    <p><br>
    </p>
    <p>Nirmoy<br>
    </p>
    <blockquote type="cite" cite="mid:c28d9c08-0ab8-780a-ae44-e444ae49500e@gmail.com"> <br>
      Christian.<br>
      <br>
      <blockquote type="cite" cite="mid:564b4de5-b1fd-283e-85b8-7819c24bca10@amd.com">
        <p><font face="Helvetica, Arial, sans-serif"><br>
          </font></p>
        <p><font face="Helvetica, Arial, sans-serif">Regards,</font></p>
        <p><font face="Helvetica, Arial, sans-serif">Nirmoy</font><br>
        </p>
        <blockquote type="cite" cite="mid:9ff705c2-a4e4-dc37-041a-66c490d8f7ad@gmail.com"> <br>
          Christian. <br>
          <br>
          <blockquote type="cite"> <br>
            <br>
            Thanks <br>
            <br>
            Nirmoy <br>
            <br>
            <br>
            <blockquote type="cite"> <br>
              Christian. <br>
              <br>
              <blockquote type="cite">+    return 0; <br>
                +} <br>
                + <br>
                +static void amdgpu_vm_pasid_remove(struct amdgpu_device
                *adev, <br>
                +                   unsigned int pasid, <br>
                +                   unsigned int *vm_pasid) <br>
                +{ <br>
                +    unsigned long flags; <br>
                + <br>
                +    if (!pasid) <br>
                +        return; <br>
                + <br>
                +   
                spin_lock_irqsave(&adev->vm_manager.pasid_lock,
                flags); <br>
                +    idr_remove(&adev->vm_manager.pasid_idr,
                pasid); <br>
                +
                spin_unlock_irqrestore(&adev->vm_manager.pasid_lock,
                flags); <br>
                + <br>
                +    if (vm_pasid) <br>
                +        *vm_pasid = 0; <br>
                +} <br>
                + <br>
                  /* <br>
                   * vm eviction_lock can be taken in MMU notifiers.
                Make sure no reclaim-FS <br>
                   * happens while holding this lock anywhere to prevent
                deadlocks when <br>
                @@ -2940,18 +2980,8 @@ int amdgpu_vm_init(struct
                amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid) <br>
                <br>
                      amdgpu_bo_unreserve(vm->root.bo); <br>
                <br>
                -    if (pasid) { <br>
                -        unsigned long flags; <br>
                - <br>
                - spin_lock_irqsave(&adev->vm_manager.pasid_lock,
                flags); <br>
                -        r =
                idr_alloc(&adev->vm_manager.pasid_idr, vm, pasid,
                pasid + 1, <br>
                -                  GFP_ATOMIC); <br>
                -
                spin_unlock_irqrestore(&adev->vm_manager.pasid_lock,
                flags); <br>
                -        if (r < 0) <br>
                -            goto error_free_root; <br>
                - <br>
                -        vm->pasid = pasid; <br>
                -    } <br>
                +    if (amdgpu_vm_pasid_alloc(adev, vm, pasid,
                &vm->pasid)) <br>
                +        goto error_free_root; <br>
                <br>
                      INIT_KFIFO(vm->faults); <br>
                <br>
                @@ -3038,19 +3068,11 @@ int
                amdgpu_vm_make_compute(struct amdgpu_device *adev,
                struct amdgpu_vm *vm, <br>
                      r = amdgpu_vm_check_clean_reserved(adev, vm); <br>
                      if (r) <br>
                          goto unreserve_bo; <br>
                +    r = amdgpu_vm_pasid_alloc(adev, vm, pasid, NULL); <br>
                +    if (r ==  -ENOSPC) <br>
                +        goto unreserve_bo; <br>
                <br>
                -    if (pasid) { <br>
                -        unsigned long flags; <br>
                - <br>
                - spin_lock_irqsave(&adev->vm_manager.pasid_lock,
                flags); <br>
                -        r =
                idr_alloc(&adev->vm_manager.pasid_idr, vm, pasid,
                pasid + 1, <br>
                -                  GFP_ATOMIC); <br>
                -
                spin_unlock_irqrestore(&adev->vm_manager.pasid_lock,
                flags); <br>
                - <br>
                -        if (r == -ENOSPC) <br>
                -            goto unreserve_bo; <br>
                -        r = 0; <br>
                -    } <br>
                +    r = 0; <br>
                <br>
                      /* Check if PD needs to be reinitialized and do it
                before <br>
                       * changing any other state, in case it fails. <br>
                @@ -3089,35 +3111,23 @@ int
                amdgpu_vm_make_compute(struct amdgpu_device *adev,
                struct amdgpu_vm *vm, <br>
                      vm->is_compute_context = true; <br>
                <br>
                      if (vm->pasid) { <br>
                -        unsigned long flags; <br>
                - <br>
                - spin_lock_irqsave(&adev->vm_manager.pasid_lock,
                flags); <br>
                -        idr_remove(&adev->vm_manager.pasid_idr,
                vm->pasid); <br>
                -
                spin_unlock_irqrestore(&adev->vm_manager.pasid_lock,
                flags); <br>
                - <br>
                          /* Free the original amdgpu allocated pasid <br>
                           * Will be replaced with kfd allocated pasid <br>
                           */ <br>
                          amdgpu_pasid_free(vm->pasid); <br>
                -        vm->pasid = 0; <br>
                +        amdgpu_vm_pasid_remove(adev, vm->pasid,
                &vm->pasid); <br>
                      } <br>
                <br>
                      /* Free the shadow bo for compute VM */ <br>
amdgpu_bo_unref(&to_amdgpu_bo_vm(vm->root.bo)->shadow); <br>
                - <br>
                      if (pasid) <br>
                          vm->pasid = pasid; <br>
                <br>
                      goto unreserve_bo; <br>
                <br>
                  free_idr: <br>
                -    if (pasid) { <br>
                -        unsigned long flags; <br>
                +    amdgpu_vm_pasid_remove(adev, pasid, NULL); <br>
                <br>
                - spin_lock_irqsave(&adev->vm_manager.pasid_lock,
                flags); <br>
                -        idr_remove(&adev->vm_manager.pasid_idr,
                pasid); <br>
                -
                spin_unlock_irqrestore(&adev->vm_manager.pasid_lock,
                flags); <br>
                -    } <br>
                  unreserve_bo: <br>
                      amdgpu_bo_unreserve(vm->root.bo); <br>
                      return r; <br>
                @@ -3133,14 +3143,7 @@ int amdgpu_vm_make_compute(struct
                amdgpu_device *adev, struct amdgpu_vm *vm, <br>
                   */ <br>
                  void amdgpu_vm_release_compute(struct amdgpu_device
                *adev, struct amdgpu_vm *vm) <br>
                  { <br>
                -    if (vm->pasid) { <br>
                -        unsigned long flags; <br>
                - <br>
                - spin_lock_irqsave(&adev->vm_manager.pasid_lock,
                flags); <br>
                -        idr_remove(&adev->vm_manager.pasid_idr,
                vm->pasid); <br>
                -
                spin_unlock_irqrestore(&adev->vm_manager.pasid_lock,
                flags); <br>
                -    } <br>
                -    vm->pasid = 0; <br>
                +    amdgpu_vm_pasid_remove(adev, vm->pasid,
                &vm->pasid); <br>
                      vm->is_compute_context = false; <br>
                  } <br>
                <br>
                @@ -3164,15 +3167,7 @@ void amdgpu_vm_fini(struct
                amdgpu_device *adev, struct amdgpu_vm *vm) <br>
                <br>
                      root = amdgpu_bo_ref(vm->root.bo); <br>
                      amdgpu_bo_reserve(root, true); <br>
                -    if (vm->pasid) { <br>
                -        unsigned long flags; <br>
                - <br>
                - spin_lock_irqsave(&adev->vm_manager.pasid_lock,
                flags); <br>
                -        idr_remove(&adev->vm_manager.pasid_idr,
                vm->pasid); <br>
                -
                spin_unlock_irqrestore(&adev->vm_manager.pasid_lock,
                flags); <br>
                -        vm->pasid = 0; <br>
                -    } <br>
                - <br>
                +    amdgpu_vm_pasid_remove(adev, vm->pasid,
                &vm->pasid); <br>
                      dma_fence_wait(vm->last_unlocked, false); <br>
                      dma_fence_put(vm->last_unlocked); <br>
                <br>
                -- <br>
                2.32.0 <br>
                <br>
              </blockquote>
              <br>
            </blockquote>
            _______________________________________________ <br>
            amd-gfx mailing list <br>
            <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org" moz-do-not-send="true">amd-gfx@lists.freedesktop.org</a> <br>
            <a class="moz-txt-link-freetext" href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Cnirmoy.das%40amd.com%7Cb2e4767f6d044494535808d9356992b0%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637599549822932980%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=IIysPahKlRK1d6Ak5BtEQbt5%2Bjowly3bZjc3hrCSgW0%3D&reserved=0" originalsrc="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" shash="Pzz6jS7Edf37CYaZZGHdcKlEkCb2J9R9LjLq3W0z4pjZ40b2HmxuFYZIIihmW4LPqUWxJFAgOKwZuYzYAcvO45icuqAo/h7H304uHAIewURbuKeTPT4mQuXEvb/c0azyn546ZvRQZmxPVy6zAkj9uHIlo5HDL/aivvzjqNhvF8c=" moz-do-not-send="true">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Cnirmoy.das%40amd.com%7C3285a973b5a4498f3b0608d93558d909%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637599478002028860%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=QLv4hbUpPF9H%2BVL4eOQlTeROWQA%2FG1LrPGFBzCQRt7o%3D&amp;reserved=0</a>
            <br>
          </blockquote>
          <br>
        </blockquote>
      </blockquote>
      <br>
    </blockquote>
  </body>
</html>