Skip to contentSkip to conversation

drm/amdkfd: Fix unaligned doorbell absolute offset for gfx8

PATCH Superseded Arvind Yadav 4 participants 6 messages Sep 27, 2023

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover drm/amdkfd: Fix unaligned doorbell absolute offset for gfx8

On older chips, the absolute doorbell offset within the doorbell page is based on the queue ID. KFD is using queue ID and doorbell size to get an absolute doorbell offset in userspace.

This patch is to adjust the absolute doorbell offset against the doorbell id considering the doorbell size of 32/64 bit.

Arvind Yadav (1):
drm/amdkfd: Fix unaligned doorbell absolute offset for gfx8

 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 drm/amdkfd: Fix unaligned doorbell absolute offset for gfx8

This patch is to adjust the absolute doorbell offset against the doorbell id considering the doorbell size of 32/64 bit.

---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +10 -1
index 0d3d538b64eb..c327f7f604d7 100644
@@ -407,7 +407,16 @@ static int allocate_doorbell(struct qcm_process_device *qpd,
 
 	q->properties.doorbell_off = amdgpu_doorbell_index_on_bar(dev->adev,
 								  qpd->proc_doorbells,
-								  q->doorbell_id);
+								  0);
+
+	/* Adjust the absolute doorbell offset against the doorbell id considering
+	 * the doorbell size of 32/64 bit.
+	 */
+	if (!KFD_IS_SOC15(dev))
+		q->properties.doorbell_off += q->doorbell_id;
+	else
+		q->properties.doorbell_off += q->doorbell_id * 2;
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
#2 lore raw

Adding [email protected] for review.

Thanks
~Arvind

Quoted 34 lines · Arvind Yadav

This patch is to adjust the absolute doorbell offset against the doorbell id considering the doorbell size of 32/64 bit.

---
  drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +10 -1
index 0d3d538b64eb..c327f7f604d7 100644
@@ -407,7 +407,16 @@ static int allocate_doorbell(struct qcm_process_device *qpd,
 
  	q->properties.doorbell_off = amdgpu_doorbell_index_on_bar(dev->adev,
  								  qpd->proc_doorbells,
-								  q->doorbell_id);
+								  0);
+
+	/* Adjust the absolute doorbell offset against the doorbell id considering
+	 * the doorbell size of 32/64 bit.
+	 */
+	if (!KFD_IS_SOC15(dev))
+		q->properties.doorbell_off += q->doorbell_id;
+	else
+		q->properties.doorbell_off += q->doorbell_id * 2;
+
  	return 0;
  }
 
maintainer
#3 lore raw
In reply to Arvind Yadav

[+Mukul]

Quoted 17 lines · Arvind Yadav

This patch is to adjust the absolute doorbell offset against the doorbell id considering the doorbell size of 32/64 bit.

---
  drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0 -0
index 0d3d538b64eb..c327f7f604d7 100644

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int allocate_doorbell(struct qcm_process_device *qpd, · line 410

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
@@ -407,7 +407,16 @@ static int allocate_doorbell(struct qcm_process_device *qpd,
 
  	q->properties.doorbell_off = amdgpu_doorbell_index_on_bar(dev->adev,
  								  qpd->proc_doorbells,
-								  q->doorbell_id);
+								  0);

Looks like we're now always calling amdgpu_doorbell_index_on_bar with the third parameter = 0. So we could remove that parameter. It doesn't do us any good and only causes bugs if we use any non-0 value.

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int allocate_doorbell(struct qcm_process_device *qpd, · line 418

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +8 -0
+
+	/* Adjust the absolute doorbell offset against the doorbell id considering
+	 * the doorbell size of 32/64 bit.
+	 */
+	if (!KFD_IS_SOC15(dev))
+		q->properties.doorbell_off += q->doorbell_id;
+	else
+		q->properties.doorbell_off += q->doorbell_id * 2;

This could be simplified and generalized as

	q->properties.doorbell_off += q->doorbell_id * dev->kfd->device_info.doorbell_size / 4;

Regards,
  Felix

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -0
+
  	return 0;
  }
 
#4 lore raw
Quoted 22 lines · Felix Kuehling

[+Mukul]

Quoted 18 lines · Arvind Yadav

This patch is to adjust the absolute doorbell offset against the doorbell id considering the doorbell size of 32/64 bit.

---
  drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0 -0
index 0d3d538b64eb..c327f7f604d7 100644
@@ -407,7 +407,16 @@ static int allocate_doorbell(struct qcm_process_device *qpd,
 
Quoted 7 lines

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int allocate_doorbell(struct qcm_process_device *qpd, · line 410

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
  	q->properties.doorbell_off = amdgpu_doorbell_index_on_bar(dev->adev,
  								  qpd->proc_doorbells,
-								  q->doorbell_id);
+								  0);

Looks like we're now always calling amdgpu_doorbell_index_on_bar with the third parameter = 0. So we could remove that parameter. It doesn't do us any good and only causes bugs if we use any non-0 value.

Hey Felix,

Actually this was happening because in usermode KFD library the doorbell-size is for non-SOC15() hardware is hard coded to 4 bytes.

We added this fix just so that the library code doesn't need to be changed, but can still get aligned to kernel code.

GFX Usermode queue code uses this doorbell-index parameter, and it gives us the right offset.

Regards

Shashank

Quoted 12 lines

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int allocate_doorbell(struct qcm_process_device *qpd, · line 418

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +8 -0
+
+	/* Adjust the absolute doorbell offset against the doorbell id considering
+	 * the doorbell size of 32/64 bit.
+	 */
+	if (!KFD_IS_SOC15(dev))
+		q->properties.doorbell_off += q->doorbell_id;
+	else
+		q->properties.doorbell_off += q->doorbell_id * 2;

This could be simplified and generalized as

Quoted 1 line
	q->properties.doorbell_off += q->doorbell_id * dev->kfd->device_info.doorbell_size / 4;

Agree, we can do this simplification.

- Shashank

Quoted 8 lines

Regards,
  Felix

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -0
+
  	return 0;
  }
 
#5 lore raw
In reply to Arvind Yadav

Adding [email protected] for review.

Thanks
~Arvind

Quoted 15 lines · Arvind Yadav

On older chips, the absolute doorbell offset within the doorbell page is based on the queue ID. KFD is using queue ID and doorbell size to get an absolute doorbell offset in userspace.

This patch is to adjust the absolute doorbell offset against the doorbell id considering the doorbell size of 32/64 bit.

Arvind Yadav (1):
drm/amdkfd: Fix unaligned doorbell absolute offset for gfx8

  drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)