<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Where is the userspace code which uses this new interface?  Can you add a link to the relevant branch to the commit message?<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Alex<br>
</div>
<div id="appendonsend"></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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Alex Sierra <alex.sierra@amd.com><br>
<b>Sent:</b> Monday, May 29, 2023 4:09 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Kuehling, Felix <Felix.Kuehling@amd.com><br>
<b>Cc:</b> Sierra Guiza, Alejandro (Alex) <Alex.Sierra@amd.com>; Yang, Philip <Philip.Yang@amd.com><br>
<b>Subject:</b> [PATCH] drm/amd: SVM flag error added at svm_range flags</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">If a return error is raised during validation and mapping of a<br>
prange, this flag is set. It is a rare occurrence, but it could happen<br>
when `amdgpu_hmm_range_get_pages_done` returns true. In such cases,<br>
the caller should retry. However, it is important to ensure that the<br>
prange is updated correctly during the retry.<br>
<br>
Signed-off-by: Alex Sierra <alex.sierra@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 +++++++++++-<br>
 include/uapi/linux/kfd_ioctl.h       |  2 ++<br>
 2 files changed, 13 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
index fcfde9140bce..96abae515bcf 100644<br>
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c<br>
@@ -756,10 +756,12 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange,<br>
                         break;<br>
                 case KFD_IOCTL_SVM_ATTR_SET_FLAGS:<br>
                         *update_mapping = true;<br>
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;<br>
                         prange->flags |= attrs[i].value;<br>
                         break;<br>
                 case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:<br>
                         *update_mapping = true;<br>
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;<br>
                         prange->flags &= ~attrs[i].value;<br>
                         break;<br>
                 case KFD_IOCTL_SVM_ATTR_GRANULARITY:<br>
@@ -778,6 +780,9 @@ svm_range_is_same_attrs(struct kfd_process *p, struct svm_range *prange,<br>
         uint32_t i;<br>
         int gpuidx;<br>
 <br>
+       if (prange->flags & KFD_IOCTL_SVM_FLAG_ERROR)<br>
+               return false;<br>
+<br>
         for (i = 0; i < nattr; i++) {<br>
                 switch (attrs[i].type) {<br>
                 case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC:<br>
@@ -1657,8 +1662,11 @@ static int svm_range_validate_and_map(struct mm_struct *mm,<br>
 unreserve_out:<br>
         svm_range_unreserve_bos(&ctx);<br>
 <br>
-       if (!r)<br>
+       prange->flags |= KFD_IOCTL_SVM_FLAG_ERROR;<br>
+       if (!r) {<br>
+               prange->flags &= ~KFD_IOCTL_SVM_FLAG_ERROR;<br>
                 prange->validate_timestamp = ktime_get_boottime();<br>
+       }<br>
 <br>
         return r;<br>
 }<br>
@@ -3674,9 +3682,11 @@ svm_range_get_attr(struct kfd_process *p, struct mm_struct *mm,<br>
                         break;<br>
                 case KFD_IOCTL_SVM_ATTR_SET_FLAGS:<br>
                         attrs[i].value = flags_and;<br>
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;<br>
                         break;<br>
                 case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:<br>
                         attrs[i].value = ~flags_or;<br>
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;<br>
                         break;<br>
                 case KFD_IOCTL_SVM_ATTR_GRANULARITY:<br>
                         attrs[i].value = (uint32_t)granularity;<br>
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h<br>
index 7e19a2d1e907..2b6f68bd06da 100644<br>
--- a/include/uapi/linux/kfd_ioctl.h<br>
+++ b/include/uapi/linux/kfd_ioctl.h<br>
@@ -1125,6 +1125,8 @@ struct kfd_ioctl_cross_memory_copy_deprecated_args {<br>
 #define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY     0x00000020<br>
 /* Keep GPU memory mapping always valid as if XNACK is disable */<br>
 #define KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED   0x00000040<br>
+/* Set during svm validation and map error */<br>
+#define KFD_IOCTL_SVM_FLAG_ERROR       0x80000000<br>
 <br>
 /**<br>
  * kfd_ioctl_svm_op - SVM ioctl operations<br>
-- <br>
2.32.0<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>