Commit 84209e02 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Linus Torvalds

mm: dont clear PG_uptodate on truncate/invalidate

Brian Wang reported that a FUSE filesystem exported through NFS could
return I/O errors on read.  This was traced to splice_direct_to_actor()
returning a short or zero count when racing with page invalidation.

However this is not FUSE or NFSD specific, other filesystems (notably
NFS) also call invalidate_inode_pages2() to purge stale data from the
cache.

If this happens while such pages are sitting in a pipe buffer, then
splice(2) from the pipe can return zero, and read(2) from the pipe can
return ENODATA.

The zero return is especially bad, since it implies end-of-file or
disconnected pipe/socket, and is documented as such for splice.  But
returning an error for read() is also nasty, when in fact there was no
error (data becoming stale is not an error).

The same problems can be triggered by "hole punching" with
madvise(MADV_REMOVE).

Fix this by not clearing the PG_uptodate flag on truncation and
invalidation.
Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
Acked-by: default avatarNick Piggin <nickpiggin@yahoo.com.au>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2b12a4c5
...@@ -104,7 +104,6 @@ truncate_complete_page(struct address_space *mapping, struct page *page) ...@@ -104,7 +104,6 @@ truncate_complete_page(struct address_space *mapping, struct page *page)
cancel_dirty_page(page, PAGE_CACHE_SIZE); cancel_dirty_page(page, PAGE_CACHE_SIZE);
remove_from_page_cache(page); remove_from_page_cache(page);
ClearPageUptodate(page);
ClearPageMappedToDisk(page); ClearPageMappedToDisk(page);
page_cache_release(page); /* pagecache ref */ page_cache_release(page); /* pagecache ref */
} }
...@@ -356,7 +355,6 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page) ...@@ -356,7 +355,6 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)
BUG_ON(PagePrivate(page)); BUG_ON(PagePrivate(page));
__remove_from_page_cache(page); __remove_from_page_cache(page);
spin_unlock_irq(&mapping->tree_lock); spin_unlock_irq(&mapping->tree_lock);
ClearPageUptodate(page);
page_cache_release(page); /* pagecache ref */ page_cache_release(page); /* pagecache ref */
return 1; return 1;
failed: failed:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment