[PATCH 2/3] drm/amdgpu: add OOM fallback on PRT teardown
Christian König
deathsimple at vodafone.de
Wed Feb 15 14:57:20 UTC 2017
From: Christian König <christian.koenig at amd.com>
Don't assume kmalloc will always succeed.
Signed-off-by: Christian König <christian.koenig at amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 447cda5..c11b6b6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1194,14 +1194,22 @@ static void amdgpu_vm_update_prt_state(struct amdgpu_device *adev)
}
/**
+ * amdgpu_vm_prt_put - drop a PRT user
+ */
+static void amdgpu_vm_prt_put(struct amdgpu_device *adev)
+{
+ if (atomic_dec_return(&adev->vm_manager.num_prt_mappings) == 0)
+ amdgpu_vm_update_prt_state(adev);
+}
+
+/**
* amdgpu_vm_prt - callback for updating the PRT status
*/
static void amdgpu_vm_prt_cb(struct fence *fence, struct fence_cb *_cb)
{
struct amdgpu_prt_cb *cb = container_of(_cb, struct amdgpu_prt_cb, cb);
- if (atomic_dec_return(&cb->adev->vm_manager.num_prt_mappings) == 0)
- amdgpu_vm_update_prt_state(cb->adev);
+ amdgpu_vm_prt_put(cb->adev);
kfree(cb);
}
@@ -1224,10 +1232,18 @@ static void amdgpu_vm_free_mapping(struct amdgpu_device *adev,
struct amdgpu_prt_cb *cb = kmalloc(sizeof(struct amdgpu_prt_cb),
GFP_KERNEL);
- cb->adev = adev;
- if (!fence || fence_add_callback(fence, &cb->cb,
- amdgpu_vm_prt_cb))
- amdgpu_vm_prt_cb(fence, &cb->cb);
+ if (!cb) {
+ /* Last resort when we are OOM */
+ if (fence)
+ fence_wait(fence, false);
+
+ amdgpu_vm_prt_put(cb->adev);
+ } else {
+ cb->adev = adev;
+ if (!fence || fence_add_callback(fence, &cb->cb,
+ amdgpu_vm_prt_cb))
+ amdgpu_vm_prt_cb(fence, &cb->cb);
+ }
}
kfree(mapping);
}
--
2.5.0
More information about the amd-gfx
mailing list