<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Bookman Old Style";
        panose-1:2 5 6 4 5 5 5 2 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="#954F72">
<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 class="WordSection1">
<p class="MsoNormal">Thanks million! I’ll change the patch.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Bookman Old Style",serif">-Jacob<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</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> Koenig, Christian <Christian.Koenig@amd.com><br>
<b>Sent:</b> Wednesday, March 4, 2020 12:09:36 AM<br>
<b>To:</b> He, Jacob <Jacob.He@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu: Update SPM_VMID with the job's vmid when application reserves the vmid</font>
<div> </div>
</div>
<div style="background-color:#FFFFFF">
<div class="x_moz-cite-prefix">Am 03.03.20 um 17:07 schrieb He, Jacob:<br>
</div>
<blockquote type="cite">
<meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:DengXian}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:"Bookman Old Style"}
@font-face
        {}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:windowtext}
a:link, span.x_MsoHyperlink
        {color:blue;
        text-decoration:underline}
.x_MsoChpDefault
        {}
@page WordSection1
        {margin:1.0in 1.25in 1.0in 1.25in}
div.x_WordSection1
        {}
-->
</style>
<p align="Left" style="font-family:Arial; font-size:10pt; color:#0078D7; margin:15pt">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div class="x_WordSection1">
<p class="x_MsoNormal">Oh, you are right! If SPM_VMID is updated by other process while the SPM enabled commands is executing, that will cause VM fault.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Is the wait vm idle right before unreserve vmid still necessary if using asynchroneously setting SPM_VMID?</p>
</div>
</div>
</blockquote>
<br>
No, that are alternative approaches.<br>
<br>
Updating the VMID asynchronously sounds a bit cleaner to me, but feel free to pick whatever is easier for you to implement.<br>
<br>
Regards,<br>
Christian.<br>
<br>
<blockquote type="cite">
<div>
<div class="x_WordSection1">
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal"><span style="">Thanks</span></p>
<p class="x_MsoNormal"><span style="">Jacob</span></p>
<p class="x_MsoNormal"> </p>
<div style="border:none; border-top:solid
            #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal" style="border:none; padding:0in"><b>From: </b><a href="mailto:Christian.Koenig@amd.com">Koenig, Christian</a><br>
<b>Sent: </b>Tuesday, March 3, 2020 11:36 PM<br>
<b>To: </b><a href="mailto:Jacob.He@amd.com">He, Jacob</a>; <a href="mailto:amd-gfx@lists.freedesktop.org">
amd-gfx@lists.freedesktop.org</a><br>
<b>Subject: </b>Re: [PATCH] drm/amdgpu: Update SPM_VMID with the job's vmid when application reserves the vmid</p>
</div>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">See the SPM buffer address is set using CP commands as well, right? And those execute asynchronously.<br>
<br>
When we now synchronously update the SPM VMID we risk that we switch from one process to another while the new process is not ready yet with its setup.<br>
<br>
That could have quite a bunch of unforeseen consequences, including accidentally writing SPM data into the new process address space at whatever buffer address was used before.<br>
<br>
This is something we at least should try to avoid.<br>
<br>
Regards,<br>
Christian.<br>
<br>
Am 03.03.20 um 16:28 schrieb He, Jacob:</p>
<blockquote style="margin-top:5.0pt; margin-bottom:5.0pt">
<p style="margin:15.0pt"><span style="font-size:10.0pt; font-family:"Arial",sans-serif; color:#0078D7">[AMD Official Use Only - Internal Distribution Only]</span></p>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
<div>
<p class="x_MsoNormal">Thanks!  Could you please take an example of trouble  “<span style="color:black">This way we avoid a bunch of trouble when one process drops the VMID reservation and another one grabs it.</span>”?</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal"><span style="">Thanks</span></p>
<p class="x_MsoNormal"><span style="">Jacob</span></p>
<p class="x_MsoNormal"> </p>
<div style="border:none; border-top:solid #E1E1E1
                1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b>From: </b><a href="mailto:Christian.Koenig@amd.com">Koenig, Christian</a><br>
<b>Sent: </b>Tuesday, March 3, 2020 11:03 PM<br>
<b>To: </b><a href="mailto:Jacob.He@amd.com">He, Jacob</a>; <a href="mailto:amd-gfx@lists.freedesktop.org">
amd-gfx@lists.freedesktop.org</a><br>
<b>Subject: </b>Re: [PATCH] drm/amdgpu: Update SPM_VMID with the job's vmid when application reserves the vmid</p>
</div>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal"><span style="color:black">Am 03.03.20 um 15:34 schrieb He, Jacob:</span></p>
<blockquote style="margin-top:5.0pt; margin-bottom:5.0pt">
<p style="margin:15.0pt"><span style="font-size:10.0pt; font-family:"Arial",sans-serif; color:#0078D7">[AMD Official Use Only - Internal Distribution Only]</span></p>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
<div>
<p class="x_MsoNormal" style="margin-bottom:12.0pt"><i><span style="color:black">It would be better if we could do that asynchronously with a register
<br>
write on the ring.</span></i></p>
<p class="x_MsoNormal"><span style="color:black">Sorry, I don’t get your point. Could you please elaborate more?
</span></p>
</div>
</blockquote>
<p class="x_MsoNormal"><span style="color:black"><br>
You pass the ring from amdgpu_vm_flush() to the *_update_spm_vmid() functions.<br>
<br>
And then instead of using WREG32() you call amdgpu_ring_emit_wreg() to make the write asynchronously on the ring buffer using a CP command.<br>
<br>
This way we avoid a bunch of trouble when one process drops the VMID reservation and another one grabs it.<br>
<br>
Regards,<br>
Christian.<br>
<br>
<br>
<br>
</span></p>
<blockquote style="margin-top:5.0pt; margin-bottom:5.0pt">
<div>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
<p class="x_MsoNormal"><span style="">Thanks</span></p>
<p class="x_MsoNormal"><span style="">Jacob</span></p>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
<div style="border:none; border-top:solid #E1E1E1
                    1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b><span style="color:black">From: </span></b><span style="color:black"><a href="mailto:ckoenig.leichtzumerken@gmail.com">Christian König</a><br>
<b>Sent: </b>Tuesday, March 3, 2020 10:16 PM<br>
<b>To: </b><a href="mailto:Jacob.He@amd.com">He, Jacob</a>; <a href="mailto:amd-gfx@lists.freedesktop.org">
amd-gfx@lists.freedesktop.org</a><br>
<b>Subject: </b>Re: [PATCH] drm/amdgpu: Update SPM_VMID with the job's vmid when application reserves the vmid</span></p>
</div>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
<p class="x_MsoNormal" style="margin-bottom:12.0pt"><span style="color:black">Am 02.03.20 um 06:35 schrieb Jacob He:<br>
> SPM access the video memory according to SPM_VMID. It should be updated<br>
> with the job's vmid right before the job is scheduled. SPM_VMID is a<br>
> global resource<br>
><br>
> Change-Id: Id3881908960398f87e7c95026a54ff83ff826700<br>
> Signed-off-by: Jacob He <a href="mailto:jacob.he@amd.com"><jacob.he@amd.com></a><br>
> ---<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++++<br>
>   1 file changed, 4 insertions(+)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
> index c00696f3017e..c761d3a0b6e8 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
> @@ -1080,8 +1080,12 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,<br>
>        struct dma_fence *fence = NULL;<br>
>        bool pasid_mapping_needed = false;<br>
>        unsigned patch_offset = 0;<br>
> +     bool update_spm_vmid_needed = (job->vm && (job->vm->reserved_vmid[vmhub] != NULL));<br>
>        int r;<br>
>   <br>
> +     if (update_spm_vmid_needed && adev->gfx.rlc.funcs->update_spm_vmid)<br>
> +             adev->gfx.rlc.funcs->update_spm_vmid(adev, job->vmid);<br>
> +<br>
<br>
It would be better if we could do that asynchronously with a register <br>
write on the ring.<br>
<br>
The alternative is that we block for the VM to be idle in <br>
amdgpu_vm_ioctl() before unreserving the VMID.<br>
<br>
In other words lock the reservation object of the root PD and call <br>
amdgpu_vm_wait_idle() before calling amdgpu_vmid_free_reserved().<br>
<br>
Regards,<br>
Christian.<br>
<br>
>        if (amdgpu_vmid_had_gpu_reset(adev, id)) {<br>
>                gds_switch_needed = true;<br>
>                vm_flush_needed = true;</span></p>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
</div>
</blockquote>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
</div>
</blockquote>
<p class="x_MsoNormal"><span style="color:black"> </span></p>
<p class="x_MsoNormal"> </p>
</div>
</div>
</blockquote>
<br>
</div>
</div>
</body>
</html>