All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 07/26] Revert "drm/i915/gem: Split eb_vma into its own allocation"
Date: Tue, 23 Jun 2020 16:28:24 +0200	[thread overview]
Message-ID: <20200623142843.423594-7-maarten.lankhorst@linux.intel.com> (raw)
In-Reply-To: <20200623142843.423594-1-maarten.lankhorst@linux.intel.com>

This reverts commit 0f1dd02295f35dcdcbaafcbcbbec0753884ab974.
This conflicts with the ww mutex handling, which needs to drop
the references after gpu submission anyway, because otherwise we
may risk unlocking a BO after first freeing it.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    | 124 +++++++-----------
 1 file changed, 51 insertions(+), 73 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
index 7cb44915cfc7..2636a130fb57 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
@@ -40,11 +40,6 @@ struct eb_vma {
 	u32 handle;
 };
 
-struct eb_vma_array {
-	struct kref kref;
-	struct eb_vma vma[];
-};
-
 enum {
 	FORCE_CPU_RELOC = 1,
 	FORCE_GTT_RELOC,
@@ -57,6 +52,7 @@ enum {
 #define __EXEC_OBJECT_NEEDS_MAP		BIT(29)
 #define __EXEC_OBJECT_NEEDS_BIAS	BIT(28)
 #define __EXEC_OBJECT_INTERNAL_FLAGS	(~0u << 28) /* all of the above */
+#define __EXEC_OBJECT_RESERVED (__EXEC_OBJECT_HAS_PIN | __EXEC_OBJECT_HAS_FENCE)
 
 #define __EXEC_HAS_RELOC	BIT(31)
 #define __EXEC_INTERNAL_FLAGS	(~0u << 31)
@@ -287,7 +283,6 @@ struct i915_execbuffer {
 	 */
 	int lut_size;
 	struct hlist_head *buckets; /** ht for relocation handles */
-	struct eb_vma_array *array;
 };
 
 static int eb_parse(struct i915_execbuffer *eb);
@@ -299,62 +294,8 @@ static inline bool eb_use_cmdparser(const struct i915_execbuffer *eb)
 		 eb->args->batch_len);
 }
 
-static struct eb_vma_array *eb_vma_array_create(unsigned int count)
-{
-	struct eb_vma_array *arr;
-
-	arr = kvmalloc(struct_size(arr, vma, count), GFP_KERNEL | __GFP_NOWARN);
-	if (!arr)
-		return NULL;
-
-	kref_init(&arr->kref);
-	arr->vma[0].vma = NULL;
-
-	return arr;
-}
-
-static inline void eb_unreserve_vma(struct eb_vma *ev)
-{
-	struct i915_vma *vma = ev->vma;
-
-	if (unlikely(ev->flags & __EXEC_OBJECT_HAS_FENCE))
-		__i915_vma_unpin_fence(vma);
-
-	if (ev->flags & __EXEC_OBJECT_HAS_PIN)
-		__i915_vma_unpin(vma);
-
-	ev->flags &= ~(__EXEC_OBJECT_HAS_PIN |
-		       __EXEC_OBJECT_HAS_FENCE);
-}
-
-static void eb_vma_array_destroy(struct kref *kref)
-{
-	struct eb_vma_array *arr = container_of(kref, typeof(*arr), kref);
-	struct eb_vma *ev = arr->vma;
-
-	while (ev->vma) {
-		eb_unreserve_vma(ev);
-		i915_vma_put(ev->vma);
-		ev++;
-	}
-
-	kvfree(arr);
-}
-
-static void eb_vma_array_put(struct eb_vma_array *arr)
-{
-	kref_put(&arr->kref, eb_vma_array_destroy);
-}
-
 static int eb_create(struct i915_execbuffer *eb)
 {
-	/* Allocate an extra slot for use by the command parser + sentinel */
-	eb->array = eb_vma_array_create(eb->buffer_count + 2);
-	if (!eb->array)
-		return -ENOMEM;
-
-	eb->vma = eb->array->vma;
-
 	if (!(eb->args->flags & I915_EXEC_HANDLE_LUT)) {
 		unsigned int size = 1 + ilog2(eb->buffer_count);
 
@@ -388,10 +329,8 @@ static int eb_create(struct i915_execbuffer *eb)
 				break;
 		} while (--size);
 
-		if (unlikely(!size)) {
-			eb_vma_array_put(eb->array);
+		if (unlikely(!size))
 			return -ENOMEM;
-		}
 
 		eb->lut_size = size;
 	} else {
@@ -502,6 +441,26 @@ eb_pin_vma(struct i915_execbuffer *eb,
 	return !eb_vma_misplaced(entry, vma, ev->flags);
 }
 
+static inline void __eb_unreserve_vma(struct i915_vma *vma, unsigned int flags)
+{
+	GEM_BUG_ON(!(flags & __EXEC_OBJECT_HAS_PIN));
+
+	if (unlikely(flags & __EXEC_OBJECT_HAS_FENCE))
+		__i915_vma_unpin_fence(vma);
+
+	__i915_vma_unpin(vma);
+}
+
+static inline void
+eb_unreserve_vma(struct eb_vma *ev)
+{
+	if (!(ev->flags & __EXEC_OBJECT_HAS_PIN))
+		return;
+
+	__eb_unreserve_vma(ev->vma, ev->flags);
+	ev->flags &= ~__EXEC_OBJECT_RESERVED;
+}
+
 static int
 eb_validate_vma(struct i915_execbuffer *eb,
 		struct drm_i915_gem_exec_object2 *entry,
@@ -944,13 +903,31 @@ eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle)
 	}
 }
 
+static void eb_release_vmas(const struct i915_execbuffer *eb)
+{
+	const unsigned int count = eb->buffer_count;
+	unsigned int i;
+
+	for (i = 0; i < count; i++) {
+		struct eb_vma *ev = &eb->vma[i];
+		struct i915_vma *vma = ev->vma;
+
+		if (!vma)
+			break;
+
+		eb->vma[i].vma = NULL;
+
+		if (ev->flags & __EXEC_OBJECT_HAS_PIN)
+			__eb_unreserve_vma(vma, ev->flags);
+
+		i915_vma_put(vma);
+	}
+}
+
 static void eb_destroy(const struct i915_execbuffer *eb)
 {
 	GEM_BUG_ON(eb->reloc_cache.rq);
 
-	if (eb->array)
-		eb_vma_array_put(eb->array);
-
 	if (eb->lut_size > 0)
 		kfree(eb->buckets);
 }
@@ -2039,12 +2016,9 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb)
 			err = i915_vma_move_to_active(vma, eb->request, flags);
 
 		i915_vma_unlock(vma);
-		eb_unreserve_vma(ev);
 	}
 	ww_acquire_fini(&acquire);
 
-	eb_vma_array_put(fetch_and_zero(&eb->array));
-
 	if (unlikely(err))
 		goto err_skip;
 
@@ -2340,7 +2314,6 @@ static int eb_parse(struct i915_execbuffer *eb)
 	eb->vma[eb->buffer_count].vma = i915_vma_get(shadow);
 	eb->vma[eb->buffer_count].flags = __EXEC_OBJECT_HAS_PIN;
 	eb->batch = &eb->vma[eb->buffer_count++];
-	eb->vma[eb->buffer_count].vma = NULL;
 
 	eb->trampoline = trampoline;
 	eb->batch_start_offset = 0;
@@ -2838,6 +2811,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,
 		args->flags |= __EXEC_HAS_RELOC;
 
 	eb.exec = exec;
+	eb.vma = (struct eb_vma *)(exec + args->buffer_count + 1);
+	eb.vma[0].vma = NULL;
 
 	eb.invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
 	reloc_cache_init(&eb.reloc_cache, eb.i915);
@@ -3014,6 +2989,8 @@ i915_gem_do_execbuffer(struct drm_device *dev,
 	if (batch->private)
 		intel_gt_buffer_pool_put(batch->private);
 err_vma:
+	if (eb.exec)
+		eb_release_vmas(&eb);
 	if (eb.trampoline)
 		i915_vma_unpin(eb.trampoline);
 	eb_unpin_engine(&eb);
@@ -3031,7 +3008,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,
 
 static size_t eb_element_size(void)
 {
-	return sizeof(struct drm_i915_gem_exec_object2);
+	return sizeof(struct drm_i915_gem_exec_object2) + sizeof(struct eb_vma);
 }
 
 static bool check_buffer_count(size_t count)
@@ -3087,7 +3064,7 @@ i915_gem_execbuffer_ioctl(struct drm_device *dev, void *data,
 	/* Copy in the exec list from userland */
 	exec_list = kvmalloc_array(count, sizeof(*exec_list),
 				   __GFP_NOWARN | GFP_KERNEL);
-	exec2_list = kvmalloc_array(count, eb_element_size(),
+	exec2_list = kvmalloc_array(count + 1, eb_element_size(),
 				    __GFP_NOWARN | GFP_KERNEL);
 	if (exec_list == NULL || exec2_list == NULL) {
 		drm_dbg(&i915->drm,
@@ -3165,7 +3142,8 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data,
 	if (err)
 		return err;
 
-	exec2_list = kvmalloc_array(count, eb_element_size(),
+	/* Allocate an extra slot for use by the command parser */
+	exec2_list = kvmalloc_array(count + 1, eb_element_size(),
 				    __GFP_NOWARN | GFP_KERNEL);
 	if (exec2_list == NULL) {
 		drm_dbg(&i915->drm, "Failed to allocate exec list for %zd buffers\n",
-- 
2.27.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2020-06-23 14:29 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23 14:28 [Intel-gfx] [PATCH 01/26] Revert "drm/i915/gem: Async GPU relocations only" Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 02/26] drm/i915: Revert relocation chaining commits Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 03/26] Revert "drm/i915/gem: Drop relocation slowpath" Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 04/26] drm/i915: Add an implementation for i915_gem_ww_ctx locking, v2 Maarten Lankhorst
2020-06-24  7:10   ` Thomas Hellström (Intel)
2020-06-24  7:43     ` Chris Wilson
2020-06-24  7:49       ` Thomas Hellström (Intel)
2020-06-24  8:27         ` Chris Wilson
2020-06-29 12:07   ` Tvrtko Ursulin
2020-06-29 12:32   ` Tvrtko Ursulin
2020-06-29 13:44     ` Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 05/26] drm/i915: Remove locking from i915_gem_object_prepare_read/write Maarten Lankhorst
2020-06-26 13:32   ` Thomas Hellström (Intel)
2020-06-29 12:56   ` Tvrtko Ursulin
2020-06-23 14:28 ` [Intel-gfx] [PATCH 06/26] drm/i915: Parse command buffer earlier in eb_relocate(slow) Maarten Lankhorst
2020-06-26 14:41   ` Thomas Hellström (Intel)
2020-06-29 10:40     ` Maarten Lankhorst
2020-06-29 11:15       ` Thomas Hellström (Intel)
2020-06-29 11:18         ` Maarten Lankhorst
2020-06-29 14:42   ` Tvrtko Ursulin
2020-06-23 14:28 ` Maarten Lankhorst [this message]
2020-06-29 15:08   ` [Intel-gfx] [PATCH 07/26] Revert "drm/i915/gem: Split eb_vma into its own allocation" Tvrtko Ursulin
2020-06-30 11:52     ` Maarten Lankhorst
2020-06-30 12:31       ` Tvrtko Ursulin
2020-06-30 14:07         ` Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 08/26] drm/i915/gem: Make eb_add_lut interruptible wait on object lock Maarten Lankhorst
2020-06-26 13:52   ` Thomas Hellström (Intel)
2020-06-29 15:14   ` Tvrtko Ursulin
2020-06-30 11:56     ` Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 09/26] drm/i915: Use per object locking in execbuf, v12 Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 10/26] drm/i915: Use ww locking in intel_renderstate Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 11/26] drm/i915: Add ww context handling to context_barrier_task Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 12/26] drm/i915: Nuke arguments to eb_pin_engine Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 13/26] drm/i915: Pin engine before pinning all objects, v4 Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 14/26] drm/i915: Rework intel_context pinning to do everything outside of pin_mutex Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 15/26] drm/i915: Make sure execbuffer always passes ww state to i915_vma_pin Maarten Lankhorst
2020-06-25 14:32   ` Thomas Hellström (Intel)
2020-06-23 14:28 ` [Intel-gfx] [PATCH 16/26] drm/i915: Convert i915_gem_object/client_blt.c to use ww locking as well, v2 Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 17/26] drm/i915: Kill last user of intel_context_create_request outside of selftests Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 18/26] drm/i915: Convert i915_perf to ww locking as well Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 19/26] drm/i915: Dirty hack to fix selftests locking inversion Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 20/26] drm/i915/selftests: Fix locking inversion in lrc selftest Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 21/26] drm/i915: Use ww pinning for intel_context_create_request() Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 22/26] drm/i915: Move i915_vma_lock in the selftests to avoid lock inversion, v2 Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 23/26] drm/i915: Add ww locking to vm_fault_gtt Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 24/26] drm/i915: Add ww locking to pin_to_display_plane Maarten Lankhorst
2020-06-23 14:28 ` [Intel-gfx] [PATCH 25/26] drm/i915: Ensure we hold the pin mutex Maarten Lankhorst
2020-06-24  1:52   ` kernel test robot
2020-06-23 14:28 ` [Intel-gfx] [PATCH 26/26] drm/i915: Kill context before taking ctx->mutex Maarten Lankhorst
2020-06-24 11:05   ` [Intel-gfx] [PATCH] " Maarten Lankhorst
2020-06-30 14:16     ` Tvrtko Ursulin
2020-07-02 13:26       ` Maarten Lankhorst
2020-07-02 14:51         ` Tvrtko Ursulin
2020-07-03 10:35           ` Maarten Lankhorst
2020-06-23 15:23 ` [Intel-gfx] [PATCH 01/26] Revert "drm/i915/gem: Async GPU relocations only" Chris Wilson
2020-06-24 11:19   ` Chris Wilson
2020-06-23 15:39 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for series starting with [01/26] " Patchwork
2020-06-24 11:58 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/26] Revert "drm/i915/gem: Async GPU relocations only" (rev2) Patchwork
2020-06-24 11:59 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2020-06-24 12:48 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2020-07-01 13:10 ` [Intel-gfx] ✗ Fi.CI.IGT: " 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=20200623142843.423594-7-maarten.lankhorst@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --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.