diff mbox series

[v2,2/2] drm/i915: check memory is mappable in read_from_page

Message ID 20220930134731.389416-2-matthew.auld@intel.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] drm/i915/display: consider DG2_RC_CCS_CC when migrating buffers | expand

Commit Message

Matthew Auld Sept. 30, 2022, 1:47 p.m. UTC
On small-bar systems we could be given something non-mappable here,
which leads to nasty oops. Make this nicer by checking if the resource
is mappable or not, and return an error otherwise.

v2: drop GEM_BUG_ON(flags & I915_BO_ALLOC_GPU_ONLY)

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Jianshui Yu <jianshui.yu@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Nirmoy Das <nirmoy.das@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_object.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Nirmoy Das Sept. 30, 2022, 2:16 p.m. UTC | #1
Reviewed-by: Nirmoy Das <nirmoy.das@intel.com>

On 9/30/2022 3:47 PM, Matthew Auld wrote:
> On small-bar systems we could be given something non-mappable here,
> which leads to nasty oops. Make this nicer by checking if the resource
> is mappable or not, and return an error otherwise.
>
> v2: drop GEM_BUG_ON(flags & I915_BO_ALLOC_GPU_ONLY)
>
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Jianshui Yu <jianshui.yu@intel.com>
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> ---
>   drivers/gpu/drm/i915/gem/i915_gem_object.c | 12 +++++++++++-
>   1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c b/drivers/gpu/drm/i915/gem/i915_gem_object.c
> index 369006c5317f..62495d5d0038 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
> @@ -444,6 +444,16 @@ i915_gem_object_read_from_page_iomap(struct drm_i915_gem_object *obj, u64 offset
>   	io_mapping_unmap(src_map);
>   }
>   
> +static bool object_has_mappable_iomem(struct drm_i915_gem_object *obj)
> +{
> +	GEM_BUG_ON(!i915_gem_object_has_iomem(obj));
> +
> +	if (IS_DGFX(to_i915(obj->base.dev)))
> +		return i915_ttm_resource_mappable(i915_gem_to_ttm(obj)->resource);
> +
> +	return true;
> +}
> +
>   /**
>    * i915_gem_object_read_from_page - read data from the page of a GEM object
>    * @obj: GEM object to read from
> @@ -466,7 +476,7 @@ int i915_gem_object_read_from_page(struct drm_i915_gem_object *obj, u64 offset,
>   
>   	if (i915_gem_object_has_struct_page(obj))
>   		i915_gem_object_read_from_page_kmap(obj, offset, dst, size);
> -	else if (i915_gem_object_has_iomem(obj))
> +	else if (i915_gem_object_has_iomem(obj) && object_has_mappable_iomem(obj))
>   		i915_gem_object_read_from_page_iomap(obj, offset, dst, size);
>   	else
>   		return -ENODEV;
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c b/drivers/gpu/drm/i915/gem/i915_gem_object.c
index 369006c5317f..62495d5d0038 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
@@ -444,6 +444,16 @@  i915_gem_object_read_from_page_iomap(struct drm_i915_gem_object *obj, u64 offset
 	io_mapping_unmap(src_map);
 }
 
+static bool object_has_mappable_iomem(struct drm_i915_gem_object *obj)
+{
+	GEM_BUG_ON(!i915_gem_object_has_iomem(obj));
+
+	if (IS_DGFX(to_i915(obj->base.dev)))
+		return i915_ttm_resource_mappable(i915_gem_to_ttm(obj)->resource);
+
+	return true;
+}
+
 /**
  * i915_gem_object_read_from_page - read data from the page of a GEM object
  * @obj: GEM object to read from
@@ -466,7 +476,7 @@  int i915_gem_object_read_from_page(struct drm_i915_gem_object *obj, u64 offset,
 
 	if (i915_gem_object_has_struct_page(obj))
 		i915_gem_object_read_from_page_kmap(obj, offset, dst, size);
-	else if (i915_gem_object_has_iomem(obj))
+	else if (i915_gem_object_has_iomem(obj) && object_has_mappable_iomem(obj))
 		i915_gem_object_read_from_page_iomap(obj, offset, dst, size);
 	else
 		return -ENODEV;