Skip to contentSkip to conversation

drm/ttm: add ttm_tt_populate wrapper

PATCH New Christian König 6 participants 18 messages Feb 2, 2018 – Feb 9, 2018 9 messages not in the archive

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

PATCH 1/5 drm/ttm: add ttm_tt_populate wrapper

Stop calling the driver callback directly.

---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 12 +++++-------
 drivers/gpu/drm/ttm/ttm_bo_vm.c   |  2 +-
 drivers/gpu/drm/ttm/ttm_tt.c      | 10 +++++++++-
 include/drm/ttm/ttm_bo_driver.h   |  9 +++++++++
 4 files changed, 24 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_util.c +5 -7
index 33ffe286f3a5..38da6903cae9 100644
@@ -375,8 +375,8 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 	/*
 	 * TTM might be null for moves within the same region.
 	 */
-	if (ttm && ttm->state == tt_unpopulated) {
-		ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
+	if (ttm) {
+		ret = ttm_tt_populate(ttm, ctx);
 		if (ret)
 			goto out1;
 	}
@@ -557,11 +557,9 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
 
 	BUG_ON(!ttm);
 
-	if (ttm->state == tt_unpopulated) {
-		ret = ttm->bdev->driver->ttm_tt_populate(ttm, &ctx);
-		if (ret)
-			return ret;
-	}
+	ret = ttm_tt_populate(ttm, &ctx);
+	if (ret)
+		return ret;
 
 	if (num_pages == 1 && (mem->placement & TTM_PL_FLAG_CACHED)) {
 		/*
drivers/gpu/drm/ttm/ttm_bo_vm.c +1 -1
index 716e724ac710..610d6714042a 100644
@@ -234,7 +234,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
 						cvma.vm_page_prot);
 
 		/* Allocate all page at once, most common usage */
-		if (ttm->bdev->driver->ttm_tt_populate(ttm, &ctx)) {
+		if (ttm_tt_populate(ttm, &ctx)) {
 			ret = VM_FAULT_OOM;
 			goto out_io_unlock;
 		}
drivers/gpu/drm/ttm/ttm_tt.c +9 -1
index 95a77dab8cc9..39c44e301c72 100644
@@ -276,7 +276,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem,
 	if (ttm->state == tt_bound)
 		return 0;
 
-	ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
+	ret = ttm_tt_populate(ttm, ctx);
 	if (ret)
 		return ret;
 
@@ -392,6 +392,14 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 	return ret;
 }
 
+int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
+{
+	if (ttm->state != tt_unpopulated)
+		return 0;
+
+	return ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
+}
+
 static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
 {
 	pgoff_t i;
include/drm/ttm/ttm_bo_driver.h +9 -0
index 9b417eb2df20..2bac25a6cf90 100644
@@ -700,6 +700,15 @@ int ttm_tt_swapin(struct ttm_tt *ttm);
 int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t placement);
 int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage);
 
+/**
+ * ttm_tt_populate - allocate pages for a ttm
+ *
+ * @ttm: Pointer to the ttm_tt structure
+ *
+ * Calls the driver method to allocate pages for a ttm
+ */
+int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
+
 /**
  * ttm_tt_unpopulate - free pages from a ttm
  *
Signature · 6 lines
2.14.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/5 drm/amdgpu: remove extra TT unpopulated check

The subsystem chould check that, not the driver.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -3
index 95f990140f2a..648c449aaa79 100644
@@ -997,9 +997,6 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
-	if (ttm->state != tt_unpopulated)
-		return 0;
-
 	if (gtt && gtt->userptr) {
 		ttm->sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
 		if (!ttm->sg)
Signature · 6 lines
2.14.1

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

A message that is not in the archive (sent off-list or not yet received): 20180202190948.2654-1-christian.koenig-5C7GfCeVMHo@public.gmane.org

#3 lore raw

PATCH 3/5 drm/radeon: remove extra TT unpopulated check

The subsystem chould check that, not the driver.

---
 drivers/gpu/drm/radeon/radeon_ttm.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +0 -3
index a0a839bc39bf..42e3ee81a96e 100644
@@ -728,9 +728,6 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm,
 	struct radeon_device *rdev;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
-	if (ttm->state != tt_unpopulated)
-		return 0;
-
 	if (gtt && gtt->userptr) {
 		ttm->sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
 		if (!ttm->sg)
Signature · 6 lines
2.14.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): 20180202190948.2654-3-christian.koenig-5C7GfCeVMHo@public.gmane.org

#5 lore raw

RE: [PATCH 3/5] drm/radeon: remove extra TT unpopulated check

-----Original Message-----
From: dri-devel [mailto:[email protected]] On Behalf Of Christian K?nig
Sent: Saturday, February 03, 2018 3:10 AM
To: [email protected]; [email protected]
Subject: [PATCH 3/5] drm/radeon: remove extra TT unpopulated check

The subsystem chould check that, not the driver.

Commit log typo, should be "should" rather than " chould". With that fix, this patch is Reviewed-by: Roger He <[email protected]>

Thanks
Roger(Hongbo.He)

---
 drivers/gpu/drm/radeon/radeon_ttm.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +0 -3
index a0a839bc39bf..42e3ee81a96e 100644
@@ -728,9 +728,6 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm,
 	struct radeon_device *rdev;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
-	if (ttm->state != tt_unpopulated)
-		return 0;
-
 	if (gtt && gtt->userptr) {
 		ttm->sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
 		if (!ttm->sg)
Signature · 10 lines
2.14.1

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

PATCH 5/5 drm/amdgpu: replace iova debugfs file with iomem

In reply to a message not in the archive

This allows access to pages allocated through the driver with optional IOMMU mapping.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57 ++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +35 -22
index 648c449aaa79..795ceaeb82d5 100644
@@ -1929,38 +1929,51 @@ static const struct file_operations amdgpu_ttm_gtt_fops = {
 
 #endif
 
-static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
-				   size_t size, loff_t *pos)
+static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
+				 size_t size, loff_t *pos)
 {
 	struct amdgpu_device *adev = file_inode(f)->i_private;
-	int r;
-	uint64_t phys;
 	struct iommu_domain *dom;
+	ssize_t result = 0;
+	int r;
 
-	// always return 8 bytes
-	if (size != 8)
-		return -EINVAL;
+	dom = iommu_get_domain_for_dev(adev->dev);
 
-	// only accept page addresses
-	if (*pos & 0xFFF)
-		return -EINVAL;
+	while (size) {
+		phys_addr_t addr = *pos & PAGE_MASK;
+		loff_t off = *pos & ~PAGE_MASK;
+		size_t bytes = PAGE_SIZE - off;
+		unsigned long pfn;
+		struct page *p;
+		void *ptr;
 
-	dom = iommu_get_domain_for_dev(adev->dev);
-	if (dom)
-		phys = iommu_iova_to_phys(dom, *pos);
-	else
-		phys = *pos;
+		addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
 
-	r = copy_to_user(buf, &phys, 8);
-	if (r)
-		return -EFAULT;
+		pfn = addr >> PAGE_SHIFT;
+		if (!pfn_valid(pfn))
+			return -EPERM;
+
+		p = pfn_to_page(pfn);
+		if (p->mapping != adev->mman.bdev.dev_mapping)
+			return -EPERM;
+
+		ptr = kmap(p);
+		r = copy_to_user(buf, ptr, bytes);
+		kunmap(p);
+		if (r)
+			return -EFAULT;
 
-	return 8;
+		size -= bytes;
+		*pos += bytes;
+		result += bytes;
+	}
+
+	return result;
 }
 
-static const struct file_operations amdgpu_ttm_iova_fops = {
+static const struct file_operations amdgpu_ttm_iomem_fops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_iova_to_phys_read,
+	.read = amdgpu_iomem_read,
 	.llseek = default_llseek
 };
 
@@ -1973,7 +1986,7 @@ static const struct {
 #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
 	{ "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT },
 #endif
-	{ "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM },
+	{ "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM },
 };
 
 #endif
Signature · 6 lines
2.14.1

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

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

I haven't tried the patch but just like to point out this breaks umr :-) I'll have to craft something on Monday to support this and iova in parallel until the iova kernels are realistically EOL'ed.

On the other hand I support this idea since it eliminates the need for an fmem hack. So much appreciated.

Cheers,
Tom

________________________________________
From: amd-gfx <[email protected]> on behalf of Christian König <[email protected]>
Sent: Friday, February 2, 2018 14:09
To: [email protected]; [email protected]
Subject: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

This allows access to pages allocated through the driver with optional IOMMU mapping.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57 ++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +35 -22
index 648c449aaa79..795ceaeb82d5 100644
@@ -1929,38 +1929,51 @@ static const struct file_operations amdgpu_ttm_gtt_fops = {
 
 #endif
 
-static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
-                                  size_t size, loff_t *pos)
+static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
+                                size_t size, loff_t *pos)
 {
        struct amdgpu_device *adev = file_inode(f)->i_private;
-       int r;
-       uint64_t phys;
        struct iommu_domain *dom;
+       ssize_t result = 0;
+       int r;
 
-       // always return 8 bytes
-       if (size != 8)
-               return -EINVAL;
+       dom = iommu_get_domain_for_dev(adev->dev);
 
-       // only accept page addresses
-       if (*pos & 0xFFF)
-               return -EINVAL;
+       while (size) {
+               phys_addr_t addr = *pos & PAGE_MASK;
+               loff_t off = *pos & ~PAGE_MASK;
+               size_t bytes = PAGE_SIZE - off;
+               unsigned long pfn;
+               struct page *p;
+               void *ptr;
 
-       dom = iommu_get_domain_for_dev(adev->dev);
-       if (dom)
-               phys = iommu_iova_to_phys(dom, *pos);
-       else
-               phys = *pos;
+               addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
 
-       r = copy_to_user(buf, &phys, 8);
-       if (r)
-               return -EFAULT;
+               pfn = addr >> PAGE_SHIFT;
+               if (!pfn_valid(pfn))
+                       return -EPERM;
+
+               p = pfn_to_page(pfn);
+               if (p->mapping != adev->mman.bdev.dev_mapping)
+                       return -EPERM;
+
+               ptr = kmap(p);
+               r = copy_to_user(buf, ptr, bytes);
+               kunmap(p);
+               if (r)
+                       return -EFAULT;
 
-       return 8;
+               size -= bytes;
+               *pos += bytes;
+               result += bytes;
+       }
+
+       return result;
 }
 
-static const struct file_operations amdgpu_ttm_iova_fops = {
+static const struct file_operations amdgpu_ttm_iomem_fops = {
        .owner = THIS_MODULE,
-       .read = amdgpu_iova_to_phys_read,
+       .read = amdgpu_iomem_read,
        .llseek = default_llseek
 };
 
@@ -1973,7 +1986,7 @@ static const struct {
 #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
        { "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT },
 #endif
-       { "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM },
+       { "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM },
 };
 
 #endif

--
2.14.1

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

A message that is not in the archive (sent off-list or not yet received): 20180202190948.2654-5-christian.koenig-5C7GfCeVMHo@public.gmane.org

#9 lore raw

RE: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Patch1 & 2 & 4, Reviewed-by: Roger He <[email protected]>
Patch 5: Acked-by: Roger He <[email protected]>

-----Original Message-----
From: dri-devel [mailto:[email protected]] On Behalf Of Christian K?nig
Sent: Saturday, February 03, 2018 3:10 AM
To: [email protected]; [email protected]
Subject: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

This allows access to pages allocated through the driver with optional IOMMU mapping.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57 ++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +35 -23
index 648c449aaa79..795ceaeb82d5 100644
@@ -1929,38 +1929,51 @@ static const struct file_operations amdgpu_ttm_gtt_fops = {
 
 #endif
 
-static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
-				   size_t size, loff_t *pos)
+static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
+				 size_t size, loff_t *pos)
 {
 	struct amdgpu_device *adev = file_inode(f)->i_private;
-	int r;
-	uint64_t phys;
 	struct iommu_domain *dom;
+	ssize_t result = 0;
+	int r;
 
-	// always return 8 bytes
-	if (size != 8)
-		return -EINVAL;
+	dom = iommu_get_domain_for_dev(adev->dev);
 
-	// only accept page addresses
-	if (*pos & 0xFFF)
-		return -EINVAL;
+	while (size) {
+		phys_addr_t addr = *pos & PAGE_MASK;
+		loff_t off = *pos & ~PAGE_MASK;
+		size_t bytes = PAGE_SIZE - off;
+		unsigned long pfn;
+		struct page *p;
+		void *ptr;
 
-	dom = iommu_get_domain_for_dev(adev->dev);
-	if (dom)
-		phys = iommu_iova_to_phys(dom, *pos);
-	else
-		phys = *pos;
+		addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
 
-	r = copy_to_user(buf, &phys, 8);
-	if (r)
-		return -EFAULT;
+		pfn = addr >> PAGE_SHIFT;
+		if (!pfn_valid(pfn))
+			return -EPERM;
+
+		p = pfn_to_page(pfn);
+		if (p->mapping != adev->mman.bdev.dev_mapping)
+			return -EPERM;
+
+		ptr = kmap(p);
+		r = copy_to_user(buf, ptr, bytes);
+		kunmap(p);
+		if (r)
+			return -EFAULT;
 
-	return 8;
+		size -= bytes;
+		*pos += bytes;
+		result += bytes;
+	}
+
+	return result;
 }
 
-static const struct file_operations amdgpu_ttm_iova_fops = {
+static const struct file_operations amdgpu_ttm_iomem_fops = {
 	.owner = THIS_MODULE,
-	.read = amdgpu_iova_to_phys_read,
+	.read = amdgpu_iomem_read,
 	.llseek = default_llseek
 };
 
@@ -1973,7 +1986,7 @@ static const struct {  #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
 	{ "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT },  #endif
-	{ "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM },
+	{ "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM },
 };
 
 #endif
--

2.14.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
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): MWHPR1201MB012743AB6452692097481D08FDFE0-3iK1xFAIwjq9imrIu4W8xGrFom/aUZj6nBOFsp37pqbUKgpGm//BTAC/[email protected]

#11 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Another thing that occurred to me is this will break write access to GPU bound memory. Previously we relied on iova to translate the address and then /dev/mem or /dev/fmem to read/write it. But since this is literally a read only method obviously there's no write support.

Tom

Quoted 103 lines · Roger

Patch1 & 2 & 4, Reviewed-by: Roger He <[email protected]>
Patch 5: Acked-by: Roger He <[email protected]>

-----Original Message-----
From: dri-devel [mailto:[email protected]] On Behalf Of Christian K?nig
Sent: Saturday, February 03, 2018 3:10 AM
To: [email protected]; [email protected]
Subject: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

This allows access to pages allocated through the driver with optional IOMMU mapping.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57 ++++++++++++++++++++-------------
  1 file changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +35 -23
index 648c449aaa79..795ceaeb82d5 100644
@@ -1929,38 +1929,51 @@ static const struct file_operations amdgpu_ttm_gtt_fops = {
 
  #endif
 
-static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
-				   size_t size, loff_t *pos)
+static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
+				 size_t size, loff_t *pos)
  {
  	struct amdgpu_device *adev = file_inode(f)->i_private;
-	int r;
-	uint64_t phys;
  	struct iommu_domain *dom;
+	ssize_t result = 0;
+	int r;
 
-	// always return 8 bytes
-	if (size != 8)
-		return -EINVAL;
+	dom = iommu_get_domain_for_dev(adev->dev);
 
-	// only accept page addresses
-	if (*pos & 0xFFF)
-		return -EINVAL;
+	while (size) {
+		phys_addr_t addr = *pos & PAGE_MASK;
+		loff_t off = *pos & ~PAGE_MASK;
+		size_t bytes = PAGE_SIZE - off;
+		unsigned long pfn;
+		struct page *p;
+		void *ptr;
 
-	dom = iommu_get_domain_for_dev(adev->dev);
-	if (dom)
-		phys = iommu_iova_to_phys(dom, *pos);
-	else
-		phys = *pos;
+		addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
 
-	r = copy_to_user(buf, &phys, 8);
-	if (r)
-		return -EFAULT;
+		pfn = addr >> PAGE_SHIFT;
+		if (!pfn_valid(pfn))
+			return -EPERM;
+
+		p = pfn_to_page(pfn);
+		if (p->mapping != adev->mman.bdev.dev_mapping)
+			return -EPERM;
+
+		ptr = kmap(p);
+		r = copy_to_user(buf, ptr, bytes);
+		kunmap(p);
+		if (r)
+			return -EFAULT;
 
-	return 8;
+		size -= bytes;
+		*pos += bytes;
+		result += bytes;
+	}
+
+	return result;
  }
 
-static const struct file_operations amdgpu_ttm_iova_fops = {
+static const struct file_operations amdgpu_ttm_iomem_fops = {
  	.owner = THIS_MODULE,
-	.read = amdgpu_iova_to_phys_read,
+	.read = amdgpu_iomem_read,
  	.llseek = default_llseek
  };
 
@@ -1973,7 +1986,7 @@ static const struct {  #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
  	{ "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT },  #endif
-	{ "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM },
+	{ "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM },
  };
 
  #endif
--

2.14.1

Quoted 9 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
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): 8c826b1d-1a3c-e36f-c978-48b286b10f0f-5C7GfCeVMHo@public.gmane.org

#13 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Well adding write support is trivial.

What I'm more concerned about is if setting page->mapping during allocation of the page could have any negative effect?

I of hand don't see any since the page isn't reclaimable directly anyway, but I'm not 100% sure of that.

Christian.

Am 05.02.2018 um 12:49 schrieb Tom St Denis:

Quoted 101 lines

Another thing that occurred to me is this will break write access to GPU bound memory.  Previously we relied on iova to translate the address and then /dev/mem or /dev/fmem to read/write it.  But since this is literally a read only method obviously there's no write support.

Tom

Quoted 95 lines · Roger

Patch1 & 2 & 4,   Reviewed-by: Roger He <[email protected]> Patch 5:  Acked-by: Roger He <[email protected]>

-----Original Message-----
From: dri-devel [mailto:[email protected]] On Behalf Of Christian K?nig
Sent: Saturday, February 03, 2018 3:10 AM
To: [email protected]; [email protected]
Subject: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

This allows access to pages allocated through the driver with optional IOMMU mapping.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57
++++++++++++++++++++-------------

  1 file changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4 -3
index 648c449aaa79..795ceaeb82d5 100644
@@ -1929,38 +1929,51 @@ static const struct file_operations 
 amdgpu_ttm_gtt_fops = {
     #endif
   -static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
-                   size_t size, loff_t *pos)
+static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
+                 size_t size, loff_t *pos)
   {
       struct amdgpu_device *adev = file_inode(f)->i_private;
-    int r;
-    uint64_t phys;
       struct iommu_domain *dom;
+    ssize_t result = 0;
+    int r;

  -    // always return 8 bytes
-    if (size != 8)
-        return -EINVAL;
+    dom = iommu_get_domain_for_dev(adev->dev);
  -    // only accept page addresses
-    if (*pos & 0xFFF)
-        return -EINVAL;
+    while (size) {
+        phys_addr_t addr = *pos & PAGE_MASK;
+        loff_t off = *pos & ~PAGE_MASK;
+        size_t bytes = PAGE_SIZE - off;
+        unsigned long pfn;
+        struct page *p;
+        void *ptr;
  -    dom = iommu_get_domain_for_dev(adev->dev); -    if (dom)
-        phys = iommu_iova_to_phys(dom, *pos);
-    else
-        phys = *pos;
+        addr = dom ? iommu_iova_to_phys(dom, addr) : addr; -    r = copy_to_user(buf, &phys, 8);
-    if (r)
-        return -EFAULT;
+        pfn = addr >> PAGE_SHIFT;
+        if (!pfn_valid(pfn))
+            return -EPERM;

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +10 -0
+
+        p = pfn_to_page(pfn);
+        if (p->mapping != adev->mman.bdev.dev_mapping)
+            return -EPERM;
+
+        ptr = kmap(p);
+        r = copy_to_user(buf, ptr, bytes);
+        kunmap(p);
+        if (r)
+            return -EFAULT;

  -    return 8;
+        size -= bytes;
+        *pos += bytes;
+        result += bytes;
+    }
+
+    return result;
  }
  -static const struct file_operations amdgpu_ttm_iova_fops = { +static const struct file_operations amdgpu_ttm_iomem_fops = {
      .owner = THIS_MODULE,
-    .read = amdgpu_iova_to_phys_read,
+    .read = amdgpu_iomem_read,
      .llseek = default_llseek
  };
  @@ -1973,7 +1986,7 @@ static const struct {  #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS { "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT }, #endif
-    { "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM },
+    { "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM },
  };
    #endif

Signature · 1 line
2.14.1
Quoted 10 lines
Quoted 9 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
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): 0db6d2d5-8cd1-31e3-8443-4be9394fd8ff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#15 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Attached is a patch for umr{master} which should in theory support both iova and iomem.

I can add the write method if you want since ya it should be fairly simple to copy/pasta that up.

Cheers,
Tom

Quoted 122 lines · Christian König

Well adding write support is trivial.

What I'm more concerned about is if setting page->mapping during allocation of the page could have any negative effect?

I of hand don't see any since the page isn't reclaimable directly anyway, but I'm not 100% sure of that.

Christian.

Am 05.02.2018 um 12:49 schrieb Tom St Denis:

Quoted 101 lines

Another thing that occurred to me is this will break write access to GPU bound memory.  Previously we relied on iova to translate the address and then /dev/mem or /dev/fmem to read/write it.  But since this is literally a read only method obviously there's no write support.

Tom

Quoted 95 lines · Roger

Patch1 & 2 & 4,   Reviewed-by: Roger He <[email protected]> Patch 5:  Acked-by: Roger He <[email protected]>

-----Original Message-----
From: dri-devel [mailto:dri-devel-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org] On Behalf Of Christian K?nig
Sent: Saturday, February 03, 2018 3:10 AM
To: [email protected]; [email protected]
Subject: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

This allows access to pages allocated through the driver with optional IOMMU mapping.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57
++++++++++++++++++++-------------

  1 file changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4 -3
index 648c449aaa79..795ceaeb82d5 100644
@@ -1929,38 +1929,51 @@ static const struct file_operations 
 amdgpu_ttm_gtt_fops = {
     #endif
   -static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
-                   size_t size, loff_t *pos)
+static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
+                 size_t size, loff_t *pos)
   {
       struct amdgpu_device *adev = file_inode(f)->i_private;
-    int r;
-    uint64_t phys;
       struct iommu_domain *dom;
+    ssize_t result = 0;
+    int r;

  -    // always return 8 bytes
-    if (size != 8)
-        return -EINVAL;
+    dom = iommu_get_domain_for_dev(adev->dev);
  -    // only accept page addresses
-    if (*pos & 0xFFF)
-        return -EINVAL;
+    while (size) {
+        phys_addr_t addr = *pos & PAGE_MASK;
+        loff_t off = *pos & ~PAGE_MASK;
+        size_t bytes = PAGE_SIZE - off;
+        unsigned long pfn;
+        struct page *p;
+        void *ptr;
  -    dom = iommu_get_domain_for_dev(adev->dev); -    if (dom)
-        phys = iommu_iova_to_phys(dom, *pos);
-    else
-        phys = *pos;
+        addr = dom ? iommu_iova_to_phys(dom, addr) : addr; -    r = copy_to_user(buf, &phys, 8);
-    if (r)
-        return -EFAULT;
+        pfn = addr >> PAGE_SHIFT;
+        if (!pfn_valid(pfn))
+            return -EPERM;

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +10 -0
+
+        p = pfn_to_page(pfn);
+        if (p->mapping != adev->mman.bdev.dev_mapping)
+            return -EPERM;
+
+        ptr = kmap(p);
+        r = copy_to_user(buf, ptr, bytes);
+        kunmap(p);
+        if (r)
+            return -EFAULT;

  -    return 8;
+        size -= bytes;
+        *pos += bytes;
+        result += bytes;
+    }
+
+    return result;
  }
  -static const struct file_operations amdgpu_ttm_iova_fops = { +static const struct file_operations amdgpu_ttm_iomem_fops = {
      .owner = THIS_MODULE,
-    .read = amdgpu_iova_to_phys_read,
+    .read = amdgpu_iomem_read,
      .llseek = default_llseek
  };
  @@ -1973,7 +1986,7 @@ static const struct {  #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS { "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT }, #endif
-    { "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM },
+    { "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM },
  };
    #endif

Signature · 1 line
2.14.1
Quoted 10 lines
Quoted 9 lines

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

Quoted 1 line

From 67703a62763dfb2107bd503c5ae76414a50c50a4 Mon Sep 17 00:00:00 2001

From: Tom St Denis <[email protected]>
Date: Mon, 5 Feb 2018 08:53:40 -0500
Subject: [PATCH umr] add support for new iomem debugfs entry

---
 src/lib/close_asic.c |  1 +
 src/lib/discover.c   |  3 +++
 src/lib/read_vram.c  | 29 +++++++++++++++++++----------
 src/umr.h            |  3 ++-
 4 files changed, 25 insertions(+), 11 deletions(-)
src/lib/close_asic.c +1 -0
index 782b1a0d029b..6b220cd578e9 100644
@@ -57,6 +57,7 @@ void umr_close_asic(struct umr_asic *asic)
 		cond_close(asic->fd.gpr);
 		cond_close(asic->fd.drm);
 		cond_close(asic->fd.iova);
+		cond_close(asic->fd.iomem);
 		umr_free_asic(asic);
 	}
 }
src/lib/discover.c +3 -0
index 4af3733c8af8..dedcedc776ab 100644
@@ -232,6 +232,8 @@ struct umr_asic *umr_discover_asic(struct umr_options *options)
 			asic->fd.gpr = open(fname, O_RDWR);
 			snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_iova", asic->instance);
 			asic->fd.iova = open(fname, O_RDWR);
+			snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_iomem", asic->instance);
+			asic->fd.iomem = open(fname, O_RDWR);
 			asic->fd.drm = -1; // default to closed
 			// if appending to the fd list remember to update close_asic() and discover_by_did()...
 		} else {
@@ -246,6 +248,7 @@ struct umr_asic *umr_discover_asic(struct umr_options *options)
 			asic->fd.gpr = -1;
 			asic->fd.drm = -1;
 			asic->fd.iova = -1;
+			asic->fd.iomem = -1;
 		}
 
 		if (options->use_pci) {
src/lib/read_vram.c +19 -10
index 25ffec93f54d..c685955e5050 100644
@@ -73,30 +73,39 @@ static void access_vram_via_mmio(struct umr_asic *asic, uint64_t address, uint32
 #define DEBUG(...)
 #endif
 
-static int umr_access_sram(uint64_t address, uint32_t size, void *dst, int write_en)
+static int umr_access_sram(struct umr_asic *asic, uint64_t address, uint32_t size, void *dst, int write_en)
 {
-	int fd;
+	int fd, need_close=0;
 
 	DEBUG("Reading physical sys addr: 0x%llx\n", (unsigned long long)address);
 
-	fd = open("/dev/fmem", O_RDWR);
-	if (fd < 0)
-		fd = open("/dev/mem", O_RDWR | O_DSYNC);
+	if (asic->fd.iomem >= 0) {
+		fd = asic->fd.iomem;
+	} else {
+		need_close = 1;
+
+		fd = open("/dev/fmem", O_RDWR);
+		if (fd < 0)
+			fd = open("/dev/mem", O_RDWR | O_DSYNC);
+	}
 	if (fd >= 0) {
 		lseek(fd, address, SEEK_SET);
 		if (write_en == 0) {
 			memset(dst, 0xFF, size);
 			if (read(fd, dst, size) != size) {
-				close(fd);
+				if (need_close)
+					close(fd);
 				return -1;
 			}
 		} else {
 			if (write(fd, dst, size) != size) {
-				close(fd);
+				if (need_close)
+					close(fd);
 				return -1;
 			}
 		}
-		close(fd);
+		if (need_close)
+			close(fd);
 		return 0;
 	}
 	return -1;
@@ -292,7 +301,7 @@ next_page:
 		// allow destination to be NULL to simply use decoder
 		if (pdst) {
 			if (pte_fields.system) {
-				if (umr_access_sram(start_addr, chunk_size, pdst, write_en) < 0) {
+				if (umr_access_sram(asic, start_addr, chunk_size, pdst, write_en) < 0) {
 					fprintf(stderr, "[ERROR]: Cannot access system ram, perhaps CONFIG_STRICT_DEVMEM is set in your kernel config?\n");
 					fprintf(stderr, "[ERROR]: Alternatively download and install /dev/fmem\n");
 					return -1;
@@ -663,7 +672,7 @@ next_page:
 		if (pte_fields.valid) {
 			if (pdst) {
 				if (pte_fields.system) {
-					if (umr_access_sram(start_addr, chunk_size, pdst, write_en) < 0) {
+					if (umr_access_sram(asic, start_addr, chunk_size, pdst, write_en) < 0) {
 						fprintf(stderr, "[ERROR]: Cannot access system ram, perhaps CONFIG_STRICT_DEVMEM is set in your kernel config?\n");
 						fprintf(stderr, "[ERROR]: Alternatively download and install /dev/fmem\n");
 						return -1;
src/umr.h +2 -1
index 9c006f00cf45..da67abf6dc2b 100644
@@ -233,7 +233,8 @@ struct umr_asic {
 		    wave,
 		    vram,
 		    gpr,
-		    iova;
+		    iova,
+		    iomem;
 	} fd;
 	struct {
 		struct pci_device *pdevice;
Signature · 1 line
2.14.3

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

#16 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

In reply to Christian König
Quoted 51 lines · Christian König

This allows access to pages allocated through the driver with optional IOMMU mapping.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57 ++++++++++++++++++++-------------
  1 file changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +13 -15
index 648c449aaa79..795ceaeb82d5 100644
@@ -1929,38 +1929,51 @@ static const struct file_operations amdgpu_ttm_gtt_fops = {
 
  #endif
 
-static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf,
-				   size_t size, loff_t *pos)
+static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf,
+				 size_t size, loff_t *pos)
  {
  	struct amdgpu_device *adev = file_inode(f)->i_private;
-	int r;
-	uint64_t phys;
  	struct iommu_domain *dom;
+	ssize_t result = 0;
+	int r;
 
-	// always return 8 bytes
-	if (size != 8)
-		return -EINVAL;
+	dom = iommu_get_domain_for_dev(adev->dev);
 
-	// only accept page addresses
-	if (*pos & 0xFFF)
-		return -EINVAL;
+	while (size) {
+		phys_addr_t addr = *pos & PAGE_MASK;
+		loff_t off = *pos & ~PAGE_MASK;
+		size_t bytes = PAGE_SIZE - off;
+		unsigned long pfn;
+		struct page *p;
+		void *ptr;
 
-	dom = iommu_get_domain_for_dev(adev->dev);
-	if (dom)
-		phys = iommu_iova_to_phys(dom, *pos);
-	else
-		phys = *pos;
+		addr = dom ? iommu_iova_to_phys(dom, addr) : addr;
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static const struct file_operations amdgpu_ttm_gtt_fops = { · line 1958

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7 -3
-	r = copy_to_user(buf, &phys, 8);
-	if (r)
-		return -EFAULT;
+		pfn = addr >> PAGE_SHIFT;
+		if (!pfn_valid(pfn))
+			return -EPERM;
+
+		p = pfn_to_page(pfn);
+		if (p->mapping != adev->mman.bdev.dev_mapping)
+			return -EPERM;

This comparison fails for both IOMMU and non-IOMMU devices in my carrizo+polaris10 box.

The address being read from is what the VM decodes to (checked with strace).

Tom
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 9b2c3354-ea82-722d-a6d2-42e2cf1e6540-5C7GfCeVMHo@public.gmane.org

#18 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Am 09.02.2018 um 14:32 schrieb Tom St Denis:

Quoted 8 lines · Christian König
Quoted 3 lines

[SNIP]
+        if (p->mapping != adev->mman.bdev.dev_mapping) +            return -EPERM;

This comparison fails for both IOMMU and non-IOMMU devices in my carrizo+polaris10 box.

The address being read from is what the VM decodes to (checked with strace).

Have you applied the whole series? That patches before this one are necessary to initialize p->mapping when there isn't any userspace mapping for the page.

Christian.

Quoted 2 lines

Tom

_______________________________________________
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): 5f37bea8-a6a3-c879-e8ec-f24948647a3e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#20 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Quoted 11 lines · Christian König

Am 09.02.2018 um 14:32 schrieb Tom St Denis:

Quoted 8 lines · Christian König
Quoted 3 lines

[SNIP]
+        if (p->mapping != adev->mman.bdev.dev_mapping) +            return -EPERM;

This comparison fails for both IOMMU and non-IOMMU devices in my carrizo+polaris10 box.

The address being read from is what the VM decodes to (checked with strace).

Have you applied the whole series? That patches before this one are necessary to initialize p->mapping when there isn't any userspace mapping for the page.

Yes, I have the entire 5 pages applied to a temp branch based on the tip of drm-next

$ git log --oneline HEAD~10..
405bc1dc85db (HEAD -> iomem) wip
a06d7a6f29e4 drm/amdgpu: replace iova debugfs file with iomem
d324c21f2c5e drm/ttm: set page mapping during allocation
9f440ee91c58 drm/radeon: remove extra TT unpopulated check
f55d505b0387 drm/amdgpu: remove extra TT unpopulated check
37d705119ea8 drm/ttm: add ttm_tt_populate wrapper
53af6035d04b (origin/amd-staging-drm-next, amd-staging-drm-next) drm/radeon: only enable swiotlb path when need v2

(the wip is me adding printks to see which error path is taken).

I don't see an init call for adev->mman.bdev.man[TTM_PL_SYSTEM] anywhere. Maybe that's related?

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

maintainer
#21 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Am 09.02.2018 um 15:02 schrieb Tom St Denis:

Quoted 25 lines · Christian König
Quoted 11 lines

Am 09.02.2018 um 14:32 schrieb Tom St Denis:

Quoted 8 lines · Christian König
Quoted 3 lines

[SNIP]
+        if (p->mapping != adev->mman.bdev.dev_mapping) +            return -EPERM;

This comparison fails for both IOMMU and non-IOMMU devices in my carrizo+polaris10 box.

The address being read from is what the VM decodes to (checked with strace).

Have you applied the whole series? That patches before this one are necessary to initialize p->mapping when there isn't any userspace mapping for the page.

Yes, I have the entire 5 pages applied to a temp branch based on the tip of drm-next

$ git log --oneline HEAD~10..
405bc1dc85db (HEAD -> iomem) wip
a06d7a6f29e4 drm/amdgpu: replace iova debugfs file with iomem
d324c21f2c5e drm/ttm: set page mapping during allocation
9f440ee91c58 drm/radeon: remove extra TT unpopulated check
f55d505b0387 drm/amdgpu: remove extra TT unpopulated check
37d705119ea8 drm/ttm: add ttm_tt_populate wrapper
53af6035d04b (origin/amd-staging-drm-next, amd-staging-drm-next) drm/radeon: only enable swiotlb path when need v2
Quoted 3 lines

(the wip is me adding printks to see which error path is taken).

I don't see an init call for adev->mman.bdev.man[TTM_PL_SYSTEM] anywhere.  Maybe that's related?

No, there is simply no need to initialize the system domain. What are the values of p->mapping and adev->mman.bdev.dev_mapping when they don't match? Maybe we are allocating memory before initializing adev->mman.bdev.dev_mapping.

Or do you have more than one GPU in the system? E.g. APU+dGPU? Could it be that you read through the wrong device?

Christian.

Quoted 2 lines

Tom

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

A message that is not in the archive (sent off-list or not yet received): ae110a8d-b1a3-7ce3-6a0d-a5bb41c48952-5C7GfCeVMHo@public.gmane.org

#23 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Quoted 1 line · Christian König

No, there is simply no need to initialize the system domain. What are the values of p->mapping and adev->mman.bdev.dev_mapping when they don't match? Maybe we are allocating memory before initializing adev->mman.bdev.dev_mapping.

In my test setup I'm running test 3 from libdrm (suite 1) with a pause before the unmap/free call. So the IB should still be mapped. Indeed the VM PTE decoding has the V bit set.

Quoted 1 line

Or do you have more than one GPU in the system? E.g. APU+dGPU? Could it be that you read through the wrong device?

I found the issue:

	while (size) {
		phys_addr_t addr = *pos & PAGE_MASK;
		loff_t off = *pos & ~PAGE_MASK;
		size_t bytes = PAGE_SIZE - off;

"bytes" should be limited by the 'size' parameter passed in. What is happening instead is it's reading the entire PTB until it hits a V=0 page and then returns an error and in the process is doing "fun things" to the user mode application (by copying more data than I asked for).

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

maintainer
#24 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Am 09.02.2018 um 15:51 schrieb Tom St Denis:

Quoted 7 lines · Christian König
Quoted 1 line

No, there is simply no need to initialize the system domain. What are the values of p->mapping and adev->mman.bdev.dev_mapping when they don't match? Maybe we are allocating memory before initializing adev->mman.bdev.dev_mapping.

In my test setup I'm running test 3 from libdrm (suite 1) with a pause before the unmap/free call.  So the IB should still be mapped.  Indeed the VM PTE decoding has the V bit set.

Quoted 1 line

Or do you have more than one GPU in the system? E.g. APU+dGPU? Could it be that you read through the wrong device?

Quoted 8 lines

I found the issue:

    while (size) {
        phys_addr_t addr = *pos & PAGE_MASK;
        loff_t off = *pos & ~PAGE_MASK;
        size_t bytes = PAGE_SIZE - off;

"bytes" should be limited by the 'size' parameter passed in.  What is happening instead is it's reading the entire PTB until it hits a V=0 page and then returns an error and in the process is doing "fun things" to the user mode application (by copying more data than I asked for).

Ah, obvious problem.

Do you want to fix it or should I take a look? You wanted to add write support as well anyway IIRC.

I've just pushed the first three patches from that series to amd-staging-drm-next.

Thanks for testing,
Christian.

Quoted 3 lines

Tom

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

#25 lore raw

Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem

Quoted 15 lines · Christian König

Am 09.02.2018 um 15:51 schrieb Tom St Denis:

Quoted 14 lines · Christian König
Quoted 1 line

No, there is simply no need to initialize the system domain. What are the values of p->mapping and adev->mman.bdev.dev_mapping when they don't match? Maybe we are allocating memory before initializing adev->mman.bdev.dev_mapping.

In my test setup I'm running test 3 from libdrm (suite 1) with a pause before the unmap/free call.  So the IB should still be mapped.  Indeed the VM PTE decoding has the V bit set.

Quoted 1 line

Or do you have more than one GPU in the system? E.g. APU+dGPU? Could it be that you read through the wrong device?

I found the issue:

    while (size) {
        phys_addr_t addr = *pos & PAGE_MASK;
        loff_t off = *pos & ~PAGE_MASK;
        size_t bytes = PAGE_SIZE - off;

Quoted 5 lines
Quoted 1 line

"bytes" should be limited by the 'size' parameter passed in.  What is happening instead is it's reading the entire PTB until it hits a V=0 page and then returns an error and in the process is doing "fun things" to the user mode application (by copying more data than I asked for).

Ah, obvious problem.

Do you want to fix it or should I take a look? You wanted to add write support as well anyway IIRC.

Yup, I can tackle this this afternoon.

I'll take your read only patch and make it do both read/write (and fix the minor error).

Tom
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#26 lore raw

PATCH 4/5 drm/ttm: set page mapping during allocation

In reply to Christian König

To aid debugging set the page mapping during allocation instead of during VM faults.

---
 drivers/gpu/drm/ttm/ttm_bo_vm.c |  1 -
 drivers/gpu/drm/ttm/ttm_tt.c    | 18 +++++++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -1
index 610d6714042a..121f017ac7ca 100644
@@ -257,7 +257,6 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
 			} else if (unlikely(!page)) {
 				break;
 			}
-			page->mapping = vma->vm_file->f_mapping;
 			page->index = drm_vma_node_start(&bo->vma_node) +
 				page_offset;
 			pfn = page_to_pfn(page);
drivers/gpu/drm/ttm/ttm_tt.c +17 -1
index 39c44e301c72..9fd7115a013a 100644
@@ -392,12 +392,28 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 	return ret;
 }
 
+static void ttm_tt_add_mapping(struct ttm_tt *ttm)
+{
+	pgoff_t i;
+
+	if (ttm->page_flags & TTM_PAGE_FLAG_SG)
+		return;
+
+	for (i = 0; i < ttm->num_pages; ++i)
+		ttm->pages[i]->mapping = ttm->bdev->dev_mapping;
+}
+
 int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 {
+	int ret;
+
 	if (ttm->state != tt_unpopulated)
 		return 0;
 
-	return ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
+	ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
+	if (!ret)
+		ttm_tt_add_mapping(ttm);
+	return ret;
 }
 
 static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
Signature · 6 lines
2.14.1

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