[Intel-gfx] [PATCH 1/2] drm/i915: Pin pages as we flush for CPU access

Chris Wilson chris at chris-wilson.co.uk
Fri May 6 14:36:30 UTC 2016


As a precautionary defensive measure against changes to the core (where
we stop changing domains when unbinding), we want to ensure that the pages
are available when we want to start CPU access, otherwise we will not
perform the requisite clflushes to make the contents coherent for the user.

We already do this for the GTT access path, so lift it from the
set-to-gtt-domain to the set-domain-ioctl caller so we also apply it for
set-to-cpu-domain.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index a88e6c9e9516..625fb402b67d 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1630,11 +1630,27 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
 	if (ret)
 		goto unref;
 
+	/* Flush and acquire obj->pages so that we are coherent through
+	 * direct access in memory with previous cached writes through
+	 * shmemfs and that our cache domain tracking remains valid.
+	 * For example, if the obj->filp was moved to swap without us
+	 * being notified and releasing the pages, we would mistakenly
+	 * continue to assume that the obj remained out of the CPU cached
+	 * domain.
+	 */
+	ret = i915_gem_object_get_pages(obj);
+	if (ret)
+		goto unref;
+
+	i915_gem_object_pin_pages(obj);
+
 	if (read_domains & I915_GEM_DOMAIN_GTT)
 		ret = i915_gem_object_set_to_gtt_domain(obj, write_domain != 0);
 	else
 		ret = i915_gem_object_set_to_cpu_domain(obj, write_domain != 0);
 
+	i915_gem_object_unpin_pages(obj);
+
 	if (write_domain != 0)
 		intel_fb_obj_invalidate(obj,
 					write_domain == I915_GEM_DOMAIN_GTT ?
@@ -3754,18 +3770,6 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
 	if (ret)
 		return ret;
 
-	/* Flush and acquire obj->pages so that we are coherent through
-	 * direct access in memory with previous cached writes through
-	 * shmemfs and that our cache domain tracking remains valid.
-	 * For example, if the obj->filp was moved to swap without us
-	 * being notified and releasing the pages, we would mistakenly
-	 * continue to assume that the obj remained out of the CPU cached
-	 * domain.
-	 */
-	ret = i915_gem_object_get_pages(obj);
-	if (ret)
-		return ret;
-
 	i915_gem_object_flush_cpu_write_domain(obj);
 
 	/* Serialise direct access to this object with the barriers for
-- 
2.8.1



More information about the Intel-gfx mailing list