drm/amdgpu: fix a potential deadlock in amdgpu_bo_create_restricted()
Subsystems (2)
PATCH v2 1/2 drm/amdgpu: fix a potential deadlock in amdgpu_bo_create_restricted()
When ttm_bo_init() fails, the reservation mutex should be unlocked.
In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when ttm_bo_init() fails and the mutex was locked as expected.
This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -1
@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + } bo->tbo.priority =ilog2 (bo->tbo.num_pages);if (kernel)
Signature · 6 lines
2.11.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): 20170209103337.1522-1-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH v2 2/2 drm/amdgpu: report the number of bytes moved at buffer creation
Like ttm_bo_validate(), ttm_bo_init() might need to move BO and the number of bytes moved by TTM should be reported. This can help the throttle buffer migration mechanism to make a better decision.
v2: fix computation
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -1720,6 +1720,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);int amdgpu_cs_get_ring (struct amdgpu_device *adev,u32 ip_type,u32 ip_instance,u32 ring,struct amdgpu_ring **out_ring); +void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev,u64 num_bytes);void amdgpu_ttm_placement_from_domain (struct amdgpu_bo *abo,u32 domain);bool amdgpu_ttm_bo_is_amdgpu_bo (struct ttm_buffer_object *bo);int amdgpu_ttm_tt_get_user_pages (struct ttm_tt *ttm,struct page **pages);
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -2
@@ -351,8 +351,7 @@ static u64 amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev)* submission. This can result in a debt that can stop buffer migrations * temporarily. */ -static void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev, -u64 num_bytes) +void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev,u64 num_bytes) {spin_lock (&adev->mm_stats.lock); adev->mm_stats.accum_us -=bytes_to_us (adev, num_bytes);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
@@ -323,6 +323,7 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,struct amdgpu_bo *bo;enum ttm_bo_type type;unsigned long page_align; +u64 initial_bytes_moved;size_t acc_size;int r;
@@ -399,10 +400,15 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, locked =ww_mutex_trylock (&bo->tbo.ttm_resv.lock);WARN_ON (!locked); } + + initial_bytes_moved =atomic64_read (&adev->num_bytes_moved); r =ttm_bo_init (&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); +amdgpu_cs_report_moved_bytes (adev, +atomic64_read (&adev->num_bytes_moved) - initial_bytes_moved); +if (unlikely (r !=0 )) {if (!resv)ww_mutex_unlock (&bo->tbo.resv->lock);
Signature · 6 lines
2.11.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): 20170209103337.1522-2-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH v2 2/2] drm/amdgpu: report the number of bytes moved at buffer creation
Quoted 3 lines · Samuel Pitoiset
Like
ttm_bo_validate(),ttm_bo_init()might need to move BO and the number of bytes moved by TTM should be reported. This can help the throttle buffer migration mechanism to make a better decision.
Hmm, this could double-count bytes if there's a concurrent CS submission going on.
It's only a heuristic, so I guess it's not too bad, but still - having at least a comment about this would be nice.
Nicolai
Quoted 54 lines
v2: fix computation
Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -1720,6 +1720,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);int amdgpu_cs_get_ring (struct amdgpu_device *adev,u32 ip_type,u32 ip_instance,u32 ring,struct amdgpu_ring **out_ring); +void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev,u64 num_bytes);void amdgpu_ttm_placement_from_domain (struct amdgpu_bo *abo,u32 domain);bool amdgpu_ttm_bo_is_amdgpu_bo (struct ttm_buffer_object *bo);int amdgpu_ttm_tt_get_user_pages (struct ttm_tt *ttm,struct page **pages);drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-2@@ -351,8 +351,7 @@ static u64 amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev)* submission. This can result in a debt that can stop buffer migrations * temporarily. */ -static void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev, -u64 num_bytes) +void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev,u64 num_bytes) {spin_lock (&adev->mm_stats.lock); adev->mm_stats.accum_us -=bytes_to_us (adev, num_bytes);drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0@@ -323,6 +323,7 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,struct amdgpu_bo *bo;enum ttm_bo_type type;unsigned long page_align; +u64 initial_bytes_moved;size_t acc_size;int r;@@ -399,10 +400,15 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, locked =ww_mutex_trylock (&bo->tbo.ttm_resv.lock);WARN_ON (!locked); } + + initial_bytes_moved =atomic64_read (&adev->num_bytes_moved);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 414
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0r =ttm_bo_init (&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); +amdgpu_cs_report_moved_bytes (adev, +atomic64_read (&adev->num_bytes_moved) - initial_bytes_moved); +if (unlikely (r !=0 )) {if (!resv)ww_mutex_unlock (&bo->tbo.resv->lock);
_______________________________________________
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): 758a0adf-3e8c-1860-7528-0099a82e79da-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH v2 2/2] drm/amdgpu: report the number of bytes moved at buffer creation
Am 13.02.2017 um 17:28 schrieb Nicolai Hähnle:
Quoted 8 lines · Samuel Pitoiset
Quoted 3 lines
Like
ttm_bo_validate(),ttm_bo_init()might need to move BO and the number of bytes moved by TTM should be reported. This can help the throttle buffer migration mechanism to make a better decision.Hmm, this could double-count bytes if there's a concurrent CS submission going on.
It's only a heuristic, so I guess it's not too bad, but still - having at least a comment about this would be nice.
Yeah, already working on this.
I've want to give ttm_bo_init and ttm_bo_validate a "context" parameter to count the bytes moved as well as the bytes it is allowed to move (as a new feature) before returning -EBUSY.
Regards,
Christian.
Quoted 73 lines
Nicolai
Quoted 70 lines
v2: fix computation
Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -1720,6 +1720,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);int amdgpu_cs_get_ring (struct amdgpu_device *adev,u32 ip_type,u32 ip_instance,u32 ring,struct amdgpu_ring **out_ring); +void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev,u64 num_bytes); void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32domain);
boolamdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo); int amdgpu_ttm_tt_get_user_pages(structttm_tt*ttm, struct page
**pages);drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0@@ -351,8 +351,7 @@ static u64 amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev) * submission. This can result in a debt that can stop buffermigrations
* temporarily.
*/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-2-static void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev, -u64 num_bytes) +void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64
num_bytes){ spin_lock(&adev->mm_stats.lock); adev->mm_stats.accum_us -= bytes_to_us(adev, num_bytes);drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6
-0@@ -323,6 +323,7 @@ int amdgpu_bo_create_restricted(structamdgpu_device *adev, struct amdgpu_bo *bo;enum ttm_bo_type type;unsigned long page_align; +u64 initial_bytes_moved;size_t acc_size;int r;@@ -399,10 +400,15 @@ int amdgpu_bo_create_restricted(structamdgpu_device *adev, locked =ww_mutex_trylock (&bo->tbo.ttm_resv.lock);WARN_ON (!locked); } + + initial_bytes_moved =atomic64_read (&adev->num_bytes_moved); r =ttm_bo_init (&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); +amdgpu_cs_report_moved_bytes (adev, +atomic64_read (&adev->num_bytes_moved) - initial_bytes_moved); +if (unlikely (r !=0 )) {
Quoted 8 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0if (!resv)ww_mutex_unlock(&bo->tbo.resv->lock);_______________________________________________
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
Re: [PATCH v2 2/2] drm/amdgpu: report the number of bytes moved at buffer creation
In reply to a message not in the archiveQuoted 7 lines · Nicolai Hähnle
Quoted 3 lines · Samuel Pitoiset
Like
ttm_bo_validate(),ttm_bo_init()might need to move BO and the number of bytes moved by TTM should be reported. This can help the throttle buffer migration mechanism to make a better decision.Hmm, this could double-count bytes if there's a concurrent CS submission going on.
You are right.
Thanks Christian for taking care of this.
Quoted 73 lines
It's only a heuristic, so I guess it's not too bad, but still - having at least a comment about this would be nice.
Nicolai
Quoted 67 lines
v2: fix computation
Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0@@ -1720,6 +1720,7 @@ int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);int amdgpu_cs_get_ring (struct amdgpu_device *adev,u32 ip_type,u32 ip_instance,u32 ring,struct amdgpu_ring **out_ring); +void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev,u64 num_bytes); void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32domain);
boolamdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo); int amdgpu_ttm_tt_get_user_pages(structttm_tt*ttm, struct page
**pages);drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-2@@ -351,8 +351,7 @@ static u64amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev) * submission. This can result in a debt that can stop buffer migrations * temporarily. */ -static void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev, -u64 num_bytes) +void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev,u64 num_bytes) {spin_lock(&adev->mm_stats.lock); adev->mm_stats.accum_us -= bytes_to_us(adev, num_bytes);drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0@@ -323,6 +323,7 @@ int amdgpu_bo_create_restricted(structamdgpu_device *adev, struct amdgpu_bo *bo;enum ttm_bo_type type;unsigned long page_align; +u64 initial_bytes_moved;size_t acc_size;int r;@@ -399,10 +400,15 @@ int amdgpu_bo_create_restricted(structamdgpu_device *adev, locked =ww_mutex_trylock (&bo->tbo.ttm_resv.lock);WARN_ON (!locked); } + + initial_bytes_moved =atomic64_read (&adev->num_bytes_moved); r = ttm_bo_init(&adev->mman.bdev, &bo->tbo, size, type, &bo->placement, page_align, !kernel, NULL, acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-0&amdgpu_ttm_bo_destroy); +amdgpu_cs_report_moved_bytes (adev, +atomic64_read (&adev->num_bytes_moved) - initial_bytes_moved); +if (unlikely (r !=0 )) {if (!resv)ww_mutex_unlock(&bo->tbo.resv->lock);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 09.02.2017 um 11:33 schrieb Samuel Pitoiset:
Quoted 12 lines
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
Quoted 6 lines
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve AMDGPU_GEM_CREATE_VRAM_CLEARED handling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>
Nice catch, both patches are Reviewed-by: Christian König <[email protected]>.
Regards,
Christian.
Quoted 11 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 413
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1&amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + } bo->tbo.priority =ilog2 (bo->tbo.num_pages);if (kernel)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 27 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve AMDGPU_GEM_CREATE_VRAM_CLEARED handling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct amdgpu_device *adev, · line 410
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }
I was looking at this myself a couple of weeks back, and I'm pretty sure I had this exact same patch just to realize that it's actually incorrect.
The problem is that ttm_bo_init will actually call the destroy function (in our case, amdgpu_ttm_bo_destroy), so at this point, bo has been freed.
This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Cheers,
Nicolai
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0bo->tbo.priority =ilog2 (bo->tbo.num_pages);if (kernel)
_______________________________________________
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): ef49a53a-6011-0de1-9ff6-3755851daf10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 44 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure I had this exact same patch just to realize that it's actually incorrect.
Quoted 5 lines
The problem is that
ttm_bo_initwill actually call the destroy function (in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xml
The resv->lock has to be unlocked when ttm_bo_init() fails (I checked with a WARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, when drm_vma_offset_add() fails and resv is not NULL, the mutex is not unlocked.
Quoted 10 lines
Cheers,
NicolaiQuoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0bo->tbo.priority =ilog2 (bo->tbo.num_pages);if (kernel)
_______________________________________________
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): 3fc6e61c-cc70-7b10-9abb-45a4f22b3909-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 56 lines · Samuel Pitoiset
Quoted 44 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure I had this exact same patch just to realize that it's actually incorrect.
Quoted 6 lines
The problem is that
ttm_bo_initwill actually call the destroy function (in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
Quoted 7 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.
err, resv is always NULL in this situation.
Quoted 11 lines
Quoted 11 lines
Cheers,
NicolaiQuoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0bo->tbo.priority =ilog2 (bo->tbo.num_pages);if (kernel)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 47 lines · Samuel Pitoiset
Quoted 44 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure I had this exact same patch just to realize that it's actually incorrect.
Quoted 8 lines
Quoted 6 lines
The problem is that
ttm_bo_initwill actually call the destroy function (in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 7 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.
On which code path is the destroy function not called? If that is the case, we're leaking memory.
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Nicolai
_______________________________________________
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): 7c0ece9f-8983-317b-0eae-adaf535c6d06-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 73 lines · Nicolai Hähnle
Quoted 48 lines · Samuel Pitoiset
Quoted 45 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure I had this exact same patch just to realize that it's actually incorrect.
Quoted 8 lines
Quoted 6 lines
The problem is that
ttm_bo_initwill actually call the destroy function (in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 7 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.
Quoted 6 lines
On which code path is the destroy function not called? If that is the case, we're leaking memory.
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Actually, I find it extremely suspicious that this patch resolves hangs. By all rights, no other task should have a pointer to this bo left. It points at problems elsewhere in the code, possibly the precise problem I've been trying to track down.
Could you please revert the patch, reproduce the hang, and report /proc/$pid/stack for all the hung tasks?
Thanks,
Nicolai
_______________________________________________
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): ed01ca29-e255-62f8-ca99-f079de294eda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 78 lines · Nicolai Hähnle
Quoted 77 lines · Nicolai Hähnle
Quoted 49 lines · Samuel Pitoiset
Quoted 46 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.Quoted 8 lines
Quoted 6 lines
The problem is that
ttm_bo_initwill actually call the destroy function (in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 7 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.On which code path is the destroy function not called? If that is the case, we're leaking memory.
Quoted 8 lines
Quoted 3 lines
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Actually, I find it extremely suspicious that this patch resolves hangs. By all rights, no other task should have a pointer to this bo left. It points at problems elsewhere in the code, possibly the precise problem I've been trying to track down.
Well, maybe we are just lucky but as I said, I checked many times to reproduce the issue with that patch applied without any success, you can trust me. Although I'm also starting to think that's not the right solution (and could introduce other ones).
Quoted 3 lines
Could you please revert the patch, reproduce the hang, and report
/proc/$pid/stackfor all the hung tasks?
Sure. The thing is: Hitman's branch has been updated during the weekend and my local installation is broken. I need to re-download the whole game (will take a while).
I will let you know when I'm able to grab that report.
Thanks Nicolai.
Quoted 3 lines
Thanks,
Nicolai
_______________________________________________
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): aaa5ce51-e2e0-f368-c3f0-b94b5afe3881-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 97 lines · Samuel Pitoiset
Quoted 79 lines · Nicolai Hähnle
Quoted 78 lines · Nicolai Hähnle
Quoted 54 lines · Samuel Pitoiset
Quoted 51 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 4 lines
Quoted 2 lines
This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 7 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.On which code path is the destroy function not called? If that is the case, we're leaking memory.
Quoted 8 lines
Quoted 3 lines
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Actually, I find it extremely suspicious that this patch resolves hangs. By all rights, no other task should have a pointer to this bo left. It points at problems elsewhere in the code, possibly the precise problem I've been trying to track down.
Well, maybe we are just lucky but as I said, I checked many times to reproduce the issue with that patch applied without any success, you can trust me. Although I'm also starting to think that's not the right solution (and could introduce other ones).
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Could you please revert the patch, reproduce the hang, and report
/proc/$pid/stackfor all the hung tasks?Sure. The thing is: Hitman's branch has been updated during the weekend and my local installation is broken. I need to re-download the whole game (will take a while).
I will let you know when I'm able to grab that report.
Hmm, so I thought about this some more, and I'm no longer so sure that your bug and mine are the same. If it was related, I'd somehow expect you to get an error about a mutex being destroyed while it's held (at least with lock debugging enabled).
Anyway... we need to change the contract of ttm_bo_init, I'm just not yet sure how, because there are two points of failure: one quite early on, and the second rather late which gets cleaned up by ttm_bo_unref.
Cheers,
Nicolai
Quoted 4 lines
Thanks Nicolai.
Quoted 3 lines
Thanks,
Nicolai
_______________________________________________
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): 4185541c-a3a4-7681-4539-54c5daddd0ac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 110 lines · Nicolai Hähnle
Quoted 100 lines · Samuel Pitoiset
Quoted 82 lines · Nicolai Hähnle
Quoted 81 lines · Nicolai Hähnle
Quoted 54 lines · Samuel Pitoiset
Quoted 51 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 5 lines
Quoted 3 lines
This code is a huge mess. I'm surprised though: have you verified that
this patch actually fixes a hang?Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 9 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function
in all situations. Presumably, whendrm_vma_offset_add()fails and resv
is not NULL, the mutex is not unlocked.On which code path is the destroy function not called? If that is the case, we're leaking memory.
Quoted 8 lines
Quoted 3 lines
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Actually, I find it extremely suspicious that this patch resolves hangs. By all rights, no other task should have a pointer to this bo left. It points at problems elsewhere in the code, possibly the precise problem I've been trying to track down.
Well, maybe we are just lucky but as I said, I checked many times to reproduce the issue with that patch applied without any success, you can trust me. Although I'm also starting to think that's not the right solution (and could introduce other ones).
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Could you please revert the patch, reproduce the hang, and report
/proc/$pid/stackfor all the hung tasks?Sure. The thing is: Hitman's branch has been updated during the weekend and my local installation is broken. I need to re-download the whole game (will take a while).
I will let you know when I'm able to grab that report.
Quoted 8 lines
Hmm, so I thought about this some more, and I'm no longer so sure that your bug and mine are the same. If it was related, I'd somehow expect you to get an error about a mutex being destroyed while it's held (at least with lock debugging enabled).
Anyway... we need to change the contract of
ttm_bo_init, I'm just not yet sure how, because there are two points of failure: one quite early on, and the second rather late which gets cleaned up byttm_bo_unref.
Maybe it would actually be best to split ttm_bo_init into two parts: the initial bulk of structure initialization as the first half, and the ttm_bo_validate in the second half.
Cheers,
Nicolai
Quoted 9 lines
Cheers,
NicolaiQuoted 4 lines
Thanks Nicolai.
Quoted 3 lines
Thanks,
Nicolai
_______________________________________________
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): 60486a5c-0ac3-675e-86f6-67f67db1213c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 116 lines · Nicolai Hähnle
Quoted 115 lines · Nicolai Hähnle
Quoted 100 lines · Samuel Pitoiset
Quoted 82 lines · Nicolai Hähnle
Quoted 81 lines · Nicolai Hähnle
Quoted 54 lines · Samuel Pitoiset
Quoted 51 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 5 lines
Quoted 3 lines
This code is a huge mess. I'm surprised though: have you verified that
this patch actually fixes a hang?Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 9 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function
in all situations. Presumably, whendrm_vma_offset_add()fails and resv
is not NULL, the mutex is not unlocked.On which code path is the destroy function not called? If that is the case, we're leaking memory.
Quoted 8 lines
Quoted 3 lines
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Actually, I find it extremely suspicious that this patch resolves hangs. By all rights, no other task should have a pointer to this bo left. It points at problems elsewhere in the code, possibly the precise problem I've been trying to track down.
Well, maybe we are just lucky but as I said, I checked many times to reproduce the issue with that patch applied without any success, you can trust me. Although I'm also starting to think that's not the right solution (and could introduce other ones).
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Could you please revert the patch, reproduce the hang, and report
/proc/$pid/stackfor all the hung tasks?Sure. The thing is: Hitman's branch has been updated during the weekend and my local installation is broken. I need to re-download the whole game (will take a while).
I will let you know when I'm able to grab that report.
Hmm, so I thought about this some more, and I'm no longer so sure that your bug and mine are the same. If it was related, I'd somehow expect you to get an error about a mutex being destroyed while it's held (at least with lock debugging enabled).
Quoted 5 lines
Quoted 3 lines
Anyway... we need to change the contract of
ttm_bo_init, I'm just not yet sure how, because there are two points of failure: one quite early on, and the second rather late which gets cleaned up byttm_bo_unref.Maybe it would actually be best to split
ttm_bo_initinto two parts: the initial bulk of structure initialization as the first half, and thettm_bo_validatein the second half.
Agreed. Have you gone ahead with your proposal?
Although Samuel's patch isn't best way, it indeed fix a OCL bug which is trying to allocate multiple big buffers.
Thanks,
David Zhou
Quoted 10 lines
Cheers,
NicolaiQuoted 6 lines
Cheers,
NicolaiQuoted 2 lines
Thanks Nicolai.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Thanks,
Nicolai_______________________________________________
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): [email protected]
Quoted 124 lines · On 14.02.2017 03:56, zhoucm1 wrote:
Quoted 121 lines · Nicolai Hähnle
Quoted 120 lines · Nicolai Hähnle
Quoted 105 lines · Samuel Pitoiset
Quoted 89 lines · Nicolai Hähnle
Quoted 81 lines · Nicolai Hähnle
Quoted 55 lines · Samuel Pitoiset
Quoted 52 lines · Nicolai Hähnle
Quoted 30 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 5 lines
Quoted 3 lines
This code is a huge mess. I'm surprised though: have you verified that
this patch actually fixes a hang?Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch
is broken.Quoted 10 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked
with aWARN_ON(is_locked)) because it doesn't call the destroy function
in all situations. Presumably, whendrm_vma_offset_add()fails and resv
is not NULL, the mutex is not unlocked.Quoted 6 lines
On which code path is the destroy function not called? If that is the case, we're leaking memory.
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Quoted 5 lines
Actually, I find it extremely suspicious that this patch resolves hangs.
By all rights, no other task should have a pointer to this bo left. It points at problems elsewhere in the code, possibly the precise problem I've been trying to track down.Well, maybe we are just lucky but as I said, I checked many times to reproduce the issue with that patch applied without any success, you can
trust me. Although I'm also starting to think that's not the right solution (and could introduce other ones).Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Could you please revert the patch, reproduce the hang, and report
/proc/$pid/stackfor all the hung tasks?Sure. The thing is: Hitman's branch has been updated during the weekend and my local installation is broken. I need to re-download the whole game (will take a while).
I will let you know when I'm able to grab that report.
Hmm, so I thought about this some more, and I'm no longer so sure that your bug and mine are the same. If it was related, I'd somehow expect you to get an error about a mutex being destroyed while it's held (at least with lock debugging enabled).
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Anyway... we need to change the contract of
ttm_bo_init, I'm just not yet sure how, because there are two points of failure: one quite early on, and the second rather late which gets cleaned up byttm_bo_unref.Maybe it would actually be best to split
ttm_bo_initinto two parts:
the initial bulk of structure initialization as the first half, and thettm_bo_validatein the second half.Agreed. Have you gone ahead with your proposal?
I'm looking into it now.
Nicolai
Quoted 24 lines
Although Samuel's patch isn't best way, it indeed fix a OCL bug which is trying to allocate multiple big buffers.
Thanks,
David ZhouQuoted 18 lines
Cheers,
NicolaiQuoted 9 lines
Cheers,
NicolaiQuoted 4 lines
Thanks Nicolai.
Quoted 3 lines
Thanks,
Nicolai_______________________________________________
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 142 lines · On Mon, Feb 13, 2017 at 9:56 PM, zhoucm1 <[email protected]> wrote:
Quoted 139 lines · Nicolai Hähnle
Quoted 135 lines · Nicolai Hähnle
Quoted 118 lines · Samuel Pitoiset
Quoted 97 lines · Nicolai Hähnle
Quoted 87 lines · Nicolai Hähnle
Quoted 58 lines · Samuel Pitoiset
Quoted 54 lines · Nicolai Hähnle
Quoted 30 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 6 lines
Quoted 3 lines
This code is a huge mess. I'm surprised though: have you verified that
this patch actually fixes a hang?Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch
is broken.Quoted 9 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function
in all situations. Presumably, whendrm_vma_offset_add()fails and resv
is not NULL, the mutex is not unlocked.Quoted 6 lines
On which code path is the destroy function not called? If that is the case, we're leaking memory.
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Quoted 5 lines
Actually, I find it extremely suspicious that this patch resolves hangs.
By all rights, no other task should have a pointer to this bo left. It points at problems elsewhere in the code, possibly the precise problem I've been trying to track down.Well, maybe we are just lucky but as I said, I checked many times to reproduce the issue with that patch applied without any success, you can trust me. Although I'm also starting to think that's not the right solution (and could introduce other ones).
Quoted 3 lines
Could you please revert the patch, reproduce the hang, and report
/proc/$pid/stackfor all the hung tasks?Quoted 5 lines
Sure. The thing is: Hitman's branch has been updated during the weekend and my local installation is broken. I need to re-download the whole game (will take a while).
I will let you know when I'm able to grab that report.
Hmm, so I thought about this some more, and I'm no longer so sure that your bug and mine are the same. If it was related, I'd somehow expect you to get an error about a mutex being destroyed while it's held (at least with lock debugging enabled).
Anyway... we need to change the contract of
ttm_bo_init, I'm just not yet sure how, because there are two points of failure: one quite early on, and the second rather late which gets cleaned up byttm_bo_unref.
Quoted 7 lines
Quoted 3 lines
Maybe it would actually be best to split
ttm_bo_initinto two parts: the initial bulk of structure initialization as the first half, and thettm_bo_validatein the second half.Agreed. Have you gone ahead with your proposal?
Although Samuel's patch isn't best way, it indeed fix a OCL bug which is trying to allocate multiple big buffers.
I've applied it for now.
Alex
Quoted 26 lines
Thanks,
David ZhouQuoted 16 lines
Cheers,
NicolaiQuoted 11 lines
Cheers,
NicolaiQuoted 5 lines
Thanks Nicolai.
Quoted 4 lines
Thanks,
NicolaiQuoted 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
Quoted 108 lines · Nicolai Hähnle
Quoted 107 lines · Samuel Pitoiset
Quoted 82 lines · Nicolai Hähnle
Quoted 81 lines · Nicolai Hähnle
Quoted 54 lines · Samuel Pitoiset
Quoted 51 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 5 lines
Quoted 3 lines
This code is a huge mess. I'm surprised though: have you verified that
this patch actually fixes a hang?Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 9 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function
in all situations. Presumably, whendrm_vma_offset_add()fails and resv
is not NULL, the mutex is not unlocked.On which code path is the destroy function not called? If that is the case, we're leaking memory.
Quoted 8 lines
Quoted 3 lines
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
Actually, I find it extremely suspicious that this patch resolves hangs. By all rights, no other task should have a pointer to this bo left. It points at problems elsewhere in the code, possibly the precise problem I've been trying to track down.
Well, maybe we are just lucky but as I said, I checked many times to reproduce the issue with that patch applied without any success, you can trust me. Although I'm also starting to think that's not the right solution (and could introduce other ones).
Quoted 3 lines
Could you please revert the patch, reproduce the hang, and report
/proc/$pid/stackfor all the hung tasks?Sure. The thing is: Hitman's branch has been updated during the weekend and my local installation is broken. I need to re-download the whole game (will take a while).
Quoted 6 lines
Quoted 1 line
I will let you know when I'm able to grab that report.
Hmm, so I thought about this some more, and I'm no longer so sure that your bug and mine are the same. If it was related, I'd somehow expect you to get an error about a mutex being destroyed while it's held (at least with lock debugging enabled).
I enabled a bunch of debugging options (include lock debugging) when I investigated into that issue.
Yeah, unclear if it's actually related but something definitely needs to be fixed.
Quoted 13 lines
Anyway... we need to change the contract of
ttm_bo_init, I'm just not yet sure how, because there are two points of failure: one quite early on, and the second rather late which gets cleaned up byttm_bo_unref.Cheers,
NicolaiQuoted 4 lines
Thanks Nicolai.
Quoted 3 lines
Thanks,
Nicolai
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 56 lines · Nicolai Hähnle
Quoted 55 lines · Samuel Pitoiset
Quoted 51 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure I had this exact same patch just to realize that it's actually incorrect.
The problem is that
ttm_bo_initwill actually call the destroy function (in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Quoted 7 lines
Quoted 1 line
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Maybe the issue is somewhere else and this not the proper solution, but I don't think the given patch is broken as-is. It fixes deadlocks which are pretty easy to reproduce with Hitman (as explained in the commit description).
Quoted 10 lines
Quoted 9 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.
Quoted 6 lines
On which code path is the destroy function not called? If that is the case, we're leaking memory.
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
No, I was wrong. resv is always NULL in this situation. The best solution is probably to try to clean up that code path because I do agree: it's a bit messy.
Quoted 2 lines
Nicolai
_______________________________________________
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): e8a51ac0-8319-810a-0fb8-992c3afd4f34-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 65 lines · Samuel Pitoiset
Quoted 62 lines · Nicolai Hähnle
Quoted 49 lines · Samuel Pitoiset
Quoted 46 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.Quoted 8 lines
Quoted 6 lines
The problem is that
ttm_bo_initwill actually call the destroy function (in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
Quoted 7 lines
Quoted 2 lines
This means we need a real fix for this; I still think the current patch is broken.
Maybe the issue is somewhere else and this not the proper solution, but I don't think the given patch is broken as-is. It fixes deadlocks which are pretty easy to reproduce with Hitman (as explained in the commit description).
I'm sorry, but a use-after-free is clearly broken.
Nicolai
Quoted 14 lines
Quoted 14 lines
Quoted 10 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.On which code path is the destroy function not called? If that is the case, we're leaking memory.
Quoted 10 lines
Quoted 3 lines
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
No, I was wrong. resv is always NULL in this situation. The best solution is probably to try to clean up that code path because I do
agree: it's a bit messy.Quoted 2 lines
Nicolai
_______________________________________________
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): eeafbad0-ca3b-ba03-7068-f54dd2119267-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 70 lines · Nicolai Hähnle
Quoted 69 lines · Samuel Pitoiset
Quoted 65 lines · Nicolai Hähnle
Quoted 54 lines · Samuel Pitoiset
Quoted 51 lines · Nicolai Hähnle
Quoted 29 lines · Samuel Pitoiset
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 4 lines
Quoted 2 lines
This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 6 lines
Quoted 4 lines
Maybe the issue is somewhere else and this not the proper solution, but I don't think the given patch is broken as-is. It fixes deadlocks which are pretty easy to reproduce with Hitman (as explained in the commit description).
I'm sorry, but a use-after-free is clearly broken.
You are right. If the destroy callback is called, there is a use-after-free which is bad, really..
Quoted 28 lines
Nicolai
Quoted 24 lines
Quoted 11 lines
Quoted 10 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.Quoted 6 lines
On which code path is the destroy function not called? If that is the case, we're leaking memory.
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
No, I was wrong. resv is always NULL in this situation. The best solution is probably to try to clean up that code path because I do
agree: it's a bit messy.Quoted 2 lines
Nicolai
_______________________________________________
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): 4d8bb8a9-d2b7-2ade-0dd0-8762e1dcc7a5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Am 13.02.2017 um 19:32 schrieb Samuel Pitoiset:
Quoted 73 lines · Nicolai Hähnle
Quoted 70 lines · Samuel Pitoiset
Quoted 69 lines · Nicolai Hähnle
Quoted 65 lines · Samuel Pitoiset
Quoted 54 lines · Nicolai Hähnle
Quoted 51 lines · Samuel Pitoiset
Quoted 29 lines
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 4 lines
Quoted 2 lines
This code is a huge mess. I'm surprised though: have you verified that this patch actually fixes a hang?
Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
This means we need a real fix for this; I still think the current patch is broken.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Maybe the issue is somewhere else and this not the proper solution, but I don't think the given patch is broken as-is. It fixes deadlocks which are pretty easy to reproduce with Hitman (as explained in the commit description).
I'm sorry, but a use-after-free is clearly broken.
You are right. If the destroy callback is called, there is a use-after-free which is bad, really..
bad. Calling the destroy callback when something goes wrong sound fishy to me in the first place when the structure initialized here is allocated by the caller.
Probably best to clean that up from the beginning.
Regards,
Christian.
Quoted 27 lines
Quoted 27 lines
Nicolai
Quoted 23 lines
Quoted 11 lines
Quoted 10 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlThe
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function in all situations. Presumably, whendrm_vma_offset_add()fails and resv is not NULL, the mutex is not unlocked.Quoted 6 lines
On which code path is the destroy function not called? If that is the case, we're leaking memory.
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
No, I was wrong. resv is always NULL in this situation. The best solution is probably to try to clean up that code path because I do
agree: it's a bit messy.Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Nicolai
_______________________________________________
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): 39ea0637-7794-865e-dbf7-6109d295064e-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 83 lines · Christian König
Am 13.02.2017 um 19:32 schrieb Samuel Pitoiset:
Quoted 82 lines · Nicolai Hähnle
Quoted 78 lines · Samuel Pitoiset
Quoted 67 lines · Nicolai Hähnle
Quoted 64 lines · Samuel Pitoiset
Quoted 54 lines · Nicolai Hähnle
Quoted 51 lines · Samuel Pitoiset
Quoted 29 lines
When
ttm_bo_init()fails, the reservation mutex should be unlocked.In debug build, the kernel reported "possible recursive locking detected" in this codepath. For debugging purposes, I also added a "WARN_ON(ww_mutex_is_locked())" when
ttm_bo_init()fails and the mutex was locked as expected.This should fix (random) GPU hangs. The easy way to reproduce the issue is to change the "Super Sampling" option from 1.0 to 2.0 in Hitman. It will create a huge buffer, evict a bunch of buffers (around ~5k) and deadlock.
This regression has been introduced pretty recently.
v2: only release the mutex if resv is NULL
Fixes 12a852219583 ("drm/amdgpu: improve
AMDGPU_GEM_CREATE_VRAM_CLEAREDhandling (v2)")Signed-off-by Samuel Pitoiset <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_restricted(struct · line 411
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-1@@ -403,8 +403,11 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, &bo->placement, page_align, !kernel,NULL , acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, &amdgpu_ttm_bo_destroy); -if (unlikely (r !=0 )) +if (unlikely (r !=0 )) { +if (!resv) +ww_mutex_unlock (&bo->tbo.resv->lock);return r; + }I was looking at this myself a couple of weeks back, and I'm pretty sure
I had this exact same patch just to realize that it's actually incorrect.The problem is that
ttm_bo_initwill actually call the destroy function
(in our case,amdgpu_ttm_bo_destroy), so at this point, bo has been freed.Quoted 5 lines
Quoted 3 lines
This code is a huge mess. I'm surprised though: have you verified that
this patch actually fixes a hang?Yes, I triple-checked. I can't reproduce the hangs with Hitman.
That's surprising, but a relief. Maybe it ties into some of the other problems I'm seeing as well.
Quoted 8 lines
Quoted 3 lines
This means we need a real fix for this; I still think the current patch
is broken.Maybe the issue is somewhere else and this not the proper solution, but I don't think the given patch is broken as-is. It fixes deadlocks which are pretty easy to reproduce with Hitman (as explained in the commit description).
I'm sorry, but a use-after-free is clearly broken.
Quoted 8 lines
Quoted 2 lines
You are right. If the destroy callback is called, there is a use-after-free which is bad, really..
bad. Calling the destroy callback when something goes wrong sound fishy to me in the first place when the structure initialized here is allocated by the caller.
Probably best to clean that up from the beginning.
Yes.
I wonder where the original issue comes from though. I will need to investigate more.
Quoted 41 lines
Regards,
Christian.Quoted 35 lines
Quoted 31 lines
Nicolai
Quoted 26 lines
Quoted 13 lines
Quoted 6 lines
This fixes a deadlock, here's the report:
https://hastebin.com/durodivoma.xmlQuoted 6 lines
The
resv->lockhas to be unlocked whenttm_bo_init()fails (I checked with aWARN_ON(is_locked)) because it doesn't call the destroy function
in all situations. Presumably, whendrm_vma_offset_add()fails and resv
is not NULL, the mutex is not unlocked.Quoted 6 lines
On which code path is the destroy function not called? If that is the case, we're leaking memory.
With the patch as-is, the error paths are either leaking memory (if you're right) or accessing memory after it's freed (otherwise). Obviously, neither is good.
No, I was wrong. resv is always NULL in this situation. The best solution is probably to try to clean up that code path because I do
agree: it's a bit messy.Quoted 2 lines
Nicolai
_______________________________________________
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