* [PATCH] xfs: fix crash and data corruption due to removal of busy COW extents
@ 2017-01-01 8:13 Christoph Hellwig
2017-01-04 5:53 ` Darrick J. Wong
0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2017-01-01 8:13 UTC (permalink / raw)
To: linux-xfs; +Cc: darrick.wong
There is a race window between write_cache_pages calling
clear_page_dirty_for_io and XFS calling set_page_writeback, in which
the mapping for an inode is tagged neither as dirty, nor as writeback.
If the COW shrinker hits in exactly that window we'll remove the delayed
COW extents and writepages trying to write it back, which in release
kernels will manifest as corruption of the bmap btree, and in debug
kernels will trip the ASSERT about now calling xfs_bmapi_write with the
COWFORK flag for holes. A complex customer load manages to hit this
window fairly reliably, probably by always having COW writeback in flight
while the cow shrinker runs.
This patch adds another check for having the I_DIRTY_PAGES flag set,
which is still set during this race window. While this fixes the problem
I'm still not overly happy about the way the COW shrinker works as it
still seems a bit fragile.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/xfs/xfs_icache.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index f295049..2d5a63a 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -1593,7 +1593,8 @@ xfs_inode_free_cowblocks(
* If the mapping is dirty or under writeback we cannot touch the
* CoW fork. Leave it alone if we're in the midst of a directio.
*/
- if (mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_DIRTY) ||
+ if ((VFS_I(ip)->i_state & I_DIRTY_PAGES) ||
+ mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_DIRTY) ||
mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_WRITEBACK) ||
atomic_read(&VFS_I(ip)->i_dio_count))
return 0;
--
2.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] xfs: fix crash and data corruption due to removal of busy COW extents
2017-01-01 8:13 [PATCH] xfs: fix crash and data corruption due to removal of busy COW extents Christoph Hellwig
@ 2017-01-04 5:53 ` Darrick J. Wong
0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2017-01-04 5:53 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-xfs
On Sun, Jan 01, 2017 at 11:13:06AM +0300, Christoph Hellwig wrote:
> There is a race window between write_cache_pages calling
> clear_page_dirty_for_io and XFS calling set_page_writeback, in which
> the mapping for an inode is tagged neither as dirty, nor as writeback.
>
> If the COW shrinker hits in exactly that window we'll remove the delayed
> COW extents and writepages trying to write it back, which in release
> kernels will manifest as corruption of the bmap btree, and in debug
> kernels will trip the ASSERT about now calling xfs_bmapi_write with the
> COWFORK flag for holes. A complex customer load manages to hit this
> window fairly reliably, probably by always having COW writeback in flight
> while the cow shrinker runs.
>
> This patch adds another check for having the I_DIRTY_PAGES flag set,
> which is still set during this race window. While this fixes the problem
> I'm still not overly happy about the way the COW shrinker works as it
> still seems a bit fragile.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/xfs/xfs_icache.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
> index f295049..2d5a63a 100644
> --- a/fs/xfs/xfs_icache.c
> +++ b/fs/xfs/xfs_icache.c
> @@ -1593,7 +1593,8 @@ xfs_inode_free_cowblocks(
> * If the mapping is dirty or under writeback we cannot touch the
> * CoW fork. Leave it alone if we're in the midst of a directio.
> */
> - if (mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_DIRTY) ||
> + if ((VFS_I(ip)->i_state & I_DIRTY_PAGES) ||
> + mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_DIRTY) ||
> mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_WRITEBACK) ||
> atomic_read(&VFS_I(ip)->i_dio_count))
> return 0;
Applied, thx.
--D
> --
> 2.1.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-04 5:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-01 8:13 [PATCH] xfs: fix crash and data corruption due to removal of busy COW extents Christoph Hellwig
2017-01-04 5:53 ` Darrick J. Wong
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).