kernel-ark/fs/ocfs2
Nick Piggin d00806b183 mm: fix fault vs invalidate race for linear mappings
Fix the race between invalidate_inode_pages and do_no_page.

Andrea Arcangeli identified a subtle race between invalidation of pages from
pagecache with userspace mappings, and do_no_page.

The issue is that invalidation has to shoot down all mappings to the page,
before it can be discarded from the pagecache.  Between shooting down ptes to
a particular page, and actually dropping the struct page from the pagecache,
do_no_page from any process might fault on that page and establish a new
mapping to the page just before it gets discarded from the pagecache.

The most common case where such invalidation is used is in file truncation.
This case was catered for by doing a sort of open-coded seqlock between the
file's i_size, and its truncate_count.

Truncation will decrease i_size, then increment truncate_count before
unmapping userspace pages; do_no_page will read truncate_count, then find the
page if it is within i_size, and then check truncate_count under the page
table lock and back out and retry if it had subsequently been changed (ptl
will serialise against unmapping, and ensure a potentially updated
truncate_count is actually visible).

Complexity and documentation issues aside, the locking protocol fails in the
case where we would like to invalidate pagecache inside i_size.  do_no_page
can come in anytime and filemap_nopage is not aware of the invalidation in
progress (as it is when it is outside i_size).  The end result is that
dangling (->mapping == NULL) pages that appear to be from a particular file
may be mapped into userspace with nonsense data.  Valid mappings to the same
place will see a different page.

Andrea implemented two working fixes, one using a real seqlock, another using
a page->flags bit.  He also proposed using the page lock in do_no_page, but
that was initially considered too heavyweight.  However, it is not a global or
per-file lock, and the page cacheline is modified in do_no_page to increment
_count and _mapcount anyway, so a further modification should not be a large
performance hit.  Scalability is not an issue.

This patch implements this latter approach.  ->nopage implementations return
with the page locked if it is possible for their underlying file to be
invalidated (in that case, they must set a special vm_flags bit to indicate
so).  do_no_page only unlocks the page after setting up the mapping
completely.  invalidation is excluded because it holds the page lock during
invalidation of each page (and ensures that the page is not mapped while
holding the lock).

This also allows significant simplifications in do_no_page, because we have
the page locked in the right place in the pagecache from the start.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 10:04:41 -07:00
..
cluster Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mfasheh/ocfs2 2007-07-16 10:52:55 -07:00
dlm [KJ PATCH] Replacing memset(<addr>,0,PAGE_SIZE) with clear_page() in fs/ocfs2/dlm/dlmrecovery.c 2007-07-10 17:19:52 -07:00
alloc.c ocfs2: support for removing file regions 2007-07-10 17:32:08 -07:00
alloc.h ocfs2: support for removing file regions 2007-07-10 17:32:08 -07:00
aops.c [PATCH] ocfs2: zero_user_page conversion 2007-07-10 17:32:10 -07:00
aops.h ocfs2: shared writeable mmap 2007-07-10 17:31:51 -07:00
buffer_head_io.c
buffer_head_io.h
dcache.c
dcache.h
dir.c ocfs2: Support creation of unwritten extents 2007-07-10 17:32:04 -07:00
dir.h
dlmglue.c [PATCH] ocfs2: use list_for_each_entry where benefical 2007-07-10 17:19:49 -07:00
dlmglue.h [PATCH] fs/ocfs2/: make 3 functions static 2007-05-02 15:07:27 -07:00
endian.h ocfs2: btree changes for unwritten extents 2007-07-10 17:32:00 -07:00
export.c ocfs2: fix sparse warnings in fs/ocfs2 2007-05-02 15:08:08 -07:00
export.h knfsd: exportfs: add exportfs.h header 2007-07-17 10:23:06 -07:00
extent_map.c ocfs2: btree changes for unwritten extents 2007-07-10 17:32:00 -07:00
extent_map.h ocfs2: Cache extent records 2007-04-26 15:10:40 -07:00
file.c arch/i386/* fs/* ipc/*: mark variables with uninitialized_var() 2007-07-17 16:23:19 -04:00
file.h ocfs2: Support xfs style space reservation ioctls 2007-07-10 17:32:09 -07:00
heartbeat.c usermodehelper: Tidy up waiting 2007-07-18 08:47:40 -07:00
heartbeat.h
inode.c header cleaning: don't include smp_lock.h when not used 2007-05-08 11:15:07 -07:00
inode.h [PATCH] Copy i_flags to ocfs2 inode flags on write 2007-05-02 15:07:58 -07:00
ioctl.c Introduce is_owner_or_cap() to wrap CAP_FOWNER use with fsuid check 2007-07-17 12:00:03 -07:00
ioctl.h ocfs2: Implement compat_ioctl() 2007-05-02 15:07:16 -07:00
journal.c [PATCH] ocfs2: use list_for_each_entry where benefical 2007-07-10 17:19:49 -07:00
journal.h ocfs2: support for removing file regions 2007-07-10 17:32:08 -07:00
localalloc.c ocfs2: fix inode leak 2007-05-25 11:00:46 -07:00
localalloc.h
Makefile
mmap.c mm: fix fault vs invalidate race for linear mappings 2007-07-19 10:04:41 -07:00
mmap.h
namei.c ocfs2: Support creation of unwritten extents 2007-07-10 17:32:04 -07:00
namei.h [PATCH] mark struct inode_operations const 2 2007-02-12 09:48:46 -08:00
ocfs1_fs_compat.h
ocfs2_fs.h ocfs2: Support xfs style space reservation ioctls 2007-07-10 17:32:09 -07:00
ocfs2_lockid.h ocfs2: Remove delete inode vote 2007-04-26 14:39:48 -07:00
ocfs2.h ocfs2: btree changes for unwritten extents 2007-07-10 17:32:00 -07:00
slot_map.c ocfs2: Add "preferred slot" mount option 2007-07-10 17:19:54 -07:00
slot_map.h
suballoc.c ocfs2: use all extent block suballocators 2007-07-10 17:31:56 -07:00
suballoc.h ocfs2: plug truncate into cached dealloc routines 2007-07-10 17:31:55 -07:00
super.c ocfs2: Support xfs style space reservation ioctls 2007-07-10 17:32:09 -07:00
super.h ocfs2: Support xfs style space reservation ioctls 2007-07-10 17:32:09 -07:00
symlink.c mm: make read_cache_page synchronous 2007-05-07 12:12:51 -07:00
symlink.h [PATCH] mark struct inode_operations const 2 2007-02-12 09:48:46 -08:00
sysfile.c
sysfile.h
uptodate.c
uptodate.h
ver.c
ver.h
vote.c header cleaning: don't include smp_lock.h when not used 2007-05-08 11:15:07 -07:00
vote.h ocfs2: remove unused code 2007-04-26 14:40:16 -07:00