Add CRIU support for amdgpu dmabuf
Subsystems (4)
PATCH v8 1/1 Add CRIU support for amdgpu dmabuf
This patch series adds support for CRIU checkpointing of processes that share memory with the amdgpu dmabuf interface.
This v8 incorporates the vm mapping rework, which it depends on.
(https://lore.kernel.org/amd-gfx/[email protected]/T/#u)
Accompanying CRIU changes:
https://github.com/checkpoint-restore/criu/pull/2613
PATCH v8 1/3 drm/amdgpu: Add CRIU ioctl to get bo info
Add new ioctl DRM_IOCTL_AMDGPU_CRIU_BO_INFO.
This ioctl returns a list of bos with their handles, sizes, and flags and domains.
This ioctl is meant to be used during CRIU checkpoint and provide information needed to reconstruct the bos in CRIU restore.
--- drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_criu.c | 101 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_criu.h | 30 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 + include/uapi/drm/amdgpu_drm.h | 28 +++++++ 5 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_criu.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_criu.h
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
@@ -63,7 +63,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \ amdgpu_xgmi.o amdgpu_csa.o amdgpu_ras.o amdgpu_vm_cpu.o \ amdgpu_vm_sdma.o amdgpu_discovery.o amdgpu_ras_eeprom.o amdgpu_nbio.o \ amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \ - amdgpu_fw_attestation.o amdgpu_securedisplay.o \ + amdgpu_fw_attestation.o amdgpu_securedisplay.o amdgpu_criu.o \ amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \ amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o amdgpu_dev_coredump.o \ amdgpu_cper.o amdgpu_userq_fence.o amdgpu_eviction_fence.o amdgpu_ip.o
drivers/gpu/drm/amd/amdgpu/amdgpu_criu.c new file +101 -0
101 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_criu.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright 2025 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef __AMDGPU_CRIU_H__ +#define __AMDGPU_CRIU_H__ + +int amdgpu_criu_bo_info_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp); + +#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -53,6 +53,7 @@#include "amdgpu_xgmi.h" #include "amdgpu_userq.h" #include "amdgpu_userq_fence.h" +#include "amdgpu_criu.h" #include "../amdxcp/amdgpu_xcp_drv.h" /*
@@ -3027,6 +3028,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_USERQ , amdgpu_userq_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SIGNAL , amdgpu_userq_signal_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_WAIT , amdgpu_userq_wait_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(AMDGPU_CRIU_BO_INFO, amdgpu_criu_bo_info_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), }; static const struct drm_driver amdgpu_kms_driver = {
include/uapi/drm/amdgpu_drm.h +28 -0
@@ -57,6 +57,7 @@ extern "C" {#define DRM_AMDGPU_USERQ 0x16#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18 +#define DRM_AMDGPU_CRIU_BO_INFO 0x19#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -77,6 +78,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait) +#define DRM_IOCTL_AMDGPU_CRIU_BO_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CRIU_BO_INFO, struct drm_amdgpu_criu_bo_info_args)/** * DOC: memory domains
@@ -1628,6 +1630,32 @@ struct drm_color_ctm_3x4 {__u64 matrix[12 ]; }; +#define AMDGPU_CRIU_BO_FLAG_IS_IMPORT (1 << 0) + +struct drm_amdgpu_criu_bo_info_args { +/* IN: Size of bo_buckets buffer. OUT: Number of bos in process (if larger than size of buffer, must retry) */ +__u32 num_bos; + +/* User pointer to array of drm_amdgpu_criu_bo_bucket */ +__u64 bo_buckets; +}; + +struct drm_amdgpu_criu_bo_bucket { +/* Size of bo */ +__u64 size; + +/* GEM_CREATE flags for re-creation of buffer */ +__u64 alloc_flags; + +/* Pending how to handle this; provides information needed to remake the buffer on restore */ +__u32 preferred_domains; + +/* Currently just one flag: IS_IMPORT */ +__u32 flags; + +__u32 gem_handle; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.34.1
PATCH v8 2/3 drm/amdgpu: Add CRIU mapping info ioctl
In reply to David FrancisAdd new ioctl DRM_IOCTL_AMDGPU_CRIU_MAPPING_INFO, which returns a list of mappings associated with a given bo, along with their positions and offsets.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_criu.c | 97 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_criu.h | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 5 ++ include/uapi/drm/amdgpu_drm.h | 27 +++++++ 5 files changed, 133 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_criu.c +97 -0
@@ -24,6 +24,7 @@#include <drm/amdgpu_drm.h> #include <drm/drm_device.h> #include <drm/drm_file.h> +#include <drm/drm_exec.h> #include "amdgpu_criu.h" #include "amdgpu.h"
@@ -99,3 +100,99 @@ int amdgpu_criu_bo_info_ioctl(struct drm_device *dev, void *data,return ret; } + +/** +* amdgpu_criu_mapping_info_ioctl - get information about a buffer's mappings +* +* @dev: drm device pointer +* @data: drm_amdgpu_criu_mapping_info_args +* @filp: drm file pointer +* +* num_mappings is set as an input to the size of the vm_buckets array. +* num_mappings is sent back as output as the number of mappings the bo has. +* If that number is larger than the size of the array, the ioctl must +* be retried. +* +* Returns: +* 0 for success, -errno for errors. +*/ +int amdgpu_criu_mapping_info_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +struct drm_amdgpu_criu_mapping_info_args *args = data; +struct drm_gem_object *gobj =idr_find (&filp->object_idr, args->gem_handle); +struct amdgpu_vm *avm = &((struct amdgpu_fpriv *)filp->driver_priv)->vm; +struct amdgpu_bo *bo =gem_to_amdgpu_bo (gobj); +struct amdgpu_bo_va *bo_va =amdgpu_vm_bo_find (avm, bo); +struct amdgpu_fpriv *fpriv = filp->driver_priv; +struct drm_amdgpu_criu_vm_bucket *vm_buckets; +struct amdgpu_bo_va_mapping *mapping; +struct drm_exec exec; +int num_mappings =0 ; +int ret; + + vm_buckets =kvcalloc (args->num_mappings,sizeof (*vm_buckets),GFP_KERNEL ); +if (!vm_buckets) { + ret = -ENOMEM ; + goto free_vms; + } + +drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT | +DRM_EXEC_IGNORE_DUPLICATES ,0 ); + drm_exec_until_all_locked(&exec) { +if (gobj) { + ret =drm_exec_lock_obj (&exec, gobj); +drm_exec_retry_on_contention (&exec); +if (ret) + goto unlock_exec; + } + + ret =amdgpu_vm_lock_pd (&fpriv->vm, &exec,2 ); +drm_exec_retry_on_contention (&exec); +if (ret) + goto unlock_exec; + } + +amdgpu_vm_bo_va_for_each_valid_mapping (bo_va, mapping) { +if (num_mappings < args->num_mappings) { + vm_buckets[num_mappings].start = mapping->start; + vm_buckets[num_mappings].last = mapping->last; + vm_buckets[num_mappings].offset = mapping->offset; + vm_buckets[num_mappings].flags = mapping->flags; + } + num_mappings +=1 ; + } + +amdgpu_vm_bo_va_for_each_invalid_mapping (bo_va, mapping) { +if (num_mappings < args->num_mappings) { + vm_buckets[num_mappings].start = mapping->start; + vm_buckets[num_mappings].last = mapping->last; + vm_buckets[num_mappings].offset = mapping->offset; + vm_buckets[num_mappings].flags = mapping->flags; + } + num_mappings +=1 ; + } + +drm_exec_fini (&exec); + +if (num_mappings >0 ) { +if (num_mappings <= args->num_mappings) { + ret =copy_to_user ((void __user *)args->vm_buckets, vm_buckets, num_mappings *sizeof (*vm_buckets)); +if (ret) { +pr_debug ("Failed to copy BO information to user\n" ); + ret = -EFAULT ; + } + } + } + args->num_mappings = num_mappings; + +kvfree (vm_buckets); + +return ret; +unlock_exec: +drm_exec_fini (&exec); +free_vms: +kvfree (vm_buckets); + +return ret; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_criu.h +3 -0
@@ -27,4 +27,7 @@int amdgpu_criu_bo_info_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_criu_mapping_info_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp); +#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -3029,6 +3029,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SIGNAL , amdgpu_userq_signal_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_WAIT , amdgpu_userq_wait_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_CRIU_BO_INFO , amdgpu_criu_bo_info_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(AMDGPU_CRIU_MAPPING_INFO, amdgpu_criu_mapping_info_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), }; static const struct drm_driver amdgpu_kms_driver = {
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5 -0
@@ -668,4 +668,9 @@ void amdgpu_vm_tlb_fence_create(struct amdgpu_device *adev,struct amdgpu_vm *vm, struct dma_fence **fence); +#define amdgpu_vm_bo_va_for_each_valid_mapping (bo_va, mapping) \ + list_for_each_entry(mapping, &bo_va->valids, list) +#define amdgpu_vm_bo_va_for_each_invalid_mapping (bo_va, mapping) \ + list_for_each_entry(mapping, &bo_va->invalids, list) +#endif
include/uapi/drm/amdgpu_drm.h +27 -0
@@ -58,6 +58,7 @@ extern "C" {#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18#define DRM_AMDGPU_CRIU_BO_INFO 0x19 +#define DRM_AMDGPU_CRIU_MAPPING_INFO 0x20#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)#define DRM_IOCTL_AMDGPU_CRIU_BO_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CRIU_BO_INFO, struct drm_amdgpu_criu_bo_info_args) +#define DRM_IOCTL_AMDGPU_CRIU_MAPPING_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CRIU_MAPPING_INFO, struct drm_amdgpu_criu_mapping_info_args)/** * DOC: memory domains
@@ -1656,6 +1658,31 @@ struct drm_amdgpu_criu_bo_bucket {__u32 gem_handle; }; +struct drm_amdgpu_criu_mapping_info_args { +/* Handle of bo to get mappings of */ +__u32 gem_handle; + +/* IN: Size of vm_buckets buffer. OUT: Number of bos in process (if larger than size of buffer, must retry) */ +__u32 num_mappings; + +/* User pointer to array of drm_amdgpu_criu_vm_bucket */ +__u64 vm_buckets; +}; + +struct drm_amdgpu_criu_vm_bucket { +/* Start of mapping (in number of pages) */ +__u64 start; + +/* End of mapping (in number of pages) */ +__u64 last; + +/* Mapping offset */ +__u64 offset; + +/* flags needed to recreate mapping */ +__u64 flags; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.34.1
PATCH v8 3/3 drm/amdgpu: Allow kfd CRIU with no buffer objects
In reply to David FrancisThe kfd CRIU checkpoint ioctl would return an error if trying to checkpoint a process with no kfd buffer objects.
This is a normal case and should not be an error.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -2
@@ -2566,8 +2566,8 @@ static int criu_restore(struct file *filep,pr_debug ("CRIU restore (num_devices:%u num_bos:%u num_objects:%u priv_data_size:%llu)\n" , args->num_devices, args->num_bos, args->num_objects, args->priv_data_size); -if (!args->bos || !args->devices || !args->priv_data || !args->priv_data_size || - !args->num_devices || !args->num_bos) +if ((args->num_bos >0 && !args->bos) || !args->devices || !args->priv_data || + !args->priv_data_size || !args->num_devices)return -EINVAL ;mutex_lock (&p->mutex);
Signature · 1 line
2.34.1
RE: [PATCH v8 3/3] drm/amdgpu: Allow kfd CRIU with no buffer objects
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 42 lines
-----Original Message-----
From: Francis, David <[email protected]>
Sent: Friday, July 18, 2025 10:48 AM
To: [email protected]
Cc: [email protected]; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Freehill, Chris <[email protected]>; Koenig, Christian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Francis, David <[email protected]>
Subject: [PATCH v8 3/3] drm/amdgpu: Allow kfd CRIU with no buffer objectsThe kfd CRIU checkpoint ioctl would return an error if trying to checkpoint a process with no kfd buffer objects.
This is a normal case and should not be an error.
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-2@@ -2566,8 +2566,8 @@ static int criu_restore(struct file *filep,pr_debug ("CRIU restore (num_devices:%u num_bos:%u num_objects:%u priv_data_size:%llu)\n", args->num_devices, args->num_bos, args->num_objects, args- >priv_data_size); -if (!args->bos || !args->devices || !args->priv_data || !args->priv_data_size || - !args->num_devices || !args->num_bos) + if ((args->num_bos > 0 && !args->bos) || !args->devices || !args->priv_data|| + !args->priv_data_size || !args->num_devices) return -EINVAL; mutex_lock(&p->mutex);--
2.34.1