Skip to contentSkip to conversation

drm: add check if io_mem_pfn is NULL and cleanup

PATCH In review Tan Xiaojun 2 participants 15 messages Dec 25, 2017

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

v2 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.

Change logs of v2:
* add new function to instead of ttm_bo_default_io_mem_pfn() and do some cleanup.

Tan Xiaojun (12):
drm/ttm: add ttm_bo_io_mem_pfn to check io_mem_pfn 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: remove ttm_bo_default_io_mem_pfn

 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        | 22 +++++++++++++---------
 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, 13 insertions(+), 30 deletions(-)
Signature · 6 lines
2.7.4

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

PATCH v2 1/12 drm/ttm: add ttm_bo_io_mem_pfn to check io_mem_pfn

The io_mem_pfn field was added in commit ea642c3216cb ("drm/ttm: add io_mem_pfn callback") 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. And add new function ttm_bo_io_mem_pfn() as wrapper.

---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +12 -1
index c8ebb75..292d157 100644
@@ -92,6 +92,17 @@ static int ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
 	return ret;
 }
 
+static unsigned long ttm_bo_io_mem_pfn(struct ttm_buffer_object *bo,
+				       unsigned long page_offset)
+{
+	struct ttm_bo_device *bdev = bo->bdev;
+
+	if (bdev->driver->io_mem_pfn)
+		return bdev->driver->io_mem_pfn(bo, page_offset);
+
+	return ttm_bo_default_io_mem_pfn(bo, page_offset);
+}
+
 static int ttm_bo_vm_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
@@ -234,7 +245,7 @@ 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);
+			pfn = ttm_bo_io_mem_pfn(bo, page_offset);
 		} else {
 			page = ttm->pages[page_offset];
 			if (unlikely(!page && i == 0)) {
Signature · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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 · 6 lines
2.7.4

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

PATCH v2 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
#12 lore raw

PATCH v2 12/12 drm/ttm: remove ttm_bo_default_io_mem_pfn

In reply to Tan Xiaojun

No one will use this function except ttm_bo_io_mem_pfn() now, so move the calculation of ttm_bo_default_io_mem_pfn() into ttm_bo_io_mem_pfn() and do some cleanup.

---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 11 ++---------
 include/drm/ttm/ttm_bo_api.h    | 11 -----------
 2 files changed, 2 insertions(+), 20 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +2 -9
index 292d157..6edc19f 100644
@@ -100,7 +100,8 @@ static unsigned long ttm_bo_io_mem_pfn(struct ttm_buffer_object *bo,
 	if (bdev->driver->io_mem_pfn)
 		return bdev->driver->io_mem_pfn(bo, page_offset);
 
-	return ttm_bo_default_io_mem_pfn(bo, 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)
@@ -415,14 +416,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
maintainer
#13 lore raw
In reply to Tan Xiaojun

Series is Reviewed-by: Christian König <[email protected]>.

I'm going to pick that up for 4.16.

Thanks for the cleanup,
Christian.

Am 25.12.2017 um 04:43 schrieb Tan Xiaojun:

Quoted 31 lines

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.

Change logs of v2:
* add new function to instead of ttm_bo_default_io_mem_pfn() and do some cleanup.

Tan Xiaojun (12):
drm/ttm: add ttm_bo_io_mem_pfn to check io_mem_pfn 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: remove ttm_bo_default_io_mem_pfn

Quoted 14 lines
  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        | 22 +++++++++++++---------
  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, 13 insertions(+), 30 deletions(-)

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

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

Series is Reviewed-by: Christian König <[email protected]>.

I'm going to pick that up for 4.16.

Thanks for the cleanup,
Christian.

Thank you very much.
Xiaojun.

Quoted 49 lines

Am 25.12.2017 um 04:43 schrieb Tan Xiaojun:

Quoted 45 lines

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.

Change logs of v2:
* add new function to instead of ttm_bo_default_io_mem_pfn() and do some cleanup.

Tan Xiaojun (12):
drm/ttm: add ttm_bo_io_mem_pfn to check io_mem_pfn 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: remove ttm_bo_default_io_mem_pfn

  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        | 22 +++++++++++++---------
  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, 13 insertions(+), 30 deletions(-)

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