Skip to contentSkip to conversation

drm: add check if io_mem_pfn is NULL and cleanup

PATCH Superseded Tan Xiaojun 2 participants 15 messages Dec 24, 2017 – Dec 25, 2017

Subsystems (11)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover drm: add check if io_mem_pfn is NULL and cleanup

I found an OOPS when I used the mainline kernel for graphical tests in Hisilicon D05, I do not know how to solve this problem until I saw your discussion on this issue a month ago:

https://lists.freedesktop.org/archives/dri-devel/2017-November/159046.html

And my problem can be solved perfectly by your solution.

This is important for me, I want to solve this problem as soon as possible. So I follow the result of your discussion, make and send these patches below.

If anything is not good, please point it out, thanks.

Michal Srb (1):
drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL

Tan Xiaojun (11):
drm/ast: remove the default io_mem_pfn set drm/bochs: remove the default io_mem_pfn set drm/cirrus: remove the default io_mem_pfn set drm/mgag200: remove the default io_mem_pfn set drm/nouveau: remove the default io_mem_pfn set drm/qxl: remove the default io_mem_pfn set drm/radeon: remove the default io_mem_pfn set drm/virtio: remove the default io_mem_pfn set drm/vmwgfx: remove the default io_mem_pfn set
staging: remove the default io_mem_pfn set
drm/ttm: unexport ttm_bo_default_io_mem_pfn and make it static

 drivers/gpu/drm/ast/ast_ttm.c          |  1 -
 drivers/gpu/drm/bochs/bochs_mm.c       |  1 -
 drivers/gpu/drm/cirrus/cirrus_ttm.c    |  1 -
 drivers/gpu/drm/mgag200/mgag200_ttm.c  |  1 -
 drivers/gpu/drm/nouveau/nouveau_bo.c   |  1 -
 drivers/gpu/drm/qxl/qxl_ttm.c          |  1 -
 drivers/gpu/drm/radeon/radeon_ttm.c    |  1 -
 drivers/gpu/drm/ttm/ttm_bo_vm.c        | 28 +++++++++++++++++++---------
 drivers/gpu/drm/virtio/virtgpu_ttm.c   |  1 -
 drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c |  1 -
 drivers/staging/vboxvideo/vbox_ttm.c   |  1 -
 include/drm/ttm/ttm_bo_api.h           | 11 -----------
 12 files changed, 19 insertions(+), 30 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/12 drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL

From: Michal Srb <[email protected]>

The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447 and is called unconditionally. However, not all drivers were updated to set it.

Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.

---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +4 -1
index c8ebb75..e25a99b 100644
@@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
 		if (bo->mem.bus.is_iomem) {
 			/* Iomem should not be marked encrypted */
 			cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
-			pfn = bdev->driver->io_mem_pfn(bo, page_offset);
+			if (bdev->driver->io_mem_pfn)
+				pfn = bdev->driver->io_mem_pfn(bo, page_offset);
+			else
+				pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);
 		} else {
 			page = ttm->pages[page_offset];
 			if (unlikely(!page && i == 0)) {
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 01/12] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL

Am 24.12.2017 um 07:14 schrieb Tan Xiaojun:

Quoted 17 lines

From: Michal Srb <[email protected]>

The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447 and is called unconditionally. However, not all drivers were updated to set it.

Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.

---
  drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -0
index c8ebb75..e25a99b 100644

drivers/gpu/drm/ttm/ttm_bo_vm.c static int ttm_bo_vm_fault(struct vm_fault *vmf) · line 240

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo_vm.c +4 -1
@@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
  		if (bo->mem.bus.is_iomem) {
  			/* Iomem should not be marked encrypted */
  			cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
-			pfn = bdev->driver->io_mem_pfn(bo, page_offset);
+			if (bdev->driver->io_mem_pfn)
+				pfn = bdev->driver->io_mem_pfn(bo, page_offset);
+			else
+				pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);

Please move this check into a new function ttm_bo_io_mem_pfn().

You can then move the calculation of ttm_bo_default_io_mem_pfn() into this new function in patch #12 as well.

Regards,
Christian.

drivers/gpu/drm/ttm/ttm_bo_vm.c static int ttm_bo_vm_fault(struct vm_fault *vmf) · line 243

Quoted 3 lines
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -0
  		} else {
  			page = ttm->pages[page_offset];
  			if (unlikely(!page && i == 0)) {

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

#3 lore raw

Re: [PATCH 01/12] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL

Quoted 29 lines · Christian König

Am 24.12.2017 um 07:14 schrieb Tan Xiaojun:

Quoted 17 lines

From: Michal Srb <[email protected]>

The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447 and is called unconditionally. However, not all drivers were updated to set it.

Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.

---
  drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -0
index c8ebb75..e25a99b 100644

drivers/gpu/drm/ttm/ttm_bo_vm.c static int ttm_bo_vm_fault(struct vm_fault *vmf) · line 240

Quoted 8 lines
drivers/gpu/drm/ttm/ttm_bo_vm.c +4 -1
@@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
          if (bo->mem.bus.is_iomem) {
              /* Iomem should not be marked encrypted */
              cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
-            pfn = bdev->driver->io_mem_pfn(bo, page_offset);
+            if (bdev->driver->io_mem_pfn)
+                pfn = bdev->driver->io_mem_pfn(bo, page_offset);
+            else
+                pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);

Please move this check into a new function ttm_bo_io_mem_pfn().

Quoted 5 lines

You can then move the calculation of ttm_bo_default_io_mem_pfn() into this new function in patch #12 as well.

Regards,
Christian.

OK. Thank you for your reply. I will modify it and send v2.

Thanks.
Xiaojun.

Quoted 7 lines

drivers/gpu/drm/ttm/ttm_bo_vm.c static int ttm_bo_vm_fault(struct vm_fault *vmf) · line 243

Quoted 3 lines
drivers/gpu/drm/ttm/ttm_bo_vm.c +0 -0
          } else {
              page = ttm->pages[page_offset];
              if (unlikely(!page && i == 0)) {

.

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

#4 lore raw

PATCH 2/12 drm/ast: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/ast/ast_ttm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/ast/ast_ttm.c +0 -1
index 696a15d..fdd521d 100644
@@ -237,7 +237,6 @@ struct ttm_bo_driver ast_bo_driver = {
 	.verify_access = ast_bo_verify_access,
 	.io_mem_reserve = &ast_ttm_io_mem_reserve,
 	.io_mem_free = &ast_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int ast_mm_init(struct ast_private *ast)
Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/12 drm/bochs: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/bochs/bochs_mm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/bochs/bochs_mm.c +0 -1
index c4cadb6..857755a 100644
@@ -205,7 +205,6 @@ struct ttm_bo_driver bochs_bo_driver = {
 	.verify_access = bochs_bo_verify_access,
 	.io_mem_reserve = &bochs_ttm_io_mem_reserve,
 	.io_mem_free = &bochs_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int bochs_mm_init(struct bochs_device *bochs)
Signature · 1 line
2.7.4
#6 lore raw

PATCH 4/12 drm/cirrus: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/cirrus/cirrus_ttm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/cirrus/cirrus_ttm.c +0 -1
index 1ff1838..2c652af 100644
@@ -237,7 +237,6 @@ struct ttm_bo_driver cirrus_bo_driver = {
 	.verify_access = cirrus_bo_verify_access,
 	.io_mem_reserve = &cirrus_ttm_io_mem_reserve,
 	.io_mem_free = &cirrus_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int cirrus_mm_init(struct cirrus_device *cirrus)
Signature · 1 line
2.7.4
#7 lore raw

PATCH 5/12 drm/mgag200: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/mgag200/mgag200_ttm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/mgag200/mgag200_ttm.c +0 -1
index 3e7e1cd..89b550f 100644
@@ -237,7 +237,6 @@ struct ttm_bo_driver mgag200_bo_driver = {
 	.verify_access = mgag200_bo_verify_access,
 	.io_mem_reserve = &mgag200_ttm_io_mem_reserve,
 	.io_mem_free = &mgag200_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int mgag200_mm_init(struct mga_device *mdev)
Signature · 1 line
2.7.4
#8 lore raw

PATCH 6/12 drm/nouveau: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -1
index 435ff86..8de82a3 100644
@@ -1667,5 +1667,4 @@ struct ttm_bo_driver nouveau_bo_driver = {
 	.fault_reserve_notify = &nouveau_ttm_fault_reserve_notify,
 	.io_mem_reserve = &nouveau_ttm_io_mem_reserve,
 	.io_mem_free = &nouveau_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
Signature · 1 line
2.7.4
#9 lore raw

PATCH 7/12 drm/qxl: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/qxl/qxl_ttm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/qxl/qxl_ttm.c +0 -1
index ab48238..a86eaf9 100644
@@ -393,7 +393,6 @@ static struct ttm_bo_driver qxl_bo_driver = {
 	.verify_access = &qxl_verify_access,
 	.io_mem_reserve = &qxl_ttm_io_mem_reserve,
 	.io_mem_free = &qxl_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 	.move_notify = &qxl_bo_move_notify,
 };
 
Signature · 1 line
2.7.4
#10 lore raw

PATCH 8/12 drm/radeon: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/radeon/radeon_ttm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/radeon/radeon_ttm.c +0 -1
index 6ada64d..8595c76 100644
@@ -844,7 +844,6 @@ static struct ttm_bo_driver radeon_bo_driver = {
 	.fault_reserve_notify = &radeon_bo_fault_reserve_notify,
 	.io_mem_reserve = &radeon_ttm_io_mem_reserve,
 	.io_mem_free = &radeon_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int radeon_ttm_init(struct radeon_device *rdev)
Signature · 1 line
2.7.4
#11 lore raw

PATCH 9/12 drm/virtio: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/virtio/virtgpu_ttm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_ttm.c +0 -1
index cd389c5..4a12434 100644
@@ -431,7 +431,6 @@ static struct ttm_bo_driver virtio_gpu_bo_driver = {
 	.verify_access = &virtio_gpu_verify_access,
 	.io_mem_reserve = &virtio_gpu_ttm_io_mem_reserve,
 	.io_mem_free = &virtio_gpu_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 	.move_notify = &virtio_gpu_bo_move_notify,
 	.swap_notify = &virtio_gpu_bo_swap_notify,
 };
Signature · 1 line
2.7.4
#12 lore raw

PATCH 10/12 drm/vmwgfx: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +0 -1
index c705632..828dd59 100644
@@ -859,5 +859,4 @@ struct ttm_bo_driver vmw_bo_driver = {
 	.fault_reserve_notify = &vmw_ttm_fault_reserve_notify,
 	.io_mem_reserve = &vmw_ttm_io_mem_reserve,
 	.io_mem_free = &vmw_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
Signature · 1 line
2.7.4
#13 lore raw

PATCH 11/12 staging: remove the default io_mem_pfn set

In reply to Tan Xiaojun

The default interface situation has been taken into the framework, so remove the default set of each module.

---
 drivers/staging/vboxvideo/vbox_ttm.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/vboxvideo/vbox_ttm.c +0 -1
index 4eb410a..4da1723 100644
@@ -241,7 +241,6 @@ static struct ttm_bo_driver vbox_bo_driver = {
 	.verify_access = vbox_bo_verify_access,
 	.io_mem_reserve = &vbox_ttm_io_mem_reserve,
 	.io_mem_free = &vbox_ttm_io_mem_free,
-	.io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int vbox_mm_init(struct vbox_private *vbox)
Signature · 1 line
2.7.4
#14 lore raw

PATCH 12/12 drm/ttm: unexport ttm_bo_default_io_mem_pfn and make it static

In reply to Tan Xiaojun

No one will use this function except in ttm_bo_vm.c now. So unexport it and make it static.

---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 23 +++++++++++++++--------
 include/drm/ttm/ttm_bo_api.h    | 11 -----------
 2 files changed, 15 insertions(+), 19 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +15 -8
index e25a99b..ff70fc96 100644
@@ -92,6 +92,21 @@ static int ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
 	return ret;
 }
 
+/**
+ * ttm_bo_default_iomem_pfn - get a pfn for a page offset
+ *
+ * @bo: the BO we need to look up the pfn for
+ * @page_offset: offset inside the BO to look up.
+ *
+ * Calculate the PFN for iomem based mappings during page fault
+ */
+static unsigned long ttm_bo_default_io_mem_pfn(struct ttm_buffer_object *bo,
+					       unsigned long page_offset)
+{
+	return ((bo->mem.bus.base + bo->mem.bus.offset) >> PAGE_SHIFT)
+		+ page_offset;
+}
+
 static int ttm_bo_vm_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
@@ -407,14 +422,6 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
 	return bo;
 }
 
-unsigned long ttm_bo_default_io_mem_pfn(struct ttm_buffer_object *bo,
-					unsigned long page_offset)
-{
-	return ((bo->mem.bus.base + bo->mem.bus.offset) >> PAGE_SHIFT)
-		+ page_offset;
-}
-EXPORT_SYMBOL(ttm_bo_default_io_mem_pfn);
-
 int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
 		struct ttm_bo_device *bdev)
 {
include/drm/ttm/ttm_bo_api.h +0 -11
index fa07be1..0b1ce05 100644
@@ -711,17 +711,6 @@ extern int ttm_fbdev_mmap(struct vm_area_struct *vma,
 			  struct ttm_buffer_object *bo);
 
 /**
- * ttm_bo_default_iomem_pfn - get a pfn for a page offset
- *
- * @bo: the BO we need to look up the pfn for
- * @page_offset: offset inside the BO to look up.
- *
- * Calculate the PFN for iomem based mappings during page fault
- */
-unsigned long ttm_bo_default_io_mem_pfn(struct ttm_buffer_object *bo,
-				        unsigned long page_offset);
-
-/**
  * ttm_bo_mmap - mmap out of the ttm device address space.
  *
  * @filp:      filp as input from the mmap method.
Signature · 1 line
2.7.4