Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1617796

[PATCH 4.9 07/72] xfs: fix eofblocks race with file extending async dio writes

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.9 07/72] xfs: fix eofblocks race with file extending async dio writes
Date 2017-04-06 11:40 +0200
Message-ID <ttc3w-6L0-25@gated-at.bofh.it> (permalink)
References <ttbh7-6aP-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Brian Foster <bfoster@redhat.com>

commit e4229d6b0bc9280f29624faf170cf76a9f1ca60e upstream.

It's possible for post-eof blocks to end up being used for direct I/O
writes. dio write performs an upfront unwritten extent allocation, sends
the dio and then updates the inode size (if necessary) on write
completion. If a file release occurs while a file extending dio write is
in flight, it is possible to mistake the post-eof blocks for speculative
preallocation and incorrectly truncate them from the inode. This means
that the resulting dio write completion can discover a hole and allocate
new blocks rather than perform unwritten extent conversion.

This requires a strange mix of I/O and is thus not likely to reproduce
in real world workloads. It is intermittently reproduced by generic/299.
The error manifests as an assert failure due to transaction overrun
because the aforementioned write completion transaction has only
reserved enough blocks for btree operations:

  XFS: Assertion failed: tp->t_blk_res_used <= tp->t_blk_res, \
   file: fs/xfs//xfs_trans.c, line: 309

The root cause is that xfs_free_eofblocks() uses i_size to truncate
post-eof blocks from the inode, but async, file extending direct writes
do not update i_size until write completion, long after inode locks are
dropped. Therefore, xfs_free_eofblocks() effectively truncates the inode
to the incorrect size.

Update xfs_free_eofblocks() to serialize against dio similar to how
extending writes are serialized against i_size updates before post-eof
block zeroing. Specifically, wait on dio while under the iolock. This
ensures that dio write completions have updated i_size before post-eof
blocks are processed.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/xfs/xfs_bmap_util.c |    3 +++
 1 file changed, 3 insertions(+)

--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -959,6 +959,9 @@ xfs_free_eofblocks(
 		if (error)
 			return error;
 
+		/* wait on dio to ensure i_size has settled */
+		inode_dio_wait(VFS_I(ip));
+
 		error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0,
 				&tp);
 		if (error) {

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.9 00/72] 4.9.21-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:30 +0200
  [PATCH 4.9 24/72] xfs: tune down agno asserts in the bmap code Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:30 +0200
  [PATCH 4.9 07/72] xfs: fix eofblocks race with file extending async dio writes Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  [PATCH 4.9 10/72] xfs: filter out obviously bad btree pointers Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  [PATCH 4.9 01/72] libceph: force GFP_NOIO for socket allocations Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  [PATCH 4.9 05/72] xfs: pull up iolock from xfs_free_eofblocks() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  [PATCH 4.9 06/72] xfs: sync eofblocks scans under iolock are livelock prone Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-04-06 11:40 +0200
  Re: [PATCH 4.9 00/72] 4.9.21-stable review Shuah Khan <shuahkh@osg.samsung.com> - 2017-04-06 19:50 +0200
  Re: [PATCH 4.9 00/72] 4.9.21-stable review Guenter Roeck <linux@roeck-us.net> - 2017-04-07 00:00 +0200

csiph-web