Skip to contentSkip to conversation

Remove process exit error message

PATCH In review Philip Yang 4 participants 13 messages May 14, 2025 – May 21, 2025

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

cover Remove process exit error message

This series fix the dmesg error message "still active bo inside vm" and 2 potential races when process exit and vm cleanup.

Philip Yang (3):
drm/amdgpu: seq64 memory unmap uses uninterruptible lock drm/amdgpu: amdgpu_vm_fini hold vm lock to access vm->va drm/amdkfd: destroy_pdds release pdd->drm_file at end

 drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c    |  8 ++++----
 drivers/gpu/drm/amd/amdkfd/kfd_process.c  | 10 +++++++---
 3 files changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/3 drm/amdgpu: seq64 memory unmap uses uninterruptible lock

To unmap and free seq64 memory when drm node close to free vm, if there is signal accepted, then taking vm lock failed and leaking seq64 va mapping, and then dmesg has error log "still active bo inside vm".

Change to use uninterruptible lock fix the mapping leaking and no dmesg error log.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c +1 -1
index 3939761be31c..d45ebfb642ca 100644
@@ -139,7 +139,7 @@ void amdgpu_seq64_unmap(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv)
 
 	vm = &fpriv->vm;
 
-	drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);
+	drm_exec_init(&exec, 0, 0);
 	drm_exec_until_all_locked(&exec) {
 		r = amdgpu_vm_lock_pd(vm, &exec, 0);
 		if (likely(!r))
Signature · 1 line
2.49.0
maintainer
#2 lore raw

Re: [PATCH 1/3] drm/amdgpu: seq64 memory unmap uses uninterruptible lock

Quoted 8 lines · Philip Yang

To unmap and free seq64 memory when drm node close to free vm, if there is signal accepted, then taking vm lock failed and leaking seq64 va mapping, and then dmesg has error log "still active bo inside vm".

Change to use uninterruptible lock fix the mapping leaking and no dmesg error log.

I'm not 100% sure but I think I've seen the same patch from Arun before. So don't be surprised if that is already fixed on amd-stangin-drm-next.

Anyway feel free to add Reviewed-by: Christian König <[email protected]> and push to amd-staging-drm-next since that change is certainly correct.

Regards,
Christian.

Quoted 17 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c +1 -1
index 3939761be31c..d45ebfb642ca 100644
@@ -139,7 +139,7 @@ void amdgpu_seq64_unmap(struct amdgpu_device *adev, struct amdgpu_fpriv *fpriv)
 
 	vm = &fpriv->vm;
 
-	drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);
+	drm_exec_init(&exec, 0, 0);
 	drm_exec_until_all_locked(&exec) {
 		r = amdgpu_vm_lock_pd(vm, &exec, 0);
 		if (likely(!r))
#3 lore raw

PATCH 2/3 drm/amdgpu: amdgpu_vm_fini hold vm lock to access vm->va

In reply to Philip Yang

Move vm root bo unreserve after vm->va mapping free because we should hold vm lock to access vm->va.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -4
index 3911c78f8282..fb5baa6ec32d 100644
@@ -2740,10 +2740,6 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 	}
 
 	amdgpu_vm_pt_free_root(adev, vm);
-	amdgpu_bo_unreserve(root);
-	amdgpu_bo_unref(&root);
-	WARN_ON(vm->root.bo);
-
 	amdgpu_vm_fini_entities(vm);
 
 	if (!RB_EMPTY_ROOT(&vm->va.rb_root)) {
@@ -2758,6 +2754,10 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 		kfree(mapping);
 	}
 
+	amdgpu_bo_unreserve(root);
+	amdgpu_bo_unref(&root);
+	WARN_ON(vm->root.bo);
+
 	dma_fence_put(vm->last_update);
 
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
Signature · 1 line
2.49.0
maintainer
#4 lore raw

Re: [PATCH 2/3] drm/amdgpu: amdgpu_vm_fini hold vm lock to access vm->va

Quoted 2 lines · Philip Yang

Move vm root bo unreserve after vm->va mapping free because we should hold vm lock to access vm->va.

That should be unnecessary since we are about to destroy the VM.

If anybody is concurrently using it at that point we are completely busted anyway.

Regards,
Christian.

Quoted 32 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -4
index 3911c78f8282..fb5baa6ec32d 100644
@@ -2740,10 +2740,6 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 	}
 
 	amdgpu_vm_pt_free_root(adev, vm);
-	amdgpu_bo_unreserve(root);
-	amdgpu_bo_unref(&root);
-	WARN_ON(vm->root.bo);
-
 	amdgpu_vm_fini_entities(vm);
 
 	if (!RB_EMPTY_ROOT(&vm->va.rb_root)) {
@@ -2758,6 +2754,10 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 		kfree(mapping);
 	}
 
+	amdgpu_bo_unreserve(root);
+	amdgpu_bo_unref(&root);
+	WARN_ON(vm->root.bo);
+
 	dma_fence_put(vm->last_update);
 
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
#5 lore raw

Re: [PATCH 2/3] drm/amdgpu: amdgpu_vm_fini hold vm lock to access vm->va

In reply to Philip Yang
Quoted 24 lines · Philip Yang

Move vm root bo unreserve after vm->va mapping free because we should hold vm lock to access vm->va.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -4
index 3911c78f8282..fb5baa6ec32d 100644
@@ -2740,10 +2740,6 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
  	}
 
  	amdgpu_vm_pt_free_root(adev, vm);
-	amdgpu_bo_unreserve(root);
-	amdgpu_bo_unref(&root);
-	WARN_ON(vm->root.bo);
-
  	amdgpu_vm_fini_entities(vm);
 
  	if (!RB_EMPTY_ROOT(&vm->va.rb_root)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 2760

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
@@ -2758,6 +2754,10 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
  		kfree(mapping);
  	}
 
+	amdgpu_bo_unreserve(root);
+	amdgpu_bo_unref(&root);
+	WARN_ON(vm->root.bo);
+

if the places of unresrved/unref vm root here do matter putting them at end of this function may look more reasonable.

Regards

Xiaogang

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
  	dma_fence_put(vm->last_update);
 
  	for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
#6 lore raw

Re: [PATCH 2/3] drm/amdgpu: amdgpu_vm_fini hold vm lock to access vm->va

Quoted 26 lines · Xiaogang
Quoted 24 lines · Philip Yang

Move vm root bo unreserve after vm->va mapping free because we should hold vm lock to access vm->va.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++----

  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -4
index 3911c78f8282..fb5baa6ec32d 100644
@@ -2740,10 +2740,6 @@ void amdgpu_vm_fini(struct amdgpu_device 
 *adev, struct amdgpu_vm *vm)
       }
         amdgpu_vm_pt_free_root(adev, vm);
-    amdgpu_bo_unreserve(root);
-    amdgpu_bo_unref(&root);
-    WARN_ON(vm->root.bo);
-
       amdgpu_vm_fini_entities(vm);
         if (!RB_EMPTY_ROOT(&vm->va.rb_root)) {
@@ -2758,6 +2754,10 @@ void amdgpu_vm_fini(struct amdgpu_device 
 *adev, struct amdgpu_vm *vm)
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 2760

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -0
           kfree(mapping);
       }
   +    amdgpu_bo_unreserve(root);
+    amdgpu_bo_unref(&root);
+    WARN_ON(vm->root.bo);
+

if the places of unresrved/unref vm root here do matter putting them at end of this function may look more reasonable.

No, this change doesn't fix any issue, as Christian stated, we should not have concurrent using of vm inside this function, hold root bo lock is only required by assert in amdgpu_vm_pt_free_root. I will drop this patch.

Regards,

Philip

Quoted 8 lines

Regards

Xiaogang

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
       dma_fence_put(vm->last_update);
         for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
#7 lore raw

PATCH 3/3 drm/amdkfd: destroy_pdds release pdd->drm_file at end

In reply to Philip Yang

Release pdd->drm_file may free the vm if this is the last reference, move it to the last step after memory is unmapped.

---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +7 -3
index e868cc8da46f..b009c852180d 100644
@@ -1063,9 +1063,6 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
 		kfd_process_device_destroy_cwsr_dgpu(pdd);
 		kfd_process_device_destroy_ib_mem(pdd);
 
-		if (pdd->drm_file)
-			fput(pdd->drm_file);
-
 		if (pdd->qpd.cwsr_kaddr && !pdd->qpd.cwsr_base)
 			free_pages((unsigned long)pdd->qpd.cwsr_kaddr,
 				get_order(KFD_CWSR_TBA_TMA_SIZE));
@@ -1088,6 +1085,13 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
 			pdd->runtime_inuse = false;
 		}
 
+		/*
+		 * This may release the vm if application already close the drm node,
+		 * do it as last step after memory unmapped.
+		 */
+		if (pdd->drm_file)
+			fput(pdd->drm_file);
+
 		kfree(pdd);
 		p->pdds[i] = NULL;
 	}
Signature · 1 line
2.49.0
#8 lore raw

Re: [PATCH 3/3] drm/amdkfd: destroy_pdds release pdd->drm_file at end

Does this patch fix a bug or just make code look more reasonable? kfd_process_destroy_pdds releases pdd related buffers, not related to operations on vm. So vm tear down dose not affect this function.

Regards

Xiaogang

Quoted 36 lines · Philip Yang

Release pdd->drm_file may free the vm if this is the last reference, move it to the last step after memory is unmapped.

---
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +7 -3
index e868cc8da46f..b009c852180d 100644
@@ -1063,9 +1063,6 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
  		kfd_process_device_destroy_cwsr_dgpu(pdd);
  		kfd_process_device_destroy_ib_mem(pdd);
 
-		if (pdd->drm_file)
-			fput(pdd->drm_file);
-
  		if (pdd->qpd.cwsr_kaddr && !pdd->qpd.cwsr_base)
  			free_pages((unsigned long)pdd->qpd.cwsr_kaddr,
  				get_order(KFD_CWSR_TBA_TMA_SIZE));
@@ -1088,6 +1085,13 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
  			pdd->runtime_inuse = false;
  		}
 
+		/*
+		 * This may release the vm if application already close the drm node,
+		 * do it as last step after memory unmapped.
+		 */
+		if (pdd->drm_file)
+			fput(pdd->drm_file);
+
  		kfree(pdd);
  		p->pdds[i] = NULL;
  	}
#9 lore raw

Re: [PATCH 3/3] drm/amdkfd: destroy_pdds release pdd->drm_file at end

Quoted 3 lines · Xiaogang

Does this patch fix a bug or just make code look more reasonable? kfd_process_destroy_pdds releases pdd related buffers, not related to operations on vm. So vm tear down dose not affect this function.

This change doesn't fix anything currently, as fput(pdd->drm_file) to free vm is right between free vm mapping qpd->cwsr_mem, qpd->ib_mem and free kernel bo qpd->proc_doorbells, pdd->proc_ctx_bo, to make it clear for future change.

Regards,

Philip

Quoted 41 lines

Regards

Xiaogang

Quoted 36 lines · Philip Yang

Release pdd->drm_file may free the vm if this is the last reference, move it to the last step after memory is unmapped.

---
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +7 -3
index e868cc8da46f..b009c852180d 100644
@@ -1063,9 +1063,6 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
  		kfd_process_device_destroy_cwsr_dgpu(pdd);
  		kfd_process_device_destroy_ib_mem(pdd);
 
-		if (pdd->drm_file)
-			fput(pdd->drm_file);
-
  		if (pdd->qpd.cwsr_kaddr && !pdd->qpd.cwsr_base)
  			free_pages((unsigned long)pdd->qpd.cwsr_kaddr,
  				get_order(KFD_CWSR_TBA_TMA_SIZE));
@@ -1088,6 +1085,13 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
  			pdd->runtime_inuse = false;
  		}
 
+		/*
+		 * This may release the vm if application already close the drm node,
+		 * do it as last step after memory unmapped.
+		 */
+		if (pdd->drm_file)
+			fput(pdd->drm_file);
+
  		kfree(pdd);
  		p->pdds[i] = NULL;
  	}
#10 lore raw

Re: [PATCH 3/3] drm/amdkfd: destroy_pdds release pdd->drm_file at end

Quoted 6 lines · Philip Yang
Quoted 3 lines · Xiaogang

Does this patch fix a bug or just make code look more reasonable? kfd_process_destroy_pdds releases pdd related buffers, not related to operations on vm. So vm tear down dose not affect this function.

This change doesn't fix anything currently, as fput(pdd->drm_file) to free vm is right between free vm mapping qpd->cwsr_mem, qpd->ib_mem and free kernel bo qpd->proc_doorbells, pdd->proc_ctx_bo, to make it clear for future change.

Then the current place to do fput(pdd->drm_file) make more sense: unmap vm mapping of qpd->cwsr_mem, qpd->ib_mem is the last place where kfd process release procedure needs vm alive. After that the kfd process release does not need vm alive. It then releases remaining buffers. So release drm_file as soon as we do not need hold it.

Regards

Xiaogang

Quoted 46 lines

Regards,

Philip

Quoted 42 lines

Regards

Xiaogang

Quoted 37 lines · Philip Yang

Release pdd->drm_file may free the vm if this is the last reference, move it to the last step after memory is unmapped.

---
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 +++++++---

  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -2
index e868cc8da46f..b009c852180d 100644
@@ -1063,9 +1063,6 @@ static void kfd_process_destroy_pdds(struct 
 kfd_process *p)
           kfd_process_device_destroy_cwsr_dgpu(pdd);
           kfd_process_device_destroy_ib_mem(pdd);
   -        if (pdd->drm_file)
-            fput(pdd->drm_file);
-
           if (pdd->qpd.cwsr_kaddr && !pdd->qpd.cwsr_base)
               free_pages((unsigned long)pdd->qpd.cwsr_kaddr,

                  get_order(KFD_CWSR_TBA_TMA_SIZE));

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -1088,6 +1085,13 @@ static void kfd_process_destroy_pdds(struct 
 kfd_process *p)
               pdd->runtime_inuse = false;
           }

  +        /*
+         * This may release the vm if application already close the drm node,
+         * do it as last step after memory unmapped.
+         */
+        if (pdd->drm_file)
+            fput(pdd->drm_file);
+
          kfree(pdd);
          p->pdds[i] = NULL;
      }

#11 lore raw

Re: [PATCH 3/3] drm/amdkfd: destroy_pdds release pdd->drm_file at end

Quoted 10 lines · Xiaogang
Quoted 6 lines · Philip Yang
Quoted 3 lines · Xiaogang

Does this patch fix a bug or just make code look more reasonable? kfd_process_destroy_pdds releases pdd related buffers, not related to operations on vm. So vm tear down dose not affect this function.

This change doesn't fix anything currently, as fput(pdd->drm_file) to free vm is right between free vm mapping qpd->cwsr_mem, qpd->ib_mem and free kernel bo qpd->proc_doorbells, pdd->proc_ctx_bo, to make it clear for future change.

Then the current place to do fput(pdd->drm_file) make more sense: unmap vm mapping of qpd->cwsr_mem, qpd->ib_mem is the last place where kfd process release procedure needs vm alive. After that the kfd process release does not need vm alive. It then releases remaining buffers. So release drm_file as soon as we do not need hold it.

The issue was  vm_fini shows error message "still active bo inside vm" (1/1000) chance, took a while to trace down the leaking vm mapping, the issue is seq64 memory mapping leaking and fixed by the first patch. KFD pdd cleanup path, free vm is in the middle of free pdd memory, this is one of the suspicious vm_fini race. We may add new pdd memory mapping to vm in future, to prevent the potential vm_fini race, this patch move free vm to after all pdd memory is freed and add comment.

Regards,

Philip

Quoted 51 lines

Regards

Xiaogang

Quoted 46 lines

Regards,

Philip

Quoted 42 lines

Regards

Xiaogang

Quoted 37 lines · Philip Yang

Release pdd->drm_file may free the vm if this is the last reference, move it to the last step after memory is unmapped.

---
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 +++++++---

  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -2
index e868cc8da46f..b009c852180d 100644
@@ -1063,9 +1063,6 @@ static void kfd_process_destroy_pdds(struct 
 kfd_process *p)
           kfd_process_device_destroy_cwsr_dgpu(pdd);
           kfd_process_device_destroy_ib_mem(pdd);
   -        if (pdd->drm_file)
-            fput(pdd->drm_file);
-
           if (pdd->qpd.cwsr_kaddr && !pdd->qpd.cwsr_base)
               free_pages((unsigned long)pdd->qpd.cwsr_kaddr,

                  get_order(KFD_CWSR_TBA_TMA_SIZE));

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -1088,6 +1085,13 @@ static void kfd_process_destroy_pdds(struct 
 kfd_process *p)
               pdd->runtime_inuse = false;
           }

  +        /*
+         * This may release the vm if application already close the drm node,
+         * do it as last step after memory unmapped. +         */
+        if (pdd->drm_file)
+            fput(pdd->drm_file);
+
          kfree(pdd);
          p->pdds[i] = NULL;
      }

#12 lore raw

Re: [PATCH 3/3] drm/amdkfd: destroy_pdds release pdd->drm_file at end

Quoted 7 lines · Philip Yang
Quoted 5 lines · Xiaogang
Quoted 3 lines · Philip Yang
Quoted 1 line · Xiaogang
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Does this patch fix a bug or just make code look more reasonable? kfd_process_destroy_pdds releases pdd related buffers, not related to operations on vm. So vm tear down dose not affect this function.

This change doesn't fix anything currently, as fput(pdd->drm_file) to free vm is right between free vm mapping qpd->cwsr_mem, qpd->ib_mem and free kernel bo qpd->proc_doorbells, pdd->proc_ctx_bo, to make it clear for future change.

Then the current place to do fput(pdd->drm_file) make more sense: unmap vm mapping of qpd->cwsr_mem, qpd->ib_mem is the last place where kfd process release procedure needs vm alive. After that the kfd process release does not need vm alive. It then releases remaining buffers. So release drm_file as soon as we do not need hold it.

The issue was  vm_fini shows error message "still active bo inside vm" (1/1000) chance, took a while to trace down the leaking vm mapping, the issue is seq64 memory mapping leaking and fixed by the first patch. KFD pdd cleanup path, free vm is in the middle of free pdd memory, this is one of the suspicious vm_fini race. We may add new pdd memory mapping to vm in future, to prevent the potential vm_fini race, this patch move free vm to after all pdd memory is freed and add comment.

I see the reason of [PATCH 1/3]. This patch is delay kfd's pdd drm_file release a bit. kfd should release drm_file as soon as it does not need vm. The issue you saw is there is buffer mapping still alive when driver decides to tear down vm.  Is the mapping from from kfd process? if not, change timing somehow at kfd process release is not right place.

Regards

Xiaogang

Quoted 56 lines

Regards,

Philip

Quoted 51 lines

Regards

Xiaogang

Quoted 46 lines

Regards,

Philip

Quoted 42 lines

Regards

Xiaogang

Quoted 37 lines · Philip Yang

Release pdd->drm_file may free the vm if this is the last reference, move it to the last step after memory is unmapped.

---
  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 10 +++++++---

  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -2
index e868cc8da46f..b009c852180d 100644
@@ -1063,9 +1063,6 @@ static void kfd_process_destroy_pdds(struct 
 kfd_process *p)
           kfd_process_device_destroy_cwsr_dgpu(pdd);
           kfd_process_device_destroy_ib_mem(pdd);
   -        if (pdd->drm_file)
-            fput(pdd->drm_file);
-
           if (pdd->qpd.cwsr_kaddr && !pdd->qpd.cwsr_base)
               free_pages((unsigned long)pdd->qpd.cwsr_kaddr,

                  get_order(KFD_CWSR_TBA_TMA_SIZE));

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -1088,6 +1085,13 @@ static void kfd_process_destroy_pdds(struct 
 kfd_process *p)
               pdd->runtime_inuse = false;
           }

  +        /*
+         * This may release the vm if application already close the drm node,
+         * do it as last step after memory unmapped. +         */
+        if (pdd->drm_file)
+            fput(pdd->drm_file);
+
          kfree(pdd);
          p->pdds[i] = NULL;
      }