<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=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@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:Aptos;
        panose-1:2 11 0 4 2 2 2 2 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Aptos",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="en-CN" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<p style="font-family:Calibri;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - AMD Internal Distribution Only]<br>
</p>
<br>
<div>
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Aptos",sans-serif">Hi <a id="OWAAM089762EA1318B444A77BCF5A836F9874" href="mailto:Christian.Koenig@amd.com">
<span style="font-family:"Aptos",sans-serif;text-decoration:none">@Koenig, Christian</span></a></span><span lang="EN-US" style="font-family:"Aptos",sans-serif"> and
<a id="OWAAMFBACA44642CE874F8BB5502F1092736E" href="mailto:Jonathan.Kim@amd.com">
<span style="font-family:"Aptos",sans-serif;text-decoration:none">@Kim, Jonathan</span></a>,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Aptos",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Aptos",sans-serif">Could you help review this patch?
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Aptos",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Aptos",sans-serif">Thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-family:"Aptos",sans-serif">Sam<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Aptos",sans-serif"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">From:
</span></b><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">Samuel Zhang <guoqing.zhang@amd.com><br>
<b>Date: </b>Wednesday, August 7, 2024 at 16:36<br>
<b>To: </b>amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc: </b>Zhang, GuoQing (Sam) <GuoQing.Zhang@amd.com><br>
<b>Subject: </b>[PATCH] drm/amdgpu: fix KFDMemoryTest.PtraceAccessInvisibleVram fail on SRIOV<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Ptrace access VRAM bo will first try sdma access in<br>
amdgpu_ttm_access_memory_sdma(), if fails, it will fallback to mmio<br>
access.<br>
<br>
Since ptrace only access 8 bytes at a time and<br>
amdgpu_ttm_access_memory_sdma() only allow PAGE_SIZE bytes access,<br>
it returns fail.<br>
On SRIOV, mmio access will also fail as MM_INDEX/MM_DATA register write<br>
is blocked for security reasons.<br>
<br>
The fix is just change len check in amdgpu_ttm_access_memory_sdma() so<br>
that len in (0, PAGE_SIZE] are allowed. This will not fix the ptrace<br>
test case on SRIOV, but also improve the access performance when the<br>
access length is < PAGE_SIZE.<br>
len > PAGE_SIZE case support is not needed as larger size will be break<br>
into chunks of PAGE_SIZE len max in mem_rw().<br>
<br>
Signed-off-by: Samuel Zhang <guoqing.zhang@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++--<br>
 1 file changed, 2 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
index 5daa05e23ddf..a6e90eada367 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
@@ -1486,7 +1486,7 @@ static int amdgpu_ttm_access_memory_sdma(struct ttm_buffer_object *bo,<br>
         unsigned int num_dw;<br>
         int r, idx;<br>
 <br>
-       if (len != PAGE_SIZE)<br>
+       if (len > PAGE_SIZE)<br>
                 return -EINVAL;<br>
 <br>
         if (!adev->mman.sdma_access_ptr)<br>
@@ -1514,7 +1514,7 @@ static int amdgpu_ttm_access_memory_sdma(struct ttm_buffer_object *bo,<br>
                 swap(src_addr, dst_addr);<br>
 <br>
         amdgpu_emit_copy_buffer(adev, &job->ibs[0], src_addr, dst_addr,<br>
-                               PAGE_SIZE, 0);<br>
+                               len, 0);<br>
 <br>
         amdgpu_ring_pad_ib(adev->mman.buffer_funcs_ring, &job->ibs[0]);<br>
         WARN_ON(job->ibs[0].length_dw > num_dw);<br>
-- <br>
2.25.1<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>