aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2010-11-17 07:28:28 -0500
committerDave Airlie <airlied@redhat.com>2010-11-21 22:25:17 -0500
commit96726fe50feae74812a2ccf5d5da23cb01c0a413 (patch)
tree1c5cb041b88e33ae5d10cb9292852cc5ee5fb24b
parent68c4fa31aa52765314b4285a7835368ea35b509c (diff)
drm/ttm: Don't deadlock on recursive multi-bo reservations
Add an aid for the driver to detect deadlocks on multi-bo reservations Update documentation. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Jerome Glisse <j.glisse@gmail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c15
-rw-r--r--include/drm/ttm/ttm_bo_driver.h25
2 files changed, 34 insertions, 6 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 9ef893d5da88..5d8750830dc3 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -223,9 +223,18 @@ int ttm_bo_reserve_locked(struct ttm_buffer_object *bo,
223 /** 223 /**
224 * Deadlock avoidance for multi-bo reserving. 224 * Deadlock avoidance for multi-bo reserving.
225 */ 225 */
226 if (use_sequence && bo->seq_valid && 226 if (use_sequence && bo->seq_valid) {
227 (sequence - bo->val_seq < (1 << 31))) { 227 /**
228 return -EAGAIN; 228 * We've already reserved this one.
229 */
230 if (unlikely(sequence == bo->val_seq))
231 return -EDEADLK;
232 /**
233 * Already reserved by a thread that will not back
234 * off for us. We need to back off.
235 */
236 if (unlikely(sequence - bo->val_seq < (1 << 31)))
237 return -EAGAIN;
229 } 238 }
230 239
231 if (no_wait) 240 if (no_wait)
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 95068e6024db..1e25a40c688e 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -859,6 +859,9 @@ extern void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo);
859 * try again. (only if use_sequence == 1). 859 * try again. (only if use_sequence == 1).
860 * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by 860 * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by
861 * a signal. Release all buffer reservations and return to user-space. 861 * a signal. Release all buffer reservations and return to user-space.
862 * -EBUSY: The function needed to sleep, but @no_wait was true
863 * -EDEADLK: Bo already reserved using @sequence. This error code will only
864 * be returned if @use_sequence is set to true.
862 */ 865 */
863extern int ttm_bo_reserve(struct ttm_buffer_object *bo, 866extern int ttm_bo_reserve(struct ttm_buffer_object *bo,
864 bool interruptible, 867 bool interruptible,
@@ -868,11 +871,27 @@ extern int ttm_bo_reserve(struct ttm_buffer_object *bo,
868/** 871/**
869 * ttm_bo_reserve_locked: 872 * ttm_bo_reserve_locked:
870 * 873 *
871 * Similar to ttm_bo_reserve, but must be called with the glob::lru_lock 874 * @bo: A pointer to a struct ttm_buffer_object.
872 * spinlock held, and will not remove reserved buffers from the lru lists. 875 * @interruptible: Sleep interruptible if waiting.
876 * @no_wait: Don't sleep while trying to reserve, rather return -EBUSY.
877 * @use_sequence: If @bo is already reserved, Only sleep waiting for
878 * it to become unreserved if @sequence < (@bo)->sequence.
879 *
880 * Must be called with struct ttm_bo_global::lru_lock held,
881 * and will not remove reserved buffers from the lru lists.
873 * The function may release the LRU spinlock if it needs to sleep. 882 * The function may release the LRU spinlock if it needs to sleep.
883 * Otherwise identical to ttm_bo_reserve.
884 *
885 * Returns:
886 * -EAGAIN: The reservation may cause a deadlock.
887 * Release all buffer reservations, wait for @bo to become unreserved and
888 * try again. (only if use_sequence == 1).
889 * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by
890 * a signal. Release all buffer reservations and return to user-space.
891 * -EBUSY: The function needed to sleep, but @no_wait was true
892 * -EDEADLK: Bo already reserved using @sequence. This error code will only
893 * be returned if @use_sequence is set to true.
874 */ 894 */
875
876extern int ttm_bo_reserve_locked(struct ttm_buffer_object *bo, 895extern int ttm_bo_reserve_locked(struct ttm_buffer_object *bo,
877 bool interruptible, 896 bool interruptible,
878 bool no_wait, bool use_sequence, 897 bool no_wait, bool use_sequence,