]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/i915: Only fence tiled region of object.
authorBob Paauwe <bob.j.paauwe@intel.com>
Thu, 18 Dec 2014 17:51:26 +0000 (09:51 -0800)
committerZefan Li <lizefan@huawei.com>
Tue, 14 Apr 2015 09:33:56 +0000 (17:33 +0800)
commit af1a7301c7cf8912dca03065d448c4437c5c239f upstream.

When creating a fence for a tiled object, only fence the area that
makes up the actual tiles.  The object may be larger than the tiled
area and if we allow those extra addresses to be fenced, they'll
get converted to addresses beyond where the object is mapped. This
opens up the possiblity of writes beyond the end of object.

To prevent this, we adjust the size of the fence to only encompass
the area that makes up the actual tiles.  The extra space is considered
un-tiled and now behaves as if it was a linear object.

Testcase: igt/gem_tiled_fence_overflow
Reported-by: Dan Hettena <danh@ghs.com>
Signed-off-by: Bob Paauwe <bob.j.paauwe@intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
[lizf: Backported to 3.4:
 - adjust context
 - adjust indentation
 - make the same change to both sandybridge_write_fence_reg()
   and i965_write_fence_reg()]
Signed-off-by: Zefan Li <lizefan@huawei.com>
drivers/gpu/drm/i915/i915_gem.c

index 2ac4ded0de99c5729f824afc6156dc1ab600b2bb..b1f1d105e8c72492aea2e0d6aa6e90bf46506352 100644 (file)
@@ -2193,6 +2193,13 @@ static int sandybridge_write_fence_reg(struct drm_i915_gem_object *obj,
        int regnum = obj->fence_reg;
        uint64_t val;
 
+       /* Adjust fence size to match tiled area */
+       if (obj->tiling_mode != I915_TILING_NONE) {
+               uint32_t row_size = obj->stride *
+                       (obj->tiling_mode == I915_TILING_Y ? 32 : 8);
+               size = (size / row_size) * row_size;
+       }
+
        val = (uint64_t)((obj->gtt_offset + size - 4096) &
                         0xfffff000) << 32;
        val |= obj->gtt_offset & 0xfffff000;
@@ -2230,6 +2237,13 @@ static int i965_write_fence_reg(struct drm_i915_gem_object *obj,
        int regnum = obj->fence_reg;
        uint64_t val;
 
+       /* Adjust fence size to match tiled area */
+       if (obj->tiling_mode != I915_TILING_NONE) {
+               uint32_t row_size = obj->stride *
+                       (obj->tiling_mode == I915_TILING_Y ? 32 : 8);
+               size = (size / row_size) * row_size;
+       }
+
        val = (uint64_t)((obj->gtt_offset + size - 4096) &
                    0xfffff000) << 32;
        val |= obj->gtt_offset & 0xfffff000;