Commit 755d2218 authored by Chris Wilson's avatar Chris Wilson Committed by Daniel Vetter

drm/i915: Pin backing pages for pwrite

By using the recently introduced pinning of pages, we can safely drop
the mutex in the knowledge that the pages are not going to disappear
jeneath us, and so we can simplify the code for iterating over the pages.

Note: The old code had such complicated page refcounting since it used
obj->pages as a micro-optimization if it's there, but that could
(before this patch) disappear when we drop the dev->struct_mutex.
Hence some manual page refcounting was required for the slow path,
complicated by the fact that pages returned by shmem_read_mapping_page
already have a pageref, which needs to be dropped again.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarBen Widawsky <ben@bwidawsk.net>
[danvet: Added note to explain the question Ben raised in review.]
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent a5570178
...@@ -690,7 +690,7 @@ shmem_pwrite_fast(struct page *page, int shmem_page_offset, int page_length, ...@@ -690,7 +690,7 @@ shmem_pwrite_fast(struct page *page, int shmem_page_offset, int page_length,
page_length); page_length);
kunmap_atomic(vaddr); kunmap_atomic(vaddr);
return ret; return ret ? -EFAULT : 0;
} }
/* Only difference to the fast-path function is that this can handle bit17 /* Only difference to the fast-path function is that this can handle bit17
...@@ -724,7 +724,7 @@ shmem_pwrite_slow(struct page *page, int shmem_page_offset, int page_length, ...@@ -724,7 +724,7 @@ shmem_pwrite_slow(struct page *page, int shmem_page_offset, int page_length,
page_do_bit17_swizzling); page_do_bit17_swizzling);
kunmap(page); kunmap(page);
return ret; return ret ? -EFAULT : 0;
} }
static int static int
...@@ -733,7 +733,6 @@ i915_gem_shmem_pwrite(struct drm_device *dev, ...@@ -733,7 +733,6 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
struct drm_i915_gem_pwrite *args, struct drm_i915_gem_pwrite *args,
struct drm_file *file) struct drm_file *file)
{ {
struct address_space *mapping = obj->base.filp->f_path.dentry->d_inode->i_mapping;
ssize_t remain; ssize_t remain;
loff_t offset; loff_t offset;
char __user *user_data; char __user *user_data;
...@@ -742,7 +741,6 @@ i915_gem_shmem_pwrite(struct drm_device *dev, ...@@ -742,7 +741,6 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
int hit_slowpath = 0; int hit_slowpath = 0;
int needs_clflush_after = 0; int needs_clflush_after = 0;
int needs_clflush_before = 0; int needs_clflush_before = 0;
int release_page;
user_data = (char __user *) (uintptr_t) args->data_ptr; user_data = (char __user *) (uintptr_t) args->data_ptr;
remain = args->size; remain = args->size;
...@@ -768,6 +766,12 @@ i915_gem_shmem_pwrite(struct drm_device *dev, ...@@ -768,6 +766,12 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
&& obj->cache_level == I915_CACHE_NONE) && obj->cache_level == I915_CACHE_NONE)
needs_clflush_before = 1; needs_clflush_before = 1;
ret = i915_gem_object_get_pages(obj);
if (ret)
return ret;
i915_gem_object_pin_pages(obj);
offset = args->offset; offset = args->offset;
obj->dirty = 1; obj->dirty = 1;
...@@ -793,18 +797,7 @@ i915_gem_shmem_pwrite(struct drm_device *dev, ...@@ -793,18 +797,7 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
((shmem_page_offset | page_length) ((shmem_page_offset | page_length)
& (boot_cpu_data.x86_clflush_size - 1)); & (boot_cpu_data.x86_clflush_size - 1));
if (obj->pages) {
page = obj->pages[offset >> PAGE_SHIFT]; page = obj->pages[offset >> PAGE_SHIFT];
release_page = 0;
} else {
page = shmem_read_mapping_page(mapping, offset >> PAGE_SHIFT);
if (IS_ERR(page)) {
ret = PTR_ERR(page);
goto out;
}
release_page = 1;
}
page_do_bit17_swizzling = obj_do_bit17_swizzling && page_do_bit17_swizzling = obj_do_bit17_swizzling &&
(page_to_phys(page) & (1 << 17)) != 0; (page_to_phys(page) & (1 << 17)) != 0;
...@@ -816,26 +809,20 @@ i915_gem_shmem_pwrite(struct drm_device *dev, ...@@ -816,26 +809,20 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
goto next_page; goto next_page;
hit_slowpath = 1; hit_slowpath = 1;
page_cache_get(page);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
ret = shmem_pwrite_slow(page, shmem_page_offset, page_length, ret = shmem_pwrite_slow(page, shmem_page_offset, page_length,
user_data, page_do_bit17_swizzling, user_data, page_do_bit17_swizzling,
partial_cacheline_write, partial_cacheline_write,
needs_clflush_after); needs_clflush_after);
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
page_cache_release(page);
next_page: next_page:
set_page_dirty(page); set_page_dirty(page);
mark_page_accessed(page); mark_page_accessed(page);
if (release_page)
page_cache_release(page);
if (ret) { if (ret)
ret = -EFAULT;
goto out; goto out;
}
remain -= page_length; remain -= page_length;
user_data += page_length; user_data += page_length;
...@@ -843,6 +830,8 @@ i915_gem_shmem_pwrite(struct drm_device *dev, ...@@ -843,6 +830,8 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
} }
out: out:
i915_gem_object_unpin_pages(obj);
if (hit_slowpath) { if (hit_slowpath) {
/* Fixup: Kill any reinstated backing storage pages */ /* Fixup: Kill any reinstated backing storage pages */
if (obj->madv == __I915_MADV_PURGED) if (obj->madv == __I915_MADV_PURGED)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment