diff mbox series

[v5,1/6] drm/i915: Call i915_gem_evict_vm in vm_fault_gtt to prevent new ENOSPC errors, v2.

Message ID 20220113114500.2039439-2-maarten.lankhorst@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: Remove short term pins from execbuf by requiring lock to unbind. | expand

Commit Message

Maarten Lankhorst Jan. 13, 2022, 11:44 a.m. UTC
Now that we cannot unbind kill the currently locked object directly
because we're removing short term pinning, we may have to unbind the
object from gtt manually, using a i915_gem_evict_vm() call.

Changes since v1:
- Remove -ENOSPC warning, can still happen with concurrent mmaps
  where we can't unbind the other mmap because of the lock held.
  This  fixes the gem_mmap_gtt@cpuset tests.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_mman.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Comments

Thomas Hellström Jan. 13, 2022, 1:30 p.m. UTC | #1
On 1/13/22 12:44, Maarten Lankhorst wrote:
> Now that we cannot unbind kill the currently locked object directly
> because we're removing short term pinning, we may have to unbind the
> object from gtt manually, using a i915_gem_evict_vm() call.
>
> Changes since v1:
> - Remove -ENOSPC warning, can still happen with concurrent mmaps
>    where we can't unbind the other mmap because of the lock held.
>    This  fixes the gem_mmap_gtt@cpuset tests.
>
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>

Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>


> ---
>   drivers/gpu/drm/i915/gem/i915_gem_mman.c | 18 ++++++++++++++++--
>   1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
> index 5ac2506f4ee8..fafd158e5313 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_mman.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
> @@ -21,6 +21,7 @@
>   #include "i915_trace.h"
>   #include "i915_user_extensions.h"
>   #include "i915_gem_ttm.h"
> +#include "i915_gem_evict.h"
>   #include "i915_vma.h"
>   
>   static inline bool
> @@ -358,8 +359,21 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
>   			vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
>   		}
>   
> -		/* The entire mappable GGTT is pinned? Unexpected! */
> -		GEM_BUG_ON(vma == ERR_PTR(-ENOSPC));
> +		/*
> +		 * The entire mappable GGTT is pinned? Unexpected!
> +		 * Try to evict the object we locked too, as normally we skip it
> +		 * due to lack of short term pinning inside execbuf.
> +		 */
> +		if (vma == ERR_PTR(-ENOSPC)) {
> +			ret = mutex_lock_interruptible(&ggtt->vm.mutex);
> +			if (!ret) {
> +				ret = i915_gem_evict_vm(&ggtt->vm);
> +				mutex_unlock(&ggtt->vm.mutex);
> +			}
> +			if (ret)
> +				goto err_reset;
> +			vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
> +		}
>   	}
>   	if (IS_ERR(vma)) {
>   		ret = PTR_ERR(vma);
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
index 5ac2506f4ee8..fafd158e5313 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_mman.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
@@ -21,6 +21,7 @@ 
 #include "i915_trace.h"
 #include "i915_user_extensions.h"
 #include "i915_gem_ttm.h"
+#include "i915_gem_evict.h"
 #include "i915_vma.h"
 
 static inline bool
@@ -358,8 +359,21 @@  static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
 			vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
 		}
 
-		/* The entire mappable GGTT is pinned? Unexpected! */
-		GEM_BUG_ON(vma == ERR_PTR(-ENOSPC));
+		/*
+		 * The entire mappable GGTT is pinned? Unexpected!
+		 * Try to evict the object we locked too, as normally we skip it
+		 * due to lack of short term pinning inside execbuf.
+		 */
+		if (vma == ERR_PTR(-ENOSPC)) {
+			ret = mutex_lock_interruptible(&ggtt->vm.mutex);
+			if (!ret) {
+				ret = i915_gem_evict_vm(&ggtt->vm);
+				mutex_unlock(&ggtt->vm.mutex);
+			}
+			if (ret)
+				goto err_reset;
+			vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
+		}
 	}
 	if (IS_ERR(vma)) {
 		ret = PTR_ERR(vma);