public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org
Subject: [RFC 2/5] drm/i915: Extract code mapping errno to vm fault code
Date: Tue, 26 Jan 2016 14:53:30 +0000	[thread overview]
Message-ID: <1453820013-3908-3-git-send-email-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <1453820013-3908-1-git-send-email-tvrtko.ursulin@linux.intel.com>

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Will be used from multiple callers in a following patch.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/i915_gem.c | 91 ++++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 42 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index af15c290c71d..dacf6a0013c5 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1772,6 +1772,53 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
 	return 0;
 }
 
+static int
+i915_gem_ret_to_vm_ret(struct drm_i915_private *dev_priv, int ret)
+{
+	switch (ret) {
+	case -EIO:
+		/*
+		 * We eat errors when the gpu is terminally wedged to avoid
+		 * userspace unduly crashing (gl has no provisions for mmaps to
+		 * fail). But any other -EIO isn't ours (e.g. swap in failure)
+		 * and so needs to be reported.
+		 */
+		if (!i915_terminally_wedged(&dev_priv->gpu_error)) {
+			ret = VM_FAULT_SIGBUS;
+			break;
+		}
+	case -EAGAIN:
+		/*
+		 * EAGAIN means the gpu is hung and we'll wait for the error
+		 * handler to reset everything when re-faulting in
+		 * i915_mutex_lock_interruptible.
+		 */
+	case 0:
+	case -ERESTARTSYS:
+	case -EINTR:
+	case -EBUSY:
+		/*
+		 * EBUSY is ok: this just means that another thread
+		 * already did the job.
+		 */
+		ret = VM_FAULT_NOPAGE;
+		break;
+	case -ENOMEM:
+		ret = VM_FAULT_OOM;
+		break;
+	case -ENOSPC:
+	case -EFAULT:
+		ret = VM_FAULT_SIGBUS;
+		break;
+	default:
+		WARN_ONCE(ret, "unhandled error in page fault\n");
+		ret = VM_FAULT_SIGBUS;
+		break;
+	}
+
+	return ret;
+}
+
 /**
  * i915_gem_fault - fault a page into the GTT
  * @vma: VMA in question
@@ -1902,49 +1949,9 @@ unpin:
 unlock:
 	mutex_unlock(&dev->struct_mutex);
 out:
-	switch (ret) {
-	case -EIO:
-		/*
-		 * We eat errors when the gpu is terminally wedged to avoid
-		 * userspace unduly crashing (gl has no provisions for mmaps to
-		 * fail). But any other -EIO isn't ours (e.g. swap in failure)
-		 * and so needs to be reported.
-		 */
-		if (!i915_terminally_wedged(&dev_priv->gpu_error)) {
-			ret = VM_FAULT_SIGBUS;
-			break;
-		}
-	case -EAGAIN:
-		/*
-		 * EAGAIN means the gpu is hung and we'll wait for the error
-		 * handler to reset everything when re-faulting in
-		 * i915_mutex_lock_interruptible.
-		 */
-	case 0:
-	case -ERESTARTSYS:
-	case -EINTR:
-	case -EBUSY:
-		/*
-		 * EBUSY is ok: this just means that another thread
-		 * already did the job.
-		 */
-		ret = VM_FAULT_NOPAGE;
-		break;
-	case -ENOMEM:
-		ret = VM_FAULT_OOM;
-		break;
-	case -ENOSPC:
-	case -EFAULT:
-		ret = VM_FAULT_SIGBUS;
-		break;
-	default:
-		WARN_ONCE(ret, "unhandled error in i915_gem_fault: %i\n", ret);
-		ret = VM_FAULT_SIGBUS;
-		break;
-	}
-
 	intel_runtime_pm_put(dev_priv);
-	return ret;
+
+	return i915_gem_ret_to_vm_ret(dev_priv, ret);
 }
 
 /**
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-01-26 14:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 14:53 [RFC 0/5] Adding CPU mmap support to DRM_IOCTL_I915_GEM_MMAP_GTT Tvrtko Ursulin
2016-01-26 14:53 ` [RFC 1/5] drm: Allow drivers setting vm_ops per vma offset node Tvrtko Ursulin
2016-01-26 14:53 ` Tvrtko Ursulin [this message]
2016-01-26 15:18   ` [RFC 2/5] drm/i915: Extract code mapping errno to vm fault code Chris Wilson
2016-01-26 16:24     ` Tvrtko Ursulin
2016-01-26 16:42       ` Chris Wilson
2016-01-26 14:53 ` [RFC 3/5] drm/i915: Add support for CPU mapping to DRM_IOCTL_I915_GEM_MMAP_GTT Tvrtko Ursulin
2016-01-26 15:10   ` Chris Wilson
2016-01-26 16:23     ` Tvrtko Ursulin
2016-01-26 16:59       ` Chris Wilson
2016-01-27 15:24         ` Tvrtko Ursulin
2016-01-27 16:36           ` Chris Wilson
2016-01-27 16:40           ` Chris Wilson
2016-01-27 15:21   ` [PATCH v2 " Tvrtko Ursulin
2016-01-27 15:51     ` Daniel Vetter
2016-01-27 16:01       ` Tvrtko Ursulin
2016-01-27 16:10         ` Daniel Vetter
2016-01-27 16:32       ` Chris Wilson
2016-01-26 14:53 ` [RFC 4/5] drm/i915: Add support for write-combined " Tvrtko Ursulin
2016-01-26 15:11   ` Chris Wilson
2016-01-27 15:22   ` [PATCH v2 " Tvrtko Ursulin
2016-01-26 14:53 ` [RFC 5/5] drm/i915: Announce the new DRM_IOCTL_I915_GEM_MMAP_GTT capabilities Tvrtko Ursulin
2016-01-28  9:18 ` ✓ Fi.CI.BAT: success for Adding CPU mmap support to DRM_IOCTL_I915_GEM_MMAP_GTT (rev3) Patchwork
2016-01-28 16:10 ` Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453820013-3908-3-git-send-email-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox