aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2014-02-05 13:25:32 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2014-04-01 23:19:29 -0400
commit4bafbec7bf60ed56ccbb36a96091bdbd162f075d (patch)
tree329693aee7863633fec5a96ea12421d9b284b002 /mm
parent9acc1a0f9af244826de0eea2c38b78410eb0df6d (diff)
process_vm_access: tidy up a bit
saner variable names, update linuxdoc comments, etc. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'mm')
-rw-r--r--mm/process_vm_access.c59
1 files changed, 19 insertions, 40 deletions
diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
index 15e4c2f312e8..d6bd3fdd6925 100644
--- a/mm/process_vm_access.c
+++ b/mm/process_vm_access.c
@@ -23,20 +23,11 @@
23 23
24/** 24/**
25 * process_vm_rw_pages - read/write pages from task specified 25 * process_vm_rw_pages - read/write pages from task specified
26 * @task: task to read/write from 26 * @pages: array of pointers to pages we want to copy
27 * @mm: mm for task
28 * @process_pages: struct pages area that can store at least
29 * nr_pages_to_copy struct page pointers
30 * @pa: address of page in task to start copying from/to
31 * @start_offset: offset in page to start copying from/to 27 * @start_offset: offset in page to start copying from/to
32 * @len: number of bytes to copy 28 * @len: number of bytes to copy
33 * @lvec: iovec array specifying where to copy to/from 29 * @iter: where to copy to/from locally
34 * @lvec_cnt: number of elements in iovec array
35 * @lvec_current: index in iovec array we are up to
36 * @lvec_offset: offset in bytes from current iovec iov_base we are up to
37 * @vm_write: 0 means copy from, 1 means copy to 30 * @vm_write: 0 means copy from, 1 means copy to
38 * @nr_pages_to_copy: number of pages to copy
39 * @bytes_copied: returns number of bytes successfully copied
40 * Returns 0 on success, error code otherwise 31 * Returns 0 on success, error code otherwise
41 */ 32 */
42static int process_vm_rw_pages(struct page **pages, 33static int process_vm_rw_pages(struct page **pages,
@@ -79,16 +70,12 @@ static int process_vm_rw_pages(struct page **pages,
79 * process_vm_rw_single_vec - read/write pages from task specified 70 * process_vm_rw_single_vec - read/write pages from task specified
80 * @addr: start memory address of target process 71 * @addr: start memory address of target process
81 * @len: size of area to copy to/from 72 * @len: size of area to copy to/from
82 * @lvec: iovec array specifying where to copy to/from locally 73 * @iter: where to copy to/from locally
83 * @lvec_cnt: number of elements in iovec array
84 * @lvec_current: index in iovec array we are up to
85 * @lvec_offset: offset in bytes from current iovec iov_base we are up to
86 * @process_pages: struct pages area that can store at least 74 * @process_pages: struct pages area that can store at least
87 * nr_pages_to_copy struct page pointers 75 * nr_pages_to_copy struct page pointers
88 * @mm: mm for task 76 * @mm: mm for task
89 * @task: task to read/write from 77 * @task: task to read/write from
90 * @vm_write: 0 means copy from, 1 means copy to 78 * @vm_write: 0 means copy from, 1 means copy to
91 * @bytes_copied: returns number of bytes successfully copied
92 * Returns 0 on success or on failure error code 79 * Returns 0 on success or on failure error code
93 */ 80 */
94static int process_vm_rw_single_vec(unsigned long addr, 81static int process_vm_rw_single_vec(unsigned long addr,
@@ -103,7 +90,6 @@ static int process_vm_rw_single_vec(unsigned long addr,
103 unsigned long start_offset = addr - pa; 90 unsigned long start_offset = addr - pa;
104 unsigned long nr_pages; 91 unsigned long nr_pages;
105 ssize_t rc = 0; 92 ssize_t rc = 0;
106 unsigned long nr_pages_copied = 0;
107 unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES 93 unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES
108 / sizeof(struct pages *); 94 / sizeof(struct pages *);
109 95
@@ -112,38 +98,32 @@ static int process_vm_rw_single_vec(unsigned long addr,
112 return 0; 98 return 0;
113 nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1; 99 nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1;
114 100
115 while ((nr_pages_copied < nr_pages) && iov_iter_count(iter)) { 101 while (!rc && nr_pages && iov_iter_count(iter)) {
116 int nr_pages_to_copy; 102 int pages = min(nr_pages, max_pages_per_loop);
117 int pages_pinned; 103 size_t bytes;
118 size_t n;
119 nr_pages_to_copy = min(nr_pages - nr_pages_copied,
120 max_pages_per_loop);
121 104
122 /* Get the pages we're interested in */ 105 /* Get the pages we're interested in */
123 down_read(&mm->mmap_sem); 106 down_read(&mm->mmap_sem);
124 pages_pinned = get_user_pages(task, mm, pa, 107 pages = get_user_pages(task, mm, pa, pages,
125 nr_pages_to_copy, 108 vm_write, 0, process_pages, NULL);
126 vm_write, 0, process_pages, NULL);
127 up_read(&mm->mmap_sem); 109 up_read(&mm->mmap_sem);
128 110
129 if (pages_pinned <= 0) 111 if (pages <= 0)
130 return -EFAULT; 112 return -EFAULT;
131 113
132 n = pages_pinned * PAGE_SIZE - start_offset; 114 bytes = pages * PAGE_SIZE - start_offset;
133 if (n > len) 115 if (bytes > len)
134 n = len; 116 bytes = len;
135 117
136 rc = process_vm_rw_pages(process_pages, 118 rc = process_vm_rw_pages(process_pages,
137 start_offset, n, iter, 119 start_offset, bytes, iter,
138 vm_write); 120 vm_write);
139 len -= n; 121 len -= bytes;
140 start_offset = 0; 122 start_offset = 0;
141 nr_pages_copied += pages_pinned; 123 nr_pages -= pages;
142 pa += pages_pinned * PAGE_SIZE; 124 pa += pages * PAGE_SIZE;
143 while (pages_pinned) 125 while (pages)
144 put_page(process_pages[--pages_pinned]); 126 put_page(process_pages[--pages]);
145 if (rc < 0)
146 break;
147 } 127 }
148 128
149 return rc; 129 return rc;
@@ -156,8 +136,7 @@ static int process_vm_rw_single_vec(unsigned long addr,
156/** 136/**
157 * process_vm_rw_core - core of reading/writing pages from task specified 137 * process_vm_rw_core - core of reading/writing pages from task specified
158 * @pid: PID of process to read/write from/to 138 * @pid: PID of process to read/write from/to
159 * @lvec: iovec array specifying where to copy to/from locally 139 * @iter: where to copy to/from locally
160 * @liovcnt: size of lvec array
161 * @rvec: iovec array specifying where to copy to/from in the other process 140 * @rvec: iovec array specifying where to copy to/from in the other process
162 * @riovcnt: size of rvec array 141 * @riovcnt: size of rvec array
163 * @flags: currently unused 142 * @flags: currently unused