From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [PATCH v2] drm/xe: Simplify locking in new_vma
Date: Mon, 17 Jun 2024 17:38:59 -0700 [thread overview]
Message-ID: <20240618003859.3239239-1-matthew.brost@intel.com> (raw)
Rather than acquiring and dropping the VM / BO dma-resv around
xe_vma_create and do the same thing upon adding preempt fences or an
error, hold these locks through the entire new_vma() function.
v2:
- Rebase (CI)
Cc: Fei Yang <fei.yang@intel.com>
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/xe/xe_vm.c | 41 +++++++++++++++++---------------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index 61d4d95a5377..5b166fa03684 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -180,16 +180,14 @@ static int add_preempt_fences(struct xe_vm *vm, struct xe_bo *bo)
struct xe_exec_queue *q;
int err;
+ xe_bo_assert_held(bo);
+
if (!vm->preempt.num_exec_queues)
return 0;
- err = xe_bo_lock(bo, true);
- if (err)
- return err;
-
err = dma_resv_reserve_fences(bo->ttm.base.resv, vm->preempt.num_exec_queues);
if (err)
- goto out_unlock;
+ return err;
list_for_each_entry(q, &vm->preempt.exec_queues, lr.link)
if (q->lr.pfence) {
@@ -198,9 +196,7 @@ static int add_preempt_fences(struct xe_vm *vm, struct xe_bo *bo)
DMA_RESV_USAGE_BOOKKEEP);
}
-out_unlock:
- xe_bo_unlock(bo);
- return err;
+ return 0;
}
static void resume_and_reinstall_preempt_fences(struct xe_vm *vm,
@@ -2140,7 +2136,7 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
struct xe_bo *bo = op->gem.obj ? gem_to_xe_bo(op->gem.obj) : NULL;
struct drm_exec exec;
struct xe_vma *vma;
- int err;
+ int err = 0;
lockdep_assert_held_write(&vm->lock);
@@ -2165,23 +2161,22 @@ static struct xe_vma *new_vma(struct xe_vm *vm, struct drm_gpuva_op_map *op,
vma = xe_vma_create(vm, bo, op->gem.offset,
op->va.addr, op->va.addr +
op->va.range - 1, pat_index, flags);
- if (bo)
- drm_exec_fini(&exec);
+ if (IS_ERR(vma))
+ goto err_unlock;
- if (xe_vma_is_userptr(vma)) {
+ if (xe_vma_is_userptr(vma))
err = xe_vma_userptr_pin_pages(to_userptr_vma(vma));
- if (err) {
- prep_vma_destroy(vm, vma, false);
- xe_vma_destroy_unlocked(vma);
- return ERR_PTR(err);
- }
- } else if (!xe_vma_has_no_bo(vma) && !bo->vm) {
+ else if (!xe_vma_has_no_bo(vma) && !bo->vm)
err = add_preempt_fences(vm, bo);
- if (err) {
- prep_vma_destroy(vm, vma, false);
- xe_vma_destroy_unlocked(vma);
- return ERR_PTR(err);
- }
+
+err_unlock:
+ if (bo)
+ drm_exec_fini(&exec);
+
+ if (err) {
+ prep_vma_destroy(vm, vma, false);
+ xe_vma_destroy_unlocked(vma);
+ vma = ERR_PTR(err);
}
return vma;
--
2.34.1
next reply other threads:[~2024-06-18 0:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 0:38 Matthew Brost [this message]
2024-06-18 0:43 ` ✓ CI.Patch_applied: success for drm/xe: Simplify locking in new_vma (rev2) Patchwork
2024-06-18 0:43 ` ✓ CI.checkpatch: " Patchwork
2024-06-18 0:44 ` ✓ CI.KUnit: " Patchwork
2024-06-18 0:56 ` ✓ CI.Build: " Patchwork
2024-06-18 0:58 ` ✗ CI.Hooks: failure " Patchwork
2024-06-18 0:59 ` ✓ CI.checksparse: success " Patchwork
2024-06-18 1:21 ` ✓ CI.BAT: " Patchwork
2024-06-18 16:46 ` ✗ CI.FULL: failure " Patchwork
2024-06-18 17:59 ` [PATCH v2] drm/xe: Simplify locking in new_vma Randhawa, Jagmeet
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=20240618003859.3239239-1-matthew.brost@intel.com \
--to=matthew.brost@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