From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Subject: [PATCH v3 3/4] drm/xe: Add vm snapshot mutex for easily taking a vm snapshot during devcoredump
Date: Fri, 2 Feb 2024 23:40:51 +0100 [thread overview]
Message-ID: <20240202224052.848867-3-maarten.lankhorst@linux.intel.com> (raw)
In-Reply-To: <20240202224052.848867-1-maarten.lankhorst@linux.intel.com>
The devcoredump is done in fence signaling context. Because of this, we
cannot take any of the normal mutexes or we would invert.
Normal: Take vm->lock, dma_fence_wait()
Devcoredump: from dma_fence_wait() context, take vm->lock.
This doesn't work, and we only care about integrity, so take the locks
around additions and removals of vma's.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
drivers/gpu/drm/xe/xe_vm.c | 8 ++++++++
drivers/gpu/drm/xe/xe_vm_types.h | 5 +++++
2 files changed, 13 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 7ae3918121a43..1f0d58bfd1046 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -1053,7 +1053,9 @@ static int xe_vm_insert_vma(struct xe_vm *vm, struct xe_vma *vma)
xe_assert(vm->xe, xe_vma_vm(vma) == vm);
lockdep_assert_held(&vm->lock);
+ mutex_lock(&vm->snap_mutex);
err = drm_gpuva_insert(&vm->gpuvm, &vma->gpuva);
+ mutex_unlock(&vm->snap_mutex);
XE_WARN_ON(err); /* Shouldn't be possible */
return err;
@@ -1064,7 +1066,9 @@ static void xe_vm_remove_vma(struct xe_vm *vm, struct xe_vma *vma)
xe_assert(vm->xe, xe_vma_vm(vma) == vm);
lockdep_assert_held(&vm->lock);
+ mutex_lock(&vm->snap_mutex);
drm_gpuva_remove(&vma->gpuva);
+ mutex_unlock(&vm->snap_mutex);
if (vm->usm.last_fault_vma == vma)
vm->usm.last_fault_vma = NULL;
}
@@ -1291,6 +1295,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
vm->flags = flags;
init_rwsem(&vm->lock);
+ mutex_init(&vm->snap_mutex);
INIT_LIST_HEAD(&vm->rebind_list);
@@ -1416,6 +1421,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
return ERR_PTR(err);
err_no_resv:
+ mutex_destroy(&vm->snap_mutex);
for_each_tile(tile, xe, id)
xe_range_fence_tree_fini(&vm->rftree[id]);
kfree(vm);
@@ -1515,6 +1521,8 @@ void xe_vm_close_and_put(struct xe_vm *vm)
up_write(&vm->lock);
+ mutex_destroy(&vm->snap_mutex);
+
mutex_lock(&xe->usm.lock);
if (vm->flags & XE_VM_FLAG_FAULT_MODE)
xe->usm.num_vm_in_fault_mode--;
diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_types.h
index f97200282ff07..2079021ba220c 100644
--- a/drivers/gpu/drm/xe/xe_vm_types.h
+++ b/drivers/gpu/drm/xe/xe_vm_types.h
@@ -161,6 +161,11 @@ struct xe_vm {
* VM
*/
struct rw_semaphore lock;
+ /**
+ * @snap_mutex: Mutex used to guard insertions and removals from gpuva,
+ * so we can take a snapshot safely from devcoredump.
+ */
+ struct mutex snap_mutex;
/**
* @rebind_list: list of VMAs that need rebinding. Protected by the
--
2.43.0
next prev parent reply other threads:[~2024-02-02 22:41 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-02 22:40 [PATCH v3 1/4] drm/xe: Add uapi for dumpable bos Maarten Lankhorst
2024-02-02 22:40 ` [PATCH v3 2/4] drm/xe: Annotate each dumpable vma as such Maarten Lankhorst
2024-02-02 22:40 ` Maarten Lankhorst [this message]
2024-02-02 22:40 ` [PATCH v3 4/4] drm/xe: Implement VM snapshot support for BO's and userptr Maarten Lankhorst
2024-02-02 22:45 ` [PATCH v3.1] " Maarten Lankhorst
2024-02-05 16:32 ` Souza, Jose
2024-02-05 20:35 ` Souza, Jose
2024-02-06 20:08 ` Souza, Jose
2024-02-13 14:41 ` Maarten Lankhorst
2024-02-05 16:47 ` Souza, Jose
2024-02-13 14:28 ` Maarten Lankhorst
2024-02-05 20:36 ` [PATCH v3 4/4] " Souza, Jose
2024-02-02 23:55 ` ✓ CI.Patch_applied: success for series starting with [v3,1/4] drm/xe: Add uapi for dumpable bos (rev2) Patchwork
2024-02-02 23:55 ` ✗ CI.checkpatch: warning " Patchwork
2024-02-02 23:56 ` ✓ CI.KUnit: success " Patchwork
2024-02-03 0:03 ` ✓ CI.Build: " Patchwork
2024-02-03 0:03 ` ✓ CI.Hooks: " Patchwork
2024-02-03 0:05 ` ✓ CI.checksparse: " Patchwork
2024-02-03 0:30 ` ✗ CI.BAT: failure " Patchwork
2024-02-05 10:00 ` [PATCH] drm/xe: Add uapi for dumpable bos Maarten Lankhorst
2024-02-05 10:03 ` ✓ CI.Patch_applied: success for series starting with drm/xe: Add uapi for dumpable bos (rev3) Patchwork
2024-02-05 10:04 ` ✗ CI.checkpatch: warning " Patchwork
2024-02-05 10:05 ` ✓ CI.KUnit: success " Patchwork
2024-02-05 10:12 ` ✓ CI.Build: " Patchwork
2024-02-05 10:12 ` ✓ CI.Hooks: " Patchwork
2024-02-05 10:14 ` ✓ CI.checksparse: " Patchwork
2024-02-05 10:37 ` ✓ CI.BAT: " 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=20240202224052.848867-3-maarten.lankhorst@linux.intel.com \
--to=maarten.lankhorst@linux.intel.com \
--cc=intel-xe@lists.freedesktop.org \
/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