drm/amdkfd: CRIU export dmabuf handles for GTT BOs
authorDavid Yat Sin <david.yatsin@amd.com>
Tue, 8 Mar 2022 19:00:50 +0000 (14:00 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 15 Mar 2022 18:25:17 +0000 (14:25 -0400)
Export dmabuf handles for GTT BOs so that their contents can be accessed
using SDMA during checkpoint/restore.

v2: Squash in fix from David to set dmabuf handle to invalid for BOs
that cannot be accessed using SDMA during checkpoint/restore.

Signed-off-by: David Yat Sin <david.yatsin@amd.com>
Reviewed-by : Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
include/uapi/linux/kfd_ioctl.h

index 2c7d76e..607f65a 100644 (file)
@@ -1759,14 +1759,18 @@ 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,
                                                &bo_bucket->dmabuf_fd);
                                if (ret)
                                        goto exit;
+                       } else {
+                               bo_bucket->dmabuf_fd = KFD_INVALID_FD;
                        }
+
                        if (bo_bucket->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL)
                                bo_bucket->offset = KFD_MMAP_TYPE_DOORBELL |
                                        KFD_MMAP_GPU_ID(pdd->dev->id);
@@ -1812,7 +1816,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,12 +2216,16 @@ 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)
                        return ret;
+       } else {
+               bo_bucket->dmabuf_fd = KFD_INVALID_FD;
        }
+
        return 0;
 }
 
@@ -2281,7 +2290,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);
index b40687b..42975e9 100644 (file)
  * - 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 */
@@ -195,6 +196,8 @@ struct kfd_ioctl_dbg_wave_control_args {
        __u32 buf_size_in_bytes;        /*including gpu_id and buf_size */
 };
 
+#define KFD_INVALID_FD     0xffffffff
+
 /* Matching HSA_EVENTTYPE */
 #define KFD_IOC_EVENT_SIGNAL                   0
 #define KFD_IOC_EVENT_NODECHANGE               1