Skip to contentSkip to conversation

drm/amdkfd: Fix CRIU restore op due to doorbell offset

PATCH Superseded Rajneesh Bhardwaj 2 participants 2 messages Sep 7, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: Fix CRIU restore op due to doorbell offset

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")'
---
 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(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -0
index 84da1a9ce37c..c476993e3927 100644
@@ -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;
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +3 -1
index b33798f89ef0..7690514c4eb3 100644
@@ -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;
 
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +9 -0
index 6e3e7f54381b..9f05f64c5af8 100644
@@ -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);
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 5 lines · Rajneesh Bhardwaj

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.

typo: extending

A few more nit-picks inline.

Quoted 15 lines
Fixes 'commit 15bcfbc55b57 ("drm/amdkfd: Allocate doorbells only when needed")'
---
  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(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index 84da1a9ce37c..c476993e3927 100644

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int criu_restore_devices(struct kfd_process *p, · line 2162

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -0
@@ -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;
+	}

Incorrect indentation. The closing brace should be indented one more tab. And the if condition would be more readable if the second line was aligned under the !pdd->doorbell_index.

You don't need a new err_alloc_doorbells label. Just goto exit.

Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -0
  	}
 
  	/*
@@ -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;
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +0 -0
index b33798f89ef0..7690514c4eb3 100644

drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c int kfd_doorbell_mmap(struct kfd_dev *dev, struct kfd_process *process, · line 161

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +2 -1
@@ -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");

Please use the same error message as above for consistency. Or better yet, move the error printing into kfd_alloc_process_doorbells, so you don't have to duplicate the same error message in multiple places.

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +1 -0
  		return -ENOMEM;
+	}
  	vma->vm_flags |= VM_IO | VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE |
  				VM_DONTDUMP | VM_PFNMAP;
 
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
index 6e3e7f54381b..9f05f64c5af8 100644

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int kfd_criu_restore_queue(struct kfd_process *p, · line 863

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +4 -0
@@ -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");

Same as above.

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int kfd_criu_restore_queue(struct kfd_process *p, · line 865

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +2 -0
+		ret = -ENOMEM;
+		goto err_alloc_doorbells;

You don't need a new err_alloc_doorbells label. Just goto exit.

Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +3 -0
+	}
+
  	/* 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);