Skip to contentSkip to conversation

drm/amdgpu: fix VA hole handling on Vega10 v2

PATCH In review Christian König 3 participants 12 messages Nov 16, 2017 – Nov 22, 2017 9 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/amdgpu: fix VA hole handling on Vega10 v2

Similar to the CPU address space the VA on Vega10 has a hole in it.

v2: use dev_dbg instead of dev_err

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 10 +++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 11 +++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  4 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  5 +++++
 4 files changed, 24 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -5
index ee7736419411..fea4429d3f72 100644
@@ -869,8 +869,8 @@ static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
 			struct amdgpu_bo_va_mapping *m;
 			struct amdgpu_bo *aobj = NULL;
 			struct amdgpu_cs_chunk *chunk;
+			uint64_t offset, va_start;
 			struct amdgpu_ib *ib;
-			uint64_t offset;
 			uint8_t *kptr;
 
 			chunk = &p->chunks[i];
@@ -880,14 +880,14 @@ static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
 			if (chunk->chunk_id != AMDGPU_CHUNK_ID_IB)
 				continue;
 
-			r = amdgpu_cs_find_mapping(p, chunk_ib->va_start,
-						   &aobj, &m);
+			va_start = chunk_ib->va_start & AMDGPU_VA_HOLE_MASK;
+			r = amdgpu_cs_find_mapping(p, va_start, &aobj, &m);
 			if (r) {
 				DRM_ERROR("IB va_start is invalid\n");
 				return r;
 			}
 
-			if ((chunk_ib->va_start + chunk_ib->ib_bytes) >
+			if ((va_start + chunk_ib->ib_bytes) >
 			    (m->last + 1) * AMDGPU_GPU_PAGE_SIZE) {
 				DRM_ERROR("IB va_start+ib_bytes is invalid\n");
 				return -EINVAL;
@@ -900,7 +900,7 @@ static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
 			}
 
 			offset = m->start * AMDGPU_GPU_PAGE_SIZE;
-			kptr += chunk_ib->va_start - offset;
+			kptr += va_start - offset;
 
 			memcpy(ib->ptr, kptr, chunk_ib->ib_bytes);
 			amdgpu_bo_kunmap(aobj);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +11 -0
index 04ddd782bf6d..432ec2924dc5 100644
@@ -566,6 +566,17 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 		return -EINVAL;
 	}
 
+	if (args->va_address >= AMDGPU_VA_HOLE_START &&
+	    args->va_address < AMDGPU_VA_HOLE_END) {
+		dev_dbg(&dev->pdev->dev,
+			"va_address 0x%LX is in VA hole 0x%LX-0x%LX\n",
+			args->va_address, AMDGPU_VA_HOLE_START,
+			AMDGPU_VA_HOLE_END);
+		return -EINVAL;
+	}
+
+	args->va_address &= AMDGPU_VA_HOLE_MASK;
+
 	if ((args->flags & ~valid_flags) && (args->flags & ~prt_flags)) {
 		dev_err(&dev->pdev->dev, "invalid flags combination 0x%08X\n",
 			args->flags);
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -1
index 65360cde5342..e84a7f7f642e 100644
@@ -578,7 +578,9 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 		if (amdgpu_sriov_vf(adev))
 			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
 		dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
-		dev_info.virtual_address_max = (uint64_t)adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+		dev_info.virtual_address_max =
+			min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,
+			    AMDGPU_VA_HOLE_START);
 		dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
 		dev_info.pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
 		dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5 -0
index e8f8896d18db..31cd57592546 100644
@@ -96,6 +96,11 @@ struct amdgpu_bo_list_entry;
 /* hardcode that limit for now */
 #define AMDGPU_VA_RESERVED_SIZE			(8ULL << 20)
 
+/* VA hole for 48bit addresses on Vega10 */
+#define AMDGPU_VA_HOLE_START			0x0000800000000000ULL
+#define AMDGPU_VA_HOLE_END			0xffff800000000000ULL
+#define AMDGPU_VA_HOLE_MASK			0x0000ffffffffffffULL
+
 /* max vmids dedicated for process */
 #define AMDGPU_VM_MAX_RESERVED_VMID	1
 
Signature · 6 lines
2.11.0

_______________________________________________
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): 20171116102252.10173-1-christian.koenig-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/3 drm/amdgpu: use dev_dbg instead of dev_err in the VA IOCTL

Userspace buggy userspace can spam the logs.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -3
index 432ec2924dc5..a8dc7b95f29a 100644
@@ -560,7 +560,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 	int r = 0;
 
 	if (args->va_address < AMDGPU_VA_RESERVED_SIZE) {
-		dev_err(&dev->pdev->dev,
+		dev_dbg(&dev->pdev->dev,
 			"va_address 0x%LX is in reserved area 0x%LX\n",
 			args->va_address, AMDGPU_VA_RESERVED_SIZE);
 		return -EINVAL;
@@ -578,7 +578,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 	args->va_address &= AMDGPU_VA_HOLE_MASK;
 
 	if ((args->flags & ~valid_flags) && (args->flags & ~prt_flags)) {
-		dev_err(&dev->pdev->dev, "invalid flags combination 0x%08X\n",
+		dev_dbg(&dev->pdev->dev, "invalid flags combination 0x%08X\n",
 			args->flags);
 		return -EINVAL;
 	}
@@ -590,7 +590,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 	case AMDGPU_VA_OP_REPLACE:
 		break;
 	default:
-		dev_err(&dev->pdev->dev, "unsupported operation %d\n",
+		dev_dbg(&dev->pdev->dev, "unsupported operation %d\n",
 			args->operation);
 		return -EINVAL;
 	}
Signature · 6 lines
2.11.0

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

PATCH 3/3 drm/amdgpu: expose the VA above the hole to userspace

In reply to a message not in the archive

Let userspace know how much area we have above the 48bit VA hole on Vega10.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 12 ++++++++++--
 include/uapi/drm/amdgpu_drm.h           |  4 ++++
 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -2
index e84a7f7f642e..9875d64ae7d5 100644
@@ -550,6 +550,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 	}
 	case AMDGPU_INFO_DEV_INFO: {
 		struct drm_amdgpu_info_device dev_info = {};
+		uint64_t vm_size;
 
 		dev_info.device_id = dev->pdev->device;
 		dev_info.chip_rev = adev->rev_id;
@@ -577,10 +578,17 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
 		if (amdgpu_sriov_vf(adev))
 			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+
+		vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
 		dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
 		dev_info.virtual_address_max =
-			min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,
-			    AMDGPU_VA_HOLE_START);
+			min(vm_size, AMDGPU_VA_HOLE_START);
+
+		vm_size -= AMDGPU_VA_RESERVED_SIZE;
+		if (vm_size > AMDGPU_VA_HOLE_START) {
+			dev_info.high_va_offset = AMDGPU_VA_HOLE_END;
+			dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;
+		}
 		dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
 		dev_info.pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
 		dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE;
include/uapi/drm/amdgpu_drm.h +4 -0
index f7a4cf1b6ef6..1dc8089b480a 100644
@@ -880,6 +880,10 @@ struct drm_amdgpu_info_device {
 	__u32 _pad1;
 	/* always on cu bitmap */
 	__u32 cu_ao_bitmap[4][4];
+	/** Starting high virtual address for UMDs. */
+	__u64 high_va_offset;
+	/** The maximum high virtual address */
+	__u64 high_va_max;
 };
 
 struct drm_amdgpu_info_hw_ip {
Signature · 6 lines
2.11.0

_______________________________________________
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): 20171116102252.10173-3-christian.koenig-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#5 lore raw

Re: [PATCH 3/3] drm/amdgpu: expose the VA above the hole to userspace

Quoted 4 lines · Christian König

Let userspace know how much area we have above the 48bit VA hole on Vega10.

Please add a patch to bump the driver version as well. With that, this series is:

Quoted 55 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 12 ++++++++++--
 include/uapi/drm/amdgpu_drm.h           |  4 ++++
 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -2
index e84a7f7f642e..9875d64ae7d5 100644
@@ -550,6 +550,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
        }
        case AMDGPU_INFO_DEV_INFO: {
                struct drm_amdgpu_info_device dev_info = {};
+               uint64_t vm_size;
 
                dev_info.device_id = dev->pdev->device;
                dev_info.chip_rev = adev->rev_id;
@@ -577,10 +578,17 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
                        dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
                if (amdgpu_sriov_vf(adev))
                        dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+
+               vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
                dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
                dev_info.virtual_address_max =
-                       min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,
-                           AMDGPU_VA_HOLE_START);
+                       min(vm_size, AMDGPU_VA_HOLE_START);
+
+               vm_size -= AMDGPU_VA_RESERVED_SIZE;
+               if (vm_size > AMDGPU_VA_HOLE_START) {
+                       dev_info.high_va_offset = AMDGPU_VA_HOLE_END;
+                       dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;
+               }
                dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
                dev_info.pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
                dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE;
include/uapi/drm/amdgpu_drm.h +4 -1
index f7a4cf1b6ef6..1dc8089b480a 100644
@@ -880,6 +880,10 @@ struct drm_amdgpu_info_device {
        __u32 _pad1;
        /* always on cu bitmap */
        __u32 cu_ao_bitmap[4][4];
+       /** Starting high virtual address for UMDs. */
+       __u64 high_va_offset;
+       /** The maximum high virtual address */
+       __u64 high_va_max;
 };
 
 struct drm_amdgpu_info_hw_ip {
--

2.11.0

Quoted 4 lines

_______________________________________________
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): CADnq5_N-nw1ZUZ5pRq0wy5qTcPtKe8DmE_pM83No0+dC4qh=uQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#7 lore raw

Re: [PATCH 3/3] drm/amdgpu: expose the VA above the hole to userspace

Am 17.11.2017 um 17:11 schrieb Alex Deucher:

Quoted 7 lines
Quoted 4 lines · Christian König

Let userspace know how much area we have above the 48bit VA hole on Vega10.

Please add a patch to bump the driver version as well.

I could add one, but actually we don't need one cause the new fields are simply zero initialized by userspace when requestion the device info.

I'm actually considering add a CC stable tag to at least  the first patch, cause when a client actually would try to use this it could confuse the hardware badly.

Christian.

Quoted 55 lines

With that,
this series is:

Quoted 51 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 12 ++++++++++--
  include/uapi/drm/amdgpu_drm.h           |  4 ++++
  2 files changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -2
index e84a7f7f642e..9875d64ae7d5 100644
@@ -550,6 +550,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
         }
         case AMDGPU_INFO_DEV_INFO: {
                 struct drm_amdgpu_info_device dev_info = {};
+               uint64_t vm_size;
 
                 dev_info.device_id = dev->pdev->device;
                 dev_info.chip_rev = adev->rev_id;
@@ -577,10 +578,17 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
                         dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
                 if (amdgpu_sriov_vf(adev))
                         dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+
+               vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
                 dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
                 dev_info.virtual_address_max =
-                       min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,
-                           AMDGPU_VA_HOLE_START);
+                       min(vm_size, AMDGPU_VA_HOLE_START);
+
+               vm_size -= AMDGPU_VA_RESERVED_SIZE;
+               if (vm_size > AMDGPU_VA_HOLE_START) {
+                       dev_info.high_va_offset = AMDGPU_VA_HOLE_END;
+                       dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;
+               }
                 dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
                 dev_info.pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
                 dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE;
include/uapi/drm/amdgpu_drm.h +4 -0
index f7a4cf1b6ef6..1dc8089b480a 100644
@@ -880,6 +880,10 @@ struct drm_amdgpu_info_device {
         __u32 _pad1;
         /* always on cu bitmap */
         __u32 cu_ao_bitmap[4][4];
+       /** Starting high virtual address for UMDs. */
+       __u64 high_va_offset;
+       /** The maximum high virtual address */
+       __u64 high_va_max;
  };
 
Quoted 8 lines
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +0 -1
  struct drm_amdgpu_info_hw_ip {
--

2.11.0

_______________________________________________
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

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

Ping? Michel, Alex can somebody take a look?

Thanks,
Christian.

Am 16.11.2017 um 11:22 schrieb Christian König:

Quoted 96 lines

Similar to the CPU address space the VA on Vega10 has a hole in it.

v2: use dev_dbg instead of dev_err

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 10 +++++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 11 +++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  4 +++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  5 +++++
  4 files changed, 24 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -5
index ee7736419411..fea4429d3f72 100644
@@ -869,8 +869,8 @@ static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
  			struct amdgpu_bo_va_mapping *m;
  			struct amdgpu_bo *aobj = NULL;
  			struct amdgpu_cs_chunk *chunk;
+			uint64_t offset, va_start;
  			struct amdgpu_ib *ib;
-			uint64_t offset;
  			uint8_t *kptr;
 
  			chunk = &p->chunks[i];
@@ -880,14 +880,14 @@ static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
  			if (chunk->chunk_id != AMDGPU_CHUNK_ID_IB)
  				continue;
 
-			r = amdgpu_cs_find_mapping(p, chunk_ib->va_start,
-						   &aobj, &m);
+			va_start = chunk_ib->va_start & AMDGPU_VA_HOLE_MASK;
+			r = amdgpu_cs_find_mapping(p, va_start, &aobj, &m);
  			if (r) {
  				DRM_ERROR("IB va_start is invalid\n");
  				return r;
  			}
 
-			if ((chunk_ib->va_start + chunk_ib->ib_bytes) >
+			if ((va_start + chunk_ib->ib_bytes) >
  			    (m->last + 1) * AMDGPU_GPU_PAGE_SIZE) {
  				DRM_ERROR("IB va_start+ib_bytes is invalid\n");
  				return -EINVAL;
@@ -900,7 +900,7 @@ static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
  			}
 
  			offset = m->start * AMDGPU_GPU_PAGE_SIZE;
-			kptr += chunk_ib->va_start - offset;
+			kptr += va_start - offset;
 
  			memcpy(ib->ptr, kptr, chunk_ib->ib_bytes);
  			amdgpu_bo_kunmap(aobj);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +11 -0
index 04ddd782bf6d..432ec2924dc5 100644
@@ -566,6 +566,17 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
  		return -EINVAL;
  	}
 
+	if (args->va_address >= AMDGPU_VA_HOLE_START &&
+	    args->va_address < AMDGPU_VA_HOLE_END) {
+		dev_dbg(&dev->pdev->dev,
+			"va_address 0x%LX is in VA hole 0x%LX-0x%LX\n",
+			args->va_address, AMDGPU_VA_HOLE_START,
+			AMDGPU_VA_HOLE_END);
+		return -EINVAL;
+	}
+
+	args->va_address &= AMDGPU_VA_HOLE_MASK;
+
  	if ((args->flags & ~valid_flags) && (args->flags & ~prt_flags)) {
  		dev_err(&dev->pdev->dev, "invalid flags combination 0x%08X\n",
  			args->flags);
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -1
index 65360cde5342..e84a7f7f642e 100644
@@ -578,7 +578,9 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
  		if (amdgpu_sriov_vf(adev))
  			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
  		dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
-		dev_info.virtual_address_max = (uint64_t)adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+		dev_info.virtual_address_max =
+			min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,
+			    AMDGPU_VA_HOLE_START);
  		dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
  		dev_info.pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE;
  		dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index e8f8896d18db..31cd57592546 100644
@@ -96,6 +96,11 @@ struct amdgpu_bo_list_entry;
  /* hardcode that limit for now */

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_bo_list_entry; · line 106

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5 -0
  #define AMDGPU_VA_RESERVED_SIZE			(8ULL << 20)
 
+/* VA hole for 48bit addresses on Vega10 */
+#define AMDGPU_VA_HOLE_START			0x0000800000000000ULL
+#define AMDGPU_VA_HOLE_END			0xffff800000000000ULL
+#define AMDGPU_VA_HOLE_MASK			0x0000ffffffffffffULL
+
  /* max vmids dedicated for process */
  #define AMDGPU_VM_MAX_RESERVED_VMID	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): d995f9a6-f76a-aa7c-4b61-fe848bfb549a-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

Reviewed-by
#10 lore raw
Quoted 1 line · Christian König

Ping? Michel, Alex can somebody take a look?

Patch 2 is

With patches 1 & 3, it's not 100% clear to me what the idea is behind the handling of the hole on the kernel and userspace side. Maybe you can add some explanation in code comments or the commit logs?

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
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): d5aafe10-1b90-ceeb-db50-99afb412eccb-otUistvHUpPR7s880joybQ@public.gmane.org

#12 lore raw

Am 17.11.2017 um 17:09 schrieb Michel Dänzer:

Quoted 10 lines · Christian König
Quoted 1 line

Ping? Michel, Alex can somebody take a look?

Patch 2 is

With patches 1 & 3, it's not 100% clear to me what the idea is behind the handling of the hole on the kernel and userspace side. Maybe you can add some explanation in code comments or the commit logs?

Yeah, that is actually a bit of a mess because the hardware documentation wasn't very clear on how this works.

How about this as extra code comment on patch 1 to the assignment of dev_info.virtual_address_max:

/*
 * Old userspace isn't aware of the VA hole on Vega10. So in theory an client could get invalid VA addresses assigned.
 * To fix this and keep backward compatibility we limit the VA space reported in this field to the range below the hole. */

The last patch is then to report the VA space above the hole, cause that is actually what libdrm should use.

The crux is when I put the VA space above the hole directly into the old fields older versions of libdrm would break and we can't do that.

Regards,
Christian.
_______________________________________________
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): 17f339f2-20fa-1aba-8ddb-86ce320fd3ce-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#14 lore raw
Quoted 24 lines · Christian König

Am 17.11.2017 um 17:09 schrieb Michel Dänzer:

Quoted 10 lines · Christian König
Quoted 1 line

Ping? Michel, Alex can somebody take a look?

Patch 2 is

With patches 1 & 3, it's not 100% clear to me what the idea is behind the handling of the hole on the kernel and userspace side. Maybe you can add some explanation in code comments or the commit logs?

Yeah, that is actually a bit of a mess because the hardware documentation wasn't very clear on how this works.

How about this as extra code comment on patch 1 to the assignment of dev_info.virtual_address_max:

/*
 * Old userspace isn't aware of the VA hole on Vega10. So in theory an client could get invalid VA addresses assigned.
 * To fix this and keep backward compatibility we limit the VA space reported in this field to the range below the hole.
 */

Quoted 5 lines

The last patch is then to report the VA space above the hole, cause that is actually what libdrm should use.

The crux is when I put the VA space above the hole directly into the old fields older versions of libdrm would break and we can't do that.

That much was actually clear. :) Maybe some questions will expose what I'm missing:

Patch 1:

Review static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev, · line 884

Quoted 8 lines
(quoted diff) +2 -2
@@ -880,14 +880,14 @@  static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
 			if (chunk->chunk_id != AMDGPU_CHUNK_ID_IB)
 				continue;
 
-			r = amdgpu_cs_find_mapping(p, chunk_ib->va_start,
-						   &aobj, &m);
+			va_start = chunk_ib->va_start & AMDGPU_VA_HOLE_MASK;
+			r = amdgpu_cs_find_mapping(p, va_start, &aobj, &m);

I don't understand how userspace can make use of the address space above the hole, since AMDGPU_VA_HOLE_MASK is 0x0000ffffffffffffULL and AMDGPU_VA_HOLE_END is 0xffff800000000000ULL, so masking with AMDGPU_VA_HOLE_MASK always results in an address below or inside the hole?

Quoted 4 lines
(quoted diff) +0 -0
@@ -566,6 +566,17 @@  int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 		return -EINVAL;
 	}
 

Review int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 578

Quoted 10 lines
(quoted diff) +10 -0
+	if (args->va_address >= AMDGPU_VA_HOLE_START &&
+	    args->va_address < AMDGPU_VA_HOLE_END) {
+		dev_dbg(&dev->pdev->dev,
+			"va_address 0x%LX is in VA hole 0x%LX-0x%LX\n",
+			args->va_address, AMDGPU_VA_HOLE_START,
+			AMDGPU_VA_HOLE_END);
+		return -EINVAL;
+	}
+
+	args->va_address &= AMDGPU_VA_HOLE_MASK;

Ignoring the above, I think the masking with AMDGPU_VA_HOLE_MASK would need to be done before checking for the hole, otherwise the masked address could be inside the hole?

Patch 3:

Quoted 7 lines
(quoted diff) +2 -0
@@ -577,10 +578,17 @@  static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
 		if (amdgpu_sriov_vf(adev))
 			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+
+		vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
 		dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;

Review static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file · line 591

Quoted 10 lines
(quoted diff) +7 -2
 		dev_info.virtual_address_max =
-			min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,
-			    AMDGPU_VA_HOLE_START);
+			min(vm_size, AMDGPU_VA_HOLE_START);
+
+		vm_size -= AMDGPU_VA_RESERVED_SIZE;
+		if (vm_size > AMDGPU_VA_HOLE_START) {
+			dev_info.high_va_offset = AMDGPU_VA_HOLE_END;
+			dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;
+		}

This mostly makes sense, except for the

		dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;

line. Can you explain how simply or'ing together the address of the end of the hole and the VM size works correctly in all cases?

As an extreme example, with vm_size == 1, this value would compute as 0xffff800000000001ULL, which seems wrong or at least weird.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
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): fe723f59-fd9a-a13c-e7b6-8da13bfa34fb-otUistvHUpPR7s880joybQ@public.gmane.org

#16 lore raw

Am 20.11.2017 um 11:36 schrieb Michel Dänzer:

Quoted 40 lines · Christian König
Quoted 24 lines

Am 17.11.2017 um 17:09 schrieb Michel Dänzer:

Quoted 10 lines · Christian König
Quoted 1 line

Ping? Michel, Alex can somebody take a look?

Patch 2 is

With patches 1 & 3, it's not 100% clear to me what the idea is behind the handling of the hole on the kernel and userspace side. Maybe you can add some explanation in code comments or the commit logs?

Yeah, that is actually a bit of a mess because the hardware documentation wasn't very clear on how this works.

How about this as extra code comment on patch 1 to the assignment of dev_info.virtual_address_max:

/*
 * Old userspace isn't aware of the VA hole on Vega10. So in theory an
client could get invalid VA addresses assigned.
 * To fix this and keep backward compatibility we limit the VA space
reported in this field to the range below the hole.
 */

Quoted 5 lines

The last patch is then to report the VA space above the hole, cause that is actually what libdrm should use.

The crux is when I put the VA space above the hole directly into the old fields older versions of libdrm would break and we can't do that.

That much was actually clear. :) Maybe some questions will expose what I'm missing:

Patch 1:

Quoted 4 lines
(quoted diff) +0 -0
@@ -880,14 +880,14 @@  static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev,
  			if (chunk->chunk_id != AMDGPU_CHUNK_ID_IB)
  				continue;
 
Quoted 8 lines

Review static int amdgpu_cs_ib_vm_chunk(struct amdgpu_device *adev, · line 884

Quoted 4 lines
(quoted diff) +2 -2
-			r = amdgpu_cs_find_mapping(p, chunk_ib->va_start,
-						   &aobj, &m);
+			va_start = chunk_ib->va_start & AMDGPU_VA_HOLE_MASK;
+			r = amdgpu_cs_find_mapping(p, va_start, &aobj, &m);

I don't understand how userspace can make use of the address space above the hole, since AMDGPU_VA_HOLE_MASK is 0x0000ffffffffffffULL and AMDGPU_VA_HOLE_END is 0xffff800000000000ULL, so masking with AMDGPU_VA_HOLE_MASK always results in an address below or inside the hole?

Yes, and exactly that is intended here.

See for programming the MC and filling the page tables you handle this as if there isn't a hole in the address space.

Only when you start to use the address from userspace you will find that you need to sign extend bit 47 into bits 48-63.

Applying the AMDGPU_VA_HOLE_MASK to and address masks out the upper 16 bits and so removes the sign extension again.

Quoted 6 lines
Quoted 6 lines
(quoted diff) +0 -0
@@ -566,6 +566,17 @@  int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
  		return -EINVAL;
  	}
 
Quoted 13 lines

Review int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 578

Quoted 10 lines
(quoted diff) +10 -0
+	if (args->va_address >= AMDGPU_VA_HOLE_START &&
+	    args->va_address < AMDGPU_VA_HOLE_END) {
+		dev_dbg(&dev->pdev->dev,
+			"va_address 0x%LX is in VA hole 0x%LX-0x%LX\n",
+			args->va_address, AMDGPU_VA_HOLE_START,
+			AMDGPU_VA_HOLE_END);
+		return -EINVAL;
+	}
+
+	args->va_address &= AMDGPU_VA_HOLE_MASK;

Ignoring the above, I think the masking with AMDGPU_VA_HOLE_MASK would need to be done before checking for the hole, otherwise the masked address could be inside the hole?

The masking just removes the sign extension which created the hole in the first place.

The VM and MC is programmed as if there isn't a hole.

Quoted 21 lines

Patch 3:

Quoted 7 lines
(quoted diff) +2 -0
@@ -577,10 +578,17 @@  static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
  			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
  		if (amdgpu_sriov_vf(adev))
  			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+
+		vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
  		dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;

Review static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file · line 591

Quoted 10 lines
(quoted diff) +7 -2
  		dev_info.virtual_address_max =
-			min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,
-			    AMDGPU_VA_HOLE_START);
+			min(vm_size, AMDGPU_VA_HOLE_START);
+
+		vm_size -= AMDGPU_VA_RESERVED_SIZE;
+		if (vm_size > AMDGPU_VA_HOLE_START) {
+			dev_info.high_va_offset = AMDGPU_VA_HOLE_END;
+			dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;
+		}

This mostly makes sense, except for the

Quoted 7 lines
		dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;

line. Can you explain how simply or'ing together the address of the end of the hole and the VM size works correctly in all cases?

As an extreme example, with vm_size == 1, this value would compute as 0xffff800000000001ULL, which seems wrong or at least weird.

We check above if vm_size is larger than AMDGPU_VA_HOLE_START, in other words larger than 0x8000000000.

Since vm_size is once more in the value range the MC expects it (without the hole) that should give us the right result to sign extend bit 47 into bits 48-63, e.g. 0xffff800000000.

And yes that initially confused me as well. Especially that you need to program the MC and fill the page tables as if there wouldn't be a hole in the address space.

Applying "& AMDGPU_VA_HOLE_MASK" and "| AMDGPU_VA_HOLE_END" just converts between the representation with and without the hole in it.

Regards,
Christian.
_______________________________________________
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): 91ea2d42-63bc-0da1-c72e-74ada52dfa64-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#18 lore raw
Quoted 126 lines · Christian König

Am 20.11.2017 um 11:36 schrieb Michel Dänzer:

Quoted 37 lines · Christian König
Quoted 25 lines

Am 17.11.2017 um 17:09 schrieb Michel Dänzer:

Quoted 11 lines · Christian König
Quoted 1 line

Ping? Michel, Alex can somebody take a look?

Patch 2 is

With patches 1 & 3, it's not 100% clear to me what the idea is behind the handling of the hole on the kernel and userspace side. Maybe you can
add some explanation in code comments or the commit logs?

Yeah, that is actually a bit of a mess because the hardware documentation wasn't very clear on how this works.

How about this as extra code comment on patch 1 to the assignment of dev_info.virtual_address_max:

/*
  * Old userspace isn't aware of the VA hole on Vega10. So in theory an client could get invalid VA addresses assigned.
  * To fix this and keep backward compatibility we limit the VA space reported in this field to the range below the hole.
  */

Quoted 5 lines

The last patch is then to report the VA space above the hole, cause that is actually what libdrm should use.

The crux is when I put the VA space above the hole directly into the old fields older versions of libdrm would break and we can't do that.

That much was actually clear. :) Maybe some questions will expose what I'm missing:

Patch 1:

Quoted 13 lines

Review static int amdgpu_cs_ib_vm_chunk(struct · line 885

Quoted 8 lines
(quoted diff) +2 -1
@@ -880,14 +880,14 @@  static int amdgpu_cs_ib_vm_chunk(struct
 amdgpu_device *adev,
               if (chunk->chunk_id != AMDGPU_CHUNK_ID_IB)
                   continue;
   -            r = amdgpu_cs_find_mapping(p, chunk_ib->va_start,
-                           &aobj, &m);
+            va_start = chunk_ib->va_start & AMDGPU_VA_HOLE_MASK;
+            r = amdgpu_cs_find_mapping(p, va_start, &aobj, &m);

I don't understand how userspace can make use of the address space above the hole, since AMDGPU_VA_HOLE_MASK is 0x0000ffffffffffffULL and AMDGPU_VA_HOLE_END is 0xffff800000000000ULL, so masking with AMDGPU_VA_HOLE_MASK always results in an address below or inside the hole?

Yes, and exactly that is intended here.

See for programming the MC and filling the page tables you handle this as if there isn't a hole in the address space.

Only when you start to use the address from userspace you will find that you need to sign extend bit 47 into bits 48-63.

Applying the AMDGPU_VA_HOLE_MASK to and address masks out the upper 16 bits and so removes the sign extension again.

Quoted 11 lines
Quoted 11 lines
(quoted diff) +0 -0
@@ -566,6 +566,17 @@  int amdgpu_gem_va_ioctl(struct drm_device *dev,
 void *data,
           return -EINVAL;
       }

  +    if (args->va_address >= AMDGPU_VA_HOLE_START && +        args->va_address < AMDGPU_VA_HOLE_END) { +        dev_dbg(&dev->pdev->dev,
+            "va_address 0x%LX is in VA hole 0x%LX-0x%LX\n", +            args->va_address, AMDGPU_VA_HOLE_START,

Quoted 8 lines
Quoted 5 lines

+            AMDGPU_VA_HOLE_END);
+        return -EINVAL;
+    }
+
+    args->va_address &= AMDGPU_VA_HOLE_MASK;

Ignoring the above, I think the masking with AMDGPU_VA_HOLE_MASK would need to be done before checking for the hole, otherwise the masked address could be inside the hole?

The masking just removes the sign extension which created the hole in the first place.

The VM and MC is programmed as if there isn't a hole.

Quoted 22 lines

Patch 3:

Quoted 10 lines
(quoted diff) +2 -0
@@ -577,10 +578,17 @@  static int amdgpu_info_ioctl(struct drm_device
 *dev, void *data, struct drm_file
               dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
           if (amdgpu_sriov_vf(adev))
               dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+
+        vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
           dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;

          dev_info.virtual_address_max =
-            min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,

Quoted 8 lines

-                AMDGPU_VA_HOLE_START);
+            min(vm_size, AMDGPU_VA_HOLE_START);
+
+        vm_size -= AMDGPU_VA_RESERVED_SIZE;
+        if (vm_size > AMDGPU_VA_HOLE_START) {
+            dev_info.high_va_offset = AMDGPU_VA_HOLE_END; +            dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size; +        }

This mostly makes sense, except for the

Quoted 7 lines

        dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;

line. Can you explain how simply or'ing together the address of the end of the hole and the VM size works correctly in all cases?

As an extreme example, with vm_size == 1, this value would compute as 0xffff800000000001ULL, which seems wrong or at least weird.

We check above if vm_size is larger than AMDGPU_VA_HOLE_START, in other words larger than 0x8000000000.

Since vm_size is once more in the value range the MC expects it (without the hole) that should give us the right result to sign extend bit 47 into bits 48-63, e.g. 0xffff800000000.

Quoted 6 lines

And yes that initially confused me as well. Especially that you need to program the MC and fill the page tables as if there wouldn't be a hole in the address space.

Applying "& AMDGPU_VA_HOLE_MASK" and "| AMDGPU_VA_HOLE_END" just converts between the representation with and without the hole in it.

Thanks for the explanation, I get it now.

For the benefit of future readers of this code, it would be nice to have a short version of this explanation as a comment, e.g. above the AMDGPU_VA_HOLE_* defines.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
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): 81190489-18f8-0469-91e9-1a3902d7543b-otUistvHUpPR7s880joybQ@public.gmane.org

#20 lore raw

Am 20.11.2017 um 15:46 schrieb Michel Dänzer:

Quoted 127 lines · Christian König
Quoted 126 lines

Am 20.11.2017 um 11:36 schrieb Michel Dänzer:

Quoted 37 lines · Christian König
Quoted 25 lines

Am 17.11.2017 um 17:09 schrieb Michel Dänzer:

Quoted 11 lines · Christian König
Quoted 1 line

Ping? Michel, Alex can somebody take a look?

Patch 2 is

With patches 1 & 3, it's not 100% clear to me what the idea is behind the handling of the hole on the kernel and userspace side. Maybe you can
add some explanation in code comments or the commit logs?

Yeah, that is actually a bit of a mess because the hardware documentation wasn't very clear on how this works.

How about this as extra code comment on patch 1 to the assignment of dev_info.virtual_address_max:

/*
  * Old userspace isn't aware of the VA hole on Vega10. So in theory an
client could get invalid VA addresses assigned.
  * To fix this and keep backward compatibility we limit the VA space
reported in this field to the range below the hole.
  */

Quoted 5 lines

The last patch is then to report the VA space above the hole, cause that is actually what libdrm should use.

The crux is when I put the VA space above the hole directly into the old fields older versions of libdrm would break and we can't do that.

That much was actually clear. :) Maybe some questions will expose what I'm missing:

Patch 1:

Quoted 13 lines

Review static int amdgpu_cs_ib_vm_chunk(struct · line 885

Quoted 8 lines
(quoted diff) +2 -1
@@ -880,14 +880,14 @@  static int amdgpu_cs_ib_vm_chunk(struct
 amdgpu_device *adev,
               if (chunk->chunk_id != AMDGPU_CHUNK_ID_IB)
                   continue;
   -            r = amdgpu_cs_find_mapping(p, chunk_ib->va_start,
-                           &aobj, &m);
+            va_start = chunk_ib->va_start & AMDGPU_VA_HOLE_MASK;
+            r = amdgpu_cs_find_mapping(p, va_start, &aobj, &m);

I don't understand how userspace can make use of the address space above the hole, since AMDGPU_VA_HOLE_MASK is 0x0000ffffffffffffULL and AMDGPU_VA_HOLE_END is 0xffff800000000000ULL, so masking with AMDGPU_VA_HOLE_MASK always results in an address below or inside the hole?

Yes, and exactly that is intended here.

See for programming the MC and filling the page tables you handle this as if there isn't a hole in the address space.

Only when you start to use the address from userspace you will find that you need to sign extend bit 47 into bits 48-63.

Applying the AMDGPU_VA_HOLE_MASK to and address masks out the upper 16 bits and so removes the sign extension again.

Quoted 10 lines
Quoted 10 lines
(quoted diff) +4 -0
@@ -566,6 +566,17 @@  int amdgpu_gem_va_ioctl(struct drm_device *dev,
 void *data,
           return -EINVAL;
       }
   +    if (args->va_address >= AMDGPU_VA_HOLE_START &&
+        args->va_address < AMDGPU_VA_HOLE_END) {
+        dev_dbg(&dev->pdev->dev,
+            "va_address 0x%LX is in VA hole 0x%LX-0x%LX\n",
+            args->va_address, AMDGPU_VA_HOLE_START,
Quoted 8 lines

Review int amdgpu_gem_va_ioctl(struct drm_device *dev, · line 578

Quoted 5 lines
(quoted diff) +5 -0
+            AMDGPU_VA_HOLE_END);
+        return -EINVAL;
+    }
+
+    args->va_address &= AMDGPU_VA_HOLE_MASK;

Ignoring the above, I think the masking with AMDGPU_VA_HOLE_MASK would need to be done before checking for the hole, otherwise the masked address could be inside the hole?

The masking just removes the sign extension which created the hole in the first place.

The VM and MC is programmed as if there isn't a hole.

Quoted 22 lines

Patch 3:

Quoted 8 lines
(quoted diff) +2 -0
@@ -577,10 +578,17 @@  static int amdgpu_info_ioctl(struct drm_device
 *dev, void *data, struct drm_file
               dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
           if (amdgpu_sriov_vf(adev))
               dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
+
+        vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
           dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;

Review static int amdgpu_info_ioctl(struct drm_device · line 592

Quoted 10 lines
(quoted diff) +7 -2
           dev_info.virtual_address_max =
-            min(adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE,
-                AMDGPU_VA_HOLE_START);
+            min(vm_size, AMDGPU_VA_HOLE_START);
+
+        vm_size -= AMDGPU_VA_RESERVED_SIZE;
+        if (vm_size > AMDGPU_VA_HOLE_START) {
+            dev_info.high_va_offset = AMDGPU_VA_HOLE_END;
+            dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;
+        }

This mostly makes sense, except for the

Quoted 7 lines

        dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size;

line. Can you explain how simply or'ing together the address of the end of the hole and the VM size works correctly in all cases?

As an extreme example, with vm_size == 1, this value would compute as 0xffff800000000001ULL, which seems wrong or at least weird.

We check above if vm_size is larger than AMDGPU_VA_HOLE_START, in other words larger than 0x8000000000.

Since vm_size is once more in the value range the MC expects it (without the hole) that should give us the right result to sign extend bit 47 into bits 48-63, e.g. 0xffff800000000.

And yes that initially confused me as well. Especially that you need to program the MC and fill the page tables as if there wouldn't be a hole in the address space.

Quoted 7 lines
Quoted 2 lines

Applying "& AMDGPU_VA_HOLE_MASK" and "| AMDGPU_VA_HOLE_END" just converts between the representation with and without the hole in it.

Thanks for the explanation, I get it now.

For the benefit of future readers of this code, it would be nice to have a short version of this explanation as a comment, e.g. above the AMDGPU_VA_HOLE_* defines.

I've added a comment and pushed the resulting patch with a CC: stable tag added.

What about the libdrm side of the change? Anybody who could take a look?

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