CRIU support for ROCm
Subsystems (4)
Felix Kuehling
maintainercover CRIU support for ROCm
This patch series is a prototype for supporting CRIU for ROCm applications. More work is needed before this can be upstreamed and released, including a new ioctl API that is extensible without breaking the ABI.
The user mode code to go with this can be found at
https://github.com/RadeonOpenCompute/criu/tree/criu-dev/test/others/ext-kfd
It will be discussed with the CRIU community on [email protected] and evolve together with this patch series.
This patch series is also available on github:
https://github.com/RadeonOpenCompute/ROCK-Kernel-Driver/commits/fxkamd/criu-wip
David Yat Sin (9):
drm/amdkfd: CRIU add queues support drm/amdkfd: CRIU restore queue ids drm/amdkfd: CRIU restore sdma id for queues drm/amdkfd: CRIU restore queue doorbell id drm/amdkfd: CRIU restore CU mask for queues drm/amdkfd: CRIU dump and restore queue mqds drm/amdkfd: CRIU dump/restore queue control stack drm/amdkfd: CRIU dump and restore events drm/amdkfd: CRIU implement gpu_id remapping
Rajneesh Bhardwaj (8):
x86/configs: CRIU update release defconfig x86/configs: CRIU update debug rock defconfig drm/amdkfd: CRIU Introduce Checkpoint-Restore APIs drm/amdkfd: CRIU Implement KFD helper ioctl drm/amdkfd: CRIU Implement KFD dumper ioctl drm/amdkfd: CRIU Implement KFD restore ioctl drm/amdkfd: CRIU Implement KFD resume ioctl
Revert "drm/amdgpu: Remove verify_access shortcut for KFD BOs"
arch/x86/configs/rock-dbg_defconfig | 53 +- arch/x86/configs/rock-rel_defconfig | 13 +- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 5 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 51 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 27 + drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 + drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 1445 ++++++++++++++--- drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c | 2 +- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 178 +- .../drm/amd/amdkfd/kfd_device_queue_manager.h | 11 +- drivers/gpu/drm/amd/amdkfd/kfd_events.c | 163 +- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h | 11 + .../gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c | 74 + .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c | 75 + .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 86 + .../gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c | 75 + drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 72 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 68 +- .../amd/amdkfd/kfd_process_queue_manager.c | 68 +- include/uapi/linux/kfd_ioctl.h | 110 +- 20 files changed, 2304 insertions(+), 285 deletions(-)
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Felix Kuehling
maintainerRFC PATCH 1/17 x86/configs: CRIU update release defconfig
From: Rajneesh Bhardwaj <[email protected]>
Update rock-rel_defconfig for monolithic kernel release that enables CRIU support with kfd.
--- arch/x86/configs/rock-rel_defconfig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
arch/x86/configs/rock-rel_defconfig +9 -4
@@ -1045,6 +1045,11 @@ CONFIG_PACKET_DIAG=m CONFIG_UNIX=y CONFIG_UNIX_SCM=y CONFIG_UNIX_DIAG=m +CONFIG_SMC_DIAG=y +CONFIG_XDP_SOCKETS_DIAG=y +CONFIG_INET_MPTCP_DIAG=y +CONFIG_TIPC_DIAG=y +CONFIG_VSOCKETS_DIAG=y # CONFIG_TLS is not set CONFIG_XFRM=y CONFIG_XFRM_ALGO=m
@@ -1089,7 +1094,7 @@ CONFIG_NET_FOU=m CONFIG_NET_FOU_IP_TUNNELS=y CONFIG_INET_AH=m CONFIG_INET_ESP=m -# CONFIG_INET_ESP_OFFLOAD is not set +CONFIG_INET_ESP_OFFLOAD=m # CONFIG_INET_ESPINTCP is not set CONFIG_INET_IPCOMP=m CONFIG_INET_XFRM_TUNNEL=m
@@ -1097,8 +1102,8 @@ CONFIG_INET_TUNNEL=m CONFIG_INET_DIAG=m CONFIG_INET_TCP_DIAG=m CONFIG_INET_UDP_DIAG=m -# CONFIG_INET_RAW_DIAG is not set -# CONFIG_INET_DIAG_DESTROY is not set +CONFIG_INET_RAW_DIAG=m +CONFIG_INET_DIAG_DESTROY=m CONFIG_TCP_CONG_ADVANCED=y CONFIG_TCP_CONG_BIC=m CONFIG_TCP_CONG_CUBIC=y
@@ -1126,7 +1131,7 @@ CONFIG_IPV6_ROUTE_INFO=y # CONFIG_IPV6_OPTIMISTIC_DAD is not set CONFIG_INET6_AH=m CONFIG_INET6_ESP=m -# CONFIG_INET6_ESP_OFFLOAD is not set +CONFIG_INET6_ESP_OFFLOAD=m # CONFIG_INET6_ESPINTCP is not set CONFIG_INET6_IPCOMP=m CONFIG_IPV6_MIP6=m
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 2/17 x86/configs: CRIU update debug rock defconfig
In reply to Felix KuehlingFrom: Rajneesh Bhardwaj <[email protected]>
- Update debug config for Checkpoint-Restore (CR) support
- Also include necessary options for CR with docker containers.
--- arch/x86/configs/rock-dbg_defconfig | 53 ++++++++++++++++++----------- 1 file changed, 34 insertions(+), 19 deletions(-)
arch/x86/configs/rock-dbg_defconfig +34 -19
@@ -236,6 +236,7 @@ CONFIG_BPF_SYSCALL=y CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y # CONFIG_BPF_PRELOAD is not set # CONFIG_USERFAULTFD is not set +CONFIG_USERFAULTFD=y CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE=y CONFIG_KCMP=y CONFIG_RSEQ=y
@@ -994,6 +995,11 @@ CONFIG_PACKET_DIAG=y CONFIG_UNIX=y CONFIG_UNIX_SCM=y CONFIG_UNIX_DIAG=y +CONFIG_SMC_DIAG=y +CONFIG_XDP_SOCKETS_DIAG=y +CONFIG_INET_MPTCP_DIAG=y +CONFIG_TIPC_DIAG=y +CONFIG_VSOCKETS_DIAG=y # CONFIG_TLS is not set CONFIG_XFRM=y CONFIG_XFRM_ALGO=y
@@ -1031,15 +1037,17 @@ CONFIG_SYN_COOKIES=y # CONFIG_NET_IPVTI is not set # CONFIG_NET_FOU is not set # CONFIG_NET_FOU_IP_TUNNELS is not set -# CONFIG_INET_AH is not set -# CONFIG_INET_ESP is not set -# CONFIG_INET_IPCOMP is not set -CONFIG_INET_TUNNEL=y -CONFIG_INET_DIAG=y -CONFIG_INET_TCP_DIAG=y -# CONFIG_INET_UDP_DIAG is not set -# CONFIG_INET_RAW_DIAG is not set -# CONFIG_INET_DIAG_DESTROY is not set +CONFIG_INET_AH=m +CONFIG_INET_ESP=m +CONFIG_INET_IPCOMP=m +CONFIG_INET_ESP_OFFLOAD=m +CONFIG_INET_TUNNEL=m +CONFIG_INET_XFRM_TUNNEL=m +CONFIG_INET_DIAG=m +CONFIG_INET_TCP_DIAG=m +CONFIG_INET_UDP_DIAG=m +CONFIG_INET_RAW_DIAG=m +CONFIG_INET_DIAG_DESTROY=y CONFIG_TCP_CONG_ADVANCED=y # CONFIG_TCP_CONG_BIC is not set CONFIG_TCP_CONG_CUBIC=y
@@ -1064,12 +1072,14 @@ CONFIG_TCP_MD5SIG=y CONFIG_IPV6=y # CONFIG_IPV6_ROUTER_PREF is not set # CONFIG_IPV6_OPTIMISTIC_DAD is not set -CONFIG_INET6_AH=y -CONFIG_INET6_ESP=y -# CONFIG_INET6_ESP_OFFLOAD is not set -# CONFIG_INET6_ESPINTCP is not set -# CONFIG_INET6_IPCOMP is not set -# CONFIG_IPV6_MIP6 is not set +CONFIG_INET6_AH=m +CONFIG_INET6_ESP=m +CONFIG_INET6_ESP_OFFLOAD=m +CONFIG_INET6_IPCOMP=m +CONFIG_IPV6_MIP6=m +CONFIG_INET6_XFRM_TUNNEL=m +CONFIG_INET_DCCP_DIAG=m +CONFIG_INET_SCTP_DIAG=m # CONFIG_IPV6_ILA is not set # CONFIG_IPV6_VTI is not set CONFIG_IPV6_SIT=y
@@ -1126,8 +1136,13 @@ CONFIG_NF_CT_PROTO_UDPLITE=y # CONFIG_NF_CONNTRACK_SANE is not set # CONFIG_NF_CONNTRACK_SIP is not set # CONFIG_NF_CONNTRACK_TFTP is not set -# CONFIG_NF_CT_NETLINK is not set -# CONFIG_NF_CT_NETLINK_TIMEOUT is not set +CONFIG_COMPAT_NETLINK_MESSAGES=y +CONFIG_NF_CT_NETLINK=m +CONFIG_NF_CT_NETLINK_TIMEOUT=m +CONFIG_NF_CT_NETLINK_HELPER=m +CONFIG_NETFILTER_NETLINK_GLUE_CT=y +CONFIG_SCSI_NETLINK=y +CONFIG_QUOTA_NETLINK_INTERFACE=y CONFIG_NF_NAT=m CONFIG_NF_NAT_REDIRECT=y CONFIG_NF_NAT_MASQUERADE=y
@@ -1971,7 +1986,7 @@ CONFIG_NETCONSOLE_DYNAMIC=y CONFIG_NETPOLL=y CONFIG_NET_POLL_CONTROLLER=y # CONFIG_RIONET is not set -# CONFIG_TUN is not set +CONFIG_TUN=y # CONFIG_TUN_VNET_CROSS_LE is not set CONFIG_VETH=y # CONFIG_NLMON is not set
@@ -3955,7 +3970,7 @@ CONFIG_MANDATORY_FILE_LOCKING=y CONFIG_FSNOTIFY=y CONFIG_DNOTIFY=y CONFIG_INOTIFY_USER=y -# CONFIG_FANOTIFY is not set +CONFIG_FANOTIFY=y CONFIG_QUOTA=y CONFIG_QUOTA_NETLINK_INTERFACE=y # CONFIG_PRINT_QUOTA_WARNING is not set
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 3/17 drm/amdkfd: CRIU Introduce Checkpoint-Restore APIs
In reply to Felix KuehlingFrom: Rajneesh Bhardwaj <[email protected]>
Checkpoint-Restore in userspace (CRIU) is a powerful tool that can snapshot a running process and later restore it on same or a remote machine but expects the processes that have a device file (e.g. GPU) associated with them, provide necessary driver support to assist CRIU and its extensible plugin interface. Thus, In order to support the Checkpoint-Restore of any ROCm process, the AMD Radeon Open Compute Kernel driver, needs to provide a set of new APIs that provide necessary VRAM metadata and its contents to a userspace component (CRIU plugin) that can store it in form of image files.
This introduces some new ioctls which will be used to checkpoint-Restore any KFD bound user process. KFD doesn't allow any arbitrary ioctl call unless it is called by the group leader process. Since these ioctls are expected to be called from a KFD criu plugin which has elevated ptrace attached priviledges and CAP_SYS_ADMIN capabilities attached with the file descriptors so modify KFD to allow such calls.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 60 ++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 28 ++++++ include/uapi/linux/kfd_ioctl.h | 110 ++++++++++++++++++++++- 3 files changed, 196 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +59 -1
@@ -33,6 +33,7 @@#include <linux/time.h> #include <linux/mm.h> #include <linux/mman.h> +#include <linux/ptrace.h> #include <linux/dma-buf.h> #include <asm/processor.h> #include "kfd_priv.h"
@@ -1802,6 +1803,37 @@ static int kfd_ioctl_svm(struct file *filep, struct kfd_process *p, void *data)return -EPERM ; }#endif +static int kfd_ioctl_criu_dumper (struct file *filep, +struct kfd_process *p,void *data) +{ +pr_info ("Inside %s\n" ,__func__); + +return 0 ; +} + +static int kfd_ioctl_criu_restorer (struct file *filep, +struct kfd_process *p,void *data) +{ +pr_info ("Inside %s\n" ,__func__); + +return 0 ; +} + +static int kfd_ioctl_criu_helper (struct file *filep, +struct kfd_process *p,void *data) +{ +pr_info ("Inside %s\n" ,__func__); + +return 0 ; +} + +static int kfd_ioctl_criu_resume (struct file *filep, +struct kfd_process *p,void *data) +{ +pr_info ("Inside %s\n" ,__func__); + +return 0 ; +}#define AMDKFD_IOCTL_DEF (ioctl, _func, _flags) \ [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags, \
@@ -1906,6 +1938,18 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {AMDKFD_IOCTL_DEF (AMDKFD_IOC_SET_XNACK_MODE , kfd_ioctl_set_xnack_mode,0 ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_CRIU_DUMPER , + kfd_ioctl_criu_dumper,KFD_IOC_FLAG_PTRACE_ATTACHED ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_CRIU_RESTORER , + kfd_ioctl_criu_restorer,KFD_IOC_FLAG_ROOT_ONLY ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_CRIU_HELPER , + kfd_ioctl_criu_helper,KFD_IOC_FLAG_PTRACE_ATTACHED ), + +AMDKFD_IOCTL_DEF (AMDKFD_IOC_CRIU_RESUME , + kfd_ioctl_criu_resume, KFD_IOC_FLAG_ROOT_ONLY), };#define AMDKFD_CORE_IOCTL_COUNT ARRAY_SIZE(amdkfd_ioctls)
@@ -1920,6 +1964,7 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)char *kdata =NULL ;unsigned int usize, asize;int retcode = -EINVAL ; +bool ptrace_attached = false;if (nr >=AMDKFD_CORE_IOCTL_COUNT ) goto err_i1;
@@ -1945,7 +1990,15 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)* processes need to create their own KFD device context. */ process = filep->private_data; -if (process->lead_thread != current->group_leader) { + +rcu_read_lock (); +if ((ioctl->flags &KFD_IOC_FLAG_PTRACE_ATTACHED ) && +ptrace_parent (process->lead_thread) == current) + ptrace_attached = true; +rcu_read_unlock (); + +if (process->lead_thread != current->group_leader + && !ptrace_attached) {dev_dbg (kfd_device,"Using KFD FD in wrong process\n" ); retcode = -EBADF ; goto err_i1;
@@ -1960,6 +2013,11 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) goto err_i1; } +/* KFD_IOC_FLAG_ROOT_ONLY is only for CAP_SYS_ADMIN */ +if (unlikely ((ioctl->flags &KFD_IOC_FLAG_ROOT_ONLY ) && + !capable (CAP_SYS_ADMIN ))) +return -EACCES ; +if (cmd & (IOC_IN |IOC_OUT )) {if (asize <=sizeof (stack_kdata)) { kdata = stack_kdata;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +28 -0
@@ -121,7 +121,35 @@*/ #define KFD_QUEUE_DOORBELL_MIRROR_OFFSET 512 +/** +* enum kfd_ioctl_flags - KFD ioctl flags +* Various flags that can be set in &amdkfd_ioctl_desc.flags to control how +* userspace can use a given ioctl. +*/ +enum kfd_ioctl_flags { +/** +* @KFD_IOC_FLAG_ROOT_ONLY: +* Certain KFD ioctls such as AMDKFD_IOC_CRIU_RESTORER can potentially +* perform privileged operations and load arbitrary data into MQDs and +* eventually HQD registers when the queue is mapped by HWS. In order to +* prevent this we should perform additional security checks. In other +* cases, certain ioctls such as AMDKFD_IOC_CRIU_RESUME might be called +* by an external process e.g. CRIU restore process, for each resuming +* tasks and thus require elevated privileges. +* +* This is equivalent to callers with the SYSADMIN capability. +*/ +KFD_IOC_FLAG_ROOT_ONLY =BIT (0 ), +/** +* @KFD_IOC_FLAG_PTRACE_ATTACHED: +* Certain KFD ioctls such as AMDKFD_IOC_CRIU_HELPER and +* AMDKFD_IOC_CRIU_DUMPER are expected to be called during a Checkpoint +* operation triggered by CRIU. Since, these are expected to be called +* from a PTRACE attched context, we must authenticate these. +*/ +KFD_IOC_FLAG_PTRACE_ATTACHED =BIT (1 ), +};/* * Kernel module parameter to specify maximum number of supported queues per * device
include/uapi/linux/kfd_ioctl.h +109 -1
122 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 4/17 drm/amdkfd: CRIU Implement KFD helper ioctl
In reply to Felix KuehlingFrom: Rajneesh Bhardwaj <[email protected]>
This IOCTL is expected to be called as a precursor to the actual Checkpoint operation. This does the basic discovery into the target process seized by CRIU and relays the information to the userspace that utilizes it to start the Checkpoint operation via another dedicated IOCTL.
The helper IOCTL determines the number of GPUs, buffer objects that are associated with the target process, its process id in caller's namespace since /proc/pid/mem interface maybe used to drain the contenets of the discovered buffer objects in userspace and getpid returns the pid of CRIU dumper process. Also the pid of a process inside a container might be different than its global pid so return the ns pid.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 42 ++++++++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 ++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 14 ++++++++ 3 files changed, 56 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +40 -2
@@ -1822,9 +1822,47 @@ static int kfd_ioctl_criu_restorer(struct file *filep,static int kfd_ioctl_criu_helper (struct file *filep,struct kfd_process *p,void *data) { -pr_info ("Inside %s\n" ,__func__); +struct kfd_ioctl_criu_helper_args *args = data; +struct kgd_mem *kgd_mem; +u64 num_of_bos =0 ; +int id, i =0 ; +void *mem; +int ret =0 ; -return 0 ; +pr_debug ("Inside %s\n" , __func__); +mutex_lock (&p->mutex); + +if (!kfd_has_process_device_data (p)) { +pr_err ("No pdd for given process\n" ); + ret = -ENODEV ; + goto err_unlock; + } + +/* Run over all PDDs of the process */ +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +idr_for_each_entry (&pdd->alloc_idr, mem, id) { +if (!mem) { + ret = -ENOMEM ; + goto err_unlock; + } + + kgd_mem = (struct kgd_mem *)mem; +if ((uint64_t )kgd_mem->va > pdd->gpuvm_base) + num_of_bos++; + } + } + + args->task_pid =task_pid_nr_ns (p->lead_thread, +task_active_pid_ns (p->lead_thread)); + args->num_of_devices = p->n_pdds; + args->num_of_bos = num_of_bos; +dev_dbg (kfd_device,"Num of bos = %llu\n" , num_of_bos); + +err_unlock: +mutex_unlock (&p->mutex); +return ret; } static int kfd_ioctl_criu_resume(struct file *filep,
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
@@ -932,6 +932,8 @@ void *kfd_process_device_translate_handle(struct kfd_process_device *p,void kfd_process_device_remove_obj_handle (struct kfd_process_device *pdd,int handle); +bool kfd_has_process_device_data (struct kfd_process *p); +/* PASIDs */ int kfd_pasid_init (void );void kfd_pasid_exit (void );
drivers/gpu/drm/amd/amdkfd/kfd_process.c +14 -0
@@ -1359,6 +1359,20 @@ static int init_doorbell_bitmap(struct qcm_process_device *qpd,return 0 ; } +bool kfd_has_process_device_data (struct kfd_process *p) +{ +int i; + +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (pdd) +return true; + } + +return false; +} +struct kfd_process_device *kfd_get_process_device_data (struct kfd_dev *dev,struct kfd_process *p) {
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Felix Kuehling
maintainerRFC PATCH 5/17 drm/amdkfd: CRIU Implement KFD dumper ioctl
In reply to Felix KuehlingFrom: Rajneesh Bhardwaj <[email protected]>
This adds support to discover the buffer objects that belong to a process being checkpointed. The data corresponding to these buffer objects is returned to user space plugin running under criu master context which then stores this info to recreate these buffer objects during a restore operation.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 96 +++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +95 -1
@@ -42,6 +42,7 @@#include "kfd_svm.h" #include "amdgpu_amdkfd.h" #include "kfd_smi_events.h" +#include "amdgpu_object.h" static long kfd_ioctl (struct file *,unsigned int ,unsigned long );static int kfd_open (struct inode *,struct file *);
@@ -1806,9 +1807,102 @@ static int kfd_ioctl_svm(struct file *filep, struct kfd_process *p, void *data)static int kfd_ioctl_criu_dumper (struct file *filep,struct kfd_process *p,void *data) { +struct kfd_ioctl_criu_dumper_args *args = data; +struct kfd_criu_bo_buckets *bo_bucket; +struct amdgpu_bo *dumper_bo; +int ret, id, index, i =0 ; +struct kgd_mem *kgd_mem; +void *mem; +pr_info ("Inside %s\n" ,__func__); -return 0 ; +if (args->num_of_bos ==0 ) { +pr_err ("No BOs to be dumped\n" ); +return -EINVAL ; + } + +if (p->n_pdds != args->num_of_devices) { +pr_err ("Invalid number of devices %d (expected = %d)\n" , + args->num_of_devices, p->n_pdds); +return -EINVAL ; + } + +pr_debug ("num of bos = %llu\n" , args->num_of_bos); + + bo_bucket =kvzalloc ((sizeof (struct kfd_criu_bo_buckets ) * + args->num_of_bos),GFP_KERNEL ); +if (!bo_bucket) +return -ENOMEM ; + +mutex_lock (&p->mutex); + +if (!kfd_has_process_device_data (p)) { +pr_err ("No pdd for given process\n" ); + ret = -ENODEV ; + goto err_unlock; + } + +/* Run over all PDDs of the process */ +for (index =0 ; index < p->n_pdds; index++) { +struct kfd_process_device *pdd = p->pdds[index]; + +idr_for_each_entry (&pdd->alloc_idr, mem, id) { +if (!mem) { + ret = -ENOMEM ; + goto err_unlock; + } + + kgd_mem = (struct kgd_mem *)mem; + dumper_bo = kgd_mem->bo; + +if ((uint64_t )kgd_mem->va > pdd->gpuvm_base) { +if (i >= args->num_of_bos) { +pr_err ("Num of BOs changed since last helper ioctl call\n" ); + ret = -EINVAL ; + goto err_unlock; + } + + bo_bucket[i].bo_addr = (uint64_t )kgd_mem->va; + bo_bucket[i].bo_size =amdgpu_bo_size (dumper_bo); + bo_bucket[i].gpu_id = pdd->dev->id; + bo_bucket[i].bo_alloc_flags = (uint32_t )kgd_mem->alloc_flags; + bo_bucket[i].idr_handle = id; + +if (bo_bucket[i].bo_alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL ) + bo_bucket[i].bo_offset =KFD_MMAP_TYPE_DOORBELL | +KFD_MMAP_GPU_ID (pdd->dev->id); +else if (bo_bucket[i].bo_alloc_flags & +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP ) + bo_bucket[i].bo_offset =KFD_MMAP_TYPE_MMIO | +KFD_MMAP_GPU_ID (pdd->dev->id); +else + bo_bucket[i].bo_offset =amdgpu_bo_mmap_offset (dumper_bo); + +pr_debug ("bo_size = 0x%llx, bo_addr = 0x%llx bo_offset = 0x%llx\n" +"gpu_id = 0x%x alloc_flags = 0x%x idr_handle = 0x%x" , + bo_bucket[i].bo_size, + bo_bucket[i].bo_addr, + bo_bucket[i].bo_offset, + bo_bucket[i].gpu_id, + bo_bucket[i].bo_alloc_flags, + bo_bucket[i].idr_handle); + i++; + } + } + } + + ret =copy_to_user ((void __user *)args->kfd_criu_bo_buckets_ptr, + bo_bucket, + (args->num_of_bos * +sizeof (struct kfd_criu_bo_buckets ))); +kvfree (bo_bucket); +mutex_unlock (&p->mutex); +return ret ? -EFAULT :0 ; + +err_unlock: +mutex_unlock (&p->mutex); +pr_err ("Dumper ioctl failed err:%d\n" , ret); +return ret; } static int kfd_ioctl_criu_restorer(struct file *filep,
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 6/17 drm/amdkfd: CRIU Implement KFD restore ioctl
In reply to Felix KuehlingFrom: Rajneesh Bhardwaj <[email protected]>
This implements the KFD CRIU Restore ioctl that lays the basic foundation for the CRIU restore operation. It provides support to create the buffer objects corresponding to Non-Paged system memory mapped for GPU and/or CPU access and lays basic foundation for the userptrs buffer objects which will be added in a seperate patch. This ioctl creates various types of buffer objects such as VRAM, MMIO, Doorbell, GTT based on the date sent from the userspace plugin. The data mostly contains the previously checkpointed KFD images from some KFD processs.
While restoring a criu process, attach old IDR values to newly created BOs. This also adds the minimal gpu mapping support for a single gpu checkpoint restore use case.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 321 ++++++++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 + 2 files changed, 325 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +319 -2
@@ -1804,6 +1804,94 @@ static int kfd_ioctl_svm(struct file *filep, struct kfd_process *p, void *data)return -EPERM ; }#endif +static int kfd_devinfo_dump (struct kfd_process *p,struct kfd_ioctl_criu_dumper_args *args) +{ +int ret =0 ; +int index; +struct kfd_criu_devinfo_bucket *devinfos; + +if (p->n_pdds != args->num_of_devices) +return -EINVAL ; + + devinfos =kvzalloc ((sizeof (struct kfd_criu_devinfo_bucket ) * + args->num_of_devices),GFP_KERNEL ); +if (!devinfos) +return -ENOMEM ; + +for (index =0 ; index < p->n_pdds; index++) { +struct kfd_process_device *pdd = p->pdds[index]; + + devinfos[index].user_gpu_id = pdd->user_gpu_id; + devinfos[index].actual_gpu_id = pdd->dev->id; + } + + ret =copy_to_user ((void __user *)args->kfd_criu_devinfo_buckets_ptr, + devinfos, + (args->num_of_devices * +sizeof (struct kfd_criu_devinfo_bucket ))); +if (ret) + ret = -EFAULT ; + +kvfree (devinfos); +return ret; +} + +static int kfd_devinfo_restore (struct kfd_process *p,struct kfd_criu_devinfo_bucket *devinfos, +uint32_t num_of_devices) +{ +int i; + +if (p->n_pdds != num_of_devices) +return -EINVAL ; + +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_dev *dev; +struct kfd_process_device *pdd; +struct file *drm_file; + + dev =kfd_device_by_id (devinfos[i].actual_gpu_id); +if (!dev) { +pr_err ("Failed to find device with gpu_id = %x\n" , + devinfos[i].actual_gpu_id); +return -EINVAL ; + } + + pdd =kfd_get_process_device_data (dev, p); +if (!pdd) { +pr_err ("Failed to get pdd for gpu_id = %x\n" , devinfos[i].actual_gpu_id); +return -EINVAL ; + } + pdd->user_gpu_id = devinfos[i].user_gpu_id; + + drm_file =fget (devinfos[i].drm_fd); +if (!drm_file) { +pr_err ("Invalid render node file descriptor sent from plugin (%d)\n" , + devinfos[i].drm_fd); +return -EINVAL ; + } + +if (pdd->drm_file) +return -EINVAL ; + +/* create the vm using render nodes for kfd pdd */ +if (kfd_process_device_init_vm (pdd, drm_file)) { +pr_err ("could not init vm for given pdd\n" ); +/* On success, the PDD keeps the drm_file reference */ +fput (drm_file); +return -EINVAL ; + } +/* +* pdd now already has the vm bound to render node so below api won't create a new +* exclusive kfd mapping but use existing one with renderDXXX but is still needed +* for iommu v2 binding and runtime pm. +*/ + pdd =kfd_bind_process_to_device (dev, p); +if (IS_ERR (pdd)) +return PTR_ERR (pdd); + } +return 0 ; +} +static int kfd_ioctl_criu_dumper (struct file *filep,struct kfd_process *p,void *data) {
@@ -1842,6 +1930,10 @@ static int kfd_ioctl_criu_dumper(struct file *filep, goto err_unlock; } + ret =kfd_devinfo_dump (p, args); +if (ret) + goto err_unlock; +/* Run over all PDDs of the process */ for (index =0 ; index < p->n_pdds; index++) {struct kfd_process_device *pdd = p->pdds[index];
@@ -1908,9 +2000,234 @@ static int kfd_ioctl_criu_dumper(struct file *filep,static int kfd_ioctl_criu_restorer (struct file *filep,struct kfd_process *p,void *data) { -pr_info ("Inside %s\n" ,__func__); +struct kfd_ioctl_criu_restorer_args *args = data; +struct kfd_criu_devinfo_bucket *devinfos =NULL ; +uint64_t *restored_bo_offsets_arr =NULL ; +struct kfd_criu_bo_buckets *bo_bucket =NULL ; +long err =0 ; +int ret, i, j =0 ; -return 0 ; + devinfos =kvzalloc ((sizeof (struct kfd_criu_devinfo_bucket ) * + args->num_of_devices),GFP_KERNEL ); +if (!devinfos) { + err = -ENOMEM ; + goto failed; + } + + err =copy_from_user (devinfos, + (void __user *)args->kfd_criu_devinfo_buckets_ptr, +sizeof (struct kfd_criu_devinfo_bucket ) * + args->num_of_devices); +if (err !=0 ) { + err = -EFAULT ; + goto failed; + } + +mutex_lock (&p->mutex); + err =kfd_devinfo_restore (p, devinfos, args->num_of_devices); +if (err) + goto err_unlock; + + + bo_bucket =kvzalloc ((sizeof (struct kfd_criu_bo_buckets ) * + args->num_of_bos),GFP_KERNEL ); +if (!bo_bucket) { + err = -ENOMEM ; + goto err_unlock; + } + + err =copy_from_user (bo_bucket, + (void __user *)args->kfd_criu_bo_buckets_ptr, + args->num_of_bos *sizeof (struct kfd_criu_bo_buckets )); +if (err !=0 ) { + err = -EFAULT ; + goto err_unlock; + } + + restored_bo_offsets_arr =kvmalloc_array (args->num_of_bos, +sizeof (*restored_bo_offsets_arr), +GFP_KERNEL ); +if (!restored_bo_offsets_arr) { + err = -ENOMEM ; + goto err_unlock; + } + +/* Create and map new BOs */ +for (i =0 ; i < args->num_of_bos; i++) { +struct kfd_dev *dev; +struct kfd_process_device *pdd; +void *mem; +u64 offset; +int idr_handle; + + dev =kfd_device_by_id (bo_bucket[i].gpu_id); +if (!dev) { + err = -EINVAL ; +pr_err ("Failed to get pdd\n" ); + goto err_unlock; + } + pdd =kfd_get_process_device_data (dev, p); +if (!pdd) { + err = -EINVAL ; +pr_err ("Failed to get pdd\n" ); + goto err_unlock; + } + +pr_debug ("kfd restore ioctl - bo_bucket[%d]:\n" , i); +pr_debug ("bo_size = 0x%llx, bo_addr = 0x%llx bo_offset = 0x%llx\n" +"gpu_id = 0x%x alloc_flags = 0x%x\n" +"idr_handle = 0x%x\n" , + bo_bucket[i].bo_size, + bo_bucket[i].bo_addr, + bo_bucket[i].bo_offset, + bo_bucket[i].gpu_id, + bo_bucket[i].bo_alloc_flags, + bo_bucket[i].idr_handle); + +if (bo_bucket[i].bo_alloc_flags & +KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL ) { +pr_debug ("restore ioctl: KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL\n" ); +if (bo_bucket[i].bo_size != +kfd_doorbell_process_slice (dev)) { + err = -EINVAL ; + goto err_unlock; + } + offset =kfd_get_process_doorbells (pdd); + }else if (bo_bucket[i].bo_alloc_flags & +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP ) { +/* MMIO BOs need remapped bus address */ +pr_info ("restore ioctl :KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP\n" ); +if (bo_bucket[i].bo_size !=PAGE_SIZE ) { +pr_err ("Invalid page size\n" ); + err = -EINVAL ; + goto err_unlock; + } + offset =amdgpu_amdkfd_get_mmio_remap_phys_addr (dev->kgd); +if (!offset) { +pr_err ("amdgpu_amdkfd_get_mmio_remap_phys_addr failed\n" ); + err = -ENOMEM ; + goto err_unlock; + } + } + +/* Create the BO */ + ret =amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu (dev->kgd, + bo_bucket[i].bo_addr, + bo_bucket[i].bo_size, + pdd->drm_priv, + (struct kgd_mem **) &mem, + &offset, + bo_bucket[i].bo_alloc_flags); +if (ret) { +pr_err ("Could not create the BO\n" ); + err = -ENOMEM ; + goto err_unlock; + } +pr_debug ("New BO created: bo_size = 0x%llx, bo_addr = 0x%llx bo_offset = 0x%llx\n" , + bo_bucket[i].bo_size, bo_bucket[i].bo_addr, offset); + +/* Restore previuos IDR handle */ +pr_debug ("Restoring old IDR handle for the BO" ); + idr_handle =idr_alloc (&pdd->alloc_idr, mem, + bo_bucket[i].idr_handle, + bo_bucket[i].idr_handle +1 ,GFP_KERNEL ); +if (idr_handle <0 ) { +pr_err ("Could not allocate idr\n" ); +amdgpu_amdkfd_gpuvm_free_memory_of_gpu (dev->kgd, + (struct kgd_mem *)mem, + pdd->drm_priv,NULL ); + goto err_unlock; + } + +if (bo_bucket[i].bo_alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL ) + restored_bo_offsets_arr[i] =KFD_MMAP_TYPE_DOORBELL | +KFD_MMAP_GPU_ID (pdd->dev->id); +if (bo_bucket[i].bo_alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP ) { + restored_bo_offsets_arr[i] =KFD_MMAP_TYPE_MMIO | +KFD_MMAP_GPU_ID (pdd->dev->id); + }else if (bo_bucket[i].bo_alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_GTT ) { + restored_bo_offsets_arr[i] = offset; +pr_debug ("updating offset for GTT\n" ); + }else if (bo_bucket[i].bo_alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_VRAM ) { + restored_bo_offsets_arr[i] = offset; +/* Update the VRAM usage count */ +WRITE_ONCE (pdd->vram_usage, + pdd->vram_usage + bo_bucket[i].bo_size); +pr_debug ("updating offset for VRAM\n" ); + } + +/* now map these BOs to GPU/s */ +for (j =0 ; j < args->num_of_devices; j++) { +struct kfd_dev *peer; +struct kfd_process_device *peer_pdd; + + peer =kfd_device_by_id (devinfos[j].actual_gpu_id); + +pr_debug ("Inside mapping loop with desired gpu_id = 0x%x\n" , + devinfos[j].actual_gpu_id); +if (!peer) { +pr_debug ("Getting device by id failed for 0x%x\n" , + devinfos[j].actual_gpu_id); + err = -EINVAL ; + goto err_unlock; + } + + peer_pdd =kfd_bind_process_to_device (peer, p); +if (IS_ERR (peer_pdd)) { + err =PTR_ERR (peer_pdd); + goto err_unlock; + } +pr_debug ("map mem in restore ioctl -> 0x%llx\n" , + ((struct kgd_mem *)mem)->va); + err =amdgpu_amdkfd_gpuvm_map_memory_to_gpu (peer->kgd, + (struct kgd_mem *)mem, peer_pdd->drm_priv); +if (err) { +pr_err ("Failed to map to gpu %d/%d\n" , + j, args->num_of_devices); + goto err_unlock; + } + } + + err =amdgpu_amdkfd_gpuvm_sync_memory (dev->kgd, + (struct kgd_mem *) mem, true); +if (err) { +pr_debug ("Sync memory failed, wait interrupted by user signal\n" ); + goto err_unlock; + } + +pr_info ("map memory was successful for the BO\n" ); + }/* done */ + +/* Flush TLBs after waiting for the page table updates to complete */ +for (j =0 ; j < args->num_of_devices; j++) { +struct kfd_dev *peer; +struct kfd_process_device *peer_pdd; + + peer =kfd_device_by_id (devinfos[j].actual_gpu_id); +if (WARN_ON_ONCE (!peer)) +continue ; + peer_pdd =kfd_get_process_device_data (peer, p); +if (WARN_ON_ONCE (!peer_pdd)) +continue ; +kfd_flush_tlb (peer_pdd); + } + + ret =copy_to_user ((void __user *)args->restored_bo_array_ptr, + restored_bo_offsets_arr, + (args->num_of_bos *sizeof (*restored_bo_offsets_arr))); +if (ret) { + err = -EFAULT ; + goto err_unlock; + } + +err_unlock: +mutex_unlock (&p->mutex); +failed: +kvfree (bo_bucket); +kvfree (restored_bo_offsets_arr); +kvfree (devinfos); + +return err; } static int kfd_ioctl_criu_helper(struct file *filep,
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -0
@@ -758,6 +758,12 @@ struct kfd_process_device {* number of CU's a device has along with number of other competing processes */ struct attribute attr_cu_occupancy; +/* +* If this process has been checkpointed before, then the user +* application will use the original gpu_id on the +* checkpointed node to refer to this device. +*/ +uint32_t user_gpu_id; };#define qpd_to_pdd (x) container_of(x, struct kfd_process_device, qpd)
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 7/17 drm/amdkfd: CRIU Implement KFD resume ioctl
In reply to Felix KuehlingFrom: Rajneesh Bhardwaj <[email protected]>
This adds support to create userptr BOs on restore and introduces a new ioctl to restart memory notifiers for the restored userptr BOs. When doing CRIU restore MMU notifications can happen anytime after we call amdgpu_mn_register. Prevent MMU notifications until we reach stage-4 of the restore process i.e. criu_resume ioctl is recieved, and the process is ready to be resumed. This ioctl is different from other KFD CRIU ioctls since its called by CRIU master restore process for all the target processes being resumed by CRIU.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 5 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 51 ++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 20 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 + drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 63 ++++++++++++++++--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 36 +++++++++-- 7 files changed, 159 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +4 -1
@@ -117,6 +117,7 @@ struct amdkfd_process_info {atomic_t evicted_bos;struct delayed_work restore_userptr_work;struct pid *pid; +bool block_mmu_notifications; };int amdgpu_amdkfd_init (void );
@@ -249,7 +250,9 @@ uint64_t amdgpu_amdkfd_gpuvm_get_process_page_dir(void *drm_priv);int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu (struct kgd_dev *kgd,uint64_t va,uint64_t size,void *drm_priv,struct kgd_mem **mem, -uint64_t *offset,uint32_t flags); +uint64_t *offset,uint32_t flags,bool criu_resume); +void amdgpu_amdkfd_block_mmu_notifications (void *p); +int amdgpu_amdkfd_criu_resume (void *p);int amdgpu_amdkfd_gpuvm_free_memory_of_gpu (struct kgd_dev *kgd,struct kgd_mem *mem,void *drm_priv,uint64_t *size);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +48 -3
90 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +20 -0
@@ -1181,6 +1181,26 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_device *bdev,return ttm_pool_free (&adev->mman.bdev.pool, ttm); } +/** +* amdgpu_ttm_tt_get_userptr - Return the userptr GTT ttm_tt for the current +* task +* +* @tbo: The ttm_buffer_object that contains the userptr +* @user_addr: The returned value +*/ +int amdgpu_ttm_tt_get_userptr (const struct ttm_buffer_object *tbo, +uint64_t *user_addr) +{ +struct amdgpu_ttm_tt *gtt; + +if (!tbo->ttm) +return -EINVAL ; + + gtt = (void *)tbo->ttm; + *user_addr = gtt->userptr; +return 0 ; +} +/** * amdgpu_ttm_tt_set_userptr - Initialize userptr GTT ttm_tt for the current * task
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +2 -0
@@ -168,6 +168,8 @@ static inline bool amdgpu_ttm_tt_get_user_pages_done(struct ttm_tt *ttm)#endif void amdgpu_ttm_tt_set_user_pages (struct ttm_tt *ttm,struct page **pages); +int amdgpu_ttm_tt_get_userptr (const struct ttm_buffer_object *tbo, +uint64_t *user_addr);int amdgpu_ttm_tt_set_userptr (struct ttm_buffer_object *bo,uint64_t addr,uint32_t flags);bool amdgpu_ttm_tt_has_userptr (struct ttm_tt *ttm);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +53 -10
113 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
@@ -937,6 +937,7 @@ void *kfd_process_device_translate_handle(struct kfd_process_device *p, int handle);void kfd_process_device_remove_obj_handle (struct kfd_process_device *pdd,int handle); +struct kfd_process *kfd_lookup_process_by_pid (struct pid *pid);bool kfd_has_process_device_data (struct kfd_process *p);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +31 -5
@@ -65,7 +65,8 @@ static struct workqueue_struct *kfd_process_wq;*/ static struct workqueue_struct *kfd_restore_wq; -static struct kfd_process *find_process (const struct task_struct *thread); +static struct kfd_process *find_process (const struct task_struct *thread, +bool ref);static void kfd_process_ref_release (struct kref *ref);static struct kfd_process *create_process (const struct task_struct *thread);static int kfd_process_init_cwsr_apu (struct kfd_process *p,struct file *filep);
@@ -670,7 +671,8 @@ static int kfd_process_alloc_gpuvm(struct kfd_process_device *pdd,int err; err =amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu (kdev->kgd, gpu_va, size, - pdd->drm_priv, &mem,NULL , flags); + pdd->drm_priv, &mem,NULL , flags, + false);if (err) goto err_alloc_mem;
@@ -773,7 +775,7 @@ struct kfd_process *kfd_create_process(struct file *filep)mutex_lock (&kfd_processes_mutex);/* A prior open of /dev/kfd could have already created the process. */ - process =find_process (thread); + process =find_process (thread, false);if (process) {pr_debug ("Process already found\n" ); }else {
@@ -852,7 +854,7 @@ struct kfd_process *kfd_get_process(const struct task_struct *thread)if (thread->group_leader->mm != thread->mm)return ERR_PTR (-EINVAL ); - process =find_process (thread); + process =find_process (thread, false);if (!process)return ERR_PTR (-EINVAL );
@@ -871,13 +873,16 @@ static struct kfd_process *find_process_by_mm(const struct mm_struct *mm)return NULL ; } -static struct kfd_process *find_process (const struct task_struct *thread) +static struct kfd_process *find_process (const struct task_struct *thread, +bool ref) {struct kfd_process *p;int idx; idx =srcu_read_lock (&kfd_processes_srcu); p =find_process_by_mm (thread->mm); +if (p && ref) +kref_get (&p->ref);srcu_read_unlock (&kfd_processes_srcu, idx);return p;
@@ -1578,6 +1583,27 @@ void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,idr_remove (&pdd->alloc_idr, handle); } +/* This increments the process->ref counter. */ +struct kfd_process *kfd_lookup_process_by_pid (struct pid *pid) +{ +struct task_struct *task =NULL ; +struct kfd_process *p =NULL ; + +if (!pid) { + task = current; +get_task_struct (task); + }else { + task =get_pid_task (pid,PIDTYPE_PID ); + } + +if (task) { + p =find_process (task, true); +put_task_struct (task); + } + +return p; +} +/* This increments the process->ref counter. */ struct kfd_process *kfd_lookup_process_by_pasid (u32 pasid) {
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 8/17 drm/amdkfd: CRIU add queues support
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
Add support to existing CRIU ioctl's to save number of queues and queue properties for each queue during checkpoint and re-create queues on restore.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 234 ++++++++++++++++++++++- 1 file changed, 231 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +231 -3
@@ -1840,7 +1840,6 @@ static int kfd_devinfo_restore(struct kfd_process *p, struct kfd_criu_devinfo_bu uint32_t num_of_devices) {int i; -if (p->n_pdds != num_of_devices)return -EINVAL ;
@@ -1891,6 +1890,77 @@ static int kfd_devinfo_restore(struct kfd_process *p, struct kfd_criu_devinfo_bu }return 0 ; } +static void criu_dump_queue (struct kfd_process_device *pdd, +struct queue *q, +struct kfd_criu_q_bucket *q_bucket) +{ + q_bucket->gpu_id = pdd->dev->id; + q_bucket->type = q->properties.type; + q_bucket->format = q->properties.format; + q_bucket->q_id = q->properties.queue_id; + q_bucket->q_address = q->properties.queue_address; + q_bucket->q_size = q->properties.queue_size; + q_bucket->priority = q->properties.priority; + q_bucket->q_percent = q->properties.queue_percent; + q_bucket->read_ptr_addr = (uint64_t )q->properties.read_ptr; + q_bucket->write_ptr_addr = (uint64_t )q->properties.write_ptr; + q_bucket->doorbell_id = q->doorbell_id; + q_bucket->doorbell_off = q->properties.doorbell_off; + q_bucket->sdma_id = q->sdma_id; + + q_bucket->eop_ring_buffer_address = + q->properties.eop_ring_buffer_address; + + q_bucket->eop_ring_buffer_size = q->properties.eop_ring_buffer_size; + + q_bucket->ctx_save_restore_area_address = + q->properties.ctx_save_restore_area_address; + + q_bucket->ctx_save_restore_area_size = + q->properties.ctx_save_restore_area_size; + + q_bucket->ctl_stack_size = q->properties.ctl_stack_size; +} + +static int criu_dump_queues_device (struct kfd_process_device *pdd, +unsigned *q_index, +unsigned int max_num_queues, +struct kfd_criu_q_bucket *user_buckets) +{ +struct queue *q; +struct kfd_criu_q_bucket q_bucket; +int ret =0 ; + +list_for_each_entry (q, &pdd->qpd.queues_list, list) { +if (q->properties.type !=KFD_QUEUE_TYPE_COMPUTE && + q->properties.type !=KFD_QUEUE_TYPE_SDMA && + q->properties.type !=KFD_QUEUE_TYPE_SDMA_XGMI ) { + +pr_err ("Unsupported queue type (%d)\n" , q->properties.type); +return -ENOTSUPP ; + } + +if (*q_index >= max_num_queues) { +pr_err ("Number of queues(%d) exceed allocated(%d)\n" , + *q_index, max_num_queues); + + ret = -ENOMEM ; +break ; + } + +memset (&q_bucket,0 ,sizeof (q_bucket)); +criu_dump_queue (pdd, q, &q_bucket); + ret =copy_to_user ((void __user *)&user_buckets[*q_index], + &q_bucket,sizeof (q_bucket)); +if (ret) { +pr_err ("Failed to copy queue information to user\n" ); + ret = -EFAULT ; +break ; + } + *q_index = *q_index +1 ; + } +return ret; +}static int kfd_ioctl_criu_dumper (struct file *filep,struct kfd_process *p,void *data)
@@ -1900,8 +1970,13 @@ static int kfd_ioctl_criu_dumper(struct file *filep,struct amdgpu_bo *dumper_bo;int ret, id, index, i =0 ;struct kgd_mem *kgd_mem; +int q_index =0 ;void *mem; +struct kfd_criu_q_bucket *user_buckets = + (struct kfd_criu_q_bucket *) args->kfd_criu_q_buckets_ptr; + +pr_info ("Inside %s\n" ,__func__);if (args->num_of_bos ==0 ) {
@@ -1922,6 +1997,8 @@ static int kfd_ioctl_criu_dumper(struct file *filep,if (!bo_bucket)return -ENOMEM ; +pr_debug ("num of queues = %u\n" , args->num_of_queues); +mutex_lock (&p->mutex);if (!kfd_has_process_device_data (p)) {
@@ -1930,9 +2007,17 @@ static int kfd_ioctl_criu_dumper(struct file *filep, goto err_unlock; } + ret =kfd_process_evict_queues (p); +if (ret) { +pr_err ("Failed to evict queues\n" ); + goto err_unlock; + } + ret =kfd_devinfo_dump (p, args); -if (ret) +if (ret) { +pr_err ("Failed to dump devices\n" ); goto err_unlock; + }/* Run over all PDDs of the process */ for (index =0 ; index < p->n_pdds; index++) {
@@ -1989,6 +2074,11 @@ static int kfd_ioctl_criu_dumper(struct file *filep, i++; } } + + ret =criu_dump_queues_device (pdd, &q_index, + args->num_of_queues, user_buckets); +if (ret) + goto err_unlock; } ret = copy_to_user((void __user *)args->kfd_criu_bo_buckets_ptr,
@@ -1996,15 +2086,131 @@ static int kfd_ioctl_criu_dumper(struct file *filep, (args->num_of_bos * sizeof(struct kfd_criu_bo_buckets)));kvfree (bo_bucket); + +kfd_process_restore_queues (p);mutex_unlock (&p->mutex); -return ret ? -EFAULT :0 ; +return 0 ; err_unlock: +kfd_process_restore_queues (p);mutex_unlock (&p->mutex);pr_err ("Dumper ioctl failed err:%d\n" , ret);return ret; } +static void set_queue_properties_from_criu (struct queue_properties *qp, +struct kfd_criu_q_bucket *q_bucket) +{ + qp->is_interop = false; + qp->is_gws = q_bucket->is_gws; + qp->queue_percent = q_bucket->q_percent; + qp->priority = q_bucket->priority; + qp->queue_address = q_bucket->q_address; + qp->queue_size = q_bucket->q_size; + qp->read_ptr = (uint32_t *) q_bucket->read_ptr_addr; + qp->write_ptr = (uint32_t *) q_bucket->write_ptr_addr; + qp->eop_ring_buffer_address = q_bucket->eop_ring_buffer_address; + qp->eop_ring_buffer_size = q_bucket->eop_ring_buffer_size; + qp->ctx_save_restore_area_address = q_bucket->ctx_save_restore_area_address; + qp->ctx_save_restore_area_size = q_bucket->ctx_save_restore_area_size; + qp->ctl_stack_size = q_bucket->ctl_stack_size; + qp->type = q_bucket->type; + qp->format = q_bucket->format; +} + +/* criu_restore_queue runs with the process mutex locked */ +int criu_restore_queue (struct kfd_process *p, +struct kfd_dev *dev, +struct kfd_process_device *pdd, +struct kfd_criu_q_bucket *q_bucket) +{ +int ret =0 ; +unsigned int queue_id; +struct queue_properties qp; + +pr_debug ("Restoring Queue: gpu_id:%x type:%x format:%x queue_id:%u " +"address:%llx size:%llx priority:%u percent:%u " +"read_ptr:%llx write_ptr:%llx doorbell_id:%x " +"doorbell_off:%llx queue_address:%llx\n" , + q_bucket->gpu_id, + q_bucket->type, + q_bucket->format, + q_bucket->q_id, + q_bucket->q_address, + q_bucket->q_size, + q_bucket->priority, + q_bucket->q_percent, + q_bucket->read_ptr_addr, + q_bucket->write_ptr_addr, + q_bucket->doorbell_id, + q_bucket->doorbell_off, + q_bucket->q_address); + +memset (&qp,0 ,sizeof (qp)); +set_queue_properties_from_criu (&qp, q_bucket); +print_queue_properties (&qp); + + ret =pqm_create_queue (&p->pqm, dev,NULL , &qp, &queue_id,NULL ); +if (ret) { +pr_err ("Failed to create new queue err:%d\n" , ret); +return -EINVAL ; + } +pr_debug ("Queue id %d was restored successfully\n" , queue_id); + +return 0 ; +} + +/* criu_restore_queues runs with the process mutex locked */ +static int criu_restore_queues (struct kfd_process *p, +struct kfd_ioctl_criu_restorer_args *args) +{ +struct kfd_process_device *pdd; +struct kfd_dev *dev; +int i; +int ret; +struct kfd_criu_q_bucket *user_buckets = + (struct kfd_criu_q_bucket *) args->kfd_criu_q_buckets_ptr; +/* +* This process will not have any queues at this point, but we are +* setting all the dqm's for this process to evicted state. +*/ +kfd_process_evict_queues (p); + +for (i =0 ; i < args->num_of_queues; i++) { +struct kfd_criu_q_bucket q_bucket; + ret =copy_from_user (&q_bucket, (void __user *)&user_buckets[i], +sizeof (struct kfd_criu_q_bucket )); + +if (ret) { + ret = -EFAULT ; +pr_err ("Failed to access" ); +return ret; + } + + dev =kfd_device_by_id (q_bucket.gpu_id); +if (!dev) { +pr_err ("Could not get kfd_dev from gpu_id = 0x%x\n" , + q_bucket.gpu_id); + + ret = -EINVAL ; +return ret; + } + + pdd =kfd_get_process_device_data (dev, p); +if (!pdd) { +pr_err ("Failed to get pdd\n" ); + ret = -EFAULT ; +return ret; + } + ret =criu_restore_queue (p, dev, pdd, &q_bucket); +if (ret) { +pr_err ("Failed to restore queue (%d)\n" , ret); +break ; + } + } +return ret; +} +static int kfd_ioctl_criu_restorer (struct file *filep,struct kfd_process *p,void *data) {
@@ -2229,6 +2435,12 @@ static int kfd_ioctl_criu_restorer(struct file *filep,kfd_flush_tlb (peer_pdd); } + ret =criu_restore_queues (p, args); +if (ret) { + err = ret; + goto err_unlock; + } + ret =copy_to_user ((void __user *)args->restored_bo_array_ptr, restored_bo_offsets_arr, (args->num_of_bos *sizeof (*restored_bo_offsets_arr)));
@@ -2286,8 +2498,10 @@ static int kfd_ioctl_criu_helper(struct file *filep, {struct kfd_ioctl_criu_helper_args *args = data;struct kgd_mem *kgd_mem; +struct queue *q;u64 num_of_bos =0 ;int id, i =0 ; +u32 q_index =0 ;void *mem;int ret =0 ;
@@ -2314,12 +2528,26 @@ static int kfd_ioctl_criu_helper(struct file *filep,if ((uint64_t )kgd_mem->va > pdd->gpuvm_base) num_of_bos++; } + +list_for_each_entry (q, &pdd->qpd.queues_list, list) { +if (q->properties.type ==KFD_QUEUE_TYPE_COMPUTE || + q->properties.type ==KFD_QUEUE_TYPE_SDMA || + q->properties.type ==KFD_QUEUE_TYPE_SDMA_XGMI ) { + + q_index++; + }else { +pr_err ("Unsupported queue type (%d)\n" , q->properties.type); + ret = -ENOTSUPP ; + goto err_unlock; + } + } } args->task_pid =task_pid_nr_ns (p->lead_thread,task_active_pid_ns (p->lead_thread)); args->num_of_devices = p->n_pdds; args->num_of_bos = num_of_bos; + args->num_of_queues = q_index;dev_dbg (kfd_device,"Num of bos = %llu\n" , num_of_bos); err_unlock:
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 9/17 drm/amdkfd: CRIU restore queue ids
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
When re-creating queues during CRIU restore, restore the queue with the same queue id value used during CRIU dump. Adding a new private structure queue_restore_data to store queue restore information.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 18 ++++++++++----- drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 +++++ .../amd/amdkfd/kfd_process_queue_manager.c | 22 ++++++++++++++++++- 4 files changed, 41 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +13 -5
@@ -313,7 +313,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, dev->id); err =pqm_create_queue (&p->pqm, dev, filep, &q_properties, &queue_id, - &doorbell_offset_in_process); +NULL , &doorbell_offset_in_process);if (err !=0 ) goto err_create_queue;
@@ -1905,7 +1905,7 @@ static void criu_dump_queue(struct kfd_process_device *pdd, q_bucket->read_ptr_addr = (uint64_t )q->properties.read_ptr; q_bucket->write_ptr_addr = (uint64_t )q->properties.write_ptr; q_bucket->doorbell_id = q->doorbell_id; - q_bucket->doorbell_off = q->properties.doorbell_off; + q_bucket->sdma_id = q->sdma_id; q_bucket->eop_ring_buffer_address =
@@ -2122,7 +2122,8 @@ static void set_queue_properties_from_criu(struct queue_properties *qp,int criu_restore_queue (struct kfd_process *p,struct kfd_dev *dev,struct kfd_process_device *pdd, -struct kfd_criu_q_bucket *q_bucket) +struct kfd_criu_q_bucket *q_bucket, +struct queue_restore_data *qrd) {int ret =0 ;unsigned int queue_id;
@@ -2150,11 +2151,14 @@ int criu_restore_queue(struct kfd_process *p,set_queue_properties_from_criu (&qp, q_bucket);print_queue_properties (&qp); - ret =pqm_create_queue (&p->pqm, dev,NULL , &qp, &queue_id,NULL ); + qrd->qid = q_bucket->q_id; + + ret =pqm_create_queue (&p->pqm, dev,NULL , &qp, &queue_id, qrd,NULL );if (ret) {pr_err ("Failed to create new queue err:%d\n" , ret);return -EINVAL ; } +pr_debug ("Queue id %d was restored successfully\n" , queue_id);return 0 ;
@@ -2178,6 +2182,10 @@ static int criu_restore_queues(struct kfd_process *p,for (i =0 ; i < args->num_of_queues; i++) {struct kfd_criu_q_bucket q_bucket; +struct queue_restore_data qrd; + +memset (&qrd,0 ,sizeof (qrd)); + ret =copy_from_user (&q_bucket, (void __user *)&user_buckets[i],sizeof (struct kfd_criu_q_bucket ));
@@ -2202,7 +2210,7 @@ static int criu_restore_queues(struct kfd_process *p, ret = -EFAULT ;return ret; } - ret =criu_restore_queue (p, dev, pdd, &q_bucket); + ret =criu_restore_queue (p, dev, pdd, &q_bucket, &qrd);if (ret) {pr_err ("Failed to restore queue (%d)\n" , ret);break ;
drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c +1 -1
@@ -185,7 +185,7 @@ static int dbgdev_register_diq(struct kfd_dbgdev *dbgdev) properties.type =KFD_QUEUE_TYPE_DIQ ; status =pqm_create_queue (dbgdev->pqm, dbgdev->dev,NULL , - &properties, &qid,NULL ); + &properties, &qid,NULL ,NULL );if (status) {pr_err ("Failed to create DIQ\n" );
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -0
@@ -468,6 +468,11 @@ enum KFD_QUEUE_PRIORITY {* it's user mode or kernel mode queue. * */ + +struct queue_restore_data { +uint32_t qid; +}; +struct queue_properties {enum kfd_queue_type type;enum kfd_queue_format format;
@@ -1055,6 +1060,7 @@ int pqm_create_queue(struct process_queue_manager *pqm,struct file *f, struct queue_properties *properties, unsigned int *qid, + const struct queue_restore_data *qrd, uint32_t *p_doorbell_offset_in_process);int pqm_destroy_queue (struct process_queue_manager *pqm,unsigned int qid); int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +21 -1
@@ -42,6 +42,20 @@ static inline struct process_queue_node *get_queue_by_qid(return NULL ; } +static int assign_queue_slot_by_qid (struct process_queue_manager *pqm, +unsigned int qid) +{ +if (qid >=KFD_MAX_NUM_OF_QUEUES_PER_PROCESS ) +return -EINVAL ; + +if (__test_and_set_bit (qid, pqm->queue_slot_bitmap)) { +pr_err ("Cannot create new queue because requested qid(%u) is in use\n" , qid); +return -ENOSPC ; + } + +return 0 ; +} +static int find_available_queue_slot (struct process_queue_manager *pqm,unsigned int *qid) {
@@ -193,6 +207,7 @@ int pqm_create_queue(struct process_queue_manager *pqm,struct file *f, struct queue_properties *properties, unsigned int *qid, + const struct queue_restore_data *qrd, uint32_t *p_doorbell_offset_in_process) { int retval;
@@ -224,7 +239,12 @@ int pqm_create_queue(struct process_queue_manager *pqm,if (pdd->qpd.queue_count >= max_queues)return -ENOSPC ; - retval =find_available_queue_slot (pqm, qid); +if (qrd) { + retval =assign_queue_slot_by_qid (pqm, qrd->qid); + *qid = qrd->qid; + }else + retval =find_available_queue_slot (pqm, qid); +if (retval !=0 )return retval;
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 10/17 drm/amdkfd: CRIU restore sdma id for queues
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
When re-creating queues during CRIU restore, restore the queue with the same sdma id value used during CRIU dump.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 1 + .../drm/amd/amdkfd/kfd_device_queue_manager.c | 48 ++++++++++++++----- .../drm/amd/amdkfd/kfd_device_queue_manager.h | 3 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + .../amd/amdkfd/kfd_process_queue_manager.c | 4 +- 5 files changed, 42 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -0
@@ -2152,6 +2152,7 @@ int criu_restore_queue(struct kfd_process *p,print_queue_properties (&qp); qrd->qid = q_bucket->q_id; + qrd->sdma_id = q_bucket->sdma_id; ret =pqm_create_queue (&p->pqm, dev,NULL , &qp, &queue_id, qrd,NULL );if (ret) {
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +36 -12
96 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +2 -1
@@ -86,7 +86,8 @@ struct device_process_node {struct device_queue_manager_ops {int (*create_queue)(struct device_queue_manager *dqm,struct queue *q, -struct qcm_process_device *qpd); +struct qcm_process_device *qpd, +const struct queue_restore_data * qrd); int (*destroy_queue)(struct device_queue_manager *dqm, struct qcm_process_device *qpd,
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
@@ -471,6 +471,7 @@ enum KFD_QUEUE_PRIORITY {struct queue_restore_data {uint32_t qid; +uint32_t sdma_id; };struct queue_properties {
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +2 -2
@@ -272,7 +272,7 @@ int pqm_create_queue(struct process_queue_manager *pqm, goto err_create_queue; pqn->q = q; pqn->kq =NULL ; - retval = dev->dqm->ops.create_queue (dev->dqm, q, &pdd->qpd); + retval = dev->dqm->ops.create_queue (dev->dqm, q, &pdd->qpd, qrd);print_queue (q);break ;
@@ -292,7 +292,7 @@ int pqm_create_queue(struct process_queue_manager *pqm, goto err_create_queue; pqn->q = q; pqn->kq =NULL ; - retval = dev->dqm->ops.create_queue (dev->dqm, q, &pdd->qpd); + retval = dev->dqm->ops.create_queue (dev->dqm, q, &pdd->qpd, qrd);print_queue (q);break ;case KFD_QUEUE_TYPE_DIQ :
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Felix Kuehling
maintainerRFC PATCH 11/17 drm/amdkfd: CRIU restore queue doorbell id
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
When re-creating queues during CRIU restore, restore the queue with the same doorbell id value used during CRIU dump.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 1 + .../drm/amd/amdkfd/kfd_device_queue_manager.c | 58 +++++++++++++------ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 1 + 3 files changed, 41 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -0
@@ -2153,6 +2153,7 @@ int criu_restore_queue(struct kfd_process *p, qrd->qid = q_bucket->q_id; qrd->sdma_id = q_bucket->sdma_id; + qrd->doorbell_id = q_bucket->doorbell_id; ret =pqm_create_queue (&p->pqm, dev,NULL , &qp, &queue_id, qrd,NULL );if (ret) {
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +39 -19
91 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
@@ -472,6 +472,7 @@ enum KFD_QUEUE_PRIORITY {struct queue_restore_data {uint32_t qid;uint32_t sdma_id; +uint32_t doorbell_id; };struct queue_properties {
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 12/17 drm/amdkfd: CRIU restore CU mask for queues
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
When re-creating queues during CRIU restore, restore the queue with the same CU mask value used during CRIU dump.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 160 +++++++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 + 2 files changed, 154 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +151 -9
@@ -1890,9 +1890,21 @@ static int kfd_devinfo_restore(struct kfd_process *p, struct kfd_criu_devinfo_bu }return 0 ; } -static void criu_dump_queue (struct kfd_process_device *pdd, + +static int get_queue_data_sizes (struct kfd_process_device *pdd, +struct queue *q, +uint32_t *cu_mask_size) +{ +int ret =0 ; + + *cu_mask_size =sizeof (uint32_t ) * (q->properties.cu_mask_count /32 ); +return ret; +} + +static int criu_dump_queue (struct kfd_process_device *pdd,struct queue *q, -struct kfd_criu_q_bucket *q_bucket) +struct kfd_criu_q_bucket *q_bucket, +struct queue_restore_data *qrd) { q_bucket->gpu_id = pdd->dev->id; q_bucket->type = q->properties.type;
@@ -1920,18 +1932,30 @@ static void criu_dump_queue(struct kfd_process_device *pdd, q->properties.ctx_save_restore_area_size; q_bucket->ctl_stack_size = q->properties.ctl_stack_size; +if (qrd->cu_mask_size) +memcpy (qrd->cu_mask, q->properties.cu_mask, qrd->cu_mask_size); + + q_bucket->cu_mask_size = qrd->cu_mask_size; +return 0 ; }static int criu_dump_queues_device (struct kfd_process_device *pdd,unsigned *q_index,unsigned int max_num_queues, -struct kfd_criu_q_bucket *user_buckets) +struct kfd_criu_q_bucket *user_buckets, +uint8_t *queues_data, +uint32_t *queues_data_offset, +uint32_t queues_data_size) {struct queue *q; +struct queue_restore_data qrd;struct kfd_criu_q_bucket q_bucket; +uint8_t *data_ptr =NULL ; +unsigned int data_ptr_size =0 ;int ret =0 ;list_for_each_entry (q, &pdd->qpd.queues_list, list) { +unsigned int q_data_size;if (q->properties.type !=KFD_QUEUE_TYPE_COMPUTE && q->properties.type !=KFD_QUEUE_TYPE_SDMA && q->properties.type !=KFD_QUEUE_TYPE_SDMA_XGMI ) {
@@ -1949,7 +1973,49 @@ static int criu_dump_queues_device(struct kfd_process_device *pdd, }memset (&q_bucket,0 ,sizeof (q_bucket)); -criu_dump_queue (pdd, q, &q_bucket); +memset (&qrd,0 ,sizeof (qrd)); + + ret =get_queue_data_sizes (pdd, q, &qrd.cu_mask_size); +if (ret) { +pr_err ("Failed to get queue dump info (%d)\n" , ret); + ret = -EFAULT ; +break ; + } + + q_data_size = qrd.cu_mask_size; + +/* Increase local buffer space if needed */ +if (data_ptr_size < q_data_size) { +if (data_ptr) +kfree (data_ptr); + + data_ptr = (uint8_t *)kzalloc (q_data_size,GFP_KERNEL ); +if (!data_ptr) { + ret = -ENOMEM ; +break ; + } + data_ptr_size = q_data_size; + } + + qrd.cu_mask = data_ptr; + ret =criu_dump_queue (pdd, q, &q_bucket, &qrd); +if (ret) +break ; + +if (*queues_data_offset + q_data_size > queues_data_size) { +pr_err ("Required memory exceeds user provided\n" ); + ret = -ENOSPC ; +break ; + } + ret =copy_to_user ((void __user *) (queues_data + *queues_data_offset), + data_ptr, q_data_size); +if (ret) { + ret = -EFAULT ; +break ; + } + q_bucket.queues_data_offset = *queues_data_offset; + *queues_data_offset += q_data_size; + ret =copy_to_user ((void __user *)&user_buckets[*q_index], &q_bucket,sizeof (q_bucket));if (ret) {
@@ -1959,6 +2025,10 @@ static int criu_dump_queues_device(struct kfd_process_device *pdd, } *q_index = *q_index +1 ; } + +if (data_ptr) +kfree (data_ptr); +return ret; }
@@ -1976,6 +2046,8 @@ static int kfd_ioctl_criu_dumper(struct file *filep,struct kfd_criu_q_bucket *user_buckets = (struct kfd_criu_q_bucket *) args->kfd_criu_q_buckets_ptr; +uint8_t *queues_data = (uint8_t *)args->queues_data_ptr; +uint32_t queues_data_offset =0 ;pr_info ("Inside %s\n" ,__func__);
@@ -2076,7 +2148,10 @@ static int kfd_ioctl_criu_dumper(struct file *filep, } ret =criu_dump_queues_device (pdd, &q_index, - args->num_of_queues, user_buckets); + args->num_of_queues, user_buckets, + queues_data, &queues_data_offset, + args->queues_data_size); +if (ret) goto err_unlock; }
@@ -2098,8 +2173,9 @@ static int kfd_ioctl_criu_dumper(struct file *filep,return ret; } -static void set_queue_properties_from_criu (struct queue_properties *qp, -struct kfd_criu_q_bucket *q_bucket) +static int set_queue_properties_from_criu (struct queue_properties *qp, +struct kfd_criu_q_bucket *q_bucket, +struct queue_restore_data *qrd) { qp->is_interop = false; qp->is_gws = q_bucket->is_gws;
@@ -2116,6 +2192,19 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->ctl_stack_size = q_bucket->ctl_stack_size; qp->type = q_bucket->type; qp->format = q_bucket->format; + +if (qrd->cu_mask_size) { + qp->cu_mask =kzalloc (qrd->cu_mask_size,GFP_KERNEL ); +if (!qp->cu_mask) { +pr_err ("Failed to allocate memory for CU mask\n" ); +return -ENOMEM ; + } + +memcpy (qp->cu_mask, qrd->cu_mask, qrd->cu_mask_size); + qp->cu_mask_count = (qrd->cu_mask_size /sizeof (uint32_t )) *32 ; + } + +return 0 ; }/* criu_restore_queue runs with the process mutex locked */
@@ -2148,7 +2237,10 @@ int criu_restore_queue(struct kfd_process *p, q_bucket->q_address);memset (&qp,0 ,sizeof (qp)); -set_queue_properties_from_criu (&qp, q_bucket); + ret =set_queue_properties_from_criu (&qp, q_bucket, qrd); +if (ret) + goto err_create_queue; +print_queue_properties (&qp); qrd->qid = q_bucket->q_id;
@@ -2158,12 +2250,18 @@ int criu_restore_queue(struct kfd_process *p, ret =pqm_create_queue (&p->pqm, dev,NULL , &qp, &queue_id, qrd,NULL );if (ret) {pr_err ("Failed to create new queue err:%d\n" , ret); -return -EINVAL ; + ret = -EINVAL ; + goto err_create_queue; }pr_debug ("Queue id %d was restored successfully\n" , queue_id);return 0 ; +err_create_queue: +if (qp.cu_mask) +kfree (qp.cu_mask); + +return ret; }/* criu_restore_queues runs with the process mutex locked */
@@ -2176,6 +2274,11 @@ static int criu_restore_queues(struct kfd_process *p,int ret;struct kfd_criu_q_bucket *user_buckets = (struct kfd_criu_q_bucket *) args->kfd_criu_q_buckets_ptr; + +uint8_t *queues_data = (uint8_t *)args->queues_data_ptr; +uint8_t *data_ptr =NULL ; +uint32_t data_ptr_size =0 ; +/* * This process will not have any queues at this point, but we are * setting all the dqm's for this process to evicted state.
@@ -2185,6 +2288,7 @@ static int criu_restore_queues(struct kfd_process *p,for (i =0 ; i < args->num_of_queues; i++) {struct kfd_criu_q_bucket q_bucket;struct queue_restore_data qrd; +uint32_t q_data_size;memset (&qrd,0 ,sizeof (qrd));
@@ -2212,12 +2316,42 @@ static int criu_restore_queues(struct kfd_process *p, ret = -EFAULT ;return ret; } + + q_data_size = q_bucket.cu_mask_size; + +/* Increase local buffer space if needed */ +if (q_data_size > data_ptr_size) { +if (data_ptr) +kfree (data_ptr); + + data_ptr = (uint8_t *)kzalloc (q_data_size,GFP_KERNEL ); +if (!data_ptr) { + ret = -ENOMEM ; +break ; + } + data_ptr_size = q_data_size; + } + + ret =copy_from_user (data_ptr, + (void __user *) queues_data + q_bucket.queues_data_offset, + q_data_size); +if (ret) { + ret = -EFAULT ; +break ; + } + + qrd.cu_mask_size = q_bucket.cu_mask_size; + qrd.cu_mask = data_ptr; + ret =criu_restore_queue (p, dev, pdd, &q_bucket, &qrd);if (ret) {pr_err ("Failed to restore queue (%d)\n" , ret);break ; } } + +if (data_ptr) +kfree (data_ptr);return ret; }
@@ -2507,6 +2641,7 @@ static int kfd_ioctl_criu_helper(struct file *filep, struct kfd_process *p, void *data) { struct kfd_ioctl_criu_helper_args *args = data; +u32 queues_data_size =0 ;struct kgd_mem *kgd_mem;struct queue *q;u64 num_of_bos =0 ;
@@ -2544,6 +2679,12 @@ static int kfd_ioctl_criu_helper(struct file *filep, q->properties.type == KFD_QUEUE_TYPE_SDMA || q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) { +u32 cu_mask_size =0 ; + ret =get_queue_data_sizes (pdd, q, &cu_mask_size); +if (ret) + goto err_unlock; + + queues_data_size += cu_mask_size; q_index++; } else {pr_err ("Unsupported queue type (%d)\n" , q->properties.type);
@@ -2558,6 +2699,7 @@ static int kfd_ioctl_criu_helper(struct file *filep, args->num_of_devices = p->n_pdds; args->num_of_bos = num_of_bos; args->num_of_queues = q_index; + args->queues_data_size = queues_data_size;dev_dbg (kfd_device,"Num of bos = %llu\n" , num_of_bos); err_unlock:
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -0
@@ -473,6 +473,9 @@ struct queue_restore_data {uint32_t qid;uint32_t sdma_id;uint32_t doorbell_id; + +void *cu_mask; +uint32_t cu_mask_size; };struct queue_properties {
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 13/17 drm/amdkfd: CRIU dump and restore queue mqds
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
Dump contents of queue MQD's on CRIU dump and restore them during CRIU restore.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 35 ++++++++-- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 64 +++++++++++++++-- .../drm/amd/amdkfd/kfd_device_queue_manager.h | 8 +++ drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h | 8 +++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c | 66 ++++++++++++++++++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c | 67 ++++++++++++++++++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 68 +++++++++++++++++++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c | 67 ++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 8 +++ .../amd/amdkfd/kfd_process_queue_manager.c | 42 ++++++++++++ 10 files changed, 422 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +28 -7
@@ -1893,11 +1893,18 @@ static int kfd_devinfo_restore(struct kfd_process *p, struct kfd_criu_devinfo_bustatic int get_queue_data_sizes (struct kfd_process_device *pdd,struct queue *q, -uint32_t *cu_mask_size) +uint32_t *cu_mask_size, +uint32_t *mqd_size) {int ret =0 ; *cu_mask_size =sizeof (uint32_t ) * (q->properties.cu_mask_count /32 ); + + ret =pqm_get_queue_dump_info (&pdd->process->pqm, q->properties.queue_id, mqd_size); +if (ret) { +pr_err ("Failed to get queue dump info (%d)\n" , ret); +return ret; + }return ret; }
@@ -1906,6 +1913,8 @@ static int criu_dump_queue(struct kfd_process_device *pdd,struct kfd_criu_q_bucket *q_bucket, struct queue_restore_data *qrd) { + int ret = 0; + q_bucket->gpu_id = pdd->dev->id; q_bucket->type = q->properties.type; q_bucket->format = q->properties.format;
@@ -1935,8 +1944,15 @@ static int criu_dump_queue(struct kfd_process_device *pdd,if (qrd->cu_mask_size)memcpy (qrd->cu_mask, q->properties.cu_mask, qrd->cu_mask_size); + ret =pqm_dump_mqd (&pdd->process->pqm, q->properties.queue_id, qrd); +if (ret) { +pr_err ("Failed dump queue_mqd (%d)\n" , ret); +return ret; + } + q_bucket->cu_mask_size = qrd->cu_mask_size; -return 0 ; + q_bucket->mqd_size = qrd->mqd_size; +return ret; } static int criu_dump_queues_device(struct kfd_process_device *pdd,
@@ -1975,14 +1991,14 @@ static int criu_dump_queues_device(struct kfd_process_device *pdd,memset (&q_bucket,0 ,sizeof (q_bucket));memset (&qrd,0 ,sizeof (qrd)); - ret =get_queue_data_sizes (pdd, q, &qrd.cu_mask_size); + ret =get_queue_data_sizes (pdd, q, &qrd.cu_mask_size, &qrd.mqd_size);if (ret) {pr_err ("Failed to get queue dump info (%d)\n" , ret); ret = -EFAULT ;break ; } - q_data_size = qrd.cu_mask_size; + q_data_size = qrd.cu_mask_size + qrd.mqd_size;/* Increase local buffer space if needed */ if (data_ptr_size < q_data_size) {
@@ -1998,6 +2014,7 @@ static int criu_dump_queues_device(struct kfd_process_device *pdd, } qrd.cu_mask = data_ptr; + qrd.mqd = data_ptr + qrd.cu_mask_size; ret =criu_dump_queue (pdd, q, &q_bucket, &qrd);if (ret)break ;
@@ -2317,7 +2334,7 @@ static int criu_restore_queues(struct kfd_process *p,return ret; } - q_data_size = q_bucket.cu_mask_size; + q_data_size = q_bucket.cu_mask_size + q_bucket.mqd_size;/* Increase local buffer space if needed */ if (q_data_size > data_ptr_size) {
@@ -2343,6 +2360,9 @@ static int criu_restore_queues(struct kfd_process *p, qrd.cu_mask_size = q_bucket.cu_mask_size; qrd.cu_mask = data_ptr; + qrd.mqd_size = q_bucket.mqd_size; + qrd.mqd = data_ptr + qrd.cu_mask_size; + ret =criu_restore_queue (p, dev, pdd, &q_bucket, &qrd);if (ret) {pr_err ("Failed to restore queue (%d)\n" , ret);
@@ -2680,11 +2700,12 @@ static int kfd_ioctl_criu_helper(struct file *filep, q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) {u32 cu_mask_size =0 ; - ret =get_queue_data_sizes (pdd, q, &cu_mask_size); +u32 mqd_size =0 ; + ret =get_queue_data_sizes (pdd, q, &cu_mask_size, &mqd_size);if (ret) goto err_unlock; - queues_data_size += cu_mask_size; + queues_data_size += cu_mask_size + mqd_size; q_index++; } else {pr_err ("Unsupported queue type (%d)\n" , q->properties.type);
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +60 -4
94 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +8 -0
@@ -135,6 +135,14 @@ struct device_queue_manager_ops {void __user *ctl_stack, u32 *ctl_stack_used_size, u32 *save_area_used_size); + +void (*get_queue_dump_info)(struct device_queue_manager *dqm, +const struct queue *q, +u32 *mqd_size); + +int (*dump_mqd)(struct device_queue_manager *dqm, +const struct queue *q, +struct queue_restore_data *qrd); };struct device_queue_manager_asic_ops {
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h +8 -0
@@ -98,6 +98,14 @@ struct mqd_manager { u32 *ctl_stack_used_size, u32 *save_area_used_size); +void (*dump_mqd)(struct mqd_manager *mm,void *mqd, +struct queue_restore_data *qrd); + +void (*restore_mqd)(struct mqd_manager *mm,void **mqd, +struct kfd_mem_obj *mqd_mem_obj,uint64_t *gart_addr, +struct queue_properties *p, +const struct queue_restore_data *qrd); +#if defined(CONFIG_DEBUG_FS )int (*debugfs_show_mqd)(struct seq_file *m,void *data);#endif
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c +66 -0
84 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +67 -0
91 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +68 -0
92 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +67 -0
91 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
@@ -476,6 +476,8 @@ struct queue_restore_data {void *cu_mask;uint32_t cu_mask_size; +void *mqd; +uint32_t mqd_size; };struct queue_properties {
@@ -1087,6 +1089,12 @@ int pqm_get_wave_state(struct process_queue_manager *pqm,int amdkfd_fence_wait_timeout (uint64_t *fence_addr,uint64_t fence_value,unsigned int timeout_ms); +int pqm_get_queue_dump_info (struct process_queue_manager *pqm, +unsigned int qid, +u32 *mqd_size); +int pqm_dump_mqd (struct process_queue_manager *pqm, +unsigned int qid, +struct queue_restore_data * qrd);/* Packet Manager */
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +42 -0
48 lines not on this page · raw message
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 14/17 drm/amdkfd: CRIU dump/restore queue control stack
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
Dump contents of queue control stacks on CRIU dump and restore them during CRIU restore.
(rajneesh: rebased to 5.11 and fixed merge conflict)
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 32 +++++++++++++++---- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 10 +++++- .../drm/amd/amdkfd/kfd_device_queue_manager.h | 4 +-- drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h | 3 ++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c | 8 +++++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c | 8 +++++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 18 +++++++++++ .../gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c | 8 +++++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 ++-- .../amd/amdkfd/kfd_process_queue_manager.c | 8 ++--- 10 files changed, 89 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +25 -7
@@ -1894,13 +1894,15 @@ static int kfd_devinfo_restore(struct kfd_process *p, struct kfd_criu_devinfo_bustatic int get_queue_data_sizes (struct kfd_process_device *pdd,struct queue *q,uint32_t *cu_mask_size, -uint32_t *mqd_size) +uint32_t *mqd_size, +uint32_t *ctl_stack_size) {int ret =0 ; *cu_mask_size =sizeof (uint32_t ) * (q->properties.cu_mask_count /32 ); - ret =pqm_get_queue_dump_info (&pdd->process->pqm, q->properties.queue_id, mqd_size); + ret =pqm_get_queue_dump_info (&pdd->process->pqm, + q->properties.queue_id, mqd_size, ctl_stack_size);if (ret) {pr_err ("Failed to get queue dump info (%d)\n" , ret);return ret;
@@ -1941,6 +1943,8 @@ static int criu_dump_queue(struct kfd_process_device *pdd, q->properties.ctx_save_restore_area_size; q_bucket->ctl_stack_size = q->properties.ctl_stack_size; + +/* queue_data contains data in this order cu_mask, mqd, ctl_stack */ if (qrd->cu_mask_size)memcpy (qrd->cu_mask, q->properties.cu_mask, qrd->cu_mask_size);
@@ -1952,6 +1956,7 @@ static int criu_dump_queue(struct kfd_process_device *pdd, q_bucket->cu_mask_size = qrd->cu_mask_size; q_bucket->mqd_size = qrd->mqd_size; + q_bucket->ctl_stack_size = qrd->ctl_stack_size;return ret; }
@@ -1991,14 +1996,15 @@ static int criu_dump_queues_device(struct kfd_process_device *pdd,memset (&q_bucket,0 ,sizeof (q_bucket));memset (&qrd,0 ,sizeof (qrd)); - ret =get_queue_data_sizes (pdd, q, &qrd.cu_mask_size, &qrd.mqd_size); + ret =get_queue_data_sizes (pdd, q, &qrd.cu_mask_size, + &qrd.mqd_size, &qrd.ctl_stack_size);if (ret) {pr_err ("Failed to get queue dump info (%d)\n" , ret); ret = -EFAULT ;break ; } - q_data_size = qrd.cu_mask_size + qrd.mqd_size; + q_data_size = qrd.cu_mask_size + qrd.mqd_size + qrd.ctl_stack_size;/* Increase local buffer space if needed */ if (data_ptr_size < q_data_size) {
@@ -2013,8 +2019,11 @@ static int criu_dump_queues_device(struct kfd_process_device *pdd, data_ptr_size = q_data_size; } +/* data stored in this order: cu_mask, mqd, mqd_ctl_stack */ qrd.cu_mask = data_ptr; qrd.mqd = data_ptr + qrd.cu_mask_size; + qrd.mqd_ctl_stack = qrd.mqd + qrd.mqd_size; + ret =criu_dump_queue (pdd, q, &q_bucket, &qrd);if (ret)break ;
@@ -2334,7 +2343,8 @@ static int criu_restore_queues(struct kfd_process *p,return ret; } - q_data_size = q_bucket.cu_mask_size + q_bucket.mqd_size; + q_data_size = q_bucket.cu_mask_size + q_bucket.mqd_size + + q_bucket.ctl_stack_size;/* Increase local buffer space if needed */ if (q_data_size > data_ptr_size) {
@@ -2363,6 +2373,9 @@ static int criu_restore_queues(struct kfd_process *p, qrd.mqd_size = q_bucket.mqd_size; qrd.mqd = data_ptr + qrd.cu_mask_size; + qrd.ctl_stack_size = q_bucket.ctl_stack_size; + qrd.mqd_ctl_stack = qrd.mqd + qrd.mqd_size; + ret =criu_restore_queue (p, dev, pdd, &q_bucket, &qrd);if (ret) {pr_err ("Failed to restore queue (%d)\n" , ret);
@@ -2701,11 +2714,16 @@ static int kfd_ioctl_criu_helper(struct file *filep,u32 cu_mask_size =0 ;u32 mqd_size =0 ; - ret =get_queue_data_sizes (pdd, q, &cu_mask_size, &mqd_size); +u32 ctl_stack_size =0 ; + + ret =get_queue_data_sizes (pdd, q, + &cu_mask_size, &mqd_size, + &ctl_stack_size);if (ret) goto err_unlock; - queues_data_size += cu_mask_size + mqd_size; + queues_data_size += cu_mask_size + mqd_size + + ctl_stack_size; q_index++; }else {pr_err ("Unsupported queue type (%d)\n" , q->properties.type);
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +9 -1
@@ -1756,14 +1756,22 @@ static int get_wave_state(struct device_queue_manager *dqm,static void get_queue_dump_info (struct device_queue_manager *dqm,const struct queue *q, -u32 *mqd_size) +u32 *mqd_size, +u32 *ctl_stack_size) {struct mqd_manager *mqd_mgr;enum KFD_MQD_TYPE mqd_type =get_mqd_type_from_queue_type (q->properties.type); +dqm_lock (dqm); mqd_mgr = dqm->mqd_mgrs[mqd_type]; *mqd_size = mqd_mgr->mqd_size; + *ctl_stack_size =0 ; + +if (q->properties.type ==KFD_QUEUE_TYPE_COMPUTE && mqd_mgr->get_dump_info) + mqd_mgr->get_dump_info (mqd_mgr, q->mqd, ctl_stack_size); + +dqm_unlock (dqm); } static int dump_mqd(struct device_queue_manager *dqm,
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h +2 -2
@@ -137,8 +137,8 @@ struct device_queue_manager_ops { u32 *save_area_used_size);void (*get_queue_dump_info)(struct device_queue_manager *dqm, -const struct queue *q, -u32 *mqd_size); +const struct queue *q,u32 *mqd_size, +u32 *ctl_stack_size); int (*dump_mqd)(struct device_queue_manager *dqm, const struct queue *q,
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h +3 -0
@@ -98,6 +98,9 @@ struct mqd_manager { u32 *ctl_stack_used_size, u32 *save_area_used_size); +void (*get_dump_info)(struct mqd_manager *mm,void *mqd, +uint32_t *ctl_stack_size); +void (*dump_mqd)(struct mqd_manager *mm,void *mqd,struct queue_restore_data *qrd);
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c +8 -0
@@ -275,6 +275,13 @@ static int destroy_mqd(struct mqd_manager *mm, void *mqd, pipe_id, queue_id); } +static void get_dump_info (struct mqd_manager *mm,void *mqd, +u32 *ctl_stack_size) +{ +/* Control stack is stored in user mode */ + *ctl_stack_size =0 ; +} +static void dump_mqd (struct mqd_manager *mm,void *mqd,struct queue_restore_data *qrd) {
@@ -450,6 +457,7 @@ struct mqd_manager *mqd_manager_init_cik(enum KFD_MQD_TYPE type, mqd->update_mqd = update_mqd; mqd->destroy_mqd = destroy_mqd; mqd->is_occupied = is_occupied; + mqd->get_dump_info = get_dump_info; mqd->dump_mqd = dump_mqd; mqd->restore_mqd = restore_mqd; mqd->mqd_size =sizeof (struct cik_mqd );
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +8 -0
@@ -283,6 +283,13 @@ static int get_wave_state(struct mqd_manager *mm, void *mqd,return 0 ; } +static void get_dump_info (struct mqd_manager *mm,void *mqd, +u32 *ctl_stack_size) +{ +/* Control stack is stored in user mode */ + *ctl_stack_size =0 ; +} +static void dump_mqd (struct mqd_manager *mm,void *mqd,struct queue_restore_data *qrd) {
@@ -477,6 +484,7 @@ struct mqd_manager *mqd_manager_init_v10(enum KFD_MQD_TYPE type, mqd->is_occupied = is_occupied; mqd->mqd_size =sizeof (struct v10_compute_mqd ); mqd->get_wave_state = get_wave_state; + mqd->get_dump_info = get_dump_info; mqd->dump_mqd = dump_mqd; mqd->restore_mqd = restore_mqd;#if defined(CONFIG_DEBUG_FS )
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +18 -0
@@ -338,13 +338,24 @@ static int get_wave_state(struct mqd_manager *mm, void *mqd,return 0 ; } +static void get_dump_info (struct mqd_manager *mm,void *mqd,u32 *ctl_stack_size) +{ +struct v9_mqd *m =get_mqd (mqd); + + *ctl_stack_size = m->cp_hqd_cntl_stack_size; +} +static void dump_mqd (struct mqd_manager *mm,void *mqd,struct queue_restore_data *qrd) {struct v9_mqd *m; +/* Control stack is located one page after MQD. */ +void *mqd_ctl_stack = (void *)((uintptr_t )mqd +PAGE_SIZE ); + m =get_mqd (mqd);memcpy (qrd->mqd, m,sizeof (struct v9_mqd )); +memcpy (qrd->mqd_ctl_stack, mqd_ctl_stack, m->cp_hqd_cntl_stack_size); } static void restore_mqd(struct mqd_manager *mm, void **mqd,
@@ -354,6 +365,8 @@ static void restore_mqd(struct mqd_manager *mm, void **mqd, {uint64_t addr;struct v9_mqd *m; +void *mqd_ctl_stack; + m = (struct v9_mqd *) mqd_mem_obj->cpu_ptr; addr = mqd_mem_obj->gpu_addr;
@@ -364,6 +377,10 @@ static void restore_mqd(struct mqd_manager *mm, void **mqd, *gart_addr = addr;/* Control stack is located one page after MQD. */ + mqd_ctl_stack = (void *)((uintptr_t )*mqd +PAGE_SIZE ); +memcpy (mqd_ctl_stack, qrd->mqd_ctl_stack, qrd->ctl_stack_size); + +/* TODO: Confirm that qp->doorbell_off is restored properly */ m->cp_hqd_pq_doorbell_control = qp->doorbell_off <<CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_OFFSET__SHIFT ;
@@ -531,6 +548,7 @@ struct mqd_manager *mqd_manager_init_v9(enum KFD_MQD_TYPE type, mqd->destroy_mqd = destroy_mqd; mqd->is_occupied = is_occupied; mqd->get_wave_state = get_wave_state; + mqd->get_dump_info = get_dump_info; mqd->dump_mqd = dump_mqd; mqd->restore_mqd = restore_mqd; mqd->mqd_size =sizeof (struct v9_mqd );
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +8 -0
@@ -303,6 +303,13 @@ static int get_wave_state(struct mqd_manager *mm, void *mqd,return 0 ; } +static void get_dump_info (struct mqd_manager *mm,void *mqd, +u32 *ctl_stack_size) +{ +/* Control stack is stored in user mode */ + *ctl_stack_size =0 ; +} +static void dump_mqd (struct mqd_manager *mm,void *mqd,struct queue_restore_data *qrd) {
@@ -499,6 +506,7 @@ struct mqd_manager *mqd_manager_init_vi(enum KFD_MQD_TYPE type, mqd->destroy_mqd = destroy_mqd; mqd->is_occupied = is_occupied; mqd->get_wave_state = get_wave_state; + mqd->get_dump_info = get_dump_info; mqd->dump_mqd = dump_mqd; mqd->restore_mqd = restore_mqd; mqd->mqd_size =sizeof (struct vi_mqd );
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +4 -2
@@ -478,6 +478,8 @@ struct queue_restore_data {uint32_t cu_mask_size;void *mqd;uint32_t mqd_size; +void *mqd_ctl_stack; +uint32_t ctl_stack_size; };struct queue_properties {
@@ -1090,8 +1092,8 @@ int amdkfd_fence_wait_timeout(uint64_t *fence_addr,uint64_t fence_value, unsigned int timeout_ms);int pqm_get_queue_dump_info (struct process_queue_manager *pqm, -unsigned int qid, -u32 *mqd_size); +unsigned int qid, +u32 *mqd_size,u32 *ctl_stack_size);int pqm_dump_mqd (struct process_queue_manager *pqm,unsigned int qid,struct queue_restore_data * qrd);
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +4 -4
@@ -527,9 +527,8 @@ int pqm_get_wave_state(struct process_queue_manager *pqm, save_area_used_size); } -int pqm_get_queue_dump_info (struct process_queue_manager *pqm, -unsigned int qid, -u32 *mqd_size) +int pqm_get_queue_dump_info (struct process_queue_manager *pqm,unsigned int qid, +u32 *mqd_size,u32 *ctl_stack_size) {struct process_queue_node *pqn;
@@ -545,7 +544,8 @@ int pqm_get_queue_dump_info(struct process_queue_manager *pqm, } pqn->q->device->dqm->ops.get_queue_dump_info (pqn->q->device->dqm, - pqn->q, mqd_size); + pqn->q, mqd_size, + ctl_stack_size);return 0 ; }
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 15/17 drm/amdkfd: CRIU dump and restore events
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
Add support to existing CRIU ioctl's to save and restore events during criu checkpoint and restore.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 185 ++++++++++++++++------- drivers/gpu/drm/amd/amdkfd/kfd_events.c | 163 ++++++++++++++++---- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 11 +- 3 files changed, 279 insertions(+), 80 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +133 -52
@@ -997,6 +997,55 @@ static int kfd_ioctl_get_process_apertures_new(struct file *filp,return 0 ; } +static int kmap_event_page (struct kfd_process *p,uint64_t event_page_offset) +{ +struct kfd_dev *kfd; +struct kfd_process_device *pdd; +void *mem, *kern_addr; +uint64_t size; +int err =0 ; + +if (p->signal_page) { +pr_err ("Event page is already set\n" ); +return -EINVAL ; + } + + kfd =kfd_device_by_id (GET_GPU_ID (event_page_offset)); +if (!kfd) { +pr_err ("Getting device by id failed in %s\n" , __func__); +return -EINVAL ; + } + + pdd =kfd_bind_process_to_device (kfd, p); +if (IS_ERR (pdd)) { +mutex_unlock (&p->mutex); +return PTR_ERR (pdd); + } + + mem =kfd_process_device_translate_handle (pdd, +GET_IDR_HANDLE (event_page_offset)); +if (!mem) { +pr_err ("Can't find BO, offset is 0x%llx\n" , event_page_offset); + +mutex_unlock (&p->mutex); +return -EINVAL ; + } + + err =amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel (kfd->kgd, + mem, &kern_addr, &size); +if (err) { +pr_err ("Failed to map event page to kernel\n" ); +return err; + } + + err =kfd_event_page_set (p, kern_addr, size, event_page_offset); +if (err) { +pr_err ("Failed to set event page\n" ); +return err; + } +return err; +} +static int kfd_ioctl_create_event (struct file *filp,struct kfd_process *p,void *data) {
@@ -1008,51 +1057,11 @@ static int kfd_ioctl_create_event(struct file *filp, struct kfd_process *p,* through the event_page_offset field. */ if (args->event_page_offset) { -struct kfd_dev *kfd; -struct kfd_process_device *pdd; -void *mem, *kern_addr; -uint64_t size; - -if (p->signal_page) { -pr_err ("Event page is already set\n" ); -return -EINVAL ; - } - - kfd =kfd_device_by_id (GET_GPU_ID (args->event_page_offset)); -if (!kfd) { -pr_err ("Getting device by id failed in %s\n" , __func__); -return -EINVAL ; - } -mutex_lock (&p->mutex); - pdd =kfd_bind_process_to_device (kfd, p); -if (IS_ERR (pdd)) { - err =PTR_ERR (pdd); - goto out_unlock; - } - - mem =kfd_process_device_translate_handle (pdd, -GET_IDR_HANDLE (args->event_page_offset)); -if (!mem) { -pr_err ("Can't find BO, offset is 0x%llx\n" , - args->event_page_offset); - err = -EINVAL ; - goto out_unlock; - } + err =kmap_event_page (p, args->event_page_offset);mutex_unlock (&p->mutex); - - err =amdgpu_amdkfd_gpuvm_map_gtt_bo_to_kernel (kfd->kgd, - mem, &kern_addr, &size); -if (err) { -pr_err ("Failed to map event page to kernel\n" ); -return err; - } - - err =kfd_event_page_set (p, kern_addr, size); -if (err) { -pr_err ("Failed to set event page\n" ); +if (err)return err; - } } err = kfd_event_create(filp, p, args->event_type,
@@ -1061,10 +1070,7 @@ static int kfd_ioctl_create_event(struct file *filp, struct kfd_process *p, &args->event_page_offset, &args->event_slot_index); -return err; - -out_unlock: -mutex_unlock (&p->mutex); +pr_debug ("Created event (id:0x%08x) (%s)\n" , args->event_id, __func__);return err; }
@@ -2062,6 +2068,7 @@ static int kfd_ioctl_criu_dumper(struct file *filep, struct kfd_process *p, void *data) { struct kfd_ioctl_criu_dumper_args *args = data; +struct kfd_criu_ev_bucket *ev_buckets =NULL ;struct kfd_criu_bo_buckets *bo_bucket;struct amdgpu_bo *dumper_bo;int ret, id, index, i =0 ;
@@ -2088,14 +2095,22 @@ static int kfd_ioctl_criu_dumper(struct file *filep,return -EINVAL ; } -pr_debug ("num of bos = %llu\n" , args->num_of_bos); +pr_debug ("num of bos = %llu queues = %u events = %u\n" , args->num_of_bos, args->num_of_queues, args->num_of_events); bo_bucket =kvzalloc ((sizeof (struct kfd_criu_bo_buckets ) * args->num_of_bos),GFP_KERNEL );if (!bo_bucket)return -ENOMEM ; -pr_debug ("num of queues = %u\n" , args->num_of_queues); +if (args->num_of_events) { + ev_buckets =kvzalloc ((sizeof (struct kfd_criu_ev_bucket ) * + args->num_of_events),GFP_KERNEL ); + +if (!ev_buckets) { + ret = -ENOMEM ; + goto clean; + } + }mutex_lock (&p->mutex);
@@ -2182,6 +2197,23 @@ static int kfd_ioctl_criu_dumper(struct file *filep, goto err_unlock; } +/* Dump events */ + ret =kfd_event_dump (p, &args->event_page_offset, ev_buckets, + args->num_of_events); +if (ret) { +pr_err ("failed to dump events, ret=%d\n" , ret); + goto err_unlock; + } + ret =copy_to_user ((void __user *)args->kfd_criu_ev_buckets_ptr, + ev_buckets, + (args->num_of_events * +sizeof (struct kfd_criu_ev_bucket ))); +kvfree (ev_buckets); +if (ret) { + ret = -EFAULT ; + goto err_unlock; + } + ret = copy_to_user((void __user *)args->kfd_criu_bo_buckets_ptr, bo_bucket, (args->num_of_bos *
@@ -2195,6 +2227,8 @@ static int kfd_ioctl_criu_dumper(struct file *filep, err_unlock:kfd_process_restore_queues (p);mutex_unlock (&p->mutex); +clean: +kvfree (ev_buckets);pr_err ("Dumper ioctl failed err:%d\n" , ret);return ret; }
@@ -2388,6 +2422,47 @@ static int criu_restore_queues(struct kfd_process *p,return ret; } +/* criu_restore_queues_events runs with the process mutex locked */ +static int criu_restore_events (struct file *filp,struct kfd_process *p, +struct kfd_ioctl_criu_restorer_args *args) +{ +int i; +struct kfd_criu_ev_bucket *events; +int ret =0 ; + +if (args->event_page_offset) { + ret =kmap_event_page (p, args->event_page_offset); +if (ret) +return ret; + } + +if (!args->num_of_events) +return 0 ; + + events =kvmalloc_array (args->num_of_events, +sizeof (struct kfd_criu_ev_bucket ), +GFP_KERNEL ); +if (!events) +return -ENOMEM ; + + ret =copy_from_user (events, (void __user *) args->kfd_criu_ev_buckets_ptr, + args->num_of_events *sizeof (struct kfd_criu_ev_bucket )); + +if (ret) { + ret = -EFAULT ; + goto exit; + } + +for (i =0 ; i < args->num_of_events; i++) { + ret =kfd_event_restore (filp, p, &events[i]); +if (ret) +pr_err ("Failed to restore event with id (%d)\n" , ret); + } +exit: +kvfree (events); +return ret; +} +static int kfd_ioctl_criu_restorer (struct file *filep,struct kfd_process *p,void *data) {
@@ -2618,13 +2693,18 @@ static int kfd_ioctl_criu_restorer(struct file *filep, goto err_unlock; } + ret =criu_restore_events (filep, p, args); +if (ret) { +pr_err ("Failed to restore events (%d)" , ret); + err = ret; + goto err_unlock; + } + ret =copy_to_user ((void __user *)args->restored_bo_array_ptr, restored_bo_offsets_arr, (args->num_of_bos *sizeof (*restored_bo_offsets_arr))); -if (ret) { +if (ret) err = -EFAULT ; - goto err_unlock; - } err_unlock:mutex_unlock (&p->mutex);
@@ -2739,8 +2819,9 @@ static int kfd_ioctl_criu_helper(struct file *filep, args->num_of_bos = num_of_bos; args->num_of_queues = q_index; args->queues_data_size = queues_data_size; -dev_dbg (kfd_device,"Num of bos = %llu\n" , num_of_bos); + args->num_of_events =kfd_get_num_events (p); +dev_dbg (kfd_device,"Num of bos = %llu queues:%u events:%u\n" , args->num_of_bos, args->num_of_queues, args->num_of_events); err_unlock:mutex_unlock (&p->mutex);return ret;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +136 -27
232 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +10 -1
@@ -1190,11 +1190,20 @@ void kfd_signal_hw_exception_event(u32 pasid);int kfd_set_event (struct kfd_process *p,uint32_t event_id);int kfd_reset_event (struct kfd_process *p,uint32_t event_id);int kfd_event_page_set (struct kfd_process *p,void *kernel_address, -uint64_t size); +uint64_t size,uint64_t user_handle); +int kfd_event_create (struct file *devkfd,struct kfd_process *p,uint32_t event_type,bool auto_reset,uint32_t node_id,uint32_t *event_id,uint32_t *event_trigger_data,uint64_t *event_page_offset,uint32_t *event_slot_index); + +int kfd_event_restore (struct file *devkfd,struct kfd_process *p, +struct kfd_criu_ev_bucket *restore_ev); + +int kfd_event_dump (struct kfd_process *p,uint64_t *user_handle, +struct kfd_criu_ev_bucket *ev_buckets,uint32_t num_events); + +int kfd_get_num_events (struct kfd_process *p);int kfd_event_destroy (struct kfd_process *p,uint32_t event_id); void kfd_signal_vm_fault_event(struct kfd_dev *dev, u32 pasid,
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 16/17 drm/amdkfd: CRIU implement gpu_id remapping
In reply to Felix KuehlingFrom: David Yat Sin <[email protected]>
When doing a restore on a different node, the gpu_id's on the restore node may be different. But the user space application will still refer use the original gpu_id's in the ioctl calls. Adding code to create a gpu id mapping so that kfd can determine actual gpu_id during the user ioctl's.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 245 +++++++++++++---------- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 + drivers/gpu/drm/amd/amdkfd/kfd_process.c | 18 ++ 3 files changed, 157 insertions(+), 109 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +136 -109
@@ -294,13 +294,14 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,return err;pr_debug ("Looking for gpu id 0x%x\n" , args->gpu_id); - dev =kfd_device_by_id (args->gpu_id); -if (!dev) { + +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) {pr_debug ("Could not find gpu id 0x%x\n" , args->gpu_id);return -EINVAL ; } - -mutex_lock (&p->mutex); + dev = pdd->dev; pdd =kfd_bind_process_to_device (dev, p);if (IS_ERR (pdd)) {
@@ -491,7 +492,6 @@ static int kfd_ioctl_set_memory_policy(struct file *filep, struct kfd_process *p, void *data) { struct kfd_ioctl_set_memory_policy_args *args = data; -struct kfd_dev *dev;int err =0 ;struct kfd_process_device *pdd;enum cache_policy default_policy, alternate_policy;
@@ -506,13 +506,15 @@ static int kfd_ioctl_set_memory_policy(struct file *filep,return -EINVAL ; } - dev =kfd_device_by_id (args->gpu_id); -if (!dev) -return -EINVAL ; -mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { +pr_debug ("Could not find gpu id 0x%x\n" , args->gpu_id); + err = -EINVAL ; + goto out; + } - pdd =kfd_bind_process_to_device (dev, p); + pdd =kfd_bind_process_to_device (pdd->dev, p);if (IS_ERR (pdd)) { err = -ESRCH ; goto out;
@@ -525,7 +527,7 @@ static int kfd_ioctl_set_memory_policy(struct file *filep, (args->alternate_policy ==KFD_IOC_CACHE_POLICY_COHERENT ) ? cache_policy_coherent : cache_policy_noncoherent; - if (!dev->dqm->ops.set_cache_memory_policy(dev->dqm, + if (!pdd->dev->dqm->ops.set_cache_memory_policy(pdd->dev->dqm, &pdd->qpd, default_policy, alternate_policy,
@@ -543,17 +545,18 @@ static int kfd_ioctl_set_trap_handler(struct file *filep, struct kfd_process *p, void *data) { struct kfd_ioctl_set_trap_handler_args *args = data; -struct kfd_dev *dev;int err =0 ;struct kfd_process_device *pdd; - dev =kfd_device_by_id (args->gpu_id); -if (!dev) -return -EINVAL ; -mutex_lock (&p->mutex); - pdd =kfd_bind_process_to_device (dev, p); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { + err = -EINVAL ; + goto out; + } + + pdd =kfd_bind_process_to_device (pdd->dev, p);if (IS_ERR (pdd)) { err = -ESRCH ; goto out;
@@ -577,16 +580,20 @@ static int kfd_ioctl_dbg_register(struct file *filep,bool create_ok;long status =0 ; - dev =kfd_device_by_id (args->gpu_id); -if (!dev) -return -EINVAL ; +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { + status = -EINVAL ; + goto out_unlock_p; + } + dev = pdd->dev;if (dev->device_info->asic_family ==CHIP_CARRIZO ) {pr_debug ("kfd_ioctl_dbg_register not supported on CZ\n" ); -return -EINVAL ; + status = -EINVAL ; + goto out_unlock_p; } -mutex_lock (&p->mutex);mutex_lock (kfd_get_dbgmgr_mutex ());/*
@@ -596,7 +603,7 @@ static int kfd_ioctl_dbg_register(struct file *filep, pdd =kfd_bind_process_to_device (dev, p);if (IS_ERR (pdd)) { status =PTR_ERR (pdd); - goto out; + goto out_unlock_dbg; }if (!dev->dbgmgr) {
@@ -614,8 +621,9 @@ static int kfd_ioctl_dbg_register(struct file *filep, status = -EINVAL ; } -out: +out_unlock_dbg:mutex_unlock (kfd_get_dbgmgr_mutex ()); +out_unlock_p:mutex_unlock (&p->mutex);return status;
@@ -625,12 +633,18 @@ static int kfd_ioctl_dbg_unregister(struct file *filep, struct kfd_process *p, void *data) { struct kfd_ioctl_dbg_unregister_args *args = data; +struct kfd_process_device *pdd;struct kfd_dev *dev;long status; - dev =kfd_device_by_id (args->gpu_id); -if (!dev || !dev->dbgmgr) +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd || !pdd->dev->dbgmgr) { +mutex_unlock (&p->mutex);return -EINVAL ; + } + dev = pdd->dev; +mutex_unlock (&p->mutex);if (dev->device_info->asic_family ==CHIP_CARRIZO ) {pr_debug ("kfd_ioctl_dbg_unregister not supported on CZ\n" );
@@ -664,6 +678,7 @@ static int kfd_ioctl_dbg_address_watch(struct file *filep, {struct kfd_ioctl_dbg_address_watch_args *args = data;struct kfd_dev *dev; +struct kfd_process_device *pdd;struct dbg_address_watch_info aw_info;unsigned char *args_buff;long status;
@@ -673,9 +688,15 @@ static int kfd_ioctl_dbg_address_watch(struct file *filep,memset ((void *) &aw_info,0 ,sizeof (struct dbg_address_watch_info )); - dev =kfd_device_by_id (args->gpu_id); -if (!dev) +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { +mutex_unlock (&p->mutex); +pr_debug ("Could not find gpu id 0x%x\n" , args->gpu_id);return -EINVAL ; + } + dev = pdd->dev; +mutex_unlock (&p->mutex);if (dev->device_info->asic_family ==CHIP_CARRIZO ) {pr_debug ("kfd_ioctl_dbg_wave_control not supported on CZ\n" );
@@ -764,6 +785,7 @@ static int kfd_ioctl_dbg_wave_control(struct file *filep, {struct kfd_ioctl_dbg_wave_control_args *args = data;struct kfd_dev *dev; +struct kfd_process_device *pdd;struct dbg_wave_control_info wac_info;unsigned char *args_buff;uint32_t computed_buff_size;
@@ -781,9 +803,15 @@ static int kfd_ioctl_dbg_wave_control(struct file *filep,sizeof (wac_info.dbgWave_msg.MemoryVA) +sizeof (wac_info.trapId); - dev =kfd_device_by_id (args->gpu_id); -if (!dev) +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { +mutex_unlock (&p->mutex); +pr_debug ("Could not find gpu id 0x%x\n" , args->gpu_id);return -EINVAL ; + } + dev = pdd->dev; +mutex_unlock (&p->mutex);if (dev->device_info->asic_family ==CHIP_CARRIZO ) {pr_debug ("kfd_ioctl_dbg_wave_control not supported on CZ\n" );
@@ -847,16 +875,19 @@ static int kfd_ioctl_get_clock_counters(struct file *filep, struct kfd_process *p, void *data) { struct kfd_ioctl_get_clock_counters_args *args = data; -struct kfd_dev *dev; +struct kfd_process_device *pdd; - dev =kfd_device_by_id (args->gpu_id); -if (dev) +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (pdd)/* Reading GPU clock counter from KGD */ - args->gpu_clock_counter =amdgpu_amdkfd_get_gpu_clock_counter (dev->kgd); + args->gpu_clock_counter =amdgpu_amdkfd_get_gpu_clock_counter (pdd->dev->kgd);else /* Node without GPU resource */ args->gpu_clock_counter =0 ; +mutex_unlock (&p->mutex); +/* No access to rdtsc. Using raw monotonic time */ args->cpu_clock_counter =ktime_get_raw_ns (); args->system_clock_counter =ktime_get_boottime_ns ();
@@ -1010,15 +1041,15 @@ static int kmap_event_page(struct kfd_process *p, uint64_t event_page_offset)return -EINVAL ; } - kfd =kfd_device_by_id (GET_GPU_ID (event_page_offset)); -if (!kfd) { + pdd =kfd_process_device_data_by_id (p,GET_GPU_ID (event_page_offset)); +if (!pdd) {pr_err ("Getting device by id failed in %s\n" , __func__);return -EINVAL ; } + kfd = pdd->dev; pdd =kfd_bind_process_to_device (kfd, p);if (IS_ERR (pdd)) { -mutex_unlock (&p->mutex);return PTR_ERR (pdd); }
@@ -1026,8 +1057,6 @@ static int kmap_event_page(struct kfd_process *p, uint64_t event_page_offset) GET_IDR_HANDLE(event_page_offset));if (!mem) {pr_err ("Can't find BO, offset is 0x%llx\n" , event_page_offset); - -mutex_unlock (&p->mutex);return -EINVAL ; }
@@ -1119,11 +1148,13 @@ static int kfd_ioctl_set_scratch_backing_va(struct file *filep,struct kfd_dev *dev;long err; - dev =kfd_device_by_id (args->gpu_id); -if (!dev) -return -EINVAL ; -mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { + err = -EINVAL ; + goto bind_process_to_device_fail; + } + dev = pdd->dev; pdd =kfd_bind_process_to_device (dev, p);if (IS_ERR (pdd)) {
@@ -1151,15 +1182,20 @@ static int kfd_ioctl_get_tile_config(struct file *filep, struct kfd_process *p, void *data) { struct kfd_ioctl_get_tile_config_args *args = data; -struct kfd_dev *dev; +struct kfd_process_device *pdd;struct tile_config config;int err =0 ; - dev =kfd_device_by_id (args->gpu_id); -if (!dev) +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { +mutex_unlock (&p->mutex);return -EINVAL ; + } + +amdgpu_amdkfd_get_tile_config (pdd->dev->kgd, &config); -amdgpu_amdkfd_get_tile_config (dev->kgd, &config); +mutex_unlock (&p->mutex); args->gb_addr_config = config.gb_addr_config; args->num_banks = config.num_banks;
@@ -1194,21 +1230,15 @@ static int kfd_ioctl_acquire_vm(struct file *filep, struct kfd_process *p, {struct kfd_ioctl_acquire_vm_args *args = data;struct kfd_process_device *pdd; -struct kfd_dev *dev;struct file *drm_file;int ret; - dev =kfd_device_by_id (args->gpu_id); -if (!dev) -return -EINVAL ; - drm_file =fget (args->drm_fd);if (!drm_file)return -EINVAL ;mutex_lock (&p->mutex); - - pdd =kfd_get_process_device_data (dev, p); + pdd =kfd_process_device_data_by_id (p, args->gpu_id);if (!pdd) { ret = -EINVAL ; goto err_unlock;
@@ -1267,19 +1297,23 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,if (args->size ==0 )return -EINVAL ; - dev =kfd_device_by_id (args->gpu_id); -if (!dev) -return -EINVAL ; +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { + err = -EINVAL ; + goto err_unlock; + } + + dev = pdd->dev;if ((flags &KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC ) && (flags &KFD_IOC_ALLOC_MEM_FLAGS_VRAM ) && !kfd_dev_is_large_bar (dev)) {pr_err ("Alloc host visible vram on small bar is not allowed\n" ); -return -EINVAL ; + err = -EINVAL ; + goto err_unlock; } -mutex_lock (&p->mutex); - pdd =kfd_bind_process_to_device (dev, p);if (IS_ERR (pdd)) { err =PTR_ERR (pdd);
@@ -1350,17 +1384,12 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,struct kfd_ioctl_free_memory_of_gpu_args *args = data;struct kfd_process_device *pdd;void *mem; -struct kfd_dev *dev;int ret;uint64_t size =0 ; - dev =kfd_device_by_id (GET_GPU_ID (args->handle)); -if (!dev) -return -EINVAL ; -mutex_lock (&p->mutex); - pdd =kfd_get_process_device_data (dev, p); + pdd =kfd_process_device_data_by_id (p,GET_GPU_ID (args->handle));if (!pdd) {pr_err ("Process device data doesn't exist\n" ); ret = -EINVAL ;
@@ -1374,7 +1403,7 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep, goto err_unlock; } - ret =amdgpu_amdkfd_gpuvm_free_memory_of_gpu (dev->kgd, + ret =amdgpu_amdkfd_gpuvm_free_memory_of_gpu (pdd->dev->kgd, (struct kgd_mem *)mem, pdd->drm_priv, &size);/* If freeing the buffer failed, leave the handle in place for
@@ -1397,15 +1426,11 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,struct kfd_ioctl_map_memory_to_gpu_args *args = data;struct kfd_process_device *pdd, *peer_pdd;void *mem; -struct kfd_dev *dev, *peer; +struct kfd_dev *dev;long err =0 ;int i;uint32_t *devices_arr =NULL ; - dev =kfd_device_by_id (GET_GPU_ID (args->handle)); -if (!dev) -return -EINVAL ; -if (!args->n_devices) {pr_debug ("Device IDs array empty\n" );return -EINVAL ;
@@ -1429,6 +1454,12 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep, }mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p,GET_GPU_ID (args->handle)); +if (!pdd) { + err = -EINVAL ; + goto get_process_device_data_failed; + } + dev = pdd->dev; pdd =kfd_bind_process_to_device (dev, p);if (IS_ERR (pdd)) {
@@ -1444,21 +1475,21 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep, }for (i = args->n_success; i < args->n_devices; i++) { - peer =kfd_device_by_id (devices_arr[i]); -if (!peer) { + peer_pdd =kfd_process_device_data_by_id (p, devices_arr[i]); +if (!peer_pdd) {pr_debug ("Getting device by id failed for 0x%x\n" , devices_arr[i]); err = -EINVAL ; goto get_mem_obj_from_handle_failed; } - peer_pdd =kfd_bind_process_to_device (peer, p); + peer_pdd =kfd_bind_process_to_device (peer_pdd->dev, p);if (IS_ERR (peer_pdd)) { err =PTR_ERR (peer_pdd); goto get_mem_obj_from_handle_failed; } err =amdgpu_amdkfd_gpuvm_map_memory_to_gpu ( - peer->kgd, (struct kgd_mem *)mem, peer_pdd->drm_priv); + peer_pdd->dev->kgd, (struct kgd_mem *)mem, peer_pdd->drm_priv);if (err) {pr_err ("Failed to map to gpu %d/%d\n" , i, args->n_devices);
@@ -1477,12 +1508,10 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,/* Flush TLBs after waiting for the page table updates to complete */ for (i =0 ; i < args->n_devices; i++) { - peer =kfd_device_by_id (devices_arr[i]); -if (WARN_ON_ONCE (!peer)) -continue ; - peer_pdd =kfd_get_process_device_data (peer, p); + peer_pdd =kfd_process_device_data_by_id (p, devices_arr[i]);if (WARN_ON_ONCE (!peer_pdd))continue ; +kfd_flush_tlb (peer_pdd); }
@@ -1490,6 +1519,7 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,return err; +get_process_device_data_failed: bind_process_to_device_failed: get_mem_obj_from_handle_failed: map_memory_to_gpu_failed:
@@ -1507,14 +1537,9 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep,struct kfd_ioctl_unmap_memory_from_gpu_args *args = data;struct kfd_process_device *pdd, *peer_pdd;void *mem; -struct kfd_dev *dev, *peer;long err =0 ;uint32_t *devices_arr =NULL , i; - dev =kfd_device_by_id (GET_GPU_ID (args->handle)); -if (!dev) -return -EINVAL ; -if (!args->n_devices) {pr_debug ("Device IDs array empty\n" );return -EINVAL ;
@@ -1538,8 +1563,7 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep, }mutex_lock (&p->mutex); - - pdd =kfd_get_process_device_data (dev, p); + pdd =kfd_process_device_data_by_id (p,GET_GPU_ID (args->handle));if (!pdd) { err = -EINVAL ; goto bind_process_to_device_failed;
@@ -1553,19 +1577,13 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep, }for (i = args->n_success; i < args->n_devices; i++) { - peer =kfd_device_by_id (devices_arr[i]); -if (!peer) { - err = -EINVAL ; - goto get_mem_obj_from_handle_failed; - } - - peer_pdd =kfd_get_process_device_data (peer, p); + peer_pdd =kfd_process_device_data_by_id (p, devices_arr[i]);if (!peer_pdd) { - err = -ENODEV ; + err = -EINVAL ; goto get_mem_obj_from_handle_failed; } err =amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu ( - peer->kgd, (struct kgd_mem *)mem, peer_pdd->drm_priv); + peer_pdd->dev->kgd, (struct kgd_mem *)mem, peer_pdd->drm_priv);if (err) {pr_err ("Failed to unmap from gpu %d/%d\n" , i, args->n_devices);
@@ -1694,23 +1712,26 @@ static int kfd_ioctl_import_dmabuf(struct file *filep,void *mem;int r; - dev =kfd_device_by_id (args->gpu_id); -if (!dev) -return -EINVAL ; +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +if (!pdd) { + r = -EINVAL ; + goto err_unlock; + } dmabuf =dma_buf_get (args->dmabuf_fd); -if (IS_ERR (dmabuf)) -return PTR_ERR (dmabuf); - -mutex_lock (&p->mutex); +if (IS_ERR (dmabuf)) { + r =PTR_ERR (dmabuf); + goto err_unlock; + } - pdd =kfd_bind_process_to_device (dev, p); + pdd =kfd_bind_process_to_device (pdd->dev, p);if (IS_ERR (pdd)) { r =PTR_ERR (pdd); goto err_unlock; } - r =amdgpu_amdkfd_gpuvm_import_dmabuf (dev->kgd, dmabuf, + r =amdgpu_amdkfd_gpuvm_import_dmabuf (pdd->dev->kgd, dmabuf, args->va_addr, pdd->drm_priv, (struct kgd_mem **)&mem, &size,NULL );
@@ -1744,13 +1765,19 @@ static int kfd_ioctl_smi_events(struct file *filep, struct kfd_process *p, void *data) { struct kfd_ioctl_smi_events_args *args = data; -struct kfd_dev *dev; +struct kfd_process_device *pdd; - dev =kfd_device_by_id (args->gpuid); -if (!dev) +mutex_lock (&p->mutex); + + pdd =kfd_process_device_data_by_id (p, args->gpuid); +if (!pdd) { +mutex_unlock (&p->mutex);return -EINVAL ; + } + +mutex_unlock (&p->mutex); -return kfd_smi_event_open (dev, &args->anon_fd); +return kfd_smi_event_open (pdd->dev, &args->anon_fd); } static int kfd_ioctl_set_xnack_mode(struct file *filep,
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -0
@@ -930,6 +930,9 @@ int kfd_process_restore_queues(struct kfd_process *p);void kfd_suspend_all_processes (void );int kfd_resume_all_processes (void ); +struct kfd_process_device *kfd_process_device_data_by_id (struct kfd_process *process, +uint32_t gpu_id); +int kfd_process_device_init_vm (struct kfd_process_device *pdd,struct file *drm_file); struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,
drivers/gpu/drm/amd/amdkfd/kfd_process.c +18 -0
@@ -1424,6 +1424,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev, pdd->runtime_inuse = false; pdd->vram_usage =0 ; pdd->sdma_past_activity_counter =0 ; + pdd->user_gpu_id = dev->id;atomic64_set (&pdd->evict_duration_counter,0 ); p->pdds[p->n_pdds++] = pdd;
@@ -1897,6 +1898,23 @@ void kfd_flush_tlb(struct kfd_process_device *pdd) } } +struct kfd_process_device *kfd_process_device_data_by_id (struct kfd_process *p,uint32_t gpu_id) +{ +int i; + +if (gpu_id) { +for (i =0 ; i < p->n_pdds; i++) { +struct kfd_process_device *pdd = p->pdds[i]; + +if (pdd->user_gpu_id == gpu_id) +return pdd; + } + +WARN_ONCE (1 ,"Failed to find mapping for gpu = 0x%x\n" , gpu_id); + } +return NULL ; +} +#if defined(CONFIG_DEBUG_FS )int kfd_debugfs_mqds_by_process (struct seq_file *m,void *data)
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
maintainerRFC PATCH 17/17 Revert "drm/amdgpu: Remove verify_access shortcut for KFD BOs"
In reply to Felix KuehlingFrom: Rajneesh Bhardwaj <[email protected]>
This reverts commit 12ebe2b9df192a2a8580cd9ee3e9940c116913c8.
This is just a temporary work around and will be dropped later.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7 -0
@@ -178,6 +178,13 @@ static int amdgpu_verify_access(struct ttm_buffer_object *bo, struct file *filp) {struct amdgpu_bo *abo =ttm_to_amdgpu_bo (bo); +/* +* Don't verify access for KFD BOs. They don't have a GEM +* object associated with them. +*/ +if (abo->kfd_bo) +return 0 ; +if (amdgpu_ttm_tt_get_usermm (bo->ttm))return -EPERM ; return drm_vma_node_verify_access(&abo->tbo.base.vma_node,
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx