From: Josef Bacik <josef@redhat.com>
To: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: [PATCH] ext4: hold page lock when checking mapping in ext4_page_mkwrite
Date: Mon, 18 Jul 2011 11:59:32 -0400 [thread overview]
Message-ID: <1311004772-14675-1-git-send-email-josef@redhat.com> (raw)
Pages can be evicted from cache outside of truncate, for example when
invalidating pages after writing with O_DIRECT. The only proper way to check
page->mapping is under the page lock, so fix ext4_page_mkwrite to do this.
Thanks,
Signed-off-by: Josef Bacik <josef@redhat.com>
---
fs/ext4/inode.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index e3126c0..1ad7d10 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5855,14 +5855,15 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
*/
down_read(&inode->i_alloc_sem);
size = i_size_read(inode);
+ lock_page(page);
if (page->mapping != mapping || size <= page_offset(page)
|| !PageUptodate(page)) {
+ unlock_page(page);
/* page got truncated from under us? */
goto out_unlock;
}
ret = 0;
- lock_page(page);
wait_on_page_writeback(page);
if (PageMappedToDisk(page)) {
up_read(&inode->i_alloc_sem);
--
1.7.5.2
next reply other threads:[~2011-07-18 15:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-18 15:59 Josef Bacik [this message]
2011-07-19 2:13 ` [PATCH] ext4: hold page lock when checking mapping in ext4_page_mkwrite Christoph Hellwig
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=1311004772-14675-1-git-send-email-josef@redhat.com \
--to=josef@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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).