diff mbox series

[13/19] drm/i915: Take object lock in i915_ggtt_pin if ww is not set

Message ID 20210830121006.2978297-14-maarten.lankhorst@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: Short-term pinning and async eviction. | expand

Commit Message

Maarten Lankhorst Aug. 30, 2021, 12:10 p.m. UTC
i915_vma_wait_for_bind needs the vma lock held, fix the caller.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_vma.c | 40 +++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 12 deletions(-)

Comments

Niranjana Vishwanathapura Sept. 8, 2021, 3:11 a.m. UTC | #1
On Mon, Aug 30, 2021 at 02:10:00PM +0200, Maarten Lankhorst wrote:
>i915_vma_wait_for_bind needs the vma lock held, fix the caller.
>

Need an lock assert in i915_vma_wait_for_bind()?

Niranjana

>Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>---
> drivers/gpu/drm/i915/i915_vma.c | 40 +++++++++++++++++++++++----------
> 1 file changed, 28 insertions(+), 12 deletions(-)
>
>diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
>index 5e0eaa9ea890..77319619dba0 100644
>--- a/drivers/gpu/drm/i915/i915_vma.c
>+++ b/drivers/gpu/drm/i915/i915_vma.c
>@@ -1322,23 +1322,15 @@ static void flush_idle_contexts(struct intel_gt *gt)
> 	intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
> }
>
>-int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
>-		  u32 align, unsigned int flags)
>+static int __i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
>+			   u32 align, unsigned int flags)
> {
> 	struct i915_address_space *vm = vma->vm;
> 	int err;
>
>-	GEM_BUG_ON(!i915_vma_is_ggtt(vma));
>-
>-#ifdef CONFIG_LOCKDEP
>-	WARN_ON(!ww && dma_resv_held(vma->obj->base.resv));
>-#endif
>-
> 	do {
>-		if (ww)
>-			err = i915_vma_pin_ww(vma, ww, 0, align, flags | PIN_GLOBAL);
>-		else
>-			err = i915_vma_pin(vma, 0, align, flags | PIN_GLOBAL);
>+		err = i915_vma_pin_ww(vma, ww, 0, align, flags | PIN_GLOBAL);
>+
> 		if (err != -ENOSPC) {
> 			if (!err) {
> 				err = i915_vma_wait_for_bind(vma);
>@@ -1357,6 +1349,30 @@ int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
> 	} while (1);
> }
>
>+int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
>+		  u32 align, unsigned int flags)
>+{
>+	struct i915_gem_ww_ctx _ww;
>+	int err;
>+
>+	GEM_BUG_ON(!i915_vma_is_ggtt(vma));
>+
>+	if (ww)
>+		return __i915_ggtt_pin(vma, ww, align, flags);
>+
>+#ifdef CONFIG_LOCKDEP
>+	WARN_ON(dma_resv_held(vma->obj->base.resv));
>+#endif
>+
>+	for_i915_gem_ww(&_ww, err, true) {
>+		err = i915_gem_object_lock(vma->obj, &_ww);
>+		if (!err)
>+			err = __i915_ggtt_pin(vma, &_ww, align, flags);
>+	}
>+
>+	return err;
>+}
>+
> static void __vma_close(struct i915_vma *vma, struct intel_gt *gt)
> {
> 	/*
>-- 
>2.32.0
>
Maarten Lankhorst Sept. 16, 2021, 1:54 p.m. UTC | #2
Op 08-09-2021 om 05:11 schreef Niranjana Vishwanathapura:
> On Mon, Aug 30, 2021 at 02:10:00PM +0200, Maarten Lankhorst wrote:
>> i915_vma_wait_for_bind needs the vma lock held, fix the caller.
>>
>
> Need an lock assert in i915_vma_wait_for_bind()?
>
> Niranjana 
Yeah, makes sense. I suppose changing dma_resv_get_excl_unlocked() to dma_resv_excl_fence() will work too. Will do that instead..
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 5e0eaa9ea890..77319619dba0 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -1322,23 +1322,15 @@  static void flush_idle_contexts(struct intel_gt *gt)
 	intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
 }
 
-int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
-		  u32 align, unsigned int flags)
+static int __i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
+			   u32 align, unsigned int flags)
 {
 	struct i915_address_space *vm = vma->vm;
 	int err;
 
-	GEM_BUG_ON(!i915_vma_is_ggtt(vma));
-
-#ifdef CONFIG_LOCKDEP
-	WARN_ON(!ww && dma_resv_held(vma->obj->base.resv));
-#endif
-
 	do {
-		if (ww)
-			err = i915_vma_pin_ww(vma, ww, 0, align, flags | PIN_GLOBAL);
-		else
-			err = i915_vma_pin(vma, 0, align, flags | PIN_GLOBAL);
+		err = i915_vma_pin_ww(vma, ww, 0, align, flags | PIN_GLOBAL);
+
 		if (err != -ENOSPC) {
 			if (!err) {
 				err = i915_vma_wait_for_bind(vma);
@@ -1357,6 +1349,30 @@  int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
 	} while (1);
 }
 
+int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
+		  u32 align, unsigned int flags)
+{
+	struct i915_gem_ww_ctx _ww;
+	int err;
+
+	GEM_BUG_ON(!i915_vma_is_ggtt(vma));
+
+	if (ww)
+		return __i915_ggtt_pin(vma, ww, align, flags);
+
+#ifdef CONFIG_LOCKDEP
+	WARN_ON(dma_resv_held(vma->obj->base.resv));
+#endif
+
+	for_i915_gem_ww(&_ww, err, true) {
+		err = i915_gem_object_lock(vma->obj, &_ww);
+		if (!err)
+			err = __i915_ggtt_pin(vma, &_ww, align, flags);
+	}
+
+	return err;
+}
+
 static void __vma_close(struct i915_vma *vma, struct intel_gt *gt)
 {
 	/*