drm/amdgpu: fix UBSAN: Undefined behaviour for amdgpu_fence.c
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix UBSAN: Undefined behaviour for amdgpu_fence.c
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
ring->me might be set as 2 with amdgpu_gfx_kiq_init_ring.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +10 -1
@@ -375,8 +375,17 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;uint64_t index; +bool uvd_ring = false; +int i; + +for (i =0 ; i <AMDGPU_MAX_UVD_INSTANCES ; ++i) { +if (ring == &adev->uvd.inst[i].ring) { + uvd_ring = true; +break ; + } + } -if (ring != &adev->uvd.inst[ring->me].ring) { +if (!uvd_ring) { ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs *4 ); }else {
Signature · 6 lines
2.17.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): [email protected]
Quoted 35 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
ring->memight be set as 2 withamdgpu_gfx_kiq_init_ring.Signed-off-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +2
-0@@ -375,8 +375,17 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;uint64_t index; +bool uvd_ring = false; +int i;
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, · line 388
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8
-1+ +for (i =0 ; i <AMDGPU_MAX_UVD_INSTANCES ; ++i) { +if (ring == &adev->uvd.inst[i].ring) { + uvd_ring = true; +break ; + } + } -if (ring != &adev->uvd.inst[ring->me].ring) { +if (!uvd_ring) {
I think we can just simplify this to:
if (ring->funcs->type != AMDGPU_RING_TYPE_UVD)
Alex
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0
-1ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs *4 ); }else { --2.17.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CADnq5_M18rgTAuJ8U8B+KOPri_2iMw5ykg4QBNM-dEVQPk+A_w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 45 lines · Alex Deucher
Quoted 44 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
ring->memight be set as 2 withamdgpu_gfx_kiq_init_ring.Signed-off-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +9
-0@@ -375,8 +375,17 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;uint64_t index; +bool uvd_ring = false; +int i; + +for (i =0 ; i <AMDGPU_MAX_UVD_INSTANCES ; ++i) { +if (ring == &adev->uvd.inst[i].ring) { + uvd_ring = true; +break ; + } + }
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, · line 388
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1
-1-if (ring != &adev->uvd.inst[ring->me].ring) { +if (!uvd_ring) {I think we can just simplify this to:
if (ring->funcs->type!=AMDGPU_RING_TYPE_UVD)Alex
Need add UVD_ENC also:
if ( ring->funcs->type != AMDGPU_RING_TYPE_UVD && ring->funcs->type != AMDGPU_RING_TYPE_UVD_ENC ) {
After this, this patch is Reviewed-by: James Zhu <[email protected]>
James
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0
-0ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs *4 );} else {--
2.17.1
Quoted 8 lines
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
_______________________________________________
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): 5b36e39b-50be-a027-1344-d3e4d720ec49-5C7GfCeVMHo@public.gmane.org
Quoted 58 lines · James Zhu
Quoted 55 lines · Alex Deucher
Quoted 52 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
ring->memight be set as 2 withamdgpu_gfx_kiq_init_ring.Signed-off-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +10
-1@@ -375,8 +375,17 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;uint64_t index; +bool uvd_ring = false; +int i; + +for (i =0 ; i <AMDGPU_MAX_UVD_INSTANCES ; ++i) { +if (ring == &adev->uvd.inst[i].ring) { + uvd_ring = true; +break ; + } + } -if (ring != &adev->uvd.inst[ring->me].ring) { +if (!uvd_ring) {
Quoted 9 lines
Quoted 4 lines
I think we can just simplify this to:
if (ring->funcs->type!=AMDGPU_RING_TYPE_UVD)Alex
Need add
UVD_ENCalso:if ( ring->funcs->type != AMDGPU_RING_TYPE_UVD && ring->funcs->type != AMDGPU_RING_TYPE_UVD_ENC ) {
The old code never checked against the enc rings. Are you sure they have the same limitation?
Alex
Quoted 23 lines
After this, this patch is Reviewed-by: James Zhu <[email protected]>
James
Quoted 17 lines
Quoted 5 lines
ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs * 4); } else {Quoted 7 lines
--
2.17.1_______________________________________________
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
_______________________________________________
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): CADnq5_OrR8DSVvrDyiBEPx4FEAP1rL-RaR8-zzeAUH44Djx=2A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 57 lines · Alex Deucher
Quoted 56 lines · James Zhu
Quoted 54 lines · Alex Deucher
Quoted 40 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
ring->memight be set as 2 withamdgpu_gfx_kiq_init_ring.Signed-off-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +3
-0@@ -375,8 +375,17 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;uint64_t index; +bool uvd_ring = false; +int i; +drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_start_ring(struct · line 390
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +7
-1+for (i =0 ; i <AMDGPU_MAX_UVD_INSTANCES ; ++i) { +if (ring == &adev->uvd.inst[i].ring) { + uvd_ring = true; +break ; + } + } -if (ring != &adev->uvd.inst[ring->me].ring) { +if (!uvd_ring) {I think we can just simplify this to:
if (ring->funcs->type!=AMDGPU_RING_TYPE_UVD)
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Alex
Need add
UVD_ENCalso:if ( ring->funcs->type != AMDGPU_RING_TYPE_UVD && ring->funcs->type != AMDGPU_RING_TYPE_UVD_ENC ) {The old code never checked against the enc rings. Are you sure they have the same limitation?
I am wrong. thanks! James
Quoted 24 lines
Alex
Quoted 21 lines
After this, this patch is Reviewed-by: James Zhu <[email protected]>
James
Quoted 16 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0
-0ring->fence_drv.cpu_addr =&adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs * 4); } else {Quoted 7 lines
--
2.17.1_______________________________________________
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
_______________________________________________
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): f1a93f3b-2c5a-29d0-5644-dee1f371e475-5C7GfCeVMHo@public.gmane.org
Quoted 68 lines · James Zhu
Quoted 65 lines · Alex Deucher
Quoted 63 lines · James Zhu
Quoted 59 lines · Alex Deucher
Quoted 42 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
ring->memight be set as 2 withamdgpu_gfx_kiq_init_ring.Signed-off-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4
-0@@ -375,8 +375,17 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;uint64_t index; +bool uvd_ring = false; +int i; + +for (i =0 ; i <AMDGPU_MAX_UVD_INSTANCES ; ++i) {drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_start_ring(struct · line 391
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +6
-1+if (ring == &adev->uvd.inst[i].ring) { + uvd_ring = true; +break ; + } + } -if (ring != &adev->uvd.inst[ring->me].ring) { +if (!uvd_ring) {I think we can just simplify this to:
if (ring->funcs->type!=AMDGPU_RING_TYPE_UVD)Alex
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Need add
UVD_ENCalso:if ( ring->funcs->type != AMDGPU_RING_TYPE_UVD && ring->funcs->type != AMDGPU_RING_TYPE_UVD_ENC ) {The old code never checked against the enc rings. Are you sure they have the same limitation?
I am wrong. thanks! James
Actually does the uvd decode ring still have this limitation or is this just some leftover from a hw limitation on an older asic? If it's still required, the current code in amdgpu_fence_driver_start_ring() won't work for multiple instances. The fences for the rings will overwrite each other.
Alex
Quoted 21 lines
Quoted 21 lines
Alex
Quoted 17 lines
After this, this patch is Reviewed-by: James Zhu <[email protected]>
James
Quoted 13 lines
Quoted 12 lines
ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs * 4); } else {--
2.17.1_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
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
A message that is not in the archive (sent off-list or not yet received): CADnq5_Mzh0ie=snVG2Kd=A_9Q6nzwXF7Q9WORKoPYB7DKoLVgQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 65 lines · Alex Deucher
Quoted 64 lines · James Zhu
Quoted 62 lines · Alex Deucher
Quoted 61 lines · James Zhu
Quoted 49 lines · Alex Deucher
Quoted 48 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
ring->memight be set as 2 withamdgpu_gfx_kiq_init_ring.Signed-off-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +9
-0@@ -375,8 +375,17 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;uint64_t index; +bool uvd_ring = false; +int i; + +for (i =0 ; i <AMDGPU_MAX_UVD_INSTANCES ; ++i) { +if (ring == &adev->uvd.inst[i].ring) { + uvd_ring = true; +break ; + } + }Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_start_ring(struct · line 390
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1
-1-if (ring != &adev->uvd.inst[ring->me].ring) { +if (!uvd_ring) {I think we can just simplify this to:
if (ring->funcs->type!=AMDGPU_RING_TYPE_UVD)Alex
Need add
UVD_ENCalso:if ( ring->funcs->type != AMDGPU_RING_TYPE_UVD && ring->funcs->type != AMDGPU_RING_TYPE_UVD_ENC ) {
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
The old code never checked against the enc rings. Are you sure they have the same limitation?
I am wrong. thanks! James
Actually does the uvd decode ring still have this limitation or is this just some leftover from a hw limitation on an older asic?
The code here inherited from old ASICs, and not be revisited since there is no problem in functional wise.
Quoted 4 lines
If
it's still required, the current code inamdgpu_fence_driver_start_ring()won't work for multiple instances. The fences for the rings will overwrite each other.
IIRC Vega20 with 2 instances have separated runtime environment, that should have fence separated as well.
Regards,
Leo
Quoted 26 lines
Alex
Quoted 23 lines
Quoted 23 lines
Alex
Quoted 21 lines
After this, this patch is Reviewed-by: James Zhu <[email protected]>
James
Quoted 16 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0
-0ring->fence_drv.cpu_addr =&adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs * 4); } else {Quoted 7 lines
--
2.17.1_______________________________________________
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
_______________________________________________
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): 607092c8-b508-03e5-1fd2-35e63053fe9e-5C7GfCeVMHo@public.gmane.org
Alex Deucher
Reviewed-byQuoted 90 lines · Leo Liu
Quoted 75 lines · Alex Deucher
Quoted 73 lines · James Zhu
Quoted 70 lines · Alex Deucher
Quoted 68 lines · James Zhu
Quoted 53 lines · Alex Deucher
Quoted 51 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
ring->memight be set as 2 withamdgpu_gfx_kiq_init_ring.Signed-off-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +9
-0@@ -375,8 +375,17 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, {struct amdgpu_device *adev = ring->adev;uint64_t index; +bool uvd_ring = false; +int i; + +for (i =0 ; i <AMDGPU_MAX_UVD_INSTANCES ; ++i) { +if (ring == &adev->uvd.inst[i].ring) { + uvd_ring = true; +break ; + } + }Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_start_ring(struct · line 391
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1
-1-if (ring != &adev->uvd.inst[ring->me].ring) { +if (!uvd_ring) {I think we can just simplify this to:
if (ring->funcs->type!=AMDGPU_RING_TYPE_UVD)Alex
Need add
UVD_ENCalso:if ( ring->funcs->type != AMDGPU_RING_TYPE_UVD && ring->funcs->type != AMDGPU_RING_TYPE_UVD_ENC ) {Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The old code never checked against the enc rings. Are you sure they have the same limitation?
I am wrong. thanks! James
Actually does the uvd decode ring still have this limitation or is this just some leftover from a hw limitation on an older asic?
The code here inherited from old ASICs, and not be revisited since there is no problem in functional wise.
Quoted 7 lines
Quoted 4 lines
If
it's still required, the current code inamdgpu_fence_driver_start_ring()won't work for multiple instances. The fences for the rings will overwrite each other.IIRC Vega20 with 2 instances have separated runtime environment, that should have fence separated as well.
Ok. For some reason I was thinking the instances shared the same copy of the firmware. Anyway, the patch as is is:
We can optimize for newer asics as a later improvement.
Alex
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 1/1 drm/amdgpu: fix UBSAN: Undefined behaviour for amdgpu_fence.c
In reply to a message not in the archive[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
The problem is the ring->me might be more than 1 for ring.
v2: simplified with ring type
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -1
@@ -376,7 +376,7 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,struct amdgpu_device *adev = ring->adev;uint64_t index; -if (ring != &adev->uvd.inst[ring->me].ring) { +if (ring->funcs->type !=AMDGPU_RING_TYPE_UVD ) { ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs *4 ); }else {
Signature · 6 lines
2.17.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): [email protected]
Alex Deucher
Reviewed-byQuoted 18 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
Quoted 5 lines
The problem is the
ring->memight be more than 1 for ring.v2: simplified with ring type
Signed-off-by Leo Liu <[email protected]>
Quoted 20 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1
-2@@ -376,7 +376,7 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,struct amdgpu_device *adev = ring->adev;uint64_t index; -if (ring != &adev->uvd.inst[ring->me].ring) { +if (ring->funcs->type !=AMDGPU_RING_TYPE_UVD ) { ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs *4 ); }else { --2.17.1
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 18 lines · Leo Liu
[ 3.866656] index 2 is out of range for type 'amdgpu_uvd_inst [2]' [ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3 [ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: events work_for_cpu_fn [ 3.866702] Call Trace: [ 3.866710] dump_stack+0x85/0xc5 [ 3.866719] ubsan_epilogue+0x9/0x40 [ 3.866727] __ubsan_handle_out_of_bounds+0x89/0x90 [ 3.866737] ? rcu_read_lock_sched_held+0x58/0x60 [ 3.866746] ? __kmalloc+0x26c/0x2d0 [ 3.866846] amdgpu_fence_driver_start_ring+0x259/0x280 [amdgpu] [ 3.866896] amdgpu_ring_init+0x12c/0x710 [amdgpu] [ 3.866906] ? sprintf+0x42/0x50 [ 3.866956] amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0 [amdgpu] [ 3.867009] gfx_v8_0_sw_init+0x1ad3/0x2360 [amdgpu] [ 3.867062] ? smu7_init+0xec/0x160 [amdgpu] [ 3.867109] amdgpu_device_init+0x112c/0x1dc0 [amdgpu]
Quoted 1 line
The problem is the
ring->memight be more than 1 for ring.
for UVD and UVD_ENC ring type, after initialization, ring->me is less than AMDGPU_MAX_UVD_INSTANCES (which is set 2 in current code base)
James
Quoted 13 lines
v2: simplified with ring type
Signed-off-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, · line 382
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1
-1@@ -376,7 +376,7 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,struct amdgpu_device *adev = ring->adev;uint64_t index; -if (ring != &adev->uvd.inst[ring->me].ring) { +if (ring->funcs->type !=AMDGPU_RING_TYPE_UVD ) { ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs *4 ); }else {
_______________________________________________
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): 1e1a1274-6a93-e17a-33c3-bc73ff59ffe2-5C7GfCeVMHo@public.gmane.org
Quoted 21 lines · James Zhu
Quoted 18 lines · Leo Liu
[ 3.866656] index 2 is out of range for type '
amdgpu_uvd_inst[2]'
[ 3.866667] CPU: 0 PID: 59 Comm: kworker/0:1 Not tainted 4.16.0-rc7+ #3
[ 3.866677] Hardware name: Gigabyte Technology Co., Ltd. GA-990FXA-UD7/GA-990FXA-UD7, BIOS F9 06/08/2012 [ 3.866693] Workqueue: eventswork_for_cpu_fn
[ 3.866702] Call Trace:
[ 3.866710]dump_stack+0x85/0xc5
[ 3.866719]ubsan_epilogue+0x9/0x40
[ 3.866727]__ubsan_handle_out_of_bounds+0x89/0x90
[ 3.866737] ?rcu_read_lock_sched_held+0x58/0x60
[ 3.866746] ?__kmalloc+0x26c/0x2d0
[ 3.866846]amdgpu_fence_driver_start_ring+0x259/0x280[amdgpu]
[ 3.866896]amdgpu_ring_init+0x12c/0x710[amdgpu]
[ 3.866906] ?sprintf+0x42/0x50
[ 3.866956]amdgpu_gfx_kiq_init_ring+0x1bc/0x3a0[amdgpu]
[ 3.867009]gfx_v8_0_sw_init+0x1ad3/0x2360[amdgpu]
[ 3.867062] ?smu7_init+0xec/0x160[amdgpu]
[ 3.867109]amdgpu_device_init+0x112c/0x1dc0[amdgpu]
Quoted 3 lines
Quoted 1 line
The problem is the
ring->memight be more than 1 for ring.for UVD and
UVD_ENCring type, after initialization,ring->meis less thanAMDGPU_MAX_UVD_INSTANCES(which is set 2 in current code base)
The problem has nothing to do with UVD. From the bt, the ring->me might be set as 2 when calling amdgpu_gfx_kiq_init_ring when initialize the gfx ring.
Regards,
Leo
Quoted 19 lines
James
Quoted 18 lines
v2: simplified with ring type
Signed-off-by Leo Liu <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1
-0@@ -376,7 +376,7 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, struct amdgpu_device *adev = ring->adev; uint64_t index; - if (ring != &adev->uvd.inst[ring->me].ring) { + if (ring->funcs->type != AMDGPU_RING_TYPE_UVD) {
Quoted 8 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0
-0ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs * 4);} else {
_______________________________________________
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