diff mbox series

[RFC,156/162] drm/i915: Use a ww transaction in i915_gem_object_pin_map_unlocked()

Message ID 20201127120718.454037-157-matthew.auld@intel.com (mailing list archive)
State New, archived
Headers show
Series DG1 + LMEM enabling | expand

Commit Message

Matthew Auld Nov. 27, 2020, 12:07 p.m. UTC
From: Thomas Hellström <thomas.hellstrom@intel.com>

By using a ww transaction, anybody using this function and ending up
evicting objects can use sleeping waits when locking objects to evict.

Signed-off-by: Thomas Hellström <thomas.hellstrom@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_pages.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_pages.c b/drivers/gpu/drm/i915/gem/i915_gem_pages.c
index d0f3da0925f5..0c20f9b18956 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_pages.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_pages.c
@@ -425,11 +425,22 @@  void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj,
 void *i915_gem_object_pin_map_unlocked(struct drm_i915_gem_object *obj,
 				       enum i915_map_type type)
 {
+	struct i915_gem_ww_ctx ww;
 	void *ret;
+	int err;
 
-	i915_gem_object_lock(obj, NULL);
-	ret = i915_gem_object_pin_map(obj, type);
-	i915_gem_object_unlock(obj);
+	for_i915_gem_ww(&ww, err, false) {
+		err = i915_gem_object_lock(obj, &ww);
+		if (err)
+			continue;
+
+		ret = i915_gem_object_pin_map(obj, type);
+		if (IS_ERR(ret))
+			err = PTR_ERR(ret);
+		/* Implicit unlock */
+	}
+	if (err)
+		return ERR_PTR(err);
 
 	return ret;
 }