lock/unlock mismatch in ttm_bo.c
Subsystems (3)
Hi all,
In the function ttm_bo_cleanup_refs() it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Thoughts?
Tom
_______________________________________________
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): 1713476e-c17f-9eea-ebd3-6999c760b678-5C7GfCeVMHo@public.gmane.org
Quoted 5 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
(also there are a handful of style issues I'll write up some patches for on Monday :-)).
Cheers,
Tom
_______________________________________________
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): 81e40cdf-6869-57fa-6858-eb77dbfb45a8-5C7GfCeVMHo@public.gmane.org
Am 19.01.2018 um 19:23 schrieb Tom St Denis:
Quoted 9 lines · Tom St Denis
Quoted 5 lines
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right?
Yeah, that used to be a really mess in TTM. Started to work on cleaning this up, but well you know only two hands and one head :)
Quoted 3 lines
Shouldn't the lock be taken/released in the same function ideally?
(also there are a handful of style issues I'll write up some patches for on Monday :-)).
Feel free to provide cleanup patches for both issues, they would be very welcome I think.
Regards,
Christian.
Quoted 7 lines
Cheers,
Tom
_______________________________________________
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 9 lines · Tom St Denis
Quoted 5 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David Zhou
Quoted 9 lines
(also there are a handful of style issues I'll write up some patches for on Monday :-)).
Cheers,
Tom
_______________________________________________
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): 57fdd509-5de6-a7d8-9588-cb2c63b8f451-5C7GfCeVMHo@public.gmane.org
Quoted 6 lines · Chunming Zhou
Quoted 3 lines · Tom St Denis
Quoted 2 lines · Tom St Denis
Hi all,
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Hi David,
Ok I'll see if I can sort this out.
Cheers,
Tom
Quoted 13 lines
Regards,
David ZhouQuoted 9 lines
(also there are a handful of style issues I'll write up some patches for on Monday :-)).
Cheers,
Tom
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David Zhou
Attached is a patch that addresses this.
I can't see any obvious race in functions that call ttm_bo_cleanup_refs() between the time they let go of the lock and the time it's taken again in the call.
Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
Quoted 1 line
From
017ebff407e8d9313f09e4ddd109ac54c3a23fbaMon Sep 17 00:00:00 2001
From: Tom St Denis <[email protected]>
Date: Mon, 22 Jan 2018 06:54:21 -0500
Subject: [PATCH] drm/ttm: Force lock to be taken/released inside
ttm_bo_cleanup_refs()
The function ttm_bo_cleanup_refs() had conditional behaviour on the global LRU lock taken outside the function.
This patch changes it so the lock is always untaken before the function ttm_bo_cleanup_refs() is called and the function takes the lock itself.
--- drivers/gpu/drm/ttm/ttm_bo.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +5 -9
@@ -487,9 +487,6 @@ static void ttm_bo_cleanup_refs_or_queue(struct ttm_buffer_object *bo)* If bo idle, remove from delayed- and lru lists, and unref. * If not idle, do nothing. * -* Must be called with lru_lock and reservation held, this function -* will drop the lru lock and optionally the reservation lock before returning. -* * @interruptible Any sleeps should occur interruptibly. * @no_wait_gpu Never wait for gpu. Return -EBUSY instead. * @unlock_resv Unlock the reservation lock as well.
@@ -503,6 +500,8 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,struct reservation_object *resv;int ret; +spin_lock (&glob->lru_lock); +if (unlikely (list_empty (&bo->ddestroy))) resv = bo->resv;else
@@ -586,17 +585,12 @@ static bool ttm_bo_delayed_delete(struct ttm_bo_device *bdev, bool remove_all)kref_get (&bo->list_kref);list_move_tail (&bo->ddestroy, &removed); +spin_unlock (&glob->lru_lock);if (remove_all || bo->resv != &bo->ttm_resv) { -spin_unlock (&glob->lru_lock);reservation_object_lock (bo->resv,NULL ); - -spin_lock (&glob->lru_lock);ttm_bo_cleanup_refs (bo, false, !remove_all, true); - }else if (reservation_object_trylock (bo->resv)) {ttm_bo_cleanup_refs (bo, false, !remove_all, true); - }else { -spin_unlock (&glob->lru_lock); }kref_put (&bo->list_kref, ttm_bo_release_list);
@@ -782,6 +776,7 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,kref_get (&bo->list_kref);if (!list_empty (&bo->ddestroy)) { +spin_unlock (&glob->lru_lock); ret =ttm_bo_cleanup_refs (bo, ctx->interruptible, ctx->no_wait_gpu, locked);kref_put (&bo->list_kref, ttm_bo_release_list);
@@ -1730,6 +1725,7 @@ int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)kref_get (&bo->list_kref);if (!list_empty (&bo->ddestroy)) { +spin_unlock (&glob->lru_lock); ret =ttm_bo_cleanup_refs (bo, false, false, locked);kref_put (&bo->list_kref, ttm_bo_release_list);return ret;
Signature · 1 line
2.14.3
_______________________________________________
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): 6c1faffd-5347-5763-e377-fd18f2e65928-5C7GfCeVMHo@public.gmane.org
The patch looks fine to me, please send it to dri mail list.
Thanks
Roger(Hongbo.He)
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Tom St Denis
Sent: Wednesday, January 24, 2018 3:25 AM
To: Zhou, David(ChunMing) <[email protected]>
Cc: Koenig, Christian <[email protected]>; amd-gfx mailing list <[email protected]>
Subject: Re: lock/unlock mismatch in ttm_bo.c
Quoted 15 lines · Chunming Zhou
Quoted 12 lines · Tom St Denis
Quoted 9 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Quoted 7 lines
Quoted 3 lines
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David Zhou
Attached is a patch that addresses this.
I can't see any obvious race in functions that callttm_bo_cleanup_refs() between the time they let go of the lock and the time it's taken again in the call.
Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Hi Tom,
Your change looks ok, as Roger suggested, you can send both dri and amd mail lists.
In addition, when I review your patches, I found a bug as the attached, you can send it together with yours if you think that's a right fix.
Regards,
David Zhou
Quoted 20 lines · Tom St Denis
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David ZhouAttached is a patch that addresses this.
Quoted 7 lines
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
From
1375451816c12b3ad0c9b59b7a36bb80d3eab071Mon Sep 17 00:00:00 2001
From: Chunming Zhou <[email protected]>
Date: Wed, 24 Jan 2018 10:59:05 +0800
Subject: [PATCH] ttm: fix double trylock reservation
--- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -1
@@ -530,7 +530,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,return -EBUSY ;spin_lock (&glob->lru_lock); -if (unlock_resv && !reservation_object_trylock (bo->resv)) { +if (!unlock_resv && !reservation_object_trylock (bo->resv)) {/* * We raced, and lost, someone else holds the reservation now, * and is probably busy in ttm_bo_cleanup_memtype_use.
Signature · 1 line
2.14.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): 95054871-ebd3-06a4-e845-9e2d7c7a56f8-5C7GfCeVMHo@public.gmane.org
update the fix.
Quoted 32 lines · Chunming Zhou
Hi Tom,
Your change looks ok, as Roger suggested, you can send both dri and amd mail lists.
In addition, when I review your patches, I found a bug as the attached, you can send it together with yours if you think that's a right fix.
Regards,
David Zhou
Quoted 20 lines · Tom St Denis
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David ZhouAttached is a patch that addresses this.
Quoted 8 lines
Quoted 5 lines
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
From
9f06e6619b47c506fc87471e38de4640c9879a9fMon Sep 17 00:00:00 2001
From: Chunming Zhou <[email protected]>
Date: Wed, 24 Jan 2018 10:59:05 +0800
Subject: [PATCH] ttm: fix double trylock reservation
--- drivers/gpu/drm/ttm/ttm_bo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
@@ -530,7 +530,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,return -EBUSY ;spin_lock (&glob->lru_lock); -if (unlock_resv && !reservation_object_trylock (bo->resv)) { +if (!unlock_resv && !reservation_object_trylock (bo->resv)) {/* * We raced, and lost, someone else holds the reservation now, * and is probably busy in ttm_bo_cleanup_memtype_use.
@@ -542,6 +542,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo,spin_unlock (&glob->lru_lock);return 0 ; } + unlock_resv = true; ret =0 ; }
Signature · 1 line
2.14.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): 7f86e76a-a61d-4420-a752-6efde8a18e88-5C7GfCeVMHo@public.gmane.org
Christian König
NAKNAK, that doesn't looks correct to me. unlock_resv means that the function is allowed to unlock the reservation.
So the original logic seems to do exactly what it is supposed to do. Please keep in mind that reservation_object_trylock returns boolean, not negative error code.
Regards,
Christian.
Am 24.01.2018 um 06:46 schrieb Chunming Zhou:
Quoted 43 lines
update the fix.
Quoted 38 lines · Chunming Zhou
Hi Tom,
Your change looks ok, as Roger suggested, you can send both dri and amd mail lists.
In addition, when I review your patches, I found a bug as the attached, you can send it together with yours if you think that's a right fix.
Regards,
David Zhou
Quoted 25 lines · Tom St Denis
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David ZhouAttached is a patch that addresses this.
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
_______________________________________________
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): 6a54eb41-d251-3026-6a2a-71abc724e3ff-5C7GfCeVMHo@public.gmane.org
Quoted 3 lines · Christian König
NAK, that doesn't looks correct to me.
unlock_resvmeans that the function is allowed to unlock the reservation.So the original logic seems to do exactly what it is supposed to do. Please keep in mind that
reservation_object_trylockreturns boolean, not negative error code.
'unlock_resv = true' means ttm_bo_cleanup_refs() is locked outside, then reservation_object_trylock will return false, then original code 'if (unlock_resv && !reservation_object_trylock(bo->resv))' will always be true, and then return directly. Is my understanding right? is that expected?
Regards,
David Zhou
Quoted 49 lines
Regards,
Christian.Am 24.01.2018 um 06:46 schrieb Chunming Zhou:
Quoted 43 lines
update the fix.
Quoted 38 lines · Chunming Zhou
Hi Tom,
Your change looks ok, as Roger suggested, you can send both dri and amd mail lists.
In addition, when I review your patches, I found a bug as the attached, you can send it together with yours if you think that's a right fix.
Regards,
David Zhou
Quoted 25 lines · Tom St Denis
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David ZhouAttached is a patch that addresses this.
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
_______________________________________________
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): 52f9c9e5-8838-448c-0bef-78d3821313a2-5C7GfCeVMHo@public.gmane.org
Quoted 8 lines · Chunming Zhou
Quoted 3 lines · Christian König
NAK, that doesn't looks correct to me.
unlock_resvmeans that the function is allowed to unlock the reservation.So the original logic seems to do exactly what it is supposed to do. Please keep in mind that
reservation_object_trylockreturns boolean, not negative error code.'
unlock_resv= true' meansttm_bo_cleanup_refs()is locked outside, thenreservation_object_trylockwill return false, then original code 'if (unlock_resv&& !reservation_object_trylock(bo->resv))' will always be true, and then return directly. Is my understanding right? is that expected?
if (unlock_resv) reservation_object_unlock(bo->resv);
Sorry for noise, it was unlocked before.
Regards,
David Zhou
Quoted 54 lines
Regards,
David ZhouQuoted 49 lines
Regards,
Christian.Am 24.01.2018 um 06:46 schrieb Chunming Zhou:
Quoted 43 lines
update the fix.
Quoted 38 lines · Chunming Zhou
Hi Tom,
Your change looks ok, as Roger suggested, you can send both dri and amd mail lists.
In addition, when I review your patches, I found a bug as the attached, you can send it together with yours if you think that's a right fix.
Regards,
David Zhou
Quoted 25 lines · Tom St Denis
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David ZhouAttached is a patch that addresses this.
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
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 24.01.2018 um 10:06 schrieb Chunming Zhou:
Quoted 8 lines · Christian König
Quoted 3 lines
NAK, that doesn't looks correct to me.
unlock_resvmeans that the function is allowed to unlock the reservation.So the original logic seems to do exactly what it is supposed to do. Please keep in mind that
reservation_object_trylockreturns boolean, not negative error code.'
unlock_resv= true' meansttm_bo_cleanup_refs()is locked outside, thenreservation_object_trylockwill return false, then original code 'if (unlock_resv&& !reservation_object_trylock(bo->resv))' will always be true, and then return directly. Is my understanding right? is that expected?
Ah, crap you are right. That must be "!unlock_resv && !reserv...".
But why do you want to set unlock_resv to true?
Regards,
Christian.
Quoted 54 lines
Regards,
David ZhouQuoted 49 lines
Regards,
Christian.Am 24.01.2018 um 06:46 schrieb Chunming Zhou:
Quoted 43 lines
update the fix.
Quoted 38 lines · Chunming Zhou
Hi Tom,
Your change looks ok, as Roger suggested, you can send both dri and amd mail lists.
In addition, when I review your patches, I found a bug as the attached, you can send it together with yours if you think that's a right fix.
Regards,
David Zhou
Quoted 25 lines · Tom St Denis
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David ZhouAttached is a patch that addresses this.
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
_______________________________________________
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): 2c32e0e5-b7bc-25f0-184f-6615d31d6a4d-5C7GfCeVMHo@public.gmane.org
Am 24.01.2018 um 10:10 schrieb Christian König:
Quoted 11 lines
Am 24.01.2018 um 10:06 schrieb Chunming Zhou:
Quoted 8 lines · Christian König
Quoted 3 lines
NAK, that doesn't looks correct to me.
unlock_resvmeans that the function is allowed to unlock the reservation.So the original logic seems to do exactly what it is supposed to do. Please keep in mind that
reservation_object_trylockreturns boolean, not negative error code.'
unlock_resv= true' meansttm_bo_cleanup_refs()is locked outside, thenreservation_object_trylockwill return false, then original code 'if (unlock_resv&& !reservation_object_trylock(bo->resv))' will always be true, and then return directly. Is my understanding right? is that expected?Ah, crap you are right. That must be "!unlock_resv && !reserv...".
No wait a moment. Your initial assumption seems to be incorrect: 'unlock_resv = true' means ttm_bo_cleanup_refs() is locked outside
When unlock_resv = false then that means ttm_bo_cleanup_refs() is locked outside.
And when we assume this, the original code is indeed right.
Christian.
Quoted 61 lines
But why do you want to set
unlock_resvto true?Regards,
Christian.Quoted 54 lines
Regards,
David ZhouQuoted 49 lines
Regards,
Christian.Am 24.01.2018 um 06:46 schrieb Chunming Zhou:
Quoted 43 lines
update the fix.
Quoted 38 lines · Chunming Zhou
Hi Tom,
Your change looks ok, as Roger suggested, you can send both dri and amd mail lists.
In addition, when I review your patches, I found a bug as the attached, you can send it together with yours if you think that's a right fix.
Regards,
David Zhou
Quoted 25 lines · Tom St Denis
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David ZhouAttached is a patch that addresses this.
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 3 lines · Christian König
NAK, that doesn't looks correct to me.
unlock_resvmeans that the function is allowed to unlock the reservation.So the original logic seems to do exactly what it is supposed to do. Please keep in mind that
reservation_object_trylockreturns boolean, not negative error code.
If the cleanup_refs() function assumes the lock is held it shouldn't release it then. My only goal here was to cleanup the lock usage so that it's only manipulated in a single context.
The lock is unlocked a bit before the function ends do the other ttm functions cleanup_refs() call require the ability to take the lock?
Tom
Quoted 49 lines
Regards,
Christian.Am 24.01.2018 um 06:46 schrieb Chunming Zhou:
Quoted 43 lines
update the fix.
Quoted 38 lines · Chunming Zhou
Hi Tom,
Your change looks ok, as Roger suggested, you can send both dri and amd mail lists.
In addition, when I review your patches, I found a bug as the attached, you can send it together with yours if you think that's a right fix.
Regards,
David Zhou
Quoted 25 lines · Tom St Denis
Quoted 8 lines · Chunming Zhou
Quoted 5 lines · Tom St Denis
Quoted 4 lines · Tom St Denis
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David ZhouAttached is a patch that addresses this.
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
That patch won't work correctly like this.
When the lock is dropped it is possible that the BO is removed from the ddelete list and ttm_bo_cleanup_refs() starts to wait for the wrong reservation object.
I think we can remove the wait for bo->resv now and always wait for bo->ttm_resv, but I'm not 100% sure.
Need to double check the code as well,
Christian.
Am 23.01.2018 um 20:25 schrieb Tom St Denis:
Quoted 18 lines · Chunming Zhou
Quoted 8 lines · Tom St Denis
Quoted 5 lines · Tom St Denis
Quoted 4 lines
Hi all,
In the function
ttm_bo_cleanup_refs()it seems possible to get to line 551 without entering the block on 516 which means you'll be unlocking a mutex that wasn't locked.Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Now it might be that in the course of the API this pattern cannot be expressed but it's not clear from the function alone that that is the case.
Looking further it seems the behaviour depends on locking in parent callers. That's kinda a no-no right? Shouldn't the lock be taken/released in the same function ideally?
Same feelings
Regards,
David Zhou
Quoted 7 lines
Attached is a patch that addresses this.
I can't see any obvious race in functions that call
ttm_bo_cleanup_refs()between the time they let go of the lock and the time it's taken again in the call.Running it on my system doesn't produce anything notable though the KASAN with DRI_PRIME=1 issue is still there (this patch neither causes that nor fixes it).
Tom
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx