Skip to contentSkip to conversation

drm/amdkfd: CRIU export dmabuf handles for GTT BOs

PATCH In review David Yat Sin 3 participants 4 messages Mar 8, 2022 – Mar 9, 2022

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

PATCH v2 1/1 drm/amdkfd: CRIU export dmabuf handles for GTT BOs

Export dmabuf handles for GTT BOs so that their contents can be accessed using SDMA during checkpoint/restore.

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 ++++++++----
 include/uapi/linux/kfd_ioctl.h           |  3 ++-
 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -4
index 2c7d76e67ddb..e1e2362841f8 100644
@@ -1759,7 +1759,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,
 					goto exit;
 				}
 			}
-			if (bo_bucket->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
+			if (bo_bucket->alloc_flags
+			    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT)) {
 				ret = criu_get_prime_handle(&dumper_bo->tbo.base,
 						bo_bucket->alloc_flags &
 						KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? DRM_RDWR : 0,
@@ -1812,7 +1813,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,
 
 exit:
 	while (ret && bo_index--) {
-		if (bo_buckets[bo_index].alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
+		if (bo_buckets[bo_index].alloc_flags
+		    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT))
 			close_fd(bo_buckets[bo_index].dmabuf_fd);
 	}
 
@@ -2211,7 +2213,8 @@ static int criu_restore_bo(struct kfd_process *p,
 
 	pr_debug("map memory was successful for the BO\n");
 	/* create the dmabuf object and export the bo */
-	if (bo_bucket->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
+	if (bo_bucket->alloc_flags
+	    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT)) {
 		ret = criu_get_prime_handle(&kgd_mem->bo->tbo.base, DRM_RDWR,
 					    &bo_bucket->dmabuf_fd);
 		if (ret)
@@ -2281,7 +2284,8 @@ static int criu_restore_bos(struct kfd_process *p,
 
 exit:
 	while (ret && i--) {
-		if (bo_buckets[i].alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
+		if (bo_buckets[i].alloc_flags
+		   & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT))
 			close_fd(bo_buckets[i].dmabuf_fd);
 	}
 	kvfree(bo_buckets);
include/uapi/linux/kfd_ioctl.h +2 -1
index b40687bf1014..eb9ff85f8556 100644
@@ -33,9 +33,10 @@
  * - 1.5 - Add SVM API
  * - 1.6 - Query clear flags in SVM get_attr API
  * - 1.7 - Checkpoint Restore (CRIU) API
+ * - 1.8 - CRIU - Support for SDMA transfers with GTT BOs
  */
 #define KFD_IOCTL_MAJOR_VERSION 1
-#define KFD_IOCTL_MINOR_VERSION 7
+#define KFD_IOCTL_MINOR_VERSION 8
 
 struct kfd_ioctl_get_version_args {
 	__u32 major_version;	/* from KFD */
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Am 2022-03-08 um 16:08 schrieb David Yat Sin:

Quoted 4 lines

Export dmabuf handles for GTT BOs so that their contents can be accessed using SDMA during checkpoint/restore.

Looks good to me. Please also post a link to the user mode change for this.

Note that the user mode code has not been merged upstream yet. I think this should be the final cleanup before the user mode CRIU plugin can be merged with the updated KFD version dependency.

Thanks,
  Felix

Quoted 65 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 ++++++++----
  include/uapi/linux/kfd_ioctl.h           |  3 ++-
  2 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -4
index 2c7d76e67ddb..e1e2362841f8 100644
@@ -1759,7 +1759,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,
  					goto exit;
  				}
  			}
-			if (bo_bucket->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
+			if (bo_bucket->alloc_flags
+			    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT)) {
  				ret = criu_get_prime_handle(&dumper_bo->tbo.base,
  						bo_bucket->alloc_flags &
  						KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? DRM_RDWR : 0,
@@ -1812,7 +1813,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,
 
  exit:
  	while (ret && bo_index--) {
-		if (bo_buckets[bo_index].alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
+		if (bo_buckets[bo_index].alloc_flags
+		    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT))
  			close_fd(bo_buckets[bo_index].dmabuf_fd);
  	}
 
@@ -2211,7 +2213,8 @@ static int criu_restore_bo(struct kfd_process *p,
 
  	pr_debug("map memory was successful for the BO\n");
  	/* create the dmabuf object and export the bo */
-	if (bo_bucket->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
+	if (bo_bucket->alloc_flags
+	    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT)) {
  		ret = criu_get_prime_handle(&kgd_mem->bo->tbo.base, DRM_RDWR,
  					    &bo_bucket->dmabuf_fd);
  		if (ret)
@@ -2281,7 +2284,8 @@ static int criu_restore_bos(struct kfd_process *p,
 
  exit:
  	while (ret && i--) {
-		if (bo_buckets[i].alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
+		if (bo_buckets[i].alloc_flags
+		   & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT))
  			close_fd(bo_buckets[i].dmabuf_fd);
  	}
  	kvfree(bo_buckets);
include/uapi/linux/kfd_ioctl.h +2 -1
index b40687bf1014..eb9ff85f8556 100644
@@ -33,9 +33,10 @@
   * - 1.5 - Add SVM API
   * - 1.6 - Query clear flags in SVM get_attr API
   * - 1.7 - Checkpoint Restore (CRIU) API
+ * - 1.8 - CRIU - Support for SDMA transfers with GTT BOs
   */
  #define KFD_IOCTL_MAJOR_VERSION 1
-#define KFD_IOCTL_MINOR_VERSION 7
+#define KFD_IOCTL_MINOR_VERSION 8
 
  struct kfd_ioctl_get_version_args {
  	__u32 major_version;	/* from KFD */
#2 lore raw

This is the link to the user mode change:
https://github.com/checkpoint-restore/criu/pull/1709

Regards,
David

Quoted 107 lines

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, March 8, 2022 4:20 PM
To: Yat Sin, David <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v2] drm/amdkfd: CRIU export dmabuf handles for GTT BOs

Am 2022-03-08 um 16:08 schrieb David Yat Sin:

Quoted 4 lines

Export dmabuf handles for GTT BOs so that their contents can be accessed using SDMA during checkpoint/restore.

Looks good to me. Please also post a link to the user mode change for this.

Note that the user mode code has not been merged upstream yet. I think this should be the final cleanup before the user mode CRIU plugin can be merged with the updated KFD version dependency.

Thanks,
  Felix

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_checkpoint_bos(struct

Quoted 11 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 ++++++++----
  include/uapi/linux/kfd_ioctl.h           |  3 ++-
  2 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index 2c7d76e67ddb..e1e2362841f8 100644
@@ -1759,7 +1759,8 @@ static int criu_checkpoint_bos(struct

kfd_process *p,

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_checkpoint_bos(struct kfd_process *p,

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -1
  					goto exit;
  				}
  			}
-			if (bo_bucket->alloc_flags &

KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_checkpoint_bos(struct

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -0
+			if (bo_bucket->alloc_flags
+			    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM |
+KFD_IOC_ALLOC_MEM_FLAGS_GTT)) {
  				ret = criu_get_prime_handle(&dumper_bo-
 tbo.base,
  						bo_bucket->alloc_flags &

KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? DRM_RDWR : 0, @@ -
1812,7

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

Quoted 5 lines

+1813,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,

  exit:
  	while (ret && bo_index--) {
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -1
-		if (bo_buckets[bo_index].alloc_flags &

KFD_IOC_ALLOC_MEM_FLAGS_VRAM)

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
+		if (bo_buckets[bo_index].alloc_flags
+		    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM |

KFD_IOC_ALLOC_MEM_FLAGS_GTT))

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_restore_bo(struct kfd_process · line 2218

Quoted 11 lines
  			close_fd(bo_buckets[bo_index].dmabuf_fd);
  	}
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -1
@@ -2211,7 +2213,8 @@ static int criu_restore_bo(struct kfd_process
 *p,
 
  	pr_debug("map memory was successful for the BO\n");
  	/* create the dmabuf object and export the bo */
-	if (bo_bucket->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
+	if (bo_bucket->alloc_flags
+	    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM |

KFD_IOC_ALLOC_MEM_FLAGS_GTT))

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_restore_bo(struct kfd_process · line 2220

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -0
+{
  		ret = criu_get_prime_handle(&kgd_mem->bo->tbo.base,

DRM_RDWR,

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_restore_bos(struct kfd_process · line 2285

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -1
  					    &bo_bucket->dmabuf_fd);
  		if (ret)
@@ -2281,7 +2284,8 @@ static int criu_restore_bos(struct kfd_process
 *p,
 
  exit:
  	while (ret && i--) {
-		if (bo_buckets[i].alloc_flags &

KFD_IOC_ALLOC_MEM_FLAGS_VRAM)

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_restore_bos(struct kfd_process · line 2289

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
+		if (bo_buckets[i].alloc_flags
+		   & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM |

KFD_IOC_ALLOC_MEM_FLAGS_GTT))

Quoted 20 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
  			close_fd(bo_buckets[i].dmabuf_fd);
  	}

kvfree(bo_buckets);

(quoted diff) +0 -0

b/include/uapi/linux/kfd_ioctl.h index b40687bf1014..eb9ff85f8556 100644

include/uapi/linux/kfd_ioctl.h +2 -1
@@ -33,9 +33,10 @@
   * - 1.5 - Add SVM API
   * - 1.6 - Query clear flags in SVM get_attr API
   * - 1.7 - Checkpoint Restore (CRIU) API
+ * - 1.8 - CRIU - Support for SDMA transfers with GTT BOs
   */
  #define KFD_IOCTL_MAJOR_VERSION 1
-#define KFD_IOCTL_MINOR_VERSION 7
+#define KFD_IOCTL_MINOR_VERSION 8
 
  struct kfd_ioctl_get_version_args {
  	__u32 major_version;	/* from KFD */
Reviewed-by on v2 1/1
#3 lore raw
In reply to David Yat Sin

[AMD Official Use Only]

Please ignore the previous email, that was sent in error. This one is with the minor version bump so this looks good.

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of David Yat Sin
Sent: Tuesday, March 8, 2022 4:08 PM
To: [email protected]; [email protected]
Cc: Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>
Subject: [PATCH v2] drm/amdkfd: CRIU export dmabuf handles for GTT BOs

Export dmabuf handles for GTT BOs so that their contents can be accessed using SDMA during checkpoint/restore.

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 ++++++++----
 include/uapi/linux/kfd_ioctl.h           |  3 ++-
 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +3 -1
index 2c7d76e67ddb..e1e2362841f8 100644
@@ -1759,7 +1759,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,
 					goto exit;
 				}
 			}
-			if (bo_bucket->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
+			if (bo_bucket->alloc_flags
+			    & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT)) 
+{
 				ret = criu_get_prime_handle(&dumper_bo->tbo.base,
 						bo_bucket->alloc_flags &

KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ? DRM_RDWR : 0, @@ -1812,7 +1813,8 @@ static int criu_checkpoint_bos(struct kfd_process *p,

exit:
while (ret && bo_index--) {
- if (bo_buckets[bo_index].alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
+ if (bo_buckets[bo_index].alloc_flags
+ & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT))
close_fd(bo_buckets[bo_index].dmabuf_fd);
}

@@ -2211,7 +2213,8 @@ static int criu_restore_bo(struct kfd_process *p,

pr_debug("map memory was successful for the BO\n");
/* create the dmabuf object and export the bo */
- if (bo_bucket->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
+ if (bo_bucket->alloc_flags
+ & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT)) {
ret = criu_get_prime_handle(&kgd_mem->bo->tbo.base, DRM_RDWR,
&bo_bucket->dmabuf_fd);
if (ret)
@@ -2281,7 +2284,8 @@ static int criu_restore_bos(struct kfd_process *p,

exit:
while (ret && i--) {
- if (bo_buckets[i].alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
+ if (bo_buckets[i].alloc_flags
+ & (KFD_IOC_ALLOC_MEM_FLAGS_VRAM | KFD_IOC_ALLOC_MEM_FLAGS_GTT))
close_fd(bo_buckets[i].dmabuf_fd);
}
kvfree(bo_buckets);

include/uapi/linux/kfd_ioctl.h +2 -1
@@ -33,9 +33,10 @@
  * - 1.5 - Add SVM API
  * - 1.6 - Query clear flags in SVM get_attr API
  * - 1.7 - Checkpoint Restore (CRIU) API
+ * - 1.8 - CRIU - Support for SDMA transfers with GTT BOs
  */
 #define KFD_IOCTL_MAJOR_VERSION 1
-#define KFD_IOCTL_MINOR_VERSION 7
+#define KFD_IOCTL_MINOR_VERSION 8
 
 struct kfd_ioctl_get_version_args {
 	__u32 major_version;	/* from KFD */

--
2.17.1