Skip to contentSkip to conversation

drm/amdkfd: Simplify the mmap offset related bit operations

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

Subsystems (3)
lore
Share & tools
lore

Zhao, Yong

author
#0 lore raw

PATCH 1/1 drm/amdkfd: Simplify the mmap offset related bit operations

The new code is much cleaner and results in better readability.

Change-Id I0c1f7cca7e24ddb7b4ffe1cb0fa71943828ae373
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 13 +++++++------
 drivers/gpu/drm/amd/amdkfd/kfd_events.c  |  1 -
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 +++------
 drivers/gpu/drm/amd/amdkfd/kfd_process.c |  3 +--
 4 files changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -6
index b91993753b82..590138727ca9 100644
@@ -298,7 +298,6 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
 	/* Return gpu_id as doorbell offset for mmap usage */
 	args->doorbell_offset = KFD_MMAP_TYPE_DOORBELL;
 	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, include the doorbell offset within the
 		 * process doorbell frame, which could be 1 page or 2 pages.
@@ -1938,20 +1937,22 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct kfd_process *process;
 	struct kfd_dev *dev = NULL;
-	unsigned long vm_pgoff;
+	unsigned long mmap_offset;
 	unsigned int gpu_id;
 
 	process = kfd_get_process(current);
 	if (IS_ERR(process))
 		return PTR_ERR(process);
 
-	vm_pgoff = vma->vm_pgoff;
-	vma->vm_pgoff = KFD_MMAP_OFFSET_VALUE_GET(vm_pgoff);
-	gpu_id = KFD_MMAP_GPU_ID_GET(vm_pgoff);
+	mmap_offset = vma->vm_pgoff << PAGE_SHIFT;
+	gpu_id = KFD_MMAP_GET_GPU_ID(mmap_offset);
 	if (gpu_id)
 		dev = kfd_device_by_id(gpu_id);
 
-	switch (vm_pgoff & KFD_MMAP_TYPE_MASK) {
+	/* only leave the offset segment */
+	vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - PAGE_SHIFT)) - 1;
+
+	switch (mmap_offset & KFD_MMAP_TYPE_MASK) {
 	case KFD_MMAP_TYPE_DOORBELL:
 		if (!dev)
 			return -ENODEV;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -1
index 908081c85de1..1f8365575b12 100644
@@ -346,7 +346,6 @@ int kfd_event_create(struct file *devkfd, struct kfd_process *p,
 		ret = create_signal_event(devkfd, p, ev);
 		if (!ret) {
 			*event_page_offset = KFD_MMAP_TYPE_EVENTS;
-			*event_page_offset <<= PAGE_SHIFT;
 			*event_slot_index = ev->event_id;
 		}
 		break;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -6
index 66bae8f2dad1..8eecd2cd1fd2 100644
@@ -59,24 +59,21 @@
  * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
  *  defines are w.r.t to PAGE_SIZE
  */
-#define KFD_MMAP_TYPE_SHIFT	(62 - PAGE_SHIFT)
+#define KFD_MMAP_TYPE_SHIFT	(62)
 #define KFD_MMAP_TYPE_MASK	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
 #define KFD_MMAP_TYPE_DOORBELL	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
 #define KFD_MMAP_TYPE_EVENTS	(0x2ULL << KFD_MMAP_TYPE_SHIFT)
 #define KFD_MMAP_TYPE_RESERVED_MEM	(0x1ULL << KFD_MMAP_TYPE_SHIFT)
 #define KFD_MMAP_TYPE_MMIO	(0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
-#define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
+#define KFD_MMAP_GPU_ID_SHIFT (46)
 #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
 				<< KFD_MMAP_GPU_ID_SHIFT)
 #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) << KFD_MMAP_GPU_ID_SHIFT)\
 				& KFD_MMAP_GPU_ID_MASK)
-#define KFD_MMAP_GPU_ID_GET(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
+#define KFD_MMAP_GET_GPU_ID(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
 				>> KFD_MMAP_GPU_ID_SHIFT)
 
-#define KFD_MMAP_OFFSET_VALUE_MASK	(0x3FFFFFFFFFFFULL >> PAGE_SHIFT)
-#define KFD_MMAP_OFFSET_VALUE_GET(offset) (offset & KFD_MMAP_OFFSET_VALUE_MASK)
-
 /*
  * When working with cp scheduler we should assign the HIQ manually or via
  * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ hqd slot
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -2
index 6abfb77ae540..39dc49b8fd85 100644
@@ -554,8 +554,7 @@ static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep)
 		if (!dev->cwsr_enabled || qpd->cwsr_kaddr || qpd->cwsr_base)
 			continue;
 
-		offset = (KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id))
-			<< PAGE_SHIFT;
+		offset = KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id);
 		qpd->tba_addr = (int64_t)vm_mmap(filep, 0,
 			KFD_CWSR_TBA_TMA_SIZE, PROT_READ | PROT_EXEC,
 			MAP_SHARED, offset);
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]

#2 lore raw

NAK. This won't work for several reasons.

The mmap_offset is used as offset parameter in the mmap system call. If you check the man page of mmap, you'll see that "offset must be a multiple of the page size". Therefore the PAGE_SHIFT is necessary.

In the case of doorbell offsets, the offset is parsed and processed by the Thunk in user mode. On GFX9 GPUs the lower bits are used for the offset of the doorbell within the doorbell page. On GFX8 the queue ID was used, but on GFX9 we had to decoupled the doorbell ID from the queue ID. If you remove the PAGE_SHIFT, you'll need to put those bits somewhere else. But that change in the encoding would break the ABI with the Thunk.

Regards,
  Felix

Quoted 100 lines · Yong

The new code is much cleaner and results in better readability.

Change-Id I0c1f7cca7e24ddb7b4ffe1cb0fa71943828ae373
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 13 +++++++------
  drivers/gpu/drm/amd/amdkfd/kfd_events.c  |  1 -
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 +++------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c |  3 +--
  4 files changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -6
index b91993753b82..590138727ca9 100644
@@ -298,7 +298,6 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  	/* Return gpu_id as doorbell offset for mmap usage */
  	args->doorbell_offset = KFD_MMAP_TYPE_DOORBELL;
  	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, include the doorbell offset within the
  		 * process doorbell frame, which could be 1 page or 2 pages.
@@ -1938,20 +1937,22 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
  {
  	struct kfd_process *process;
  	struct kfd_dev *dev = NULL;
-	unsigned long vm_pgoff;
+	unsigned long mmap_offset;
  	unsigned int gpu_id;
 
  	process = kfd_get_process(current);
  	if (IS_ERR(process))
  		return PTR_ERR(process);
 
-	vm_pgoff = vma->vm_pgoff;
-	vma->vm_pgoff = KFD_MMAP_OFFSET_VALUE_GET(vm_pgoff);
-	gpu_id = KFD_MMAP_GPU_ID_GET(vm_pgoff);
+	mmap_offset = vma->vm_pgoff << PAGE_SHIFT;
+	gpu_id = KFD_MMAP_GET_GPU_ID(mmap_offset);
  	if (gpu_id)
  		dev = kfd_device_by_id(gpu_id);
 
-	switch (vm_pgoff & KFD_MMAP_TYPE_MASK) {
+	/* only leave the offset segment */
+	vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - PAGE_SHIFT)) - 1;
+
+	switch (mmap_offset & KFD_MMAP_TYPE_MASK) {
  	case KFD_MMAP_TYPE_DOORBELL:
  		if (!dev)
  			return -ENODEV;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -1
index 908081c85de1..1f8365575b12 100644
@@ -346,7 +346,6 @@ int kfd_event_create(struct file *devkfd, struct kfd_process *p,
  		ret = create_signal_event(devkfd, p, ev);
  		if (!ret) {
  			*event_page_offset = KFD_MMAP_TYPE_EVENTS;
-			*event_page_offset <<= PAGE_SHIFT;
  			*event_slot_index = ev->event_id;
  		}
  		break;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -6
index 66bae8f2dad1..8eecd2cd1fd2 100644
@@ -59,24 +59,21 @@
   * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
   *  defines are w.r.t to PAGE_SIZE
   */
-#define KFD_MMAP_TYPE_SHIFT	(62 - PAGE_SHIFT)
+#define KFD_MMAP_TYPE_SHIFT	(62)
  #define KFD_MMAP_TYPE_MASK	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_DOORBELL	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_EVENTS	(0x2ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_RESERVED_MEM	(0x1ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_MMIO	(0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
-#define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
+#define KFD_MMAP_GPU_ID_SHIFT (46)
  #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
  				<< KFD_MMAP_GPU_ID_SHIFT)
  #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) << KFD_MMAP_GPU_ID_SHIFT)\
  				& KFD_MMAP_GPU_ID_MASK)
-#define KFD_MMAP_GPU_ID_GET(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
+#define KFD_MMAP_GET_GPU_ID(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
  				>> KFD_MMAP_GPU_ID_SHIFT)
 
-#define KFD_MMAP_OFFSET_VALUE_MASK	(0x3FFFFFFFFFFFULL >> PAGE_SHIFT)
-#define KFD_MMAP_OFFSET_VALUE_GET(offset) (offset & KFD_MMAP_OFFSET_VALUE_MASK)
-
  /*
   * When working with cp scheduler we should assign the HIQ manually or via
   * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ hqd slot
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index 6abfb77ae540..39dc49b8fd85 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep) · line 560

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -2
@@ -554,8 +554,7 @@ static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep)
  		if (!dev->cwsr_enabled || qpd->cwsr_kaddr || qpd->cwsr_base)
  			continue;
 
-		offset = (KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id))
-			<< PAGE_SHIFT;
+		offset = KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id);
  		qpd->tba_addr = (int64_t)vm_mmap(filep, 0,
  			KFD_CWSR_TBA_TMA_SIZE, PROT_READ | PROT_EXEC,
  			MAP_SHARED, offset);

_______________________________________________
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): c237f5bf-6638-2d90-3f94-e1eca2c22780-5C7GfCeVMHo@public.gmane.org

author
#4 lore raw

Hi Felix,

The PAGE_SHIFT was not deleted but merged into the KFD_*_SHIFT in kfd_priv.h. Because of that, this change is actually transparent to the thunk, and it only straightens up the bit shift operations in most cases.

Regards,
Yong
________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, November 1, 2019 5:13 PM
To: [email protected] <[email protected]>; Zhao, Yong <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: Simplify the mmap offset related bit operations

NAK. This won't work for several reasons.

The mmap_offset is used as offset parameter in the mmap system call. If you check the man page of mmap, you'll see that "offset must be a multiple of the page size". Therefore the PAGE_SHIFT is necessary.

In the case of doorbell offsets, the offset is parsed and processed by the Thunk in user mode. On GFX9 GPUs the lower bits are used for the offset of the doorbell within the doorbell page. On GFX8 the queue ID was used, but on GFX9 we had to decoupled the doorbell ID from the queue ID. If you remove the PAGE_SHIFT, you'll need to put those bits somewhere else. But that change in the encoding would break the ABI with the Thunk.

Regards,
Felix

Quoted 100 lines · Yong

The new code is much cleaner and results in better readability.

Change-Id I0c1f7cca7e24ddb7b4ffe1cb0fa71943828ae373
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 13 +++++++------
  drivers/gpu/drm/amd/amdkfd/kfd_events.c  |  1 -
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 +++------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c |  3 +--
  4 files changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -6
index b91993753b82..590138727ca9 100644
@@ -298,7 +298,6 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
       /* Return gpu_id as doorbell offset for mmap usage */
       args->doorbell_offset = KFD_MMAP_TYPE_DOORBELL;
       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, include the doorbell offset within the
                * process doorbell frame, which could be 1 page or 2 pages.
@@ -1938,20 +1937,22 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
  {
       struct kfd_process *process;
       struct kfd_dev *dev = NULL;
-     unsigned long vm_pgoff;
+     unsigned long mmap_offset;
       unsigned int gpu_id;
 
       process = kfd_get_process(current);
       if (IS_ERR(process))
               return PTR_ERR(process);
 
-     vm_pgoff = vma->vm_pgoff;
-     vma->vm_pgoff = KFD_MMAP_OFFSET_VALUE_GET(vm_pgoff);
-     gpu_id = KFD_MMAP_GPU_ID_GET(vm_pgoff);
+     mmap_offset = vma->vm_pgoff << PAGE_SHIFT;
+     gpu_id = KFD_MMAP_GET_GPU_ID(mmap_offset);
       if (gpu_id)
               dev = kfd_device_by_id(gpu_id);
 
-     switch (vm_pgoff & KFD_MMAP_TYPE_MASK) {
+     /* only leave the offset segment */
+     vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - PAGE_SHIFT)) - 1;
+
+     switch (mmap_offset & KFD_MMAP_TYPE_MASK) {
       case KFD_MMAP_TYPE_DOORBELL:
               if (!dev)
                       return -ENODEV;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -1
index 908081c85de1..1f8365575b12 100644
@@ -346,7 +346,6 @@ int kfd_event_create(struct file *devkfd, struct kfd_process *p,
               ret = create_signal_event(devkfd, p, ev);
               if (!ret) {
                       *event_page_offset = KFD_MMAP_TYPE_EVENTS;
-                     *event_page_offset <<= PAGE_SHIFT;
                       *event_slot_index = ev->event_id;
               }
               break;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -6
index 66bae8f2dad1..8eecd2cd1fd2 100644
@@ -59,24 +59,21 @@
   * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
   *  defines are w.r.t to PAGE_SIZE
   */
-#define KFD_MMAP_TYPE_SHIFT  (62 - PAGE_SHIFT)
+#define KFD_MMAP_TYPE_SHIFT  (62)
  #define KFD_MMAP_TYPE_MASK  (0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_DOORBELL      (0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_EVENTS        (0x2ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_RESERVED_MEM  (0x1ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_MMIO  (0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
-#define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
+#define KFD_MMAP_GPU_ID_SHIFT (46)
  #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
                               << KFD_MMAP_GPU_ID_SHIFT)
  #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) << KFD_MMAP_GPU_ID_SHIFT)\
                               & KFD_MMAP_GPU_ID_MASK)
-#define KFD_MMAP_GPU_ID_GET(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
+#define KFD_MMAP_GET_GPU_ID(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
                               >> KFD_MMAP_GPU_ID_SHIFT)
 
-#define KFD_MMAP_OFFSET_VALUE_MASK   (0x3FFFFFFFFFFFULL >> PAGE_SHIFT)
-#define KFD_MMAP_OFFSET_VALUE_GET(offset) (offset & KFD_MMAP_OFFSET_VALUE_MASK)
-
  /*
   * When working with cp scheduler we should assign the HIQ manually or via
   * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ hqd slot
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index 6abfb77ae540..39dc49b8fd85 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep) · line 560

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -2
@@ -554,8 +554,7 @@ static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep)
               if (!dev->cwsr_enabled || qpd->cwsr_kaddr || qpd->cwsr_base)
                       continue;
 
-             offset = (KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id))
-                     << PAGE_SHIFT;
+             offset = KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id);
               qpd->tba_addr = (int64_t)vm_mmap(filep, 0,
                       KFD_CWSR_TBA_TMA_SIZE, PROT_READ | PROT_EXEC,
                       MAP_SHARED, offset);

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

#5 lore raw
In reply to a message not in the archive
Quoted 36 lines · Yong

The new code is much cleaner and results in better readability.

Change-Id I0c1f7cca7e24ddb7b4ffe1cb0fa71943828ae373
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 13 +++++++------
  drivers/gpu/drm/amd/amdkfd/kfd_events.c  |  1 -
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 +++------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c |  3 +--
  4 files changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -3
index b91993753b82..590138727ca9 100644
@@ -298,7 +298,6 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
  	/* Return gpu_id as doorbell offset for mmap usage */
  	args->doorbell_offset = KFD_MMAP_TYPE_DOORBELL;
  	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, include the doorbell offset within the
  		 * process doorbell frame, which could be 1 page or 2 pages.
@@ -1938,20 +1937,22 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
  {
  	struct kfd_process *process;
  	struct kfd_dev *dev = NULL;
-	unsigned long vm_pgoff;
+	unsigned long mmap_offset;
  	unsigned int gpu_id;
 
  	process = kfd_get_process(current);
  	if (IS_ERR(process))
  		return PTR_ERR(process);
 
-	vm_pgoff = vma->vm_pgoff;

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_mmap(struct file *filp, struct vm_area_struct *vma) · line 1953

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4 -3
-	vma->vm_pgoff = KFD_MMAP_OFFSET_VALUE_GET(vm_pgoff);
-	gpu_id = KFD_MMAP_GPU_ID_GET(vm_pgoff);
+	mmap_offset = vma->vm_pgoff << PAGE_SHIFT;
+	gpu_id = KFD_MMAP_GET_GPU_ID(mmap_offset);
  	if (gpu_id)
  		dev = kfd_device_by_id(gpu_id);
 
-	switch (vm_pgoff & KFD_MMAP_TYPE_MASK) {
+	/* only leave the offset segment */
+	vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - PAGE_SHIFT)) - 1;

You're now open-coding what used to be done by the KFD_MMAP_OFFSET_VALUE_GET macro. I don't see how this is an improvement. Maybe better to update the macro to do this.

Quoted 35 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
+
+	switch (mmap_offset & KFD_MMAP_TYPE_MASK) {
  	case KFD_MMAP_TYPE_DOORBELL:
  		if (!dev)
  			return -ENODEV;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -1
index 908081c85de1..1f8365575b12 100644
@@ -346,7 +346,6 @@ int kfd_event_create(struct file *devkfd, struct kfd_process *p,
  		ret = create_signal_event(devkfd, p, ev);
  		if (!ret) {
  			*event_page_offset = KFD_MMAP_TYPE_EVENTS;
-			*event_page_offset <<= PAGE_SHIFT;
  			*event_slot_index = ev->event_id;
  		}
  		break;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -2
index 66bae8f2dad1..8eecd2cd1fd2 100644
@@ -59,24 +59,21 @@
   * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
   *  defines are w.r.t to PAGE_SIZE
   */
-#define KFD_MMAP_TYPE_SHIFT	(62 - PAGE_SHIFT)
+#define KFD_MMAP_TYPE_SHIFT	(62)
  #define KFD_MMAP_TYPE_MASK	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_DOORBELL	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_EVENTS	(0x2ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_RESERVED_MEM	(0x1ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_MMIO	(0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
-#define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
+#define KFD_MMAP_GPU_ID_SHIFT (46)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 78

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -3
  #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
  				<< KFD_MMAP_GPU_ID_SHIFT)
  #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) << KFD_MMAP_GPU_ID_SHIFT)\
  				& KFD_MMAP_GPU_ID_MASK)
-#define KFD_MMAP_GPU_ID_GET(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
+#define KFD_MMAP_GET_GPU_ID(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
  				>> KFD_MMAP_GPU_ID_SHIFT)
 
-#define KFD_MMAP_OFFSET_VALUE_MASK	(0x3FFFFFFFFFFFULL >> PAGE_SHIFT)
-#define KFD_MMAP_OFFSET_VALUE_GET(offset) (offset & KFD_MMAP_OFFSET_VALUE_MASK)

This macro is still useful. See above. I think you should just update the mask and continue using it for clarity.

Regards,
  Felix

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
-
  /*
   * When working with cp scheduler we should assign the HIQ manually or via
   * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ hqd slot
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index 6abfb77ae540..39dc49b8fd85 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep) · line 560

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -2
@@ -554,8 +554,7 @@ static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep)
  		if (!dev->cwsr_enabled || qpd->cwsr_kaddr || qpd->cwsr_base)
  			continue;
 
-		offset = (KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id))
-			<< PAGE_SHIFT;
+		offset = KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id);
  		qpd->tba_addr = (int64_t)vm_mmap(filep, 0,
  			KFD_CWSR_TBA_TMA_SIZE, PROT_READ | PROT_EXEC,
  			MAP_SHARED, offset);

_______________________________________________
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): 2d2985b2-bcd2-3f56-918e-948020c61993-5C7GfCeVMHo@public.gmane.org

author
#7 lore raw

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_mmap(struct file *filp, struct vm_area_struct *vma) · line 1953

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
+     /* only leave the offset segment */
+     vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - PAGE_SHIFT)) - 1;

You're now open-coding what used to be done by the KFD_MMAP_OFFSET_VALUE_GET macro. I don't see how this is an improvement. Maybe better to update the macro to do this.

I can definitely do that, but I think we'd better delete this line completely as it seems odd to change vm_pgoff. Moreover this vm_pgoff is not used at all in the following function calls. What do you think?

Regards,
Yong
________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, November 1, 2019 6:48 PM
To: Zhao, Yong <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: Simplify the mmap offset related bit operations

Quoted 36 lines · Yong

The new code is much cleaner and results in better readability.

Change-Id I0c1f7cca7e24ddb7b4ffe1cb0fa71943828ae373
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 13 +++++++------
  drivers/gpu/drm/amd/amdkfd/kfd_events.c  |  1 -
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 +++------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c |  3 +--
  4 files changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -3
index b91993753b82..590138727ca9 100644
@@ -298,7 +298,6 @@ static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,
       /* Return gpu_id as doorbell offset for mmap usage */
       args->doorbell_offset = KFD_MMAP_TYPE_DOORBELL;
       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, include the doorbell offset within the
                * process doorbell frame, which could be 1 page or 2 pages.
@@ -1938,20 +1937,22 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
  {
       struct kfd_process *process;
       struct kfd_dev *dev = NULL;
-     unsigned long vm_pgoff;
+     unsigned long mmap_offset;
       unsigned int gpu_id;
 
       process = kfd_get_process(current);
       if (IS_ERR(process))
               return PTR_ERR(process);
 
-     vm_pgoff = vma->vm_pgoff;

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_mmap(struct file *filp, struct vm_area_struct *vma) · line 1953

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4 -3
-     vma->vm_pgoff = KFD_MMAP_OFFSET_VALUE_GET(vm_pgoff);
-     gpu_id = KFD_MMAP_GPU_ID_GET(vm_pgoff);
+     mmap_offset = vma->vm_pgoff << PAGE_SHIFT;
+     gpu_id = KFD_MMAP_GET_GPU_ID(mmap_offset);
       if (gpu_id)
               dev = kfd_device_by_id(gpu_id);
 
-     switch (vm_pgoff & KFD_MMAP_TYPE_MASK) {
+     /* only leave the offset segment */
+     vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - PAGE_SHIFT)) - 1;

You're now open-coding what used to be done by the KFD_MMAP_OFFSET_VALUE_GET macro. I don't see how this is an improvement. Maybe better to update the macro to do this.

Quoted 35 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
+
+     switch (mmap_offset & KFD_MMAP_TYPE_MASK) {
       case KFD_MMAP_TYPE_DOORBELL:
               if (!dev)
                       return -ENODEV;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -1
index 908081c85de1..1f8365575b12 100644
@@ -346,7 +346,6 @@ int kfd_event_create(struct file *devkfd, struct kfd_process *p,
               ret = create_signal_event(devkfd, p, ev);
               if (!ret) {
                       *event_page_offset = KFD_MMAP_TYPE_EVENTS;
-                     *event_page_offset <<= PAGE_SHIFT;
                       *event_slot_index = ev->event_id;
               }
               break;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -2
index 66bae8f2dad1..8eecd2cd1fd2 100644
@@ -59,24 +59,21 @@
   * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. Hence, these
   *  defines are w.r.t to PAGE_SIZE
   */
-#define KFD_MMAP_TYPE_SHIFT  (62 - PAGE_SHIFT)
+#define KFD_MMAP_TYPE_SHIFT  (62)
  #define KFD_MMAP_TYPE_MASK  (0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_DOORBELL      (0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_EVENTS        (0x2ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_RESERVED_MEM  (0x1ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_MMIO  (0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
-#define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
+#define KFD_MMAP_GPU_ID_SHIFT (46)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 78

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -3
  #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
                               << KFD_MMAP_GPU_ID_SHIFT)
  #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) << KFD_MMAP_GPU_ID_SHIFT)\
                               & KFD_MMAP_GPU_ID_MASK)
-#define KFD_MMAP_GPU_ID_GET(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
+#define KFD_MMAP_GET_GPU_ID(offset)    ((offset & KFD_MMAP_GPU_ID_MASK) \
                               >> KFD_MMAP_GPU_ID_SHIFT)
 
-#define KFD_MMAP_OFFSET_VALUE_MASK   (0x3FFFFFFFFFFFULL >> PAGE_SHIFT)
-#define KFD_MMAP_OFFSET_VALUE_GET(offset) (offset & KFD_MMAP_OFFSET_VALUE_MASK)

This macro is still useful. See above. I think you should just update the mask and continue using it for clarity.

Regards,
Felix

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
-
  /*
   * When working with cp scheduler we should assign the HIQ manually or via
   * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ hqd slot
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
index 6abfb77ae540..39dc49b8fd85 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep) · line 560

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -2
@@ -554,8 +554,7 @@ static int kfd_process_init_cwsr_apu(struct kfd_process *p, struct file *filep)
               if (!dev->cwsr_enabled || qpd->cwsr_kaddr || qpd->cwsr_base)
                       continue;
 
-             offset = (KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id))
-                     << PAGE_SHIFT;
+             offset = KFD_MMAP_TYPE_RESERVED_MEM | KFD_MMAP_GPU_ID(dev->id);
               qpd->tba_addr = (int64_t)vm_mmap(filep, 0,
                       KFD_CWSR_TBA_TMA_SIZE, PROT_READ | PROT_EXEC,
                       MAP_SHARED, offset);

_______________________________________________
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): DM6PR12MB27789FF639D6516AAB7E6099F0620-lmeGfMZKVrFSet88YzIdmgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

Acked-by Oded Gabbay
#9 lore raw
Quoted 10 lines · Yong
Quoted 3 lines

+     /* only leave the offset segment */
+     vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - PAGE_SHIFT)) - 1;

You're now open-coding what used to be done by the KFD_MMAP_OFFSET_VALUE_GET macro. I don't see how this is an improvement.
Maybe better to update the macro to do this.

Quoted 3 lines

I can definitely do that, but I think we'd better delete this line completely as it seems odd to change vm_pgoff. Moreover this vm_pgoff is not used at all in the following function calls. What do you think?

I think you're right. Looks like a historical accident. I see that older versions of kfd_event_mmap used to access vm_pgoff and probably depended on this. We removed that in this commit:

commit 50cb7dd94cb43a6204813376e1be1d21780b71fb
Author: Felix Kuehling <[email protected]>
Date:   Fri Oct 27 19:35:26 2017 -0400

    drm/amdkfd: Simplify events page allocator

    The first event page is always big enough to handle all events. Handling of multiple events pages is not supported by user mode, and not necessary.

Regards,
  Felix

Quoted 143 lines

Regards,
Yong
------------------------------------------------------------------------
*From:* Kuehling, Felix <[email protected]>
*Sent:* Friday, November 1, 2019 6:48 PM
*To:* Zhao, Yong <[email protected]>; [email protected] <[email protected]>
*Subject:* Re: [PATCH] drm/amdkfd: Simplify the mmap offset related bit operations

Quoted 4 lines · Yong

The new code is much cleaner and results in better readability.

Change-Id I0c1f7cca7e24ddb7b4ffe1cb0fa71943828ae373

Review

Quoted 8 lines

---
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 13 +++++++------ drivers/gpu/drm/amd/amdkfd/kfd_events.c  |  1 - drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 +++------ drivers/gpu/drm/amd/amdkfd/kfd_process.c |  3 +--

   4 files changed, 11 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_create_queue(struct file

Quoted 4 lines

index b91993753b82..590138727ca9 100644

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
@@ -298,7 +298,6 @@ static int kfd_ioctl_create_queue(struct file 

*filep, struct kfd_process *p,

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p,

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -1
         /* Return gpu_id as doorbell offset for mmap usage */
         args->doorbell_offset = KFD_MMAP_TYPE_DOORBELL;
         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, include the doorbell offset within the
                  * process doorbell frame, which could be 1 page or 2 

pages.

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_mmap(struct file *filp,

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
@@ -1938,20 +1937,22 @@ static int kfd_mmap(struct file *filp, 

struct vm_area_struct *vma)

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -2
    {
         struct kfd_process *process;
         struct kfd_dev *dev = NULL;
-     unsigned long vm_pgoff;
+     unsigned long mmap_offset;
         unsigned int gpu_id;
 
         process = kfd_get_process(current);
         if (IS_ERR(process))
                 return PTR_ERR(process);
 
-     vm_pgoff = vma->vm_pgoff;

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4 -3
-     vma->vm_pgoff = KFD_MMAP_OFFSET_VALUE_GET(vm_pgoff);
-     gpu_id = KFD_MMAP_GPU_ID_GET(vm_pgoff);
+     mmap_offset = vma->vm_pgoff << PAGE_SHIFT;
+     gpu_id = KFD_MMAP_GET_GPU_ID(mmap_offset);
         if (gpu_id)
                 dev = kfd_device_by_id(gpu_id);
 
-     switch (vm_pgoff & KFD_MMAP_TYPE_MASK) {
+     /* only leave the offset segment */
+     vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - 

PAGE_SHIFT)) - 1;

You're now open-coding what used to be done by the KFD_MMAP_OFFSET_VALUE_GET macro. I don't see how this is an improvement. Maybe better to update the macro to do this.

Review

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
+
+     switch (mmap_offset & KFD_MMAP_TYPE_MASK) {

        case KFD_MMAP_TYPE_DOORBELL:
                if (!dev)
                        return -ENODEV;

(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

drivers/gpu/drm/amd/amdkfd/kfd_events.c int kfd_event_create(struct file *devkfd, struct

Quoted 4 lines

index 908081c85de1..1f8365575b12 100644

drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
@@ -346,7 +346,6 @@ int kfd_event_create(struct file *devkfd, struct 

kfd_process *p,

Review

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -1
                 ret = create_signal_event(devkfd, p, ev);
                 if (!ret) {
                         *event_page_offset = KFD_MMAP_TYPE_EVENTS;
-                     *event_page_offset <<= PAGE_SHIFT;
                         *event_slot_index = ev->event_id;
                 }
                 break;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 59

Quoted 5 lines

index 66bae8f2dad1..8eecd2cd1fd2 100644

drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
@@ -59,24 +59,21 @@
     * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages. 

Hence, these

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
     *  defines are w.r.t to PAGE_SIZE
     */
-#define KFD_MMAP_TYPE_SHIFT  (62 - PAGE_SHIFT)
+#define KFD_MMAP_TYPE_SHIFT  (62)
    #define KFD_MMAP_TYPE_MASK  (0x3ULL << KFD_MMAP_TYPE_SHIFT)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
    #define KFD_MMAP_TYPE_DOORBELL      (0x3ULL << KFD_MMAP_TYPE_SHIFT)
    #define KFD_MMAP_TYPE_EVENTS        (0x2ULL << KFD_MMAP_TYPE_SHIFT)
    #define KFD_MMAP_TYPE_RESERVED_MEM  (0x1ULL << KFD_MMAP_TYPE_SHIFT)
    #define KFD_MMAP_TYPE_MMIO  (0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
-#define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
+#define KFD_MMAP_GPU_ID_SHIFT (46)
    #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
                                 << KFD_MMAP_GPU_ID_SHIFT)
    #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) << 

KFD_MMAP_GPU_ID_SHIFT)\

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 74

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
                                 & KFD_MMAP_GPU_ID_MASK)
-#define KFD_MMAP_GPU_ID_GET(offset)    ((offset & 

KFD_MMAP_GPU_ID_MASK) \

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 74

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
+#define KFD_MMAP_GET_GPU_ID(offset)    ((offset & 

KFD_MMAP_GPU_ID_MASK) \

drivers/gpu/drm/amd/amdkfd/kfd_priv.h

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -2
                                 >> KFD_MMAP_GPU_ID_SHIFT)
 
-#define KFD_MMAP_OFFSET_VALUE_MASK (0x3FFFFFFFFFFFULL >> PAGE_SHIFT)
-#define KFD_MMAP_OFFSET_VALUE_GET(offset) (offset & 

KFD_MMAP_OFFSET_VALUE_MASK)

This macro is still useful. See above. I think you should just update the mask and continue using it for clarity.

Regards,
   Felix

drivers/gpu/drm/amd/amdkfd/kfd_priv.h

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
-
    /*
     * When working with cp scheduler we should assign the HIQ 

manually or via

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 79

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
     * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ 

hqd slot

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_process.c

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct

Quoted 4 lines

index 6abfb77ae540..39dc49b8fd85 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -554,8 +554,7 @@ static int kfd_process_init_cwsr_apu(struct 

kfd_process *p, struct file *filep)

Quoted 1 line

                if (!dev->cwsr_enabled || qpd->cwsr_kaddr ||

Quoted 11 lines

qpd->cwsr_base)

Quoted 3 lines

                        continue;

-             offset = (KFD_MMAP_TYPE_RESERVED_MEM |

KFD_MMAP_GPU_ID(dev->id))

Quoted 2 lines

-                     << PAGE_SHIFT;
+             offset = KFD_MMAP_TYPE_RESERVED_MEM |

KFD_MMAP_GPU_ID(dev->id);

Quoted 3 lines

                qpd->tba_addr = (int64_t)vm_mmap(filep, 0, KFD_CWSR_TBA_TMA_SIZE, PROT_READ | PROT_EXEC, MAP_SHARED, offset);

_______________________________________________
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): f066444f-a621-f6d4-0c85-2071bf528b2e-5C7GfCeVMHo@public.gmane.org

author Acked-by Oded Gabbay
#11 lore raw

Okay. I will delete that line.

Regards,
Yong
________________________________
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, November 5, 2019 5:34 PM
To: Zhao, Yong <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: Simplify the mmap offset related bit operations

Quoted 10 lines · Yong

Review

Quoted 3 lines
(quoted diff) +2 -0
+     /* only leave the offset segment */
+     vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT - PAGE_SHIFT)) - 1;

You're now open-coding what used to be done by the KFD_MMAP_OFFSET_VALUE_GET macro. I don't see how this is an improvement.
Maybe better to update the macro to do this.

Quoted 3 lines

I can definitely do that, but I think we'd better delete this line completely as it seems odd to change vm_pgoff. Moreover this vm_pgoff is not used at all in the following function calls. What do you think?

I think you're right. Looks like a historical accident. I see that older versions of kfd_event_mmap used to access vm_pgoff and probably depended on this. We removed that in this commit:

commit 50cb7dd94cb43a6204813376e1be1d21780b71fb

Author: Felix Kuehling <[email protected]>
Date:   Fri Oct 27 19:35:26 2017 -0400

drm/amdkfd: Simplify events page allocator

The first event page is always big enough to handle all events. Handling of multiple events pages is not supported by user mode, and not necessary.

Regards,
Felix

Quoted 143 lines

Regards,
Yong
------------------------------------------------------------------------
*From:* Kuehling, Felix <[email protected]>
*Sent:* Friday, November 1, 2019 6:48 PM
*To:* Zhao, Yong <[email protected]>; [email protected] <[email protected]>
*Subject:* Re: [PATCH] drm/amdkfd: Simplify the mmap offset related
bit operations

Quoted 4 lines · Yong

The new code is much cleaner and results in better readability.

Change-Id I0c1f7cca7e24ddb7b4ffe1cb0fa71943828ae373

Review

Quoted 8 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 13 +++++++------
  drivers/gpu/drm/amd/amdkfd/kfd_events.c  |  1 -
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  9 +++------
  drivers/gpu/drm/amd/amdkfd/kfd_process.c |  3 +--
  4 files changed, 11 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_create_queue(struct file

Quoted 4 lines

index b91993753b82..590138727ca9 100644

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
@@ -298,7 +298,6 @@ static int kfd_ioctl_create_queue(struct file

*filep, struct kfd_process *p,

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_create_queue(struct file · line 303

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -1
       /* Return gpu_id as doorbell offset for mmap usage */
       args->doorbell_offset = KFD_MMAP_TYPE_DOORBELL;
       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, include the doorbell offset within the
                * process doorbell frame, which could be 1 page or 2

pages.

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_mmap(struct file *filp,

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
@@ -1938,20 +1937,22 @@ static int kfd_mmap(struct file *filp,

struct vm_area_struct *vma)

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -2
  {
       struct kfd_process *process;
       struct kfd_dev *dev = NULL;
-     unsigned long vm_pgoff;
+     unsigned long mmap_offset;
       unsigned int gpu_id;
 
       process = kfd_get_process(current);
       if (IS_ERR(process))
               return PTR_ERR(process);
 
-     vm_pgoff = vma->vm_pgoff;

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_mmap(struct file *filp, · line 1953

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4 -3
-     vma->vm_pgoff = KFD_MMAP_OFFSET_VALUE_GET(vm_pgoff);
-     gpu_id = KFD_MMAP_GPU_ID_GET(vm_pgoff);
+     mmap_offset = vma->vm_pgoff << PAGE_SHIFT;
+     gpu_id = KFD_MMAP_GET_GPU_ID(mmap_offset);
       if (gpu_id)
               dev = kfd_device_by_id(gpu_id);
 
-     switch (vm_pgoff & KFD_MMAP_TYPE_MASK) {
+     /* only leave the offset segment */
+     vma->vm_pgoff &= (1ULL << (KFD_MMAP_GPU_ID_SHIFT -

PAGE_SHIFT)) - 1;

You're now open-coding what used to be done by the KFD_MMAP_OFFSET_VALUE_GET macro. I don't see how this is an improvement. Maybe better to update the macro to do this.

Review

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -0
+
+     switch (mmap_offset & KFD_MMAP_TYPE_MASK) {
       case KFD_MMAP_TYPE_DOORBELL:
               if (!dev)
                       return -ENODEV;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_events.c

drivers/gpu/drm/amd/amdkfd/kfd_events.c int kfd_event_create(struct file *devkfd, struct

Quoted 4 lines

index 908081c85de1..1f8365575b12 100644

drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -0
@@ -346,7 +346,6 @@ int kfd_event_create(struct file *devkfd, struct

kfd_process *p,

Review

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +0 -1
               ret = create_signal_event(devkfd, p, ev);
               if (!ret) {
                       *event_page_offset = KFD_MMAP_TYPE_EVENTS;
-                     *event_page_offset <<= PAGE_SHIFT;
                       *event_slot_index = ev->event_id;
               }
               break;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 59

Quoted 5 lines

index 66bae8f2dad1..8eecd2cd1fd2 100644

drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
@@ -59,24 +59,21 @@
   * NOTE: struct vm_area_struct.vm_pgoff uses offset in pages.

Hence, these

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
   *  defines are w.r.t to PAGE_SIZE
   */
-#define KFD_MMAP_TYPE_SHIFT  (62 - PAGE_SHIFT)
+#define KFD_MMAP_TYPE_SHIFT  (62)
  #define KFD_MMAP_TYPE_MASK  (0x3ULL << KFD_MMAP_TYPE_SHIFT)

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 72

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
  #define KFD_MMAP_TYPE_DOORBELL      (0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_EVENTS        (0x2ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_RESERVED_MEM  (0x1ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_MMIO  (0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
-#define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
+#define KFD_MMAP_GPU_ID_SHIFT (46)
  #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
                               << KFD_MMAP_GPU_ID_SHIFT)
  #define KFD_MMAP_GPU_ID(gpu_id) ((((uint64_t)gpu_id) <<

KFD_MMAP_GPU_ID_SHIFT)\

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 74

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
                               & KFD_MMAP_GPU_ID_MASK)
-#define KFD_MMAP_GPU_ID_GET(offset)    ((offset &

KFD_MMAP_GPU_ID_MASK) \

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 74

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
+#define KFD_MMAP_GET_GPU_ID(offset)    ((offset &

KFD_MMAP_GPU_ID_MASK) \

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 78

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -2
                               >> KFD_MMAP_GPU_ID_SHIFT)
 
-#define KFD_MMAP_OFFSET_VALUE_MASK (0x3FFFFFFFFFFFULL >> PAGE_SHIFT)
-#define KFD_MMAP_OFFSET_VALUE_GET(offset) (offset &

KFD_MMAP_OFFSET_VALUE_MASK)

This macro is still useful. See above. I think you should just update the mask and continue using it for clarity.

Regards,
Felix

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 78

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -1
-
  /*
   * When working with cp scheduler we should assign the HIQ

manually or via

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 79

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
   * the amdgpu driver to a fixed hqd slot, here are the fixed HIQ

hqd slot

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_process.c

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct

Quoted 4 lines

index 6abfb77ae540..39dc49b8fd85 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -554,8 +554,7 @@ static int kfd_process_init_cwsr_apu(struct

kfd_process *p, struct file *filep)

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct · line 554

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
               if (!dev->cwsr_enabled || qpd->cwsr_kaddr ||
Quoted 11 lines

qpd->cwsr_base)

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct · line 557

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -1
                       continue;
 
-             offset = (KFD_MMAP_TYPE_RESERVED_MEM |

KFD_MMAP_GPU_ID(dev->id))

drivers/gpu/drm/amd/amdkfd/kfd_process.c static int kfd_process_init_cwsr_apu(struct · line 557

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
-                     << PAGE_SHIFT;
+             offset = KFD_MMAP_TYPE_RESERVED_MEM |

KFD_MMAP_GPU_ID(dev->id);

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
               qpd->tba_addr = (int64_t)vm_mmap(filep, 0,
                       KFD_CWSR_TBA_TMA_SIZE, PROT_READ | PROT_EXEC,
                       MAP_SHARED, offset);

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