Recently introduced change to allocate doorbells only when the first queue is created or mapped for CPU / GPU access, did not consider Checkpoint Restore scenario completely. This fix allows the CRIU restore operation by extedning the doorbell optimization to CRIU restore scenario. Fixes: 'commit 15bcfbc55b57 ("drm/amdkfd: Allocate doorbells only when needed")' Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@xxxxxxx> --- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 ++++++++ drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c | 4 +++- drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c index 84da1a9ce37c..c476993e3927 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -2153,6 +2153,13 @@ static int criu_restore_devices(struct kfd_process *p, ret = PTR_ERR(pdd); goto exit; } + + if (!pdd->doorbell_index && + kfd_alloc_process_doorbells(pdd->dev, &pdd->doorbell_index) < 0) { + pr_err("Failed to allocate process doorbells\n"); + ret = -ENOMEM; + goto err_alloc_doorbells; + } } /* @@ -2161,6 +2168,7 @@ static int criu_restore_devices(struct kfd_process *p, */ *priv_offset += args->num_devices * sizeof(*device_privs); +err_alloc_doorbells: exit: kfree(device_buckets); return ret; diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c b/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c index b33798f89ef0..7690514c4eb3 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c @@ -157,8 +157,10 @@ int kfd_doorbell_mmap(struct kfd_dev *dev, struct kfd_process *process, /* Calculate physical address of doorbell */ address = kfd_get_process_doorbells(pdd); - if (!address) + if (!address) { + pr_err("Failed to get physical address of process doorbell\n"); return -ENOMEM; + } vma->vm_flags |= VM_IO | VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE | VM_DONTDUMP | VM_PFNMAP; diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c index 6e3e7f54381b..9f05f64c5af8 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -857,6 +857,14 @@ int kfd_criu_restore_queue(struct kfd_process *p, ret = -EINVAL; goto exit; } + + if (!pdd->doorbell_index && + kfd_alloc_process_doorbells(pdd->dev, &pdd->doorbell_index) < 0) { + pr_err("Failed to alloc process doorbells\n"); + ret = -ENOMEM; + goto err_alloc_doorbells; + } + /* data stored in this order: mqd, ctl_stack */ mqd = q_extra_data; ctl_stack = mqd + q_data->mqd_size; @@ -876,6 +884,7 @@ int kfd_criu_restore_queue(struct kfd_process *p, if (q_data->gws) ret = pqm_set_gws(&p->pqm, q_data->q_id, pdd->dev->gws); +err_alloc_doorbells: exit: if (ret) pr_err("Failed to restore queue (%d)\n", ret); -- 2.17.1