From: Xiaogang.Chen <xiaogang.chen@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Alex.Sierra@amd.com, Philip.Yang@amd.com, felix.kuehling@amd.com,
Jesse.Zhang@amd.com, "Xiaogang . Chen" <Xiaogang.Chen@amd.com>
Subject: [PATCH] drm/amdkfd: Fix a race condition of vram buffer unref in svm code
Date: Tue, 26 Sep 2023 22:00:08 -0500 [thread overview]
Message-ID: <20230927030008.278066-1-xiaogang.chen@amd.com> (raw)
From: Xiaogang Chen <xiaogang.chen@amd.com>
prange->svm_bo unref can happen in both mmu callback and a callback 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@amd.com>
---
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
next reply other threads:[~2023-09-27 3:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 3:00 Xiaogang.Chen [this message]
2023-09-27 3:13 ` [PATCH] drm/amdkfd: Fix a race condition of vram buffer unref in svm code Zhang, Jesse(Jie)
2023-09-27 13:59 ` Philip Yang
2023-09-27 14:19 ` Eric Huang
2023-09-27 15:10 ` Chen, Xiaogang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230927030008.278066-1-xiaogang.chen@amd.com \
--to=xiaogang.chen@amd.com \
--cc=Alex.Sierra@amd.com \
--cc=Jesse.Zhang@amd.com \
--cc=Philip.Yang@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=felix.kuehling@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox