linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: hold page lock when checking mapping in ext4_page_mkwrite
@ 2011-07-18 15:59 Josef Bacik
  2011-07-19  2:13 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Josef Bacik @ 2011-07-18 15:59 UTC (permalink / raw)
  To: linux-ext4, tytso

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: hold page lock when checking mapping in ext4_page_mkwrite
  2011-07-18 15:59 [PATCH] ext4: hold page lock when checking mapping in ext4_page_mkwrite Josef Bacik
@ 2011-07-19  2:13 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2011-07-19  2:13 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-ext4, tytso

On Mon, Jul 18, 2011 at 11:59:32AM -0400, Josef Bacik wrote:
> 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,

Josef, please check the ext4_page_mkwrite implementation in the vfs
tree, which is just a wrapper around the generic code and thus shouldn't
have this problem any more.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-19  2:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-18 15:59 [PATCH] ext4: hold page lock when checking mapping in ext4_page_mkwrite Josef Bacik
2011-07-19  2:13 ` Christoph Hellwig

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).