From c3a690240423fc4eb8a0c3c7df025d13eadf140b Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 10 Oct 2016 13:26:27 -0400 Subject: [PATCH 1/3] fix ITER_PIPE interaction with direct_IO by making sure we call iov_iter_advance() on original iov_iter even if direct_IO (done on its copy) has returned 0. It's a no-op for old iov_iter flavours and does the right thing (== truncation of the stuff we'd allocated, but not filled) in ITER_PIPE case. Failures (e.g. -EIO) get caught and dealt with by cleanup in generic_file_read_iter(). Signed-off-by: Al Viro --- fs/splice.c | 12 +++--------- fs/xfs/xfs_file.c | 2 +- mm/filemap.c | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index aa38901a4f10..153d4f3bd441 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -315,15 +315,9 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, *ppos = kiocb.ki_pos; file_accessed(in); } else if (ret < 0) { - if (WARN_ON(to.idx != idx || to.iov_offset)) { - /* - * a bogus ->read_iter() has copied something and still - * returned an error instead of a short read. - */ - to.idx = idx; - to.iov_offset = 0; - iov_iter_advance(&to, 0); /* to free what was emitted */ - } + to.idx = idx; + to.iov_offset = 0; + iov_iter_advance(&to, 0); /* to free what was emitted */ /* * callers of ->splice_read() expect -EAGAIN on * "can't put anything in there", rather than -EFAULT. diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 92f16cfb81e8..26cf153e3714 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -317,7 +317,7 @@ xfs_file_dio_aio_read( data = *to; ret = __blockdev_direct_IO(iocb, inode, target->bt_bdev, &data, xfs_get_blocks_direct, NULL, NULL, 0); - if (ret > 0) { + if (ret >= 0) { iocb->ki_pos += ret; iov_iter_advance(to, ret); } diff --git a/mm/filemap.c b/mm/filemap.c index 8a287dfc5372..6b965efe215e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1920,7 +1920,7 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) retval = mapping->a_ops->direct_IO(iocb, &data); } - if (retval > 0) { + if (retval >= 0) { iocb->ki_pos += retval; iov_iter_advance(iter, retval); } From b57332b4105abf1d518d93886e547ee2f98cd414 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 10 Oct 2016 13:57:37 -0400 Subject: [PATCH 2/3] constify iov_iter_count() and iter_is_iovec() Signed-off-by: Al Viro --- include/linux/uio.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index b5ebe6dca404..544c03552b99 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -110,12 +110,12 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages); const void *dup_iter(struct iov_iter *new, struct iov_iter *old, gfp_t flags); -static inline size_t iov_iter_count(struct iov_iter *i) +static inline size_t iov_iter_count(const struct iov_iter *i) { return i->count; } -static inline bool iter_is_iovec(struct iov_iter *i) +static inline bool iter_is_iovec(const struct iov_iter *i) { return !(i->type & (ITER_BVEC | ITER_KVEC | ITER_PIPE)); } From cd27e455042da85b088bdd3a6e00da1d5b4df9f1 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 10 Oct 2016 13:39:05 -0400 Subject: [PATCH 3/3] [btrfs] fix check_direct_IO() for non-iovec iterators looking for duplicate ->iov_base makes sense only for iovec-backed iterators; for kvec-backed ones it's pointless, for bvec-backed ones it's pointless and broken on 32bit (we walk through an array of struct bio_vec accessing them as if they were struct iovec; works by accident on 64bit, but on 32bit it'll blow up) and for pipe-backed ones it's pointless and ends up oopsing. Signed-off-by: Al Viro --- fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e6811c42e41e..ff15cf42763a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8618,7 +8618,7 @@ static ssize_t check_direct_IO(struct btrfs_root *root, struct kiocb *iocb, goto out; /* If this is a write we don't need to check anymore */ - if (iov_iter_rw(iter) == WRITE) + if (iov_iter_rw(iter) != READ || !iter_is_iovec(iter)) return 0; /* * Check to make sure we don't have duplicate iov_base's in this