<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Am 09.10.19 um 13:12 schrieb Yin,
      Tianci (Rico):<br>
    </div>
    <blockquote type="cite"
cite="mid:SN1PR12MB2544F1BE7D37DEC4721AF95D95950@SN1PR12MB2544.namprd12.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        <font size="2"><span style="font-size:11pt">Here is where you
            definitively set "ret" so DO NOT preinitialize it to 0,<br>
          </span></font></div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        <font size="2"><span style="font-size:11pt">just to avoid "pesky
            compiler unininitialized variable warnings"--those<br>
            are helpful to make the code more secure: a variable should
            be intentionally<br>
            initialized in all paths.</span></font></div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        <br>
      </div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        <span style="color: rgb(12, 100, 192);">Rico: Still in
          confusion, pre-initialization can avoid "uninitialized
          variable", why should we can't pre-initialize?
        </span><br>
      </div>
    </blockquote>
    <br>
    Because it avoids the uninitialized variable warning :)<br>
    <br>
    See we really want the warning because it means that we have a bug
    in the code somewhere.<br>
    <br>
    Regards,<br>
    Christian.<br>
    <br>
    <blockquote type="cite"
cite="mid:SN1PR12MB2544F1BE7D37DEC4721AF95D95950@SN1PR12MB2544.namprd12.prod.outlook.com">
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
      </div>
      <hr style="display:inline-block;width:98%" tabindex="-1">
      <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
          face="Calibri, sans-serif" color="#000000"><b>From:</b>
          Tuikov, Luben <a class="moz-txt-link-rfc2396E" href="mailto:Luben.Tuikov@amd.com"><Luben.Tuikov@amd.com></a><br>
          <b>Sent:</b> Wednesday, October 9, 2019 11:44<br>
          <b>To:</b> Alex Deucher <a class="moz-txt-link-rfc2396E" href="mailto:alexdeucher@gmail.com"><alexdeucher@gmail.com></a>;
          <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
          <a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx@lists.freedesktop.org"><amd-gfx@lists.freedesktop.org></a><br>
          <b>Cc:</b> Deucher, Alexander
          <a class="moz-txt-link-rfc2396E" href="mailto:Alexander.Deucher@amd.com"><Alexander.Deucher@amd.com></a>; Yin, Tianci (Rico)
          <a class="moz-txt-link-rfc2396E" href="mailto:Tianci.Yin@amd.com"><Tianci.Yin@amd.com></a><br>
          <b>Subject:</b> Re: [PATCH 7/8] drm/amdgpu: reserve vram for
          memory training</font>
        <div> </div>
      </div>
      <div class="BodyFragment"><font size="2"><span
            style="font-size:11pt;">
            <div class="PlainText">On 2019-10-08 3:29 p.m., Alex Deucher
              wrote:<br>
              > From: "Tianci.Yin" <a class="moz-txt-link-rfc2396E" href="mailto:tianci.yin@amd.com"><tianci.yin@amd.com></a><br>
              > <br>
              > memory training using specific fixed vram segment,
              reserve these<br>
              > segments before anyone may allocate it.<br>
              > <br>
              > Change-Id: I1436755813a565608a2857a683f535377620a637<br>
              > Reviewed-by: Alex Deucher
              <a class="moz-txt-link-rfc2396E" href="mailto:alexander.deucher@amd.com"><alexander.deucher@amd.com></a><br>
              > Signed-off-by: Tianci.Yin <a class="moz-txt-link-rfc2396E" href="mailto:tianci.yin@amd.com"><tianci.yin@amd.com></a><br>
              > ---<br>
              >  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 96
              +++++++++++++++++++++++++<br>
              >  1 file changed, 96 insertions(+)<br>
              > <br>
              > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
              b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
              > index 74a9bd94f10c..0819721af16e 100644<br>
              > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
              > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
              > @@ -1667,6 +1667,93 @@ static int
              amdgpu_ttm_fw_reserve_vram_init(struct amdgpu_device
              *adev)<br>
              >                                         
              &adev->fw_vram_usage.va);<br>
              >  }<br>
              >  <br>
              > +/*<br>
              > + * Memoy training reservation functions<br>
              > + */<br>
              <br>
              Include an empty line between the two comments, just as
              you would<br>
              a paragraph in written text.<br>
              <br>
              > +/**<br>
              > + * amdgpu_ttm_training_reserve_vram_fini - free
              memory training reserved vram<br>
              > + *<br>
              > + * @adev: amdgpu_device pointer<br>
              > + *<br>
              > + * free memory training reserved vram if it has been
              reserved.<br>
              > + */<br>
              > +static int
              amdgpu_ttm_training_reserve_vram_fini(struct amdgpu_device
              *adev)<br>
              > +{<br>
              > +     int ret = 0;<br>
              > +     struct psp_memory_training_context *ctx =
              &adev->psp.mem_train_ctx;<br>
              > +<br>
              > +     ctx->init = PSP_MEM_TRAIN_NOT_SUPPORT;<br>
              > +     if(ctx->c2p_bo) {<br>
              <br>
              Space after keywords, according to LKCS:<br>
              if (...)<br>
              <br>
              > +            
              amdgpu_bo_free_kernel(&ctx->c2p_bo, NULL, NULL);<br>
              > +             ctx->c2p_bo = NULL;<br>
              > +     }<br>
              > +     if(ctx->p2c_bo) {<br>
              <br>
              Space after keywords, according to LKCS:<br>
              if (...)<br>
              <br>
              > +            
              amdgpu_bo_free_kernel(&ctx->p2c_bo, NULL, NULL);<br>
              > +             ctx->p2c_bo = NULL;<br>
              > +     }<br>
              > +<br>
              > +     return ret;<br>
              > +}<br>
              <br>
              Get rid of "ret" variable altogether as it is not used in
              this function.<br>
              <br>
              > +<br>
              > +/**<br>
              > + * amdgpu_ttm_training_reserve_vram_init - create bo
              vram reservation from memory training<br>
              > + *<br>
              > + * @adev: amdgpu_device pointer<br>
              > + *<br>
              > + * create bo vram reservation from memory training.<br>
              > + */<br>
              > +static int
              amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device
              *adev)<br>
              > +{<br>
              > +     int ret = 0;<br>
              <br>
              DO NOT preinitialize ret.<br>
              <br>
              > +     struct psp_memory_training_context *ctx =
              &adev->psp.mem_train_ctx;<br>
              > +<br>
              > +     memset(ctx, 0, sizeof(*ctx));<br>
              > +     if(!adev->fw_vram_usage.mem_train_support) {<br>
              <br>
              Space after keywords: "if (".<br>
              <br>
              > +             DRM_DEBUG("memory training does not
              support!\n");<br>
              > +             return 0;<br>
              > +     }<br>
              > +<br>
              > +     ctx->c2p_train_data_offset =
              adev->fw_vram_usage.mem_train_fb_loc;<br>
              > +     ctx->p2c_train_data_offset =
              (adev->gmc.mc_vram_size - GDDR6_MEM_TRAINING_OFFSET);<br>
              > +     ctx->train_data_size =
              GDDR6_MEM_TRAINING_DATA_SIZE_IN_BYTES;<br>
              > +<br>
              > +    
DRM_DEBUG("train_data_size:%llx,p2c_train_data_offset:%llx,c2p_train_data_offset:%llx.\n",<br>
              > +               ctx->train_data_size,<br>
              > +               ctx->p2c_train_data_offset,<br>
              > +               ctx->c2p_train_data_offset);<br>
              > +<br>
              > +     ret = amdgpu_bo_create_kernel_at(adev,<br>
              <br>
              Here is where you definitively set "ret" so DO NOT
              preinitialize it to 0,<br>
              just to avoid "pesky compiler unininitialized variable
              warnings"--those<br>
              are helpful to make the code more secure: a variable
              should be intentionally<br>
              initialized in all paths.<br>
              <br>
              > +                                     
              ctx->p2c_train_data_offset,<br>
              > +                                     
              ctx->train_data_size,<br>
              > +                                     
              AMDGPU_GEM_DOMAIN_VRAM,<br>
              > +                                     
              &ctx->p2c_bo,<br>
              > +                                      NULL);<br>
              > +     if(ret) {<br>
              <br>
              Space after keywords "if (".<br>
              <br>
              > +             DRM_ERROR("alloc p2c_bo failed(%d)!\n",
              ret);<br>
              > +             ret = -ENOMEM;<br>
              > +             goto err_out;<br>
              > +     }<br>
              > +<br>
              > +     ret = amdgpu_bo_create_kernel_at(adev,<br>
              > +                                     
              ctx->c2p_train_data_offset,<br>
              > +                                     
              ctx->train_data_size,<br>
              > +                                     
              AMDGPU_GEM_DOMAIN_VRAM,<br>
              > +                                     
              &ctx->c2p_bo,<br>
              > +                                      NULL);<br>
              > +     if(ret) {<br>
              <br>
              Space after keywords: "if (", according to LKCS.<br>
              <br>
              Regards,<br>
              Luben<br>
              <br>
              > +             DRM_ERROR("alloc c2p_bo failed(%d)!\n",
              ret);<br>
              > +             ret = -ENOMEM;<br>
              > +             goto err_out;<br>
              > +     }<br>
              > +<br>
              > +     ctx->init = PSP_MEM_TRAIN_RESERVE_SUCCESS;<br>
              > +     return 0;<br>
              > +<br>
              > +err_out:<br>
              > +     amdgpu_ttm_training_reserve_vram_fini(adev);<br>
              > +     return ret;<br>
              > +}<br>
              > +<br>
              >  /**<br>
              >   * amdgpu_ttm_init - Init the memory management
              (ttm) as well as various<br>
              >   * gtt/vram related fields.<br>
              > @@ -1740,6 +1827,14 @@ int amdgpu_ttm_init(struct
              amdgpu_device *adev)<br>
              >                return r;<br>
              >        }<br>
              >  <br>
              > +     /*<br>
              > +      *The reserved vram for memory training must be
              pinned to the specified<br>
              > +      *place on the VRAM, so reserve it early.<br>
              > +      */<br>
              > +     r =
              amdgpu_ttm_training_reserve_vram_init(adev);<br>
              > +     if (r)<br>
              > +             return r;<br>
              > +<br>
              >        /* allocate memory as required for VGA<br>
              >         * This is used for VGA emulation and pre-OS
              scanout buffers to<br>
              >         * avoid display artifacts while transitioning
              between pre-OS<br>
              > @@ -1825,6 +1920,7 @@ void amdgpu_ttm_fini(struct
              amdgpu_device *adev)<br>
              >                return;<br>
              >  <br>
              >        amdgpu_ttm_debugfs_fini(adev);<br>
              > +     amdgpu_ttm_training_reserve_vram_fini(adev);<br>
              >        amdgpu_ttm_fw_reserve_vram_fini(adev);<br>
              >        if (adev->mman.aper_base_kaddr)<br>
              >               
              iounmap(adev->mman.aper_base_kaddr);<br>
              > <br>
              <br>
            </div>
          </span></font></div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
amd-gfx mailing list
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a></pre>
    </blockquote>
    <br>
  </body>
</html>