]> www.infradead.org Git - users/jedix/linux-maple.git/commit
ext4: fix races between page faults and hole punching
authorJan Kara <jack@suse.com>
Mon, 7 Dec 2015 19:28:03 +0000 (14:28 -0500)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 26 May 2016 22:45:44 +0000 (15:45 -0700)
commit88080088ce54f35a8e8b7e9994c4f5d43c39be0c
tree537f1c35608fc2c9899b1f8afd169fae2bc98d80
parentea8ca021bcaeda8c02cfa353d4238d6cb1c498f8
ext4: fix races between page faults and hole punching

Orabug: 23331007

Currently, page faults and hole punching are completely unsynchronized.
This can result in page fault faulting in a page into a range that we
are punching after truncate_pagecache_range() has been called and thus
we can end up with a page mapped to disk blocks that will be shortly
freed. Filesystem corruption will shortly follow. Note that the same
race is avoided for truncate by checking page fault offset against
i_size but there isn't similar mechanism available for punching holes.

Fix the problem by creating new rw semaphore i_mmap_sem in inode and
grab it for writing over truncate, hole punching, and other functions
removing blocks from extent tree and for read over page faults. We
cannot easily use i_data_sem for this since that ranks below transaction
start and we need something ranking above it so that it can be held over
the whole truncate / hole punching operation. Also remove various
workarounds we had in the code to reduce race window when page fault
could have created pages with stale mapping information.

Signed-off-by: Jan Kara <jack@suse.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Mingming Cao <mingming.cao@oracle.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
(cherry picked from commit 248766f068fd1d3d95479f470bc926d1136141d6)

Signed-off-by: Dan Duval <dan.duval@oracle.com>
fs/ext4/ext4.h
fs/ext4/extents.c
fs/ext4/file.c
fs/ext4/inode.c
fs/ext4/super.c
fs/ext4/truncate.h