RE: [PATCH] drm/amdkfd: Fix a race condition of vram buffer unref in svm code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[AMD Official Use Only - General]

Reviewed-by: Jesse Zhang <Jesse.Zhang@xxxxxxx>
-----Original Message-----
From: Xiaogang.Chen <xiaogang.chen@xxxxxxx>
Sent: Wednesday, September 27, 2023 11:00 AM
To: amd-gfx@xxxxxxxxxxxxxxxxxxxxx
Cc: Yang, Philip <Philip.Yang@xxxxxxx>; Kuehling, Felix <Felix.Kuehling@xxxxxxx>; Zhang, Jesse(Jie) <Jesse.Zhang@xxxxxxx>; Sierra Guiza, Alejandro (Alex) <Alex.Sierra@xxxxxxx>; Chen, Xiaogang <Xiaogang.Chen@xxxxxxx>; Chen, Xiaogang <Xiaogang.Chen@xxxxxxx>
Subject: [PATCH] drm/amdkfd: Fix a race condition of vram buffer unref in svm code

From: Xiaogang Chen <xiaogang.chen@xxxxxxx>

prange->svm_bo unref can happen in both mmu callback and a callback
prange->after
migrate to system ram. Both are async call in different tasks. Sync svm_bo unref operation to avoid random "use-after-free".

Signed-off-by: Xiaogang.Chen <Xiaogang.Chen@xxxxxxx>
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 70aa882636ab..8e246e848018 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -637,6 +637,15 @@ void svm_range_vram_node_free(struct svm_range *prange)  {
        svm_range_bo_unref(prange->svm_bo);
        prange->ttm_res = NULL;
+       /* serialize prange->svm_bo unref */
+       mutex_lock(&prange->lock);
+       /* prange->svm_bo has not been unref */
+       if (prange->ttm_res) {
+               prange->ttm_res = NULL;
+               mutex_unlock(&prange->lock);
+               svm_range_bo_unref(prange->svm_bo);
+       } else
+               mutex_unlock(&prange->lock);
 }

 struct kfd_node *
--
2.25.1





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux