From: "Chen, Xiaogang" <xiaogang.chen@amd.com>
To: Eric Huang <jinhuieric.huang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdkfd: Fix a race condition of vram buffer unref in svm code
Date: Wed, 27 Sep 2023 10:10:04 -0500 [thread overview]
Message-ID: <ebfb955d-3060-adaa-d526-b2bcb7fe5686@amd.com> (raw)
In-Reply-To: <101279ab-0c40-e169-e1b8-3a171d20bbb7@amd.com>
On 9/27/2023 9:19 AM, Eric Huang wrote:
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> On 2023-09-26 23:00, Xiaogang.Chen wrote:
>> 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;
> Are above two lines not removed?
you are right, It was caused by copy-paste when edit. I tested it
without these two lines. I will remove these two lines when send to gerrit.
Thanks
Xiaogang
>
> Regards,
> Eric
>> + /* 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 *
>
prev parent reply other threads:[~2023-09-27 15:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 3:00 [PATCH] drm/amdkfd: Fix a race condition of vram buffer unref in svm code Xiaogang.Chen
2023-09-27 3:13 ` Zhang, Jesse(Jie)
2023-09-27 13:59 ` Philip Yang
2023-09-27 14:19 ` Eric Huang
2023-09-27 15:10 ` Chen, Xiaogang [this message]
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=ebfb955d-3060-adaa-d526-b2bcb7fe5686@amd.com \
--to=xiaogang.chen@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=jinhuieric.huang@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