diff mbox series

drm/i915: Fix errors when there is no free DSM

Message ID 20220121192450.208535-1-jose.souza@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: Fix errors when there is no free DSM | expand

Commit Message

Souza, Jose Jan. 21, 2022, 7:24 p.m. UTC
Part of DSM(data stolen memory) is reserved for HW functions and GUC
and in some platform this reserved block takes the whole DSM leaving
no memory to allocated by i915_gem_object_create_stolen() and friends.

In such cases i915_gem_init_stolen() was not calling drm_mm_init()
and returning 0, causing errors later when testing memory
(intel_memory_region_memtest()) and in intel_memory_regions_hw_probe()
saying setup of memory region failed:

checking generic (91000000 300000) vs hw (23fe7e000000 2000000)
checking generic (91000000 300000) vs hw (237800000000 800000000)
i915 0000:8c:00.0: [drm:i915_gem_init_stolen [i915]] GEN6_STOLEN_RESERVED = 0x00000003ff800185
i915 0000:8c:00.0: [drm:i915_gem_init_stolen [i915]] Memory reserved for graphics device: 8192K, usable: 0K
i915 0000:8c:00.0: Failed to read back from memory region:[mem 0x3ff800000-0x3ff7fffff] at [0x0000237bff800000 + 0x0000000000000000] for i915_gem_stolen_lmem_setup [i915]; wrote 0, read (ff, ff, ff)
i915 0000:8c:00.0: [drm] *ERROR* Failed to setup region 6 (type=3:0), error -22
[drm:intel_gt_setup_lmem [i915]] LMEM: debug trace data region: [0x0-0x2000000]
i915 0000:8c:00.0: [drm:intel_gt_setup_lmem [i915]] Local memory: [mem 0x00000000-0x3faffffff]

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 9 ++++++---
 drivers/gpu/drm/i915/intel_memory_region.c | 3 +++
 2 files changed, 9 insertions(+), 3 deletions(-)

Comments

Ville Syrjälä Jan. 21, 2022, 7:53 p.m. UTC | #1
On Fri, Jan 21, 2022 at 11:24:50AM -0800, José Roberto de Souza wrote:
> Part of DSM(data stolen memory) is reserved for HW functions and GUC
> and in some platform this reserved block takes the whole DSM leaving
> no memory to allocated by i915_gem_object_create_stolen() and friends.
> 
> In such cases i915_gem_init_stolen() was not calling drm_mm_init()
> and returning 0, causing errors later when testing memory
> (intel_memory_region_memtest()) and in intel_memory_regions_hw_probe()
> saying setup of memory region failed:

I think you might that a bit backwards. There are a lot of other cases
where don't initialize stolen and still return 0 here. But in those cases
we *don't* call drm_mm_init() and everyone just uses drm_mm_initialized()
to check whether stolen was actually initialized or not.

> 
> checking generic (91000000 300000) vs hw (23fe7e000000 2000000)
> checking generic (91000000 300000) vs hw (237800000000 800000000)
> i915 0000:8c:00.0: [drm:i915_gem_init_stolen [i915]] GEN6_STOLEN_RESERVED = 0x00000003ff800185
> i915 0000:8c:00.0: [drm:i915_gem_init_stolen [i915]] Memory reserved for graphics device: 8192K, usable: 0K
> i915 0000:8c:00.0: Failed to read back from memory region:[mem 0x3ff800000-0x3ff7fffff] at [0x0000237bff800000 + 0x0000000000000000] for i915_gem_stolen_lmem_setup [i915]; wrote 0, read (ff, ff, ff)
> i915 0000:8c:00.0: [drm] *ERROR* Failed to setup region 6 (type=3:0), error -22
> [drm:intel_gt_setup_lmem [i915]] LMEM: debug trace data region: [0x0-0x2000000]
> i915 0000:8c:00.0: [drm:intel_gt_setup_lmem [i915]] Local memory: [mem 0x00000000-0x3faffffff]
> 
> Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 9 ++++++---
>  drivers/gpu/drm/i915/intel_memory_region.c | 3 +++
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
> index 26975d8577760..6e90357b2d1fd 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
> @@ -495,13 +495,16 @@ static int i915_gem_init_stolen(struct intel_memory_region *mem)
>  	 * memory, so just consider the start. */
>  	reserved_total = stolen_top - reserved_base;
>  
> +	i915->stolen_usable_size =
> +		resource_size(&i915->dsm) - reserved_total;
> +
>  	drm_dbg(&i915->drm,
>  		"Memory reserved for graphics device: %lluK, usable: %lluK\n",
>  		(u64)resource_size(&i915->dsm) >> 10,
> -		((u64)resource_size(&i915->dsm) - reserved_total) >> 10);
> +		(u64)i915->stolen_usable_size >> 10);
>  
> -	i915->stolen_usable_size =
> -		resource_size(&i915->dsm) - reserved_total;
> +	if (i915->stolen_usable_size == 0)
> +		return -ENOMEM;
>  
>  	/* Basic memrange allocator for stolen space. */
>  	drm_mm_init(&i915->mm.stolen, 0, i915->stolen_usable_size);
> diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
> index c70d7e286a512..317d67fa3a36e 100644
> --- a/drivers/gpu/drm/i915/intel_memory_region.c
> +++ b/drivers/gpu/drm/i915/intel_memory_region.c
> @@ -324,6 +324,9 @@ int intel_memory_regions_hw_probe(struct drm_i915_private *i915)
>  
>  		if (IS_ERR(mem)) {
>  			err = PTR_ERR(mem);
> +			if (err == -ENOMEM)
> +				continue;
> +
>  			drm_err(&i915->drm,
>  				"Failed to setup region(%d) type=%d\n",
>  				err, type);
> -- 
> 2.34.1
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
index 26975d8577760..6e90357b2d1fd 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
@@ -495,13 +495,16 @@  static int i915_gem_init_stolen(struct intel_memory_region *mem)
 	 * memory, so just consider the start. */
 	reserved_total = stolen_top - reserved_base;
 
+	i915->stolen_usable_size =
+		resource_size(&i915->dsm) - reserved_total;
+
 	drm_dbg(&i915->drm,
 		"Memory reserved for graphics device: %lluK, usable: %lluK\n",
 		(u64)resource_size(&i915->dsm) >> 10,
-		((u64)resource_size(&i915->dsm) - reserved_total) >> 10);
+		(u64)i915->stolen_usable_size >> 10);
 
-	i915->stolen_usable_size =
-		resource_size(&i915->dsm) - reserved_total;
+	if (i915->stolen_usable_size == 0)
+		return -ENOMEM;
 
 	/* Basic memrange allocator for stolen space. */
 	drm_mm_init(&i915->mm.stolen, 0, i915->stolen_usable_size);
diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
index c70d7e286a512..317d67fa3a36e 100644
--- a/drivers/gpu/drm/i915/intel_memory_region.c
+++ b/drivers/gpu/drm/i915/intel_memory_region.c
@@ -324,6 +324,9 @@  int intel_memory_regions_hw_probe(struct drm_i915_private *i915)
 
 		if (IS_ERR(mem)) {
 			err = PTR_ERR(mem);
+			if (err == -ENOMEM)
+				continue;
+
 			drm_err(&i915->drm,
 				"Failed to setup region(%d) type=%d\n",
 				err, type);