Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 307001
b: refs/heads/master
c: f56f821
h: refs/heads/master
i:
  306999: 730cd99
v: v3
  • Loading branch information
Daniel Vetter committed Mar 27, 2012
1 parent 177ab0c commit 119ca16
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d174bd6472d79fb5603dc8bd35e5184d83194ea8
refs/heads/master: f56f821feb7b36223f309e0ec05986bb137ce418
6 changes: 3 additions & 3 deletions trunk/drivers/gpu/drm/i915/i915_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ i915_gem_shmem_pread(struct drm_device *dev,
mutex_unlock(&dev->struct_mutex);

if (!prefaulted) {
ret = fault_in_pages_writeable(user_data, remain);
ret = fault_in_multipages_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
Expand Down Expand Up @@ -809,8 +809,8 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
args->size))
return -EFAULT;

ret = fault_in_pages_readable((char __user *)(uintptr_t)args->data_ptr,
args->size);
ret = fault_in_multipages_readable((char __user *)(uintptr_t)args->data_ptr,
args->size);
if (ret)
return -EFAULT;

Expand Down
2 changes: 1 addition & 1 deletion trunk/drivers/gpu/drm/i915/i915_gem_execbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
if (!access_ok(VERIFY_WRITE, ptr, length))
return -EFAULT;

if (fault_in_pages_readable(ptr, length))
if (fault_in_multipages_readable(ptr, length))
return -EFAULT;
}

Expand Down
64 changes: 62 additions & 2 deletions trunk/include/linux/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static inline int fault_in_pages_writeable(char __user *uaddr, int size)
*/
if (((unsigned long)uaddr & PAGE_MASK) !=
((unsigned long)end & PAGE_MASK))
ret = __put_user(0, end);
ret = __put_user(0, end);
}
return ret;
}
Expand All @@ -445,13 +445,73 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size)

if (((unsigned long)uaddr & PAGE_MASK) !=
((unsigned long)end & PAGE_MASK)) {
ret = __get_user(c, end);
ret = __get_user(c, end);
(void)c;
}
}
return ret;
}

/*
* Multipage variants of the above prefault helpers, useful if more than
* PAGE_SIZE of data needs to be prefaulted. These are separate from the above
* functions (which only handle up to PAGE_SIZE) to avoid clobbering the
* filemap.c hotpaths.
*/
static inline int fault_in_multipages_writeable(char __user *uaddr, int size)
{
int ret;
const char __user *end = uaddr + size - 1;

if (unlikely(size == 0))
return 0;

/*
* Writing zeroes into userspace here is OK, because we know that if
* the zero gets there, we'll be overwriting it.
*/
while (uaddr <= end) {
ret = __put_user(0, uaddr);
if (ret != 0)
return ret;
uaddr += PAGE_SIZE;
}

/* Check whether the range spilled into the next page. */
if (((unsigned long)uaddr & PAGE_MASK) ==
((unsigned long)end & PAGE_MASK))
ret = __put_user(0, end);

return ret;
}

static inline int fault_in_multipages_readable(const char __user *uaddr,
int size)
{
volatile char c;
int ret;
const char __user *end = uaddr + size - 1;

if (unlikely(size == 0))
return 0;

while (uaddr <= end) {
ret = __get_user(c, uaddr);
if (ret != 0)
return ret;
uaddr += PAGE_SIZE;
}

/* Check whether the range spilled into the next page. */
if (((unsigned long)uaddr & PAGE_MASK) ==
((unsigned long)end & PAGE_MASK)) {
ret = __get_user(c, end);
(void)c;
}

return ret;
}

int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
pgoff_t index, gfp_t gfp_mask);
int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
Expand Down

0 comments on commit 119ca16

Please sign in to comment.