<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;}
@font-face
        {font-family:"Bookman Old Style \,serif";}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.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">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="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is the wait vm idle right before unreserve vmid still necessary if using asynchroneously setting SPM_VMID?</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Bookman Old Style",serif">Thanks<o:p></o:p></span></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 style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="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="MsoNormal"><o:p> </o:p></p>
<p class="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:<o:p></o:p></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]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<div>
<p class="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>”?<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Bookman Old Style ,serif",serif">Thanks</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Bookman Old Style ,serif",serif">Jacob</span><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="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<o:p></o:p></p>
</div>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><span style="color:black">Am 03.03.20 um 15:34 schrieb He, Jacob:</span><o:p></o:p></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="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
<div>
<p class="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><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black">Sorry, I don’t get your point. Could you please elaborate more?
</span><o:p></o:p></p>
</div>
</blockquote>
<p class="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><o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Bookman Old Style",serif">Thanks</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Bookman Old Style",serif">Jacob</span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="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><o:p></o:p></p>
</div>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="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><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
</div>
</blockquote>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:black"> </span><o:p></o:p></p>
</div>
</blockquote>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>