AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Philip Yang <yangp@amd.com>
To: Felix Kuehling <felix.kuehling@amd.com>,
	Philip Yang <Philip.Yang@amd.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdkfd: Fix false positive queue buffer free warning
Date: Wed, 15 Oct 2025 15:59:05 -0400	[thread overview]
Message-ID: <8d7f6229-7a68-22a9-a197-a3ba5abdd020@amd.com> (raw)
In-Reply-To: <d79b9ae7-f444-4d12-a494-f67feffdfca4@amd.com>


On 2025-10-14 15:46, Felix Kuehling wrote:
>
> On 2025-10-10 15:33, Philip Yang wrote:
>> If active queue buffer is freed, kfd_lookup_process_by_mm return NULL,
>> means process exited and mm is gone, it is fine to evict queue then
>> free queue buffer CPU mapping and memory from do_exit.
>
> In that case, kfd2kgd_quiesce_mm will also fail with -ESRCH. I'm 
> surprised you're getting here at all. I would have expected the queues 
> to be already stopped when the process is gone. But it seems that's 
> only done in the kfd_process_wq_release worker. So is there a time 
> window where the queues are still running, but the queue mappings are 
> destroyed and the queues can't be stopped because we can't look up the 
> process from mm any more?
yes, we should only show warning message if process mm is still alive 
when queue buffer is freed and evict the queues.
>
> Maybe we need to stop the queues in kfd_process_notifier_release to be 
> safe. It should only need the DQM lock, which should be safe to take 
> in an MMU notifiers context.

There is race that queue is running when svm is unmapped on CPU,will add 
another patch in v2 to stop user queues when mm release notifier.

Thanks.

Philip

>
> Regards,
>   Felix
>
>
>>
>> Only show warning message if process mm is still alive when queue
>> buffer is freed.
>>
>> Fixes: b049504e211e ("drm/amdkfd: Validate user queue svm memory 
>> residency")
>> Signed-off-by: Philip Yang <Philip.Yang@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 15 ++++++++++++---
>>   1 file changed, 12 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
>> b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
>> index 48c9a211e415..9174f718482a 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
>> @@ -2487,17 +2487,26 @@ svm_range_unmap_from_cpu(struct mm_struct 
>> *mm, struct svm_range *prange,
>>       bool unmap_parent;
>>       uint32_t i;
>>   +    p = kfd_lookup_process_by_mm(mm);
>> +
>>       if (atomic_read(&prange->queue_refcount)) {
>>           int r;
>>   -        pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",
>> -            prange->start << PAGE_SHIFT);
>> +        /*
>> +         * Evict queue if queue buffer freed with warning message.
>> +         * If process is not found, this is free CPU mapping from
>> +         * do_exit, then it is fine to free queue buffer.
>> +         */
>> +        if (p) {
>> +            pr_warn("Freeing queue vital buffer 0x%lx, queue 
>> evicted\n",
>> +                prange->start << PAGE_SHIFT);
>> +        }
>> +
>>           r = kgd2kfd_quiesce_mm(mm, KFD_QUEUE_EVICTION_TRIGGER_SVM);
>>           if (r)
>>               pr_debug("failed %d to quiesce KFD queues\n", r);
>>       }
>>   -    p = kfd_lookup_process_by_mm(mm);
>>       if (!p)
>>           return;
>>       svms = &p->svms;

      reply	other threads:[~2025-10-15 19:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-10 19:33 [PATCH] drm/amdkfd: Fix false positive queue buffer free warning Philip Yang
2025-10-14 19:46 ` Felix Kuehling
2025-10-15 19:59   ` Philip Yang [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=8d7f6229-7a68-22a9-a197-a3ba5abdd020@amd.com \
    --to=yangp@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