From: Maarten@mblankhorst.nl, "Lankhorst <maarten.lankhorst"@linux.intel.com
To: intel-xe@lists.freedesktop.org
Cc: Maarten Lankhorst <dev@lankhorst.se>
Subject: [Intel-xe] [PATCH 3/4] drm/xe: Add vm snapshot mutex for easily taking a vm snapshot during devcoredump
Date: Tue, 24 Oct 2023 14:22:55 +0200 [thread overview]
Message-ID: <20231024122256.19512-4-dev@lankhorst.se> (raw)
In-Reply-To: <20231024122256.19512-1-dev@lankhorst.se>
From: Maarten Lankhorst <dev@lankhorst.se>
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 <dev@lankhorst.se>
---
drivers/gpu/drm/xe/xe_vm.c | 7 +++++++
drivers/gpu/drm/xe/xe_vm_types.h | 5 +++++
2 files changed, 12 insertions(+)
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index e17af7aa1ca1..b42ca1069c5b 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -1168,7 +1168,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;
@@ -1179,7 +1181,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;
}
@@ -1352,6 +1356,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);
@@ -1489,6 +1494,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
dma_resv_unlock(&vm->resv);
drm_gpuvm_destroy(&vm->gpuvm);
err_put:
+ mutex_destroy(&vm->snap_mutex);
dma_resv_fini(&vm->resv);
for_each_tile(tile, xe, id)
xe_range_fence_tree_fini(&vm->rftree[id]);
@@ -1594,6 +1600,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
up_write(&vm->lock);
drm_gpuvm_destroy(&vm->gpuvm);
+ mutex_destroy(&vm->snap_mutex);
mutex_lock(&xe->usm.lock);
if (vm->flags & XE_VM_FLAG_FAULT_MODE)
diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_types.h
index 6852af366ea2..da42b1ee7aaa 100644
--- a/drivers/gpu/drm/xe/xe_vm_types.h
+++ b/drivers/gpu/drm/xe/xe_vm_types.h
@@ -182,6 +182,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, and if they are
--
2.40.1
next prev parent reply other threads:[~2023-10-24 12:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-24 12:22 [Intel-xe] [PATCH 0/4] drm/xe: Implement snapshot support Maarten, Lankhorst <maarten.lankhorst
2023-10-24 12:22 ` [Intel-xe] [PATCH 1/4] drm/xe: Add uapi for dumpable bos Maarten, Lankhorst <maarten.lankhorst
2023-11-13 21:41 ` Souza, Jose
2023-10-24 12:22 ` [Intel-xe] [PATCH 2/4] drm/xe: Annotate each dumpable vma as such Maarten, Lankhorst <maarten.lankhorst
2023-10-24 12:22 ` Maarten, Lankhorst <maarten.lankhorst [this message]
2023-10-24 12:22 ` [Intel-xe] [PATCH 4/4] drm/xe: Implement VM snapshot support Maarten, Lankhorst <maarten.lankhorst
2023-10-27 12:17 ` Thomas Hellström
2023-10-27 17:47 ` Maarten Lankhorst
2023-11-13 21:52 ` Souza, Jose
2024-01-22 18:03 ` Souza, Jose
2023-10-24 13:07 ` [Intel-xe] ✓ CI.Patch_applied: success for drm/xe: Implement " Patchwork
2023-10-24 13:07 ` [Intel-xe] ✗ CI.checkpatch: warning " Patchwork
2023-10-24 13:09 ` [Intel-xe] ✓ CI.KUnit: success " Patchwork
2023-10-24 13:16 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-10-24 13:16 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-10-24 13:18 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-10-24 13:52 ` [Intel-xe] ✓ CI.BAT: " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2023-10-13 15:21 [Intel-xe] [PATCH 0/4] RFC for discussion of devcoredump uapi maarten.lankhorst
2023-10-13 15:21 ` [Intel-xe] [PATCH 3/4] drm/xe: Add vm snapshot mutex for easily taking a vm snapshot during devcoredump maarten.lankhorst
2023-10-13 19:21 ` Matthew Brost
2023-10-17 10:15 ` Maarten Lankhorst
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=20231024122256.19512-4-dev@lankhorst.se \
--to=maarten@mblankhorst.nl \
--cc="Lankhorst <maarten.lankhorst"@linux.intel.com \
--cc=dev@lankhorst.se \
--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