drm/ttm: Refuse to fault (prime-) imported pages
Subsystems (3)
PATCH 1/1 drm/ttm: Refuse to fault (prime-) imported pages
This is illegal for at least two reasons:
1) While it may work on some platforms / iommus, obtaining page pointers from mapped sg-lists is illegal, since the DMA API allows page pointer information to be destroyed in the sg mapping process.
2) TTM has no way of determining the linear kernel map caching state of the underlying pages. PTEs with conflicting caching state pointing to the same pfn is not allowed.
TTM operations touching pages of imported sg-tables should be redirected through the proper dma-buf operations.
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/ttm/ttm_bo_vm.c +9 -0
@@ -132,6 +132,15 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)return VM_FAULT_NOPAGE ; } +/* +* Refuse to fault imported pages. This should be handled +* (if at all) by redirecting mmap to the exporter. +*/ +if (bo->ttm && (bo->ttm->page_flags &TTM_PAGE_FLAG_SG )) { + retval =VM_FAULT_SIGBUS ; + goto out_unlock; + } +if (bdev->driver->fault_reserve_notify) { ret = bdev->driver->fault_reserve_notify (bo);switch (ret) {
Signature · 1 line
1.7.10.4
Quoted 6 lines · Thomas Hellstrom
This is illegal for at least two reasons:
1) While it may work on some platforms / iommus, obtaining page pointers from mapped sg-lists is illegal, since the DMA API allows page pointer information to be destroyed in the sg mapping process.
Quoted 8 lines
2) TTM has no way of determining the linear kernel map caching state of the underlying pages. PTEs with conflicting caching state pointing to the same pfn is not allowed.
TTM operations touching pages of imported sg-tables should be redirected through the proper dma-buf operations.
Signed-off-by Thomas Hellstrom <[email protected]>
Shouldn't we do something similar in the kmap helpers ttm_bo_util.c like ttm_bo_kmap and ttm_bo_move_memcpy? Maybe just a BUG to catch driver bugs. Otherwise this sounds like the right thing to do, so Acked. -Daniel
Quoted 30 lines
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/gpu/drm/ttm/ttm_bo_vm.c +9
-0@@ -132,6 +132,15 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)return VM_FAULT_NOPAGE ; } +/* +* Refuse to fault imported pages. This should be handled +* (if at all) by redirecting mmap to the exporter. +*/ +if (bo->ttm && (bo->ttm->page_flags &TTM_PAGE_FLAG_SG )) { + retval =VM_FAULT_SIGBUS ; + goto out_unlock; + } +if (bdev->driver->fault_reserve_notify) { ret = bdev->driver->fault_reserve_notify (bo);switch (ret) {Signature · 5 lines
1.7.10.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 11 lines · Daniel Vetter
Quoted 10 lines · Thomas Hellstrom
This is illegal for at least two reasons:
1) While it may work on some platforms / iommus, obtaining page pointers from mapped sg-lists is illegal, since the DMA API allows page pointer information to be destroyed in the sg mapping process.
2) TTM has no way of determining the linear kernel map caching state of the underlying pages. PTEs with conflicting caching state pointing to the same pfn is not allowed.
Quoted 8 lines
Quoted 4 lines
TTM operations touching pages of imported sg-tables should be redirected through the proper dma-buf operations.
Signed-off-by Thomas Hellstrom <[email protected]>Shouldn't we do something similar in the kmap helpers
ttm_bo_util.clikettm_bo_kmapandttm_bo_move_memcpy? Maybe just a BUG to catch driver bugs. Otherwise this sounds like the right thing to do, so Acked. -Daniel
Indeed, although I think that TTM should by default reroute the ttm_bo_kmap operations through the
correct dma-buf ops. Haven't gotten around to do that yet.
/Thomas
Quoted 30 lines
Quoted 30 lines
--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/gpu/drm/ttm/ttm_bo_vm.c +9
-0@@ -132,6 +132,15 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)return VM_FAULT_NOPAGE ; } +/* +* Refuse to fault imported pages. This should be handled +* (if at all) by redirecting mmap to the exporter. +*/ +if (bo->ttm && (bo->ttm->page_flags &TTM_PAGE_FLAG_SG )) { + retval =VM_FAULT_SIGBUS ; + goto out_unlock; + } +if (bdev->driver->fault_reserve_notify) { ret = bdev->driver->fault_reserve_notify (bo);switch (ret) {Signature · 5 lines
1.7.10.4 _______________________________________________ dri-devel mailing list [email protected] https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/dri-devel&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=l5Ago9ekmVFZ3c4M6eauqrJWGwjf6fTb%2BP3CxbBFkVM%3D%0A&m=3HWzF0bywXXmhWUQ1pCmbecMKkpEmnzo1A%2FnuPHbTX8%3D%0A&s=7209cea9c0020dea424c53ca15e12218f0370076ed1105a55775ea3d39a2b267