diff mbox

[v2] drm/i915: Avoid writing relocs with addresses in non-canonical form

Message ID 20151204153930.GO27216@nuc-i3427.alporthouse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson Dec. 4, 2015, 3:39 p.m. UTC
On Fri, Dec 04, 2015 at 04:20:43PM +0100, Micha? Winiarski wrote:
> According to bspec, some parts of HW expect the addresses to be in
> a canonical form, where bits [63:48] == [47]. Let's convert addresses to
> canonical form prior to relocating and return converted offsets to
> userspace.
> 
> v2: Whitespace fixup, gen8_canonical_addr description (Chris, Ville)
> 
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Michel Thierry <michel.thierry@intel.com>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Micha? Winiarski <michal.winiarski@intel.com>

There is a hole! Inside the actual relocation fixup you need

Otherwise we may cross the 1<<47 boundary without swapping into cannonical
form.
-Chris
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index a4c243cec4aa..6d1a2d20337b 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -249,6 +249,12 @@  static inline int use_cpu_reloc(struct drm_i915_gem_object *obj)
                obj->cache_level != I915_CACHE_NONE);
 }
 
+static uint64_t relocation_target(struct drm_i915_gem_relocation_entry *reloc,
+                                 uint64_t target_offset)
+{
+       return gen8_cannonical_address((int)reloc->delta + target_offset);
+}
+
 static int
 relocate_entry_cpu(struct drm_i915_gem_object *obj,
                   struct drm_i915_gem_relocation_entry *reloc,
@@ -256,7 +262,7 @@  relocate_entry_cpu(struct drm_i915_gem_object *obj,
 {
        struct drm_device *dev = obj->base.dev;
        uint32_t page_offset = offset_in_page(reloc->offset);
-       uint64_t delta = reloc->delta + target_offset;
+       uint64_t delta = relocation_target(reloc, target_get);
        char *vaddr;
        int ret;
 
@@ -292,7 +298,7 @@  relocate_entry_gtt(struct drm_i915_gem_object *obj,
 {
        struct drm_device *dev = obj->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       uint64_t delta = reloc->delta + target_offset;
+       uint64_t delta = relocation_target(reloc, target_get);
        uint64_t offset;
        void __iomem *reloc_page;
        int ret;
@@ -347,7 +353,7 @@  relocate_entry_clflush(struct drm_i915_gem_object *obj,
 {
        struct drm_device *dev = obj->base.dev;
        uint32_t page_offset = offset_in_page(reloc->offset);
-       uint64_t delta = (int)reloc->delta + target_offset;
+       uint64_t delta = relocation_target(reloc, target_get);
        char *vaddr;
        int ret;