From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: [Intel-gfx] [PATCH 1/2] drm/i915: Take the object lock when destroying vmas from vm destruction
Date: Mon, 4 Jul 2022 15:52:48 +0200 [thread overview]
Message-ID: <20220704135249.8241-2-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20220704135249.8241-1-thomas.hellstrom@linux.intel.com>
Currently we guarantee that vmas stay alive when the object lock is held
only if we also hold a private vm reference. In order to relax the latter
requirement, take the object lock also when destroying vmas from the
vm destruction path.
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
drivers/gpu/drm/i915/gt/intel_gtt.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c
index b67831833c9a..92e22f727f88 100644
--- a/drivers/gpu/drm/i915/gt/intel_gtt.c
+++ b/drivers/gpu/drm/i915/gt/intel_gtt.c
@@ -112,7 +112,10 @@ int map_pt_dma_locked(struct i915_address_space *vm, struct drm_i915_gem_object
static void clear_vm_list(struct list_head *list)
{
struct i915_vma *vma, *vn;
+ bool unlocked;
+restart:
+ unlocked = false;
list_for_each_entry_safe(vma, vn, list, vm_link) {
struct drm_i915_gem_object *obj = vma->obj;
@@ -138,8 +141,22 @@ static void clear_vm_list(struct list_head *list)
i915_vm_resv_get(vma->vm);
vma->vm_ddestroy = true;
} else {
+ if (!i915_gem_object_trylock(obj, NULL)) {
+ unlocked = true;
+ mutex_unlock(&vma->vm->mutex);
+ i915_gem_object_lock(obj, NULL);
+ mutex_lock(&vma->vm->mutex);
+ /*
+ * The vma may now be on a different list,
+ * but not destroyed. We don't care.
+ * destroy it.
+ */
+ }
i915_vma_destroy_locked(vma);
+ i915_gem_object_unlock(obj);
i915_gem_object_put(obj);
+ if (unlocked)
+ goto restart;
}
}
--
2.36.1
WARNING: multiple messages have this Message-ID (diff)
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: [PATCH 1/2] drm/i915: Take the object lock when destroying vmas from vm destruction
Date: Mon, 4 Jul 2022 15:52:48 +0200 [thread overview]
Message-ID: <20220704135249.8241-2-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20220704135249.8241-1-thomas.hellstrom@linux.intel.com>
Currently we guarantee that vmas stay alive when the object lock is held
only if we also hold a private vm reference. In order to relax the latter
requirement, take the object lock also when destroying vmas from the
vm destruction path.
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
drivers/gpu/drm/i915/gt/intel_gtt.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c
index b67831833c9a..92e22f727f88 100644
--- a/drivers/gpu/drm/i915/gt/intel_gtt.c
+++ b/drivers/gpu/drm/i915/gt/intel_gtt.c
@@ -112,7 +112,10 @@ int map_pt_dma_locked(struct i915_address_space *vm, struct drm_i915_gem_object
static void clear_vm_list(struct list_head *list)
{
struct i915_vma *vma, *vn;
+ bool unlocked;
+restart:
+ unlocked = false;
list_for_each_entry_safe(vma, vn, list, vm_link) {
struct drm_i915_gem_object *obj = vma->obj;
@@ -138,8 +141,22 @@ static void clear_vm_list(struct list_head *list)
i915_vm_resv_get(vma->vm);
vma->vm_ddestroy = true;
} else {
+ if (!i915_gem_object_trylock(obj, NULL)) {
+ unlocked = true;
+ mutex_unlock(&vma->vm->mutex);
+ i915_gem_object_lock(obj, NULL);
+ mutex_lock(&vma->vm->mutex);
+ /*
+ * The vma may now be on a different list,
+ * but not destroyed. We don't care.
+ * destroy it.
+ */
+ }
i915_vma_destroy_locked(vma);
+ i915_gem_object_unlock(obj);
i915_gem_object_put(obj);
+ if (unlocked)
+ goto restart;
}
}
--
2.36.1
next prev parent reply other threads:[~2022-07-04 16:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-04 13:52 [Intel-gfx] [PATCH 0/2] Protect vma destruction with the object lock Thomas Hellström
2022-07-04 13:52 ` Thomas Hellström
2022-07-04 13:52 ` Thomas Hellström [this message]
2022-07-04 13:52 ` [PATCH 1/2] drm/i915: Take the object lock when destroying vmas from vm destruction Thomas Hellström
2022-07-04 13:52 ` [Intel-gfx] [PATCH 2/2] drm/i915/gem: Rework i915_gem_object_unbind to rely on the object lock Thomas Hellström
2022-07-04 13:52 ` Thomas Hellström
2022-07-04 20:28 ` [Intel-gfx] ✓ Fi.CI.BAT: success for Protect vma destruction with " Patchwork
2022-07-05 1:53 ` [Intel-gfx] ✗ Fi.CI.IGT: 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=20220704135249.8241-2-thomas.hellstrom@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.