From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 2/2] drm/i915: Disable page-faults around the fast pwrite/pread paths
Date: Sat, 9 Jul 2011 09:38:51 +0100 [thread overview]
Message-ID: <1310200731-18086-2-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <1310200731-18086-1-git-send-email-chris@chris-wilson.co.uk>
These paths hold onto the struct mutex whilst accessing pages. In
order, to prevent a recursive dead-lock should we fault-in a GTT mapped
page we need to return -EFAULT and fallback to the slow path.
Lockdep has complained before about the potential dead-lock, but rvis is
the first application found to sufficiently abuse the API to trigger it.
Cursory performance regression testing on a 1GiB PineView system using
x11perf, cairo-perf-trace, glxgears and a few game benchmarks suggested
no large regressions with just a 2% slowdown for firefox. The caveat is
that this was an otherwise idle system and that for 32-bit systems
io_mapping_map_atomic_wc() already disabled page-faults.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38115
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem.c | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 2fce620..ecb27fd 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -365,9 +365,15 @@ i915_gem_shmem_pread_fast(struct drm_device *dev,
return PTR_ERR(page);
vaddr = kmap_atomic(page);
+ /* We have to disable faulting here in case the user address
+ * is really a GTT mapping and so we can not enter
+ * i915_gem_fault() whilst already holding struct_mutex.
+ */
+ pagefault_disable();
ret = __copy_to_user_inatomic(user_data,
vaddr + page_offset,
page_length);
+ pagefault_enable();
kunmap_atomic(vaddr);
mark_page_accessed(page);
@@ -593,8 +599,14 @@ fast_user_write(struct io_mapping *mapping,
unsigned long unwritten;
vaddr_atomic = io_mapping_map_atomic_wc(mapping, page_base);
+ /* We have to disable faulting here in case the user address
+ * is really a GTT mapping and so we can not enter
+ * i915_gem_fault() whilst already holding struct_mutex.
+ */
+ pagefault_disable();
unwritten = __copy_from_user_inatomic_nocache(vaddr_atomic + page_offset,
user_data, length);
+ pagefault_enable();
io_mapping_unmap_atomic(vaddr_atomic);
return unwritten;
}
@@ -812,11 +824,17 @@ i915_gem_shmem_pwrite_fast(struct drm_device *dev,
if (IS_ERR(page))
return PTR_ERR(page);
- vaddr = kmap_atomic(page, KM_USER0);
+ vaddr = kmap_atomic(page);
+ /* We have to disable faulting here in case the user address
+ * is really a GTT mapping and so we can not enter
+ * i915_gem_fault() whilst already holding struct_mutex.
+ */
+ pagefault_disable();
ret = __copy_from_user_inatomic(vaddr + page_offset,
user_data,
page_length);
- kunmap_atomic(vaddr, KM_USER0);
+ pagefault_enable();
+ kunmap_atomic(vaddr);
set_page_dirty(page);
mark_page_accessed(page);
--
1.7.5.4
next prev parent reply other threads:[~2011-07-09 8:38 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-09 8:38 [PATCH 1/2] drm/i915: Prefault all pages for pread and pwrite Chris Wilson
2011-07-09 8:38 ` Chris Wilson [this message]
2011-07-09 14:41 ` [PATCH 2/2] drm/i915: Disable page-faults around the fast pwrite/pread paths Eric Anholt
2011-07-09 17:40 ` Chris Wilson
2011-07-09 20:24 ` Keith Packard
2011-07-09 20:50 ` Chris Wilson
2011-07-09 21:06 ` Keith Packard
2011-07-09 21:23 ` Chris Wilson
2011-07-09 22:07 ` Keith Packard
2011-07-11 16:51 ` Chris Wilson
2011-07-11 19:55 ` Keith Packard
2011-07-10 18:45 ` Eric Anholt
2011-07-10 20:29 ` Keith Packard
2011-07-09 20:21 ` [PATCH 1/2] drm/i915: Prefault all pages for pread and pwrite Keith Packard
2011-07-09 20:31 ` Chris Wilson
2011-07-10 1:40 ` Ben Widawsky
2011-07-10 8:08 ` Chris Wilson
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=1310200731-18086-2-git-send-email-chris@chris-wilson.co.uk \
--to=chris@chris-wilson.co.uk \
--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;
as well as URLs for NNTP newsgroup(s).