Skip to contentSkip to conversation

drm/amd: SVM flag error added at svm_range flags

PATCH In review Alex Sierra 3 participants 3 messages May 29, 2023 – May 31, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd: SVM flag error added at svm_range flags

If a return error is raised during validation and mapping of a prange, this flag is set. It is a rare occurrence, but it could happen when amdgpu_hmm_range_get_pages_done returns true. In such cases, the caller should retry. However, it is important to ensure that the prange is updated correctly during the retry.

---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 +++++++++++-
 include/uapi/linux/kfd_ioctl.h       |  2 ++
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +11 -1
index fcfde9140bce..96abae515bcf 100644
@@ -756,10 +756,12 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange,
 			break;
 		case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
 			*update_mapping = true;
+			attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
 			prange->flags |= attrs[i].value;
 			break;
 		case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
 			*update_mapping = true;
+			attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
 			prange->flags &= ~attrs[i].value;
 			break;
 		case KFD_IOCTL_SVM_ATTR_GRANULARITY:
@@ -778,6 +780,9 @@ svm_range_is_same_attrs(struct kfd_process *p, struct svm_range *prange,
 	uint32_t i;
 	int gpuidx;
 
+	if (prange->flags & KFD_IOCTL_SVM_FLAG_ERROR)
+		return false;
+
 	for (i = 0; i < nattr; i++) {
 		switch (attrs[i].type) {
 		case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC:
@@ -1657,8 +1662,11 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
 unreserve_out:
 	svm_range_unreserve_bos(&ctx);
 
-	if (!r)
+	prange->flags |= KFD_IOCTL_SVM_FLAG_ERROR;
+	if (!r) {
+		prange->flags &= ~KFD_IOCTL_SVM_FLAG_ERROR;
 		prange->validate_timestamp = ktime_get_boottime();
+	}
 
 	return r;
 }
@@ -3674,9 +3682,11 @@ svm_range_get_attr(struct kfd_process *p, struct mm_struct *mm,
 			break;
 		case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
 			attrs[i].value = flags_and;
+			attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
 			break;
 		case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
 			attrs[i].value = ~flags_or;
+			attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
 			break;
 		case KFD_IOCTL_SVM_ATTR_GRANULARITY:
 			attrs[i].value = (uint32_t)granularity;
include/uapi/linux/kfd_ioctl.h +2 -0
index 7e19a2d1e907..2b6f68bd06da 100644
@@ -1125,6 +1125,8 @@ struct kfd_ioctl_cross_memory_copy_deprecated_args {
 #define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY     0x00000020
 /* Keep GPU memory mapping always valid as if XNACK is disable */
 #define KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED   0x00000040
+/* Set during svm validation and map error */
+#define KFD_IOCTL_SVM_FLAG_ERROR       0x80000000
 
 /**
  * kfd_ioctl_svm_op - SVM ioctl operations
Signature · 1 line
2.32.0
#1 lore raw

[Public]

Where is the userspace code which uses this new interface? Can you add a link to the relevant branch to the commit message?

Alex
________________________________
From: amd-gfx <[email protected]> on behalf of Alex Sierra <[email protected]>
Sent: Monday, May 29, 2023 4:09 PM
To: [email protected] <[email protected]>; Kuehling, Felix <[email protected]>
Cc: Sierra Guiza, Alejandro (Alex) <[email protected]>; Yang, Philip <[email protected]>
Subject: [PATCH] drm/amd: SVM flag error added at svm_range flags

If a return error is raised during validation and mapping of a prange, this flag is set. It is a rare occurrence, but it could happen when amdgpu_hmm_range_get_pages_done returns true. In such cases, the caller should retry. However, it is important to ensure that the prange is updated correctly during the retry.

---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 +++++++++++-
 include/uapi/linux/kfd_ioctl.h       |  2 ++
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +11 -1
index fcfde9140bce..96abae515bcf 100644
@@ -756,10 +756,12 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange,
                         break;
                 case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
                         *update_mapping = true;
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
                         prange->flags |= attrs[i].value;
                         break;
                 case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
                         *update_mapping = true;
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
                         prange->flags &= ~attrs[i].value;
                         break;
                 case KFD_IOCTL_SVM_ATTR_GRANULARITY:
@@ -778,6 +780,9 @@ svm_range_is_same_attrs(struct kfd_process *p, struct svm_range *prange,
         uint32_t i;
         int gpuidx;
 
+       if (prange->flags & KFD_IOCTL_SVM_FLAG_ERROR)
+               return false;
+
         for (i = 0; i < nattr; i++) {
                 switch (attrs[i].type) {
                 case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC:
@@ -1657,8 +1662,11 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
 unreserve_out:
         svm_range_unreserve_bos(&ctx);
 
-       if (!r)
+       prange->flags |= KFD_IOCTL_SVM_FLAG_ERROR;
+       if (!r) {
+               prange->flags &= ~KFD_IOCTL_SVM_FLAG_ERROR;
                 prange->validate_timestamp = ktime_get_boottime();
+       }
 
         return r;
 }
@@ -3674,9 +3682,11 @@ svm_range_get_attr(struct kfd_process *p, struct mm_struct *mm,
                         break;
                 case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
                         attrs[i].value = flags_and;
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
                         break;
                 case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
                         attrs[i].value = ~flags_or;
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR;
                         break;
                 case KFD_IOCTL_SVM_ATTR_GRANULARITY:
                         attrs[i].value = (uint32_t)granularity;
include/uapi/linux/kfd_ioctl.h +2 -0
index 7e19a2d1e907..2b6f68bd06da 100644
@@ -1125,6 +1125,8 @@ struct kfd_ioctl_cross_memory_copy_deprecated_args {
 #define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY     0x00000020
 /* Keep GPU memory mapping always valid as if XNACK is disable */
 #define KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED   0x00000040
+/* Set during svm validation and map error */
+#define KFD_IOCTL_SVM_FLAG_ERROR       0x80000000
 
 /**
  * kfd_ioctl_svm_op - SVM ioctl operations

--
2.32.0

maintainer
#2 lore raw

This flag was never meant for user mode. Alex ended up implementing it differently in a way that doesn't need to change the flags exposed to user mode. See his patch "drm/amdkfd: flag added to handle errors from svm validate and map". This patch is no longer needed.

Regards,
  Felix

Am 2023-05-31 um 10:09 schrieb Deucher, Alexander:

Quoted 97 lines

[Public]

Where is the userspace code which uses this new interface? Can you add a link to the relevant branch to the commit message?

Alex
------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Alex Sierra <[email protected]> *Sent:* Monday, May 29, 2023 4:09 PM
*To:* [email protected] <[email protected]>; Kuehling, Felix <[email protected]> *Cc:* Sierra Guiza, Alejandro (Alex) <[email protected]>; Yang, Philip <[email protected]> *Subject:* [PATCH] drm/amd: SVM flag error added at svm_range flags
If a return error is raised during validation and mapping of a
prange, this flag is set. It is a rare occurrence, but it could happen
when amdgpu_hmm_range_get_pages_done returns true. In such cases,
the caller should retry. However, it is important to ensure that the
prange is updated correctly during the retry.

---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 +++++++++++- include/uapi/linux/kfd_ioctl.h       |  2 ++

 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index fcfde9140bce..96abae515bcf 100644
@@ -756,10 +756,12 @@ svm_range_apply_attrs(struct kfd_process *p, 
 struct svm_range *prange,
                          break;

                 case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
                         *update_mapping = true;
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR; prange->flags |= attrs[i].value; break;
                 case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
                         *update_mapping = true;
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR; prange->flags &= ~attrs[i].value; break;
                 case KFD_IOCTL_SVM_ATTR_GRANULARITY:

drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -0
@@ -778,6 +780,9 @@ svm_range_is_same_attrs(struct kfd_process *p, 
 struct svm_range *prange,
          uint32_t i;
          int gpuidx;
 
+       if (prange->flags & KFD_IOCTL_SVM_FLAG_ERROR)
+               return false;
+
          for (i = 0; i < nattr; i++) {
                  switch (attrs[i].type) {

                 case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC:

drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
@@ -1657,8 +1662,11 @@ static int svm_range_validate_and_map(struct 
 mm_struct *mm,

 unreserve_out:
         svm_range_unreserve_bos(&ctx);

-       if (!r)
+       prange->flags |= KFD_IOCTL_SVM_FLAG_ERROR;
+       if (!r) {
+               prange->flags &= ~KFD_IOCTL_SVM_FLAG_ERROR; prange->validate_timestamp = ktime_get_boottime(); +       }

         return r;
 }

drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
@@ -3674,9 +3682,11 @@ svm_range_get_attr(struct kfd_process *p, 
 struct mm_struct *mm,
                          break;

                 case KFD_IOCTL_SVM_ATTR_SET_FLAGS:
                         attrs[i].value = flags_and;
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR; break;
                 case KFD_IOCTL_SVM_ATTR_CLR_FLAGS:
                         attrs[i].value = ~flags_or;
+                       attrs[i].value &= ~KFD_IOCTL_SVM_FLAG_ERROR; break;
                 case KFD_IOCTL_SVM_ATTR_GRANULARITY:
                         attrs[i].value = (uint32_t)granularity;

include/uapi/linux/kfd_ioctl.h +2 -0
index 7e19a2d1e907..2b6f68bd06da 100644
@@ -1125,6 +1125,8 @@ struct kfd_ioctl_cross_memory_copy_deprecated_args {
  #define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY 0x00000020
  /* Keep GPU memory mapping always valid as if XNACK is disable */
  #define KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED 0x00000040
+/* Set during svm validation and map error */
+#define KFD_IOCTL_SVM_FLAG_ERROR       0x80000000
 
  /**
   * kfd_ioctl_svm_op - SVM ioctl operations
Signature · 1 line
2.32.0