]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/amdgpu: Avoid reclaim while holding locks taken in MMU notifier
authorFelix Kuehling <Felix.Kuehling@amd.com>
Fri, 23 Mar 2018 19:32:30 +0000 (15:32 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 3 Aug 2018 05:48:02 +0000 (07:48 +0200)
[ Upstream commit 6e08e0995b8f339fd2a7ee4fa11f17396405ef60 ]

When an MMU notifier runs in memory reclaim context, it can deadlock
trying to take locks that are already held in the thread causing the
memory reclaim. The solution is to avoid memory reclaim while holding
locks that are taken in MMU notifiers.

This commit fixes kmalloc while holding rmn->lock by moving the call
outside the lock. The GFX MMU notifier also locks reservation objects.
I have no good solution for avoiding reclaim while holding reservation
objects. The HSA MMU notifier will not lock any reservation objects.

v2: Moved allocation outside lock instead of using GFP_NOIO

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Acked-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c

index bd67f4cb8e6ce57f6ebec1cd8b654cc87aa38718..3b3ee737657c8ac9b971bd026fabe53157917382 100644 (file)
@@ -316,7 +316,7 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
        unsigned long end = addr + amdgpu_bo_size(bo) - 1;
        struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
        struct amdgpu_mn *rmn;
-       struct amdgpu_mn_node *node = NULL;
+       struct amdgpu_mn_node *node = NULL, *new_node;
        struct list_head bos;
        struct interval_tree_node *it;
 
@@ -324,6 +324,10 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
        if (IS_ERR(rmn))
                return PTR_ERR(rmn);
 
+       new_node = kmalloc(sizeof(*new_node), GFP_KERNEL);
+       if (!new_node)
+               return -ENOMEM;
+
        INIT_LIST_HEAD(&bos);
 
        down_write(&rmn->lock);
@@ -337,13 +341,10 @@ int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
                list_splice(&node->bos, &bos);
        }
 
-       if (!node) {
-               node = kmalloc(sizeof(struct amdgpu_mn_node), GFP_KERNEL);
-               if (!node) {
-                       up_write(&rmn->lock);
-                       return -ENOMEM;
-               }
-       }
+       if (!node)
+               node = new_node;
+       else
+               kfree(new_node);
 
        bo->mn = rmn;