From 91fb567b784d5a3ef430211f8de8e91901e4845c Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 21 Dec 2012 12:40:59 +0000 Subject: [PATCH] drm/i915,agp/intel: Detect invalid accesses by clearing unused portions Signed-off-by: Chris Wilson --- drivers/char/agp/intel-gtt.c | 29 +++++++++++++++++++++-------- drivers/gpu/drm/i915/i915_gem_gtt.c | 3 ++- include/drm/intel-gtt.h | 3 ++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c index 7ad6d13..3ddc81a 100644 --- a/drivers/char/agp/intel-gtt.c +++ b/drivers/char/agp/intel-gtt.c @@ -799,7 +799,8 @@ static bool i830_check_flags(unsigned int flags) void intel_gtt_insert_sg_entries(const struct sg_table *st, unsigned int pg, - unsigned int flags) + unsigned int flags, + bool append_scratch_page) { struct scatterlist *sg; int i, j; @@ -829,6 +830,9 @@ void intel_gtt_insert_sg_entries(const struct sg_table *st, BUG_ON(!sg_is_chain(sg)); sg = sg_chain_ptr(sg); } while (1); + if (append_scratch_page) + intel_private.driver->write_entry(intel_private.base.scratch_page_dma, + pg++, 0); readl(intel_private.gtt+pg-1); } EXPORT_SYMBOL(intel_gtt_insert_sg_entries); @@ -848,6 +852,17 @@ static void intel_gtt_insert_pages(unsigned int first_entry, readl(intel_private.gtt+j-1); } +static void _intel_gtt_scratch_range(unsigned int first_entry, unsigned int num_entries) +{ + unsigned int i; + + for (i = first_entry; i < (first_entry + num_entries); i++) { + intel_private.driver->write_entry(intel_private.base.scratch_page_dma, + i, 0); + } + readl(intel_private.gtt+i-1); +} + static int intel_fake_agp_insert_entries(struct agp_memory *mem, off_t pg_start, int type) { @@ -859,7 +874,7 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem, if (intel_private.clear_fake_agp) { int start = intel_private.base.stolen_size / PAGE_SIZE; int end = intel_private.base.gtt_mappable_entries; - intel_gtt_clear_range(start, end - start); + _intel_gtt_scratch_range(start, end - start); intel_private.clear_fake_agp = false; } @@ -888,7 +903,7 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem, if (ret != 0) return ret; - intel_gtt_insert_sg_entries(&st, pg_start, type); + intel_gtt_insert_sg_entries(&st, pg_start, type, false); mem->sg_list = st.sgl; mem->num_sg = st.nents; } else @@ -906,10 +921,8 @@ void intel_gtt_clear_range(unsigned int first_entry, unsigned int num_entries) { unsigned int i; - for (i = first_entry; i < (first_entry + num_entries); i++) { - intel_private.driver->write_entry(intel_private.base.scratch_page_dma, - i, 0); - } + for (i = first_entry; i < (first_entry + num_entries); i++) + writel(0, intel_private.gtt + i); readl(intel_private.gtt+i-1); } EXPORT_SYMBOL(intel_gtt_clear_range); @@ -923,7 +936,7 @@ static int intel_fake_agp_remove_entries(struct agp_memory *mem, if (intel_private.base.do_idle_maps) return -ENODEV; - intel_gtt_clear_range(pg_start, mem->page_count); + _intel_gtt_scratch_range(pg_start, mem->page_count); if (intel_private.base.needs_dmar) { intel_gtt_unmap_memory(mem->sg_list, mem->num_sg); diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index cc1be53..d3ca235 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -475,7 +475,8 @@ void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj, AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY; intel_gtt_insert_sg_entries(obj->pages, obj->gtt_space->start >> PAGE_SHIFT, - flags); + flags, + obj->gtt_space->hole_follows); } else { gen6_ggtt_bind_object(obj, cache_level); } diff --git a/include/drm/intel-gtt.h b/include/drm/intel-gtt.h index b9be101..0d7354d 100644 --- a/include/drm/intel-gtt.h +++ b/include/drm/intel-gtt.h @@ -33,7 +33,8 @@ bool intel_enable_gtt(void); void intel_gtt_chipset_flush(void); void intel_gtt_insert_sg_entries(const struct sg_table *st, unsigned int pg_start, - unsigned int flags); + unsigned int flags, + bool append_scratch_page); void intel_gtt_clear_range(unsigned int first_entry, unsigned int num_entries); /* Special gtt memory types */ -- 1.7.10.4