drm/amdgpu: Add gem_prime_mmap support
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: Add gem_prime_mmap support
v2: drop hdp invalidate/flush.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77 ++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
@@ -395,11 +395,14 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags); +struct drm_gem_object *amdgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj);struct reservation_object *amdgpu_gem_prime_res_obj (struct drm_gem_object *);void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj);void amdgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock.
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj,
@@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table, .gem_prime_vmap = amdgpu_gem_prime_vmap, .gem_prime_vunmap = amdgpu_gem_prime_vunmap, + .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +76 -1
96 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ 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): 1505342358-21512-1-git-send-email-Samuel.Li-5C7GfCeVMHo@public.gmane.org
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 69 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77 ++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -395,11 +395,14 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags); +struct drm_gem_object *amdgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj);struct reservation_object *amdgpu_gem_prime_res_obj (struct drm_gem_object *);void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj);void amdgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj,@@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table, .gem_prime_vmap = amdgpu_gem_prime_vmap, .gem_prime_vunmap = amdgpu_gem_prime_vunmap, + .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +12
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ;
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) · line 81
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +10
-0+ +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start) +return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff =amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ;
Maybe better use "vma->vm_pgoff += amdgpu_bo_mmap_offset(bo) >> PAGE_SHIFT;", but I'm not sure.
How other drivers handle this?
Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +27
-0+ +/* prime mmap does not need to check access, so allow here */ + ret =drm_vma_node_allow (&obj->vma_node, vma->vm_file->private_data); +if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, vma->vm_file->private_data); + +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach,@@ -130,14 +164,55 @@ struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access (struct dma_buf *dma_buf,enum dma_data_direction direction) +{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access (struct dma_buf *dma_buf,enum dma_data_direction direction) +{ +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; +struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags) {struct amdgpu_bo *bo =gem_to_amdgpu_bo (gobj); +struct dma_buf *dma_buf;
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj) · line 195
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-1if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); -return drm_gem_prime_export (dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access = amdgpu_gem_begin_cpu_access; + amdgpu_dmabuf_ops.end_cpu_access = amdgpu_gem_end_cpu_access; + dma_buf->ops = &amdgpu_dmabuf_ops;
This isn't race free and needs to be fixed.
Better add callbacks to drm_prime.c similar to drm_gem_dmabuf_mmap().
Alternative you could just completely drop amdgpu_gem_begin_cpu_access() and amdgpu_gem_end_cpu_access() as well.
When the buffer is shared between device it is pinned anyway and when it isn't shared ttm_bo_mmap() is able to handle VRAM mappings as well.
Regards,
Christian.
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +13
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf) +{ +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/*
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj) · line 218
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9
-0+* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
_______________________________________________
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): f68eaecb-ee43-78ba-2609-2ff6bb53ac50-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 3 lines
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;", but I'm not sure. How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a fake offset here.
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar todrm_gem_dmabuf_mmap().
What do you mean "This isn't race free"?
Regards,
Sam
Quoted 155 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 66 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77 ++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -395,11 +395,14 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags); +struct drm_gem_object *amdgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj);struct reservation_object *amdgpu_gem_prime_res_obj (struct drm_gem_object *);void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj);void amdgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj,@@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table, .gem_prime_vmap = amdgpu_gem_prime_vmap, .gem_prime_vunmap = amdgpu_gem_prime_vunmap, + .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +11
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) +{ + struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ;drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) · line 80
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +10
-0+ +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start) +return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff =amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;", but I'm not sure.How other drivers handle this?
Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +25
-0+ +/* prime mmap does not need to check access, so allow here */ + ret =drm_vma_node_allow (&obj->vma_node, vma->vm_file->private_data); +if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, vma->vm_file->private_data); + +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach,@@ -130,14 +164,55 @@ struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction) +{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access (struct dma_buf *dma_buf,enum dma_data_direction direction) +{ +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; +struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags) {drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj) · line 193
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0struct amdgpu_bo *bo =gem_to_amdgpu_bo (gobj); +struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access = amdgpu_gem_begin_cpu_access; + amdgpu_dmabuf_ops.end_cpu_access = amdgpu_gem_end_cpu_access; + dma_buf->ops = &amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar todrm_gem_dmabuf_mmap().Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()andamdgpu_gem_end_cpu_access()as well.When the buffer is shared between device it is pinned anyway and when it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings as well.Regards,
Christian.Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +15
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf) +{ +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf.
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj) · line 218
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
_______________________________________________
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): b1064525-5b36-1c12-4da6-aa4a805caaec-5C7GfCeVMHo@public.gmane.org
Quoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj) · line 195
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access = amdgpu_gem_begin_cpu_access; + amdgpu_dmabuf_ops.end_cpu_access = amdgpu_gem_end_cpu_access; + dma_buf->ops = &amdgpu_dmabuf_ops;
What happens when another thread is using amdgpu_dmabuf_ops to call begin_cpu_access/end_cpu_access when you are fixing it up again?
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.
Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;", but I'm not sure. How other drivers handle this?This is a good catch. Looks like pgoff is honored during prime mmap, not a fake offset here.
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar todrm_gem_dmabuf_mmap().
Quoted 170 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 162 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 66 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77 ++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -395,11 +395,14 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags); +struct drm_gem_object *amdgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj);struct reservation_object *amdgpu_gem_prime_res_obj (struct drm_gem_object *);void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj);void amdgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj,@@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table, .gem_prime_vmap = amdgpu_gem_prime_vmap, .gem_prime_vunmap = amdgpu_gem_prime_vunmap, + .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +11
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) +{ + struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ;drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) · line 80
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +10
-0+ +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start) +return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff =amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;", but I'm not sure.How other drivers handle this?
Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +25
-0+ +/* prime mmap does not need to check access, so allow here */ + ret =drm_vma_node_allow (&obj->vma_node, vma->vm_file->private_data); +if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, vma->vm_file->private_data); + +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach,@@ -130,14 +164,55 @@ struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj)return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_direction direction) +{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access (struct dma_buf *dma_buf,enum dma_data_direction direction) +{ +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; +struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags) {drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *obj) · line 193
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0struct amdgpu_bo *bo =gem_to_amdgpu_bo (gobj); +struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access = amdgpu_gem_begin_cpu_access; + amdgpu_dmabuf_ops.end_cpu_access = amdgpu_gem_end_cpu_access; + dma_buf->ops = &amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar todrm_gem_dmabuf_mmap().Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()andamdgpu_gem_end_cpu_access()as well.When the buffer is shared between device it is pinned anyway and when it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings as well.Regards,
Christian.Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +22
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *dma_buf) +{ +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
_______________________________________________
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): f0a22ddb-d747-6d93-adf3-428fd10f0ab5-5C7GfCeVMHo@public.gmane.org
Quoted 2 lines
What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?
Right, that is an issue.
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be dropped (other drivers implemented too), so I would like to keep it there for now.
Sam
Quoted 209 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportQuoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;", but I'm not sure.Quoted 2 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@ amdgpu_gem_prime_import_sg_table(struct
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 398
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags); +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 402
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj); struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj);void amdgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct +vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1.gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0+ .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +14
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) +{ + struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start)Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff =amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;", but I'm not sure.Quoted 7 lines
Quoted 6 lines
How other drivers handle this?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ +/* prime mmap does not need to check access, so allow here */ + ret = drm_vma_node_allow(&obj->vma_node, vma->vm_file-
private_data);Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0+if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data);Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+ +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, @@ -130,14+164,55 @@ struct
reservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv;}
+static int amdgpu_gem_begin_cpu_access(structdma_buf*dma_buf,
enumdma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,enum
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; +struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags) {Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 8 lines
struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 2 lines
Quoted 2 lines
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()andamdgpu_gem_end_cpu_access()as well.Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings as well.Quoted 4 lines
Quoted 4 lines
Regards,
Christian.
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +16
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
_______________________________________________
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): BLUPR12MB06283E58EC4B6434D71DCF50F5610-7LeqcoF/[email protected]
Am 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 3 lines
Quoted 2 lines
What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be able to deal with that.
Quoted 5 lines
Quoted 4 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be dropped (other drivers implemented too), so I would like to keep it there for now.
Wait a second what do you mean with "CPU access needs synchronization"?
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
Regards,
Christian.
Quoted 221 lines
Sam
Quoted 217 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportQuoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;", but I'm not sure.Quoted 2 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@ amdgpu_gem_prime_import_sg_table(struct
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 398
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags); +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h amdgpu_gem_prime_import_sg_table(struct · line 402
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj); struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj);void amdgpu_gem_prime_vunmap (struct drm_gem_object *obj,void *vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct +vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1.gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0+ .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +14
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) +{ + struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start)Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff =amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;", but I'm not sure.Quoted 6 lines
Quoted 5 lines
How other drivers handle this?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ +/* prime mmap does not need to check access, so allow here */ + ret = drm_vma_node_allow(&obj->vma_node, vma->vm_file-
private_data);Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0+if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data);Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+ +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, @@ -130,14+164,55 @@ struct
reservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf *dma_buf,enum
dma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,enum
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; +struct dma_buf *amdgpu_gem_prime_export (struct drm_device *dev,struct drm_gem_object *gobj,int flags) {Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 8 lines
struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()andamdgpu_gem_end_cpu_access()as well.Quoted 1 line
Quoted 1 line
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings as well.Quoted 8 lines
Quoted 8 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
_______________________________________________
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): ddf0fe6c-4de7-ae03-a61f-30e3cc1cf315-5C7GfCeVMHo@public.gmane.org
Quoted 2 lines
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
During pining, it will all the fences to finish. That shall be OK.
Sam
Quoted 265 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 12:21 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportAm 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 3 lines
Quoted 2 lines
What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be able to deal with that.
Quoted 5 lines
Quoted 4 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be
dropped (other drivers implemented too), so I would like to keep it there for now.
Wait a second what do you mean with "CPU access needs synchronization"?
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
Regards,
Christian.Quoted 9 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 17 lines
Quoted 17 lines
Quoted 2 lines
What do you mean "This isn't race free"?
Take a look at the code again:
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Quoted 6 lines
Quoted 6 lines
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 26 lines
Quoted 26 lines
PAGE_SHIFT;", but I'm not sure.Quoted 3 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 2 lines
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct dma_buf *amdgpu_gem_prime_export(struct drm_device*dev,
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 398
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct drm_gem_object *gobj, int flags); +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 402
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj); struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj); void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj,void
Quoted 34 lines
Quoted 34 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0*vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct +vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1.gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0+ .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 59
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +14
-0vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff =amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ;Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 32 lines
Quoted 32 lines
PAGE_SHIFT;", but I'm not sure.Quoted 6 lines
Quoted 5 lines
How other drivers handle this?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ +/* prime mmap does not need to check access, so allow here */ + ret = drm_vma_node_allow(&obj->vma_node, vma->vm_file-
private_data);Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0+if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data);Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+ +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, @@ -130,14+164,55 @@ struct
reservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf
*dma_buf, enumdma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,enum
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; + struct dma_buf *amdgpu_gem_prime_export(struct drm_device*dev,
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 11 lines
struct drm_gem_object *gobj, int flags) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
Quoted 8 lines
Quoted 8 lines
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()andamdgpu_gem_end_cpu_access()as
Quoted 22 lines
Quoted 22 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings as well.Quoted 8 lines
Quoted 8 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf.
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
_______________________________________________
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): BLUPR12MB06286EB4DD86B34C84F124EAF5610-7LeqcoF/[email protected]
Am 20.09.2017 um 19:34 schrieb Li, Samuel:
Quoted 3 lines
Quoted 2 lines
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
During pining, it will all the fences to finish. That shall be OK.
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more.
It doesn't wait for anything.
Christian.
Quoted 266 lines
Sam
Quoted 261 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 12:21 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportAm 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 3 lines
Quoted 2 lines
What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be able to deal with that.
Quoted 4 lines
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be
dropped (other drivers implemented too), so I would like to keep it there for now.
Wait a second what do you mean with "CPU access needs synchronization"?
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
Regards,
Christian.Quoted 8 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 16 lines
Quoted 16 lines
Quoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Quoted 6 lines
Quoted 6 lines
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 26 lines
Quoted 26 lines
PAGE_SHIFT;", but I'm not sure.Quoted 3 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 2 lines
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct dma_buf *amdgpu_gem_prime_export(struct drm_device*dev,
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 398
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct drm_gem_object *gobj, int flags); +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 402
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj); struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj); void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj,void
Quoted 34 lines
Quoted 34 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0*vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct +vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1.gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0+ .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 59
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +14
-0vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff =amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ;Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 32 lines
Quoted 32 lines
PAGE_SHIFT;", but I'm not sure.Quoted 6 lines
Quoted 5 lines
How other drivers handle this?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ +/* prime mmap does not need to check access, so allow here */ + ret = drm_vma_node_allow(&obj->vma_node, vma->vm_file-
private_data);Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0+if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data);Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+ +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, @@ -130,14+164,55 @@ struct
reservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf
*dma_buf, enumdma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,enum
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; + struct dma_buf *amdgpu_gem_prime_export(struct drm_device*dev,
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 11 lines
struct drm_gem_object *gobj, int flags) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
Quoted 8 lines
Quoted 8 lines
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()andamdgpu_gem_end_cpu_access()as
Quoted 22 lines
Quoted 22 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings as well.Quoted 8 lines
Quoted 8 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
_______________________________________________
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): 70db5b39-546e-ac15-635e-dad73420e8bc-5C7GfCeVMHo@public.gmane.org
Quoted 2 lines
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more. It doesn't wait for anything.
It does. The following is from amdgpu_gem_prime_pin(),
91 * Wait for all shared fences to complete before we switch to future
92 * use of exclusive fence on this prime shared bo.
93 */
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
95 MAX_SCHEDULE_TIMEOUT);
96 if (unlikely(ret < 0)) {
97 DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
98 amdgpu_bo_unreserve(bo);
99 return ret;100 }
Besides, pinning process prepares all the stuff before and after moving buffer(ttm_bo_validate, amdgpu_ttm_bind), I think if a buffer can be moved, it is probably also in a good condition to be accessed.
Sam
Quoted 303 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 1:38 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportAm 20.09.2017 um 19:34 schrieb Li, Samuel:
Quoted 3 lines
Quoted 2 lines
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
During pining, it will all the fences to finish. That shall be OK.
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more.
It doesn't wait for anything.
Christian.
Quoted 10 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 12:21 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 3 lines
Quoted 3 lines
Am 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 1 line
Quoted 1 line
What happens when another thread is using
amdgpu_dmabuf_opstocall
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
begin_cpu_access/end_cpu_access when you are fixing it up again?
Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be able
to
Quoted 11 lines
Quoted 11 lines
deal with that.
Quoted 5 lines
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be
dropped (other drivers implemented too), so I would like to keep it there for now.
Wait a second what do you mean with "CPU access needs
synchronization"?
Quoted 21 lines
Quoted 21 lines
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
Regards,
Christian.Quoted 8 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opstocall
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
begin_cpu_access/end_cpu_access when you are fixing it up again?
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;Quoted 37 lines
Quoted 37 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 26 lines
Quoted 26 lines
PAGE_SHIFT;", but I'm not sure.Quoted 3 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 4 lines
Quoted 4 lines
*dev,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct drm_gem_object *gobj, int flags); +struct drm_gem_object *amdgpu_gem_prime_import(structQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 402
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj); struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj); void amdgpu_gem_prime_vunmap(struct drm_gem_object*obj,
Quoted 3 lines
Quoted 3 lines
void
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0*vaddr); +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock.
Quoted 49 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-2- .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843 ,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0+ .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 59
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); + struct amdgpu_device *adev = amdgpu_ttm_adev(bo-tbo.bdev);
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +10
-0+unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+if (asize < vma->vm_end - vma->vm_start) +return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff = amdgpu_bo_mmap_offset(bo) >>
PAGE_SHIFT;Quoted 25 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 23 lines
Quoted 23 lines
PAGE_SHIFT;", but I'm not sure.Quoted 6 lines
Quoted 5 lines
How other drivers handle this?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ +/* prime mmap does not need to check access, so allow here */ + ret = drm_vma_node_allow(&obj->vma_node, vma->vm_file-
private_data);Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data); +Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct
dma_buf_attachment*attach, @@
-130,14
+164,55 @@ structreservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf
*dma_buf, enumdma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf
*dma_buf,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
enum
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; + struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 14 lines
Quoted 14 lines
*dev,
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 11 lines
struct drm_gem_object *gobj, int flags) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()and
amdgpu_gem_end_cpu_access()Quoted 5 lines
Quoted 5 lines
as
Quoted 4 lines
Quoted 4 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings aswell.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf.
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
_______________________________________________
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): BLUPR12MB0628DCFA21305B174B919D9EF5610-7LeqcoF/[email protected]
Am 20.09.2017 um 19:47 schrieb Li, Samuel:
Quoted 9 lines
Quoted 2 lines
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more. It doesn't wait for anything.
It does. The following is from
amdgpu_gem_prime_pin(),
91 * Wait for all shared fences to complete before we switch to future
92 * use of exclusive fence on this prime shared bo.
93 */
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
95MAX_SCHEDULE_TIMEOUT);
96 if (unlikely(ret < 0)) {
Quoted 6 lines
97 DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret); 98 amdgpu_bo_unreserve(bo); 99 return ret;100 }
Besides, pinning process prepares all the stuff before and after moving
buffer(ttm_bo_validate, amdgpu_ttm_bind),
No, you misunderstood what this is good for.
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel driver.
As soon the the BO is exported that shouldn't wait for anything any more.
Quoted 1 line
I think if a buffer can be moved, it is probably also in a good condition to be accessed.
That is complete nonsense.
ttm_bo_validate() is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.
amdgpu_ttm_bind() in turn binds the BO to the GART space and isn't related to CPU access either.
What you most likely need to do here is to use reservation_object_wait_timeout_rcu() to wait for all GPU operations to end.
Regards,
Christian.
Quoted 306 lines
Sam
Quoted 303 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 1:38 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportAm 20.09.2017 um 19:34 schrieb Li, Samuel:
Quoted 3 lines
Quoted 2 lines
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
During pining, it will all the fences to finish. That shall be OK.
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more.
It doesn't wait for anything.
Christian.
Quoted 9 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 12:21 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Am 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 1 line
Quoted 1 line
What happens when another thread is using
amdgpu_dmabuf_opstocall
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
begin_cpu_access/end_cpu_access when you are fixing it up again?
Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be able
to
Quoted 11 lines
Quoted 11 lines
deal with that.
Quoted 5 lines
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be
dropped (other drivers implemented too), so I would like to keep it there for now.
Wait a second what do you mean with "CPU access needs
synchronization"?
Quoted 20 lines
Quoted 20 lines
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to finish.
Regards,
Christian.Quoted 8 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opstocall
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
begin_cpu_access/end_cpu_access when you are fixing it up again?
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;Quoted 37 lines
Quoted 37 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 26 lines
Quoted 26 lines
PAGE_SHIFT;", but I'm not sure.Quoted 3 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 4 lines
Quoted 4 lines
*dev,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct drm_gem_object *gobj, int flags); +struct drm_gem_object *amdgpu_gem_prime_import(structQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 402
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj); struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj); void amdgpu_gem_prime_vunmap(struct drm_gem_object*obj,
Quoted 3 lines
Quoted 3 lines
void
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0*vaddr); +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock.
Quoted 49 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-2- .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843 ,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0+ .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 59
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); + struct amdgpu_device *adev = amdgpu_ttm_adev(bo-tbo.bdev);
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +10
-0+unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+if (asize < vma->vm_end - vma->vm_start) +return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff = amdgpu_bo_mmap_offset(bo) >>
PAGE_SHIFT;Quoted 25 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 23 lines
Quoted 23 lines
PAGE_SHIFT;", but I'm not sure.Quoted 6 lines
Quoted 5 lines
How other drivers handle this?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ +/* prime mmap does not need to check access, so allow here */ + ret = drm_vma_node_allow(&obj->vma_node, vma->vm_file-
private_data);Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data); +Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct
dma_buf_attachment*attach, @@
-130,14
+164,55 @@ structreservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf
*dma_buf, enumdma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf
*dma_buf,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
enum
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; + struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 14 lines
Quoted 14 lines
*dev,
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 11 lines
struct drm_gem_object *gobj, int flags) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()and
amdgpu_gem_end_cpu_access()Quoted 5 lines
Quoted 5 lines
as
Quoted 4 lines
Quoted 4 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings aswell.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +13
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_get (obj); +return obj; + }
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ } + +return drm_gem_prime_import (dev, dma_buf); }_______________________________________________
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): 085926a6-90fc-2cf7-f05e-e762fa401fe8-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 2 lines
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel driver.
Actually here it is going to wait for all fences,
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true...
Quoted 5 lines
ttm_bo_validate()is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.Quoted 1 line
amdgpu_ttm_bind()in turn binds the BO to the GART space and isn't relatedto CPU access either.
ttm_bo_validate() can move buffer is necessary, and amdgpu_ttm_bind() will flush hdp, which we have discussed before.
Quoted 2 lines
What you most likely need to do here is to use
reservation_object_wait_timeout_rcu()to wait for all GPU operations to end.
Right, that is called by amdgpu_gem_prime_pin().
Sam
Quoted 368 lines
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, September 20, 2017 2:15 PM
To: Li, Samuel <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportAm 20.09.2017 um 19:47 schrieb Li, Samuel:
Quoted 7 lines
Quoted 2 lines
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more. It doesn't wait for anything.
It does. The following is from
amdgpu_gem_prime_pin(),
91 * Wait for all shared fences to complete before we switch to future
92 * use of exclusive fence on this prime shared bo.
93 */
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true,false,
Quoted 9 lines
95
MAX_SCHEDULE_TIMEOUT);
96 if (unlikely(ret < 0)) {97 DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret); 98 amdgpu_bo_unreserve(bo); 99 return ret;100 }
Besides, pinning process prepares all the stuff before and after moving
buffer(ttm_bo_validate, amdgpu_ttm_bind),No, you misunderstood what this is good for.
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel driver.
As soon the the BO is exported that shouldn't wait for anything any more.
Quoted 1 line
I think if a buffer can be moved, it is probably also in a good condition to be
accessed.
That is complete nonsense.
ttm_bo_validate()is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.
amdgpu_ttm_bind()in turn binds the BO to the GART space and isn't related to CPU access either.What you most likely need to do here is to use
reservation_object_wait_timeout_rcu()to wait for all GPU operations to end.Regards,
Christian.Quoted 8 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 1:38 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 4 lines
Quoted 4 lines
Am 20.09.2017 um 19:34 schrieb Li, Samuel:
Quoted 2 lines
Quoted 2 lines
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to
finish.
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
During pining, it will all the fences to finish. That shall be OK.
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more.
It doesn't wait for anything.
Christian.
Quoted 4 lines
Sam
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 12:21 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Am 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 1 line
Quoted 1 line
What happens when another thread is using
amdgpu_dmabuf_opsto
Quoted 4 lines
Quoted 4 lines
call
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
begin_cpu_access/end_cpu_access when you are fixing it up again?
Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be
able
Quoted 11 lines
Quoted 11 lines
to
Quoted 10 lines
Quoted 10 lines
deal with that.
Quoted 5 lines
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be
dropped (other drivers implemented too), so I would like to keep it there for now.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Wait a second what do you mean with "CPU access needs
synchronization"?
Quoted 5 lines
Quoted 5 lines
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to
finish.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Regards,
Christian.Quoted 7 lines
Sam
Quoted 4 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; amd-Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Add
gem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsto
Quoted 53 lines
Quoted 53 lines
call
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
begin_cpu_access/end_cpu_access when you are fixing it up again?
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;Quoted 37 lines
Quoted 37 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 26 lines
Quoted 26 lines
PAGE_SHIFT;", but I'm not sure.Quoted 3 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
*dev,
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 398
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct drm_gem_object *gobj, int flags); +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj); void amdgpu_gem_prime_unpin(struct drm_gem_object*obj);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 403
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void *amdgpu_gem_prime_vmap(struct drm_gem_object*obj);
Quoted 41 lines
Quoted 41 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 405
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void amdgpu_gem_prime_vunmap(struct drm_gem_object*obj,
Quoted 3 lines
Quoted 3 lines
void
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0*vaddr); +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another
lock.
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-2- .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843 ,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,
+ .gem_prime_mmap =amdgpu_gem_prime_mmap,
.name =DRIVER_NAME,
.desc =DRIVER_DESC, diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.cindex 5b3f928..13c977a 100644drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 59
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object*obj,
Quoted 25 lines
Quoted 25 lines
Quoted 16 lines
Quoted 5 lines
struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); + struct amdgpu_device *adev = amdgpu_ttm_adev(bo-tbo.bdev);
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +10
-0+unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+if (asize < vma->vm_end - vma->vm_start) +return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff = amdgpu_bo_mmap_offset(bo) >>
PAGE_SHIFT;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 5 lines
Quoted 5 lines
PAGE_SHIFT;", but I'm not sure.Quoted 4 lines
Quoted 4 lines
How other drivers handle this?
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2
-0+ +/* prime mmap does not need to check access, so allow here */
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 84
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1
-0+ ret = drm_vma_node_allow(&obj->vma_node, vma-vm_file-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
private_data);Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+if (ret) +return ret; + + ret = ttm_bo_mmap(vma->vm_file, vma, &adev-mman.bdev);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 96
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0+drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data); + +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device*dev,
Quoted 63 lines
Quoted 63 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
struct
dma_buf_attachment*attach, @@
-130,14
+164,55 @@ structreservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf
*dma_buf, enumdma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf
*dma_buf,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
enum
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; + struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 14 lines
Quoted 14 lines
*dev,
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 11 lines
struct drm_gem_object *gobj, int flags) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()and
amdgpu_gem_end_cpu_access()Quoted 5 lines
Quoted 5 lines
as
Quoted 4 lines
Quoted 4 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings aswell.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem
Quoted 15 lines
increases
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }_______________________________________________
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): BLUPR12MB0628E9219A8C44D7220AA5F8F5610-7LeqcoF/[email protected]
Am 20.09.2017 um 22:31 schrieb Li, Samuel:
Quoted 4 lines
Quoted 2 lines
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel driver.
Actually here it is going to wait for all fences,
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true...
That is actually a bug, we only need to wait here when prime_shared_count == 0.
Quoted 6 lines
Quoted 5 lines
ttm_bo_validate()is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.Quoted 1 line
amdgpu_ttm_bind()in turn binds the BO to the GART space and isn't relatedto CPU access either.
ttm_bo_validate()can move buffer is necessary,
No, that is a very common misconception.
ttm_bo_validate() schedules the buffer to be moved at some point in the future.
The only thing which saves us here is the fact that TTM waits for the move to be completed in it's page fault handler.
Quoted 1 line
and
amdgpu_ttm_bind()will flush hdp, which we have discussed before.
And as concluded before that is unnecessary.
Quoted 4 lines
Quoted 3 lines
What you most likely need to do here is to use
reservation_object_wait_timeout_rcu()to wait for all GPU operations to end.Right, that is called by
amdgpu_gem_prime_pin().
Please just completely drop the begin_cpu_access() and end_cpu_access() callbacks.
Checking other drivers the only one actually implementing something special is the i915 driver which needs to remove the BO from the GTT domain for cache coherency I think.
The omap driver implements those callbacks to grab an extra reference to the pages while they are access, we don't need to do this since TTM grabs an extra reference during the mmap anyway.
All other drivers implementing mmap (exynos, rockchip, tilcdc, arcpgu, msm, meson, etnaviv, sti, qxl, vc4, rcar-du, atmel-hlcdc, imx, mediatek, mali, vgem, fsl-dcu, zte, hisilicon, sun4i, mxsfb) don't have a begin/end callback.
Pinning the BO can actually cause problem with the display code when the BO needs to be scanned out, so we should avoid that as much as possible.
Regards,
Christian.
Quoted 381 lines
Sam
Quoted 378 lines
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, September 20, 2017 2:15 PM
To: Li, Samuel <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportAm 20.09.2017 um 19:47 schrieb Li, Samuel:
Quoted 7 lines
Quoted 2 lines
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more. It doesn't wait for anything.
It does. The following is from
amdgpu_gem_prime_pin(),
91 * Wait for all shared fences to complete before we switch to future
92 * use of exclusive fence on this prime shared bo.
93 */
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true,false,
Quoted 9 lines
95 MAX_SCHEDULE_TIMEOUT); 96 if (unlikely(ret < 0)) { 97 DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret); 98 amdgpu_bo_unreserve(bo); 99 return ret;100 }
Besides, pinning process prepares all the stuff before and after moving
buffer(ttm_bo_validate, amdgpu_ttm_bind),No, you misunderstood what this is good for.
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel driver.
As soon the the BO is exported that shouldn't wait for anything any more.
Quoted 1 line
I think if a buffer can be moved, it is probably also in a good condition to be
accessed.
That is complete nonsense.
ttm_bo_validate()is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.
amdgpu_ttm_bind()in turn binds the BO to the GART space and isn't related to CPU access either.What you most likely need to do here is to use
reservation_object_wait_timeout_rcu()to wait for all GPU operations to end.Regards,
Christian.Quoted 7 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 1:38 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 3 lines
Quoted 3 lines
Am 20.09.2017 um 19:34 schrieb Li, Samuel:
Quoted 2 lines
Quoted 2 lines
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to
finish.
Quoted 12 lines
Quoted 12 lines
Quoted 1 line
During pining, it will all the fences to finish. That shall be OK.
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more.
It doesn't wait for anything.
Christian.
Quoted 4 lines
Sam
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 12:21 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Am 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 1 line
Quoted 1 line
What happens when another thread is using
amdgpu_dmabuf_opsto
Quoted 4 lines
Quoted 4 lines
call
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
begin_cpu_access/end_cpu_access when you are fixing it up again?
Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be
able
Quoted 11 lines
Quoted 11 lines
to
Quoted 10 lines
Quoted 10 lines
deal with that.
Quoted 5 lines
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be
dropped (other drivers implemented too), so I would like to keep it there for now.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Wait a second what do you mean with "CPU access needs
synchronization"?
Quoted 5 lines
Quoted 5 lines
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to
finish.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Regards,
Christian.Quoted 7 lines
Sam
Quoted 4 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; amd-Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Add
gem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsto
Quoted 53 lines
Quoted 53 lines
call
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
begin_cpu_access/end_cpu_access when you are fixing it up again?
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;Quoted 37 lines
Quoted 37 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 26 lines
Quoted 26 lines
PAGE_SHIFT;", but I'm not sure.Quoted 3 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
*dev,
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 398
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct drm_gem_object *gobj, int flags); +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj); void amdgpu_gem_prime_unpin(struct drm_gem_object*obj);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 403
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void *amdgpu_gem_prime_vmap(struct drm_gem_object*obj);
Quoted 41 lines
Quoted 41 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 405
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void amdgpu_gem_prime_vunmap(struct drm_gem_object*obj,
Quoted 3 lines
Quoted 3 lines
void
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0*vaddr); +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another
lock.
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-2- .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843 ,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,
+ .gem_prime_mmap =amdgpu_gem_prime_mmap,
.name =DRIVER_NAME,
.desc =DRIVER_DESC, diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.cindex 5b3f928..13c977a 100644drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 59
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object*obj,
Quoted 25 lines
Quoted 25 lines
Quoted 16 lines
Quoted 5 lines
struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); + struct amdgpu_device *adev = amdgpu_ttm_adev(bo-tbo.bdev);
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +10
-0+unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+if (asize < vma->vm_end - vma->vm_start) +return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff = amdgpu_bo_mmap_offset(bo) >>
PAGE_SHIFT;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 5 lines
Quoted 5 lines
PAGE_SHIFT;", but I'm not sure.Quoted 4 lines
Quoted 4 lines
How other drivers handle this?
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +2
-0+ +/* prime mmap does not need to check access, so allow here */
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 84
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1
-0+ ret = drm_vma_node_allow(&obj->vma_node, vma-vm_file-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
private_data);Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+if (ret) +return ret; + + ret = ttm_bo_mmap(vma->vm_file, vma, &adev-mman.bdev);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 96
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0+drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data); + +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device*dev,
Quoted 63 lines
Quoted 63 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
struct
dma_buf_attachment*attach, @@
-130,14
+164,55 @@ structreservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct dma_buf
*dma_buf, enumdma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf
*dma_buf,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
enum
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; + struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 14 lines
Quoted 14 lines
*dev,
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 11 lines
struct drm_gem_object *gobj, int flags) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()and
amdgpu_gem_end_cpu_access()Quoted 5 lines
Quoted 5 lines
as
Quoted 4 lines
Quoted 4 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings aswell.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }_______________________________________________
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): ca08675a-7bb0-5e44-bb1f-dab3a0f14802-5C7GfCeVMHo@public.gmane.org
Quoted 5 lines
Please just completely drop the
begin_cpu_access()andend_cpu_access()callbacks.
Checking other drivers the only one actually implementing something special is the i915 driver which needs to remove the BO from the GTT domain for cache coherency I think.
Well, as the first step, we can drop the begin/end() callbacks for now, and revisit later.
Sam
Quoted 438 lines
-----Original Message-----
From: Koenig, Christian
Sent: Thursday, September 21, 2017 3:39 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportAm 20.09.2017 um 22:31 schrieb Li, Samuel:
Quoted 2 lines
Quoted 2 lines
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel
driver.
Quoted 2 lines
Actually here it is going to wait for all fences,
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true...That is actually a bug, we only need to wait here when
prime_shared_count== 0.Quoted 7 lines
Quoted 6 lines
ttm_bo_validate()is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.Quoted 2 lines
amdgpu_ttm_bind()in turn binds the BO to the GART space and isn't relatedto CPU access either.
ttm_bo_validate()can move buffer is necessary,No, that is a very common misconception.
ttm_bo_validate()schedules the buffer to be moved at some point in the future.The only thing which saves us here is the fact that TTM waits for the move to be completed in it's page fault handler.
Quoted 1 line
and
amdgpu_ttm_bind()will flush hdp, which we have discussed before.And as concluded before that is unnecessary.
Quoted 3 lines
Quoted 3 lines
What you most likely need to do here is to use
reservation_object_wait_timeout_rcu()to wait for all GPU operations toend.
Quoted 1 line
Right, that is called by
amdgpu_gem_prime_pin().Please just completely drop the
begin_cpu_access()andend_cpu_access()callbacks.Checking other drivers the only one actually implementing something special is the i915 driver which needs to remove the BO from the GTT domain for cache coherency I think.
The omap driver implements those callbacks to grab an extra reference to the pages while they are access, we don't need to do this since TTM grabs an extra reference during the mmap anyway.
All other drivers implementing mmap (exynos, rockchip, tilcdc, arcpgu, msm, meson, etnaviv, sti, qxl, vc4, rcar-du, atmel-hlcdc, imx, mediatek, mali, vgem, fsl-dcu, zte, hisilicon, sun4i, mxsfb) don't have a begin/end callback.
Pinning the BO can actually cause problem with the display code when the BO needs to be scanned out, so we should avoid that as much as possible.
Regards,
Christian.Quoted 9 lines
Sam
Quoted 6 lines
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, September 20, 2017 2:15 PM
To: Li, Samuel <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 6 lines
Quoted 6 lines
Am 20.09.2017 um 19:47 schrieb Li, Samuel:
Quoted 4 lines
Quoted 2 lines
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more. It doesn't wait for anything.
It does. The following is from
amdgpu_gem_prime_pin(),
91 * Wait for all shared fences to complete before we switch tofuture
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
92 * use of exclusive fence on this prime shared bo. 93 */ 94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true,false,
Quoted 7 lines
95 MAX_SCHEDULE_TIMEOUT); 96 if (unlikely(ret < 0)) { 97 DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret); 98 amdgpu_bo_unreserve(bo); 99 return ret;100 }
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Besides, pinning process prepares all the stuff before and after moving
buffer(ttm_bo_validate, amdgpu_ttm_bind),No, you misunderstood what this is good for.
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel
driver.
Quoted 13 lines
Quoted 13 lines
As soon the the BO is exported that shouldn't wait for anything any more.
Quoted 2 lines
I think if a buffer can be moved, it is probably also in a good condition to be
accessed.
That is complete nonsense.
ttm_bo_validate()is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.Quoted 5 lines
Quoted 5 lines
amdgpu_ttm_bind()in turn binds the BO to the GART space and isn't related to CPU access either.What you most likely need to do here is to use
reservation_object_wait_timeout_rcu()to wait for all GPU operations toend.
Quoted 24 lines
Quoted 24 lines
Regards,
Christian.Quoted 7 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 1:38 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 3 lines
Quoted 3 lines
Am 20.09.2017 um 19:34 schrieb Li, Samuel:
Quoted 2 lines
Quoted 2 lines
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to
finish.
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
During pining, it will all the fences to finish. That shall be OK.
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more.
It doesn't wait for anything.
Christian.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Sam
Quoted 4 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 12:21 PM
To: Li, Samuel <[email protected]>; amd-Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Add
gem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Am 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 1 line
Quoted 1 line
What happens when another thread is using
amdgpu_dmabuf_opsQuoted 3 lines
Quoted 3 lines
to
Quoted 2 lines
Quoted 2 lines
call
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
begin_cpu_access/end_cpu_access when you are fixing it up
again?
Quoted 28 lines
Quoted 28 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be
able
Quoted 11 lines
Quoted 11 lines
to
Quoted 10 lines
Quoted 10 lines
deal with that.
Quoted 5 lines
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be
dropped (other drivers implemented too), so I would like to keep it there for now.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Wait a second what do you mean with "CPU access needs
synchronization"?
Quoted 5 lines
Quoted 5 lines
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to
finish.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Regards,
Christian.Quoted 3 lines
Sam
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; amd-Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Add
gem_prime_mmapQuoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
support
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsQuoted 3 lines
Quoted 3 lines
to
Quoted 2 lines
Quoted 2 lines
call
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
begin_cpu_access/end_cpu_access when you are fixing it up
again?
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>
PAGE_SHIFT;Quoted 37 lines
Quoted 37 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 26 lines
Quoted 26 lines
PAGE_SHIFT;", but I'm not sure.Quoted 3 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 4 lines
Quoted 4 lines
*dev,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct drm_gem_object *gobj, int flags); +struct drm_gem_object *amdgpu_gem_prime_import(struct
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drm_device*dev,Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf); int amdgpu_gem_prime_pin(struct drm_gem_object*obj);
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 401
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void amdgpu_gem_prime_unpin(struct drm_gem_object*obj);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 403
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void *amdgpu_gem_prime_vmap(struct drm_gem_object*obj);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void amdgpu_gem_prime_vunmap(struct
drm_gem_objectQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
*obj,
Quoted 3 lines
Quoted 3 lines
void
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0*vaddr); +int amdgpu_gem_prime_mmap(struct drm_gem_object*obj,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
struct
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+vm_area_struct *vma); int amdgpu_gem_debugfs_init(struct amdgpu_device*adev);
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
/* sub-allocation manager, it has to be protectedby another
lock.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = {Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = { · line 841
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-1.prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj,@@
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
-843,6
+843,7 @@ static structdrm_driverkms_driver= {
.gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,
+ .gem_prime_mmap =amdgpu_gem_prime_mmap,
.name =DRIVER_NAME,
.desc =DRIVER_DESC, diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.cindex 5b3f928..13c977a 100644drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ voidamdgpu_gem_prime_vunmap(struct
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drm_gem_object*obj, void *vaddr)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object*obj,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); + struct amdgpu_device *adev = amdgpu_ttm_adev(bo-tbo.bdev);
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL )Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void · line 78
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+return -ENODEV ; + +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start) +return -EINVAL ; + + if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) || + (bo->flags &
AMDGPU_GEM_CREATE_NO_CPU_ACCESS)) {Quoted 89 lines
Quoted 89 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void · line 81
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+return -EPERM ; + } + vma->vm_pgoff = amdgpu_bo_mmap_offset(bo) >>
PAGE_SHIFT;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 6 lines
Quoted 6 lines
PAGE_SHIFT;", but I'm not sure.Quoted 5 lines
Quoted 5 lines
How other drivers handle this?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ +/* prime mmap does not need to check access, so allow +here */
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void · line 85
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +1
-0+ ret = drm_vma_node_allow(&obj->vma_node, vma-vm_file-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
private_data);Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+if (ret) +return ret; + + ret = ttm_bo_mmap(vma->vm_file, vma, &adev-mman.bdev);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0+drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data); + +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device*dev,
Quoted 59 lines
Quoted 59 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
struct
dma_buf_attachment*attach,
@@
-130,14
+164,55 @@ structreservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
return bo->tbo.resv; } +static int amdgpu_gem_begin_cpu_access(struct
dma_buf*dma_buf, enumdma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf
*dma_buf,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
enum
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; + struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 14 lines
Quoted 14 lines
*dev,
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 11 lines
struct drm_gem_object *gobj, int flags) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()and
amdgpu_gem_end_cpu_access()Quoted 6 lines
Quoted 6 lines
as
Quoted 5 lines
Quoted 5 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings aswell.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Regards,
Christian.
Quoted 30 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
Quoted 23 lines
Quoted 23 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drm_device*dev,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }_______________________________________________
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): BLUPR12MB0628E666BD4B7BD7483B9F63F5660-7LeqcoF/[email protected]
Am 21.09.2017 um 16:31 schrieb Li, Samuel:
Quoted 6 lines
Quoted 5 lines
Please just completely drop the
begin_cpu_access()andend_cpu_access()callbacks.
Checking other drivers the only one actually implementing something special is the i915 driver which needs to remove the BO from the GTT domain for cache coherency I think.Well, as the first step, we can drop the begin/end() callbacks for now, and revisit later.
Yeah, that's something I can perfectly live with. How about adding an in code comment and noting it in the commit message?
Christian.
Quoted 460 lines
Sam
Quoted 457 lines
-----Original Message-----
From: Koenig, Christian
Sent: Thursday, September 21, 2017 3:39 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportAm 20.09.2017 um 22:31 schrieb Li, Samuel:
Quoted 2 lines
Quoted 2 lines
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel
driver.
Quoted 2 lines
Actually here it is going to wait for all fences,
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true...That is actually a bug, we only need to wait here when
prime_shared_count== 0.Quoted 7 lines
Quoted 6 lines
ttm_bo_validate()is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.Quoted 2 lines
amdgpu_ttm_bind()in turn binds the BO to the GART space and isn't relatedto CPU access either.
ttm_bo_validate()can move buffer is necessary,No, that is a very common misconception.
ttm_bo_validate()schedules the buffer to be moved at some point in the future.The only thing which saves us here is the fact that TTM waits for the move to be completed in it's page fault handler.
Quoted 1 line
and
amdgpu_ttm_bind()will flush hdp, which we have discussed before.And as concluded before that is unnecessary.
Quoted 2 lines
Quoted 2 lines
What you most likely need to do here is to use
reservation_object_wait_timeout_rcu()to wait for all GPU operations toend.
Quoted 1 line
Right, that is called by
amdgpu_gem_prime_pin().Please just completely drop the
begin_cpu_access()andend_cpu_access()callbacks.Checking other drivers the only one actually implementing something special is the i915 driver which needs to remove the BO from the GTT domain for cache coherency I think.
The omap driver implements those callbacks to grab an extra reference to the pages while they are access, we don't need to do this since TTM grabs an extra reference during the mmap anyway.
All other drivers implementing mmap (exynos, rockchip, tilcdc, arcpgu, msm, meson, etnaviv, sti, qxl, vc4, rcar-du, atmel-hlcdc, imx, mediatek, mali, vgem, fsl-dcu, zte, hisilicon, sun4i, mxsfb) don't have a begin/end callback.
Pinning the BO can actually cause problem with the display code when the BO needs to be scanned out, so we should avoid that as much as possible.
Regards,
Christian.Quoted 8 lines
Sam
Quoted 6 lines
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Wednesday, September 20, 2017 2:15 PM
To: Li, Samuel <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 5 lines
Quoted 5 lines
Am 20.09.2017 um 19:47 schrieb Li, Samuel:
Quoted 4 lines
Quoted 2 lines
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more. It doesn't wait for anything.
It does. The following is from
amdgpu_gem_prime_pin(),
91 * Wait for all shared fences to complete before we switch tofuture
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
92 * use of exclusive fence on this prime shared bo. 93 */ 94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true,false,
Quoted 7 lines
95 MAX_SCHEDULE_TIMEOUT); 96 if (unlikely(ret < 0)) { 97 DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret); 98 amdgpu_bo_unreserve(bo); 99 return ret;100 }
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Besides, pinning process prepares all the stuff before and after moving
buffer(ttm_bo_validate, amdgpu_ttm_bind),No, you misunderstood what this is good for.
The waiting done here is only for the shared fence to switch from explicitly to implicitly synchronization for correct interaction with the Intel
driver.
Quoted 12 lines
Quoted 12 lines
As soon the the BO is exported that shouldn't wait for anything any more.
Quoted 2 lines
I think if a buffer can be moved, it is probably also in a good condition to be
accessed.
That is complete nonsense.
ttm_bo_validate()is an asynchronous operation to enable GPU access to the BO, it isn't related at all to possible CPU access and can actually prevent it a number of cases.Quoted 5 lines
Quoted 5 lines
amdgpu_ttm_bind()in turn binds the BO to the GART space and isn't related to CPU access either.What you most likely need to do here is to use
reservation_object_wait_timeout_rcu()to wait for all GPU operations toend.
Quoted 23 lines
Quoted 23 lines
Regards,
Christian.Quoted 7 lines
Sam
Quoted 5 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 1:38 PM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupport
Quoted 3 lines
Quoted 3 lines
Am 20.09.2017 um 19:34 schrieb Li, Samuel:
Quoted 2 lines
Quoted 2 lines
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to
finish.
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
During pining, it will all the fences to finish. That shall be OK.
No that isn't correct. Pinning just notes that the BO shouldn't be moved any more.
It doesn't wait for anything.
Christian.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Sam
Quoted 4 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 12:21 PM
To: Li, Samuel <[email protected]>; amd-Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Add
gem_prime_mmapsupport
Quoted 2 lines
Quoted 2 lines
Am 20.09.2017 um 17:44 schrieb Li, Samuel:
Quoted 1 line
Quoted 1 line
What happens when another thread is using
amdgpu_dmabuf_opsQuoted 3 lines
Quoted 3 lines
to
Quoted 2 lines
Quoted 2 lines
call
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
begin_cpu_access/end_cpu_access when you are fixing it up
again?
Quoted 28 lines
Quoted 28 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Right, that is an issue.
A simple "if (!amdgpu_dmabuf_ops.begin_cpu_access)" should be
able
Quoted 11 lines
Quoted 11 lines
to
Quoted 10 lines
Quoted 10 lines
deal with that.
Quoted 5 lines
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be
dropped (other drivers implemented too), so I would like to keep it there for now.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Wait a second what do you mean with "CPU access needs
synchronization"?
Quoted 5 lines
Quoted 5 lines
At least i915 makes the memory GPU inaccessible when you start to use it with the CPU.
If that is what this callback should do then this implementation would be incorrect. Pinning doesn't wait for any GPU operation to
finish.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Regards,
Christian.Quoted 3 lines
Sam
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; amd-Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Add
gem_prime_mmapQuoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
support
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsQuoted 3 lines
Quoted 3 lines
to
Quoted 2 lines
Quoted 2 lines
call
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
begin_cpu_access/end_cpu_access when you are fixing it up
again?
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ vma->vm_pgoff = amdgpu_bo_mmap_offset(bo) >>
PAGE_SHIFT;Quoted 37 lines
Quoted 37 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 26 lines
Quoted 26 lines
PAGE_SHIFT;", but I'm not sure.Quoted 3 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+ dma_buf->ops = &amdgpu_dmabuf_ops;
This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by: Samuel Li <[email protected]>
---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index d2aaad7..188b705 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 4 lines
Quoted 4 lines
*dev,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
struct drm_gem_object *gobj,
int flags);
+struct drm_gem_object*amdgpu_gem_prime_import(struct
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drm_device*dev,Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ struct dma_buf *dma_buf);
int amdgpu_gem_prime_pin(struct drm_gem_object*obj);
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
void amdgpu_gem_prime_unpin(struct drm_gem_object
*obj);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
struct reservation_object
*amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 1 line
Quoted 1 line
Quoted 1 line
void *amdgpu_gem_prime_vmap(struct drm_gem_object
*obj);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
void amdgpu_gem_prime_vunmap(struct
drm_gem_objectQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
*obj,
Quoted 3 lines
Quoted 3 lines
void
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
*vaddr);
+int amdgpu_gem_prime_mmap(struct drm_gem_object*obj,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
struct
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+vm_area_struct *vma);
int amdgpu_gem_debugfs_init(struct amdgpu_device*adev);
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
/* sub-allocation manager, it has to be protected
by anotherlock.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 2cdf844..9b63ac5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = {Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_export = amdgpu_gem_prime_export,
- .gem_prime_import = drm_gem_prime_import,
+ .gem_prime_import = amdgpu_gem_prime_import,
.gem_prime_pin = amdgpu_gem_prime_pin,
.gem_prime_unpin = amdgpu_gem_prime_unpin,
.gem_prime_res_obj = amdgpu_gem_prime_res_obj,@@
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
-843,6
+843,7 @@ static struct drm_driver kms_driver = {
.gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
.gem_prime_vmap = amdgpu_gem_prime_vmap,
.gem_prime_vunmap = amdgpu_gem_prime_vunmap,
+ .gem_prime_mmap = amdgpu_gem_prime_mmap,
.name = DRIVER_NAME,
.desc = DRIVER_DESC, diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index 5b3f928..13c977a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
@@ -57,6 +57,40 @@ voidamdgpu_gem_prime_vunmap(struct
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drm_gem_object*obj, void *vaddr)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
ttm_bo_kunmap(&bo->dma_buf_vmap);
}
+int amdgpu_gem_prime_mmap(struct drm_gem_object*obj,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
struct
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
vm_area_struct *vma)
+{
+ struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+ struct amdgpu_device *adev = amdgpu_ttm_adev(bo-tbo.bdev);
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+ unsigned asize = amdgpu_bo_size(bo);
+ int ret;
+
+ if (!vma->vm_file)
+ return -ENODEV;
+
+ if (adev == NULL)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ return -ENODEV;
+
+ /* Check for valid size. */
+ if (asize < vma->vm_end - vma->vm_start)
+ return -EINVAL;
+
+ if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) ||
+ (bo->flags &
AMDGPU_GEM_CREATE_NO_CPU_ACCESS)) {Quoted 86 lines
Quoted 86 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ return -EPERM;
+ }
+ vma->vm_pgoff = amdgpu_bo_mmap_offset(bo) >>
PAGE_SHIFT;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Maybe better use "
vma->vm_pgoff+=
amdgpu_bo_mmap_offset(bo)>>Quoted 6 lines
Quoted 6 lines
PAGE_SHIFT;", but I'm not sure.Quoted 5 lines
Quoted 5 lines
How other drivers handle this?
Quoted 3 lines
+
+ /* prime mmap does not need to check access, so allow
+ here*/
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ ret = drm_vma_node_allow(&obj->vma_node, vma-
vm_file-
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
private_data);Quoted 4 lines
Quoted 4 lines
+ if (ret)
+ return ret;
+
+ ret = ttm_bo_mmap(vma->vm_file, vma, &adev-mman.bdev);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ drm_vma_node_revoke(&obj->vma_node,
+ vma->vm_file->private_data);
+
+ return ret;
+}
+
struct drm_gem_object *
amdgpu_gem_prime_import_sg_table(struct drm_device*dev,
Quoted 56 lines
Quoted 56 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
struct dma_buf_attachment *attach,
@@
-130,14
+164,55 @@ struct reservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
return bo->tbo.resv;
}
+static int amdgpu_gem_begin_cpu_access(struct
dma_buf *dma_buf, enum dma_data_direction direction)
+{
+ return amdgpu_gem_prime_pin(dma_buf->priv);
+}
+
+static int amdgpu_gem_end_cpu_access(struct dma_buf
*dma_buf,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
enum
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
+dma_data_direction direction) {
+ amdgpu_gem_prime_unpin(dma_buf->priv);
+
+ return 0;
+}
+
+static struct dma_buf_ops amdgpu_dmabuf_ops;
+
struct dma_buf *amdgpu_gem_prime_export(struct
drm_deviceQuoted 14 lines
Quoted 14 lines
*dev,
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
struct drm_gem_object *gobj,
int flags)
{
struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);
+ struct dma_buf *dma_buf;
if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
return ERR_PTR(-EPERM);
- return drm_gem_prime_export(dev, gobj, flags);
+ dma_buf = drm_gem_prime_export(dev, gobj, flags);
+ amdgpu_dmabuf_ops = *(dma_buf->ops);
+ amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
amdgpu_gem_end_cpu_access;Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+ dma_buf->ops = &amdgpu_dmabuf_ops;
This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 1 line
Quoted 1 line
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()and
amdgpu_gem_end_cpu_access()Quoted 6 lines
Quoted 6 lines
as
Quoted 5 lines
Quoted 5 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and when
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings aswell.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Regards,
Christian.Quoted 5 lines
+
+ return dma_buf;
+}
+
+struct drm_gem_object*amdgpu_gem_prime_import(struct
Quoted 23 lines
Quoted 23 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drm_device*dev,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ struct dma_buf *dma_buf) {
+ struct drm_gem_object *obj;
+
+ if (dma_buf->ops == &amdgpu_dmabuf_ops) {
+ obj = dma_buf->priv;
+ if (obj->dev == dev) {
+ /*
+ * Importing dmabuf exported from out own gemincreases
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
+ * refcount on gem itself instead of f_count of dmabuf.
+ */
+ drm_gem_object_get(obj);
+ return obj;
+ }
+ }
+
+ return drm_gem_prime_import(dev, dma_buf);
}_______________________________________________
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
Quoted 9 lines
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Li, Samuel
Sent: Wednesday, September 20, 2017 11:44 AM
To: Koenig, Christian; [email protected]
Subject: RE: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportQuoted 2 lines
What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?
Quoted 8 lines
Right, that is an issue.
Quoted 3 lines
I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
CPU access needs synchronization anyway, so the two callbacks cannot be dropped (other drivers implemented too), so I would like to keep it there for now.
Pinning only needs to happen for device access (i.e., so the pages don't get swapped out).
Alex
Quoted 248 lines
Sam
Quoted 57 lines
-----Original Message-----
From: Koenig, Christian
Sent: Wednesday, September 20, 2017 2:58 AM
To: Li, Samuel <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/1] drm/amdgpu: Addgem_prime_mmapsupportQuoted 1 line
What do you mean "This isn't race free"?
Take a look at the code again:
Review
Quoted 3 lines
(quoted diff) +3
-0+ dma_buf = drm_gem_prime_export(dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;What happens when another thread is using
amdgpu_dmabuf_opsto call begin_cpu_access/end_cpu_access when you are fixing it up again?I would just completely drop the two callbacks, pinning is not necessary for CPU access and thinking more about it it actually has some unwanted side effects.
Regards,
Christian.Am 19.09.2017 um 23:22 schrieb Samuel Li:
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
+
vma->vm_pgoff=amdgpu_bo_mmap_offset(bo)>>PAGE_SHIFT;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)
PAGE_SHIFT;", but I'm not sure.Quoted 2 lines
Quoted 1 line
How other drivers handle this?
This is a good catch. Looks like pgoff is honored during prime mmap, not a
fake offset here.
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks todrm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 16 lines
What do you mean "This isn't race free"?
Regards,
SamQuoted 8 lines · Christian König
Am 14.09.2017 um 00:39 schrieb Samuel Li:
Quoted 7 lines
v2: drop hdp invalidate/flush.
Signed-off-by Samuel Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 77++++++++++++++++++++++++++++++-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h
Quoted 8 lines
3 files changed, 81 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -395,11 +395,14 @@amdgpu_gem_prime_import_sg_table(struct
Quoted 2 lines
drm_device*dev,Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0struct dma_buf *amdgpu_gem_prime_export(struct drm_device*dev,
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 398
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0struct drm_gem_object *gobj, int flags); +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h line 402
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ struct dma_buf *dma_buf);int amdgpu_gem_prime_pin (struct drm_gem_object *obj);void amdgpu_gem_prime_unpin (struct drm_gem_object *obj); struct reservation_object *amdgpu_gem_prime_res_obj(struct
drm_gem_object*);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0void *amdgpu_gem_prime_vmap (struct drm_gem_object *obj); void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj,void
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0*vaddr); +int amdgpu_gem_prime_mmap (struct drm_gem_object *obj,struct +vm_area_struct *vma);int amdgpu_gem_debugfs_init (struct amdgpu_device *adev);/* sub-allocation manager, it has to be protected by another lock. drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -835,7 +835,7 @@ static struct drm_driver kms_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static struct drm_driver kms_driver = {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1.gem_prime_export = amdgpu_gem_prime_export, - .gem_prime_import = drm_gem_prime_import, + .gem_prime_import = amdgpu_gem_prime_import, .gem_prime_pin = amdgpu_gem_prime_pin, .gem_prime_unpin = amdgpu_gem_prime_unpin, .gem_prime_res_obj = amdgpu_gem_prime_res_obj, @@ -843,6 +843,7 @@ static struct drm_driver kms_driver = { .gem_prime_import_sg_table =
amdgpu_gem_prime_import_sg_table,Quoted 15 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct
Quoted 11 lines
.gem_prime_vmap =
amdgpu_gem_prime_vmap, .gem_prime_vunmap =amdgpu_gem_prime_vunmap,drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0+ .gem_prime_mmap = amdgpu_gem_prime_mmap, .name = DRIVER_NAME, .desc = DRIVER_DESC,drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct
drm_gem_object*obj, void *vaddr)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +0
-0ttm_bo_kunmap (&bo->dma_buf_vmap); } +int amdgpu_gem_prime_mmap(struct drm_gem_object *obj,struct
Quoted 32 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +14
-0vm_area_struct *vma) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +unsigned asize =amdgpu_bo_size (bo); +int ret; + +if (!vma->vm_file) +return -ENODEV ; + +if (adev ==NULL ) +return -ENODEV ; + +/* Check for valid size. */ +if (asize < vma->vm_end - vma->vm_start)Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c void amdgpu_gem_prime_vunmap(struct · line 81
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +7
-0+return -EINVAL ; + +if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) || + (bo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS )) { +return -EPERM ; + } + vma->vm_pgoff =amdgpu_bo_mmap_offset (bo) >>PAGE_SHIFT ;Maybe better use "
vma->vm_pgoff+=amdgpu_bo_mmap_offset(bo)
PAGE_SHIFT;", but I'm not sure.Quoted 7 lines
Quoted 6 lines
How other drivers handle this?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +3
-0+ +/* prime mmap does not need to check access, so allow here */ + ret = drm_vma_node_allow(&obj->vma_node, vma->vm_file-
private_data);Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +6
-0+if (ret) +return ret; + + ret =ttm_bo_mmap (vma->vm_file, vma, &adev->mman.bdev); +drm_vma_node_revoke (&obj->vma_node, + vma->vm_file->private_data);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+ +return ret; +} +struct drm_gem_object * amdgpu_gem_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, @@ -130,14+164,55 @@ struct
reservation_object*amdgpu_gem_prime_res_obj(struct
drm_gem_object*obj)Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
return bo->tbo.resv;}
+static int amdgpu_gem_begin_cpu_access(structdma_buf
*dma_buf,Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 6 lines
enum
dma_data_directiondirection)drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+{ +return amdgpu_gem_prime_pin (dma_buf->priv); +} + +static int amdgpu_gem_end_cpu_access(struct dma_buf *dma_buf,enum
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +8
-0+dma_data_direction direction) { +amdgpu_gem_prime_unpin (dma_buf->priv); + +return 0 ; +} + +static struct dma_buf_ops amdgpu_dmabuf_ops; + struct dma_buf *amdgpu_gem_prime_export(struct drm_device*dev,
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 11 lines
struct
drm_gem_object*gobj, int flags){ struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +4
-0+struct dma_buf *dma_buf;if (amdgpu_ttm_tt_get_usermm (bo->tbo.ttm))return ERR_PTR (-EPERM ); - return drm_gem_prime_export(dev, gobj, flags); + dma_buf =drm_gem_prime_export (dev, gobj, flags); + amdgpu_dmabuf_ops = *(dma_buf->ops); + amdgpu_dmabuf_ops.begin_cpu_access =
amdgpu_gem_begin_cpu_access;Quoted 1 line
Quoted 1 line
Quoted 1 line
+ amdgpu_dmabuf_ops.end_cpu_access =
amdgpu_gem_end_cpu_access;Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+
dma_buf->ops=&amdgpu_dmabuf_ops;This isn't race free and needs to be fixed.
Better add callbacks to
drm_prime.csimilar to
drm_gem_dmabuf_mmap().Quoted 2 lines
Quoted 2 lines
Alternative you could just completely drop
amdgpu_gem_begin_cpu_access()andamdgpu_gem_end_cpu_access()as
Quoted 3 lines
well.
Quoted 2 lines
Quoted 2 lines
When the buffer is shared between device it is pinned anyway and
when
Quoted 5 lines
it isn't shared
ttm_bo_mmap()is able to handle VRAM mappings as well.Quoted 4 lines
Quoted 4 lines
Regards,
Christian.Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +5
-0+ +return dma_buf; +} + +struct drm_gem_object *amdgpu_gem_prime_import(struct
drm_device*dev,Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +16
-0+ struct dma_buf *dma_buf) { +struct drm_gem_object *obj; + +if (dma_buf->ops == &amdgpu_dmabuf_ops) { + obj = dma_buf->priv; +if (obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_get (obj); +return obj; + } + } + +return drm_gem_prime_import (dev, dma_buf); }
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