1
0
Fork 0

process_vm_access: tidy up a bit

saner variable names, update linuxdoc comments, etc.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
hifive-unleashed-5.1
Al Viro 2014-02-05 13:25:32 -05:00
parent 9acc1a0f9a
commit 4bafbec7bf
1 changed files with 19 additions and 40 deletions

View File

@ -23,20 +23,11 @@
/** /**
* process_vm_rw_pages - read/write pages from task specified * process_vm_rw_pages - read/write pages from task specified
* @task: task to read/write from * @pages: array of pointers to pages we want to copy
* @mm: mm for task
* @process_pages: struct pages area that can store at least
* nr_pages_to_copy struct page pointers
* @pa: address of page in task to start copying from/to
* @start_offset: offset in page to start copying from/to * @start_offset: offset in page to start copying from/to
* @len: number of bytes to copy * @len: number of bytes to copy
* @lvec: iovec array specifying where to copy to/from * @iter: where to copy to/from locally
* @lvec_cnt: number of elements in iovec array
* @lvec_current: index in iovec array we are up to
* @lvec_offset: offset in bytes from current iovec iov_base we are up to
* @vm_write: 0 means copy from, 1 means copy to * @vm_write: 0 means copy from, 1 means copy to
* @nr_pages_to_copy: number of pages to copy
* @bytes_copied: returns number of bytes successfully copied
* Returns 0 on success, error code otherwise * Returns 0 on success, error code otherwise
*/ */
static int process_vm_rw_pages(struct page **pages, static int process_vm_rw_pages(struct page **pages,
@ -79,16 +70,12 @@ static int process_vm_rw_pages(struct page **pages,
* process_vm_rw_single_vec - read/write pages from task specified * process_vm_rw_single_vec - read/write pages from task specified
* @addr: start memory address of target process * @addr: start memory address of target process
* @len: size of area to copy to/from * @len: size of area to copy to/from
* @lvec: iovec array specifying where to copy to/from locally * @iter: where to copy to/from locally
* @lvec_cnt: number of elements in iovec array
* @lvec_current: index in iovec array we are up to
* @lvec_offset: offset in bytes from current iovec iov_base we are up to
* @process_pages: struct pages area that can store at least * @process_pages: struct pages area that can store at least
* nr_pages_to_copy struct page pointers * nr_pages_to_copy struct page pointers
* @mm: mm for task * @mm: mm for task
* @task: task to read/write from * @task: task to read/write from
* @vm_write: 0 means copy from, 1 means copy to * @vm_write: 0 means copy from, 1 means copy to
* @bytes_copied: returns number of bytes successfully copied
* Returns 0 on success or on failure error code * Returns 0 on success or on failure error code
*/ */
static int process_vm_rw_single_vec(unsigned long addr, static int process_vm_rw_single_vec(unsigned long addr,
@ -103,7 +90,6 @@ static int process_vm_rw_single_vec(unsigned long addr,
unsigned long start_offset = addr - pa; unsigned long start_offset = addr - pa;
unsigned long nr_pages; unsigned long nr_pages;
ssize_t rc = 0; ssize_t rc = 0;
unsigned long nr_pages_copied = 0;
unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES
/ sizeof(struct pages *); / sizeof(struct pages *);
@ -112,38 +98,32 @@ static int process_vm_rw_single_vec(unsigned long addr,
return 0; return 0;
nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1; nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1;
while ((nr_pages_copied < nr_pages) && iov_iter_count(iter)) { while (!rc && nr_pages && iov_iter_count(iter)) {
int nr_pages_to_copy; int pages = min(nr_pages, max_pages_per_loop);
int pages_pinned; size_t bytes;
size_t n;
nr_pages_to_copy = min(nr_pages - nr_pages_copied,
max_pages_per_loop);
/* Get the pages we're interested in */ /* Get the pages we're interested in */
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
pages_pinned = get_user_pages(task, mm, pa, pages = get_user_pages(task, mm, pa, pages,
nr_pages_to_copy, vm_write, 0, process_pages, NULL);
vm_write, 0, process_pages, NULL);
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
if (pages_pinned <= 0) if (pages <= 0)
return -EFAULT; return -EFAULT;
n = pages_pinned * PAGE_SIZE - start_offset; bytes = pages * PAGE_SIZE - start_offset;
if (n > len) if (bytes > len)
n = len; bytes = len;
rc = process_vm_rw_pages(process_pages, rc = process_vm_rw_pages(process_pages,
start_offset, n, iter, start_offset, bytes, iter,
vm_write); vm_write);
len -= n; len -= bytes;
start_offset = 0; start_offset = 0;
nr_pages_copied += pages_pinned; nr_pages -= pages;
pa += pages_pinned * PAGE_SIZE; pa += pages * PAGE_SIZE;
while (pages_pinned) while (pages)
put_page(process_pages[--pages_pinned]); put_page(process_pages[--pages]);
if (rc < 0)
break;
} }
return rc; return rc;
@ -156,8 +136,7 @@ static int process_vm_rw_single_vec(unsigned long addr,
/** /**
* process_vm_rw_core - core of reading/writing pages from task specified * process_vm_rw_core - core of reading/writing pages from task specified
* @pid: PID of process to read/write from/to * @pid: PID of process to read/write from/to
* @lvec: iovec array specifying where to copy to/from locally * @iter: where to copy to/from locally
* @liovcnt: size of lvec array
* @rvec: iovec array specifying where to copy to/from in the other process * @rvec: iovec array specifying where to copy to/from in the other process
* @riovcnt: size of rvec array * @riovcnt: size of rvec array
* @flags: currently unused * @flags: currently unused