aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 13:30:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 13:30:18 -0400
commit16b9057804c02e2d351e9c8f606e909b43cbd9e7 (patch)
treea3ac6e1d9d57a8abf4267e5ead3f2de1309335eb /mm
parent5c02c392cd2320e8d612376d6b72b6548a680923 (diff)
parentc2338f2dc7c1e9f6202f370c64ffd7f44f3d4b51 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs updates from Al Viro: "This the bunch that sat in -next + lock_parent() fix. This is the minimal set; there's more pending stuff. In particular, I really hope to get acct.c fixes merged this cycle - we need that to deal sanely with delayed-mntput stuff. In the next pile, hopefully - that series is fairly short and localized (kernel/acct.c, fs/super.c and fs/namespace.c). In this pile: more iov_iter work. Most of prereqs for ->splice_write with sane locking order are there and Kent's dio rewrite would also fit nicely on top of this pile" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (70 commits) lock_parent: don't step on stale ->d_parent of all-but-freed one kill generic_file_splice_write() ceph: switch to iter_file_splice_write() shmem: switch to iter_file_splice_write() nfs: switch to iter_splice_write_file() fs/splice.c: remove unneeded exports ocfs2: switch to iter_file_splice_write() ->splice_write() via ->write_iter() bio_vec-backed iov_iter optimize copy_page_{to,from}_iter() bury generic_file_aio_{read,write} lustre: get rid of messing with iovecs ceph: switch to ->write_iter() ceph_sync_direct_write: stop poking into iov_iter guts ceph_sync_read: stop poking into iov_iter guts new helper: copy_page_from_iter() fuse: switch to ->write_iter() btrfs: switch to ->write_iter() ocfs2: switch to ->write_iter() xfs: switch to ->write_iter() ...
Diffstat (limited to 'mm')
-rw-r--r--mm/filemap.c158
-rw-r--r--mm/iov_iter.c595
-rw-r--r--mm/page_io.c21
-rw-r--r--mm/process_vm_access.c10
-rw-r--r--mm/shmem.c26
-rw-r--r--mm/vmscan.c2
6 files changed, 626 insertions, 186 deletions
diff --git a/mm/filemap.c b/mm/filemap.c
index 7fadf1c62838..dafb06f70a09 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1665,96 +1665,42 @@ out:
1665 return written ? written : error; 1665 return written ? written : error;
1666} 1666}
1667 1667
1668/*
1669 * Performs necessary checks before doing a write
1670 * @iov: io vector request
1671 * @nr_segs: number of segments in the iovec
1672 * @count: number of bytes to write
1673 * @access_flags: type of access: %VERIFY_READ or %VERIFY_WRITE
1674 *
1675 * Adjust number of segments and amount of bytes to write (nr_segs should be
1676 * properly initialized first). Returns appropriate error code that caller
1677 * should return or zero in case that write should be allowed.
1678 */
1679int generic_segment_checks(const struct iovec *iov,
1680 unsigned long *nr_segs, size_t *count, int access_flags)
1681{
1682 unsigned long seg;
1683 size_t cnt = 0;
1684 for (seg = 0; seg < *nr_segs; seg++) {
1685 const struct iovec *iv = &iov[seg];
1686
1687 /*
1688 * If any segment has a negative length, or the cumulative
1689 * length ever wraps negative then return -EINVAL.
1690 */
1691 cnt += iv->iov_len;
1692 if (unlikely((ssize_t)(cnt|iv->iov_len) < 0))
1693 return -EINVAL;
1694 if (access_ok(access_flags, iv->iov_base, iv->iov_len))
1695 continue;
1696 if (seg == 0)
1697 return -EFAULT;
1698 *nr_segs = seg;
1699 cnt -= iv->iov_len; /* This segment is no good */
1700 break;
1701 }
1702 *count = cnt;
1703 return 0;
1704}
1705EXPORT_SYMBOL(generic_segment_checks);
1706
1707/** 1668/**
1708 * generic_file_aio_read - generic filesystem read routine 1669 * generic_file_read_iter - generic filesystem read routine
1709 * @iocb: kernel I/O control block 1670 * @iocb: kernel I/O control block
1710 * @iov: io vector request 1671 * @iter: destination for the data read
1711 * @nr_segs: number of segments in the iovec
1712 * @pos: current file position
1713 * 1672 *
1714 * This is the "read()" routine for all filesystems 1673 * This is the "read_iter()" routine for all filesystems
1715 * that can use the page cache directly. 1674 * that can use the page cache directly.
1716 */ 1675 */
1717ssize_t 1676ssize_t
1718generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov, 1677generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
1719 unsigned long nr_segs, loff_t pos)
1720{ 1678{
1721 struct file *filp = iocb->ki_filp; 1679 struct file *file = iocb->ki_filp;
1722 ssize_t retval; 1680 ssize_t retval = 0;
1723 size_t count;
1724 loff_t *ppos = &iocb->ki_pos; 1681 loff_t *ppos = &iocb->ki_pos;
1725 struct iov_iter i; 1682 loff_t pos = *ppos;
1726
1727 count = 0;
1728 retval = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE);
1729 if (retval)
1730 return retval;
1731 iov_iter_init(&i, iov, nr_segs, count, 0);
1732 1683
1733 /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ 1684 /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
1734 if (filp->f_flags & O_DIRECT) { 1685 if (file->f_flags & O_DIRECT) {
1686 struct address_space *mapping = file->f_mapping;
1687 struct inode *inode = mapping->host;
1688 size_t count = iov_iter_count(iter);
1735 loff_t size; 1689 loff_t size;
1736 struct address_space *mapping;
1737 struct inode *inode;
1738 1690
1739 mapping = filp->f_mapping;
1740 inode = mapping->host;
1741 if (!count) 1691 if (!count)
1742 goto out; /* skip atime */ 1692 goto out; /* skip atime */
1743 size = i_size_read(inode); 1693 size = i_size_read(inode);
1744 retval = filemap_write_and_wait_range(mapping, pos, 1694 retval = filemap_write_and_wait_range(mapping, pos,
1745 pos + iov_length(iov, nr_segs) - 1); 1695 pos + count - 1);
1746 if (!retval) { 1696 if (!retval) {
1747 retval = mapping->a_ops->direct_IO(READ, iocb, 1697 struct iov_iter data = *iter;
1748 iov, pos, nr_segs); 1698 retval = mapping->a_ops->direct_IO(READ, iocb, &data, pos);
1749 } 1699 }
1700
1750 if (retval > 0) { 1701 if (retval > 0) {
1751 *ppos = pos + retval; 1702 *ppos = pos + retval;
1752 count -= retval; 1703 iov_iter_advance(iter, retval);
1753 /*
1754 * If we did a short DIO read we need to skip the
1755 * section of the iov that we've already read data into.
1756 */
1757 iov_iter_advance(&i, retval);
1758 } 1704 }
1759 1705
1760 /* 1706 /*
@@ -1765,17 +1711,17 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
1765 * and return. Otherwise fallthrough to buffered io for 1711 * and return. Otherwise fallthrough to buffered io for
1766 * the rest of the read. 1712 * the rest of the read.
1767 */ 1713 */
1768 if (retval < 0 || !count || *ppos >= size) { 1714 if (retval < 0 || !iov_iter_count(iter) || *ppos >= size) {
1769 file_accessed(filp); 1715 file_accessed(file);
1770 goto out; 1716 goto out;
1771 } 1717 }
1772 } 1718 }
1773 1719
1774 retval = do_generic_file_read(filp, ppos, &i, retval); 1720 retval = do_generic_file_read(file, ppos, iter, retval);
1775out: 1721out:
1776 return retval; 1722 return retval;
1777} 1723}
1778EXPORT_SYMBOL(generic_file_aio_read); 1724EXPORT_SYMBOL(generic_file_read_iter);
1779 1725
1780#ifdef CONFIG_MMU 1726#ifdef CONFIG_MMU
1781/** 1727/**
@@ -2386,9 +2332,7 @@ int pagecache_write_end(struct file *file, struct address_space *mapping,
2386EXPORT_SYMBOL(pagecache_write_end); 2332EXPORT_SYMBOL(pagecache_write_end);
2387 2333
2388ssize_t 2334ssize_t
2389generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov, 2335generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos)
2390 unsigned long *nr_segs, loff_t pos,
2391 size_t count, size_t ocount)
2392{ 2336{
2393 struct file *file = iocb->ki_filp; 2337 struct file *file = iocb->ki_filp;
2394 struct address_space *mapping = file->f_mapping; 2338 struct address_space *mapping = file->f_mapping;
@@ -2396,11 +2340,9 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
2396 ssize_t written; 2340 ssize_t written;
2397 size_t write_len; 2341 size_t write_len;
2398 pgoff_t end; 2342 pgoff_t end;
2343 struct iov_iter data;
2399 2344
2400 if (count != ocount) 2345 write_len = iov_iter_count(from);
2401 *nr_segs = iov_shorten((struct iovec *)iov, *nr_segs, count);
2402
2403 write_len = iov_length(iov, *nr_segs);
2404 end = (pos + write_len - 1) >> PAGE_CACHE_SHIFT; 2346 end = (pos + write_len - 1) >> PAGE_CACHE_SHIFT;
2405 2347
2406 written = filemap_write_and_wait_range(mapping, pos, pos + write_len - 1); 2348 written = filemap_write_and_wait_range(mapping, pos, pos + write_len - 1);
@@ -2427,7 +2369,8 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
2427 } 2369 }
2428 } 2370 }
2429 2371
2430 written = mapping->a_ops->direct_IO(WRITE, iocb, iov, pos, *nr_segs); 2372 data = *from;
2373 written = mapping->a_ops->direct_IO(WRITE, iocb, &data, pos);
2431 2374
2432 /* 2375 /*
2433 * Finally, try again to invalidate clean pages which might have been 2376 * Finally, try again to invalidate clean pages which might have been
@@ -2444,6 +2387,7 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
2444 2387
2445 if (written > 0) { 2388 if (written > 0) {
2446 pos += written; 2389 pos += written;
2390 iov_iter_advance(from, written);
2447 if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { 2391 if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) {
2448 i_size_write(inode, pos); 2392 i_size_write(inode, pos);
2449 mark_inode_dirty(inode); 2393 mark_inode_dirty(inode);
@@ -2568,10 +2512,9 @@ again:
2568EXPORT_SYMBOL(generic_perform_write); 2512EXPORT_SYMBOL(generic_perform_write);
2569 2513
2570/** 2514/**
2571 * __generic_file_aio_write - write data to a file 2515 * __generic_file_write_iter - write data to a file
2572 * @iocb: IO state structure (file, offset, etc.) 2516 * @iocb: IO state structure (file, offset, etc.)
2573 * @iov: vector with data to write 2517 * @from: iov_iter with data to write
2574 * @nr_segs: number of segments in the vector
2575 * 2518 *
2576 * This function does all the work needed for actually writing data to a 2519 * This function does all the work needed for actually writing data to a
2577 * file. It does all basic checks, removes SUID from the file, updates 2520 * file. It does all basic checks, removes SUID from the file, updates
@@ -2585,26 +2528,16 @@ EXPORT_SYMBOL(generic_perform_write);
2585 * A caller has to handle it. This is mainly due to the fact that we want to 2528 * A caller has to handle it. This is mainly due to the fact that we want to
2586 * avoid syncing under i_mutex. 2529 * avoid syncing under i_mutex.
2587 */ 2530 */
2588ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 2531ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
2589 unsigned long nr_segs)
2590{ 2532{
2591 struct file *file = iocb->ki_filp; 2533 struct file *file = iocb->ki_filp;
2592 struct address_space * mapping = file->f_mapping; 2534 struct address_space * mapping = file->f_mapping;
2593 size_t ocount; /* original count */
2594 size_t count; /* after file limit checks */
2595 struct inode *inode = mapping->host; 2535 struct inode *inode = mapping->host;
2596 loff_t pos = iocb->ki_pos; 2536 loff_t pos = iocb->ki_pos;
2597 ssize_t written = 0; 2537 ssize_t written = 0;
2598 ssize_t err; 2538 ssize_t err;
2599 ssize_t status; 2539 ssize_t status;
2600 struct iov_iter from; 2540 size_t count = iov_iter_count(from);
2601
2602 ocount = 0;
2603 err = generic_segment_checks(iov, &nr_segs, &ocount, VERIFY_READ);
2604 if (err)
2605 return err;
2606
2607 count = ocount;
2608 2541
2609 /* We can write back this queue in page reclaim */ 2542 /* We can write back this queue in page reclaim */
2610 current->backing_dev_info = mapping->backing_dev_info; 2543 current->backing_dev_info = mapping->backing_dev_info;
@@ -2615,6 +2548,8 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2615 if (count == 0) 2548 if (count == 0)
2616 goto out; 2549 goto out;
2617 2550
2551 iov_iter_truncate(from, count);
2552
2618 err = file_remove_suid(file); 2553 err = file_remove_suid(file);
2619 if (err) 2554 if (err)
2620 goto out; 2555 goto out;
@@ -2623,17 +2558,13 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2623 if (err) 2558 if (err)
2624 goto out; 2559 goto out;
2625 2560
2626 iov_iter_init(&from, iov, nr_segs, count, 0);
2627
2628 /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ 2561 /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
2629 if (unlikely(file->f_flags & O_DIRECT)) { 2562 if (unlikely(file->f_flags & O_DIRECT)) {
2630 loff_t endbyte; 2563 loff_t endbyte;
2631 2564
2632 written = generic_file_direct_write(iocb, iov, &from.nr_segs, pos, 2565 written = generic_file_direct_write(iocb, from, pos);
2633 count, ocount);
2634 if (written < 0 || written == count) 2566 if (written < 0 || written == count)
2635 goto out; 2567 goto out;
2636 iov_iter_advance(&from, written);
2637 2568
2638 /* 2569 /*
2639 * direct-io write to a hole: fall through to buffered I/O 2570 * direct-io write to a hole: fall through to buffered I/O
@@ -2642,7 +2573,7 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2642 pos += written; 2573 pos += written;
2643 count -= written; 2574 count -= written;
2644 2575
2645 status = generic_perform_write(file, &from, pos); 2576 status = generic_perform_write(file, from, pos);
2646 /* 2577 /*
2647 * If generic_perform_write() returned a synchronous error 2578 * If generic_perform_write() returned a synchronous error
2648 * then we want to return the number of bytes which were 2579 * then we want to return the number of bytes which were
@@ -2674,7 +2605,7 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2674 */ 2605 */
2675 } 2606 }
2676 } else { 2607 } else {
2677 written = generic_perform_write(file, &from, pos); 2608 written = generic_perform_write(file, from, pos);
2678 if (likely(written >= 0)) 2609 if (likely(written >= 0))
2679 iocb->ki_pos = pos + written; 2610 iocb->ki_pos = pos + written;
2680 } 2611 }
@@ -2682,30 +2613,25 @@ out:
2682 current->backing_dev_info = NULL; 2613 current->backing_dev_info = NULL;
2683 return written ? written : err; 2614 return written ? written : err;
2684} 2615}
2685EXPORT_SYMBOL(__generic_file_aio_write); 2616EXPORT_SYMBOL(__generic_file_write_iter);
2686 2617
2687/** 2618/**
2688 * generic_file_aio_write - write data to a file 2619 * generic_file_write_iter - write data to a file
2689 * @iocb: IO state structure 2620 * @iocb: IO state structure
2690 * @iov: vector with data to write 2621 * @from: iov_iter with data to write
2691 * @nr_segs: number of segments in the vector
2692 * @pos: position in file where to write
2693 * 2622 *
2694 * This is a wrapper around __generic_file_aio_write() to be used by most 2623 * This is a wrapper around __generic_file_write_iter() to be used by most
2695 * filesystems. It takes care of syncing the file in case of O_SYNC file 2624 * filesystems. It takes care of syncing the file in case of O_SYNC file
2696 * and acquires i_mutex as needed. 2625 * and acquires i_mutex as needed.
2697 */ 2626 */
2698ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 2627ssize_t generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
2699 unsigned long nr_segs, loff_t pos)
2700{ 2628{
2701 struct file *file = iocb->ki_filp; 2629 struct file *file = iocb->ki_filp;
2702 struct inode *inode = file->f_mapping->host; 2630 struct inode *inode = file->f_mapping->host;
2703 ssize_t ret; 2631 ssize_t ret;
2704 2632
2705 BUG_ON(iocb->ki_pos != pos);
2706
2707 mutex_lock(&inode->i_mutex); 2633 mutex_lock(&inode->i_mutex);
2708 ret = __generic_file_aio_write(iocb, iov, nr_segs); 2634 ret = __generic_file_write_iter(iocb, from);
2709 mutex_unlock(&inode->i_mutex); 2635 mutex_unlock(&inode->i_mutex);
2710 2636
2711 if (ret > 0) { 2637 if (ret > 0) {
@@ -2717,7 +2643,7 @@ ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2717 } 2643 }
2718 return ret; 2644 return ret;
2719} 2645}
2720EXPORT_SYMBOL(generic_file_aio_write); 2646EXPORT_SYMBOL(generic_file_write_iter);
2721 2647
2722/** 2648/**
2723 * try_to_release_page() - release old fs-specific metadata on a page 2649 * try_to_release_page() - release old fs-specific metadata on a page
diff --git a/mm/iov_iter.c b/mm/iov_iter.c
index 10e46cd721de..7b5dbd1517b5 100644
--- a/mm/iov_iter.c
+++ b/mm/iov_iter.c
@@ -1,8 +1,10 @@
1#include <linux/export.h> 1#include <linux/export.h>
2#include <linux/uio.h> 2#include <linux/uio.h>
3#include <linux/pagemap.h> 3#include <linux/pagemap.h>
4#include <linux/slab.h>
5#include <linux/vmalloc.h>
4 6
5size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, 7static size_t copy_page_to_iter_iovec(struct page *page, size_t offset, size_t bytes,
6 struct iov_iter *i) 8 struct iov_iter *i)
7{ 9{
8 size_t skip, copy, left, wanted; 10 size_t skip, copy, left, wanted;
@@ -72,13 +74,97 @@ size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes,
72 } 74 }
73 kunmap(page); 75 kunmap(page);
74done: 76done:
77 if (skip == iov->iov_len) {
78 iov++;
79 skip = 0;
80 }
81 i->count -= wanted - bytes;
82 i->nr_segs -= iov - i->iov;
83 i->iov = iov;
84 i->iov_offset = skip;
85 return wanted - bytes;
86}
87
88static size_t copy_page_from_iter_iovec(struct page *page, size_t offset, size_t bytes,
89 struct iov_iter *i)
90{
91 size_t skip, copy, left, wanted;
92 const struct iovec *iov;
93 char __user *buf;
94 void *kaddr, *to;
95
96 if (unlikely(bytes > i->count))
97 bytes = i->count;
98
99 if (unlikely(!bytes))
100 return 0;
101
102 wanted = bytes;
103 iov = i->iov;
104 skip = i->iov_offset;
105 buf = iov->iov_base + skip;
106 copy = min(bytes, iov->iov_len - skip);
107
108 if (!fault_in_pages_readable(buf, copy)) {
109 kaddr = kmap_atomic(page);
110 to = kaddr + offset;
111
112 /* first chunk, usually the only one */
113 left = __copy_from_user_inatomic(to, buf, copy);
114 copy -= left;
115 skip += copy;
116 to += copy;
117 bytes -= copy;
118
119 while (unlikely(!left && bytes)) {
120 iov++;
121 buf = iov->iov_base;
122 copy = min(bytes, iov->iov_len);
123 left = __copy_from_user_inatomic(to, buf, copy);
124 copy -= left;
125 skip = copy;
126 to += copy;
127 bytes -= copy;
128 }
129 if (likely(!bytes)) {
130 kunmap_atomic(kaddr);
131 goto done;
132 }
133 offset = to - kaddr;
134 buf += copy;
135 kunmap_atomic(kaddr);
136 copy = min(bytes, iov->iov_len - skip);
137 }
138 /* Too bad - revert to non-atomic kmap */
139 kaddr = kmap(page);
140 to = kaddr + offset;
141 left = __copy_from_user(to, buf, copy);
142 copy -= left;
143 skip += copy;
144 to += copy;
145 bytes -= copy;
146 while (unlikely(!left && bytes)) {
147 iov++;
148 buf = iov->iov_base;
149 copy = min(bytes, iov->iov_len);
150 left = __copy_from_user(to, buf, copy);
151 copy -= left;
152 skip = copy;
153 to += copy;
154 bytes -= copy;
155 }
156 kunmap(page);
157done:
158 if (skip == iov->iov_len) {
159 iov++;
160 skip = 0;
161 }
75 i->count -= wanted - bytes; 162 i->count -= wanted - bytes;
76 i->nr_segs -= iov - i->iov; 163 i->nr_segs -= iov - i->iov;
77 i->iov = iov; 164 i->iov = iov;
78 i->iov_offset = skip; 165 i->iov_offset = skip;
79 return wanted - bytes; 166 return wanted - bytes;
80} 167}
81EXPORT_SYMBOL(copy_page_to_iter);
82 168
83static size_t __iovec_copy_from_user_inatomic(char *vaddr, 169static size_t __iovec_copy_from_user_inatomic(char *vaddr,
84 const struct iovec *iov, size_t base, size_t bytes) 170 const struct iovec *iov, size_t base, size_t bytes)
@@ -107,7 +193,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
107 * were successfully copied. If a fault is encountered then return the number of 193 * were successfully copied. If a fault is encountered then return the number of
108 * bytes which were copied. 194 * bytes which were copied.
109 */ 195 */
110size_t iov_iter_copy_from_user_atomic(struct page *page, 196static size_t copy_from_user_atomic_iovec(struct page *page,
111 struct iov_iter *i, unsigned long offset, size_t bytes) 197 struct iov_iter *i, unsigned long offset, size_t bytes)
112{ 198{
113 char *kaddr; 199 char *kaddr;
@@ -127,36 +213,8 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
127 213
128 return copied; 214 return copied;
129} 215}
130EXPORT_SYMBOL(iov_iter_copy_from_user_atomic);
131
132/*
133 * This has the same sideeffects and return value as
134 * iov_iter_copy_from_user_atomic().
135 * The difference is that it attempts to resolve faults.
136 * Page must not be locked.
137 */
138size_t iov_iter_copy_from_user(struct page *page,
139 struct iov_iter *i, unsigned long offset, size_t bytes)
140{
141 char *kaddr;
142 size_t copied;
143
144 kaddr = kmap(page);
145 if (likely(i->nr_segs == 1)) {
146 int left;
147 char __user *buf = i->iov->iov_base + i->iov_offset;
148 left = __copy_from_user(kaddr + offset, buf, bytes);
149 copied = bytes - left;
150 } else {
151 copied = __iovec_copy_from_user_inatomic(kaddr + offset,
152 i->iov, i->iov_offset, bytes);
153 }
154 kunmap(page);
155 return copied;
156}
157EXPORT_SYMBOL(iov_iter_copy_from_user);
158 216
159void iov_iter_advance(struct iov_iter *i, size_t bytes) 217static void advance_iovec(struct iov_iter *i, size_t bytes)
160{ 218{
161 BUG_ON(i->count < bytes); 219 BUG_ON(i->count < bytes);
162 220
@@ -191,7 +249,6 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
191 i->nr_segs = nr_segs; 249 i->nr_segs = nr_segs;
192 } 250 }
193} 251}
194EXPORT_SYMBOL(iov_iter_advance);
195 252
196/* 253/*
197 * Fault in the first iovec of the given iov_iter, to a maximum length 254 * Fault in the first iovec of the given iov_iter, to a maximum length
@@ -204,21 +261,483 @@ EXPORT_SYMBOL(iov_iter_advance);
204 */ 261 */
205int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes) 262int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes)
206{ 263{
207 char __user *buf = i->iov->iov_base + i->iov_offset; 264 if (!(i->type & ITER_BVEC)) {
208 bytes = min(bytes, i->iov->iov_len - i->iov_offset); 265 char __user *buf = i->iov->iov_base + i->iov_offset;
209 return fault_in_pages_readable(buf, bytes); 266 bytes = min(bytes, i->iov->iov_len - i->iov_offset);
267 return fault_in_pages_readable(buf, bytes);
268 }
269 return 0;
210} 270}
211EXPORT_SYMBOL(iov_iter_fault_in_readable); 271EXPORT_SYMBOL(iov_iter_fault_in_readable);
212 272
273static unsigned long alignment_iovec(const struct iov_iter *i)
274{
275 const struct iovec *iov = i->iov;
276 unsigned long res;
277 size_t size = i->count;
278 size_t n;
279
280 if (!size)
281 return 0;
282
283 res = (unsigned long)iov->iov_base + i->iov_offset;
284 n = iov->iov_len - i->iov_offset;
285 if (n >= size)
286 return res | size;
287 size -= n;
288 res |= n;
289 while (size > (++iov)->iov_len) {
290 res |= (unsigned long)iov->iov_base | iov->iov_len;
291 size -= iov->iov_len;
292 }
293 res |= (unsigned long)iov->iov_base | size;
294 return res;
295}
296
297void iov_iter_init(struct iov_iter *i, int direction,
298 const struct iovec *iov, unsigned long nr_segs,
299 size_t count)
300{
301 /* It will get better. Eventually... */
302 if (segment_eq(get_fs(), KERNEL_DS))
303 direction |= ITER_KVEC;
304 i->type = direction;
305 i->iov = iov;
306 i->nr_segs = nr_segs;
307 i->iov_offset = 0;
308 i->count = count;
309}
310EXPORT_SYMBOL(iov_iter_init);
311
312static ssize_t get_pages_iovec(struct iov_iter *i,
313 struct page **pages, size_t maxsize,
314 size_t *start)
315{
316 size_t offset = i->iov_offset;
317 const struct iovec *iov = i->iov;
318 size_t len;
319 unsigned long addr;
320 int n;
321 int res;
322
323 len = iov->iov_len - offset;
324 if (len > i->count)
325 len = i->count;
326 if (len > maxsize)
327 len = maxsize;
328 addr = (unsigned long)iov->iov_base + offset;
329 len += *start = addr & (PAGE_SIZE - 1);
330 addr &= ~(PAGE_SIZE - 1);
331 n = (len + PAGE_SIZE - 1) / PAGE_SIZE;
332 res = get_user_pages_fast(addr, n, (i->type & WRITE) != WRITE, pages);
333 if (unlikely(res < 0))
334 return res;
335 return (res == n ? len : res * PAGE_SIZE) - *start;
336}
337
338static ssize_t get_pages_alloc_iovec(struct iov_iter *i,
339 struct page ***pages, size_t maxsize,
340 size_t *start)
341{
342 size_t offset = i->iov_offset;
343 const struct iovec *iov = i->iov;
344 size_t len;
345 unsigned long addr;
346 void *p;
347 int n;
348 int res;
349
350 len = iov->iov_len - offset;
351 if (len > i->count)
352 len = i->count;
353 if (len > maxsize)
354 len = maxsize;
355 addr = (unsigned long)iov->iov_base + offset;
356 len += *start = addr & (PAGE_SIZE - 1);
357 addr &= ~(PAGE_SIZE - 1);
358 n = (len + PAGE_SIZE - 1) / PAGE_SIZE;
359
360 p = kmalloc(n * sizeof(struct page *), GFP_KERNEL);
361 if (!p)
362 p = vmalloc(n * sizeof(struct page *));
363 if (!p)
364 return -ENOMEM;
365
366 res = get_user_pages_fast(addr, n, (i->type & WRITE) != WRITE, p);
367 if (unlikely(res < 0)) {
368 kvfree(p);
369 return res;
370 }
371 *pages = p;
372 return (res == n ? len : res * PAGE_SIZE) - *start;
373}
374
375static int iov_iter_npages_iovec(const struct iov_iter *i, int maxpages)
376{
377 size_t offset = i->iov_offset;
378 size_t size = i->count;
379 const struct iovec *iov = i->iov;
380 int npages = 0;
381 int n;
382
383 for (n = 0; size && n < i->nr_segs; n++, iov++) {
384 unsigned long addr = (unsigned long)iov->iov_base + offset;
385 size_t len = iov->iov_len - offset;
386 offset = 0;
387 if (unlikely(!len)) /* empty segment */
388 continue;
389 if (len > size)
390 len = size;
391 npages += (addr + len + PAGE_SIZE - 1) / PAGE_SIZE
392 - addr / PAGE_SIZE;
393 if (npages >= maxpages) /* don't bother going further */
394 return maxpages;
395 size -= len;
396 offset = 0;
397 }
398 return min(npages, maxpages);
399}
400
401static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len)
402{
403 char *from = kmap_atomic(page);
404 memcpy(to, from + offset, len);
405 kunmap_atomic(from);
406}
407
408static void memcpy_to_page(struct page *page, size_t offset, char *from, size_t len)
409{
410 char *to = kmap_atomic(page);
411 memcpy(to + offset, from, len);
412 kunmap_atomic(to);
413}
414
415static size_t copy_page_to_iter_bvec(struct page *page, size_t offset, size_t bytes,
416 struct iov_iter *i)
417{
418 size_t skip, copy, wanted;
419 const struct bio_vec *bvec;
420 void *kaddr, *from;
421
422 if (unlikely(bytes > i->count))
423 bytes = i->count;
424
425 if (unlikely(!bytes))
426 return 0;
427
428 wanted = bytes;
429 bvec = i->bvec;
430 skip = i->iov_offset;
431 copy = min_t(size_t, bytes, bvec->bv_len - skip);
432
433 kaddr = kmap_atomic(page);
434 from = kaddr + offset;
435 memcpy_to_page(bvec->bv_page, skip + bvec->bv_offset, from, copy);
436 skip += copy;
437 from += copy;
438 bytes -= copy;
439 while (bytes) {
440 bvec++;
441 copy = min(bytes, (size_t)bvec->bv_len);
442 memcpy_to_page(bvec->bv_page, bvec->bv_offset, from, copy);
443 skip = copy;
444 from += copy;
445 bytes -= copy;
446 }
447 kunmap_atomic(kaddr);
448 if (skip == bvec->bv_len) {
449 bvec++;
450 skip = 0;
451 }
452 i->count -= wanted - bytes;
453 i->nr_segs -= bvec - i->bvec;
454 i->bvec = bvec;
455 i->iov_offset = skip;
456 return wanted - bytes;
457}
458
459static size_t copy_page_from_iter_bvec(struct page *page, size_t offset, size_t bytes,
460 struct iov_iter *i)
461{
462 size_t skip, copy, wanted;
463 const struct bio_vec *bvec;
464 void *kaddr, *to;
465
466 if (unlikely(bytes > i->count))
467 bytes = i->count;
468
469 if (unlikely(!bytes))
470 return 0;
471
472 wanted = bytes;
473 bvec = i->bvec;
474 skip = i->iov_offset;
475
476 kaddr = kmap_atomic(page);
477
478 to = kaddr + offset;
479
480 copy = min(bytes, bvec->bv_len - skip);
481
482 memcpy_from_page(to, bvec->bv_page, bvec->bv_offset + skip, copy);
483
484 to += copy;
485 skip += copy;
486 bytes -= copy;
487
488 while (bytes) {
489 bvec++;
490 copy = min(bytes, (size_t)bvec->bv_len);
491 memcpy_from_page(to, bvec->bv_page, bvec->bv_offset, copy);
492 skip = copy;
493 to += copy;
494 bytes -= copy;
495 }
496 kunmap_atomic(kaddr);
497 if (skip == bvec->bv_len) {
498 bvec++;
499 skip = 0;
500 }
501 i->count -= wanted;
502 i->nr_segs -= bvec - i->bvec;
503 i->bvec = bvec;
504 i->iov_offset = skip;
505 return wanted;
506}
507
508static size_t copy_from_user_bvec(struct page *page,
509 struct iov_iter *i, unsigned long offset, size_t bytes)
510{
511 char *kaddr;
512 size_t left;
513 const struct bio_vec *bvec;
514 size_t base = i->iov_offset;
515
516 kaddr = kmap_atomic(page);
517 for (left = bytes, bvec = i->bvec; left; bvec++, base = 0) {
518 size_t copy = min(left, bvec->bv_len - base);
519 if (!bvec->bv_len)
520 continue;
521 memcpy_from_page(kaddr + offset, bvec->bv_page,
522 bvec->bv_offset + base, copy);
523 offset += copy;
524 left -= copy;
525 }
526 kunmap_atomic(kaddr);
527 return bytes;
528}
529
530static void advance_bvec(struct iov_iter *i, size_t bytes)
531{
532 BUG_ON(i->count < bytes);
533
534 if (likely(i->nr_segs == 1)) {
535 i->iov_offset += bytes;
536 i->count -= bytes;
537 } else {
538 const struct bio_vec *bvec = i->bvec;
539 size_t base = i->iov_offset;
540 unsigned long nr_segs = i->nr_segs;
541
542 /*
543 * The !iov->iov_len check ensures we skip over unlikely
544 * zero-length segments (without overruning the iovec).
545 */
546 while (bytes || unlikely(i->count && !bvec->bv_len)) {
547 int copy;
548
549 copy = min(bytes, bvec->bv_len - base);
550 BUG_ON(!i->count || i->count < copy);
551 i->count -= copy;
552 bytes -= copy;
553 base += copy;
554 if (bvec->bv_len == base) {
555 bvec++;
556 nr_segs--;
557 base = 0;
558 }
559 }
560 i->bvec = bvec;
561 i->iov_offset = base;
562 i->nr_segs = nr_segs;
563 }
564}
565
566static unsigned long alignment_bvec(const struct iov_iter *i)
567{
568 const struct bio_vec *bvec = i->bvec;
569 unsigned long res;
570 size_t size = i->count;
571 size_t n;
572
573 if (!size)
574 return 0;
575
576 res = bvec->bv_offset + i->iov_offset;
577 n = bvec->bv_len - i->iov_offset;
578 if (n >= size)
579 return res | size;
580 size -= n;
581 res |= n;
582 while (size > (++bvec)->bv_len) {
583 res |= bvec->bv_offset | bvec->bv_len;
584 size -= bvec->bv_len;
585 }
586 res |= bvec->bv_offset | size;
587 return res;
588}
589
590static ssize_t get_pages_bvec(struct iov_iter *i,
591 struct page **pages, size_t maxsize,
592 size_t *start)
593{
594 const struct bio_vec *bvec = i->bvec;
595 size_t len = bvec->bv_len - i->iov_offset;
596 if (len > i->count)
597 len = i->count;
598 if (len > maxsize)
599 len = maxsize;
600 *start = bvec->bv_offset + i->iov_offset;
601
602 get_page(*pages = bvec->bv_page);
603
604 return len;
605}
606
607static ssize_t get_pages_alloc_bvec(struct iov_iter *i,
608 struct page ***pages, size_t maxsize,
609 size_t *start)
610{
611 const struct bio_vec *bvec = i->bvec;
612 size_t len = bvec->bv_len - i->iov_offset;
613 if (len > i->count)
614 len = i->count;
615 if (len > maxsize)
616 len = maxsize;
617 *start = bvec->bv_offset + i->iov_offset;
618
619 *pages = kmalloc(sizeof(struct page *), GFP_KERNEL);
620 if (!*pages)
621 return -ENOMEM;
622
623 get_page(**pages = bvec->bv_page);
624
625 return len;
626}
627
628static int iov_iter_npages_bvec(const struct iov_iter *i, int maxpages)
629{
630 size_t offset = i->iov_offset;
631 size_t size = i->count;
632 const struct bio_vec *bvec = i->bvec;
633 int npages = 0;
634 int n;
635
636 for (n = 0; size && n < i->nr_segs; n++, bvec++) {
637 size_t len = bvec->bv_len - offset;
638 offset = 0;
639 if (unlikely(!len)) /* empty segment */
640 continue;
641 if (len > size)
642 len = size;
643 npages++;
644 if (npages >= maxpages) /* don't bother going further */
645 return maxpages;
646 size -= len;
647 offset = 0;
648 }
649 return min(npages, maxpages);
650}
651
652size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes,
653 struct iov_iter *i)
654{
655 if (i->type & ITER_BVEC)
656 return copy_page_to_iter_bvec(page, offset, bytes, i);
657 else
658 return copy_page_to_iter_iovec(page, offset, bytes, i);
659}
660EXPORT_SYMBOL(copy_page_to_iter);
661
662size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes,
663 struct iov_iter *i)
664{
665 if (i->type & ITER_BVEC)
666 return copy_page_from_iter_bvec(page, offset, bytes, i);
667 else
668 return copy_page_from_iter_iovec(page, offset, bytes, i);
669}
670EXPORT_SYMBOL(copy_page_from_iter);
671
672size_t iov_iter_copy_from_user_atomic(struct page *page,
673 struct iov_iter *i, unsigned long offset, size_t bytes)
674{
675 if (i->type & ITER_BVEC)
676 return copy_from_user_bvec(page, i, offset, bytes);
677 else
678 return copy_from_user_atomic_iovec(page, i, offset, bytes);
679}
680EXPORT_SYMBOL(iov_iter_copy_from_user_atomic);
681
682void iov_iter_advance(struct iov_iter *i, size_t size)
683{
684 if (i->type & ITER_BVEC)
685 advance_bvec(i, size);
686 else
687 advance_iovec(i, size);
688}
689EXPORT_SYMBOL(iov_iter_advance);
690
213/* 691/*
214 * Return the count of just the current iov_iter segment. 692 * Return the count of just the current iov_iter segment.
215 */ 693 */
216size_t iov_iter_single_seg_count(const struct iov_iter *i) 694size_t iov_iter_single_seg_count(const struct iov_iter *i)
217{ 695{
218 const struct iovec *iov = i->iov;
219 if (i->nr_segs == 1) 696 if (i->nr_segs == 1)
220 return i->count; 697 return i->count;
698 else if (i->type & ITER_BVEC)
699 return min(i->count, i->iov->iov_len - i->iov_offset);
221 else 700 else
222 return min(i->count, iov->iov_len - i->iov_offset); 701 return min(i->count, i->bvec->bv_len - i->iov_offset);
223} 702}
224EXPORT_SYMBOL(iov_iter_single_seg_count); 703EXPORT_SYMBOL(iov_iter_single_seg_count);
704
705unsigned long iov_iter_alignment(const struct iov_iter *i)
706{
707 if (i->type & ITER_BVEC)
708 return alignment_bvec(i);
709 else
710 return alignment_iovec(i);
711}
712EXPORT_SYMBOL(iov_iter_alignment);
713
714ssize_t iov_iter_get_pages(struct iov_iter *i,
715 struct page **pages, size_t maxsize,
716 size_t *start)
717{
718 if (i->type & ITER_BVEC)
719 return get_pages_bvec(i, pages, maxsize, start);
720 else
721 return get_pages_iovec(i, pages, maxsize, start);
722}
723EXPORT_SYMBOL(iov_iter_get_pages);
724
725ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,
726 struct page ***pages, size_t maxsize,
727 size_t *start)
728{
729 if (i->type & ITER_BVEC)
730 return get_pages_alloc_bvec(i, pages, maxsize, start);
731 else
732 return get_pages_alloc_iovec(i, pages, maxsize, start);
733}
734EXPORT_SYMBOL(iov_iter_get_pages_alloc);
735
736int iov_iter_npages(const struct iov_iter *i, int maxpages)
737{
738 if (i->type & ITER_BVEC)
739 return iov_iter_npages_bvec(i, maxpages);
740 else
741 return iov_iter_npages_iovec(i, maxpages);
742}
743EXPORT_SYMBOL(iov_iter_npages);
diff --git a/mm/page_io.c b/mm/page_io.c
index 58b50d2901fe..243a9b76e5ce 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -264,9 +264,17 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
264 struct kiocb kiocb; 264 struct kiocb kiocb;
265 struct file *swap_file = sis->swap_file; 265 struct file *swap_file = sis->swap_file;
266 struct address_space *mapping = swap_file->f_mapping; 266 struct address_space *mapping = swap_file->f_mapping;
267 struct iovec iov = { 267 struct bio_vec bv = {
268 .iov_base = kmap(page), 268 .bv_page = page,
269 .iov_len = PAGE_SIZE, 269 .bv_len = PAGE_SIZE,
270 .bv_offset = 0
271 };
272 struct iov_iter from = {
273 .type = ITER_BVEC | WRITE,
274 .count = PAGE_SIZE,
275 .iov_offset = 0,
276 .nr_segs = 1,
277 .bvec = &bv
270 }; 278 };
271 279
272 init_sync_kiocb(&kiocb, swap_file); 280 init_sync_kiocb(&kiocb, swap_file);
@@ -275,10 +283,9 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
275 283
276 set_page_writeback(page); 284 set_page_writeback(page);
277 unlock_page(page); 285 unlock_page(page);
278 ret = mapping->a_ops->direct_IO(KERNEL_WRITE, 286 ret = mapping->a_ops->direct_IO(ITER_BVEC | WRITE,
279 &kiocb, &iov, 287 &kiocb, &from,
280 kiocb.ki_pos, 1); 288 kiocb.ki_pos);
281 kunmap(page);
282 if (ret == PAGE_SIZE) { 289 if (ret == PAGE_SIZE) {
283 count_vm_event(PSWPOUT); 290 count_vm_event(PSWPOUT);
284 ret = 0; 291 ret = 0;
diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
index 8505c9262b35..5077afcd9e11 100644
--- a/mm/process_vm_access.c
+++ b/mm/process_vm_access.c
@@ -46,11 +46,7 @@ static int process_vm_rw_pages(struct page **pages,
46 copy = len; 46 copy = len;
47 47
48 if (vm_write) { 48 if (vm_write) {
49 if (copy > iov_iter_count(iter)) 49 copied = copy_page_from_iter(page, offset, copy, iter);
50 copy = iov_iter_count(iter);
51 copied = iov_iter_copy_from_user(page, iter,
52 offset, copy);
53 iov_iter_advance(iter, copied);
54 set_page_dirty_lock(page); 50 set_page_dirty_lock(page);
55 } else { 51 } else {
56 copied = copy_page_to_iter(page, offset, copy, iter); 52 copied = copy_page_to_iter(page, offset, copy, iter);
@@ -278,7 +274,7 @@ static ssize_t process_vm_rw(pid_t pid,
278 if (rc <= 0) 274 if (rc <= 0)
279 goto free_iovecs; 275 goto free_iovecs;
280 276
281 iov_iter_init(&iter, iov_l, liovcnt, rc, 0); 277 iov_iter_init(&iter, vm_write ? WRITE : READ, iov_l, liovcnt, rc);
282 278
283 rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV, 279 rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV,
284 iovstack_r, &iov_r); 280 iovstack_r, &iov_r);
@@ -341,7 +337,7 @@ compat_process_vm_rw(compat_pid_t pid,
341 &iov_l); 337 &iov_l);
342 if (rc <= 0) 338 if (rc <= 0)
343 goto free_iovecs; 339 goto free_iovecs;
344 iov_iter_init(&iter, iov_l, liovcnt, rc, 0); 340 iov_iter_init(&iter, vm_write ? WRITE : READ, iov_l, liovcnt, rc);
345 rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, 341 rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt,
346 UIO_FASTIOV, iovstack_r, 342 UIO_FASTIOV, iovstack_r,
347 &iov_r); 343 &iov_r);
diff --git a/mm/shmem.c b/mm/shmem.c
index 5402481c28d1..f484c276e994 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1406,8 +1406,7 @@ shmem_write_end(struct file *file, struct address_space *mapping,
1406 return copied; 1406 return copied;
1407} 1407}
1408 1408
1409static ssize_t shmem_file_aio_read(struct kiocb *iocb, 1409static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
1410 const struct iovec *iov, unsigned long nr_segs, loff_t pos)
1411{ 1410{
1412 struct file *file = iocb->ki_filp; 1411 struct file *file = iocb->ki_filp;
1413 struct inode *inode = file_inode(file); 1412 struct inode *inode = file_inode(file);
@@ -1416,15 +1415,8 @@ static ssize_t shmem_file_aio_read(struct kiocb *iocb,
1416 unsigned long offset; 1415 unsigned long offset;
1417 enum sgp_type sgp = SGP_READ; 1416 enum sgp_type sgp = SGP_READ;
1418 int error = 0; 1417 int error = 0;
1419 ssize_t retval; 1418 ssize_t retval = 0;
1420 size_t count;
1421 loff_t *ppos = &iocb->ki_pos; 1419 loff_t *ppos = &iocb->ki_pos;
1422 struct iov_iter iter;
1423
1424 retval = generic_segment_checks(iov, &nr_segs, &count, VERIFY_WRITE);
1425 if (retval)
1426 return retval;
1427 iov_iter_init(&iter, iov, nr_segs, count, 0);
1428 1420
1429 /* 1421 /*
1430 * Might this read be for a stacking filesystem? Then when reading 1422 * Might this read be for a stacking filesystem? Then when reading
@@ -1500,14 +1492,14 @@ static ssize_t shmem_file_aio_read(struct kiocb *iocb,
1500 * Ok, we have the page, and it's up-to-date, so 1492 * Ok, we have the page, and it's up-to-date, so
1501 * now we can copy it to user space... 1493 * now we can copy it to user space...
1502 */ 1494 */
1503 ret = copy_page_to_iter(page, offset, nr, &iter); 1495 ret = copy_page_to_iter(page, offset, nr, to);
1504 retval += ret; 1496 retval += ret;
1505 offset += ret; 1497 offset += ret;
1506 index += offset >> PAGE_CACHE_SHIFT; 1498 index += offset >> PAGE_CACHE_SHIFT;
1507 offset &= ~PAGE_CACHE_MASK; 1499 offset &= ~PAGE_CACHE_MASK;
1508 1500
1509 page_cache_release(page); 1501 page_cache_release(page);
1510 if (!iov_iter_count(&iter)) 1502 if (!iov_iter_count(to))
1511 break; 1503 break;
1512 if (ret < nr) { 1504 if (ret < nr) {
1513 error = -EFAULT; 1505 error = -EFAULT;
@@ -2629,13 +2621,13 @@ static const struct file_operations shmem_file_operations = {
2629 .mmap = shmem_mmap, 2621 .mmap = shmem_mmap,
2630#ifdef CONFIG_TMPFS 2622#ifdef CONFIG_TMPFS
2631 .llseek = shmem_file_llseek, 2623 .llseek = shmem_file_llseek,
2632 .read = do_sync_read, 2624 .read = new_sync_read,
2633 .write = do_sync_write, 2625 .write = new_sync_write,
2634 .aio_read = shmem_file_aio_read, 2626 .read_iter = shmem_file_read_iter,
2635 .aio_write = generic_file_aio_write, 2627 .write_iter = generic_file_write_iter,
2636 .fsync = noop_fsync, 2628 .fsync = noop_fsync,
2637 .splice_read = shmem_file_splice_read, 2629 .splice_read = shmem_file_splice_read,
2638 .splice_write = generic_file_splice_write, 2630 .splice_write = iter_file_splice_write,
2639 .fallocate = shmem_fallocate, 2631 .fallocate = shmem_fallocate,
2640#endif 2632#endif
2641}; 2633};
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e01ded365440..0f16ffe8eb67 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -464,7 +464,7 @@ static pageout_t pageout(struct page *page, struct address_space *mapping,
464 * stalls if we need to run get_block(). We could test 464 * stalls if we need to run get_block(). We could test
465 * PagePrivate for that. 465 * PagePrivate for that.
466 * 466 *
467 * If this process is currently in __generic_file_aio_write() against 467 * If this process is currently in __generic_file_write_iter() against
468 * this page's queue, we can perform writeback even if that 468 * this page's queue, we can perform writeback even if that
469 * will block. 469 * will block.
470 * 470 *