drm/amdgpu: introduce struct amdgpu_bo_dmabuf
Subsystems (2)
PATCH 1/4 drm/amdgpu: introduce struct amdgpu_bo_dmabuf
Implement a new struct amdgpu_bo_dmabuf as subclass of struct amdgpu_bo and a function to create amdgpu_bo_dmabuf bo.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 30 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 9 +++++++ 2 files changed, 39 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +30 -0
@@ -727,6 +727,36 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev, *ubo_ptr =to_amdgpu_bo_user (bo_ptr);return r; } + +/** +* amdgpu_bo_create_dmabuf - create an &amdgpu_bo_dmabuf buffer object +* @adev: amdgpu device object +* @bp: parameters to be used for the buffer object +* @ubo_ptr: pointer to the buffer object pointer +* +* Create a BO to be used by prime BO export; +* +* Returns: +* 0 for success or a negative error code on failure. +*/ + +int amdgpu_bo_create_dmabuf (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo_dmabuf **dbo_ptr) +{ +struct amdgpu_bo *bo_ptr; +int r; + + bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW ; + bp->bo_ptr_size =sizeof (struct amdgpu_bo_dmabuf ); + r =amdgpu_bo_do_create (adev, bp, &bo_ptr); +if (r) +return r; + + *dbo_ptr =to_amdgpu_bo_dmabuf (bo_ptr); +return r; +} +/** * amdgpu_bo_validate - validate an &amdgpu_bo buffer object * @bo: pointer to the buffer object
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +9 -0
@@ -38,6 +38,7 @@#define AMDGPU_BO_MAX_PLACEMENTS 3#define to_amdgpu_bo_user (abo) container_of((abo), struct amdgpu_bo_user, bo) +#define to_amdgpu_bo_dmabuf (abo) container_of((abo), struct amdgpu_bo_dmabuf, bo)struct amdgpu_bo_param {unsigned long size;
@@ -119,6 +120,11 @@ struct amdgpu_bo_user { }; +struct amdgpu_bo_dmabuf { +struct amdgpu_bo bo; +unsigned int prime_shared_count; +}; +static inline struct amdgpu_bo *ttm_to_amdgpu_bo (struct ttm_buffer_object *tbo) { return container_of(tbo, struct amdgpu_bo, tbo);
@@ -265,6 +271,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,int amdgpu_bo_create_user (struct amdgpu_device *adev,struct amdgpu_bo_param *bp,struct amdgpu_bo_user **ubo_ptr); +int amdgpu_bo_create_dmabuf (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo_dmabuf **dbo_ptr);void amdgpu_bo_free_kernel (struct amdgpu_bo **bo,u64 *gpu_addr,void **cpu_addr);int amdgpu_bo_kmap (struct amdgpu_bo *bo,void **ptr);
Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/4 drm/amdgpu: use amdgpu_bo_create_dmabuf()
Modify amdgpu_gem_object_create() to allocateamdgpu_bo_dmabuf BO for ttm_bo_type_sg.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10 -2
@@ -59,6 +59,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, {struct amdgpu_bo *bo;struct amdgpu_bo_user *ubo; +struct amdgpu_bo_dmabuf *dbo;struct amdgpu_bo_param bp;int r;
@@ -74,11 +75,18 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, bp.domain = initial_domain; bp.bo_ptr_size =sizeof (struct amdgpu_bo ); - r =amdgpu_bo_create_user (adev, &bp, &ubo); +if (type != ttm_bo_type_sg) + r =amdgpu_bo_create_user (adev, &bp, &ubo); +else + r =amdgpu_bo_create_dmabuf (adev, &bp, &dbo);if (r)return r; - bo = &ubo->bo; +if (type != ttm_bo_type_sg) + bo = &ubo->bo; +else + bo = &dbo->bo; + *obj = &bo->tbo.base; (*obj)->funcs = &amdgpu_gem_object_funcs;
Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 drm/amdgpu: introduce is_amdgpu_dmabuf()
In reply to Nirmoy DasImplement is_amdgpu_dmabuf() helper function.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 + 2 files changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5 -0
@@ -120,6 +120,11 @@ bool amdgpu_bo_is_amdgpu_bo(struct ttm_buffer_object *bo)return false; } +bool is_amdgpu_bo_dmabuf (struct amdgpu_bo *bo) +{ +return (bo->tbo.type == ttm_bo_type_sg); +} +/** * amdgpu_bo_placement_from_domain - set buffer's placement * @abo: &amdgpu_bo buffer object whose placement is to be set
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
@@ -274,6 +274,7 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,int amdgpu_bo_create_dmabuf (struct amdgpu_device *adev,struct amdgpu_bo_param *bp,struct amdgpu_bo_dmabuf **dbo_ptr); +bool is_amdgpu_bo_dmabuf (struct amdgpu_bo *bo);void amdgpu_bo_free_kernel (struct amdgpu_bo **bo,u64 *gpu_addr,void **cpu_addr);int amdgpu_bo_kmap (struct amdgpu_bo *bo,void **ptr);
Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 drm/amdgpu: use amdgpu_bo_dmabuf for shared prime count
In reply to Nirmoy DasRemove prime_shared_count from base class and use that the subclass, amdgpu_bo_dmabuf.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 12 ++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 - 5 files changed, 11 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -618,7 +618,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,struct amdgpu_bo *bo =ttm_to_amdgpu_bo (e->tv.bo);/* Make sure we use the exclusive slot for shared BOs */ -if (bo->prime_shared_count) +if (is_amdgpu_bo_dmabuf (bo)) e->tv.num_shared =0 ; e->bo_va =amdgpu_vm_bo_find (vm, bo); }
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +8 -4
@@ -143,6 +143,7 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf, {struct drm_gem_object *obj = dmabuf->priv;struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_bo_dmabuf *dbo =to_amdgpu_bo_dmabuf (bo);struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);int r;
@@ -172,7 +173,7 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,if (r) goto out; - bo->prime_shared_count++; + dbo->prime_shared_count++;amdgpu_bo_unreserve (bo);return 0 ;
@@ -194,10 +195,11 @@ static void amdgpu_dma_buf_detach(struct dma_buf *dmabuf, {struct drm_gem_object *obj = dmabuf->priv;struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_bo_dmabuf *dbo =to_amdgpu_bo_dmabuf (bo);struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); -if (attach->dev->driver != adev->dev->driver && bo->prime_shared_count) - bo->prime_shared_count--; +if (attach->dev->driver != adev->dev->driver && dbo->prime_shared_count) + dbo->prime_shared_count--;pm_runtime_mark_last_busy (adev_to_drm (adev)->dev);pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);
@@ -431,6 +433,7 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)struct amdgpu_device *adev =drm_to_adev (dev);struct drm_gem_object *gobj;struct amdgpu_bo *bo; +struct amdgpu_bo_dmabuf *dbo;uint64_t flags =0 ;int ret;
@@ -449,10 +452,11 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf) goto error; bo =gem_to_amdgpu_bo (gobj); + dbo =to_amdgpu_bo_dmabuf (bo); bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ;if (dma_buf->ops != &amdgpu_dmabuf_ops) - bo->prime_shared_count =1 ; + dbo->prime_shared_count =1 ;dma_resv_unlock (resv);return gobj;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -1
@@ -783,7 +783,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,break ; }case AMDGPU_GEM_OP_SET_PLACEMENT : -if (robj->prime_shared_count && (args->value &AMDGPU_GEM_DOMAIN_VRAM )) { +if (is_amdgpu_bo_dmabuf (robj) && (args->value &AMDGPU_GEM_DOMAIN_VRAM )) { r = -EINVAL ;amdgpu_bo_unreserve (robj);break ;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
@@ -965,7 +965,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,return -EINVAL ;/* A shared bo cannot be migrated to VRAM */ -if (bo->prime_shared_count || bo->tbo.base.import_attach) { +if (is_amdgpu_bo_dmabuf (bo) || bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT ) domain =AMDGPU_GEM_DOMAIN_GTT ;else
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0 -1
@@ -93,7 +93,6 @@ struct amdgpu_bo {struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;u64 flags; -unsigned prime_shared_count;/* per VM structure for page tables and with virtual addresses */ struct amdgpu_vm_bo_base *vm_bo;/* Constant after initialization */
Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerRe: [PATCH 4/4] drm/amdgpu: use amdgpu_bo_dmabuf for shared prime count
That whole approach won't work :)
The prime_shared_count is on the exported BO and not on the imported one.
So any user BO can be exported.
Regards,
Christian.
Am 17.03.21 um 08:47 schrieb Nirmoy Das:
Quoted 112 lines
Remove
prime_shared_countfrom base class and use that the subclass,amdgpu_bo_dmabuf.Signed-off-by Nirmoy Das <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 12 ++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 - 5 files changed, 11 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -618,7 +618,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,struct amdgpu_bo *bo =ttm_to_amdgpu_bo (e->tv.bo);/* Make sure we use the exclusive slot for shared BOs */ -if (bo->prime_shared_count) +if (is_amdgpu_bo_dmabuf (bo)) e->tv.num_shared =0 ; e->bo_va =amdgpu_vm_bo_find (vm, bo); }drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +8
-4@@ -143,6 +143,7 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf, {struct drm_gem_object *obj = dmabuf->priv;struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_bo_dmabuf *dbo =to_amdgpu_bo_dmabuf (bo);struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);int r;@@ -172,7 +173,7 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,if (r) goto out; - bo->prime_shared_count++; + dbo->prime_shared_count++;amdgpu_bo_unreserve (bo);return 0 ;@@ -194,10 +195,11 @@ static void amdgpu_dma_buf_detach(struct dma_buf *dmabuf, {struct drm_gem_object *obj = dmabuf->priv;struct amdgpu_bo *bo =gem_to_amdgpu_bo (obj); +struct amdgpu_bo_dmabuf *dbo =to_amdgpu_bo_dmabuf (bo);struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); -if (attach->dev->driver != adev->dev->driver && bo->prime_shared_count) - bo->prime_shared_count--; +if (attach->dev->driver != adev->dev->driver && dbo->prime_shared_count) + dbo->prime_shared_count--;pm_runtime_mark_last_busy (adev_to_drm (adev)->dev);pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);@@ -431,6 +433,7 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)struct amdgpu_device *adev =drm_to_adev (dev);struct drm_gem_object *gobj;struct amdgpu_bo *bo; +struct amdgpu_bo_dmabuf *dbo;uint64_t flags =0 ;int ret;@@ -449,10 +452,11 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf) goto error; bo =gem_to_amdgpu_bo (gobj); + dbo =to_amdgpu_bo_dmabuf (bo); bo->allowed_domains =AMDGPU_GEM_DOMAIN_GTT ; bo->preferred_domains =AMDGPU_GEM_DOMAIN_GTT ;if (dma_buf->ops != &amdgpu_dmabuf_ops) - bo->prime_shared_count =1 ; + dbo->prime_shared_count =1 ;dma_resv_unlock (resv);return gobj;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-1@@ -783,7 +783,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,break ; }case AMDGPU_GEM_OP_SET_PLACEMENT : -if (robj->prime_shared_count && (args->value &AMDGPU_GEM_DOMAIN_VRAM )) { +if (is_amdgpu_bo_dmabuf (robj) && (args->value &AMDGPU_GEM_DOMAIN_VRAM )) { r = -EINVAL ;amdgpu_bo_unreserve (robj);break ;drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1@@ -965,7 +965,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,return -EINVAL ;/* A shared bo cannot be migrated to VRAM */ -if (bo->prime_shared_count || bo->tbo.base.import_attach) { +if (is_amdgpu_bo_dmabuf (bo) || bo->tbo.base.import_attach) {if (domain &AMDGPU_GEM_DOMAIN_GTT ) domain =AMDGPU_GEM_DOMAIN_GTT ;else drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 98
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-1@@ -93,7 +93,6 @@ struct amdgpu_bo {struct ttm_buffer_object tbo;struct ttm_bo_kmap_obj kmap;u64 flags; -unsigned prime_shared_count;/* per VM structure for page tables and with virtual addresses */ struct amdgpu_vm_bo_base *vm_bo;/* Constant after initialization */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 4/4] drm/amdgpu: use amdgpu_bo_dmabuf for shared prime count
Quoted 5 lines · Christian König
That whole approach won't work :)
The
prime_shared_countis on the exported BO and not on the imported one.So any user BO can be exported.
So any BO from any drm driver is possible. No wonder it worked with amdgpu-amdgpu test machine.
OK scrapping the series :/
Thanks,
Nirmoy
Quoted 114 lines
Regards,
Christian.Am 17.03.21 um 08:47 schrieb Nirmoy Das:
Quoted 109 lines
Remove
prime_shared_countfrom base class and use that the subclass,amdgpu_bo_dmabuf.Signed-off-by Nirmoy Das <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +-drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c| 12 ++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 -5 files changed, 11 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -618,7 +618,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, struct amdgpu_bo *bo = ttm_to_amdgpu_bo(e->tv.bo); /* Make sure we use the exclusive slot for shared BOs */ - if (bo->prime_shared_count) + if (is_amdgpu_bo_dmabuf(bo)) e->tv.num_shared = 0; e->bo_va = amdgpu_vm_bo_find(vm, bo); }drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-0@@ -143,6 +143,7 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf, { struct drm_gem_object *obj = dmabuf->priv; struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); + struct amdgpu_bo_dmabuf *dbo = to_amdgpu_bo_dmabuf(bo); struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); int r;@@ -172,7 +173,7 @@ static int amdgpu_dma_buf_attach(struct
dma_buf*dmabuf, if (r)
goto out;
- bo->prime_shared_count++;
+ dbo->prime_shared_count++;
amdgpu_bo_unreserve(bo);
return 0;
@@ -194,10 +195,11 @@ static void amdgpu_dma_buf_detach(structdma_buf*dmabuf, {
structdrm_gem_object*obj =dmabuf->priv;
structamdgpu_bo*bo =gem_to_amdgpu_bo(obj);
+ structamdgpu_bo_dmabuf*dbo =to_amdgpu_bo_dmabuf(bo);
structamdgpu_device*adev =amdgpu_ttm_adev(bo->tbo.bdev);
- if (attach->dev->driver!=adev->dev->driver&&bo->prime_shared_count) - bo->prime_shared_count--;
+ if (attach->dev->driver!=adev->dev->driver&&dbo->prime_shared_count)
+ dbo->prime_shared_count--; pm_runtime_mark_last_busy(adev_to_drm(adev)->dev); pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-0@@ -431,6 +433,7 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf) struct amdgpu_device *adev = drm_to_adev(dev); struct drm_gem_object *gobj; struct amdgpu_bo *bo; + struct amdgpu_bo_dmabuf *dbo; uint64_t flags = 0; int ret;@@ -449,10 +452,11 @@
amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)goto error;
bo =gem_to_amdgpu_bo(gobj);
+ dbo =to_amdgpu_bo_dmabuf(bo);
bo->allowed_domains=AMDGPU_GEM_DOMAIN_GTT;
bo->preferred_domains=AMDGPU_GEM_DOMAIN_GTT;
if (dma_buf->ops!=&amdgpu_dmabuf_ops)
-bo->prime_shared_count= 1;
+dbo->prime_shared_count= 1;
dma_resv_unlock(resv);
return gobj;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -783,7 +783,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, break; }case
AMDGPU_GEM_OP_SET_PLACEMENT:
- if (robj->prime_shared_count&& (args->value&AMDGPU_GEM_DOMAIN_VRAM)) {
+ if (is_amdgpu_bo_dmabuf(robj)&& (args->value&AMDGPU_GEM_DOMAIN_VRAM)) {
r =-EINVAL;amdgpu_bo_unreserve(robj);
break;drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1@@ -965,7 +965,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, return -EINVAL; /* A shared bo cannot be migrated to VRAM */ - if (bo->prime_shared_count || bo->tbo.base.import_attach) { + if (is_amdgpu_bo_dmabuf(bo) || bo->tbo.base.import_attach) { if (domain & AMDGPU_GEM_DOMAIN_GTT) domain = AMDGPU_GEM_DOMAIN_GTT;else
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 98
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-1@@ -93,7 +93,6 @@ struct amdgpu_bo { struct ttm_buffer_object tbo; struct ttm_bo_kmap_obj kmap; u64 flags; - unsigned prime_shared_count; /* per VM structure for page tables and with virtual addresses */ struct amdgpu_vm_bo_base *vm_bo; /* Constant after initialization */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerRe: [PATCH 4/4] drm/amdgpu: use amdgpu_bo_dmabuf for shared prime count
Am 17.03.21 um 09:13 schrieb Nirmoy:
Quoted 12 lines · Christian König
Quoted 5 lines
That whole approach won't work :)
The
prime_shared_countis on the exported BO and not on the imported one.So any user BO can be exported.
So any BO from any drm driver is possible. No wonder it worked with amdgpu-amdgpu test machine.
OK scrapping the series :/
Try looking into the page table BOs, that has much more potential for a cleanup than this single field here.
Christian.
Quoted 130 lines
Thanks,
Nirmoy
Quoted 123 lines
Regards,
Christian.Am 17.03.21 um 08:47 schrieb Nirmoy Das:
Quoted 117 lines
Remove
prime_shared_countfrom base class and use that the subclass,amdgpu_bo_dmabuf.Signed-off-by Nirmoy Das <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +-drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c| 12 ++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 -5 files changed, 11 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -618,7 +618,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, struct amdgpu_bo *bo = ttm_to_amdgpu_bo(e->tv.bo); /* Make sure we use the exclusive slot for shared BOs */ - if (bo->prime_shared_count) + if (is_amdgpu_bo_dmabuf(bo)) e->tv.num_shared = 0; e->bo_va = amdgpu_vm_bo_find(vm, bo); }drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-0@@ -143,6 +143,7 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf, { struct drm_gem_object *obj = dmabuf->priv; struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); + struct amdgpu_bo_dmabuf *dbo = to_amdgpu_bo_dmabuf(bo); struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); int r;@@ -172,7 +173,7 @@ static int amdgpu_dma_buf_attach(struct
dma_buf*dmabuf, if (r)
goto out;
- bo->prime_shared_count++;
+ dbo->prime_shared_count++;
amdgpu_bo_unreserve(bo);
return 0;
@@ -194,10 +195,11 @@ static void amdgpu_dma_buf_detach(structdma_buf*dmabuf, {
structdrm_gem_object*obj =dmabuf->priv;
structamdgpu_bo*bo =gem_to_amdgpu_bo(obj);
+ structamdgpu_bo_dmabuf*dbo =to_amdgpu_bo_dmabuf(bo);
structamdgpu_device*adev =amdgpu_ttm_adev(bo->tbo.bdev);
- if (attach->dev->driver!=adev->dev->driver&&bo->prime_shared_count) - bo->prime_shared_count--;
+ if (attach->dev->driver!=adev->dev->driver&&dbo->prime_shared_count)
+ dbo->prime_shared_count--; pm_runtime_mark_last_busy(adev_to_drm(adev)->dev); pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-0@@ -431,6 +433,7 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf) struct amdgpu_device *adev = drm_to_adev(dev); struct drm_gem_object *gobj; struct amdgpu_bo *bo; + struct amdgpu_bo_dmabuf *dbo; uint64_t flags = 0; int ret;@@ -449,10 +452,11 @@
amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)goto error;
bo =gem_to_amdgpu_bo(gobj);
+ dbo =to_amdgpu_bo_dmabuf(bo);
bo->allowed_domains=AMDGPU_GEM_DOMAIN_GTT;
bo->preferred_domains=AMDGPU_GEM_DOMAIN_GTT;
if (dma_buf->ops!=&amdgpu_dmabuf_ops)
-bo->prime_shared_count= 1;
+dbo->prime_shared_count= 1;
dma_resv_unlock(resv);
return gobj;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -783,7 +783,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, break; }case
AMDGPU_GEM_OP_SET_PLACEMENT:
- if (robj->prime_shared_count&& (args->value&AMDGPU_GEM_DOMAIN_VRAM)) {
+ if (is_amdgpu_bo_dmabuf(robj)&& (args->value&AMDGPU_GEM_DOMAIN_VRAM)) {
r =-EINVAL;amdgpu_bo_unreserve(robj);
break;drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1@@ -965,7 +965,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, return -EINVAL; /* A shared bo cannot be migrated to VRAM */ - if (bo->prime_shared_count || bo->tbo.base.import_attach) { + if (is_amdgpu_bo_dmabuf(bo) || bo->tbo.base.import_attach) { if (domain & AMDGPU_GEM_DOMAIN_GTT) domain = AMDGPU_GEM_DOMAIN_GTT;else
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-1@@ -93,7 +93,6 @@ struct amdgpu_bo { struct ttm_buffer_object tbo; struct ttm_bo_kmap_obj kmap; u64 flags; - unsigned prime_shared_count; /* per VM structure for page tables and with virtual addresses */ struct amdgpu_vm_bo_base *vm_bo; /* Constant after initialization */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 4/4] drm/amdgpu: use amdgpu_bo_dmabuf for shared prime count
Quoted 12 lines · Christian König
Am 17.03.21 um 09:13 schrieb Nirmoy:
Quoted 9 lines · Christian König
Quoted 5 lines
That whole approach won't work :)
The
prime_shared_countis on the exported BO and not on the imported one.So any user BO can be exported.
Quoted 7 lines
Quoted 3 lines
So any BO from any drm driver is possible. No wonder it worked with amdgpu-amdgpu test machine.
OK scrapping the series :/
Try looking into the page table BOs, that has much more potential for a cleanup than this single field here.
Christian.
Thanks, checking it.
Nirmoy
Quoted 123 lines
Quoted 123 lines
Thanks,
Nirmoy
Quoted 115 lines
Regards,
Christian.Am 17.03.21 um 08:47 schrieb Nirmoy Das:
Quoted 110 lines
Remove
prime_shared_countfrom base class and use that the subclass,amdgpu_bo_dmabuf.Signed-off-by Nirmoy Das <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +-drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c| 12 ++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 -5 files changed, 11 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -618,7 +618,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, struct amdgpu_bo *bo = ttm_to_amdgpu_bo(e->tv.bo); /* Make sure we use the exclusive slot for shared BOs */ - if (bo->prime_shared_count) + if (is_amdgpu_bo_dmabuf(bo)) e->tv.num_shared = 0; e->bo_va = amdgpu_vm_bo_find(vm, bo); }drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-0@@ -143,6 +143,7 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf, { struct drm_gem_object *obj = dmabuf->priv; struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); + struct amdgpu_bo_dmabuf *dbo = to_amdgpu_bo_dmabuf(bo); struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); int r;@@ -172,7 +173,7 @@ static int amdgpu_dma_buf_attach(struct
dma_buf*dmabuf, if (r)
goto out;
- bo->prime_shared_count++;
+ dbo->prime_shared_count++;
amdgpu_bo_unreserve(bo);
return 0;
@@ -194,10 +195,11 @@ static void amdgpu_dma_buf_detach(structdma_buf*dmabuf, {
structdrm_gem_object*obj =dmabuf->priv;
structamdgpu_bo*bo =gem_to_amdgpu_bo(obj);
+ structamdgpu_bo_dmabuf*dbo =to_amdgpu_bo_dmabuf(bo);
structamdgpu_device*adev =amdgpu_ttm_adev(bo->tbo.bdev);
- if (attach->dev->driver!=adev->dev->driver&&bo->prime_shared_count) - bo->prime_shared_count--;
+ if (attach->dev->driver!=adev->dev->driver&&dbo->prime_shared_count)
+ dbo->prime_shared_count--; pm_runtime_mark_last_busy(adev_to_drm(adev)->dev); pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1
-0@@ -431,6 +433,7 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf) struct amdgpu_device *adev = drm_to_adev(dev); struct drm_gem_object *gobj; struct amdgpu_bo *bo; + struct amdgpu_bo_dmabuf *dbo; uint64_t flags = 0; int ret;@@ -449,10 +452,11 @@
amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)goto error;
bo =gem_to_amdgpu_bo(gobj);
+ dbo =to_amdgpu_bo_dmabuf(bo);
bo->allowed_domains=AMDGPU_GEM_DOMAIN_GTT;
bo->preferred_domains=AMDGPU_GEM_DOMAIN_GTT;
if (dma_buf->ops!=&amdgpu_dmabuf_ops)
-bo->prime_shared_count= 1;
+dbo->prime_shared_count= 1;
dma_resv_unlock(resv);
return gobj;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -783,7 +783,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, break; }case
AMDGPU_GEM_OP_SET_PLACEMENT:
- if (robj->prime_shared_count&& (args->value&AMDGPU_GEM_DOMAIN_VRAM)) {
+ if (is_amdgpu_bo_dmabuf(robj)&& (args->value&AMDGPU_GEM_DOMAIN_VRAM)) {
r =-EINVAL;amdgpu_bo_unreserve(robj);
break;drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-1@@ -965,7 +965,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, return -EINVAL; /* A shared bo cannot be migrated to VRAM */ - if (bo->prime_shared_count || bo->tbo.base.import_attach) { + if (is_amdgpu_bo_dmabuf(bo) || bo->tbo.base.import_attach) { if (domain & AMDGPU_GEM_DOMAIN_GTT) domain = AMDGPU_GEM_DOMAIN_GTT;else
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0@@ -93,7 +93,6 @@ struct amdgpu_bo {
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo { · line 98
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-1struct ttm_buffer_object tbo; struct ttm_bo_kmap_obj kmap; u64 flags; - unsigned prime_shared_count; /* per VM structure for page tables and with virtual addresses */ struct amdgpu_vm_bo_base *vm_bo; /* Constant after initialization */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 17.03.21 um 08:47 schrieb Nirmoy Das:
Quoted 64 lines
Implement a new struct
amdgpu_bo_dmabufas subclass of structamdgpu_boand a function to createamdgpu_bo_dmabufbo.Signed-off-by Nirmoy Das <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 30 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 9 +++++++ 2 files changed, 39 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +30
-0@@ -727,6 +727,36 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev, *ubo_ptr =to_amdgpu_bo_user (bo_ptr);return r; } + +/** +* amdgpu_bo_create_dmabuf - create an &amdgpu_bo_dmabuf buffer object +* @adev: amdgpu device object +* @bp: parameters to be used for the buffer object +* @ubo_ptr: pointer to the buffer object pointer +* +* Create a BO to be used by prime BO export; +* +* Returns: +* 0 for success or a negative error code on failure. +*/ + +int amdgpu_bo_create_dmabuf (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo_dmabuf **dbo_ptr) +{ +struct amdgpu_bo *bo_ptr; +int r; + + bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW ; + bp->bo_ptr_size =sizeof (struct amdgpu_bo_dmabuf ); + r =amdgpu_bo_do_create (adev, bp, &bo_ptr); +if (r) +return r; + + *dbo_ptr =to_amdgpu_bo_dmabuf (bo_ptr); +return r; +} +/** * amdgpu_bo_validate - validate an &amdgpu_bo buffer object * @bo: pointer to the buffer object drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1
-0@@ -38,6 +38,7 @@#define AMDGPU_BO_MAX_PLACEMENTS 3#define to_amdgpu_bo_user (abo) container_of((abo), struct amdgpu_bo_user, bo) +#define to_amdgpu_bo_dmabuf (abo) container_of((abo), struct amdgpu_bo_dmabuf, bo)struct amdgpu_bo_param {unsigned long size;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h struct amdgpu_bo_user { · line 124
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0@@ -119,6 +120,11 @@ struct amdgpu_bo_user { }; +struct amdgpu_bo_dmabuf { +struct amdgpu_bo bo;
That won't work like this. Imported DMA-bufs are also user BOs and can have tilling flags and metadata.
Christian.
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3
-0+unsigned int prime_shared_count; +}; +static inline struct amdgpu_bo *ttm_to_amdgpu_bo (struct ttm_buffer_object *tbo) { return container_of(tbo, struct amdgpu_bo, tbo);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev, · line 279
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3
-0@@ -265,6 +271,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,int amdgpu_bo_create_user (struct amdgpu_device *adev,struct amdgpu_bo_param *bp,struct amdgpu_bo_user **ubo_ptr); +int amdgpu_bo_create_dmabuf (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo_dmabuf **dbo_ptr);void amdgpu_bo_free_kernel (struct amdgpu_bo **bo,u64 *gpu_addr,void **cpu_addr);int amdgpu_bo_kmap (struct amdgpu_bo *bo,void **ptr);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx