drm/amdgpu: fix NULL pointer dereference
Subsystems (2)
PATCH 1/2 drm/amdgpu: fix NULL pointer dereference
ttm->sg needs to be checked before accessing its child member.
Call Trace: amdgpu_ttm_backend_destroy+0x12/0x70 [amdgpu] ttm_bo_cleanup_memtype_use+0x3a/0x60 [ttm] ttm_bo_release+0x17d/0x300 [ttm] amdgpu_bo_unref+0x1a/0x30 [amdgpu] amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu+0x78b/0x8b0 [amdgpu] kfd_ioctl_alloc_memory_of_gpu+0x118/0x220 [amdgpu] kfd_ioctl+0x222/0x400 [amdgpu] ? kfd_dev_is_large_bar+0x90/0x90 [amdgpu] __x64_sys_ioctl+0x8e/0xd0 ? __context_tracking_exit+0x52/0x90 do_syscall_64+0x33/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f97f264d317 Code: b3 66 90 48 8b 05 71 4b 2d 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 41 4b 2d 00 f7 d8 64 89 01 48 RSP: 002b:00007ffdb402c338 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 00007f97f3cc63a0 RCX: 00007f97f264d317 RDX: 00007ffdb402c380 RSI: 00000000c0284b16 RDI: 0000000000000003 RBP: 00007ffdb402c380 R08: 00007ffdb402c428 R09: 00000000c4000004 R10: 00000000c4000004 R11: 0000000000000246 R12: 00000000c0284b16 R13: 0000000000000003 R14: 00007f97f3cc63a0 R15: 00007f8836200000
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
@@ -867,7 +867,7 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;/* double check that we don't free the table twice */ -if (!ttm->sg->sgl) +if (!ttm->sg || !ttm->sg->sgl)return ;/* unmap the pages mapped to the device */
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/2 drm/amdgpu: fix compiler warning
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int write = !(gtt->userflags & AMDGPU_GEM_USERPTR_READONLY);
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -2
@@ -824,7 +824,6 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev,struct amdgpu_device *adev =amdgpu_ttm_adev (bdev);struct amdgpu_ttm_tt *gtt = (void *)ttm;int r; -int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY );enum dma_data_direction direction = write ?DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;
@@ -861,7 +860,6 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, {struct amdgpu_device *adev =amdgpu_ttm_adev (bdev);struct amdgpu_ttm_tt *gtt = (void *)ttm; -int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY );enum dma_data_direction direction = write ?DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerRe: [PATCH 2/2] drm/amdgpu: fix compiler warning
Am 30.03.21 um 12:02 schrieb Guchun Chen:
Quoted 2 lines
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY);
Well there seems to be some kind of bug in the compiler if it complains about the code below.
Quoted 11 lines
Signed-off-by Guchun Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- 1 file changed, 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev, · line 827
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-1@@ -824,7 +824,6 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev,struct amdgpu_device *adev =amdgpu_ttm_adev (bdev);struct amdgpu_ttm_tt *gtt = (void *)ttm;int r; -
Better have variable like "r" and "i" declared last.
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, · line 865
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-1int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY );enum dma_data_direction direction = write ?DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;@@ -861,7 +860,6 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, {struct amdgpu_device *adev =amdgpu_ttm_adev (bdev);struct amdgpu_ttm_tt *gtt = (void *)ttm; -int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY );enum dma_data_direction direction = write ?DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
RE: [PATCH 2/2] drm/amdgpu: fix compiler warning
[AMD Public Use]
Inline comments after yours'.
Regards,
Guchun
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, March 30, 2021 6:40 PM
To: Chen, Guchun <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: fix compiler warning
Am 30.03.21 um 12:02 schrieb Guchun Chen:
Quoted 2 lines
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY);
Well there seems to be some kind of bug in the compiler if it complains about the code below.
[Guchun]From linux coding style's perspective, we shall put the declarations together, separated from code by one blank line, right?
Quoted 12 lines
Signed-off-by Guchun Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- 1 file changed, 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev, · line 827
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-1@@ -824,7 +824,6 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev,struct amdgpu_device *adev =amdgpu_ttm_adev (bdev);struct amdgpu_ttm_tt *gtt = (void *)ttm;int r; -
Better have variable like "r" and "i" declared last.
[Guchun]Will send v2 to address this if you don't have objection to this patch.
Christian.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY );enum dma_data_direction direction = write ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE; @@ -861,7 +860,6 @@ static voidamdgpu_ttm_tt_unpin_userptr(struct
ttm_device*bdev,
{
structamdgpu_device*adev =amdgpu_ttm_adev(bdev); structamdgpu_ttm_tt*gtt = (void *)ttm;
-
int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY); enumdma_data_directiondirection = write ?
DMA_BIDIRECTIONAL:DMA_TO_DEVICE;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/2] drm/amdgpu: fix compiler warning
Am 30.03.21 um 15:10 schrieb Chen, Guchun:
Quoted 13 lines
[AMD Public Use]
Inline comments after yours'.
Regards,
Guchun-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, March 30, 2021 6:40 PM
To: Chen, Guchun <[email protected]>; [email protected]; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: fix compiler warning
Quoted 5 lines
Am 30.03.21 um 12:02 schrieb Guchun Chen:
Quoted 2 lines
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int write = !(gtt->userflags & AMDGPU_GEM_USERPTR_READONLY);Well there seems to be some kind of bug in the compiler if it complains about the code below.
[Guchun]From linux coding style's perspective, we shall put the declarations together, separated from code by one blank line, right?
Correct, yes. I don't mind blank lines when you have for example some consts, but others sometimes complain about that.
Quoted 6 lines
Quoted 6 lines
Signed-off-by Guchun Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 -- 1 file changed, 2 deletions(-)
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev, · line 827
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-1@@ -824,7 +824,6 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev,struct amdgpu_device *adev =amdgpu_ttm_adev (bdev);struct amdgpu_ttm_tt *gtt = (void *)ttm;int r; -Better have variable like "r" and "i" declared last.
[Guchun]Will send v2 to address this if you don't have objection to this patch.
Thanks,
Christian.
Quoted 14 lines
Christian.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY );enum dma_data_direction direction = write ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE; @@ -861,7 +860,6 @@ static voidamdgpu_ttm_tt_unpin_userptr(struct
ttm_device*bdev,{ struct amdgpu_device *adev = amdgpu_ttm_adev(bdev); struct amdgpu_ttm_tt *gtt = (void *)ttm;-
int write = !(gtt->userflags &AMDGPU_GEM_USERPTR_READONLY); enumdma_data_directiondirection = write ?
DMA_BIDIRECTIONAL:DMA_TO_DEVICE;
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 30.03.21 um 12:02 schrieb Guchun Chen:
Quoted 24 lines
ttm->sgneeds to be checked before accessing its child member.Call Trace: amdgpu_ttm_backend_destroy+0x12/0x70 [amdgpu] ttm_bo_cleanup_memtype_use+0x3a/0x60 [ttm] ttm_bo_release+0x17d/0x300 [ttm] amdgpu_bo_unref+0x1a/0x30 [amdgpu] amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu+0x78b/0x8b0 [amdgpu] kfd_ioctl_alloc_memory_of_gpu+0x118/0x220 [amdgpu] kfd_ioctl+0x222/0x400 [amdgpu] ? kfd_dev_is_large_bar+0x90/0x90 [amdgpu] __x64_sys_ioctl+0x8e/0xd0 ? __context_tracking_exit+0x52/0x90 do_syscall_64+0x33/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f97f264d317 Code: b3 66 90 48 8b 05 71 4b 2d 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 41 4b 2d 00 f7 d8 64 89 01 48 RSP: 002b:00007ffdb402c338 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 00007f97f3cc63a0 RCX: 00007f97f264d317 RDX: 00007ffdb402c380 RSI: 00000000c0284b16 RDI: 0000000000000003 RBP: 00007ffdb402c380 R08: 00007ffdb402c428 R09: 00000000c4000004 R10: 00000000c4000004 R11: 0000000000000246 R12: 00000000c0284b16 R13: 0000000000000003 R14: 00007f97f3cc63a0 R15: 00007f8836200000
Quoted 1 line
Signed-off-by Guchun Chen <[email protected]>
Yeah I had this one on my TODO list as well.
For now the patch is Acked-by: Christian König <[email protected]>, but I'm not 100% sure if this is the right fix.
Please keep an eye open if anybody complains about issues with this patch, if yes we need to get back to the drawing board.
Christian.
Quoted 9 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, · line 873
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -867,7 +867,7 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;/* double check that we don't free the table twice */ -if (!ttm->sg->sgl) +if (!ttm->sg || !ttm->sg->sgl)return ;/* unmap the pages mapped to the device */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Public Use]
Thanks Christian, I will put laser focus on this patch after merging it.
I notice the same logic in radeon code radeon_ttm_tt_unpin_userptr. Shall I create another patch to fix it as well?
Regards,
Guchun
-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, March 30, 2021 6:39 PM
To: Chen, Guchun <[email protected]>; [email protected]; Koenig, Christian <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: fix NULL pointer dereference
Am 30.03.21 um 12:02 schrieb Guchun Chen:
Quoted 26 lines
ttm->sgneeds to be checked before accessing its child member.Call Trace: amdgpu_ttm_backend_destroy+0x12/0x70 [amdgpu] ttm_bo_cleanup_memtype_use+0x3a/0x60 [ttm] ttm_bo_release+0x17d/0x300 [ttm] amdgpu_bo_unref+0x1a/0x30 [amdgpu] amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu+0x78b/0x8b0 [amdgpu] kfd_ioctl_alloc_memory_of_gpu+0x118/0x220 [amdgpu] kfd_ioctl+0x222/0x400 [amdgpu] ? kfd_dev_is_large_bar+0x90/0x90 [amdgpu] __x64_sys_ioctl+0x8e/0xd0 ? __context_tracking_exit+0x52/0x90 do_syscall_64+0x33/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f97f264d317 Code: b3 66 90 48 8b 05 71 4b 2d 00 64 c7 00 26 00 00 00 48 c7 c0 ffff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 41 4b 2d 00 f7 d8 64 89 01 48
RSP: 002b:00007ffdb402c338 EFLAGS: 00000246ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX:00007f97f3cc63a0RCX:00007f97f264d317
RDX:00007ffdb402c380RSI:00000000c0284b16RDI: 0000000000000003
RBP:00007ffdb402c380R08:00007ffdb402c428R09:00000000c4000004
R10:00000000c4000004R11: 0000000000000246 R12:00000000c0284b16
R13: 0000000000000003 R14:00007f97f3cc63a0R15:00007f8836200000
Quoted 1 line
Signed-off-by Guchun Chen <[email protected]>
Yeah I had this one on my TODO list as well.
For now the patch is Acked-by: Christian König <[email protected]>, but I'm not 100% sure if this is the right fix.
Please keep an eye open if anybody complains about issues with this patch, if yes we need to get back to the drawing board.
Christian.
Quoted 10 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, · line 873
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -867,7 +867,7 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;/* double check that we don't free the table twice */ -if (!ttm->sg->sgl) +if (!ttm->sg || !ttm->sg->sgl)return ;/* unmap the pages mapped to the device */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 30.03.21 um 15:15 schrieb Chen, Guchun:
Quoted 5 lines
[AMD Public Use]
Thanks Christian, I will put laser focus on this patch after merging it.
I notice the same logic in radeon code
radeon_ttm_tt_unpin_userptr. Shall I create another patch to fix it as well?
If you have time, then please do so. Cause those bugs are on my todo list for quite a while and I couldn't find time to fix them.
Regards,
Christian.
Quoted 58 lines
Regards,
Guchun-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, March 30, 2021 6:39 PM
To: Chen, Guchun <[email protected]>; [email protected]; Koenig, Christian <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: fix NULL pointer dereferenceAm 30.03.21 um 12:02 schrieb Guchun Chen:
Quoted 26 lines
ttm->sgneeds to be checked before accessing its child member.Call Trace: amdgpu_ttm_backend_destroy+0x12/0x70 [amdgpu] ttm_bo_cleanup_memtype_use+0x3a/0x60 [ttm] ttm_bo_release+0x17d/0x300 [ttm] amdgpu_bo_unref+0x1a/0x30 [amdgpu] amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu+0x78b/0x8b0 [amdgpu] kfd_ioctl_alloc_memory_of_gpu+0x118/0x220 [amdgpu] kfd_ioctl+0x222/0x400 [amdgpu] ? kfd_dev_is_large_bar+0x90/0x90 [amdgpu] __x64_sys_ioctl+0x8e/0xd0 ? __context_tracking_exit+0x52/0x90 do_syscall_64+0x33/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f97f264d317 Code: b3 66 90 48 8b 05 71 4b 2d 00 64 c7 00 26 00 00 00 48 c7 c0 ffff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 41 4b 2d 00 f7 d8 64 89 01 48
RSP: 002b:00007ffdb402c338 EFLAGS: 00000246ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX:00007f97f3cc63a0RCX:00007f97f264d317
RDX:00007ffdb402c380RSI:00000000c0284b16RDI: 0000000000000003
RBP:00007ffdb402c380R08:00007ffdb402c428R09:00000000c4000004
R10:00000000c4000004R11: 0000000000000246 R12:00000000c0284b16
R13: 0000000000000003 R14:00007f97f3cc63a0R15:00007f8836200000Quoted 1 line
Signed-off-by Guchun Chen <[email protected]>Yeah I had this one on my TODO list as well.
For now the patch is Acked-by: Christian König <[email protected]>, but I'm not 100% sure if this is the right fix.
Please keep an eye open if anybody complains about issues with this patch, if yes we need to get back to the drawing board.
Christian.
Quoted 12 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0@@ -867,7 +867,7 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, DMA_BIDIRECTIONAL :DMA_TO_DEVICE ;
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static void amdgpu_ttm_tt_unpin_userptr(struct ttm_device *bdev, · line 873
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1/* double check that we don't free the table twice */ -if (!ttm->sg->sgl) +if (!ttm->sg || !ttm->sg->sgl)return ;/* unmap the pages mapped to the device */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx