Commit 9f78bdfa authored by Al Viro's avatar Al Viro

process_vm_access: switch to iov_iter

instead of keeping its pieces in separate variables and passing
pointers to all of them...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 1291afc1
...@@ -45,9 +45,7 @@ static int process_vm_rw_pages(struct task_struct *task, ...@@ -45,9 +45,7 @@ static int process_vm_rw_pages(struct task_struct *task,
unsigned long pa, unsigned long pa,
unsigned long start_offset, unsigned long start_offset,
unsigned long len, unsigned long len,
const struct iovec **iovp, struct iov_iter *iter,
unsigned long *left,
size_t *lvec_offset,
int vm_write, int vm_write,
unsigned int nr_pages_to_copy, unsigned int nr_pages_to_copy,
ssize_t *bytes_copied) ssize_t *bytes_copied)
...@@ -59,7 +57,7 @@ static int process_vm_rw_pages(struct task_struct *task, ...@@ -59,7 +57,7 @@ static int process_vm_rw_pages(struct task_struct *task,
int ret; int ret;
ssize_t bytes_to_copy; ssize_t bytes_to_copy;
ssize_t rc = 0; ssize_t rc = 0;
const struct iovec *iov = *iovp; const struct iovec *iov = iter->iov;
*bytes_copied = 0; *bytes_copied = 0;
...@@ -77,14 +75,14 @@ static int process_vm_rw_pages(struct task_struct *task, ...@@ -77,14 +75,14 @@ static int process_vm_rw_pages(struct task_struct *task,
/* Do the copy for each page */ /* Do the copy for each page */
for (pgs_copied = 0; for (pgs_copied = 0;
(pgs_copied < nr_pages_to_copy) && *left; (pgs_copied < nr_pages_to_copy) && iter->nr_segs;
pgs_copied++) { pgs_copied++) {
/* Make sure we have a non zero length iovec */ /* Make sure we have a non zero length iovec */
while (*left && iov->iov_len == 0) { while (iter->nr_segs && iov->iov_len == 0) {
iov++; iov++;
(*left)--; iter->nr_segs--;
} }
if (!*left) if (!iter->nr_segs)
break; break;
/* /*
...@@ -96,18 +94,18 @@ static int process_vm_rw_pages(struct task_struct *task, ...@@ -96,18 +94,18 @@ static int process_vm_rw_pages(struct task_struct *task,
len - *bytes_copied); len - *bytes_copied);
bytes_to_copy = min_t(ssize_t, bytes_to_copy, bytes_to_copy = min_t(ssize_t, bytes_to_copy,
iov->iov_len iov->iov_len
- *lvec_offset); - iter->iov_offset);
target_kaddr = kmap(process_pages[pgs_copied]) + start_offset; target_kaddr = kmap(process_pages[pgs_copied]) + start_offset;
if (vm_write) if (vm_write)
ret = copy_from_user(target_kaddr, ret = copy_from_user(target_kaddr,
iov->iov_base iov->iov_base
+ *lvec_offset, + iter->iov_offset,
bytes_to_copy); bytes_to_copy);
else else
ret = copy_to_user(iov->iov_base ret = copy_to_user(iov->iov_base
+ *lvec_offset, + iter->iov_offset,
target_kaddr, bytes_to_copy); target_kaddr, bytes_to_copy);
kunmap(process_pages[pgs_copied]); kunmap(process_pages[pgs_copied]);
if (ret) { if (ret) {
...@@ -117,15 +115,15 @@ static int process_vm_rw_pages(struct task_struct *task, ...@@ -117,15 +115,15 @@ static int process_vm_rw_pages(struct task_struct *task,
goto end; goto end;
} }
*bytes_copied += bytes_to_copy; *bytes_copied += bytes_to_copy;
*lvec_offset += bytes_to_copy; iter->iov_offset += bytes_to_copy;
if (*lvec_offset == iov->iov_len) { if (iter->iov_offset == iov->iov_len) {
/* /*
* Need to copy remaining part of page into the * Need to copy remaining part of page into the
* next iovec if there are any bytes left in page * next iovec if there are any bytes left in page
*/ */
(*left)--; iter->nr_segs--;
iov++; iov++;
*lvec_offset = 0; iter->iov_offset = 0;
start_offset = (start_offset + bytes_to_copy) start_offset = (start_offset + bytes_to_copy)
% PAGE_SIZE; % PAGE_SIZE;
if (start_offset) if (start_offset)
...@@ -147,7 +145,7 @@ static int process_vm_rw_pages(struct task_struct *task, ...@@ -147,7 +145,7 @@ static int process_vm_rw_pages(struct task_struct *task,
put_page(process_pages[j]); put_page(process_pages[j]);
} }
*iovp = iov; iter->iov = iov;
return rc; return rc;
} }
...@@ -172,9 +170,7 @@ static int process_vm_rw_pages(struct task_struct *task, ...@@ -172,9 +170,7 @@ static int process_vm_rw_pages(struct task_struct *task,
*/ */
static int process_vm_rw_single_vec(unsigned long addr, static int process_vm_rw_single_vec(unsigned long addr,
unsigned long len, unsigned long len,
const struct iovec **iovp, struct iov_iter *iter,
unsigned long *left,
size_t *lvec_offset,
struct page **process_pages, struct page **process_pages,
struct mm_struct *mm, struct mm_struct *mm,
struct task_struct *task, struct task_struct *task,
...@@ -198,14 +194,12 @@ static int process_vm_rw_single_vec(unsigned long addr, ...@@ -198,14 +194,12 @@ 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) && *left) { while ((nr_pages_copied < nr_pages) && iter->nr_segs) {
nr_pages_to_copy = min(nr_pages - nr_pages_copied, nr_pages_to_copy = min(nr_pages - nr_pages_copied,
max_pages_per_loop); max_pages_per_loop);
rc = process_vm_rw_pages(task, mm, process_pages, pa, rc = process_vm_rw_pages(task, mm, process_pages, pa,
start_offset, len, start_offset, len, iter,
iovp, left,
lvec_offset,
vm_write, nr_pages_to_copy, vm_write, nr_pages_to_copy,
&bytes_copied_loop); &bytes_copied_loop);
start_offset = 0; start_offset = 0;
...@@ -240,8 +234,7 @@ static int process_vm_rw_single_vec(unsigned long addr, ...@@ -240,8 +234,7 @@ static int process_vm_rw_single_vec(unsigned long addr,
* return less bytes than expected if an error occurs during the copying * return less bytes than expected if an error occurs during the copying
* process. * process.
*/ */
static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec, static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
unsigned long liovcnt,
const struct iovec *rvec, const struct iovec *rvec,
unsigned long riovcnt, unsigned long riovcnt,
unsigned long flags, int vm_write) unsigned long flags, int vm_write)
...@@ -256,8 +249,6 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec, ...@@ -256,8 +249,6 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
ssize_t bytes_copied = 0; ssize_t bytes_copied = 0;
unsigned long nr_pages = 0; unsigned long nr_pages = 0;
unsigned long nr_pages_iov; unsigned long nr_pages_iov;
unsigned long left = liovcnt;
size_t iov_l_curr_offset = 0;
ssize_t iov_len; ssize_t iov_len;
/* /*
...@@ -312,11 +303,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec, ...@@ -312,11 +303,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
goto put_task_struct; goto put_task_struct;
} }
for (i = 0; i < riovcnt && left; i++) { for (i = 0; i < riovcnt && iter->nr_segs; i++) {
rc = process_vm_rw_single_vec( rc = process_vm_rw_single_vec(
(unsigned long)rvec[i].iov_base, rvec[i].iov_len, (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
&lvec, &left, &iov_l_curr_offset, iter, process_pages, mm, task, vm_write,
process_pages, mm, task, vm_write, &bytes_copied_loop); &bytes_copied_loop);
bytes_copied += bytes_copied_loop; bytes_copied += bytes_copied_loop;
if (rc != 0) { if (rc != 0) {
/* If we have managed to copy any data at all then /* If we have managed to copy any data at all then
...@@ -365,6 +356,7 @@ static ssize_t process_vm_rw(pid_t pid, ...@@ -365,6 +356,7 @@ static ssize_t process_vm_rw(pid_t pid,
struct iovec iovstack_r[UIO_FASTIOV]; struct iovec iovstack_r[UIO_FASTIOV];
struct iovec *iov_l = iovstack_l; struct iovec *iov_l = iovstack_l;
struct iovec *iov_r = iovstack_r; struct iovec *iov_r = iovstack_r;
struct iov_iter iter;
ssize_t rc; ssize_t rc;
if (flags != 0) if (flags != 0)
...@@ -380,13 +372,14 @@ static ssize_t process_vm_rw(pid_t pid, ...@@ -380,13 +372,14 @@ static ssize_t process_vm_rw(pid_t pid,
if (rc <= 0) if (rc <= 0)
goto free_iovecs; goto free_iovecs;
iov_iter_init(&iter, iov_l, liovcnt, rc, 0);
rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV, rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV,
iovstack_r, &iov_r); iovstack_r, &iov_r);
if (rc <= 0) if (rc <= 0)
goto free_iovecs; goto free_iovecs;
rc = process_vm_rw_core(pid, iov_l, liovcnt, iov_r, riovcnt, flags, rc = process_vm_rw_core(pid, &iter, iov_r, riovcnt, flags, vm_write);
vm_write);
free_iovecs: free_iovecs:
if (iov_r != iovstack_r) if (iov_r != iovstack_r)
...@@ -426,6 +419,7 @@ compat_process_vm_rw(compat_pid_t pid, ...@@ -426,6 +419,7 @@ compat_process_vm_rw(compat_pid_t pid,
struct iovec iovstack_r[UIO_FASTIOV]; struct iovec iovstack_r[UIO_FASTIOV];
struct iovec *iov_l = iovstack_l; struct iovec *iov_l = iovstack_l;
struct iovec *iov_r = iovstack_r; struct iovec *iov_r = iovstack_r;
struct iov_iter iter;
ssize_t rc = -EFAULT; ssize_t rc = -EFAULT;
if (flags != 0) if (flags != 0)
...@@ -441,14 +435,14 @@ compat_process_vm_rw(compat_pid_t pid, ...@@ -441,14 +435,14 @@ compat_process_vm_rw(compat_pid_t pid,
&iov_l); &iov_l);
if (rc <= 0) if (rc <= 0)
goto free_iovecs; goto free_iovecs;
iov_iter_init(&iter, iov_l, liovcnt, rc, 0);
rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt,
UIO_FASTIOV, iovstack_r, UIO_FASTIOV, iovstack_r,
&iov_r); &iov_r);
if (rc <= 0) if (rc <= 0)
goto free_iovecs; goto free_iovecs;
rc = process_vm_rw_core(pid, iov_l, liovcnt, iov_r, riovcnt, flags, rc = process_vm_rw_core(pid, &iter, iov_r, riovcnt, flags, vm_write);
vm_write);
free_iovecs: free_iovecs:
if (iov_r != iovstack_r) if (iov_r != iovstack_r)
......
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