Get references to queue buffers in CRIU restore
Subsystems (3)
CRIU has been blocked for a while because of a check for the queue buffers in the queue properties.
CRIU restore has not been acquiring references to the underlying buffers, leaving it vulnerable to having its resources freed underneath it.
Acquire them; non-svm ones during restore and svm ones during resume.
This exposes a spurious dmesg warning for not having the vm lock during svm unmap; also fix that.
I am aware the third patch also may require follow-up work to handle the eviction case. I hope these patches can be accepted without that work so CRIU may continue.
David Francis
PATCH v2 1/3 drm/amdkfd: Acquire buffers in CRIU queue restore (again)
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.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- .../amd/amdkfd/kfd_process_queue_manager.c | 34 +++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 8 ++++- 4 files changed, 41 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -1
@@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 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;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
@@ -1381,7 +1381,7 @@ 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_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);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,
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +32 -2
@@ -985,8 +985,14 @@ int kfd_criu_checkpoint_queues(struct kfd_process *p, }static void set_queue_properties_from_criu (struct queue_properties *qp, -struct kfd_criu_queue_priv_data *q_data) +struct kfd_criu_queue_priv_data *q_data, +struct kfd_process_device *pdd) { +struct kfd_topology_device *topo_dev; +uint32_t num_xcc =NUM_XCC (pdd->dev->xcc_mask); + + topo_dev =kfd_topology_device_by_id (pdd->dev->id); + qp->is_interop = false; qp->queue_percent = q_data->q_percent; qp->priority = q_data->priority;
@@ -998,6 +1004,16 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->eop_ring_buffer_size = q_data->eop_ring_buffer_size; qp->ctx_save_restore_area_address = q_data->ctx_save_restore_area_address; qp->ctx_save_restore_area_size = q_data->ctx_save_restore_area_size; + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size; + }else { + qp->ctl_stack_size = q_data->ctl_stack_size; + } + qp->type = q_data->type; qp->format = q_data->format; }
@@ -1047,7 +1063,13 @@ int kfd_criu_restore_queue(struct kfd_process *p, }memset (&qp,0 ,sizeof (qp)); -set_queue_properties_from_criu (&qp, q_data); +set_queue_properties_from_criu (&qp, q_data, pdd); + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE && !qp.ctl_stack_size) { +pr_err ("Failed to determine ctl_stack_size for compute queue\n" ); + ret = -EINVAL ; + goto exit; + }/* Per-XCC control stack size from topology, as create-queue requires */ if (qp.type ==KFD_QUEUE_TYPE_COMPUTE && pdd->dev->kfd->cwsr_enabled) {
@@ -1095,9 +1117,17 @@ int kfd_criu_restore_queue(struct kfd_process *p,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); goto exit; }
drivers/gpu/drm/amd/amdkfd/kfd_queue.c +7 -1
@@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct queue_properties *properties)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_process_device *pdd, struct queue_propeamdgpu_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)
Signature · 1 line
2.34.1
Felix Kuehling
maintainerRe: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 65 lines · David Francis
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.
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- .../amd/amdkfd/kfd_process_queue_manager.c | 34 +++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 8 ++++- 4 files changed, 41 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 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;drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-1@@ -1381,7 +1381,7 @@ 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_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);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,drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +7
-1@@ -985,8 +985,14 @@ int kfd_criu_checkpoint_queues(struct kfd_process *p, }static void set_queue_properties_from_criu (struct queue_properties *qp, -struct kfd_criu_queue_priv_data *q_data) +struct kfd_criu_queue_priv_data *q_data, +struct kfd_process_device *pdd) { +struct kfd_topology_device *topo_dev; +uint32_t num_xcc =NUM_XCC (pdd->dev->xcc_mask); + + topo_dev =kfd_topology_device_by_id (pdd->dev->id); + qp->is_interop = false; qp->queue_percent = q_data->q_percent; qp->priority = q_data->priority;
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0@@ -998,6 +1004,16 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->eop_ring_buffer_size = q_data->eop_ring_buffer_size; qp->ctx_save_restore_area_address = q_data->ctx_save_restore_area_address; qp->ctx_save_restore_area_size = q_data->ctx_save_restore_area_size; + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;
I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0 ctl_stack_size? And is that's the case, wouldn't that break restore anyway?
Other than that, this patch looks good to me.
Regards,
Felix
Quoted 66 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +19
-1+ }else { + qp->ctl_stack_size = q_data->ctl_stack_size; + } + qp->type = q_data->type; qp->format = q_data->format; }@@ -1047,7 +1063,13 @@ int kfd_criu_restore_queue(struct kfd_process *p, }memset (&qp,0 ,sizeof (qp)); -set_queue_properties_from_criu (&qp, q_data); +set_queue_properties_from_criu (&qp, q_data, pdd); + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE && !qp.ctl_stack_size) { +pr_err ("Failed to determine ctl_stack_size for compute queue\n" ); + ret = -EINVAL ; + goto exit; + }/* Per-XCC control stack size from topology, as create-queue requires */ if (qp.type ==KFD_QUEUE_TYPE_COMPUTE && pdd->dev->kfd->cwsr_enabled) {@@ -1095,9 +1117,17 @@ int kfd_criu_restore_queue(struct kfd_process *p,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); goto exit; }drivers/gpu/drm/amd/amdkfd/kfd_queue.c +7
-1@@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct queue_properties *properties)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_process_device *pdd, struct queue_propeamdgpu_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)
Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0+ +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?
A lot of mqd managers don't set mqd->get_checkpoint_info, so the ctl_stack_size ends up as 0.
kfd_queue_acquire_buffers requires the ctl_stack_size to be equal to topo_dev->node_props.ctl_stack_size anyways, so I think it makes sense to default to that value if the input is 0.
David Francis
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, October 30, 2026 5:15 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 65 lines · David Francis
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.
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- .../amd/amdkfd/kfd_process_queue_manager.c | 34 +++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 8 ++++- 4 files changed, 41 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 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;drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-1@@ -1381,7 +1381,7 @@ 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_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);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,drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +7
-1@@ -985,8 +985,14 @@ int kfd_criu_checkpoint_queues(struct kfd_process *p, }static void set_queue_properties_from_criu (struct queue_properties *qp, -struct kfd_criu_queue_priv_data *q_data) +struct kfd_criu_queue_priv_data *q_data, +struct kfd_process_device *pdd) { +struct kfd_topology_device *topo_dev; +uint32_t num_xcc =NUM_XCC (pdd->dev->xcc_mask); + + topo_dev =kfd_topology_device_by_id (pdd->dev->id); + qp->is_interop = false; qp->queue_percent = q_data->q_percent; qp->priority = q_data->priority;
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0@@ -998,6 +1004,16 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->eop_ring_buffer_size = q_data->eop_ring_buffer_size; qp->ctx_save_restore_area_address = q_data->ctx_save_restore_area_address; qp->ctx_save_restore_area_size = q_data->ctx_save_restore_area_size; + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;
I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0 ctl_stack_size? And is that's the case, wouldn't that break restore anyway?
Other than that, this patch looks good to me.
Regards,
Felix
Quoted 66 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +19
-1+ }else { + qp->ctl_stack_size = q_data->ctl_stack_size; + } + qp->type = q_data->type; qp->format = q_data->format; }@@ -1047,7 +1063,13 @@ int kfd_criu_restore_queue(struct kfd_process *p, }memset (&qp,0 ,sizeof (qp)); -set_queue_properties_from_criu (&qp, q_data); +set_queue_properties_from_criu (&qp, q_data, pdd); + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE && !qp.ctl_stack_size) { +pr_err ("Failed to determine ctl_stack_size for compute queue\n" ); + ret = -EINVAL ; + goto exit; + }/* Per-XCC control stack size from topology, as create-queue requires */ if (qp.type ==KFD_QUEUE_TYPE_COMPUTE && pdd->dev->kfd->cwsr_enabled) {@@ -1095,9 +1117,17 @@ int kfd_criu_restore_queue(struct kfd_process *p,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); goto exit; }drivers/gpu/drm/amd/amdkfd/kfd_queue.c +7
-1@@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct queue_properties *properties)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_process_device *pdd, struct queue_propeamdgpu_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)
Felix Kuehling
maintainerRe: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 10 lines · David
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0+ +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?
Quoted 6 lines
A lot of mqd managers don't set
mqd->get_checkpoint_info, so thectl_stack_sizeends up as 0.
kfd_queue_acquire_buffersrequires thectl_stack_sizeto be equal totopo_dev->node_props.ctl_stack_sizeanyways, so I think it makes sense to default to that value if the input is 0.
I guess get_checkpoint_info is not implemented for GPUs that don't allocate the control stack in kernel mode. Either way, the control stack ends up being saved or copied into the user mode context save buffer, so the control stack contents are saved regardless of the size reported here.
With that in mind, I think your change kind of makes sense. I think the cleanest solution would be to just ignore the ctl_stack_size in the q_data and always get it from the topo_dev->node_props. You could even remove from the q_data completely. It's not needed. Just make sure you bump KFD_CRIU_PRIV_VERSION so that restoring an old checkpoint on a new driver would fail gracefully.
Then you could also remove all those per-GPU generation get_checkpoint_info functions.
Regards,
Felix
Quoted 161 lines
David Francis
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, October 30, 2026 5:15 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)Quoted 65 lines · David Francis
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.
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- .../amd/amdkfd/kfd_process_queue_manager.c | 34 +++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 8 ++++- 4 files changed, 41 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 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;drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-1@@ -1381,7 +1381,7 @@ 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_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);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,drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +7
-1@@ -985,8 +985,14 @@ int kfd_criu_checkpoint_queues(struct kfd_process *p, }static void set_queue_properties_from_criu (struct queue_properties *qp, -struct kfd_criu_queue_priv_data *q_data) +struct kfd_criu_queue_priv_data *q_data, +struct kfd_process_device *pdd) { +struct kfd_topology_device *topo_dev; +uint32_t num_xcc =NUM_XCC (pdd->dev->xcc_mask); + + topo_dev =kfd_topology_device_by_id (pdd->dev->id); + qp->is_interop = false; qp->queue_percent = q_data->q_percent; qp->priority = q_data->priority;drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0@@ -998,6 +1004,16 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->eop_ring_buffer_size = q_data->eop_ring_buffer_size; qp->ctx_save_restore_area_address = q_data->ctx_save_restore_area_address; qp->ctx_save_restore_area_size = q_data->ctx_save_restore_area_size; + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?Other than that, this patch looks good to me.
Regards,
FelixQuoted 66 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +19
-1+ }else { + qp->ctl_stack_size = q_data->ctl_stack_size; + } + qp->type = q_data->type; qp->format = q_data->format; }@@ -1047,7 +1063,13 @@ int kfd_criu_restore_queue(struct kfd_process *p, }memset (&qp,0 ,sizeof (qp)); -set_queue_properties_from_criu (&qp, q_data); +set_queue_properties_from_criu (&qp, q_data, pdd); + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE && !qp.ctl_stack_size) { +pr_err ("Failed to determine ctl_stack_size for compute queue\n" ); + ret = -EINVAL ; + goto exit; + }/* Per-XCC control stack size from topology, as create-queue requires */ if (qp.type ==KFD_QUEUE_TYPE_COMPUTE && pdd->dev->kfd->cwsr_enabled) {@@ -1095,9 +1117,17 @@ int kfd_criu_restore_queue(struct kfd_process *p,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); goto exit; }drivers/gpu/drm/amd/amdkfd/kfd_queue.c +7
-1@@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct queue_properties *properties)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_process_device *pdd, struct queue_propeamdgpu_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)
Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 23 lines
Quoted 10 lines
Quoted 4 lines
I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?A lot of mqd managers don't set
mqd->get_checkpoint_info, so thectl_stack_sizeends up as 0.
kfd_queue_acquire_buffersrequires thectl_stack_sizeto be equal totopo_dev->node_props.ctl_stack_sizeanyways, so I think it makes sense to default to that value if the input is 0.I guess
get_checkpoint_infois not implemented for GPUs that don't allocate the control stack in kernel mode. Either way, the control stack ends up being saved or copied into the user mode context save buffer, so the control stack contents are saved regardless of the size reported here.With that in mind, I think your change kind of makes sense. I think the cleanest solution would be to just ignore the
ctl_stack_sizein theq_dataand always get it from thetopo_dev->node_props. You could even remove from theq_datacompletely. It's not needed. Just make sure you bumpKFD_CRIU_PRIV_VERSIONso that restoring an old checkpoint on a new driver would fail gracefully.
Quoted 3 lines
Then you could also remove all those per-GPU generation
get_checkpoint_infofunctions.
I think that cleanup makes sense. Is there any concern about bumping the CRIU priv version and creating this incompatibility with old dump files when we don't have to? (We could for instance just leave that field as padding)
David Francis
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Monday, November 2, 2026 3:09 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 10 lines · David
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0+ +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?
Quoted 6 lines
A lot of mqd managers don't set
mqd->get_checkpoint_info, so thectl_stack_sizeends up as 0.
kfd_queue_acquire_buffersrequires thectl_stack_sizeto be equal totopo_dev->node_props.ctl_stack_sizeanyways, so I think it makes sense to default to that value if the input is 0.
I guess get_checkpoint_info is not implemented for GPUs that don't allocate the control stack in kernel mode. Either way, the control stack ends up being saved or copied into the user mode context save buffer, so the control stack contents are saved regardless of the size reported here.
With that in mind, I think your change kind of makes sense. I think the cleanest solution would be to just ignore the ctl_stack_size in the q_data and always get it from the topo_dev->node_props. You could even remove from the q_data completely. It's not needed. Just make sure you bump KFD_CRIU_PRIV_VERSION so that restoring an old checkpoint on a new driver would fail gracefully.
Then you could also remove all those per-GPU generation get_checkpoint_info functions.
Regards,
Felix
Quoted 161 lines
David Francis
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, October 30, 2026 5:15 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)Quoted 65 lines · David Francis
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.
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- .../amd/amdkfd/kfd_process_queue_manager.c | 34 +++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 8 ++++- 4 files changed, 41 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 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;drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-1@@ -1381,7 +1381,7 @@ 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_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);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,drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +7
-1@@ -985,8 +985,14 @@ int kfd_criu_checkpoint_queues(struct kfd_process *p, }static void set_queue_properties_from_criu (struct queue_properties *qp, -struct kfd_criu_queue_priv_data *q_data) +struct kfd_criu_queue_priv_data *q_data, +struct kfd_process_device *pdd) { +struct kfd_topology_device *topo_dev; +uint32_t num_xcc =NUM_XCC (pdd->dev->xcc_mask); + + topo_dev =kfd_topology_device_by_id (pdd->dev->id); + qp->is_interop = false; qp->queue_percent = q_data->q_percent; qp->priority = q_data->priority;drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0@@ -998,6 +1004,16 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->eop_ring_buffer_size = q_data->eop_ring_buffer_size; qp->ctx_save_restore_area_address = q_data->ctx_save_restore_area_address; qp->ctx_save_restore_area_size = q_data->ctx_save_restore_area_size; + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?Other than that, this patch looks good to me.
Regards,
FelixQuoted 66 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +19
-1+ }else { + qp->ctl_stack_size = q_data->ctl_stack_size; + } + qp->type = q_data->type; qp->format = q_data->format; }@@ -1047,7 +1063,13 @@ int kfd_criu_restore_queue(struct kfd_process *p, }memset (&qp,0 ,sizeof (qp)); -set_queue_properties_from_criu (&qp, q_data); +set_queue_properties_from_criu (&qp, q_data, pdd); + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE && !qp.ctl_stack_size) { +pr_err ("Failed to determine ctl_stack_size for compute queue\n" ); + ret = -EINVAL ; + goto exit; + }/* Per-XCC control stack size from topology, as create-queue requires */ if (qp.type ==KFD_QUEUE_TYPE_COMPUTE && pdd->dev->kfd->cwsr_enabled) {@@ -1095,9 +1117,17 @@ int kfd_criu_restore_queue(struct kfd_process *p,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); goto exit; }drivers/gpu/drm/amd/amdkfd/kfd_queue.c +7
-1@@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct queue_properties *properties)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_process_device *pdd, struct queue_propeamdgpu_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)
Felix Kuehling
maintainerRe: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 22 lines · David
Quoted 22 lines
Quoted 10 lines
Quoted 4 lines
I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?A lot of mqd managers don't set
mqd->get_checkpoint_info, so thectl_stack_sizeends up as 0.
kfd_queue_acquire_buffersrequires thectl_stack_sizeto be equal totopo_dev->node_props.ctl_stack_sizeanyways, so I think it makes sense to default to that value if the input is 0.I guess
get_checkpoint_infois not implemented for GPUs that don't allocate the control stack in kernel mode. Either way, the control stack ends up being saved or copied into the user mode context save buffer, so the control stack contents are saved regardless of the size reported here.With that in mind, I think your change kind of makes sense. I think the cleanest solution would be to just ignore the
ctl_stack_sizein theq_dataand always get it from thetopo_dev->node_props. You could even remove from theq_datacompletely. It's not needed. Just make sure you bumpKFD_CRIU_PRIV_VERSIONso that restoring an old checkpoint on a new driver would fail gracefully.
Quoted 7 lines
Quoted 3 lines
Then you could also remove all those per-GPU generation
get_checkpoint_infofunctions.I think that cleanup makes sense. Is there any concern about bumping the CRIU priv version and creating this incompatibility with old dump files when we don't have to? (We could for instance just leave that field as padding)
Yeah, I wouldn't consider this an ABI breakage since the private checkpoint data is opaque to user mode. I think preserving checkpoint viability across driver versions is not a requirement. The version check is there to protect against an unlikely scenario. That said, we could leave it as padding to avoid the version bump. But that kind of clutter can accumulate over time. We'd want to remember to clean it up when we need to bump the version for some other reason in the future.
Regards,
Felix
Quoted 206 lines
David Francis
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Monday, November 2, 2026 3:09 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)Quoted 10 lines · David
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0+ +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?Quoted 6 lines
A lot of mqd managers don't set
mqd->get_checkpoint_info, so thectl_stack_sizeends up as 0.
kfd_queue_acquire_buffersrequires thectl_stack_sizeto be equal totopo_dev->node_props.ctl_stack_sizeanyways, so I think it makes sense to default to that value if the input is 0.I guess
get_checkpoint_infois not implemented for GPUs that don't allocate the control stack in kernel mode. Either way, the control stack ends up being saved or copied into the user mode context save buffer, so the control stack contents are saved regardless of the size reported here.With that in mind, I think your change kind of makes sense. I think the cleanest solution would be to just ignore the
ctl_stack_sizein theq_dataand always get it from thetopo_dev->node_props. You could even remove from theq_datacompletely. It's not needed. Just make sure you bumpKFD_CRIU_PRIV_VERSIONso that restoring an old checkpoint on a new driver would fail gracefully.Then you could also remove all those per-GPU generation
get_checkpoint_infofunctions.Regards,
FelixQuoted 160 lines
David Francis
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, October 30, 2026 5:15 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)Quoted 65 lines · David Francis
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.
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- .../amd/amdkfd/kfd_process_queue_manager.c | 34 +++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 8 ++++- 4 files changed, 41 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 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;drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-1@@ -1381,7 +1381,7 @@ 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_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);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,drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +7
-1@@ -985,8 +985,14 @@ int kfd_criu_checkpoint_queues(struct kfd_process *p, }static void set_queue_properties_from_criu (struct queue_properties *qp, -struct kfd_criu_queue_priv_data *q_data) +struct kfd_criu_queue_priv_data *q_data, +struct kfd_process_device *pdd) { +struct kfd_topology_device *topo_dev; +uint32_t num_xcc =NUM_XCC (pdd->dev->xcc_mask); + + topo_dev =kfd_topology_device_by_id (pdd->dev->id); + qp->is_interop = false; qp->queue_percent = q_data->q_percent; qp->priority = q_data->priority;drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0@@ -998,6 +1004,16 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->eop_ring_buffer_size = q_data->eop_ring_buffer_size; qp->ctx_save_restore_area_address = q_data->ctx_save_restore_area_address; qp->ctx_save_restore_area_size = q_data->ctx_save_restore_area_size; + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?Other than that, this patch looks good to me.
Regards,
FelixQuoted 66 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +19
-1+ }else { + qp->ctl_stack_size = q_data->ctl_stack_size; + } + qp->type = q_data->type; qp->format = q_data->format; }@@ -1047,7 +1063,13 @@ int kfd_criu_restore_queue(struct kfd_process *p, }memset (&qp,0 ,sizeof (qp)); -set_queue_properties_from_criu (&qp, q_data); +set_queue_properties_from_criu (&qp, q_data, pdd); + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE && !qp.ctl_stack_size) { +pr_err ("Failed to determine ctl_stack_size for compute queue\n" ); + ret = -EINVAL ; + goto exit; + }/* Per-XCC control stack size from topology, as create-queue requires */ if (qp.type ==KFD_QUEUE_TYPE_COMPUTE && pdd->dev->kfd->cwsr_enabled) {@@ -1095,9 +1117,17 @@ int kfd_criu_restore_queue(struct kfd_process *p,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); goto exit; }drivers/gpu/drm/amd/amdkfd/kfd_queue.c +7
-1@@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct queue_properties *properties)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_process_device *pdd, struct queue_propeamdgpu_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)
Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
With that in mind, I think your change kind of makes sense. I think the cleanest solution would be to just ignore the
ctl_stack_sizein theq_dataand always get it from thetopo_dev->node_props. You could even remove from theq_datacompletely. It's not needed. Just make sure you bumpKFD_CRIU_PRIV_VERSIONso that restoring an old checkpoint on a new driver would fail gracefully.Quoted 7 lines
Quoted 3 lines
Then you could also remove all those per-GPU generation
get_checkpoint_infofunctions.I think that cleanup makes sense. Is there any concern about bumping the CRIU priv version and creating this incompatibility with old dump files when we don't have to? (We could for instance just leave that field as padding)
Quoted 8 lines
Yeah, I wouldn't consider this an ABI breakage since the private checkpoint data is opaque to user mode. I think preserving checkpoint viability across driver versions is not a requirement. The version check is there to protect against an unlikely scenario. That said, we could leave it as padding to avoid the version bump. But that kind of clutter can accumulate over time. We'd want to remember to clean it up when we need to bump the version for some other reason in the future.
I was thrown off by a difference between staging and unified branches; we are currently already setting qp->ctl_stack_size to always be the topo dev value, and using the priv data ctl_stack_size to represent something different
/* Per-XCC control stack size from topology, as create-queue requires */
if (qp.type == KFD_QUEUE_TYPE_COMPUTE && pdd->dev->kfd->cwsr_enabled) {
topo_dev = kfd_topology_device_by_id(pdd->dev->id);
if (!topo_dev) {
ret = -EINVAL;
goto exit;
}
qp.ctl_stack_size = topo_dev->node_props.ctl_stack_size;
}
if (q_data->ctl_stack_size > (u64)qp.ctl_stack_size * NUM_XCC(pdd->dev->xcc_mask)) {
ret = -EINVAL;
goto exit;
}
*priv_data_offset += sizeof(*q_data);
q_extra_data_size = (uint64_t)q_data->ctl_stack_size + q_data->mqd_size;Given that, it's probably best not to change set_queue_properties_from_criu at all in this patch
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Monday, November 2, 2026 3:31 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)
Quoted 22 lines · David
Quoted 22 lines
Quoted 10 lines
Quoted 4 lines
I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?A lot of mqd managers don't set
mqd->get_checkpoint_info, so thectl_stack_sizeends up as 0.
kfd_queue_acquire_buffersrequires thectl_stack_sizeto be equal totopo_dev->node_props.ctl_stack_sizeanyways, so I think it makes sense to default to that value if the input is 0.I guess
get_checkpoint_infois not implemented for GPUs that don't allocate the control stack in kernel mode. Either way, the control stack ends up being saved or copied into the user mode context save buffer, so the control stack contents are saved regardless of the size reported here.With that in mind, I think your change kind of makes sense. I think the cleanest solution would be to just ignore the
ctl_stack_sizein theq_dataand always get it from thetopo_dev->node_props. You could even remove from theq_datacompletely. It's not needed. Just make sure you bumpKFD_CRIU_PRIV_VERSIONso that restoring an old checkpoint on a new driver would fail gracefully.
Quoted 7 lines
Quoted 3 lines
Then you could also remove all those per-GPU generation
get_checkpoint_infofunctions.I think that cleanup makes sense. Is there any concern about bumping the CRIU priv version and creating this incompatibility with old dump files when we don't have to? (We could for instance just leave that field as padding)
Yeah, I wouldn't consider this an ABI breakage since the private checkpoint data is opaque to user mode. I think preserving checkpoint viability across driver versions is not a requirement. The version check is there to protect against an unlikely scenario. That said, we could leave it as padding to avoid the version bump. But that kind of clutter can accumulate over time. We'd want to remember to clean it up when we need to bump the version for some other reason in the future.
Regards,
Felix
Quoted 206 lines
David Francis
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Monday, November 2, 2026 3:09 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)Quoted 10 lines · David
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0+ +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?Quoted 6 lines
A lot of mqd managers don't set
mqd->get_checkpoint_info, so thectl_stack_sizeends up as 0.
kfd_queue_acquire_buffersrequires thectl_stack_sizeto be equal totopo_dev->node_props.ctl_stack_sizeanyways, so I think it makes sense to default to that value if the input is 0.I guess
get_checkpoint_infois not implemented for GPUs that don't allocate the control stack in kernel mode. Either way, the control stack ends up being saved or copied into the user mode context save buffer, so the control stack contents are saved regardless of the size reported here.With that in mind, I think your change kind of makes sense. I think the cleanest solution would be to just ignore the
ctl_stack_sizein theq_dataand always get it from thetopo_dev->node_props. You could even remove from theq_datacompletely. It's not needed. Just make sure you bumpKFD_CRIU_PRIV_VERSIONso that restoring an old checkpoint on a new driver would fail gracefully.Then you could also remove all those per-GPU generation
get_checkpoint_infofunctions.Regards,
FelixQuoted 160 lines
David Francis
________________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, October 30, 2026 5:15 PM
To: Francis, David; [email protected]
Cc: Koenig, Christian
Subject: Re: [PATCH v2 1/3] drm/amdkfd: Acquire buffers in CRIU queue restore (again)Quoted 65 lines · David Francis
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.
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- .../amd/amdkfd/kfd_process_queue_manager.c | 34 +++++++++++++++++-- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 8 ++++- 4 files changed, 41 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -433,7 +433,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, 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;drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-1@@ -1381,7 +1381,7 @@ 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_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);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,drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +7
-1@@ -985,8 +985,14 @@ int kfd_criu_checkpoint_queues(struct kfd_process *p, }static void set_queue_properties_from_criu (struct queue_properties *qp, -struct kfd_criu_queue_priv_data *q_data) +struct kfd_criu_queue_priv_data *q_data, +struct kfd_process_device *pdd) { +struct kfd_topology_device *topo_dev; +uint32_t num_xcc =NUM_XCC (pdd->dev->xcc_mask); + + topo_dev =kfd_topology_device_by_id (pdd->dev->id); + qp->is_interop = false; qp->queue_percent = q_data->q_percent; qp->priority = q_data->priority;drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c static void set_queue_properties_from_criu(struct queue_properties *qp, · line 1012
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6
-0@@ -998,6 +1004,16 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->eop_ring_buffer_size = q_data->eop_ring_buffer_size; qp->ctx_save_restore_area_address = q_data->ctx_save_restore_area_address; qp->ctx_save_restore_area_size = q_data->ctx_save_restore_area_size; + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE ) { +if (q_data->ctl_stack_size) + qp->ctl_stack_size = q_data->ctl_stack_size / num_xcc; +else if (topo_dev) + qp->ctl_stack_size = topo_dev->node_props.ctl_stack_size;I'm curious what this case is needed for. In what circumstances would a CRIU checkpoint contain 0
ctl_stack_size? And is that's the case, wouldn't that break restore anyway?Other than that, this patch looks good to me.
Regards,
FelixQuoted 66 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +19
-1+ }else { + qp->ctl_stack_size = q_data->ctl_stack_size; + } + qp->type = q_data->type; qp->format = q_data->format; }@@ -1047,7 +1063,13 @@ int kfd_criu_restore_queue(struct kfd_process *p, }memset (&qp,0 ,sizeof (qp)); -set_queue_properties_from_criu (&qp, q_data); +set_queue_properties_from_criu (&qp, q_data, pdd); + +if (q_data->type ==KFD_QUEUE_TYPE_COMPUTE && !qp.ctl_stack_size) { +pr_err ("Failed to determine ctl_stack_size for compute queue\n" ); + ret = -EINVAL ; + goto exit; + }/* Per-XCC control stack size from topology, as create-queue requires */ if (qp.type ==KFD_QUEUE_TYPE_COMPUTE && pdd->dev->kfd->cwsr_enabled) {@@ -1095,9 +1117,17 @@ int kfd_criu_restore_queue(struct kfd_process *p,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); goto exit; }drivers/gpu/drm/amd/amdkfd/kfd_queue.c +7
-1@@ -239,7 +239,7 @@ static void kfd_queue_put_bos(struct queue_properties *properties)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_process_device *pdd, struct queue_propeamdgpu_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)
PATCH v2 2/3 drm/amdkfd: Get reference to svm queue buffers during CRIU resume
In reply to David FrancisWhen a user queue is created through kfd, the driver normally acquires a reference to each buffer backing the queue, to ensure those buffers can't be freed from under the queue.
During CRIU restore, we weren't acquiring those buffers. One of them (cwsr) is svm memory. During CRIU, svm memory is restored during RESUME phase, after queues are restored.
During CRIU queue restore, keep a record of the svm buffer's address and size, and then get a reference to it during RESUME phase.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 5 ++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 +++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 1 + .../amd/amdkfd/kfd_process_queue_manager.c | 38 +++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 4 +- 5 files changed, 51 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4 -1
@@ -2833,7 +2833,7 @@ static int criu_resume(struct file *filep, {struct kfd_process *target =NULL ;struct pid *pid =NULL ; -int ret =0 ; +int i, ret =0 ;pr_debug ("Inside %s, target pid for criu restore: %d\n" , __func__, args->pid);
@@ -2861,6 +2861,9 @@ static int criu_resume(struct file *filep, goto exit; } +for (i =0 ; i < target->n_pdds; i++) +kfd_criu_resume_pdd (target->pdds[i]); + ret =amdgpu_amdkfd_criu_resume (target->kgd_process_info);if (ret)pr_err ("amdgpu_amdkfd_criu_resume failed for %i\n" , args->pid);
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -0
@@ -895,6 +895,9 @@ struct kfd_process_device {u32 pasid;/* Indicates this process has requested PTL stay disabled */ bool ptl_disable_req; + +/* CRIU data preserved between restore and resume */ +struct list_head criu_pdd_metadata_list; };#define qpd_to_pdd (x) container_of(x, struct kfd_process_device, qpd)
@@ -1371,6 +1374,8 @@ int kfd_criu_restore_event(struct file *devkfd,uint8_t __user *user_priv_data, uint64_t *priv_data_offset, uint64_t max_priv_data_size); + +int kfd_criu_resume_pdd (struct kfd_process_device *pdd);/* CRIU - End */ /* Queue Context Management */
@@ -1387,6 +1392,7 @@ 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);void kfd_queue_ctx_save_restore_size (struct kfd_topology_device *dev); +int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size);struct mqd_manager *mqd_manager_init_cik (enum KFD_MQD_TYPE type,struct kfd_node *dev);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -1801,6 +1801,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, pdd->dev = dev;INIT_LIST_HEAD (&pdd->qpd.queues_list);INIT_LIST_HEAD (&pdd->qpd.priv_queue_list); +INIT_LIST_HEAD (&pdd->criu_pdd_metadata_list);mutex_init (&pdd->doorbell_mutex); pdd->qpd.dqm = dev->dqm; pdd->qpd.pqm = &p->pqm;
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +38 -0
@@ -1018,6 +1018,12 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->format = q_data->format; } +struct criu_pdd_metadata { +struct list_head list; +uint64_t ctx_save_restore_area_address; +uint32_t ctx_save_restore_area_size; +}; + int kfd_criu_restore_queue(struct kfd_process *p, uint8_t __user *user_priv_ptr, uint64_t *priv_data_offset,
@@ -1026,6 +1032,7 @@ int kfd_criu_restore_queue(struct kfd_process *p,uint8_t *mqd, *ctl_stack, *q_extra_data =NULL ;struct kfd_criu_queue_priv_data *q_data;struct kfd_topology_device *topo_dev; +struct criu_pdd_metadata *resume_info;struct kfd_process_device *pdd;uint64_t q_extra_data_size;struct queue_properties qp;
@@ -1131,6 +1138,11 @@ int kfd_criu_restore_queue(struct kfd_process *p, goto exit; } + resume_info =kzalloc (sizeof (struct criu_pdd_metadata ),GFP_KERNEL ); + resume_info->ctx_save_restore_area_address = qp.ctx_save_restore_area_address; + resume_info->ctx_save_restore_area_size = qp.ctx_save_restore_area_size; +list_add_tail (&resume_info->list, &pdd->criu_pdd_metadata_list); +if (q_data->gws) ret =pqm_set_gws (&p->pqm, q_data->q_id, pdd->dev->gws);
@@ -1146,6 +1158,32 @@ int kfd_criu_restore_queue(struct kfd_process *p,return ret; } +int kfd_criu_resume_pdd (struct kfd_process_device *pdd) +{ +struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (pdd->dev->id); +struct criu_pdd_metadata *resume_info; +struct criu_pdd_metadata *next =NULL ; +u64 total_cwsr_size; +int ret =0 ; + +list_for_each_entry (resume_info, &pdd->criu_pdd_metadata_list, list) { + total_cwsr_size = resume_info->ctx_save_restore_area_size + + topo_dev->node_props.debug_memory_size; + total_cwsr_size =ALIGN (total_cwsr_size,PAGE_SIZE ); + + ret =kfd_queue_buffer_svm_get (pdd, resume_info->ctx_save_restore_area_address, total_cwsr_size); +if (ret) +break ; + } + +list_for_each_entry_safe (resume_info, next, &pdd->criu_pdd_metadata_list, list) { +list_del (&resume_info->list); +kfree (resume_info); + } + +return ret; +} + int pqm_get_queue_checkpoint_info(struct process_queue_manager *pqm, unsigned int qid, uint32_t *mqd_size,
drivers/gpu/drm/amd/amdkfd/kfd_queue.c +2 -2
@@ -88,7 +88,7 @@ void uninit_queue(struct queue *q)#if IS_ENABLED (CONFIG_HSA_AMD_SVM ) -static int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size) +int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size) {struct kfd_process *p = pdd->process;struct list_head update_list;
@@ -182,7 +182,7 @@ static void kfd_queue_buffer_svm_put(struct kfd_process_device *pdd, u64 addr, u }#else -static int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size) +int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size) {return -EINVAL ; }
Signature · 1 line
2.34.1
Felix Kuehling
maintainerRe: [PATCH v2 2/3] drm/amdkfd: Get reference to svm queue buffers during CRIU resume
Quoted 112 lines · David Francis
When a user queue is created through kfd, the driver normally acquires a reference to each buffer backing the queue, to ensure those buffers can't be freed from under the queue.
During CRIU restore, we weren't acquiring those buffers. One of them (cwsr) is svm memory. During CRIU, svm memory is restored during RESUME phase, after queues are restored.
During CRIU queue restore, keep a record of the svm buffer's address and size, and then get a reference to it during RESUME phase.
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 5 ++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 +++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 1 + .../amd/amdkfd/kfd_process_queue_manager.c | 38 +++++++++++++++++++ drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 4 +- 5 files changed, 51 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4
-1@@ -2833,7 +2833,7 @@ static int criu_resume(struct file *filep, {struct kfd_process *target =NULL ;struct pid *pid =NULL ; -int ret =0 ; +int i, ret =0 ;pr_debug ("Inside %s, target pid for criu restore: %d\n" , __func__, args->pid);@@ -2861,6 +2861,9 @@ static int criu_resume(struct file *filep, goto exit; } +for (i =0 ; i < target->n_pdds; i++) +kfd_criu_resume_pdd (target->pdds[i]); + ret =amdgpu_amdkfd_criu_resume (target->kgd_process_info);if (ret)pr_err ("amdgpu_amdkfd_criu_resume failed for %i\n" , args->pid);drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6
-0@@ -895,6 +895,9 @@ struct kfd_process_device {u32 pasid;/* Indicates this process has requested PTL stay disabled */ bool ptl_disable_req; + +/* CRIU data preserved between restore and resume */ +struct list_head criu_pdd_metadata_list; };#define qpd_to_pdd (x) container_of(x, struct kfd_process_device, qpd)@@ -1371,6 +1374,8 @@ int kfd_criu_restore_event(struct file *devkfd,uint8_t __user *user_priv_data, uint64_t *priv_data_offset, uint64_t max_priv_data_size); + +int kfd_criu_resume_pdd (struct kfd_process_device *pdd);/* CRIU - End */ /* Queue Context Management */ @@ -1387,6 +1392,7 @@ 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);void kfd_queue_ctx_save_restore_size (struct kfd_topology_device *dev); +int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size);struct mqd_manager *mqd_manager_init_cik (enum KFD_MQD_TYPE type,struct kfd_node *dev);drivers/gpu/drm/amd/amdkfd/kfd_process.c +1
-0@@ -1801,6 +1801,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, pdd->dev = dev;INIT_LIST_HEAD (&pdd->qpd.queues_list);INIT_LIST_HEAD (&pdd->qpd.priv_queue_list); +INIT_LIST_HEAD (&pdd->criu_pdd_metadata_list);mutex_init (&pdd->doorbell_mutex); pdd->qpd.dqm = dev->dqm; pdd->qpd.pqm = &p->pqm;drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +7
-0@@ -1018,6 +1018,12 @@ static void set_queue_properties_from_criu(struct queue_properties *qp, qp->format = q_data->format; } +struct criu_pdd_metadata { +struct list_head list; +uint64_t ctx_save_restore_area_address; +uint32_t ctx_save_restore_area_size; +}; + int kfd_criu_restore_queue(struct kfd_process *p, uint8_t __user *user_priv_ptr, uint64_t *priv_data_offset,@@ -1026,6 +1032,7 @@ int kfd_criu_restore_queue(struct kfd_process *p,uint8_t *mqd, *ctl_stack, *q_extra_data =NULL ;struct kfd_criu_queue_priv_data *q_data;struct kfd_topology_device *topo_dev; +struct criu_pdd_metadata *resume_info;struct kfd_process_device *pdd;uint64_t q_extra_data_size;struct queue_properties qp;
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int kfd_criu_restore_queue(struct kfd_process *p, · line 1144
Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +4
-0@@ -1131,6 +1138,11 @@ int kfd_criu_restore_queue(struct kfd_process *p, goto exit; } + resume_info =kzalloc (sizeof (struct criu_pdd_metadata ),GFP_KERNEL ); + resume_info->ctx_save_restore_area_address = qp.ctx_save_restore_area_address; + resume_info->ctx_save_restore_area_size = qp.ctx_save_restore_area_size; +list_add_tail (&resume_info->list, &pdd->criu_pdd_metadata_list);
Do we really need to allocate a new data structure here and a new list in the PDD? There is a list of all queues in struct qcm_process_device (pdd->qpd.queues_list). You could iterate over that. Each struct queue already has the addresses you need in q->properties.
Regards,
Felix
Quoted 59 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +27
-0+if (q_data->gws) ret =pqm_set_gws (&p->pqm, q_data->q_id, pdd->dev->gws);@@ -1146,6 +1158,32 @@ int kfd_criu_restore_queue(struct kfd_process *p,return ret; } +int kfd_criu_resume_pdd (struct kfd_process_device *pdd) +{ +struct kfd_topology_device *topo_dev =kfd_topology_device_by_id (pdd->dev->id); +struct criu_pdd_metadata *resume_info; +struct criu_pdd_metadata *next =NULL ; +u64 total_cwsr_size; +int ret =0 ; + +list_for_each_entry (resume_info, &pdd->criu_pdd_metadata_list, list) { + total_cwsr_size = resume_info->ctx_save_restore_area_size + + topo_dev->node_props.debug_memory_size; + total_cwsr_size =ALIGN (total_cwsr_size,PAGE_SIZE ); + + ret =kfd_queue_buffer_svm_get (pdd, resume_info->ctx_save_restore_area_address, total_cwsr_size); +if (ret) +break ; + } + +list_for_each_entry_safe (resume_info, next, &pdd->criu_pdd_metadata_list, list) { +list_del (&resume_info->list); +kfree (resume_info); + } + +return ret; +} + int pqm_get_queue_checkpoint_info(struct process_queue_manager *pqm, unsigned int qid, uint32_t *mqd_size,drivers/gpu/drm/amd/amdkfd/kfd_queue.c +2
-2@@ -88,7 +88,7 @@ void uninit_queue(struct queue *q)#if IS_ENABLED (CONFIG_HSA_AMD_SVM ) -static int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size) +int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size) {struct kfd_process *p = pdd->process;struct list_head update_list;@@ -182,7 +182,7 @@ static void kfd_queue_buffer_svm_put(struct kfd_process_device *pdd, u64 addr, u }#else -static int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size) +int kfd_queue_buffer_svm_get (struct kfd_process_device *pdd,u64 addr,u64 size) {return -EINVAL ; }
PATCH v2 3/3 drm/amdkfd: Don't check for vm ready on svm unmap
In reply to David FrancisThere was an amdgpu_vm_ready check in svm_range_unmap_from_gpu.
This is improper, because
- amdgpu_vm_ready checks for the vm to be locked, and unmap is expected to occur without that lock held
- amdgpu_vm_ready fails if the vm is in the process of eviction, but there's no need for unmap during eviction to be an error
Remove it (and swallow the -EBUSY error from eviction in progress)
This change is necessary to avoid dmesg spam from the vm lock check; handling eviction may require additional checks
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +6 -6
@@ -1425,6 +1425,7 @@ svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm, {uint64_t init_pte_value = adev->gmc.init_pte_flags;uint64_t gpu_start, gpu_end; +int ret;/* Convert CPU page range to GPU page range */ gpu_start = start *AMDGPU_GPU_PAGES_IN_CPU_PAGE ;
@@ -1433,14 +1434,13 @@ svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,pr_debug ("CPU[0x%llx 0x%llx] -> GPU[0x%llx 0x%llx]\n" , start, last, gpu_start, gpu_end); -if (!amdgpu_vm_ready (vm)) { -pr_debug ("VM not ready, canceling unmap\n" ); -return -EINVAL ; - } - -return amdgpu_vm_update_range (adev, vm, false, true, true, false,NULL , gpu_start, + ret =amdgpu_vm_update_range (adev, vm, false, true, true, false,NULL , gpu_start, gpu_end, init_pte_value,0 ,0 ,NULL ,NULL , fence); +/* EBUSY here means "vm not ready for updates because it in the process of evicting." +* If that is true, it's safe to not update the range now since the vm is not in use. +*/ +return ret ==EBUSY ?0 : ret; } static int
Signature · 1 line
2.34.1
Re: [PATCH v2 3/3] drm/amdkfd: Don't check for vm ready on svm unmap
Quoted 35 lines · David Francis
There was an
amdgpu_vm_readycheck insvm_range_unmap_from_gpu.This is improper, because
-amdgpu_vm_readychecks for the vm to be locked, and unmap is expected to occur without that lock held
-amdgpu_vm_readyfails if the vm is in the process of eviction, but there's no need for unmap during eviction to be an errorRemove it (and swallow the
-EBUSYerror from eviction in progress)This change is necessary to avoid dmesg spam from the vm lock check; handling eviction may require additional checks
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1
-1@@ -1425,6 +1425,7 @@ svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm, {uint64_t init_pte_value = adev->gmc.init_pte_flags;uint64_t gpu_start, gpu_end; +int ret;/* Convert CPU page range to GPU page range */ gpu_start = start *AMDGPU_GPU_PAGES_IN_CPU_PAGE ;@@ -1433,14 +1434,13 @@ svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,pr_debug ("CPU[0x%llx 0x%llx] -> GPU[0x%llx 0x%llx]\n" , start, last, gpu_start, gpu_end); -if (!amdgpu_vm_ready (vm)) {
drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 1441
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3
-5-pr_debug ("VM not ready, canceling unmap\n" ); -return -EINVAL ; - } - -return amdgpu_vm_update_range (adev, vm, false, true, true, false,NULL , gpu_start, + ret =amdgpu_vm_update_range (adev, vm, false, true, true, false,NULL , gpu_start, gpu_end, init_pte_value,0 ,0 ,NULL ,NULL , fence); +/* EBUSY here means "vm not ready for updates because it in the process of evicting." +* If that is true, it's safe to not update the range now since the vm is not in use.
I guess this is true. But as we discovered, we'll need to do the unmap or re-validation of the range eventually, before the VM is restored (in restore_process_worker) and user mode queues restarted. It's not a new bug, so we can do this in a later patch.
drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 1443
Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-0+*/ +return ret ==EBUSY ?0 : ret;
This should be -EBUSY (negative sign). With that fixed, the patch is
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0} static int