Skip to contentSkip to conversation

drm/amdkfd: Use better name to indicate the offset is in dwords

PATCH In review Zhao, Yong 2 participants 7 messages Nov 1, 2019 – Nov 11, 2019 4 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Zhao, Yong

author
#0 lore raw

PATCH 1/2 drm/amdkfd: Use better name to indicate the offset is in dwords

Change-Id I75da23bba90231762cf58da3170f5bb77ece45ed
---
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c          | 14 +++++++-------
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h              |  8 ++++----
 3 files changed, 12 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
index 984c2f2b24b6..4503fb26fe5b 100644
@@ -170,7 +170,7 @@ static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q)
 	}
 
 	q->properties.doorbell_off =
-		kfd_doorbell_id_to_offset(dev, q->process,
+		kfd_get_doorbell_dw_offset_from_bar(dev, q->process,
 					  q->doorbell_id);
 
 	return 0;
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +7 -7
index ebe79bf00145..f904355c44a1 100644
@@ -91,7 +91,7 @@ int kfd_doorbell_init(struct kfd_dev *kfd)
 	kfd->doorbell_base = kfd->shared_resources.doorbell_physical_address +
 				doorbell_start_offset;
 
-	kfd->doorbell_id_offset = doorbell_start_offset / sizeof(u32);
+	kfd->doorbell_base_dw_offset = doorbell_start_offset / sizeof(u32);
 
 	kfd->doorbell_kernel_ptr = ioremap(kfd->doorbell_base,
 					   kfd_doorbell_process_slice(kfd));
@@ -103,8 +103,8 @@ int kfd_doorbell_init(struct kfd_dev *kfd)
 	pr_debug("doorbell base           == 0x%08lX\n",
 			(uintptr_t)kfd->doorbell_base);
 
-	pr_debug("doorbell_id_offset      == 0x%08lX\n",
-			kfd->doorbell_id_offset);
+	pr_debug("doorbell_base_dw_offset      == 0x%08lX\n",
+			kfd->doorbell_base_dw_offset);
 
 	pr_debug("doorbell_process_limit  == 0x%08lX\n",
 			doorbell_process_limit);
@@ -185,7 +185,7 @@ void __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd,
 	 * Calculating the kernel doorbell offset using the first
 	 * doorbell page.
 	 */
-	*doorbell_off = kfd->doorbell_id_offset + inx;
+	*doorbell_off = kfd->doorbell_base_dw_offset + inx;
 
 	pr_debug("Get kernel queue doorbell\n"
 			"     doorbell offset   == 0x%08X\n"
@@ -225,17 +225,17 @@ void write_kernel_doorbell64(void __iomem *db, u64 value)
 	}
 }
 
-unsigned int kfd_doorbell_id_to_offset(struct kfd_dev *kfd,
+unsigned int kfd_get_doorbell_dw_offset_from_bar(struct kfd_dev *kfd,
 					struct kfd_process *process,
 					unsigned int doorbell_id)
 {
 	/*
-	 * doorbell_id_offset accounts for doorbells taken by KGD.
+	 * doorbell_base_dw_offset accounts for doorbells taken by KGD.
 	 * index * kfd_doorbell_process_slice/sizeof(u32) adjusts to
 	 * the process's doorbells. The offset returned is in dword
 	 * units regardless of the ASIC-dependent doorbell size.
 	 */
-	return kfd->doorbell_id_offset +
+	return kfd->doorbell_base_dw_offset +
 		process->doorbell_index
 		* kfd_doorbell_process_slice(kfd) / sizeof(u32) +
 		doorbell_id * kfd->device_info->doorbell_size / sizeof(u32);
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +4 -4
index 62db4d20ed32..7c561c98f2e2 100644
@@ -238,9 +238,9 @@ struct kfd_dev {
 					 * KFD. It is aligned for mapping
 					 * into user mode
 					 */
-	size_t doorbell_id_offset;	/* Doorbell offset (from KFD doorbell
-					 * to HW doorbell, GFX reserved some
-					 * at the start)
+	size_t doorbell_base_dw_offset;	/* Doorbell dword offset (from KFD
+					 * doorbell to PCI doorbell bar,
+					 * GFX reserved some at the start)
 					 */
 	u32 __iomem *doorbell_kernel_ptr; /* This is a pointer for a doorbells
 					   * page used by kernel queue
@@ -821,7 +821,7 @@ void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr);
 u32 read_kernel_doorbell(u32 __iomem *db);
 void write_kernel_doorbell(void __iomem *db, u32 value);
 void write_kernel_doorbell64(void __iomem *db, u64 value);
-unsigned int kfd_doorbell_id_to_offset(struct kfd_dev *kfd,
+unsigned int kfd_get_doorbell_dw_offset_from_bar(struct kfd_dev *kfd,
 					struct kfd_process *process,
 					unsigned int doorbell_id);
 phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev,
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#2 lore raw

PATCH 2/2 drm/amdkfd: Avoid using doorbell_off as offset in process doorbell pages

dorbell_off in the queue properties is mainly used for the doorbell dw offset in pci bar. We should not set it to the doorbell byte offset in process doorbell pages. This makes the code much easier to read.

Change-Id I553045ff9fcb3676900c92d10426f2ceb3660005
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c             | 12 ++++++------
 drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c              |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h                |  3 ++-
 .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c   |  8 ++++++--
 4 files changed, 15 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -6
index d9e36dbf13d5..b91993753b82 100644
@@ -258,6 +258,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
 	unsigned int queue_id;
 	struct kfd_process_device *pdd;
 	struct queue_properties q_properties;
+	uint32_t doorbell_offset_in_process = 0;
 
 	memset(&q_properties, 0, sizeof(struct queue_properties));
 
@@ -286,7 +287,8 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
 			p->pasid,
 			dev->id);
 
-	err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, &queue_id);
+	err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, &queue_id,
+			&doorbell_offset_in_process);
 	if (err != 0)
 		goto err_create_queue;
 
@@ -298,12 +300,10 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
 	args->doorbell_offset |= KFD_MMAP_GPU_ID(args->gpu_id);
 	args->doorbell_offset <<= PAGE_SHIFT;
 	if (KFD_IS_SOC15(dev->device_info->asic_family))
-		/* On SOC15 ASICs, doorbell allocation must be
-		 * per-device, and independent from the per-process
-		 * queue_id. Return the doorbell offset within the
-		 * doorbell aperture to user mode.
+		/* On SOC15 ASICs, include the doorbell offset within the
+		 * process doorbell frame, which could be 1 page or 2 pages.
 		 */
-		args->doorbell_offset |= q_properties.doorbell_off;
+		args->doorbell_offset |= doorbell_offset_in_process;
 
 	mutex_unlock(&p->mutex);
 
drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c +1 -1
index d59f2cd056c6..1d33c4f25263 100644
@@ -185,7 +185,7 @@ static int dbgdev_register_diq(struct kfd_dbgdev *dbgdev)
 	properties.type = KFD_QUEUE_TYPE_DIQ;
 
 	status = pqm_create_queue(dbgdev->pqm, dbgdev->dev, NULL,
-				&properties, &qid);
+				&properties, &qid, NULL);
 
 	if (status) {
 		pr_err("Failed to create DIQ\n");
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -1
index 7c561c98f2e2..66bae8f2dad1 100644
@@ -907,7 +907,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
 			    struct kfd_dev *dev,
 			    struct file *f,
 			    struct queue_properties *properties,
-			    unsigned int *qid);
+			    unsigned int *qid,
+			    uint32_t *p_doorbell_offset_in_process);
 int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);
 int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
 			struct queue_properties *p);
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6 -2
index 8509814a6ff0..48185d2957e9 100644
@@ -192,7 +192,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
 			    struct kfd_dev *dev,
 			    struct file *f,
 			    struct queue_properties *properties,
-			    unsigned int *qid)
+			    unsigned int *qid,
+			    uint32_t *p_doorbell_offset_in_process)
 {
 	int retval;
 	struct kfd_process_device *pdd;
@@ -307,8 +308,11 @@ int pqm_create_queue(struct process_queue_manager *pqm,
 		/* Return the doorbell offset within the doorbell page
 		 * to the caller so it can be passed up to user mode
 		 * (in bytes).
+		 * There are always 1024 doorbells per process, so in case
+		 * of 8-byte doorbells, there are two doorbell pages per
+		 * process.
 		 */
-		properties->doorbell_off =
+		*p_doorbell_offset_in_process =
 			(q->properties.doorbell_off * sizeof(uint32_t)) &
 			(kfd_doorbell_process_slice(dev) - 1);
 
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#4 lore raw

Re: [PATCH 2/2] drm/amdkfd: Avoid using doorbell_off as offset in process doorbell pages

Quoted 3 lines · Yong

dorbell_off in the queue properties is mainly used for the doorbell dw offset in pci bar. We should not set it to the doorbell byte offset in process doorbell pages. This makes the code much easier to read.

I kind of agree. I think what's confusing is that the queue_properties structure is used for two different purposes.

1. For storing queue properties provided by user mode through KFD ioctls
2. A subset of struct queue passed to mqd_manager and elsewhere (that's why some driver state is creeping into it)

Maybe a follow-up could cleanly separate the queue properties from the queue driver state. That would probably change some internal interfaces to use struct queue instead of queue_properties.

Anyway, this patch is

Quoted 89 lines
Change-Id I553045ff9fcb3676900c92d10426f2ceb3660005
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c             | 12 ++++++------
  drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c              |  2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h                |  3 ++-
  .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c   |  8 ++++++--
  4 files changed, 15 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -6
index d9e36dbf13d5..b91993753b82 100644
@@ -258,6 +258,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  	unsigned int queue_id;
  	struct kfd_process_device *pdd;
  	struct queue_properties q_properties;
+	uint32_t doorbell_offset_in_process = 0;
 
  	memset(&q_properties, 0, sizeof(struct queue_properties));
 
@@ -286,7 +287,8 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  			p->pasid,
  			dev->id);
 
-	err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, &queue_id);
+	err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, &queue_id,
+			&doorbell_offset_in_process);
  	if (err != 0)
  		goto err_create_queue;
 
@@ -298,12 +300,10 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  	args->doorbell_offset |= KFD_MMAP_GPU_ID(args->gpu_id);
  	args->doorbell_offset <<= PAGE_SHIFT;
  	if (KFD_IS_SOC15(dev->device_info->asic_family))
-		/* On SOC15 ASICs, doorbell allocation must be
-		 * per-device, and independent from the per-process
-		 * queue_id. Return the doorbell offset within the
-		 * doorbell aperture to user mode.
+		/* On SOC15 ASICs, include the doorbell offset within the
+		 * process doorbell frame, which could be 1 page or 2 pages.
  		 */
-		args->doorbell_offset |= q_properties.doorbell_off;
+		args->doorbell_offset |= doorbell_offset_in_process;
 
  	mutex_unlock(&p->mutex);
 
drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c +1 -1
index d59f2cd056c6..1d33c4f25263 100644
@@ -185,7 +185,7 @@ static int dbgdev_register_diq(struct kfd_dbgdev *dbgdev)
  	properties.type = KFD_QUEUE_TYPE_DIQ;
 
  	status = pqm_create_queue(dbgdev->pqm, dbgdev->dev, NULL,
-				&properties, &qid);
+				&properties, &qid, NULL);
 
  	if (status) {
  		pr_err("Failed to create DIQ\n");
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -1
index 7c561c98f2e2..66bae8f2dad1 100644
@@ -907,7 +907,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  			    struct kfd_dev *dev,
  			    struct file *f,
  			    struct queue_properties *properties,
-			    unsigned int *qid);
+			    unsigned int *qid,
+			    uint32_t *p_doorbell_offset_in_process);
  int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);
  int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
  			struct queue_properties *p);
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +2 -1
index 8509814a6ff0..48185d2957e9 100644
@@ -192,7 +192,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  			    struct kfd_dev *dev,
  			    struct file *f,
  			    struct queue_properties *properties,
-			    unsigned int *qid)
+			    unsigned int *qid,
+			    uint32_t *p_doorbell_offset_in_process)
  {
  	int retval;
  	struct kfd_process_device *pdd;

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_create_queue(struct process_queue_manager *pqm, · line 315

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +3 -1
@@ -307,8 +308,11 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  		/* Return the doorbell offset within the doorbell page
  		 * to the caller so it can be passed up to user mode
  		 * (in bytes).
+		 * There are always 1024 doorbells per process, so in case
+		 * of 8-byte doorbells, there are two doorbell pages per
+		 * process.
  		 */
-		properties->doorbell_off =
 		*p_doorbell_offset_in_process =

You need a NULL pointer check here because you call this with a NULL pointer from the DIQ code.

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_create_queue(struct process_queue_manager *pqm, · line 317

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
  			(q->properties.doorbell_off * sizeof(uint32_t)) &
  			(kfd_doorbell_process_slice(dev) - 1);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): a21e8321-51bf-f840-f891-2335be774131-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Re: [PATCH 2/2] drm/amdkfd: Avoid using doorbell_off as offset in process doorbell pages

Quoted 11 lines · Felix Kuehling
Quoted 3 lines · Yong

dorbell_off in the queue properties is mainly used for the doorbell dw offset in pci bar. We should not set it to the doorbell byte offset in process doorbell pages. This makes the code much easier to read.

I kind of agree. I think what's confusing is that the queue_properties structure is used for two different purposes.

1. For storing queue properties provided by user mode through KFD ioctls
2. A subset of struct queue passed to mqd_manager and elsewhere (that's why some driver state is creeping into it)

Quoted 6 lines

Maybe a follow-up could cleanly separate the queue properties from the queue driver state. That would probably change some internal interfaces to use struct queue instead of queue_properties.

Anyway, this patch is

I pointed out a missing NULL pointer check inline near the end of the patch. I should have mentioned it here. Please fix that before you submit.

Thanks,
  Felix

Quoted 102 lines
Quoted 89 lines
Change-Id I553045ff9fcb3676900c92d10426f2ceb3660005
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c             | 12 ++++++------
  drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c              |  2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h                |  3 ++-
  .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c   |  8 ++++++--
  4 files changed, 15 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -6
index d9e36dbf13d5..b91993753b82 100644
@@ -258,6 +258,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  	unsigned int queue_id;
  	struct kfd_process_device *pdd;
  	struct queue_properties q_properties;
+	uint32_t doorbell_offset_in_process = 0;
 
  	memset(&q_properties, 0, sizeof(struct queue_properties));
 
@@ -286,7 +287,8 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  			p->pasid,
  			dev->id);
 
-	err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, &queue_id);
+	err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, &queue_id,
+			&doorbell_offset_in_process);
  	if (err != 0)
  		goto err_create_queue;
 
@@ -298,12 +300,10 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  	args->doorbell_offset |= KFD_MMAP_GPU_ID(args->gpu_id);
  	args->doorbell_offset <<= PAGE_SHIFT;
  	if (KFD_IS_SOC15(dev->device_info->asic_family))
-		/* On SOC15 ASICs, doorbell allocation must be
-		 * per-device, and independent from the per-process
-		 * queue_id. Return the doorbell offset within the
-		 * doorbell aperture to user mode.
+		/* On SOC15 ASICs, include the doorbell offset within the
+		 * process doorbell frame, which could be 1 page or 2 pages.
  		 */
-		args->doorbell_offset |= q_properties.doorbell_off;
+		args->doorbell_offset |= doorbell_offset_in_process;
 
  	mutex_unlock(&p->mutex);
 
drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c +1 -1
index d59f2cd056c6..1d33c4f25263 100644
@@ -185,7 +185,7 @@ static int dbgdev_register_diq(struct kfd_dbgdev *dbgdev)
  	properties.type = KFD_QUEUE_TYPE_DIQ;
 
  	status = pqm_create_queue(dbgdev->pqm, dbgdev->dev, NULL,
-				&properties, &qid);
+				&properties, &qid, NULL);
 
  	if (status) {
  		pr_err("Failed to create DIQ\n");
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -1
index 7c561c98f2e2..66bae8f2dad1 100644
@@ -907,7 +907,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  			    struct kfd_dev *dev,
  			    struct file *f,
  			    struct queue_properties *properties,
-			    unsigned int *qid);
+			    unsigned int *qid,
+			    uint32_t *p_doorbell_offset_in_process);
  int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);
  int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
  			struct queue_properties *p);
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +2 -1
index 8509814a6ff0..48185d2957e9 100644
@@ -192,7 +192,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  			    struct kfd_dev *dev,
  			    struct file *f,
  			    struct queue_properties *properties,
-			    unsigned int *qid)
+			    unsigned int *qid,
+			    uint32_t *p_doorbell_offset_in_process)
  {
  	int retval;
  	struct kfd_process_device *pdd;

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_create_queue(struct process_queue_manager *pqm, · line 315

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +3 -1
@@ -307,8 +308,11 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  		/* Return the doorbell offset within the doorbell page
  		 * to the caller so it can be passed up to user mode
  		 * (in bytes).
+		 * There are always 1024 doorbells per process, so in case
+		 * of 8-byte doorbells, there are two doorbell pages per
+		 * process.
  		 */
-		properties->doorbell_off =
 		*p_doorbell_offset_in_process =

You need a NULL pointer check here because you call this with a NULL pointer from the DIQ code.

Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_create_queue(struct process_queue_manager *pqm, · line 317

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
  			(q->properties.doorbell_off * sizeof(uint32_t)) &
  			(kfd_doorbell_process_slice(dev) - 1);

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 78f9e381-e490-5555-c84d-ca76dcee7c83-5C7GfCeVMHo@public.gmane.org

author
#8 lore raw

Re: [PATCH 2/2] drm/amdkfd: Avoid using doorbell_off as offset in process doorbell pages

The NULL pointer is not an issue, because for DIQ, the if (q) condition, which guards the section but is now shown, will never be satisfied. Anyway, I still added the NULL pointer check.

With that, I have pushed the change.

Yong

Quoted 14 lines · Felix Kuehling
Quoted 13 lines · Felix Kuehling
Quoted 3 lines · Yong

dorbell_off in the queue properties is mainly used for the doorbell dw offset in pci bar. We should not set it to the doorbell byte offset in process doorbell pages. This makes the code much easier to read.

I kind of agree. I think what's confusing is that the queue_properties structure is used for two different purposes.

1. For storing queue properties provided by user mode through KFD ioctls
2. A subset of struct queue passed to mqd_manager and elsewhere (that's why some driver state is creeping into it)

Maybe a follow-up could cleanly separate the queue properties from the queue driver state. That would probably change some internal interfaces to use struct queue instead of queue_properties.

Quoted 111 lines
Quoted 4 lines

Anyway, this patch is

I pointed out a missing NULL pointer check inline near the end of the patch. I should have mentioned it here. Please fix that before you submit.

Thanks,
  Felix

Quoted 101 lines
Quoted 89 lines
Change-Id I553045ff9fcb3676900c92d10426f2ceb3660005
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c             | 12 ++++++------
  drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c              |  2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h                |  3 ++-
  .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c   |  8 ++++++--
  4 files changed, 15 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +6 -6
index d9e36dbf13d5..b91993753b82 100644
@@ -258,6 +258,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  	unsigned int queue_id;
  	struct kfd_process_device *pdd;
  	struct queue_properties q_properties;
+	uint32_t doorbell_offset_in_process = 0;
 
  	memset(&q_properties, 0, sizeof(struct queue_properties));
 
@@ -286,7 +287,8 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  			p->pasid,
  			dev->id);
 
-	err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, &queue_id);
+	err = pqm_create_queue(&p->pqm, dev, filep, &q_properties, &queue_id,
+			&doorbell_offset_in_process);
  	if (err != 0)
  		goto err_create_queue;
 
@@ -298,12 +300,10 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  	args->doorbell_offset |= KFD_MMAP_GPU_ID(args->gpu_id);
  	args->doorbell_offset <<= PAGE_SHIFT;
  	if (KFD_IS_SOC15(dev->device_info->asic_family))
-		/* On SOC15 ASICs, doorbell allocation must be
-		 * per-device, and independent from the per-process
-		 * queue_id. Return the doorbell offset within the
-		 * doorbell aperture to user mode.
+		/* On SOC15 ASICs, include the doorbell offset within the
+		 * process doorbell frame, which could be 1 page or 2 pages.
  		 */
-		args->doorbell_offset |= q_properties.doorbell_off;
+		args->doorbell_offset |= doorbell_offset_in_process;
 
  	mutex_unlock(&p->mutex);
 
drivers/gpu/drm/amd/amdkfd/kfd_dbgdev.c +1 -1
index d59f2cd056c6..1d33c4f25263 100644
@@ -185,7 +185,7 @@ static int dbgdev_register_diq(struct kfd_dbgdev *dbgdev)
  	properties.type = KFD_QUEUE_TYPE_DIQ;
 
  	status = pqm_create_queue(dbgdev->pqm, dbgdev->dev, NULL,
-				&properties, &qid);
+				&properties, &qid, NULL);
 
  	if (status) {
  		pr_err("Failed to create DIQ\n");
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -1
index 7c561c98f2e2..66bae8f2dad1 100644
@@ -907,7 +907,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  			    struct kfd_dev *dev,
  			    struct file *f,
  			    struct queue_properties *properties,
-			    unsigned int *qid);
+			    unsigned int *qid,
+			    uint32_t *p_doorbell_offset_in_process);
  int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);
  int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
  			struct queue_properties *p);
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +2 -1
index 8509814a6ff0..48185d2957e9 100644
@@ -192,7 +192,8 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  			    struct kfd_dev *dev,
  			    struct file *f,
  			    struct queue_properties *properties,
-			    unsigned int *qid)
+			    unsigned int *qid,
+			    uint32_t *p_doorbell_offset_in_process)
  {
  	int retval;
  	struct kfd_process_device *pdd;

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_create_queue(struct process_queue_manager *pqm, · line 315

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +3 -1
@@ -307,8 +308,11 @@ int pqm_create_queue(struct process_queue_manager *pqm,
  		/* Return the doorbell offset within the doorbell page
  		 * to the caller so it can be passed up to user mode
  		 * (in bytes).
+		 * There are always 1024 doorbells per process, so in case
+		 * of 8-byte doorbells, there are two doorbell pages per
+		 * process.
  		 */
-		properties->doorbell_off =
 		*p_doorbell_offset_in_process =

You need a NULL pointer check here because you call this with a NULL pointer from the DIQ code.

It is not an issue, because for DIQ, the if (q) condition, which guards this section but is now shown, will never be satisfied. Anyway, I still added the NULL pointer check.

With that, I have pushed the change.

Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_create_queue(struct process_queue_manager *pqm, · line 317

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0 -0
  			(q->properties.doorbell_off * sizeof(uint32_t)) &
  			(kfd_doorbell_process_slice(dev) - 1);

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#9 lore raw
In reply to a message not in the archive

ping

Quoted 93 lines · Yong
Change-Id I75da23bba90231762cf58da3170f5bb77ece45ed
---
  .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  |  2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c          | 14 +++++++-------
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h              |  8 ++++----
  3 files changed, 12 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
index 984c2f2b24b6..4503fb26fe5b 100644
@@ -170,7 +170,7 @@ static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q)
  	}
 
  	q->properties.doorbell_off =
-		kfd_doorbell_id_to_offset(dev, q->process,
+		kfd_get_doorbell_dw_offset_from_bar(dev, q->process,
  					  q->doorbell_id);
 
  	return 0;
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +7 -7
index ebe79bf00145..f904355c44a1 100644
@@ -91,7 +91,7 @@ int kfd_doorbell_init(struct kfd_dev *kfd)
  	kfd->doorbell_base = kfd->shared_resources.doorbell_physical_address +
  				doorbell_start_offset;
 
-	kfd->doorbell_id_offset = doorbell_start_offset / sizeof(u32);
+	kfd->doorbell_base_dw_offset = doorbell_start_offset / sizeof(u32);
 
  	kfd->doorbell_kernel_ptr = ioremap(kfd->doorbell_base,
  					   kfd_doorbell_process_slice(kfd));
@@ -103,8 +103,8 @@ int kfd_doorbell_init(struct kfd_dev *kfd)
  	pr_debug("doorbell base           == 0x%08lX\n",
  			(uintptr_t)kfd->doorbell_base);
 
-	pr_debug("doorbell_id_offset      == 0x%08lX\n",
-			kfd->doorbell_id_offset);
+	pr_debug("doorbell_base_dw_offset      == 0x%08lX\n",
+			kfd->doorbell_base_dw_offset);
 
  	pr_debug("doorbell_process_limit  == 0x%08lX\n",
  			doorbell_process_limit);
@@ -185,7 +185,7 @@ void __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd,
  	 * Calculating the kernel doorbell offset using the first
  	 * doorbell page.
  	 */
-	*doorbell_off = kfd->doorbell_id_offset + inx;
+	*doorbell_off = kfd->doorbell_base_dw_offset + inx;
 
  	pr_debug("Get kernel queue doorbell\n"
  			"     doorbell offset   == 0x%08X\n"
@@ -225,17 +225,17 @@ void write_kernel_doorbell64(void __iomem *db, u64 value)
  	}
  }
 
-unsigned int kfd_doorbell_id_to_offset(struct kfd_dev *kfd,
+unsigned int kfd_get_doorbell_dw_offset_from_bar(struct kfd_dev *kfd,
  					struct kfd_process *process,
  					unsigned int doorbell_id)
  {
  	/*
-	 * doorbell_id_offset accounts for doorbells taken by KGD.
+	 * doorbell_base_dw_offset accounts for doorbells taken by KGD.
  	 * index * kfd_doorbell_process_slice/sizeof(u32) adjusts to
  	 * the process's doorbells. The offset returned is in dword
  	 * units regardless of the ASIC-dependent doorbell size.
  	 */
-	return kfd->doorbell_id_offset +
+	return kfd->doorbell_base_dw_offset +
  		process->doorbell_index
  		* kfd_doorbell_process_slice(kfd) / sizeof(u32) +
  		doorbell_id * kfd->device_info->doorbell_size / sizeof(u32);
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -3
index 62db4d20ed32..7c561c98f2e2 100644
@@ -238,9 +238,9 @@ struct kfd_dev {
  					 * KFD. It is aligned for mapping
  					 * into user mode
  					 */
-	size_t doorbell_id_offset;	/* Doorbell offset (from KFD doorbell
-					 * to HW doorbell, GFX reserved some
-					 * at the start)
+	size_t doorbell_base_dw_offset;	/* Doorbell dword offset (from KFD
+					 * doorbell to PCI doorbell bar,
+					 * GFX reserved some at the start)
  					 */
  	u32 __iomem *doorbell_kernel_ptr; /* This is a pointer for a doorbells
  					   * page used by kernel queue

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr); · line 827

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
@@ -821,7 +821,7 @@ void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr);
  u32 read_kernel_doorbell(u32 __iomem *db);
  void write_kernel_doorbell(void __iomem *db, u32 value);
  void write_kernel_doorbell64(void __iomem *db, u64 value);
-unsigned int kfd_doorbell_id_to_offset(struct kfd_dev *kfd,
+unsigned int kfd_get_doorbell_dw_offset_from_bar(struct kfd_dev *kfd,
  					struct kfd_process *process,
  					unsigned int doorbell_id);
  phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#10 lore raw
In reply to a message not in the archive
Quoted 2 lines · Yong
Change-Id I75da23bba90231762cf58da3170f5bb77ece45ed

I agree with the name changes. One suggestion for a comment inline. With that fixed, this patch is

Quoted 78 lines
---
  .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  |  2 +-
  drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c          | 14 +++++++-------
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h              |  8 ++++----
  3 files changed, 12 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -1
index 984c2f2b24b6..4503fb26fe5b 100644
@@ -170,7 +170,7 @@ static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q)
  	}
 
  	q->properties.doorbell_off =
-		kfd_doorbell_id_to_offset(dev, q->process,
+		kfd_get_doorbell_dw_offset_from_bar(dev, q->process,
  					  q->doorbell_id);
 
  	return 0;
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c +7 -7
index ebe79bf00145..f904355c44a1 100644
@@ -91,7 +91,7 @@ int kfd_doorbell_init(struct kfd_dev *kfd)
  	kfd->doorbell_base = kfd->shared_resources.doorbell_physical_address +
  				doorbell_start_offset;
 
-	kfd->doorbell_id_offset = doorbell_start_offset / sizeof(u32);
+	kfd->doorbell_base_dw_offset = doorbell_start_offset / sizeof(u32);
 
  	kfd->doorbell_kernel_ptr = ioremap(kfd->doorbell_base,
  					   kfd_doorbell_process_slice(kfd));
@@ -103,8 +103,8 @@ int kfd_doorbell_init(struct kfd_dev *kfd)
  	pr_debug("doorbell base           == 0x%08lX\n",
  			(uintptr_t)kfd->doorbell_base);
 
-	pr_debug("doorbell_id_offset      == 0x%08lX\n",
-			kfd->doorbell_id_offset);
+	pr_debug("doorbell_base_dw_offset      == 0x%08lX\n",
+			kfd->doorbell_base_dw_offset);
 
  	pr_debug("doorbell_process_limit  == 0x%08lX\n",
  			doorbell_process_limit);
@@ -185,7 +185,7 @@ void __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd,
  	 * Calculating the kernel doorbell offset using the first
  	 * doorbell page.
  	 */
-	*doorbell_off = kfd->doorbell_id_offset + inx;
+	*doorbell_off = kfd->doorbell_base_dw_offset + inx;
 
  	pr_debug("Get kernel queue doorbell\n"
  			"     doorbell offset   == 0x%08X\n"
@@ -225,17 +225,17 @@ void write_kernel_doorbell64(void __iomem *db, u64 value)
  	}
  }
 
-unsigned int kfd_doorbell_id_to_offset(struct kfd_dev *kfd,
+unsigned int kfd_get_doorbell_dw_offset_from_bar(struct kfd_dev *kfd,
  					struct kfd_process *process,
  					unsigned int doorbell_id)
  {
  	/*
-	 * doorbell_id_offset accounts for doorbells taken by KGD.
+	 * doorbell_base_dw_offset accounts for doorbells taken by KGD.
  	 * index * kfd_doorbell_process_slice/sizeof(u32) adjusts to
  	 * the process's doorbells. The offset returned is in dword
  	 * units regardless of the ASIC-dependent doorbell size.
  	 */
-	return kfd->doorbell_id_offset +
+	return kfd->doorbell_base_dw_offset +
  		process->doorbell_index
  		* kfd_doorbell_process_slice(kfd) / sizeof(u32) +
  		doorbell_id * kfd->device_info->doorbell_size / sizeof(u32);
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
index 62db4d20ed32..7c561c98f2e2 100644

drivers/gpu/drm/amd/amdkfd/kfd_priv.h struct kfd_dev { · line 243

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -3
@@ -238,9 +238,9 @@ struct kfd_dev {
  					 * KFD. It is aligned for mapping
  					 * into user mode
  					 */
-	size_t doorbell_id_offset;	/* Doorbell offset (from KFD doorbell
-					 * to HW doorbell, GFX reserved some
-					 * at the start)
+	size_t doorbell_base_dw_offset;	/* Doorbell dword offset (from KFD
+					 * doorbell to PCI doorbell bar,
+					 * GFX reserved some at the start)

This is still a bit convoluted and sounds backwards. I suggest this wording:

    Offset from the start of the PCI doorbell BAR to the first KFD doorbell in dwords

Regards,
  Felix

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr); · line 827

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
  					 */
  	u32 __iomem *doorbell_kernel_ptr; /* This is a pointer for a doorbells
  					   * page used by kernel queue
@@ -821,7 +821,7 @@ void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr);
  u32 read_kernel_doorbell(u32 __iomem *db);
  void write_kernel_doorbell(void __iomem *db, u32 value);
  void write_kernel_doorbell64(void __iomem *db, u64 value);
-unsigned int kfd_doorbell_id_to_offset(struct kfd_dev *kfd,
+unsigned int kfd_get_doorbell_dw_offset_from_bar(struct kfd_dev *kfd,
  					struct kfd_process *process,
  					unsigned int doorbell_id);
  phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx