Experimental P2P buffer sharing v2
Subsystems (4)
cover Experimental P2P buffer sharing v2
This patch series adds experimental P2P buffer sharing in amdgpu. It's disabled by default and can be enabled with amdgpu.p2p_sharing=1.
v2:
* Changed drm helper function to cast to GEM object
* Added foreign BO checks to DC code paths
* Updated commit message for amdgpu_cs change
Amber Lin (1):
drm/amdgpu: handle foreign BOs in the VM mapping
Christian König (4):
drm/amdgpu: disallow foreign BOs for CS w/o GPUVM mapping drm/amdgpu: disallow foreign BOs in the display path v2 drm/amdgpu: separate BO from GEM object drm/amdgpu: enable foreign DMA-buf objects v2
Felix Kuehling (1):
drm: Add helper to cast DMA-buf to GEM object
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 16 ++++- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 6 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 41 ++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 80 +++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 ++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 +++-- drivers/gpu/drm/amd/amdgpu/dce_v10_0.c | 5 ++ drivers/gpu/drm/amd/amdgpu/dce_v11_0.c | 5 ++ drivers/gpu/drm/amd/amdgpu/dce_v6_0.c | 5 ++ drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 5 ++ .../drm/amd/display/amdgpu_dm/amdgpu_dm_types.c | 5 ++ drivers/gpu/drm/drm_prime.c | 25 +++++++ include/drm/drmP.h | 2 + 16 files changed, 219 insertions(+), 26 deletions(-)
Signature · 6 lines
1.9.1 _______________________________________________ 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): 1499837367-8368-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
PATCH 1/6 drm: Add helper to cast DMA-buf to GEM object
--- drivers/gpu/drm/drm_prime.c | 25 +++++++++++++++++++++++++ include/drm/drmP.h | 2 ++ 2 files changed, 27 insertions(+)
drivers/gpu/drm/drm_prime.c +25 -0
@@ -594,6 +594,31 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,EXPORT_SYMBOL (drm_gem_prime_handle_to_fd);/** +* drm_gem_prime_dmabuf_to_object - try to cast dmabuf to GEM object +* @dma_buf: dma-buf object to cast +* @driver: driver that is the expected exporter of the dma-buf +* +* If @dma_buf represents a GEM object, this function return a pointer +* to it. Optionally, if @driver is not NULL, it also checks that the +* object was exported by @driver. Otherwise it returns NULL. +*/ +struct drm_gem_object *drm_gem_prime_dmabuf_to_object (struct dma_buf *dma_buf, +struct drm_driver *driver) +{ +struct drm_gem_object *obj; + +if (dma_buf->ops != &drm_gem_prime_dmabuf_ops) +return NULL ; + + obj = dma_buf->priv; +if (driver && obj->dev->driver != driver) +return NULL ; + +return obj; +} +EXPORT_SYMBOL (drm_gem_prime_dmabuf_to_object); + +/** * drm_gem_prime_import - helper library implementation of the import callback * @dev: drm_device to import into * @dma_buf: dma-buf object to import
include/drm/drmP.h +2 -0
@@ -767,6 +767,8 @@ extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,extern int drm_gem_prime_handle_to_fd (struct drm_device *dev,struct drm_file *file_priv,uint32_t handle,uint32_t flags,int *prime_fd); +extern struct drm_gem_object *drm_gem_prime_dmabuf_to_object ( +struct dma_buf *dma_buf,struct drm_driver *driver);extern struct drm_gem_object *drm_gem_prime_import (struct drm_device *dev,struct dma_buf *dma_buf); extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
Signature · 6 lines
1.9.1 _______________________________________________ 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): 1499837367-8368-2-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
Christian König
Reviewed-byRe: [PATCH 1/6] drm: Add helper to cast DMA-buf to GEM object
Am 12.07.2017 um 07:29 schrieb Felix Kuehling:
Quoted 1 line
Signed-off-by Felix Kuehling <[email protected]>
Quoted 46 lines
--- drivers/gpu/drm/drm_prime.c | 25 +++++++++++++++++++++++++ include/drm/drmP.h | 2 ++ 2 files changed, 27 insertions(+)drivers/gpu/drm/drm_prime.c +25
-0@@ -594,6 +594,31 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,EXPORT_SYMBOL (drm_gem_prime_handle_to_fd);/** +* drm_gem_prime_dmabuf_to_object - try to cast dmabuf to GEM object +* @dma_buf: dma-buf object to cast +* @driver: driver that is the expected exporter of the dma-buf +* +* If @dma_buf represents a GEM object, this function return a pointer +* to it. Optionally, if @driver is not NULL, it also checks that the +* object was exported by @driver. Otherwise it returns NULL. +*/ +struct drm_gem_object *drm_gem_prime_dmabuf_to_object (struct dma_buf *dma_buf, +struct drm_driver *driver) +{ +struct drm_gem_object *obj; + +if (dma_buf->ops != &drm_gem_prime_dmabuf_ops) +return NULL ; + + obj = dma_buf->priv; +if (driver && obj->dev->driver != driver) +return NULL ; + +return obj; +} +EXPORT_SYMBOL (drm_gem_prime_dmabuf_to_object); + +/** * drm_gem_prime_import - helper library implementation of the import callback * @dev: drm_device to import into * @dma_buf: dma-buf object to import include/drm/drmP.h +0
-0
include/drm/drmP.h extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev, · line 774
Quoted 8 lines
include/drm/drmP.h +2
-0@@ -767,6 +767,8 @@ extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,extern int drm_gem_prime_handle_to_fd (struct drm_device *dev,struct drm_file *file_priv,uint32_t handle,uint32_t flags,int *prime_fd); +extern struct drm_gem_object *drm_gem_prime_dmabuf_to_object ( +struct dma_buf *dma_buf,struct drm_driver *driver);extern struct drm_gem_object *drm_gem_prime_import (struct drm_device *dev,struct dma_buf *dma_buf); extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 1/6] drm: Add helper to cast DMA-buf to GEM object
In reply to Felix KuehlingQuoted 27 lines · Felix Kuehling
Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/drm_prime.c | 25 +++++++++++++++++++++++++ include/drm/drmP.h | 2 ++ 2 files changed, 27 insertions(+)drivers/gpu/drm/drm_prime.c +13
-0@@ -594,6 +594,31 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,EXPORT_SYMBOL (drm_gem_prime_handle_to_fd);/** +* drm_gem_prime_dmabuf_to_object - try to cast dmabuf to GEM object +* @dma_buf: dma-buf object to cast +* @driver: driver that is the expected exporter of the dma-buf +* +* If @dma_buf represents a GEM object, this function return a pointer +* to it. Optionally, if @driver is not NULL, it also checks that the +* object was exported by @driver. Otherwise it returns NULL. +*/ +struct drm_gem_object *drm_gem_prime_dmabuf_to_object (struct dma_buf *dma_buf, +struct drm_driver *driver) +{ +struct drm_gem_object *obj; +
drivers/gpu/drm/drm_prime.c int drm_gem_prime_handle_to_fd(struct drm_device *dev, · line 619
Quoted 10 lines
drivers/gpu/drm/drm_prime.c +10
-0+if (dma_buf->ops != &drm_gem_prime_dmabuf_ops) +return NULL ; + + obj = dma_buf->priv; +if (driver && obj->dev->driver != driver) +return NULL ; + +return obj; +} +EXPORT_SYMBOL (drm_gem_prime_dmabuf_to_object);
Bonus points bikeshed: Would be sweet to use that helper in drm_prime.c itself, and iirc some drivers could use it too.
-Daniel
Quoted 25 lines
drivers/gpu/drm/drm_prime.c +2
-0+ +/** * drm_gem_prime_import - helper library implementation of the import callback * @dev: drm_device to import into * @dma_buf: dma-buf object to import include/drm/drmP.h +2
-0@@ -767,6 +767,8 @@ extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,extern int drm_gem_prime_handle_to_fd (struct drm_device *dev,struct drm_file *file_priv,uint32_t handle,uint32_t flags,int *prime_fd); +extern struct drm_gem_object *drm_gem_prime_dmabuf_to_object ( +struct dma_buf *dma_buf,struct drm_driver *driver);extern struct drm_gem_object *drm_gem_prime_import (struct drm_device *dev,struct dma_buf *dma_buf); extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,Signature · 6 lines
1.9.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 20170712081108.3yqdbmpxxvnm5kqz-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org
Re: [PATCH 1/6] drm: Add helper to cast DMA-buf to GEM object
Hi Daniel,
Quoted 40 lines · Daniel Vetter
Quoted 27 lines · Felix Kuehling
Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/drm_prime.c | 25 +++++++++++++++++++++++++ include/drm/drmP.h | 2 ++ 2 files changed, 27 insertions(+)drivers/gpu/drm/drm_prime.c +13
-0@@ -594,6 +594,31 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,EXPORT_SYMBOL (drm_gem_prime_handle_to_fd);/** +* drm_gem_prime_dmabuf_to_object - try to cast dmabuf to GEM object +* @dma_buf: dma-buf object to cast +* @driver: driver that is the expected exporter of the dma-buf +* +* If @dma_buf represents a GEM object, this function return a pointer +* to it. Optionally, if @driver is not NULL, it also checks that the +* object was exported by @driver. Otherwise it returns NULL. +*/ +struct drm_gem_object *drm_gem_prime_dmabuf_to_object (struct dma_buf *dma_buf, +struct drm_driver *driver) +{ +struct drm_gem_object *obj; +drivers/gpu/drm/drm_prime.c int drm_gem_prime_handle_to_fd(struct drm_device *dev, · line 619
Quoted 10 lines
drivers/gpu/drm/drm_prime.c +10
-0+if (dma_buf->ops != &drm_gem_prime_dmabuf_ops) +return NULL ; + + obj = dma_buf->priv; +if (driver && obj->dev->driver != driver) +return NULL ; + +return obj; +} +EXPORT_SYMBOL (drm_gem_prime_dmabuf_to_object);Reviewed-by Daniel Vetter <[email protected]>
Quoted 2 lines
Bonus points bikeshed: Would be sweet to use that helper in
drm_prime.citself,
I found only one place in drm_prime.c where it would make sense. In most cases, the drm_prime_* functions called through drm_gem_prime_dmabuf_ops already know that they're dealing with a GEM object. So the extra checks in the new helper are redundant.
In drm_gem_prime_import I could make the following change:
drivers/gpu/drm/drm_prime.c +8 -10
@@ -634,16 +634,14 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,struct drm_gem_object *obj;int ret; -if (dma_buf->ops == &drm_gem_prime_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_reference (obj); -return obj; - } + obj =drm_gem_prime_dmabuf_to_object (dma_buf,NULL ); +if (obj && obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_reference (obj); +return obj; }if (!dev->driver->gem_prime_import_sg_table)
Do you want me to do that in the same commit, or a separate one?
Quoted 1 line
and iirc some drivers could use it too.
I guess other drivers would have to wait until Alex pushes this to drm-next.
Regards,
Felix
Quoted 23 lines
-Daniel
Quoted 21 lines
drivers/gpu/drm/drm_prime.c +2
-0+ +/** * drm_gem_prime_import - helper library implementation of the import callback * @dev: drm_device to import into * @dma_buf: dma-buf object to import include/drm/drmP.h +2
-0@@ -767,6 +767,8 @@ extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,extern int drm_gem_prime_handle_to_fd (struct drm_device *dev,struct drm_file *file_priv,uint32_t handle,uint32_t flags,int *prime_fd); +extern struct drm_gem_object *drm_gem_prime_dmabuf_to_object ( +struct dma_buf *dma_buf,struct drm_driver *driver);extern struct drm_gem_object *drm_gem_prime_import (struct drm_device *dev,struct dma_buf *dma_buf); extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,Signature · 1 line
1.9.1
Quoted 4 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
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): 3f277697-b5d1-2222-7edf-ec0b509d5453-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 1/6] drm: Add helper to cast DMA-buf to GEM object
Quoted 29 lines · Felix Kuehling
drivers/gpu/drm/drm_prime.c +8
-10@@ -634,16 +634,14 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,struct drm_gem_object *obj;int ret; -if (dma_buf->ops == &drm_gem_prime_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_reference (obj); -return obj; - } + obj =drm_gem_prime_dmabuf_to_object (dma_buf,NULL ); +if (obj && obj->dev == dev) { +/* +* Importing dmabuf exported from out own gem increases +* refcount on gem itself instead of f_count of dmabuf. +*/ +drm_gem_object_reference (obj); +return obj; }if (!dev->driver->gem_prime_import_sg_table)
Quoted 1 line
Do you want me to do that in the same commit, or a separate one?
I'd squash it into the one commit you have already. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/6 drm/amdgpu: disallow foreign BOs for CS w/o GPUVM mapping
In reply to a message not in the archiveFrom: Christian König <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
@@ -1397,7 +1397,8 @@ struct amdgpu_bo_va_mapping *struct amdgpu_bo_list_entry *lobj; lobj = &parser->bo_list->array[i]; -if (!lobj->bo_va) +if (!lobj->bo_va || +amdgpu_ttm_adev (lobj->bo_va->bo->tbo.bdev) != parser->adev)continue ;list_for_each_entry (mapping, &lobj->bo_va->valids, list) {
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/6 drm/amdgpu: disallow foreign BOs in the display path v2
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Pinning them in other devices VRAM would obviously not work.
v2: Add checks to DC code paths
--- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 6 ++++++ drivers/gpu/drm/amd/amdgpu/dce_v10_0.c | 5 +++++ drivers/gpu/drm/amd/amdgpu/dce_v11_0.c | 5 +++++ drivers/gpu/drm/amd/amdgpu/dce_v6_0.c | 5 +++++ drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 5 +++++ drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c | 5 +++++ 6 files changed, 31 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +6 -0
@@ -180,6 +180,12 @@ int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc, obj = new_amdgpu_fb->obj; new_abo =gem_to_amdgpu_bo (obj); +if (amdgpu_ttm_adev (new_abo->tbo.bdev) != adev) { +DRM_ERROR ("Foreign BOs not allowed in the display engine\n" ); + r = -EINVAL ; + goto cleanup; + } +/* pin the new buffer */ r =amdgpu_bo_reserve (new_abo, false);if (unlikely (r !=0 )) {
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c +5 -0
@@ -1915,6 +1915,11 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,*/ obj = amdgpu_fb->obj; abo =gem_to_amdgpu_bo (obj); +if (amdgpu_ttm_adev (abo->tbo.bdev) != adev) { +DRM_ERROR ("Foreign BOs not allowed in the display engine\n" ); +return -EINVAL ; + } + r =amdgpu_bo_reserve (abo, false);if (unlikely (r !=0 ))return r;
drivers/gpu/drm/amd/amdgpu/dce_v11_0.c +5 -0
@@ -1954,6 +1954,11 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,*/ obj = amdgpu_fb->obj; abo =gem_to_amdgpu_bo (obj); +if (amdgpu_ttm_adev (abo->tbo.bdev) != adev) { +DRM_ERROR ("Foreign BOs not allowed in the display engine\n" ); +return -EINVAL ; + } + r =amdgpu_bo_reserve (abo, false);if (unlikely (r !=0 ))return r;
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c +5 -0
@@ -1868,6 +1868,11 @@ static int dce_v6_0_crtc_do_set_base(struct drm_crtc *crtc,*/ obj = amdgpu_fb->obj; abo =gem_to_amdgpu_bo (obj); +if (amdgpu_ttm_adev (abo->tbo.bdev) != adev) { +DRM_ERROR ("Foreign BOs not allowed in the display engine\n" ); +return -EINVAL ; + } + r =amdgpu_bo_reserve (abo, false);if (unlikely (r !=0 ))return r;
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c +5 -0
@@ -1846,6 +1846,11 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,*/ obj = amdgpu_fb->obj; abo =gem_to_amdgpu_bo (obj); +if (amdgpu_ttm_adev (abo->tbo.bdev) != adev) { +DRM_ERROR ("Foreign BOs not allowed in the display engine\n" ); +return -EINVAL ; + } + r =amdgpu_bo_reserve (abo, false);if (unlikely (r !=0 ))return r;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c +5 -0
@@ -1621,6 +1621,11 @@ static int dm_plane_helper_prepare_fb( obj = afb->obj; rbo =gem_to_amdgpu_bo (obj); +if (amdgpu_ttm_adev (rbo->tbo.bdev)->ddev != plane->dev) { +DRM_ERROR ("Foreign BOs not allowed in the display engine\n" ); +return -EINVAL ; + } + r =amdgpu_bo_reserve (rbo, false);if (unlikely (r !=0 ))return r;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/6 drm/amdgpu: separate BO from GEM object
In reply to a message not in the archiveFrom: Christian König <[email protected]>
This allows us to have multiple GEM objects for one BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 12 +++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 41 +++++++++++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 +---- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 20 ++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++++++++-- 5 files changed, 77 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -2
@@ -417,6 +417,12 @@ struct amdgpu_bo_va {#define AMDGPU_GEM_DOMAIN_MAX 0x3 +struct amdgpu_gem_object { +struct drm_gem_object base; +struct list_head list; +struct amdgpu_bo *bo; +}; +struct amdgpu_bo {/* Protected by tbo.reserved */ u32 prefered_domains;
@@ -433,12 +439,14 @@ struct amdgpu_bo {void *metadata;u32 metadata_size;unsigned prime_shared_count; +/* GEM objects refereing to this BO */ +struct list_head gem_objects; +/* list of all virtual address to which this bo * is associated to */ struct list_head va;/* Constant after initialization */ -struct drm_gem_object gem_base;struct amdgpu_bo *parent;struct amdgpu_bo *shadow;
@@ -447,7 +455,7 @@ struct amdgpu_bo {struct list_head mn_list;struct list_head shadow_list; }; -#define gem_to_amdgpu_bo (gobj) container_of((gobj), struct amdgpu_bo, gem_base) +#define gem_to_amdgpu_bo (gobj) container_of((gobj), struct amdgpu_gem_object, base)->bovoid amdgpu_gem_object_free (struct drm_gem_object *obj); int amdgpu_gem_object_open(struct drm_gem_object *obj,
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +32 -9
66 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -6
@@ -95,7 +95,6 @@ static void amdgpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)amdgpu_update_memory_usage (adev, &bo->tbo.mem,NULL ); -drm_gem_object_release (&bo->gem_base);amdgpu_bo_unref (&bo->parent);if (!list_empty (&bo->shadow_list)) {mutex_lock (&adev->shadow_list_lock);
@@ -344,13 +343,9 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, bo =kzalloc (sizeof (struct amdgpu_bo ),GFP_KERNEL );if (bo ==NULL )return -ENOMEM ; - r =drm_gem_object_init (adev->ddev, &bo->gem_base, size); -if (unlikely (r)) { -kfree (bo); -return r; - }INIT_LIST_HEAD (&bo->shadow_list);INIT_LIST_HEAD (&bo->va); +INIT_LIST_HEAD (&bo->gem_objects); bo->prefered_domains = domain & (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT | AMDGPU_GEM_DOMAIN_CPU |
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +19 -1
@@ -65,6 +65,7 @@ struct drm_gem_object *struct reservation_object *resv = attach->dmabuf->resv;struct amdgpu_device *adev = dev->dev_private;struct amdgpu_bo *bo; +struct amdgpu_gem_object *gobj;int ret;ww_mutex_lock (&resv->lock,NULL );
@@ -75,7 +76,24 @@ struct drm_gem_object *return ERR_PTR (ret); bo->prime_shared_count =1 ; -return &bo->gem_base; + + gobj =kzalloc (sizeof (struct amdgpu_gem_object ),GFP_KERNEL ); +if (unlikely (!gobj)) { +amdgpu_bo_unref (&bo); +return ERR_PTR (-ENOMEM ); + } + + ret =drm_gem_object_init (adev->ddev, &gobj->base,amdgpu_bo_size (bo)); +if (unlikely (ret)) { +kfree (gobj); +amdgpu_bo_unref (&bo); +return ERR_PTR (ret); + } + +list_add (&gobj->list, &bo->gem_objects); + gobj->bo =amdgpu_bo_ref (bo); + +return &gobj->base; }int amdgpu_gem_prime_pin (struct drm_gem_object *obj)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +15 -2
@@ -256,11 +256,24 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,static int amdgpu_verify_access (struct ttm_buffer_object *bo,struct file *filp) { struct amdgpu_bo *abo = container_of(bo, struct amdgpu_bo, tbo); +struct drm_file *file_priv = filp->private_data; +struct amdgpu_gem_object *gobj;if (amdgpu_ttm_tt_get_usermm (bo->ttm))return -EPERM ; -return drm_vma_node_verify_access (&abo->gem_base.vma_node, - filp->private_data); + +ww_mutex_lock (&abo->tbo.resv->lock,NULL ); +list_for_each_entry (gobj, &abo->gem_objects, list) { +if (gobj->base.dev != file_priv->minor->dev) +continue ; + +ww_mutex_unlock (&abo->tbo.resv->lock); +return drm_vma_node_verify_access (&gobj->base.vma_node, + file_priv); + } +ww_mutex_unlock (&abo->tbo.resv->lock); + +return -EPERM ; } static void amdgpu_move_null(struct ttm_buffer_object *bo,
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/6 drm/amdgpu: handle foreign BOs in the VM mapping
In reply to a message not in the archiveFrom: Amber Lin <[email protected]>
Set the system bit for foreign BO mappings and use the remote VRAM BAR address as the VRAM base offset.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13 -4
@@ -1586,6 +1586,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev,dma_addr_t *pages_addr, struct amdgpu_vm *vm, struct amdgpu_bo_va_mapping *mapping, + uint64_t vram_base_offset, uint64_t flags, struct drm_mm_node *nodes, struct dma_fence **fence)
@@ -1644,7 +1645,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, max_entries =min (max_entries,16ull *1024ull ); addr =0 ; }else if (flags &AMDGPU_PTE_VALID ) { - addr += adev->vm_manager.vram_base_offset; + addr += vram_base_offset; } addr += pfn <<PAGE_SHIFT ;
@@ -1689,6 +1690,8 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,struct ttm_mem_reg *mem;struct drm_mm_node *nodes;struct dma_fence *exclusive; +uint64_t vram_base_offset = adev->vm_manager.vram_base_offset; +struct amdgpu_device *bo_adev;int r;if (clear || !bo_va->bo) {
@@ -1710,9 +1713,15 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,if (bo_va->bo) { flags =amdgpu_ttm_tt_pte_flags (adev, bo_va->bo->tbo.ttm, mem); + bo_adev =amdgpu_ttm_adev (bo_va->bo->tbo.bdev); gtt_flags = (amdgpu_ttm_is_bound (bo_va->bo->tbo.ttm) && - adev ==amdgpu_ttm_adev (bo_va->bo->tbo.bdev)) ? + adev == bo_adev) ? flags :0 ; +if (mem && mem->mem_type ==TTM_PL_VRAM && + adev != bo_adev) { + flags |=AMDGPU_PTE_SYSTEM ; + vram_base_offset = bo_adev->mc.aper_base; + } }else { flags =0x0 ; gtt_flags = ~0x0 ;
@@ -1726,8 +1735,8 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,list_for_each_entry (mapping, &bo_va->invalids, list) { r =amdgpu_vm_bo_split_mapping (adev, exclusive, gtt_flags, pages_addr, vm, - mapping, flags, nodes, - &bo_va->last_pt_update); + mapping, vram_base_offset, flags, + nodes, &bo_va->last_pt_update);if (r)return r; }
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/6 drm/amdgpu: enable foreign DMA-buf objects v2
In reply to a message not in the archiveFrom: Christian König <[email protected]>
We should be able to handle BOs from other instances as well.
v2:
* Add a module option that is off-by-default
* Use new DRM helper function to check the exporting driver
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 6 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 60 +++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -129,6 +129,8 @@extern int amdgpu_cik_support;#endif +extern int amdgpu_p2p_sharing; +#define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL/* 3GB by default */ #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000#define AMDGPU_MAX_USEC_TIMEOUT 100000/* 100 ms */
@@ -471,6 +473,8 @@ struct drm_gem_object *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 *);
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +5 -1
@@ -120,6 +120,7 @@int amdgpu_param_buf_per_se =0 ;int amdgpu_job_hang_limit =0 ;int amdgpu_lbpw =-1 ; +int amdgpu_p2p_sharing =0 ;MODULE_PARM_DESC (vramlimit,"Restrict VRAM for testing, in megabytes" );module_param_named (vramlimit, amdgpu_vram_limit, int,0600 );
@@ -289,6 +290,9 @@module_param_named (cik_support, amdgpu_cik_support, int,0444 );#endif +MODULE_PARM_DESC (p2p_sharing,"Enable P2P buffer sharing (1 = enabled, 0 = disabled (default))" ); +module_param_named (p2p_sharing, amdgpu_p2p_sharing, int,0444 ); +static const struct pci_device_id pciidlist[] = { #ifdef CONFIG_DRM_AMDGPU_SI
@@ -835,7 +839,7 @@ long amdgpu_drm_ioctl(struct file *filp, .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,
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +60 -0
63 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx