Skip to contentSkip to conversation

drm/amdkfd: Fix false positive queue buffer free warning

PATCH In review Philip Yang 4 participants 10 messages Oct 20, 2025 – Oct 22, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 drm/amdkfd: Fix false positive queue buffer free warning

Only show warning message if process mm is still alive when queue buffer is freed.

If kfd_lookup_process_by_mm return NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.

Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -2
index 4d4a47313f5b..d1b2f8525f80 100644
@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,
 	bool unmap_parent;
 	uint32_t i;
 
-	if (atomic_read(&prange->queue_refcount)) {
+	p = kfd_lookup_process_by_mm(mm);
+
+	if (p && atomic_read(&prange->queue_refcount)) {
 		int r;
 
 		pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",
@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,
 			pr_debug("failed %d to quiesce KFD queues\n", r);
 	}
 
-	p = kfd_lookup_process_by_mm(mm);
 	if (!p)
 		return;
 	svms = &p->svms;
Signature · 1 line
2.49.0
#1 lore raw

PATCH v3 2/2 drm/amdkfd: Dequeue user queues when process mm released

Move kfd_process_dequeue_from_all_devices from kfd_process_wq_release to mmu notifier release callback, do it earlier to ensure no system memory access from GPU because the process memory is going to free from CPU after mmu release notifier callback returns.

---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +7 -1
index 849456ac498b..9080d23d22ae 100644
@@ -1162,7 +1162,6 @@ static void kfd_process_wq_release(struct work_struct *work)
 					     release_work);
 	struct dma_fence *ef;
 
-	kfd_process_dequeue_from_all_devices(p);
 	pqm_uninit(&p->pqm);
 
 	/*
@@ -1226,6 +1225,13 @@ static void kfd_process_notifier_release_internal(struct kfd_process *p)
 	cancel_delayed_work_sync(&p->eviction_work);
 	cancel_delayed_work_sync(&p->restore_work);
 
+	/*
+	 * Evict and remove user queues because exit_mmap free process memory,
+	 * it is not safe for GPU to access system memory after mmu release
+	 * notifier callback returns.
+	 */
+	kfd_process_dequeue_from_all_devices(p);
+
 	for (i = 0; i < p->n_pdds; i++) {
 		struct kfd_process_device *pdd = p->pdds[i];
 
Signature · 1 line
2.49.0
#2 lore raw
In reply to Philip Yang
Quoted 17 lines · Philip Yang

Only show warning message if process mm is still alive when queue buffer is freed.

If kfd_lookup_process_by_mm return NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.

Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")
---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 4d4a47313f5b..d1b2f8525f80 100644

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange, · line 2490

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -1
@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,
  	bool unmap_parent;
  	uint32_t i;
 
-	if (atomic_read(&prange->queue_refcount)) {
+	p = kfd_lookup_process_by_mm(mm);

p->mm is null, not p  because driver set p->mm to null. But still prange->queue_refcount is ref of queues from this prange. If app unmap this prange app should have destroyed the queues associated with this prange already. If not, it is not driver issue. I think driver should send this warning anyway to indicate there are queues not destroyed by app before app unmap the prange. It is an app race condition, not driver.

Regards

Xiaogang

Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -1
+
+	if (p && atomic_read(&prange->queue_refcount)) {
  		int r;
 
  		pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",
@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,
  			pr_debug("failed %d to quiesce KFD queues\n", r);
  	}
 
-	p = kfd_lookup_process_by_mm(mm);
  	if (!p)
  		return;
  	svms = &p->svms;
#3 lore raw

[Public]

You can see this error message on CTRL-C or gpu reset conditions.
Those don’t seem like application race conditions to me i.e. the app can’t do anything about terminations it can’t see coming. It appears any bad actor could spam dmesgs with these error messages if they wanted to with the way the driver currently is.

Jon

From: amd-gfx <[email protected]> On Behalf Of Chen, Xiaogang
Sent: Monday, October 20, 2025 12:00 PM
To: Yang, Philip <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>
Subject: Re: [PATCH v3 1/2] drm/amdkfd: Fix false positive queue buffer free warning

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

On 10/20/2025 9:30 AM, Philip Yang wrote:

Only show warning message if process mm is still alive when queue

buffer is freed.

If kfd_lookup_process_by_mm return NULL, means the process is already

exited and mm is gone, it is fine to free queue buffer.

Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")

---

 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0

index 4d4a47313f5b..d1b2f8525f80 100644

--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,

         bool unmap_parent;

         uint32_t i;

- if (atomic_read(&prange->queue_refcount)) {

+ p = kfd_lookup_process_by_mm(mm);

p->mm is null, not p because driver set p->mm to null. But still prange->queue_refcount is ref of queues from this prange. If app unmap this prange app should have destroyed the queues associated with this prange already. If not, it is not driver issue. I think driver should send this warning anyway to indicate there are queues not destroyed by app before app unmap the prange. It is an app race condition, not driver.

Regards

Xiaogang

+

+ if (p && atomic_read(&prange->queue_refcount)) {

                int r;



                pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",

@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,

                        pr_debug("failed %d to quiesce KFD queues\n", r);

         }

- p = kfd_lookup_process_by_mm(mm);

         if (!p)

                return;

         svms = &p->svms;
#7 lore raw
In reply to Chen, Xiaogang
Quoted 23 lines · Xiaogang
Quoted 20 lines · Philip Yang

Only show warning message if process mm is still alive when queue buffer is freed.

If kfd_lookup_process_by_mm return NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.

Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")
---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 4d4a47313f5b..d1b2f8525f80 100644
@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,
  	bool unmap_parent;
  	uint32_t i;
 
Quoted 5 lines

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange, · line 2490

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -1
-	if (atomic_read(&prange->queue_refcount)) {
+	p = kfd_lookup_process_by_mm(mm);

p->mm is null, not p  because driver set p->mm to null. But still prange->queue_refcount is ref of queues from this prange. If app unmap this prange app should have destroyed the queues associated with this prange already. If not, it is not driver issue.

right, we still pr_warn if app unmap the prange with queue_refcount not zero, p is not NULL for this case.

Quoted 3 lines

I think driver should send this warning anyway to indicate there are queues not destroyed by app before app unmap the prange.

if app killed or segmentation fault, mm is gone first, then queue is destroyed in scheduled release wq, then exit_mmap unmap the prange with queue_refcount not zero, p is NULL, should not pr_warn, because warning message "Freeing queue vital buffer...." is not related to app segmentation fault or killed.

Regards,

Philip

Quoted 19 lines

It is an app race condition, not driver.

Regards

Xiaogang

Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -1
+
+	if (p && atomic_read(&prange->queue_refcount)) {
  		int r;
 
  		pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",
@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,
  			pr_debug("failed %d to quiesce KFD queues\n", r);
  	}
 
-	p = kfd_lookup_process_by_mm(mm);
  	if (!p)
  		return;
  	svms = &p->svms;
#8 lore raw
Quoted 30 lines · Philip Yang
Quoted 15 lines · Xiaogang
Quoted 12 lines · Philip Yang

Only show warning message if process mm is still alive when queue buffer is freed.

If kfd_lookup_process_by_mm return NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.

Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_cpu(struct mm_struct *mm, · line 2491

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -0
index 4d4a47313f5b..d1b2f8525f80 100644
@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, 
 struct svm_range *prange,
       bool unmap_parent;
       uint32_t i;
   -    if (atomic_read(&prange->queue_refcount)) {
+    p = kfd_lookup_process_by_mm(mm);

p->mm is null, not p  because driver set p->mm to null. But still prange->queue_refcount is ref of queues from this prange. If app unmap this prange app should have destroyed the queues associated with this prange already. If not, it is not driver issue.

Quoted 5 lines

right, we still pr_warn if app unmap the prange with queue_refcount not zero, p is not NULL for this case.

Quoted 3 lines

I think driver should send this warning anyway to indicate there are queues not destroyed by app before app unmap the prange.

if app killed or segmentation fault, mm is gone first, then queue is destroyed in scheduled release wq, then exit_mmap unmap the prange with queue_refcount not zero, p is NULL, should not pr_warn, because warning message "Freeing queue vital buffer...." is not related to app segmentation fault or killed.

Then can we put pqm_uninit at kfd_process_notifier_release_internal as you did at second patch with kfd_process_dequeue_from_all_devices: destroy queue when mm is gone?

And if this is for the cases "app got killed or segment fault" how important user should not see this warning message? Something was wrong already anyway.

My thought is that prange->queue_refcount means queue number associated with prange. If it got unmap the queues should be destroyed already, if not, something was wrong somewhere, then need send this warning message.

Regards

Xiaogang

Quoted 23 lines

Regards,

Philip

Quoted 18 lines

It is an app race condition, not driver.

Regards

Xiaogang

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
+
+    if (p && atomic_read(&prange->queue_refcount)) {
           int r;
             pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",
@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, 
 struct svm_range *prange,
               pr_debug("failed %d to quiesce KFD queues\n", r);
       }
   -    p = kfd_lookup_process_by_mm(mm);
       if (!p)
           return;

      svms = &p->svms;

#4 lore raw
In reply to Kim, Jonathan
Quoted 10 lines · Jonathan

[Public]

You can see this error message on CTRL-C or gpu reset conditions.

Those don’t seem like application race conditions to me i.e. the app can’t do anything about terminations it can’t see coming.

It appears any bad actor could spam dmesgs with these error messages if they wanted to with the way the driver currently is.

If this warning message comes out due to some unexpected things happened(like ctrl-c) I think user would not be surprised to see some warnings.

Regards

Xiaogang

Quoted 85 lines

Jon

*From:*amd-gfx <[email protected]> *On Behalf Of *Chen, Xiaogang *Sent:* Monday, October 20, 2025 12:00 PM
*To:* Yang, Philip <[email protected]>; [email protected] *Cc:* Kuehling, Felix <[email protected]>
*Subject:* Re: [PATCH v3 1/2] drm/amdkfd: Fix false positive queue buffer free warning

*Caution:*This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

On 10/20/2025 9:30 AM, Philip Yang wrote:

    Only show warning message if process mm is still alive when queue

    buffer is freed.

    If kfd_lookup_process_by_mm return NULL, means the process is already

    exited and mm is gone, it is fine to free queue buffer.

    Fixes: b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")

    Signed-off-by: Philip Yang<[email protected]> <mailto:[email protected]>

    ---

      drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--

      1 file changed, 3 insertions(+), 2 deletions(-)

    diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

    index 4d4a47313f5b..d1b2f8525f80 100644

    --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

    +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

    @@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,

              bool unmap_parent;

              uint32_t i;

      

    -        if (atomic_read(&prange->queue_refcount)) {

    +        p = kfd_lookup_process_by_mm(mm);

p->mm is null, not p  because driver set p->mm to null. But still prange->queue_refcount is ref of queues from this prange. If app unmap this prange app should have destroyed the queues associated with this prange already. If not, it is not driver issue. I think driver should send this warning anyway to indicate there are queues not destroyed by app before app unmap the prange. It is an app race condition, not driver.

Regards

Xiaogang

    +

    +        if (p && atomic_read(&prange->queue_refcount)) {

                     int r;

      

                     pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",

    @@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,

                             pr_debug("failed %d to quiesce KFD queues\n", r);

              }

      

    -        p = kfd_lookup_process_by_mm(mm);

              if (!p)

                     return;

              svms = &p->svms;
#5 lore raw

[Public]

Why print something under conditions where it’s not needed then?
Could this not be a pr_debug instead?
The number of queues could be quite large.
I don’t see the merit in potentially spamming dmesgs if driver is going to clean up anyways.

Jon

From: Chen, Xiaogang <[email protected]>
Sent: Monday, October 20, 2025 1:34 PM
To: Kim, Jonathan <[email protected]>; Yang, Philip <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>
Subject: Re: [PATCH v3 1/2] drm/amdkfd: Fix false positive queue buffer free warning

On 10/20/2025 11:24 AM, Kim, Jonathan wrote:

[Public]

You can see this error message on CTRL-C or gpu reset conditions.
Those don’t seem like application race conditions to me i.e. the app can’t do anything about terminations it can’t see coming. It appears any bad actor could spam dmesgs with these error messages if they wanted to with the way the driver currently is.

If this warning message comes out due to some unexpected things happened(like ctrl-c) I think user would not be surprised to see some warnings.

Regards

Xiaogang

Jon

From: amd-gfx <[email protected]><mailto:[email protected]> On Behalf Of Chen, Xiaogang
Sent: Monday, October 20, 2025 12:00 PM
To: Yang, Philip <[email protected]><mailto:[email protected]>; [email protected]<mailto:[email protected]>
Cc: Kuehling, Felix <[email protected]><mailto:[email protected]>
Subject: Re: [PATCH v3 1/2] drm/amdkfd: Fix false positive queue buffer free warning

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

On 10/20/2025 9:30 AM, Philip Yang wrote:

Only show warning message if process mm is still alive when queue

buffer is freed.

If kfd_lookup_process_by_mm return NULL, means the process is already

exited and mm is gone, it is fine to free queue buffer.

Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")

---

 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0

index 4d4a47313f5b..d1b2f8525f80 100644

--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,

         bool unmap_parent;

         uint32_t i;

- if (atomic_read(&prange->queue_refcount)) {

+ p = kfd_lookup_process_by_mm(mm);

p->mm is null, not p because driver set p->mm to null. But still prange->queue_refcount is ref of queues from this prange. If app unmap this prange app should have destroyed the queues associated with this prange already. If not, it is not driver issue. I think driver should send this warning anyway to indicate there are queues not destroyed by app before app unmap the prange. It is an app race condition, not driver.

Regards

Xiaogang

+

+ if (p && atomic_read(&prange->queue_refcount)) {

                int r;



                pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",

@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,

                        pr_debug("failed %d to quiesce KFD queues\n", r);

         }

- p = kfd_lookup_process_by_mm(mm);

         if (!p)

                return;

         svms = &p->svms;
#6 lore raw
Quoted 4 lines · Jonathan

[Public]

Quoted 8 lines

Why print something under conditions where it’s not needed then?

Could this not be a pr_debug instead?

The number of queues could be quite large.

I don’t see the merit in potentially spamming dmesgs if driver is going to clean up anyways.

I think the issue here is not about print this warning or not. The issue is queues associate with prange should have been destroyed before prange got unmapped.

Regards

Xiaogang

Quoted 132 lines

Jon

*From:*Chen, Xiaogang <[email protected]>
*Sent:* Monday, October 20, 2025 1:34 PM
*To:* Kim, Jonathan <[email protected]>; Yang, Philip <[email protected]>; [email protected] *Cc:* Kuehling, Felix <[email protected]>
*Subject:* Re: [PATCH v3 1/2] drm/amdkfd: Fix false positive queue buffer free warning

On 10/20/2025 11:24 AM, Kim, Jonathan wrote:

[Public]

You can see this error message on CTRL-C or gpu reset conditions.

Those don’t seem like application race conditions to me i.e. the app can’t do anything about terminations it can’t see coming.

It appears any bad actor could spam dmesgs with these error messages if they wanted to with the way the driver currently is.

If this warning message comes out due to some unexpected things happened(like ctrl-c) I think user would not be surprised to see some warnings.

Regards

Xiaogang

    Jon

    *From:*amd-gfx <[email protected]>
    <mailto:[email protected]> *On Behalf Of
    *Chen, Xiaogang
    *Sent:* Monday, October 20, 2025 12:00 PM
    *To:* Yang, Philip <[email protected]>
    <mailto:[email protected]>; [email protected]
    *Cc:* Kuehling, Felix <[email protected]>
    <mailto:[email protected]>
    *Subject:* Re: [PATCH v3 1/2] drm/amdkfd: Fix false positive queue
    buffer free warning


    	

    *Caution:*This message originated from an External Source. Use
    proper caution when opening attachments, clicking links, or
    responding.

    On 10/20/2025 9:30 AM, Philip Yang wrote:

        Only show warning message if process mm is still alive when queue

        buffer is freed.

          

        If kfd_lookup_process_by_mm return NULL, means the process is already

        exited and mm is gone, it is fine to free queue buffer.

          

        Fixes: b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")

        Signed-off-by: Philip Yang<[email protected]> <mailto:[email protected]>

        ---

          drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--

          1 file changed, 3 insertions(+), 2 deletions(-)

          

        diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

        index 4d4a47313f5b..d1b2f8525f80 100644

        --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

        +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c

        @@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,

                  bool unmap_parent;

                  uint32_t i;

          

        -        if (atomic_read(&prange->queue_refcount)) {

        +        p = kfd_lookup_process_by_mm(mm);

    p->mm is null, not p  because driver set p->mm to null. But
    still prange->queue_refcount is ref of queues from this prange. If
    app unmap this prange app should have destroyed the queues
    associated with this prange already. If not, it is not driver
    issue. I think driver should send this warning anyway to indicate
    there are queues not destroyed by app before app unmap the prange.
    It is an app race condition, not driver.

    Regards

    Xiaogang

          

        +

        +        if (p && atomic_read(&prange->queue_refcount)) {

                         int r;

          

                         pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",

        @@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,

                                 pr_debug("failed %d to quiesce KFD queues\n", r);

                  }

          

        -        p = kfd_lookup_process_by_mm(mm);

                  if (!p)

                         return;

                  svms = &p->svms;
#9 lore raw
In reply to Chen, Xiaogang
Quoted 33 lines · Xiaogang
Quoted 30 lines · Philip Yang
Quoted 28 lines · Xiaogang
Quoted 17 lines · Philip Yang

Only show warning message if process mm is still alive when queue buffer is freed.

If kfd_lookup_process_by_mm return NULL, means the process is already exited and mm is gone, it is fine to free queue buffer.

Fixes b049504e211e ("drm/amdkfd: Validate user queue svm memory residency")

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 4d4a47313f5b..d1b2f8525f80 100644

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_cpu(struct mm_struct · line 2491

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -0
@@ -2487,7 +2487,9 @@ svm_range_unmap_from_cpu(struct mm_struct 
 *mm, struct svm_range *prange,
       bool unmap_parent;
       uint32_t i;
   -    if (atomic_read(&prange->queue_refcount)) {
+    p = kfd_lookup_process_by_mm(mm);

p->mm is null, not p  because driver set p->mm to null. But still prange->queue_refcount is ref of queues from this prange. If app unmap this prange app should have destroyed the queues associated with this prange already. If not, it is not driver issue.

Quoted 8 lines
Quoted 5 lines

right, we still pr_warn if app unmap the prange with queue_refcount not zero, p is not NULL for this case.

Quoted 3 lines

I think driver should send this warning anyway to indicate there are queues not destroyed by app before app unmap the prange.

if app killed or segmentation fault, mm is gone first, then queue is destroyed in scheduled release wq, then exit_mmap unmap the prange with queue_refcount not zero, p is NULL, should not pr_warn, because warning message "Freeing queue vital buffer...." is not related to app segmentation fault or killed.

Then can we put pqm_uninit at kfd_process_notifier_release_internal as you did at second patch with kfd_process_dequeue_from_all_devices: destroy queue when mm is gone?

This is good idea,I didn't try because it seems not safe to destroy user queues inside mmu release notifier callback, which free and clean queue resource, BOs.

After testing on HWS, MES, with SDMA updating page table, no circular locking warning (have to fix one circular locking warning to be sure), and the warning message "Freeing queue vital buffer..." is gone too. I will send out v4 patch.

Regards,

Philip

Quoted 32 lines

And if this is for the cases "app got killed or segment fault" how important user should not see this warning message? Something was wrong already anyway.

My thought is that prange->queue_refcount means queue number associated with prange. If it got unmap the queues should be destroyed already, if not, something was wrong somewhere, then need send this warning message.

Regards

Xiaogang

Quoted 23 lines

Regards,

Philip

Quoted 18 lines

It is an app race condition, not driver.

Regards

Xiaogang

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
+
+    if (p && atomic_read(&prange->queue_refcount)) {
           int r;
             pr_warn("Freeing queue vital buffer 0x%lx, queue evicted\n",
@@ -2497,7 +2499,6 @@ svm_range_unmap_from_cpu(struct mm_struct 
 *mm, struct svm_range *prange,
               pr_debug("failed %d to quiesce KFD queues\n", r);
       }
   -    p = kfd_lookup_process_by_mm(mm);
       if (!p)
           return;

      svms = &p->svms;