From: Vitaly Mayatskikh <v.mayatskih@gmail.com>
To: Josef Bacik <josef@redhat.com>
Cc: sandeen@redhat.com, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] Perform check in iov_iter_fault_in_readable() by check_readable_bytes()
Date: Thu, 14 May 2009 18:19:01 +0200 [thread overview]
Message-ID: <1242317939-15392-3-git-send-email-v.mayatskih@gmail.com> (raw)
In-Reply-To: <1242317939-15392-1-git-send-email-v.mayatskih@gmail.com>
This patch changes iov_iter_fault_in_readable() to use check_readable_bytes()
instead of fault_in_pages_readable(). It allows iov_iter_fault_in_readable()
callers to know how much data is accessible and proceed with it. It makes
sys_write() more POSIX-friendly.
Signed-off-by: Vitaly Mayatskikh <v.mayatskih@gmail.com>
---
fs/fuse/file.c | 6 ++++--
mm/filemap.c | 13 +++++++++----
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 06f30e9..c74ef04 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -782,13 +782,15 @@ static ssize_t fuse_fill_write_pages(struct fuse_req *req,
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
size_t bytes = min_t(size_t, PAGE_CACHE_SIZE - offset,
iov_iter_count(ii));
-
+ long accessible;
bytes = min_t(size_t, bytes, fc->max_write - count);
again:
err = -EFAULT;
- if (iov_iter_fault_in_readable(ii, bytes))
+ accessible = iov_iter_fault_in_readable(ii, bytes);
+ if (accessible < 0)
break;
+ bytes = accessible;
err = -ENOMEM;
page = grab_cache_page_write_begin(mapping, index, 0);
diff --git a/mm/filemap.c b/mm/filemap.c
index 379ff0b..ef598a1 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1947,8 +1947,9 @@ EXPORT_SYMBOL(iov_iter_advance);
/*
* Fault in the first iovec of the given iov_iter, to a maximum length
- * of bytes. Returns 0 on success, or non-zero if the memory could not be
- * accessed (ie. because it is an invalid address).
+ * of bytes. Returns count of accessible bytes on success, or -EFAULT
+ * if the memory could not be accessed (ie. because it is an invalid
+ * address).
*
* writev-intensive code may want this to prefault several iovecs -- that
* would be possible (callers must not rely on the fact that _only_ the
@@ -1958,7 +1959,7 @@ int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes)
{
char __user *buf = i->iov->iov_base + i->iov_offset;
bytes = min(bytes, i->iov->iov_len - i->iov_offset);
- return fault_in_pages_readable(buf, bytes);
+ return check_readable_bytes(buf, bytes);
}
EXPORT_SYMBOL(iov_iter_fault_in_readable);
@@ -2215,6 +2216,7 @@ static ssize_t generic_perform_write(struct file *file,
unsigned long offset; /* Offset into pagecache page */
unsigned long bytes; /* Bytes to write to page */
size_t copied; /* Bytes copied from user */
+ long accessible;
void *fsdata;
offset = (pos & (PAGE_CACHE_SIZE - 1));
@@ -2234,10 +2236,13 @@ again:
* to check that the address is actually valid, when atomic
* usercopies are used, below.
*/
- if (unlikely(iov_iter_fault_in_readable(i, bytes))) {
+
+ accessible = iov_iter_fault_in_readable(i, bytes);
+ if (accessible < 0) {
status = -EFAULT;
break;
}
+ bytes = accessible;
status = a_ops->write_begin(file, mapping, pos, bytes, flags,
&page, &fsdata);
--
1.6.2.2
next prev parent reply other threads:[~2009-05-14 16:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-14 16:18 [PATCH 0/2] sys_write() should write all valid data Vitaly Mayatskikh
2009-05-14 16:19 ` [PATCH 1/2] Introduce check_readable_bytes() Vitaly Mayatskikh
2009-05-14 17:40 ` Josef Bacik
2009-05-14 17:57 ` Vitaly Mayatskikh
2009-05-14 16:19 ` Vitaly Mayatskikh [this message]
2009-05-15 6:56 ` [PATCH 2/2] Perform check in iov_iter_fault_in_readable() by check_readable_bytes() Andi Kleen
2009-05-15 7:56 ` Vitaly Mayatskikh
2009-05-15 9:38 ` Andi Kleen
2009-05-15 11:56 ` Vitaly Mayatskikh
2009-05-15 12:19 ` Andi Kleen
2009-05-15 13:43 ` Jamie Lokier
2009-05-15 14:01 ` Andi Kleen
2009-05-15 14:37 ` Jamie Lokier
2009-05-18 8:31 ` Alan Cox
2009-05-18 9:48 ` Jamie Lokier
2009-05-18 10:03 ` Alan Cox
2009-05-18 10:16 ` Andi Kleen
2009-05-19 8:55 ` Pavel Machek
2009-05-14 18:02 ` [PATCH 0/2] sys_write() should write all valid data Josef Bacik
2009-05-14 18:48 ` Vitaly Mayatskikh
2009-05-14 19:05 ` Josef Bacik
2009-05-15 6:52 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1242317939-15392-3-git-send-email-v.mayatskih@gmail.com \
--to=v.mayatskih@gmail.com \
--cc=josef@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sandeen@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).