linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Dave Chinner <david@fromorbit.com>
Cc: Jan Kara <jack@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-fsdevel@vger.kernel.org, Al Viro <viro@ZenIV.linux.org.uk>,
	Christoph Hellwig <hch@infradead.org>,
	dchinner@redhat.com, sandeen@redhat.com,
	Kamal Mostafa <kamal@canonical.com>
Subject: Re: [PATCH 01/19] mm: Make default vm_ops provide ->page_mkwrite handler
Date: Wed, 28 Mar 2012 11:48:56 +0200	[thread overview]
Message-ID: <20120328094856.GA18751@quack.suse.cz> (raw)
In-Reply-To: <20120327224553.GG5091@dastard>

On Wed 28-03-12 09:45:53, Dave Chinner wrote:
> On Wed, Mar 28, 2012 at 12:08:19AM +0200, Jan Kara wrote:
> > On Tue 27-03-12 14:38:15, Andrew Morton wrote:
> > > On Tue, 27 Mar 2012 09:55:27 +0200
> > > Jan Kara <jack@suse.cz> wrote:
> > > > On Fri 23-03-12 15:45:02, Andrew Morton wrote:
> > > > > On Mon,  5 Mar 2012 17:00:59 +0100
> > > > > Jan Kara <jack@suse.cz> wrote:
> > > > > 
> > > > > > --- a/mm/filemap.c
> > > > > > +++ b/mm/filemap.c
> > > > > > @@ -1759,8 +1759,28 @@ page_not_uptodate:
> > > > > >  }
> > > > > >  EXPORT_SYMBOL(filemap_fault);
> > > > > >  
> > > > > > +int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
> > > > > > +{
> > > > > > +	struct page *page = vmf->page;
> > > > > > +	struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
> > > > > > +	int ret = VM_FAULT_LOCKED;
> > > > > > +
> > > > > > +	file_update_time(vma->vm_file);
> > > > > > +	lock_page(page);
> > > > > > +	if ((page->mapping != inode->i_mapping) ||
> > > > > > +	    (page_offset(page) > i_size_read(inode))) {
> > > > > 
> > > > > Would benefit from a comment explaining how the page can come to be
> > > > > outside i_size, and why we fail in that case.
> > > 
> > > This?
> > > 
> > > > > I don't think i_mutex is held here, so this test is rather meaningless
> > > > > and racy anyway?
> > > >   i_size test is racy if that's what you mean by "this test". Just I did
> > > > the test this way because it's like this in other places and I figured
> > > > truncate_pagecache() can take relatively long time so the test has some
> > > > effect. But if you think it's not worth it, I can remove it.
> > > 
> > > It bugs me when we copy-n-paste code without remembering why we had it
> > > there in the first place :( iirc, mmapped pages outside i_size can and
> > > do happen in some race situations, and are benign.
> >   Yeah. Certainly there can be pages beyond i_size because we first set
> > file size and then go and remove pages beyond new i_size one by one when we
> > do truncate. We must be careful not to create any new pages beyond i_size
> > but that's what filemap_fault() takes care of. So I think i_size check in
> > ->page_mkwrite() isn't strictly needed.
> 
> Actually, I think it is. In __do_fault(), we drop the page lock
> between the .fault call and the .page_mkwrite() call, so the size
> checks in .fault for the given page being faulted are no longer
> valid as truncate serialises only on the page lock. Hence we have to
> repeat the truncate race checks again in .page_mkwrite() after we
> relock the page.
  I was thinking about this scenario as well but I think doesn't cause any
problems. But maybe there's some noise in what the condition actually is.
So I currently have:
	if (page->mapping != inode->i_mapping)
		bail..
	do stuff.
And I think that is enough. Because only filemap_fault() creates new page,
->page_mkwrite() only uses the page reference from vmf->page. So the only
thing that can happen after __do_fault() drops page lock is that
truncate_pagecache() will go and truncate the page (thus page->mapping will
be NULL) and the condition I currently have should be enough to catch that.

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

  reply	other threads:[~2012-03-28  9:48 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-05 16:00 [PATCH 00/19] Fix filesystem freezing deadlocks Jan Kara
2012-03-05 16:00 ` [PATCH 01/19] mm: Make default vm_ops provide ->page_mkwrite handler Jan Kara
2012-03-23 22:45   ` Andrew Morton
2012-03-27  7:55     ` Jan Kara
2012-03-27 21:38       ` Andrew Morton
2012-03-27 22:08         ` Jan Kara
2012-03-27 22:45           ` Dave Chinner
2012-03-28  9:48             ` Jan Kara [this message]
2012-03-05 16:01 ` [PATCH 02/19] fs: Push mnt_want_write() outside of i_mutex Jan Kara
2012-03-05 16:01 ` [PATCH 03/19] fat: " Jan Kara
2012-03-05 16:01 ` [PATCH 04/19] btrfs: " Jan Kara
     [not found] ` <1330963277-26336-1-git-send-email-jack-AlSwsSmVLrQ@public.gmane.org>
2012-03-05 16:01   ` [PATCH 05/19] nfsd: " Jan Kara
2012-03-05 16:01   ` [PATCH 14/19] fuse: Convert to new freezing mechanism Jan Kara
2012-03-05 16:01 ` [PATCH 06/19] fs: Improve filesystem freezing handling Jan Kara
2012-03-05 16:01 ` [PATCH 07/19] fs: Add freezing handling to mnt_want_write() / mnt_drop_write() Jan Kara
2012-03-05 16:01 ` [PATCH 08/19] fs: Skip atime update on frozen filesystem Jan Kara
2012-03-05 16:01 ` [PATCH 09/19] fs: Protect write paths by sb_start_write - sb_end_write Jan Kara
2012-03-05 16:01 ` [PATCH 10/19] ext4: Convert to new freezing mechanism Jan Kara
2012-03-07 22:32   ` Kamal Mostafa
2012-03-08  9:05     ` Jan Kara
2012-03-05 16:01 ` [PATCH 11/19] xfs: Convert to new freezing code Jan Kara
2012-03-08 23:20   ` Dave Chinner
2012-03-09  8:23     ` Jan Kara
2012-03-09 14:22     ` Jan Kara
2012-03-11 22:45       ` Dave Chinner
2012-03-12 17:55         ` Jan Kara
2012-03-12 23:48           ` Dave Chinner
2012-03-13 21:30             ` Jan Kara
2012-03-14  3:00               ` Dave Chinner
2012-03-05 16:01 ` [PATCH 12/19] ocfs2: Convert to new freezing mechanism Jan Kara
2012-03-05 16:01 ` [PATCH 13/19] gfs2: " Jan Kara
2012-03-05 16:01 ` [PATCH 15/19] ntfs: " Jan Kara
2012-03-05 16:01 ` [PATCH 16/19] nilfs2: " Jan Kara
2012-03-05 16:01 ` [PATCH 17/19] btrfs: " Jan Kara
2012-03-05 16:01 ` [PATCH 18/19] fs: Remove old " Jan Kara
2012-03-05 16:01 ` [PATCH 19/19] fs: Refuse to freeze filesystem with open but unlinked files Jan Kara
2012-03-11 20:22 ` [PATCH 00/19] Fix filesystem freezing deadlocks Kamal Mostafa
  -- strict thread matches above, loose matches on Subject: below --
2012-03-28 23:43 [PATCH 00/19 v4] " Jan Kara
2012-03-28 23:43 ` [PATCH 01/19] mm: Make default vm_ops provide ->page_mkwrite handler Jan Kara

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=20120328094856.GA18751@quack.suse.cz \
    --to=jack@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=david@fromorbit.com \
    --cc=dchinner@redhat.com \
    --cc=hch@infradead.org \
    --cc=kamal@canonical.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sandeen@redhat.com \
    --cc=viro@ZenIV.linux.org.uk \
    /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).