From: Matthew Brost <matthew.brost@intel.com>
To: Matthew Auld <matthew.auld@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH] drm/xe: Convert to USM lock to rwsem
Date: Wed, 18 Sep 2024 15:24:03 +0000 [thread overview]
Message-ID: <ZurwkyNtFvcbIJ5F@DUT025-TGLU.fm.intel.com> (raw)
In-Reply-To: <148ac588-d4bd-4a86-849b-5e28b530b3b7@intel.com>
On Wed, Sep 18, 2024 at 08:56:26AM +0100, Matthew Auld wrote:
> On 18/09/2024 06:44, Matthew Brost wrote:
> > Remove contention from GPU fault path for ASID->VM lookup.
> >
> > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > ---
> > drivers/gpu/drm/xe/xe_device.c | 4 +---
> > drivers/gpu/drm/xe/xe_device_types.h | 2 +-
> > drivers/gpu/drm/xe/xe_gt_pagefault.c | 8 ++++----
> > drivers/gpu/drm/xe/xe_vm.c | 8 ++++----
> > 4 files changed, 10 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> > index 4d3c794f134c..38eade07a004 100644
> > --- a/drivers/gpu/drm/xe/xe_device.c
> > +++ b/drivers/gpu/drm/xe/xe_device.c
> > @@ -335,9 +335,7 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
> > init_waitqueue_head(&xe->ufence_wq);
> > - err = drmm_mutex_init(&xe->drm, &xe->usm.lock);
> > - if (err)
> > - goto err;
> > + init_rwsem(&xe->usm.lock);
> > xa_init_flags(&xe->usm.asid_to_vm, XA_FLAGS_ALLOC);
> > diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
> > index c92df0a2423f..4507a5756a05 100644
> > --- a/drivers/gpu/drm/xe/xe_device_types.h
> > +++ b/drivers/gpu/drm/xe/xe_device_types.h
> > @@ -395,7 +395,7 @@ struct xe_device {
> > /** @usm.next_asid: next ASID, used to cyclical alloc asids */
> > u32 next_asid;
> > /** @usm.lock: protects UM state */
> > - struct mutex lock;
> > + struct rw_semaphore lock;
> > } usm;
> > /** @pinned: pinned BO state */
> > diff --git a/drivers/gpu/drm/xe/xe_gt_pagefault.c b/drivers/gpu/drm/xe/xe_gt_pagefault.c
> > index 00af059a8971..5c3af2bb5402 100644
> > --- a/drivers/gpu/drm/xe/xe_gt_pagefault.c
> > +++ b/drivers/gpu/drm/xe/xe_gt_pagefault.c
> > @@ -198,13 +198,13 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)
> > return -EFAULT;
> > /* ASID to VM */
> > - mutex_lock(&xe->usm.lock);
> > + down_read(&xe->usm.lock);
> > vm = xa_load(&xe->usm.asid_to_vm, pf->asid);
> > if (vm && xe_vm_in_fault_mode(vm))
> > xe_vm_get(vm);
> > else
> > vm = NULL;
> > - mutex_unlock(&xe->usm.lock);
> > + up_read(&xe->usm.lock);
> > if (!vm)
> > return -EINVAL;
> > @@ -549,11 +549,11 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)
> > return -EINVAL;
> > /* ASID to VM */
> > - mutex_lock(&xe->usm.lock);
> > + down_read(&xe->usm.lock);
> > vm = xa_load(&xe->usm.asid_to_vm, acc->asid);
> > if (vm)
> > xe_vm_get(vm);
> > - mutex_unlock(&xe->usm.lock);
> > + up_read(&xe->usm.lock);
> > if (!vm || !xe_vm_in_fault_mode(vm))
> > return -EINVAL;
>
> Looks like we potentially leak the vm here. Could maybe make this the same
Yep, noticed that too. Was going to do in follow up today.
Matt
> as above? Maybe even a small helper.
>
> Anyway,
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>
>
> > diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> > index 7acd5fc9d032..a3d7cb7cfd22 100644
> > --- a/drivers/gpu/drm/xe/xe_vm.c
> > +++ b/drivers/gpu/drm/xe/xe_vm.c
> > @@ -1613,7 +1613,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
> > up_write(&vm->lock);
> > - mutex_lock(&xe->usm.lock);
> > + down_write(&xe->usm.lock);
> > if (vm->usm.asid) {
> > void *lookup;
> > @@ -1623,7 +1623,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)
> > lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid);
> > xe_assert(xe, lookup == vm);
> > }
> > - mutex_unlock(&xe->usm.lock);
> > + up_write(&xe->usm.lock);
> > for_each_tile(tile, xe, id)
> > xe_range_fence_tree_fini(&vm->rftree[id]);
> > @@ -1772,11 +1772,11 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
> > goto err_close_and_put;
> > if (xe->info.has_asid) {
> > - mutex_lock(&xe->usm.lock);
> > + down_write(&xe->usm.lock);
> > err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
> > XA_LIMIT(1, XE_MAX_ASID - 1),
> > &xe->usm.next_asid, GFP_KERNEL);
> > - mutex_unlock(&xe->usm.lock);
> > + up_write(&xe->usm.lock);
> > if (err < 0)
> > goto err_free_id;
next prev parent reply other threads:[~2024-09-18 15:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-18 5:44 [PATCH] drm/xe: Convert to USM lock to rwsem Matthew Brost
2024-09-18 7:02 ` ✓ CI.Patch_applied: success for " Patchwork
2024-09-18 7:02 ` ✓ CI.checkpatch: " Patchwork
2024-09-18 7:03 ` ✓ CI.KUnit: " Patchwork
2024-09-18 7:15 ` ✓ CI.Build: " Patchwork
2024-09-18 7:32 ` ✓ CI.Hooks: " Patchwork
2024-09-18 7:33 ` ✓ CI.checksparse: " Patchwork
2024-09-18 7:56 ` [PATCH] " Matthew Auld
2024-09-18 15:24 ` Matthew Brost [this message]
2024-09-18 8:05 ` Ghimiray, Himal Prasad
2024-09-18 8:27 ` ✗ CI.BAT: failure for " Patchwork
2024-09-18 10:20 ` ✗ CI.FULL: " 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=ZurwkyNtFvcbIJ5F@DUT025-TGLU.fm.intel.com \
--to=matthew.brost@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.auld@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