All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH 09/16] drm/i915: don't clobber userspace memory before commiting to the pread
Date: Sun, 25 Mar 2012 19:47:36 +0200	[thread overview]
Message-ID: <1332697663-31256-9-git-send-email-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <1332697663-31256-1-git-send-email-daniel.vetter@ffwll.ch>

The pagemap.h prefault helpers do the prefaulting by simply writing
some data into every page. Hence we should not prefault when we're not
yet commited to to actually writing data to userspace. The problem is
now that
- we can't prefault while holding dev->struct_mutex for we could
  deadlock with our own pagefault handler
- we need to grab dev->struct_mutex before copying to sync up with any
  outsanding gpu writes.

Therefore only prefault when we're dropping the lock the first time in
the pread slowpath - at that point we're committed to the write, don't
wait on the gpu anymore and hence won't return early (with e.g.
-EINTR).

Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index ddd1fa4..34593e4 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -320,6 +320,7 @@ i915_gem_shmem_pread(struct drm_device *dev,
 	int shmem_page_offset, page_length, ret = 0;
 	int obj_do_bit17_swizzling, page_do_bit17_swizzling;
 	int hit_slowpath = 0;
+	int prefaulted = 0;
 	int needs_clflush = 0;
 	int release_page;
 
@@ -388,6 +389,16 @@ i915_gem_shmem_pread(struct drm_device *dev,
 		page_cache_get(page);
 		mutex_unlock(&dev->struct_mutex);
 
+		if (!prefaulted) {
+			ret = fault_in_pages_writeable(user_data, remain);
+			/* Userspace is tricking us, but we've already clobbered
+			 * its pages with the prefault and promised to write the
+			 * data up to the first fault. Hence ignore any errors
+			 * and just continue. */
+			(void)ret;
+			prefaulted = 1;
+		}
+
 		vaddr = kmap(page);
 		if (needs_clflush)
 			drm_clflush_virt_range(vaddr + shmem_page_offset,
@@ -451,11 +462,6 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
 		       args->size))
 		return -EFAULT;
 
-	ret = fault_in_pages_writeable((char __user *)(uintptr_t)args->data_ptr,
-				       args->size);
-	if (ret)
-		return -EFAULT;
-
 	ret = i915_mutex_lock_interruptible(dev);
 	if (ret)
 		return ret;
-- 
1.7.7.6

  parent reply	other threads:[~2012-03-25 18:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-25 17:47 [PATCH 01/16] drm/i915: merge shmem_pwrite slow&fast-path Daniel Vetter
2012-03-25 17:47 ` [PATCH 02/16] drm/i915: merge shmem_pread slow&fast-path Daniel Vetter
2012-03-25 17:47 ` [PATCH 03/16] drm: add helper to clflush a virtual address range Daniel Vetter
2012-03-25 17:47 ` [PATCH 04/16] drm/i915: move clflushing into shmem_pread Daniel Vetter
2012-03-25 17:47 ` [PATCH 05/16] drm/i915: kill ranged cpu read domain support Daniel Vetter
2012-03-25 17:47 ` [PATCH 06/16] drm/i915: don't use gtt_pwrite on LLC cached objects Daniel Vetter
2012-03-25 17:47 ` [PATCH 07/16] drm/i915: don't call shmem_read_mapping unnecessarily Daniel Vetter
2012-03-26  9:10   ` Daniel Vetter
2012-03-25 17:47 ` [PATCH 08/16] drm/i915: drop gtt slowpath Daniel Vetter
2012-03-25 17:47 ` Daniel Vetter [this message]
2012-03-25 17:47 ` [PATCH 10/16] drm/i915: implement inline clflush for pwrite Daniel Vetter
2012-03-25 17:47 ` [PATCH 11/16] drm/i915: fall back to shmem pwrite when the buffer is not accessible Daniel Vetter
2012-03-25 17:47 ` [PATCH 12/16] drm/i915: use uncached writes in pwrite Daniel Vetter
2012-03-25 17:47 ` [PATCH 13/16] drm/i915: extract copy helpers from shmem_pread|pwrite Daniel Vetter
2012-03-26  9:05   ` Chris Wilson
2012-03-25 17:47 ` [PATCH 14/16] mm: extend prefault helpers to fault in more than PAGE_SIZE Daniel Vetter
2012-03-26  9:09   ` Chris Wilson
2012-03-25 17:47 ` [PATCH 15/16] drm/i915: fixup in-line clflushing on bit17 swizzled bos Daniel Vetter
2012-03-26  9:18   ` Chris Wilson
2012-03-26  9:26     ` Daniel Vetter
2012-03-26 12:50       ` Chris Wilson
2012-03-25 17:47 ` [PATCH 16/16] drm/i915: mark pwrite/pread slowpaths with unlikely Daniel Vetter
2012-03-26  9:09   ` Chris Wilson
2012-03-27 11:42     ` Daniel Vetter

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=1332697663-31256-9-git-send-email-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.