<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 7/23/2025 8:30 AM, Russell, Kent
wrote:<br>
</div>
<blockquote type="cite" cite="mid:BL1PR12MB5898AFDD9DCC03E472E38368855FA@BL1PR12MB5898.namprd12.prod.outlook.com">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Aptos;}@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
font-size:10.0pt;
font-family:"Courier New";}span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Arial",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}div.WordSection1
{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<p style="font-family:Calibri;font-size:10pt;color:#008000;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div class="WordSection1">
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">The
big thing is that HMM doesn’t support a lack of read
permissions. So does it make sense to make any HMM calls
or set any HMM flags if it’s an unsupported
configuration that it will fault on? That was why I went
down this path, since trying to remove the READ
permissions here while still using HMM calls could go
sideways, if HMM will automatically fail if READ
permissions are missing.
<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></font></p>
</div>
</div>
</blockquote>
<p><font size="2" face="Arial">I do not see HMM can only work if
read permission is specified. From code comments "If the vma
does not allow read access, then assume that it does not allow
write access either".</font></p>
<p><font size="3" face="Arial"><span style="font-size:12.0pt">hmm_range_fault
uses cpu page fault to valid pages. If it cannot do that it
return error code specified the reasons. Driver needs check
the error code to decide what to do after. Current driver
checks if read is allowed, if not, driver assumes it is write
permission. That does not consider VM_NONE that specifies the
vma is not accessible, then the vms is not fault-able.<br>
</span></font></p>
<p><font size="3" face="Arial"><span style="font-size:12.0pt">This
issue not only exists in svm code. For user buffer
registration and validation current driver does not consider
VM_NONE either. I think part of the changes is: before let </span></font><font size="3" face="Arial"><span style="font-size:12.0pt">hmm_range_fault
do page validation check vma->flags to decide if can set </span></font><font size="3" face="Arial"><span style="font-size:12.0pt">hmm_range->default_flags
to HMM_PFN_REQ_FAULT or not. </span></font><font size="3" face="Arial"><span style="font-size:12.0pt">Do not request hmm
fault on area that is not faultable.</span></font></p>
<p><font size="3" face="Arial"><span style="font-size:12.0pt">Regards</span></font></p>
<p><font size="3" face="Arial"><span style="font-size:12.0pt">Xiaogang<br>
</span></font></p>
<p><font size="3" face="Aptos"><span style="font-size:12.0pt"></span></font></p>
<blockquote type="cite" cite="mid:BL1PR12MB5898AFDD9DCC03E472E38368855FA@BL1PR12MB5898.namprd12.prod.outlook.com">
<div>
<div class="WordSection1">
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;font-family:"Arial",sans-serif">Kent<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:11.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></font></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><font size="2" face="Calibri"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;font-weight:bold">From:</span></font></b><font size="2" face="Calibri"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
Chen, Xiaogang <a class="moz-txt-link-rfc2396E" href="mailto:Xiaogang.Chen@amd.com"><Xiaogang.Chen@amd.com></a> <br>
<b><span style="font-weight:bold">Sent:</span></b>
Tuesday, July 22, 2025 6:46 PM<br>
<b><span style="font-weight:bold">To:</span></b>
Russell, Kent <a class="moz-txt-link-rfc2396E" href="mailto:Kent.Russell@amd.com"><Kent.Russell@amd.com></a>;
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
<b><span style="font-weight:bold">Cc:</span></b>
Kuehling, Felix <a class="moz-txt-link-rfc2396E" href="mailto:Felix.Kuehling@amd.com"><Felix.Kuehling@amd.com></a><br>
<b><span style="font-weight:bold">Subject:</span></b>
Re: [PATCH] drm/amdkfd: Handle lack of READ
permissions in SVM mapping<o:p></o:p></span></font></p>
</div>
</div>
<p class="MsoNormal"><font size="3" face="Aptos"><span style="font-size:12.0pt"><o:p> </o:p></span></font></p>
<p><font size="3" face="Aptos"><span style="font-size:12.0pt"><o:p> </o:p></span></font></p>
<div>
<p class="MsoNormal"><font size="3" face="Aptos"><span style="font-size:12.0pt">On 7/22/2025 11:24 AM, Kent
Russell wrote:<o:p></o:p></span></font></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">HMM assumes that pages have READ permissions by default. Inside<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">svm_range_validate_and_map, we add READ permissions then add WRITE<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">permissions if the VMA isn't read-only. This will conflict with regions<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">that only have PROT_WRITE or have PROT_NONE. When that happens,<o:p></o:p></span></font></pre>
</blockquote>
<p class="MsoNormal"><font size="3" face="Aptos"><span style="font-size:12.0pt">Why read-only conflict with
PROT_WRITE or have PROT_NONE? They are
vma->vm_flags that specifies the vma protection.
User can change its value at runtime. Is user not
allowed to change it from read-only to PROT_NONE? <o:p></o:p></span></font></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"><o:p> </o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">svm_range_validate_and_map will continue to retry, silently, giving the<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">impression of a hang.<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"><o:p> </o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">If pages don't have READ permissions, simply unmap them and continue. If<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">they weren't mapped in the first place, this would be a no-op. Since x86<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">doesn't support write-only, and PROT_NONE doesn't allow reads or writes<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">anyways, this will allow the svm range validation to continue without<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">getting stuck in a loop forever on mappings we can't use with HMM.<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"><o:p> </o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">Signed-off-by: Kent Russell <a href="mailto:kent.russell@amd.com" moz-do-not-send="true"><kent.russell@amd.com></a><o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">---<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"> drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 18 ++++++++++++++++++<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"> 1 file changed, 18 insertions(+)<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"><o:p> </o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">index e23b5a0f31f2..10b70b941b11 100644<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">@@ -1713,6 +1713,24 @@ static int svm_range_validate_and_map(struct mm_struct *mm,<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"> <o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"> next = min(vma->vm_end, end);<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"> npages = (next - addr) >> PAGE_SHIFT;<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ /* HMM requires at least READ permissions. If provided with PROT_NONE,<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ * unmap the memory. If it's not already mapped, this is a no-op<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ * If PROT_WRITE is provided without READ, warn first then unmap<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ */<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ if (!(vma->vm_flags & VM_READ)) {<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ unsigned long e, s;<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ if (vma->vm_flags & VM_WRITE)<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ pr_warn("VM_WRITE without VM_READ is not supported");<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ s = max(start, prange->start);<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ e = min(end, prange->last);<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ if (e >= s)<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ svm_range_unmap_from_gpus(prange, s, e,<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ KFD_SVM_UNMAP_TRIGGER_UNMAP_FROM_CPU);<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ addr = next;<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ continue;<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+ }<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt">+<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"> WRITE_ONCE(p->svms.faulting_task, current);<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"> r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages,<o:p></o:p></span></font></pre>
<pre><font size="2" face="Courier New"><span style="font-size:10.0pt"> readonly, owner, NULL,<o:p></o:p></span></font></pre>
</blockquote>
<p><font size="3" face="Aptos"><span style="font-size:12.0pt">It seems the real problem is
at amdgpu_hmm_range_get_pages. It always set
HMM_PFN_REQ_FAULT to hmm_range->default_flags.
HMM_PFN_REQ_FAULT means the page is faultable and a
future call with HMM_PFN_REQ_FAULT could succeed. When
vma->vm_flags is PROT_NONE the vma is not
faultable, so hmm_range->default_flags should be
not set to HMM_PFN_REQ_FAULT to avoid hmm_range_fault
fault this vma.
<o:p></o:p></span></font></p>
<p><font size="3" face="Aptos"><span style="font-size:12.0pt">Regards<o:p></o:p></span></font></p>
<p><font size="3" face="Aptos"><span style="font-size:12.0pt">Xiaogang<o:p></o:p></span></font></p>
<p><font size="3" face="Aptos"><span style="font-size:12.0pt"><o:p> </o:p></span></font></p>
<p><font size="3" face="Aptos"><span style="font-size:12.0pt"><o:p> </o:p></span></font></p>
<p><font size="3" face="Aptos"><span style="font-size:12.0pt"><o:p> </o:p></span></font></p>
</div>
</div>
</div>
</blockquote>
</body>
</html>