Commit 0d2b42b0 authored by Christian König's avatar Christian König Committed by Alex Deucher

drm/amdgpu: Revert "remove the userptr rmn->lock"

This reverts commit c02196834456f2d5fad334088b70e98ce4967c34.

In the meantime we moved get_user_pages() outside of the reservation lock,
so that shouldn't be an issue any more
Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 0ccbf119
...@@ -48,7 +48,8 @@ struct amdgpu_mn { ...@@ -48,7 +48,8 @@ struct amdgpu_mn {
/* protected by adev->mn_lock */ /* protected by adev->mn_lock */
struct hlist_node node; struct hlist_node node;
/* objects protected by mm->mmap_sem */ /* objects protected by lock */
struct mutex lock;
struct rb_root objects; struct rb_root objects;
}; };
...@@ -72,7 +73,7 @@ static void amdgpu_mn_destroy(struct work_struct *work) ...@@ -72,7 +73,7 @@ static void amdgpu_mn_destroy(struct work_struct *work)
struct amdgpu_bo *bo, *next_bo; struct amdgpu_bo *bo, *next_bo;
mutex_lock(&adev->mn_lock); mutex_lock(&adev->mn_lock);
down_write(&rmn->mm->mmap_sem); mutex_lock(&rmn->lock);
hash_del(&rmn->node); hash_del(&rmn->node);
rbtree_postorder_for_each_entry_safe(node, next_node, &rmn->objects, rbtree_postorder_for_each_entry_safe(node, next_node, &rmn->objects,
it.rb) { it.rb) {
...@@ -82,7 +83,7 @@ static void amdgpu_mn_destroy(struct work_struct *work) ...@@ -82,7 +83,7 @@ static void amdgpu_mn_destroy(struct work_struct *work)
} }
kfree(node); kfree(node);
} }
up_write(&rmn->mm->mmap_sem); mutex_unlock(&rmn->lock);
mutex_unlock(&adev->mn_lock); mutex_unlock(&adev->mn_lock);
mmu_notifier_unregister_no_release(&rmn->mn, rmn->mm); mmu_notifier_unregister_no_release(&rmn->mn, rmn->mm);
kfree(rmn); kfree(rmn);
...@@ -126,6 +127,8 @@ static void amdgpu_mn_invalidate_range_start(struct mmu_notifier *mn, ...@@ -126,6 +127,8 @@ static void amdgpu_mn_invalidate_range_start(struct mmu_notifier *mn,
/* notification is exclusive, but interval is inclusive */ /* notification is exclusive, but interval is inclusive */
end -= 1; end -= 1;
mutex_lock(&rmn->lock);
it = interval_tree_iter_first(&rmn->objects, start, end); it = interval_tree_iter_first(&rmn->objects, start, end);
while (it) { while (it) {
struct amdgpu_mn_node *node; struct amdgpu_mn_node *node;
...@@ -160,6 +163,8 @@ static void amdgpu_mn_invalidate_range_start(struct mmu_notifier *mn, ...@@ -160,6 +163,8 @@ static void amdgpu_mn_invalidate_range_start(struct mmu_notifier *mn,
amdgpu_bo_unreserve(bo); amdgpu_bo_unreserve(bo);
} }
} }
mutex_unlock(&rmn->lock);
} }
static const struct mmu_notifier_ops amdgpu_mn_ops = { static const struct mmu_notifier_ops amdgpu_mn_ops = {
...@@ -196,6 +201,7 @@ static struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev) ...@@ -196,6 +201,7 @@ static struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev)
rmn->adev = adev; rmn->adev = adev;
rmn->mm = mm; rmn->mm = mm;
rmn->mn.ops = &amdgpu_mn_ops; rmn->mn.ops = &amdgpu_mn_ops;
mutex_init(&rmn->lock);
rmn->objects = RB_ROOT; rmn->objects = RB_ROOT;
r = __mmu_notifier_register(&rmn->mn, mm); r = __mmu_notifier_register(&rmn->mn, mm);
...@@ -242,7 +248,7 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr) ...@@ -242,7 +248,7 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
INIT_LIST_HEAD(&bos); INIT_LIST_HEAD(&bos);
down_write(&rmn->mm->mmap_sem); mutex_lock(&rmn->lock);
while ((it = interval_tree_iter_first(&rmn->objects, addr, end))) { while ((it = interval_tree_iter_first(&rmn->objects, addr, end))) {
kfree(node); kfree(node);
...@@ -256,7 +262,7 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr) ...@@ -256,7 +262,7 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
if (!node) { if (!node) {
node = kmalloc(sizeof(struct amdgpu_mn_node), GFP_KERNEL); node = kmalloc(sizeof(struct amdgpu_mn_node), GFP_KERNEL);
if (!node) { if (!node) {
up_write(&rmn->mm->mmap_sem); mutex_unlock(&rmn->lock);
return -ENOMEM; return -ENOMEM;
} }
} }
...@@ -271,7 +277,7 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr) ...@@ -271,7 +277,7 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
interval_tree_insert(&node->it, &rmn->objects); interval_tree_insert(&node->it, &rmn->objects);
up_write(&rmn->mm->mmap_sem); mutex_unlock(&rmn->lock);
return 0; return 0;
} }
...@@ -297,7 +303,7 @@ void amdgpu_mn_unregister(struct amdgpu_bo *bo) ...@@ -297,7 +303,7 @@ void amdgpu_mn_unregister(struct amdgpu_bo *bo)
return; return;
} }
down_write(&rmn->mm->mmap_sem); mutex_lock(&rmn->lock);
/* save the next list entry for later */ /* save the next list entry for later */
head = bo->mn_list.next; head = bo->mn_list.next;
...@@ -312,6 +318,6 @@ void amdgpu_mn_unregister(struct amdgpu_bo *bo) ...@@ -312,6 +318,6 @@ void amdgpu_mn_unregister(struct amdgpu_bo *bo)
kfree(node); kfree(node);
} }
up_write(&rmn->mm->mmap_sem); mutex_unlock(&rmn->lock);
mutex_unlock(&adev->mn_lock); mutex_unlock(&adev->mn_lock);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment