drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)
Subsystems (3)
PATCH 1/2 drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure as union(in, out)
simply some code logic
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +63 -0
69 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -1
@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) +DRM_IOCTL_DEF_DRV (AMDGPU_FREESYNC , amdgpu_display_freesync_ioctl,DRM_MASTER ), + DRM_IOCTL_DEF_DRV(AMDGPU_GEM_FIND_BO, amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };const int amdgpu_max_kms_ioctl =ARRAY_SIZE (amdgpu_ioctls_kms);
include/uapi/drm/amdgpu_drm.h +21 -0
@@ -54,6 +54,7 @@#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16/* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d
@@ -74,6 +75,7 @@#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)#define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo)/** * DOC: memory domains
@@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out {struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { +/* CPU address */ +__u64 addr; +/* memory size from CPU address */ +__u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { +/* offset in bo */ +__u64 offset; +/* resulting GEM handle */ +__u32 handle; +}; + +union drm_amdgpu_gem_find_bo { +struct drm_amdgpu_gem_find_bo_in in; +struct drm_amdgpu_gem_find_bo_out out; +}; +struct drm_amdgpu_wait_cs_in {/* Command submission handle * handle equals 0 means none to wait for
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/2 drm/amdgpu: bump version for API to find bo by cpu mapping
In reply to a message not in the archivebump version for new API involved.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -70,9 +70,10 @@* - 3.25.0 - Add support for sensor query info (stable pstate sclk/mclk). * - 3.26.0 - GFX9: Process AMDGPU_IB_FLAG_TC_WB_NOT_INVALIDATE. * - 3.27.0 - Add new chunk to to AMDGPU_CS to enable BO_LIST creation. +* - 3.28.0 - Add API to find bo by cpu mapping for UMD bo validation. */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 27 +#define KMS_DRIVER_MINOR 28#define KMS_DRIVER_PATCHLEVEL 0int amdgpu_vram_limit =0 ;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)
simply some code logic
Do we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 37 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,return 0 ; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, +struct drm_gem_object *obj) +{ +int i;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 304
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10
-0+struct drm_gem_object *tmp; + +spin_lock (&filp->table_lock); +idr_for_each_entry (&filp->object_idr, tmp, i) { +if (obj == tmp) { +drm_gem_object_reference (obj); +spin_unlock (&filp->table_lock); +return i; + } + }
Please double check if that is still up to date.
I think we could as well try to use the DMA-buf handle tree for that.
Christian.
Quoted 102 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +49
-0+spin_unlock (&filp->table_lock); + +return 0 ; +} + +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +union drm_amdgpu_gem_find_bo *args = data; +struct drm_gem_object *gobj; +struct amdgpu_bo *bo; +struct ttm_buffer_object *tbo; +struct vm_area_struct *vma; +uint32_t handle; +int r; + +if (offset_in_page (args->in.addr | args->in.size)) +return -EINVAL ; + +down_read (¤t->mm->mmap_sem); + vma =find_vma (current->mm, args->in.addr); +if (!vma || vma->vm_file != filp->filp || + (args->in.size > (vma->vm_end - args->in.addr))) { + args->out.handle =0 ; +up_read (¤t->mm->mmap_sem); +return -EINVAL ; + } + args->out.offset = args->in.addr - vma->vm_start; + + tbo = vma->vm_private_data; + bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_ref (bo); + gobj = &bo->gem_base; + + handle =amdgpu_gem_get_handle_from_object (filp, gobj); +if (!handle) { + r =drm_gem_handle_create (filp, gobj, &handle); +if (r) { +DRM_ERROR ("create gem handle failed\n" ); +up_read (¤t->mm->mmap_sem); +return r; + } + } + args->out.handle = handle; +up_read (¤t->mm->mmap_sem); + +return 0 ; +} +int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-1@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) +DRM_IOCTL_DEF_DRV (AMDGPU_FREESYNC , amdgpu_display_freesync_ioctl,DRM_MASTER ), + DRM_IOCTL_DEF_DRV(AMDGPU_GEM_FIND_BO, amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };const int amdgpu_max_kms_ioctl =ARRAY_SIZE (amdgpu_ioctls_kms);include/uapi/drm/amdgpu_drm.h +14
-0@@ -54,6 +54,7 @@#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16/* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d@@ -74,6 +75,7 @@#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)#define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo)/** * DOC: memory domains @@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out {struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { +/* CPU address */ +__u64 addr; +/* memory size from CPU address */ +__u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { +/* offset in bo */ +__u64 offset; +/* resulting GEM handle */ +__u32 handle;
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_gem_wait_idle_out { · line 418
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +7
-0+}; + +union drm_amdgpu_gem_find_bo { +struct drm_amdgpu_gem_find_bo_in in; +struct drm_amdgpu_gem_find_bo_out out; +}; +struct drm_amdgpu_wait_cs_in {/* Command submission handle * handle equals 0 means none to wait for
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Thanks for Jerry still remembers this series.
Hi Christian,
For upstream of this feature, seems we already had agreement long time ago. Two reasons for upstreaming:
1. this bug was found by an opengl game, so this bug also is in mesa driver in theory.
2. after upstream these patches, we can reduce pro specific patches, and close to open source.
Btw, an unit test is excepted when upstreaming, I remember Alex mentioned.
Thanks,
David Zhou
-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, July 30, 2018 6:48 PM
To: Zhang, Jerry <[email protected]>; [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)
simply some code logic
Do we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 38 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,return 0 ; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, +struct drm_gem_object *obj) { +int i;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 303
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10
-0+struct drm_gem_object *tmp; + +spin_lock (&filp->table_lock); +idr_for_each_entry (&filp->object_idr, tmp, i) { +if (obj == tmp) { +drm_gem_object_reference (obj); +spin_unlock (&filp->table_lock); +return i; + } + }
Please double check if that is still up to date.
I think we could as well try to use the DMA-buf handle tree for that.
Christian.
Quoted 103 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +49
-0+spin_unlock (&filp->table_lock); + +return 0 ; +} + +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +union drm_amdgpu_gem_find_bo *args = data; +struct drm_gem_object *gobj; +struct amdgpu_bo *bo; +struct ttm_buffer_object *tbo; +struct vm_area_struct *vma; +uint32_t handle; +int r; + +if (offset_in_page (args->in.addr | args->in.size)) +return -EINVAL ; + +down_read (¤t->mm->mmap_sem); + vma =find_vma (current->mm, args->in.addr); +if (!vma || vma->vm_file != filp->filp || + (args->in.size > (vma->vm_end - args->in.addr))) { + args->out.handle =0 ; +up_read (¤t->mm->mmap_sem); +return -EINVAL ; + } + args->out.offset = args->in.addr - vma->vm_start; + + tbo = vma->vm_private_data; + bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_ref (bo); + gobj = &bo->gem_base; + + handle =amdgpu_gem_get_handle_from_object (filp, gobj); +if (!handle) { + r =drm_gem_handle_create (filp, gobj, &handle); +if (r) { +DRM_ERROR ("create gem handle failed\n" ); +up_read (¤t->mm->mmap_sem); +return r; + } + } + args->out.handle = handle; +up_read (¤t->mm->mmap_sem); + +return 0 ; +} +int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3
-1@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) +DRM_IOCTL_DEF_DRV (AMDGPU_FREESYNC , amdgpu_display_freesync_ioctl,DRM_MASTER ), +DRM_IOCTL_DEF_DRV (AMDGPU_GEM_FIND_BO , +amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };const int amdgpu_max_kms_ioctl =ARRAY_SIZE (amdgpu_ioctls_kms);(quoted diff) +0
-0
b/include/uapi/drm/amdgpu_drm.hindex 94444ee..000c415 100644include/uapi/drm/amdgpu_drm.h +13
-0@@ -54,6 +54,7 @@#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16/* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d@@ -74,6 +75,7 @@#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)#define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo)/** * DOC: memory domains @@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out {struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { +/* CPU address */ +__u64 addr; +/* memory size from CPU address */ +__u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { +/* offset in bo */ +__u64 offset; +/* resulting GEM handle */
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_gem_wait_idle_out { · line 417
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +7
-0+__u32 handle; +}; + +union drm_amdgpu_gem_find_bo { +struct drm_amdgpu_gem_find_bo_in in; +struct drm_amdgpu_gem_find_bo_out out; }; +struct drm_amdgpu_wait_cs_in {/* Command submission handle * handle equals 0 means none to wait for
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Typo, excepted -> expected
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhou, David(ChunMing)
Sent: Tuesday, July 31, 2018 9:41 AM
To: Koenig, Christian <[email protected]>; Zhang, Jerry <[email protected]>; [email protected]
Subject: RE: [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)
Thanks for Jerry still remembers this series.
Hi Christian,
For upstream of this feature, seems we already had agreement long time ago. Two reasons for upstreaming:
1. this bug was found by an opengl game, so this bug also is in mesa driver in theory.
2. after upstream these patches, we can reduce pro specific patches, and close to open source.
Btw, an unit test is excepted when upstreaming, I remember Alex mentioned.
Thanks,
David Zhou
-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, July 30, 2018 6:48 PM
To: Zhang, Jerry <[email protected]>; [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)
simply some code logic
Do we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 38 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,return 0 ; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, +struct drm_gem_object *obj) { +int i;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 303
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10
-0+struct drm_gem_object *tmp; + +spin_lock (&filp->table_lock); +idr_for_each_entry (&filp->object_idr, tmp, i) { +if (obj == tmp) { +drm_gem_object_reference (obj); +spin_unlock (&filp->table_lock); +return i; + } + }
Please double check if that is still up to date.
I think we could as well try to use the DMA-buf handle tree for that.
Christian.
Quoted 103 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +49
-0+spin_unlock (&filp->table_lock); + +return 0 ; +} + +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +union drm_amdgpu_gem_find_bo *args = data; +struct drm_gem_object *gobj; +struct amdgpu_bo *bo; +struct ttm_buffer_object *tbo; +struct vm_area_struct *vma; +uint32_t handle; +int r; + +if (offset_in_page (args->in.addr | args->in.size)) +return -EINVAL ; + +down_read (¤t->mm->mmap_sem); + vma =find_vma (current->mm, args->in.addr); +if (!vma || vma->vm_file != filp->filp || + (args->in.size > (vma->vm_end - args->in.addr))) { + args->out.handle =0 ; +up_read (¤t->mm->mmap_sem); +return -EINVAL ; + } + args->out.offset = args->in.addr - vma->vm_start; + + tbo = vma->vm_private_data; + bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_ref (bo); + gobj = &bo->gem_base; + + handle =amdgpu_gem_get_handle_from_object (filp, gobj); +if (!handle) { + r =drm_gem_handle_create (filp, gobj, &handle); +if (r) { +DRM_ERROR ("create gem handle failed\n" ); +up_read (¤t->mm->mmap_sem); +return r; + } + } + args->out.handle = handle; +up_read (¤t->mm->mmap_sem); + +return 0 ; +} +int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3
-1@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) +DRM_IOCTL_DEF_DRV (AMDGPU_FREESYNC , amdgpu_display_freesync_ioctl,DRM_MASTER ), +DRM_IOCTL_DEF_DRV (AMDGPU_GEM_FIND_BO , +amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };const int amdgpu_max_kms_ioctl =ARRAY_SIZE (amdgpu_ioctls_kms);(quoted diff) +0
-0
b/include/uapi/drm/amdgpu_drm.hindex 94444ee..000c415 100644include/uapi/drm/amdgpu_drm.h +13
-0@@ -54,6 +54,7 @@#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16/* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d@@ -74,6 +75,7 @@#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)#define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo)/** * DOC: memory domains @@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out {struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { +/* CPU address */ +__u64 addr; +/* memory size from CPU address */ +__u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { +/* offset in bo */ +__u64 offset; +/* resulting GEM handle */
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_gem_wait_idle_out { · line 417
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +7
-0+__u32 handle; +}; + +union drm_amdgpu_gem_find_bo { +struct drm_amdgpu_gem_find_bo_in in; +struct drm_amdgpu_gem_find_bo_out out; }; +struct drm_amdgpu_wait_cs_in {/* Command submission handle * handle equals 0 means none to wait for
_______________________________________________
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 8 lines · David(ChunMing)
Typo, excepted -> expected
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhou, David(ChunMing)
Sent: Tuesday, July 31, 2018 9:41 AM
To: Koenig, Christian <[email protected]>; Zhang, Jerry <[email protected]>; [email protected]
Subject: RE: [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)
Quoted 7 lines
Thanks for Jerry still remembers this series.
Hi Christian,
For upstream of this feature, seems we already had agreement long time ago. Two reasons for upstreaming:
1. this bug was found by an opengl game, so this bug also is in mesa driver in theory.
2. after upstream these patches, we can reduce pro specific patches, and close to open source.
Thanks for explanation.
Quoted 2 lines
Btw, an unit test is excepted when upstreaming, I remember Alex mentioned.
Yes, I will.
Quoted 55 lines
Thanks,
David Zhou
-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, July 30, 2018 6:48 PM
To: Zhang, Jerry <[email protected]>; [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)
simply some code logicDo we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 35 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,return 0 ; }
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 303
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +13
-0+static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, +struct drm_gem_object *obj) { +int i; +struct drm_gem_object *tmp; + +spin_lock (&filp->table_lock); +idr_for_each_entry (&filp->object_idr, tmp, i) { +if (obj == tmp) { +drm_gem_object_reference (obj); +spin_unlock (&filp->table_lock); +return i; + } + }Please double check if that is still up to date.
We may have to replace drm_gem_object_reference() with drm_gem_object_get().
On 2nd thought, do we really need to do reference every time?
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Quoted 2 lines
I think we could as well try to use the DMA-buf handle tree for that.
If the bo is not import/export, DMA-buf will be NULL always.
Regards,
Jerry
Quoted 113 lines
Christian.
Quoted 110 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +49
-0+spin_unlock (&filp->table_lock); + +return 0 ; +} + +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +union drm_amdgpu_gem_find_bo *args = data; +struct drm_gem_object *gobj; +struct amdgpu_bo *bo; +struct ttm_buffer_object *tbo; +struct vm_area_struct *vma; +uint32_t handle; +int r; + +if (offset_in_page (args->in.addr | args->in.size)) +return -EINVAL ; + +down_read (¤t->mm->mmap_sem); + vma =find_vma (current->mm, args->in.addr); +if (!vma || vma->vm_file != filp->filp || + (args->in.size > (vma->vm_end - args->in.addr))) { + args->out.handle =0 ; +up_read (¤t->mm->mmap_sem); +return -EINVAL ; + } + args->out.offset = args->in.addr - vma->vm_start; + + tbo = vma->vm_private_data; + bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_ref (bo); + gobj = &bo->gem_base; + + handle =amdgpu_gem_get_handle_from_object (filp, gobj); +if (!handle) { + r =drm_gem_handle_create (filp, gobj, &handle); +if (r) { +DRM_ERROR ("create gem handle failed\n" ); +up_read (¤t->mm->mmap_sem); +return r; + } + } + args->out.handle = handle; +up_read (¤t->mm->mmap_sem); + +return 0 ; +} +int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3
-1@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) +DRM_IOCTL_DEF_DRV (AMDGPU_FREESYNC , amdgpu_display_freesync_ioctl,DRM_MASTER ), +DRM_IOCTL_DEF_DRV (AMDGPU_GEM_FIND_BO , +amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };const int amdgpu_max_kms_ioctl =ARRAY_SIZE (amdgpu_ioctls_kms);(quoted diff) +0
-0
b/include/uapi/drm/amdgpu_drm.hindex 94444ee..000c415 100644include/uapi/drm/amdgpu_drm.h +20
-0@@ -54,6 +54,7 @@#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16/* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d@@ -74,6 +75,7 @@#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)#define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo)/** * DOC: memory domains @@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out {struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { +/* CPU address */ +__u64 addr; +/* memory size from CPU address */ +__u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { +/* offset in bo */ +__u64 offset; +/* resulting GEM handle */ +__u32 handle; +}; + +union drm_amdgpu_gem_find_bo { +struct drm_amdgpu_gem_find_bo_in in; +struct drm_amdgpu_gem_find_bo_out out; }; +
Quoted 9 lines
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_gem_wait_idle_out { · line 417
Quoted 3 lines
include/uapi/drm/amdgpu_drm.h +0
-0struct drm_amdgpu_wait_cs_in {/* Command submission handle * handle equals 0 means none to wait for _______________________________________________
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
Am 31.07.2018 um 03:40 schrieb Zhou, David(ChunMing):
Quoted 7 lines
Thanks for Jerry still remembers this series.
Hi Christian,
For upstream of this feature, seems we already had agreement long time ago. Two reasons for upstreaming:
1. this bug was found by an opengl game, so this bug also is in mesa driver in theory.
2. after upstream these patches, we can reduce pro specific patches, and close to open source.
I mean the functionality is actually rather simple, so I don't see much of an issue with that.
Quoted 1 line
Btw, an unit test is excepted when upstreaming, I remember Alex mentioned.
Yeah, agree an unit test is really a must have for that.
Christian.
Quoted 181 lines
Thanks,
David Zhou
-----Original Message-----
From: Christian König <[email protected]>
Sent: Monday, July 30, 2018 6:48 PM
To: Zhang, Jerry <[email protected]>; [email protected]
Cc: Zhou, David(ChunMing) <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: return bo itself if userptr is cpu addr of bo (v3)Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)
simply some code logicDo we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 37 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,return 0 ; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, +struct drm_gem_object *obj) { +int i;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 303
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10
-0+struct drm_gem_object *tmp; + +spin_lock (&filp->table_lock); +idr_for_each_entry (&filp->object_idr, tmp, i) { +if (obj == tmp) { +drm_gem_object_reference (obj); +spin_unlock (&filp->table_lock); +return i; + } + }Please double check if that is still up to date.
I think we could as well try to use the DMA-buf handle tree for that.
Christian.
Quoted 109 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +49
-0+spin_unlock (&filp->table_lock); + +return 0 ; +} + +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +union drm_amdgpu_gem_find_bo *args = data; +struct drm_gem_object *gobj; +struct amdgpu_bo *bo; +struct ttm_buffer_object *tbo; +struct vm_area_struct *vma; +uint32_t handle; +int r; + +if (offset_in_page (args->in.addr | args->in.size)) +return -EINVAL ; + +down_read (¤t->mm->mmap_sem); + vma =find_vma (current->mm, args->in.addr); +if (!vma || vma->vm_file != filp->filp || + (args->in.size > (vma->vm_end - args->in.addr))) { + args->out.handle =0 ; +up_read (¤t->mm->mmap_sem); +return -EINVAL ; + } + args->out.offset = args->in.addr - vma->vm_start; + + tbo = vma->vm_private_data; + bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_ref (bo); + gobj = &bo->gem_base; + + handle =amdgpu_gem_get_handle_from_object (filp, gobj); +if (!handle) { + r =drm_gem_handle_create (filp, gobj, &handle); +if (r) { +DRM_ERROR ("create gem handle failed\n" ); +up_read (¤t->mm->mmap_sem); +return r; + } + } + args->out.handle = handle; +up_read (¤t->mm->mmap_sem); + +return 0 ; +} +int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3
-1@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) +DRM_IOCTL_DEF_DRV (AMDGPU_FREESYNC , amdgpu_display_freesync_ioctl,DRM_MASTER ), +DRM_IOCTL_DEF_DRV (AMDGPU_GEM_FIND_BO , +amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };const int amdgpu_max_kms_ioctl =ARRAY_SIZE (amdgpu_ioctls_kms);(quoted diff) +0
-0
b/include/uapi/drm/amdgpu_drm.hindex 94444ee..000c415 100644include/uapi/drm/amdgpu_drm.h +19
-0@@ -54,6 +54,7 @@#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16/* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d@@ -74,6 +75,7 @@#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)#define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo)/** * DOC: memory domains @@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out {struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { +/* CPU address */ +__u64 addr; +/* memory size from CPU address */ +__u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { +/* offset in bo */ +__u64 offset; +/* resulting GEM handle */ +__u32 handle; +}; + +union drm_amdgpu_gem_find_bo { +struct drm_amdgpu_gem_find_bo_in in; +struct drm_amdgpu_gem_find_bo_out out; };
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_gem_wait_idle_out { · line 418
Quoted 4 lines
include/uapi/drm/amdgpu_drm.h +1
-0+struct drm_amdgpu_wait_cs_in {/* Command submission handle * handle equals 0 means none to wait for _______________________________________________
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 49 lines · Christian König
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)
simply some code logicDo we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 40 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +8
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,return 0 ; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, +struct drm_gem_object *obj) +{ +int i; +struct drm_gem_object *tmp; + +spin_lock (&filp->table_lock); +idr_for_each_entry (&filp->object_idr, tmp, i) {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 304
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6
-0+if (obj == tmp) { +drm_gem_object_reference (obj); +spin_unlock (&filp->table_lock); +return i; + } + }Please double check if that is still up to date.
We may have to replace drm_gem_object_reference() with drm_gem_object_get().
On 2nd thought, do we really need to do reference every time?
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Quoted 2 lines
I think we could as well try to use the DMA-buf handle tree for that.
If the bo is not import/export, DMA-buf will be NULL always.
Regards,
Jerry
Quoted 103 lines
Christian.
Quoted 100 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +49
-0+spin_unlock (&filp->table_lock); + +return 0 ; +} + +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +union drm_amdgpu_gem_find_bo *args = data; +struct drm_gem_object *gobj; +struct amdgpu_bo *bo; +struct ttm_buffer_object *tbo; +struct vm_area_struct *vma; +uint32_t handle; +int r; + +if (offset_in_page (args->in.addr | args->in.size)) +return -EINVAL ; + +down_read (¤t->mm->mmap_sem); + vma =find_vma (current->mm, args->in.addr); +if (!vma || vma->vm_file != filp->filp || + (args->in.size > (vma->vm_end - args->in.addr))) { + args->out.handle =0 ; +up_read (¤t->mm->mmap_sem); +return -EINVAL ; + } + args->out.offset = args->in.addr - vma->vm_start; + + tbo = vma->vm_private_data; + bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_ref (bo); + gobj = &bo->gem_base; + + handle =amdgpu_gem_get_handle_from_object (filp, gobj); +if (!handle) { + r =drm_gem_handle_create (filp, gobj, &handle); +if (r) { +DRM_ERROR ("create gem handle failed\n" ); +up_read (¤t->mm->mmap_sem); +return r; + } + } + args->out.handle = handle; +up_read (¤t->mm->mmap_sem); + +return 0 ; +} +int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-1@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) +DRM_IOCTL_DEF_DRV (AMDGPU_FREESYNC , amdgpu_display_freesync_ioctl,DRM_MASTER ), + DRM_IOCTL_DEF_DRV(AMDGPU_GEM_FIND_BO, amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };const int amdgpu_max_kms_ioctl =ARRAY_SIZE (amdgpu_ioctls_kms);include/uapi/drm/amdgpu_drm.h +16
-0@@ -54,6 +54,7 @@#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16/* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d@@ -74,6 +75,7 @@#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)#define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo)/** * DOC: memory domains @@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out {struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { +/* CPU address */ +__u64 addr; +/* memory size from CPU address */ +__u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { +/* offset in bo */ +__u64 offset; +/* resulting GEM handle */ +__u32 handle; +}; +
Quoted 9 lines
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_gem_wait_idle_out { · line 418
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +5
-0+union drm_amdgpu_gem_find_bo { +struct drm_amdgpu_gem_find_bo_in in; +struct drm_amdgpu_gem_find_bo_out out; +}; +struct drm_amdgpu_wait_cs_in {/* Command submission handle * handle equals 0 means none to wait for
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
Quoted 63 lines · Christian König
Quoted 53 lines
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)simply some code logicDo we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 44 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 63
+++++++++++++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c| 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, + struct drm_file *filp); int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,struct
drm_file*filp);
int amdgpu_gem_wait_idle_ioctl(structdrm_device*dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +8
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, return 0; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, + struct drm_gem_object *obj) +{ + int i; + struct drm_gem_object *tmp; + + spin_lock(&filp->table_lock); + idr_for_each_entry(&filp->object_idr, tmp, i) {Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 304
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6
-0+ if (obj == tmp) { + drm_gem_object_reference(obj); + spin_unlock(&filp->table_lock); + return i; + } + }Please double check if that is still up to date.
Quoted 3 lines
We may have to replace
drm_gem_object_reference()withdrm_gem_object_get().On 2nd thought, do we really need to do reference every time?
Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
Quoted 1 line
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
So that needs to be solved before we can upstream the changes.
Regards,
Christian.
Quoted 128 lines
Quoted 4 lines
I think we could as well try to use the DMA-buf handle tree for that.
If the bo is not import/export, DMA-buf will be NULL always.
Regards,
JerryQuoted 110 lines
Christian.
Quoted 107 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +49
-0+spin_unlock (&filp->table_lock); + + return 0; +} + +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, + struct drm_file *filp) +{ + union drm_amdgpu_gem_find_bo *args = data; + struct drm_gem_object *gobj; + struct amdgpu_bo *bo; + struct ttm_buffer_object *tbo; + struct vm_area_struct *vma; + uint32_t handle; + int r; + + if (offset_in_page(args->in.addr | args->in.size)) + return -EINVAL; + + down_read(¤t->mm->mmap_sem); + vma = find_vma(current->mm, args->in.addr); + if (!vma || vma->vm_file != filp->filp || + (args->in.size > (vma->vm_end - args->in.addr))) { + args->out.handle = 0; + up_read(¤t->mm->mmap_sem); + return -EINVAL; + } + args->out.offset = args->in.addr - vma->vm_start; + + tbo = vma->vm_private_data; + bo = container_of(tbo, struct amdgpu_bo, tbo); + amdgpu_bo_ref(bo); + gobj = &bo->gem_base; + + handle = amdgpu_gem_get_handle_from_object(filp, gobj); + if (!handle) { + r = drm_gem_handle_create(filp, gobj, &handle); + if (r) { + DRM_ERROR("create gem handle failed\n"); + up_read(¤t->mm->mmap_sem); + return r; + } + } + args->out.handle = handle; + up_read(¤t->mm->mmap_sem); + + return 0; +} + int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, struct drm_file *filp){
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-1@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe) DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) + DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER), + DRM_IOCTL_DEF_DRV(AMDGPU_GEM_FIND_BO,
amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };
const intamdgpu_max_kms_ioctl=ARRAY_SIZE(amdgpu_ioctls_kms);include/uapi/drm/amdgpu_drm.h +3
-0@@ -54,6 +54,7 @@ #define DRM_AMDGPU_VM 0x13 #define DRM_AMDGPU_FENCE_TO_HANDLE 0x14 #define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16 /* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d@@ -74,6 +75,7 @@ #define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle) #define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched) #define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo) /*** DOC: memory domains
include/uapi/drm/amdgpu_drm.h +14
-0@@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out { struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { + /* CPU address */ + __u64 addr; + /* memory size from CPU address */ + __u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { + /* offset in bo */ + __u64 offset; + /* resulting GEM handle */ + __u32 handle; +}; +Quoted 9 lines
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_gem_wait_idle_out { · line 418
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +5
-0+union drm_amdgpu_gem_find_bo { + struct drm_amdgpu_gem_find_bo_in in; + struct drm_amdgpu_gem_find_bo_out out; +}; + struct drm_amdgpu_wait_cs_in { /* Command submission handle* handle equals 0 means none to wait for
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
Quoted 66 lines · Christian König
Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
Quoted 59 lines · Christian König
Quoted 49 lines
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)
simply some code logicDo we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 40 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +8
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,return 0 ; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, +struct drm_gem_object *obj) +{ +int i; +struct drm_gem_object *tmp; + +spin_lock (&filp->table_lock); +idr_for_each_entry (&filp->object_idr, tmp, i) {Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 303
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6
-0+if (obj == tmp) { +drm_gem_object_reference (obj); +spin_unlock (&filp->table_lock); +return i; + } + }Please double check if that is still up to date.
Quoted 3 lines
We may have to replace
drm_gem_object_reference()withdrm_gem_object_get().On 2nd thought, do we really need to do reference every time?
Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
Quoted 7 lines
Quoted 1 line
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
So that needs to be solved before we can upstream the changes.
Thanks for your info.
It's better to fix that before upstream.
Regards,
Jerry
Quoted 130 lines
Regards,
Christian.Quoted 125 lines
Quoted 4 lines
I think we could as well try to use the DMA-buf handle tree for that.
If the bo is not import/export, DMA-buf will be NULL always.
Regards,
JerryQuoted 103 lines
Christian.
Quoted 100 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +49
-0+spin_unlock (&filp->table_lock); + +return 0 ; +} + +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +union drm_amdgpu_gem_find_bo *args = data; +struct drm_gem_object *gobj; +struct amdgpu_bo *bo; +struct ttm_buffer_object *tbo; +struct vm_area_struct *vma; +uint32_t handle; +int r; + +if (offset_in_page (args->in.addr | args->in.size)) +return -EINVAL ; + +down_read (¤t->mm->mmap_sem); + vma =find_vma (current->mm, args->in.addr); +if (!vma || vma->vm_file != filp->filp || + (args->in.size > (vma->vm_end - args->in.addr))) { + args->out.handle =0 ; +up_read (¤t->mm->mmap_sem); +return -EINVAL ; + } + args->out.offset = args->in.addr - vma->vm_start; + + tbo = vma->vm_private_data; + bo = container_of(tbo, struct amdgpu_bo, tbo); +amdgpu_bo_ref (bo); + gobj = &bo->gem_base; + + handle =amdgpu_gem_get_handle_from_object (filp, gobj); +if (!handle) { + r =drm_gem_handle_create (filp, gobj, &handle); +if (r) { +DRM_ERROR ("create gem handle failed\n" ); +up_read (¤t->mm->mmap_sem); +return r; + } + } + args->out.handle = handle; +up_read (¤t->mm->mmap_sem); + +return 0 ; +} +int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-1@@ -1100,7 +1100,8 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), - DRM_IOCTL_DEF_DRV(AMDGPU_FREESYNC, amdgpu_display_freesync_ioctl, DRM_MASTER) +DRM_IOCTL_DEF_DRV (AMDGPU_FREESYNC , amdgpu_display_freesync_ioctl,DRM_MASTER ), + DRM_IOCTL_DEF_DRV(AMDGPU_GEM_FIND_BO, amdgpu_gem_find_bo_by_cpu_mapping_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) };const int amdgpu_max_kms_ioctl =ARRAY_SIZE (amdgpu_ioctls_kms);include/uapi/drm/amdgpu_drm.h +16
-0@@ -54,6 +54,7 @@#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_GEM_FIND_BO 0x16/* not upstream */ #define DRM_AMDGPU_FREESYNC 0x5d@@ -74,6 +75,7 @@#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched)#define DRM_IOCTL_AMDGPU_FREESYNC DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FREESYNC, struct drm_amdgpu_freesync) +#define DRM_IOCTL_AMDGPU_GEM_FIND_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_FIND_BO, union drm_amdgpu_gem_find_bo)/** * DOC: memory domains @@ -392,6 +394,25 @@ struct drm_amdgpu_gem_wait_idle_out {struct drm_amdgpu_gem_wait_idle_out out; }; +struct drm_amdgpu_gem_find_bo_in { +/* CPU address */ +__u64 addr; +/* memory size from CPU address */ +__u64 size; +}; + +struct drm_amdgpu_gem_find_bo_out { +/* offset in bo */ +__u64 offset; +/* resulting GEM handle */ +__u32 handle; +}; +Quoted 9 lines
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_gem_wait_idle_out { · line 417
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +5
-0+union drm_amdgpu_gem_find_bo { +struct drm_amdgpu_gem_find_bo_in in; +struct drm_amdgpu_gem_find_bo_out out; +}; +struct drm_amdgpu_wait_cs_in {/* Command submission handle * handle equals 0 means none to wait for _______________________________________________
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
Am 31.07.2018 um 10:05 schrieb Zhang, Jerry (Junwei):
Quoted 73 lines · Christian König
Quoted 72 lines
Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
Quoted 63 lines · Christian König
Quoted 53 lines
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)simply some code logicDo we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 44 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c| 63
+++++++++++++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c| 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, + struct drm_file *filp); int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,struct
drm_file*filp);
int amdgpu_gem_wait_idle_ioctl(structdrm_device*dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +8
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, return 0; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, + struct drm_gem_object *obj) +{ + int i; + struct drm_gem_object *tmp; + + spin_lock(&filp->table_lock); + idr_for_each_entry(&filp->object_idr, tmp, i) {Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device · line 304
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6
-0+ if (obj == tmp) { + drm_gem_object_reference(obj); + spin_unlock(&filp->table_lock); + return i; + } + }Please double check if that is still up to date.
Quoted 3 lines
We may have to replace
drm_gem_object_reference()withdrm_gem_object_get().On 2nd thought, do we really need to do reference every time?
Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
Quoted 1 line
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Quoted 8 lines
Quoted 5 lines
Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
So that needs to be solved before we can upstream the changes.
Thanks for your info.
It's better to fix that before upstream.
Thinking more about this the hash currently used in libdrm is not adequate any more.
E.g. we now need to be able to find all BOs based on their handle. Since the handles are dense either an r/b tree or a radix tree now sounds like the best approach to me.
Christian.
Quoted 3 lines
Regards,
Jerry
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 74 lines · Christian König
Am 31.07.2018 um 10:05 schrieb Zhang, Jerry (Junwei):
Quoted 73 lines · Christian König
Quoted 72 lines
Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
Quoted 59 lines · Christian König
Quoted 49 lines
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
Quoted 5 lines
From: Chunming Zhou <[email protected]>
v2: get original gem handle from gobj
v3: update find bo data structure asunion(in, out)
simply some code logicDo we now have an open source user for this, so that we can upstream it? One more point below.
Quoted 40 lines
Signed-off-by Chunming Zhou <[email protected]>Signed-off-by Junwei Zhang <[email protected]> (v3)Reviewed-by Christian König <[email protected]>Reviewed-by Jammy Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 63 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +- include/uapi/drm/amdgpu_drm.h | 21 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1213,6 +1213,8 @@ int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);int amdgpu_gem_userptr_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_gem_find_bo_by_cpu_mapping_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp);int amdgpu_gem_mmap_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +8
-0@@ -288,6 +288,69 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,return 0 ; } +static int amdgpu_gem_get_handle_from_object (struct drm_file *filp, +struct drm_gem_object *obj) +{ +int i; +struct drm_gem_object *tmp; + +spin_lock (&filp->table_lock); +idr_for_each_entry (&filp->object_idr, tmp, i) {Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 303
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6
-0+if (obj == tmp) { +drm_gem_object_reference (obj); +spin_unlock (&filp->table_lock); +return i; + } + }Please double check if that is still up to date.
Quoted 3 lines
We may have to replace
drm_gem_object_reference()withdrm_gem_object_get().On 2nd thought, do we really need to do reference every time?
Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
Quoted 1 line
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
So that needs to be solved before we can upstream the changes.
Thanks for your info.
It's better to fix that before upstream.Thinking more about this the hash currently used in libdrm is not adequate any more.
E.g. we now need to be able to find all BOs based on their handle. Since the handles are dense either an r/b tree or a radix tree now sounds like the best approach to me.
Not sure the exact reason that we added hash table in libdrm.
But it really costs much less time than calling IOCTL to find BO by their handles.
In this case, UMD seems not to be able to get BO handle and try to verify it by cpu address then. In another word, UMD would like to find if the memory is created as BO or system memory, I suppose.
Regards,
Jerry
Quoted 7 lines
Christian.
Quoted 3 lines
Regards,
Jerry
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 31.07.2018 um 10:58 schrieb Zhang, Jerry (Junwei):
Quoted 23 lines · Christian König
Quoted 22 lines
Am 31.07.2018 um 10:05 schrieb Zhang, Jerry (Junwei):
Quoted 21 lines · Christian König
Quoted 19 lines
Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
Quoted 8 lines · Christian König
Quoted 3 lines
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
[SNIP]
Please double check if that is still up to date.We may have to replace
drm_gem_object_reference()withdrm_gem_object_get().On 2nd thought, do we really need to do reference every time?
Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
Quoted 1 line
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
So that needs to be solved before we can upstream the changes.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Thanks for your info.
It's better to fix that before upstream.Thinking more about this the hash currently used in libdrm is not adequate any more.
E.g. we now need to be able to find all BOs based on their handle. Since the handles are dense either an r/b tree or a radix tree now sounds like the best approach to me.
Not sure the exact reason that we added hash table in libdrm.
The reason for that was that when a kernel function returns a handle we need to make sure that we always use the same struct amdgpu_bo for it.
Otherwise you run into quite some problems with syncing etc...
Quoted 1 line
But it really costs much less time than calling IOCTL to find BO by their handles.
Well we could just completely drop the kernel implementation and use an userspace implementation.
And yes I agree when we need a tree anyway it would probably be faster than calling the IOCTL to find the BO.
Christian.
Quoted 12 lines
In this case, UMD seems not to be able to get BO handle and try to verify it by cpu address then. In another word, UMD would like to find if the memory is created as BO or system memory, I suppose.
Regards,
JerryQuoted 4 lines
Christian.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
Regards,
Jerry_______________________________________________
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 29 lines · Christian König
Am 31.07.2018 um 10:58 schrieb Zhang, Jerry (Junwei):
Quoted 28 lines · Christian König
Quoted 27 lines
Am 31.07.2018 um 10:05 schrieb Zhang, Jerry (Junwei):
Quoted 15 lines · Christian König
Quoted 14 lines
Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
Quoted 8 lines · Christian König
Quoted 3 lines
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
[SNIP]
Please double check if that is still up to date.We may have to replace
drm_gem_object_reference()withdrm_gem_object_get().On 2nd thought, do we really need to do reference every time?
Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
Quoted 1 line
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Quoted 8 lines
Quoted 5 lines
Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
So that needs to be solved before we can upstream the changes.
Thanks for your info.
It's better to fix that before upstream.Thinking more about this the hash currently used in libdrm is not adequate any more.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
E.g. we now need to be able to find all BOs based on their handle. Since the handles are dense either an r/b tree or a radix tree now sounds like the best approach to me.
Not sure the exact reason that we added hash table in libdrm.
The reason for that was that when a kernel function returns a handle we need to make sure that we always use the same struct
amdgpu_bofor it.Otherwise you run into quite some problems with syncing etc...
Thanks for your explanation.
Quoted 4 lines
Quoted 2 lines
But it really costs much less time than calling IOCTL to find BO by their handles.
Well we could just completely drop the kernel implementation and use an userspace implementation.
Do you mean to implement finding bo by cpu address in libdrm completely? e.g. to create a tree to manage bo handle in libdrm?
Jerry
Quoted 25 lines
And yes I agree when we need a tree anyway it would probably be faster than calling the IOCTL to find the BO.
Christian.
Quoted 19 lines
In this case, UMD seems not to be able to get BO handle and try to verify it by cpu address then. In another word, UMD would like to find if the memory is created as BO or system memory, I suppose.
Regards,
JerryQuoted 7 lines
Christian.
Quoted 3 lines
Regards,
Jerry_______________________________________________
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
Am 31.07.2018 um 11:54 schrieb Zhang, Jerry (Junwei):
Quoted 38 lines · Christian König
Quoted 29 lines
Am 31.07.2018 um 10:58 schrieb Zhang, Jerry (Junwei):
Quoted 28 lines · Christian König
Quoted 27 lines
Am 31.07.2018 um 10:05 schrieb Zhang, Jerry (Junwei):
Quoted 15 lines · Christian König
Quoted 14 lines
Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
Quoted 8 lines · Christian König
Quoted 3 lines
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
[SNIP]
Please double check if that is still up to date.We may have to replace
drm_gem_object_reference()withdrm_gem_object_get().On 2nd thought, do we really need to do reference every time?
Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
Quoted 1 line
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Quoted 8 lines
Quoted 5 lines
Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
So that needs to be solved before we can upstream the changes.
Thanks for your info.
It's better to fix that before upstream.Thinking more about this the hash currently used in libdrm is not adequate any more.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
E.g. we now need to be able to find all BOs based on their handle. Since the handles are dense either an r/b tree or a radix tree now sounds like the best approach to me.
Not sure the exact reason that we added hash table in libdrm.
The reason for that was that when a kernel function returns a handle we need to make sure that we always use the same struct
amdgpu_bofor it.Otherwise you run into quite some problems with syncing etc...
Quoted 8 lines
Thanks for your explanation.
Quoted 4 lines
Quoted 2 lines
But it really costs much less time than calling IOCTL to find BO by their handles.
Well we could just completely drop the kernel implementation and use an userspace implementation.
Do you mean to implement finding bo by cpu address in libdrm completely?
Yes, exactly.
Quoted 1 line
e.g. to create a tree to manage bo handle in libdrm?
I mean when we need to create a tree to map the handle to a BO you could also create a tree to map the CPU pointer to the BO directly and avoid the IOCTL overhead completely.
Christian.
Quoted 28 lines
Jerry
Quoted 25 lines
And yes I agree when we need a tree anyway it would probably be faster than calling the IOCTL to find the BO.
Christian.
Quoted 19 lines
In this case, UMD seems not to be able to get BO handle and try to verify it by cpu address then. In another word, UMD would like to find if the memory is created as BO or system memory, I suppose.
Regards,
JerryQuoted 7 lines
Christian.
Quoted 3 lines
Regards,
Jerry_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
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
Can this be implemented as a wrapper on top of libdrm? So that the tree (or hash table) isn't created for UMDs that don't need it.
Marek
Quoted 130 lines · Christian König
Am 31.07.2018 um 11:54 schrieb Zhang, Jerry (Junwei):
Quoted 71 lines · Christian König
Quoted 53 lines
Am 31.07.2018 um 10:58 schrieb Zhang, Jerry (Junwei):
Quoted 51 lines · Christian König
Quoted 47 lines
Am 31.07.2018 um 10:05 schrieb Zhang, Jerry (Junwei):
Quoted 32 lines · Christian König
Quoted 30 lines
Am 31.07.2018 um 08:58 schrieb Zhang, Jerry (Junwei):
Quoted 8 lines · Christian König
Quoted 4 lines
Am 30.07.2018 um 12:02 schrieb Junwei Zhang:
[SNIP]
Please double check if that is still up to date.Quoted 4 lines
We may have to replace
drm_gem_object_reference()withdrm_gem_object_get().On 2nd thought, do we really need to do reference every time?
Yes, that's a must have. Otherwise the handle could be freed and reused already when we return.
Quoted 2 lines
if UMD find the same gem object for 3 times, it also need to explicitly free(put) that object for 3 times?
Correct yes. Thinking more about this the real problem is to translate the handle into a structure in libdrm.
Here we are back to the problem Marek and Michel has been working on for a while that we always need to be able to translate a handle into a bo structure.....
Quoted 5 lines
Quoted 1 line
So that needs to be solved before we can upstream the changes.
Thanks for your info.
It's better to fix that before upstream.Thinking more about this the hash currently used in libdrm is not adequate any more.
E.g. we now need to be able to find all BOs based on their handle. Since the handles are dense either an r/b tree or a radix tree now sounds like the best approach to me.
Quoted 7 lines
Quoted 1 line
Not sure the exact reason that we added hash table in libdrm.
The reason for that was that when a kernel function returns a handle we need to make sure that we always use the same struct
amdgpu_bofor it.Otherwise you run into quite some problems with syncing etc...
Thanks for your explanation.
Quoted 5 lines
Quoted 3 lines
But it really costs much less time than calling IOCTL to find BO by their handles.
Quoted 5 lines
Quoted 2 lines
Well we could just completely drop the kernel implementation and use an userspace implementation.
Do you mean to implement finding bo by cpu address in libdrm completely?
Yes, exactly.
Quoted 1 line
e.g. to create a tree to manage bo handle in libdrm?
I mean when we need to create a tree to map the handle to a BO you could also create a tree to map the CPU pointer to the BO directly and avoid the IOCTL overhead completely.
Christian.
Quoted 33 lines
Jerry
Quoted 30 lines
And yes I agree when we need a tree anyway it would probably be faster than calling the IOCTL to find the BO.
Christian.
Quoted 22 lines
In this case, UMD seems not to be able to get BO handle and try to verify it by cpu address then.
In another word, UMD would like to find if the memory is created as BO or system memory, I suppose.Regards,
JerryQuoted 8 lines
Christian.
Quoted 3 lines
Regards,
Jerry_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfxQuoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
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
Am 01.08.2018 um 00:07 schrieb Marek Olšák:
Quoted 2 lines
Can this be implemented as a wrapper on top of libdrm? So that the tree (or hash table) isn't created for UMDs that don't need it.
No, the problem is that an application gets a CPU pointer from one API and tries to import that pointer into another one.
In other words we need to implement this independent of the UMD who mapped the BO.
Christian.
Quoted 3 lines
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 11 lines · Christian König
Am 01.08.2018 um 00:07 schrieb Marek Olšák:
Quoted 3 lines
Can this be implemented as a wrapper on top of libdrm? So that the tree (or hash table) isn't created for UMDs that don't need it.
No, the problem is that an application gets a CPU pointer from one API and tries to import that pointer into another one.
In other words we need to implement this independent of the UMD who mapped the BO.
Yeah, it could be an optional feature of libdrm, and other components should be able to disable it to remove the overhead.
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 01.08.2018 um 19:39 schrieb Marek Olšák:
Quoted 6 lines
Quoted 4 lines · Christian König
Am 01.08.2018 um 00:07 schrieb Marek Olšák:
Quoted 2 lines
Can this be implemented as a wrapper on top of libdrm? So that the tree (or hash table) isn't created for UMDs that don't need it.
Quoted 7 lines
Quoted 5 lines
No, the problem is that an application gets a CPU pointer from one API and tries to import that pointer into another one.
In other words we need to implement this independent of the UMD who mapped the BO.
Yeah, it could be an optional feature of libdrm, and other components should be able to disable it to remove the overhead.
The overhead is negligible, the real problem is the memory footprint.
A brief look at the hash implementation in libdrm showed that this is actually really inefficient.
I think we have the choice of implementing a r/b tree to map the CPU pointer addresses or implement a quadratic tree to map the handles.
The later is easy to do and would also allow to get rid of the hash table as well.
Christian.
Quoted 2 lines
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 25 lines · Christian König
Am 01.08.2018 um 19:39 schrieb Marek Olšák:
Quoted 14 lines
Quoted 11 lines · Christian König
Am 01.08.2018 um 00:07 schrieb Marek Olšák:
Quoted 3 lines
Can this be implemented as a wrapper on top of libdrm? So that the tree (or hash table) isn't created for UMDs that don't need it.
No, the problem is that an application gets a CPU pointer from one API and
tries to import that pointer into another one.Quoted 6 lines
Quoted 3 lines
In other words we need to implement this independent of the UMD who mapped
the BO.Yeah, it could be an optional feature of libdrm, and other components should be able to disable it to remove the overhead.
The overhead is negligible, the real problem is the memory footprint.
Quoted 8 lines
A brief look at the hash implementation in libdrm showed that this is actually really inefficient.
I think we have the choice of implementing a r/b tree to map the CPU pointer addresses or implement a quadratic tree to map the handles.
The later is easy to do and would also allow to get rid of the hash table as well.
We can also use the hash table from mesa/src/util.
I don't think the overhead would be negligible. It would be a log(n) insertion in bo_map and a log(n) deletion in bo_unmap. If you did bo_map+bo_unmap 10000 times, would it be negligible?
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 01.08.2018 um 19:59 schrieb Marek Olšák:
Quoted 27 lines
Quoted 25 lines · Christian König
Am 01.08.2018 um 19:39 schrieb Marek Olšák:
Quoted 10 lines
Quoted 8 lines · Christian König
Am 01.08.2018 um 00:07 schrieb Marek Olšák:
Quoted 2 lines
Can this be implemented as a wrapper on top of libdrm? So that the tree (or hash table) isn't created for UMDs that don't need it.
No, the problem is that an application gets a CPU pointer from one API and
tries to import that pointer into another one.Quoted 5 lines
Quoted 3 lines
In other words we need to implement this independent of the UMD who mapped
the BO.Yeah, it could be an optional feature of libdrm, and other components should be able to disable it to remove the overhead.
The overhead is negligible, the real problem is the memory footprint.
A brief look at the hash implementation in libdrm showed that this is actually really inefficient.
I think we have the choice of implementing a r/b tree to map the CPU pointer addresses or implement a quadratic tree to map the handles.
Quoted 7 lines
Quoted 2 lines
The later is easy to do and would also allow to get rid of the hash table as well.
We can also use the hash table from mesa/src/util.
I don't think the overhead would be negligible. It would be a log(n) insertion in
bo_mapand a log(n) deletion inbo_unmap. If you did bo_map+bo_unmap 10000 times, would it be negligible?
Compared to what the kernel needs to do for updating the page tables it is less than 1% of the total work.
The real question is if it wouldn't be simpler to use a tree for the handles. Since the handles are dense you can just use an unbalanced tree which is really easy.
For a tree of the CPU mappings we would need an r/b interval tree, which is hard to implement and quite some overkill.
Do you have any numbers how many BOs really get a CPU mapping in a real world application?
Christian.
Quoted 2 lines
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 55 lines · Christian König
Am 01.08.2018 um 19:59 schrieb Marek Olšák:
Quoted 40 lines
Quoted 29 lines · Christian König
Am 01.08.2018 um 19:39 schrieb Marek Olšák:
Quoted 14 lines
Quoted 11 lines · Christian König
Am 01.08.2018 um 00:07 schrieb Marek Olšák:
Quoted 3 lines
Can this be implemented as a wrapper on top of libdrm? So that the tree (or hash table) isn't created for UMDs that don't need it.
No, the problem is that an application gets a CPU pointer from one API and
tries to import that pointer into another one.Quoted 6 lines
Quoted 3 lines
In other words we need to implement this independent of the UMD who mapped
the BO.Yeah, it could be an optional feature of libdrm, and other components should be able to disable it to remove the overhead.
The overhead is negligible, the real problem is the memory footprint.
A brief look at the hash implementation in libdrm showed that this is actually really inefficient.
Quoted 7 lines
I think we have the choice of implementing a r/b tree to map the CPU pointer
addresses or implement a quadratic tree to map the handles.The later is easy to do and would also allow to get rid of the hash table as
well.Quoted 5 lines
We can also use the hash table from mesa/src/util.
I don't think the overhead would be negligible. It would be a log(n) insertion in
bo_mapand a log(n) deletion inbo_unmap. If you did bo_map+bo_unmap 10000 times, would it be negligible?Compared to what the kernel needs to do for updating the page tables it is less than 1% of the total work.
The real question is if it wouldn't be simpler to use a tree for the handles. Since the handles are dense you can just use an unbalanced tree which is really easy.
Quoted 5 lines
For a tree of the CPU mappings we would need an r/b interval tree, which is hard to implement and quite some overkill.
Do you have any numbers how many BOs really get a CPU mapping in a real world application?
Without our suballocator, we sometimes exceeded the max. mmap limit (~64K). It should be much less with the suballocator with 128KB slabs, probably a few thousands.
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 60 lines · Marek Olšák
Quoted 58 lines · Christian König
Am 01.08.2018 um 19:59 schrieb Marek Olšák:
Quoted 40 lines
Quoted 29 lines · Christian König
Am 01.08.2018 um 19:39 schrieb Marek Olšák:
Quoted 14 lines
Quoted 11 lines · Christian König
Am 01.08.2018 um 00:07 schrieb Marek Olšák:
Quoted 3 lines
Can this be implemented as a wrapper on top of libdrm? So that the tree (or hash table) isn't created for UMDs that don't need it.
No, the problem is that an application gets a CPU pointer from one API and
tries to import that pointer into another one.Quoted 6 lines
Quoted 3 lines
In other words we need to implement this independent of the UMD who mapped
the BO.Yeah, it could be an optional feature of libdrm, and other components should be able to disable it to remove the overhead.
The overhead is negligible, the real problem is the memory footprint.
A brief look at the hash implementation in libdrm showed that this is actually really inefficient.
Quoted 7 lines
I think we have the choice of implementing a r/b tree to map the CPU pointer
addresses or implement a quadratic tree to map the handles.The later is easy to do and would also allow to get rid of the hash table as
well.Quoted 5 lines
We can also use the hash table from mesa/src/util.
I don't think the overhead would be negligible. It would be a log(n) insertion in
bo_mapand a log(n) deletion inbo_unmap. If you did bo_map+bo_unmap 10000 times, would it be negligible?Compared to what the kernel needs to do for updating the page tables it is less than 1% of the total work.
The real question is if it wouldn't be simpler to use a tree for the handles. Since the handles are dense you can just use an unbalanced tree which is really easy.
For a tree of the CPU mappings we would need an r/b interval tree, which is hard to implement and quite some overkill.
Quoted 6 lines
Quoted 2 lines
Do you have any numbers how many BOs really get a CPU mapping in a real world application?
Without our suballocator, we sometimes exceeded the max. mmap limit (~64K). It should be much less with the suballocator with 128KB slabs, probably a few thousands.
Is there a way to verify that it has performance issue if moving the cpu mapping in libdrm hash table from kernel side?
AFAIW, only one game will use that with close OGL.
Regards,
Jerry
Quoted 3 lines
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 02.08.2018 um 08:20 schrieb Zhang, Jerry (Junwei):
Quoted 19 lines · Marek Olšák
Quoted 18 lines
Quoted 15 lines · Christian König
Am 01.08.2018 um 19:59 schrieb Marek Olšák:
Quoted 1 line
[SNIP]
Compared to what the kernel needs to do for updating the page tables it is less than 1% of the total work.
The real question is if it wouldn't be simpler to use a tree for the handles. Since the handles are dense you can just use an unbalanced tree which is really easy.
For a tree of the CPU mappings we would need an r/b interval tree, which is hard to implement and quite some overkill.
Do you have any numbers how many BOs really get a CPU mapping in a real world application?
Quoted 6 lines
Quoted 3 lines
Without our suballocator, we sometimes exceeded the max. mmap limit (~64K). It should be much less with the suballocator with 128KB slabs, probably a few thousands.
Is there a way to verify that it has performance issue if moving the cpu mapping in libdrm hash table from kernel side?
Going to take a look at this, but I have the feeling that the CPU overhead we need to add in userspace isn't that much.
Quoted 2 lines
AFAIW, only one game will use that with close OGL.
Well, I would also say that this is a bug in the game and should be fixed there.
Christian.
Quoted 7 lines
Regards,
JerryQuoted 3 lines
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx