From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380718; b=fjj40TqyAeiE4OTEfJ5eEJk3k3JOHp/in4IKqhzQfLkUIw5L39jktSihnxmImeS31eJP 11bwrYksH9bH6cRFWLHnNvYVIZUcxAARUgrP3S10ME4+99krUZSItzfE+hTrd/BvzDhE1 R4+obhJic3U9x2gUuvHsWeSEFujXZjUTmiHufTOqhAsMEa4yeEIvLP1CgqPQO4mAz0FlG T/WFLdkAsTI2vx9aWfQuTrzbBR51eLgHvJu8pgby732xlExd/2GQQ604Aukgl4pU8hNaX ZuecJL8W4HEe3D3S8IW9BTFJzXbNxwI5pX3WXvd/jYX4q3fG/tEHxtKym70WxNGZo1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380718; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=0Q/0yS6zjRvbP4KoG1OqTchXP4ZAJUCo/bqnmYswSJQ=; b=0snUltfE/eB9XdKMrCNzkfVdcR+dPQsWHoh5JagoKtDDIix7ciZ7uYEbeXZiO6P0nJFB Voo/a8zDHMasv3PIu4NpCGHYYOvaRfT11/tVFBcrXAjlkmQsKRDeEpb/Hm0zSLNCw4Jqf bHyzOmi3Ahn7yZPulYjxcsa+Ym7wW9k5RXxlP4XuoDYWD4kyaML5HeMNn66IDl8sQJl9L egi9Edwdl3ztI6pd/Fj0MeQT/ruKhzQX/Pq4iE2dxBC3nV8nIoJ7K3cJua5OvJMQPh/bW zL8C/loQniI9NMONBsURx3rIf57NsNBVMkWl/SX/41ZxStRFkVM7TY5VRPrMg61NYNg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=H+s+iTTv; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39FFB606A322; Fri, 4 Dec 2026 10:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=H+s+iTTv Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD2C51F000CE; Fri, 4 Dec 2026 10:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380718; bh=0Q/0yS6zjRvbP4KoG1OqTchXP4ZAJUCo/bqnmYswSJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=H+s+iTTvpFXw4vgUaVEJtOTUcStQ+Ad2DjxtcZAoKl3zzI9PXx6xGowTbCVGYRH7+ oVnd3XnN+y56cAkujc5eiQg6R75MDf25olqdTa/J8ryN1nl1CiVEqCU8pLKjODNjIp YQeab8RF8tSS+ZH41JKZUt4JYuGIk7pZCwVMJadY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Francis , Felix Kuehling , Alex Deucher Subject: [PATCH 7.3 392/742] drm/amdkfd: Acquire buffers in CRIU queue restore (again) Date: Fri, 4 Dec 2026 19:04:16 +0900 Message-ID: <20261204100645.503532225@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Francis commit 37820a7c716636b6ea499cc73875617886f4377f upstream. CRIU queue restore doesn't acquire the bo buffers in the same way normal queue creation does. In normal queue creation, the driver gets an additional reference on the queue's underlying buffers that lasts until the queue is destroyed; this prevents the queue's buffers from being removed from underneath it. Acquire them, but don't get the svm bo. SVM isn't yet fully restored by this point in CRIU and so there's no svm range to get. This will be addressed in the next patch. v2: Don't use checkpoint ctl_stack_size v5: Also avoid cwsr in criu failure path Signed-off-by: David Francis Reviewed-by: Felix Kuehling Signed-off-by: Alex Deucher (cherry picked from commit 56ca6fb5b148eb045aef34c4e05f1f56864611d5) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 4 ++-- drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 12 ++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 13 ++++++++++--- 4 files changed, 24 insertions(+), 9 deletions(-) --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct goto err_bind_process; } - err = kfd_queue_acquire_buffers(pdd, &q_properties); + err = kfd_queue_acquire_buffers(pdd, &q_properties, false); if (err) { pr_debug("failed to acquire user queue buffers\n"); goto err_acquire_queue_buf; @@ -478,7 +478,7 @@ static int kfd_ioctl_create_queue(struct err_create_queue: kfd_queue_unref_bo_vas(pdd, &q_properties); - kfd_queue_release_buffers(pdd, &q_properties); + kfd_queue_release_buffers(pdd, &q_properties, false); err_acquire_queue_buf: err_sdma_engine_id: err_bind_process: --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -1386,8 +1386,8 @@ void print_queue(struct queue *q); int kfd_queue_buffer_get(struct amdgpu_vm *vm, void __user *addr, struct amdgpu_bo **pbo, u64 expected_size); void kfd_queue_buffer_put(struct amdgpu_bo **bo); -int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties); -int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_properties *properties); +int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties, bool is_criu); +int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_properties *properties, bool is_criu); void kfd_queue_unref_bo_va(struct amdgpu_vm *vm, struct amdgpu_bo **bo); int kfd_queue_unref_bo_vas(struct kfd_process_device *pdd, struct queue_properties *properties); --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -227,7 +227,7 @@ void pqm_uninit(struct process_queue_man pqm->process); if (pdd) { kfd_queue_unref_bo_vas(pdd, &pqn->q->properties); - kfd_queue_release_buffers(pdd, &pqn->q->properties); + kfd_queue_release_buffers(pdd, &pqn->q->properties, false); } else { WARN_ON(!pdd); } @@ -571,7 +571,7 @@ int pqm_destroy_queue(struct process_que goto err_destroy_queue; } kfd_procfs_del_queue(pqn->q); - kfd_queue_release_buffers(pdd, &pqn->q->properties); + kfd_queue_release_buffers(pdd, &pqn->q->properties, false); pqm_clean_queue_resource(pqm, pqn); uninit_queue(pqn->q); } @@ -1093,9 +1093,17 @@ int kfd_criu_restore_queue(struct kfd_pr print_queue_properties(&qp); + ret = kfd_queue_acquire_buffers(pdd, &qp, true); + if (ret) { + pr_err("Failed to acquire user queue buffers err:%d\n", ret); + goto exit; + } + ret = pqm_create_queue(&p->pqm, pdd->dev, &qp, &queue_id, q_data, mqd, ctl_stack, NULL); if (ret) { pr_err("Failed to create new queue err:%d\n", ret); + kfd_queue_unref_bo_vas(pdd, &qp); + kfd_queue_release_buffers(pdd, &qp, true); goto exit; } --- a/drivers/gpu/drm/amd/amdkfd/kfd_queue.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_queue.c @@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct que kfd_queue_buffer_put(&properties->cwsr_bo); } -int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties) +int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_properties *properties, bool is_criu) { struct kfd_topology_device *topo_dev; u64 expected_queue_size; @@ -334,6 +334,12 @@ int kfd_queue_acquire_buffers(struct kfd amdgpu_bo_unreserve(vm->root.bo); + /* CRIU svm buffers are restored at a later stage than queues. They'll be in + * before the queue is actually used, so no risk here + */ + if (is_criu) + return 0; + err = kfd_queue_buffer_svm_get(pdd, properties->ctx_save_restore_area_address, total_cwsr_size); if (err) @@ -362,7 +368,7 @@ out_err_release: return err; } -int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_properties *properties) +int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_properties *properties, bool is_criu) { struct kfd_topology_device *topo_dev; u64 total_cwsr_size; @@ -380,7 +386,8 @@ int kfd_queue_release_buffers(struct kfd return -EINVAL; total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE); - kfd_queue_buffer_svm_put(pdd, properties->ctx_save_restore_area_address, total_cwsr_size); + if (!is_criu) + kfd_queue_buffer_svm_put(pdd, properties->ctx_save_restore_area_address, total_cwsr_size); return 0; }