Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Oak Zeng <oak.zeng@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: thomas.hellstrom@intel.com, matthew.brost@intel.com,
	brian.welty@intel.com, himal.prasad.ghimiray@intel.com,
	lucas.demarchi@intel.com
Subject: [PATCH 4/4] drm/xe: destroy userptr vma on UNMAP event
Date: Wed, 20 Mar 2024 22:29:39 -0400	[thread overview]
Message-ID: <20240321022939.2279979-5-oak.zeng@intel.com> (raw)
In-Reply-To: <20240321022939.2279979-1-oak.zeng@intel.com>

When there is MMU_NOTIFY_UNMAP event happens, the userptr
is munmapped from CPU. There is no need to keep the xe_vma
for this userptr from GPU side. So we destroy it.

But we can't destroy vma directly from the mmu notifier
callback function, because we need to remove mmu
notifier during vma destroy. If we remove mmu notifier
directly from mmu notifier callback, it is a deadlock.
xe_vma_destroy is modified to destroy vma in a worker
thread.

Another reason of this change is, for the future
hmmptr codes, we destroy vma when hmmptr is unmapped
from CPU. We want to unify the hmmptr and userptr
code.

I believe this is also the correct behavior for userptr.
This patch is experimental for CI and open to discuss

Signed-off-by: Oak Zeng <oak.zeng@intel.com>
---
 drivers/gpu/drm/xe/xe_vm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 11a4bb9d5415..90d1163c1090 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -40,6 +40,8 @@
 #include "xe_wa.h"
 #include "xe_hmm.h"
 
+static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence);
+
 static struct drm_gem_object *xe_vm_obj(struct xe_vm *vm)
 {
 	return vm->gpuvm.r_obj;
@@ -604,6 +606,9 @@ static bool vma_userptr_invalidate(struct mmu_interval_notifier *mni,
 
 	trace_xe_vma_userptr_invalidate_complete(vma);
 
+	if (range->event == MMU_NOTIFY_UNMAP)
+		xe_vma_destroy(vma, NULL);
+
 	return true;
 }
 
@@ -901,7 +906,8 @@ static void xe_vma_destroy(struct xe_vma *vma, struct dma_fence *fence)
 			xe_vma_destroy_late(vma);
 		}
 	} else {
-		xe_vma_destroy_late(vma);
+		INIT_WORK(&vma->destroy_work, vma_destroy_work_func);
+		queue_work(system_unbound_wq, &vma->destroy_work);
 	}
 }
 
-- 
2.26.3


  parent reply	other threads:[~2024-03-21  2:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21  2:29 [PATCH 0/4] Change userptr so it can be unified with hmmptr Oak Zeng
2024-03-21  2:27 ` ✓ CI.Patch_applied: success for " Patchwork
2024-03-21  2:27 ` ✗ CI.checkpatch: warning " Patchwork
2024-03-21  2:28 ` ✓ CI.KUnit: success " Patchwork
2024-03-21  2:29 ` [PATCH 1/4] drm/xe: Introduce helper to populate userptr Oak Zeng
2024-03-21  2:29 ` [PATCH 2/4] drm/xe: Introduce a helper to free sg table Oak Zeng
2024-03-21  2:29 ` [PATCH 3/4] drm/xe: Use hmm_range_fault to populate user pages Oak Zeng
2024-03-21  2:29 ` Oak Zeng [this message]
2024-03-21  3:21   ` [PATCH 4/4] drm/xe: destroy userptr vma on UNMAP event Matthew Brost
2024-03-21 14:56     ` Zeng, Oak
2024-03-21 17:01       ` Matthew Brost
2024-03-21 20:00         ` Zeng, Oak
2024-03-21 14:30   ` Hellstrom, Thomas
2024-03-21 17:31     ` Zeng, Oak
2024-03-21  2:39 ` ✓ CI.Build: success for Change userptr so it can be unified with hmmptr Patchwork
2024-03-21  2:43 ` ✓ CI.Hooks: " Patchwork
2024-03-21  2:44 ` ✓ CI.checksparse: " Patchwork
2024-03-21  3:12 ` ✗ CI.BAT: failure " Patchwork

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=20240321022939.2279979-5-oak.zeng@intel.com \
    --to=oak.zeng@intel.com \
    --cc=brian.welty@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=thomas.hellstrom@intel.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