Skip to content

Commit 43566de

Browse files
ickledanvet
authored andcommitted
drm/i915: Broaden application of set-domain(GTT)
Previously, this was restricted to only operate on bound objects - to make pointer access through the GTT to the object coherent with writes to and from the GPU. A second usecase is drm_intel_bo_wait_rendering() which at present does not function unless the object also happens to be bound into the GGTT (on current systems that is becoming increasingly rare, especially for the typical requests from mesa). A third usecase is a future patch wishing to extend the coverage of the GTT domain to include objects not bound into the GGTT but still in its coherent cache domain. For the latter pair of requests, we need to operate on the object regardless of its bind state. v2: After discussion with Akash, we came to the conclusion that the get-pages was required in order for accurate domain tracking in the corner cases (like the shrinker) and also useful for ensuring memory coherency with earlier cached CPU mmaps in case userspace uses exotic cache bypass (non-temporal) instructions. v3: Fix the inactive object check. v4: Rebase to latest drm-intel-nightly codebase Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Akash Goel <akash.goel@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent b9b5dce commit 43566de

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
153153
return 0;
154154
}
155155

156-
static inline bool
157-
i915_gem_object_is_inactive(struct drm_i915_gem_object *obj)
158-
{
159-
return i915_gem_obj_bound_any(obj) && !obj->active;
160-
}
161-
162156
int
163157
i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
164158
struct drm_file *file)
@@ -1472,18 +1466,10 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
14721466
if (ret)
14731467
goto unref;
14741468

1475-
if (read_domains & I915_GEM_DOMAIN_GTT) {
1469+
if (read_domains & I915_GEM_DOMAIN_GTT)
14761470
ret = i915_gem_object_set_to_gtt_domain(obj, write_domain != 0);
1477-
1478-
/* Silently promote "you're not bound, there was nothing to do"
1479-
* to success, since the client was just asking us to
1480-
* make sure everything was done.
1481-
*/
1482-
if (ret == -EINVAL)
1483-
ret = 0;
1484-
} else {
1471+
else
14851472
ret = i915_gem_object_set_to_cpu_domain(obj, write_domain != 0);
1486-
}
14871473

14881474
unref:
14891475
drm_gem_object_unreference(&obj->base);
@@ -3699,15 +3685,10 @@ i915_gem_object_flush_cpu_write_domain(struct drm_i915_gem_object *obj,
36993685
int
37003686
i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
37013687
{
3702-
struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
3703-
struct i915_vma *vma = i915_gem_obj_to_ggtt(obj);
37043688
uint32_t old_write_domain, old_read_domains;
3689+
struct i915_vma *vma;
37053690
int ret;
37063691

3707-
/* Not valid to be called on unbound objects. */
3708-
if (vma == NULL)
3709-
return -EINVAL;
3710-
37113692
if (obj->base.write_domain == I915_GEM_DOMAIN_GTT)
37123693
return 0;
37133694

@@ -3716,6 +3697,19 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
37163697
return ret;
37173698

37183699
i915_gem_object_retire(obj);
3700+
3701+
/* Flush and acquire obj->pages so that we are coherent through
3702+
* direct access in memory with previous cached writes through
3703+
* shmemfs and that our cache domain tracking remains valid.
3704+
* For example, if the obj->filp was moved to swap without us
3705+
* being notified and releasing the pages, we would mistakenly
3706+
* continue to assume that the obj remained out of the CPU cached
3707+
* domain.
3708+
*/
3709+
ret = i915_gem_object_get_pages(obj);
3710+
if (ret)
3711+
return ret;
3712+
37193713
i915_gem_object_flush_cpu_write_domain(obj, false);
37203714

37213715
/* Serialise direct access to this object with the barriers for
@@ -3747,9 +3741,10 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
37473741
old_write_domain);
37483742

37493743
/* And bump the LRU for this access */
3750-
if (i915_gem_object_is_inactive(obj))
3744+
vma = i915_gem_obj_to_ggtt(obj);
3745+
if (vma && drm_mm_node_allocated(&vma->node) && !obj->active)
37513746
list_move_tail(&vma->mm_list,
3752-
&dev_priv->gtt.base.inactive_list);
3747+
&to_i915(obj->base.dev)->gtt.base.inactive_list);
37533748

37543749
return 0;
37553750
}

0 commit comments

Comments
 (0)