android_kernel_samsung_univ.../fs/xfs
Amir Goldstein 66824bdf4c xfs: fix incorrect log_flushed on fsync
commit 47c7d0b19502583120c3f396c7559e7a77288a68 upstream.

When calling into _xfs_log_force{,_lsn}() with a pointer
to log_flushed variable, log_flushed will be set to 1 if:
1. xlog_sync() is called to flush the active log buffer
AND/OR
2. xlog_wait() is called to wait on a syncing log buffers

xfs_file_fsync() checks the value of log_flushed after
_xfs_log_force_lsn() call to optimize away an explicit
PREFLUSH request to the data block device after writing
out all the file's pages to disk.

This optimization is incorrect in the following sequence of events:

 Task A                    Task B
 -------------------------------------------------------
 xfs_file_fsync()
   _xfs_log_force_lsn()
     xlog_sync()
        [submit PREFLUSH]
                           xfs_file_fsync()
                             file_write_and_wait_range()
                               [submit WRITE X]
                               [endio  WRITE X]
                             _xfs_log_force_lsn()
                               xlog_wait()
        [endio  PREFLUSH]

The write X is not guarantied to be on persistent storage
when PREFLUSH request in completed, because write A was submitted
after the PREFLUSH request, but xfs_file_fsync() of task A will
be notified of log_flushed=1 and will skip explicit flush.

If the system crashes after fsync of task A, write X may not be
present on disk after reboot.

This bug was discovered and demonstrated using Josef Bacik's
dm-log-writes target, which can be used to record block io operations
and then replay a subset of these operations onto the target device.
The test goes something like this:
- Use fsx to execute ops of a file and record ops on log device
- Every now and then fsync the file, store md5 of file and mark
  the location in the log
- Then replay log onto device for each mark, mount fs and compare
  md5 of file to stored value

Cc: Christoph Hellwig <hch@lst.de>
Cc: Josef Bacik <jbacik@fb.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
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>
2018-06-13 16:15:27 +02:00
..
libxfs xfs: detect agfl count corruption and reset agfl 2018-06-06 16:46:20 +02:00
Kconfig
kmem.c xfs: remove kmem_zalloc_greedy 2017-10-08 10:14:20 +02:00
kmem.h xfs: remove kmem_zalloc_greedy 2017-10-08 10:14:20 +02:00
Makefile xfs: stats are no longer dependent on CONFIG_PROC_FS 2015-10-19 08:42:46 +11:00
mrlock.h
uuid.c
uuid.h
xfs_acl.c posix_acl: Clear SGID bit when setting file permissions 2016-10-31 04:13:58 -06:00
xfs_acl.h xfs: Fix error path in xfs_get_acl 2015-11-10 10:09:45 +11:00
xfs_aops.c xfs: ubsan fixes 2018-02-03 17:04:29 +01:00
xfs_aops.h xfs: DAX does not use IO completion callbacks 2015-11-03 12:37:02 +11:00
xfs_attr_inactive.c
xfs_attr_list.c xfs: only return -errno or success from attr ->put_listent 2017-06-07 12:06:03 +02:00
xfs_attr.h xfs: only return -errno or success from attr ->put_listent 2017-06-07 12:06:03 +02:00
xfs_bmap_util.c xfs: bad assertion for delalloc an extent that start at i_size 2017-06-07 12:06:02 +02:00
xfs_bmap_util.h
xfs_buf_item.c
xfs_buf_item.h
xfs_buf.c xfs: fix up quotacheck buffer list error handling 2017-06-07 12:06:02 +02:00
xfs_buf.h xfs: fix up quotacheck buffer list error handling 2017-06-07 12:06:02 +02:00
xfs_dir2_readdir.c xfs: prevent multi-fsb dir readahead from reading random blocks 2017-06-07 12:06:02 +02:00
xfs_discard.c Force log to disk before reading the AGF during a fstrim 2018-05-30 07:49:07 +02:00
xfs_discard.h
xfs_dquot_item.c
xfs_dquot_item.h
xfs_dquot.c xfs: per-filesystem stats counter implementation 2015-10-12 18:21:22 +11:00
xfs_dquot.h
xfs_error.c xfs: print name of verifier if it fails 2016-06-07 18:14:38 -07:00
xfs_error.h
xfs_export.c
xfs_export.h
xfs_extent_busy.c
xfs_extent_busy.h
xfs_extfree_item.c
xfs_extfree_item.h
xfs_file.c xfs: prevent creating negative-sized file via INSERT_RANGE 2018-05-16 10:06:48 +02:00
xfs_filestream.c
xfs_filestream.h
xfs_fsops.c xfs: Don't wrap growfs AGFL indexes 2016-06-07 18:14:38 -07:00
xfs_fsops.h
xfs_globals.c
xfs_icache.c xfs: update ag iterator to support wait on new inodes 2017-06-07 12:06:02 +02:00
xfs_icache.h xfs: update ag iterator to support wait on new inodes 2017-06-07 12:06:02 +02:00
xfs_icreate_item.c
xfs_icreate_item.h
xfs_inode_item.c xfs: optimise away log forces on timestamp updates for fdatasync 2015-11-03 13:14:59 +11:00
xfs_inode_item.h xfs: optimise away log forces on timestamp updates for fdatasync 2015-11-03 13:14:59 +11:00
xfs_inode.c xfs: skip stale inodes in xfs_iflush_cluster 2016-06-07 18:14:38 -07:00
xfs_inode.h xfs: support ability to wait on new inodes 2017-06-07 12:06:02 +02:00
xfs_ioctl.c xfs: in _attrlist_by_handle, copy the cursor back to userspace 2017-06-07 12:06:03 +02:00
xfs_ioctl.h
xfs_ioctl32.c xfs: prefix XATTR_LIST_MAX with XFS_ 2015-10-12 16:02:56 +11:00
xfs_ioctl32.h
xfs_iomap.c Merge branch 'xfs-dax-updates' into for-next 2015-11-03 13:28:41 +11:00
xfs_iomap.h
xfs_iops.c xfs: per-filesystem stats counter implementation 2015-10-12 18:21:22 +11:00
xfs_iops.h
xfs_itable.c xfs: remove kmem_zalloc_greedy 2017-10-08 10:14:20 +02:00
xfs_itable.h
xfs_linux.h xfs: XFS_IS_REALTIME_INODE() should be false if no rt device present 2017-09-13 14:09:46 -07:00
xfs_log_cil.c
xfs_log_priv.h
xfs_log_recover.c xfs: fix log block underflow during recovery cycle verification 2017-12-20 10:04:59 +01:00
xfs_log.c xfs: fix incorrect log_flushed on fsync 2018-06-13 16:15:27 +02:00
xfs_log.h
xfs_message.c xfs: more info from kmem deadlocks and high-level error msgs 2015-10-12 16:04:45 +11:00
xfs_message.h
xfs_mount.c Merge branch 'xfs-misc-fixes-for-4.4-2' into for-next 2015-11-03 13:27:58 +11:00
xfs_mount.h xfs: detect agfl count corruption and reset agfl 2018-06-06 16:46:20 +02:00
xfs_mru_cache.c
xfs_mru_cache.h
xfs_pnfs.c
xfs_pnfs.h
xfs_qm_bhv.c
xfs_qm_syscalls.c xfs: wait on new inodes during quotaoff dquot release 2017-06-07 12:06:02 +02:00
xfs_qm.c xfs: quota: check result of register_shrinker() 2018-03-03 10:19:44 +01:00
xfs_qm.h
xfs_quota.h
xfs_quotaops.c
xfs_rtalloc.c
xfs_rtalloc.h
xfs_stats.c xfs: stats are no longer dependent on CONFIG_PROC_FS 2015-10-19 08:42:46 +11:00
xfs_stats.h xfs: per-filesystem stats counter implementation 2015-10-12 18:21:22 +11:00
xfs_super.c xfs: disallow rw remount on fs with unknown ro-compat features 2016-06-07 18:14:38 -07:00
xfs_super.h
xfs_symlink.c
xfs_symlink.h
xfs_sysctl.c
xfs_sysctl.h
xfs_sysfs.c
xfs_sysfs.h
xfs_trace.c
xfs_trace.h xfs: detect agfl count corruption and reset agfl 2018-06-06 16:46:20 +02:00
xfs_trans_ail.c Revert "xfs: clear PF_NOFREEZE for xfsaild kthread" 2016-02-25 12:01:24 -08:00
xfs_trans_buf.c
xfs_trans_dquot.c
xfs_trans_extfree.c
xfs_trans_inode.c xfs: optimise away log forces on timestamp updates for fdatasync 2015-11-03 13:14:59 +11:00
xfs_trans_priv.h
xfs_trans.c xfs: per-filesystem stats counter implementation 2015-10-12 18:21:22 +11:00
xfs_trans.h
xfs_xattr.c Make __xfs_xattr_put_listen preperly report errors. 2017-06-14 13:16:27 +02:00
xfs.h