linux/fs/xfs
Brian Foster 96cbb7e99d xfs: don't BUG() on mixed direct and mapped I/O
commit 04197b341f upstream.

We've had reports of generic/095 causing XFS to BUG() in
__xfs_get_blocks() due to the existence of delalloc blocks on a
direct I/O read. generic/095 issues a mix of various types of I/O,
including direct and memory mapped I/O to a single file. This is
clearly not supported behavior and is known to lead to such
problems. E.g., the lack of exclusion between the direct I/O and
write fault paths means that a write fault can allocate delalloc
blocks in a region of a file that was previously a hole after the
direct read has attempted to flush/inval the file range, but before
it actually reads the block mapping. In turn, the direct read
discovers a delalloc extent and cannot proceed.

While the appropriate solution here is to not mix direct and memory
mapped I/O to the same regions of the same file, the current
BUG_ON() behavior is probably overkill as it can crash the entire
system.  Instead, localize the failure to the I/O in question by
returning an error for a direct I/O that cannot be handled safely
due to delalloc blocks. Be careful to allow the case of a direct
write to post-eof delalloc blocks. This can occur due to speculative
preallocation and is safe as post-eof blocks are not accompanied by
dirty pages in pagecache (conversely, preallocation within eof must
have been zeroed, and thus dirtied, before the inode size could have
been increased beyond said blocks).

Finally, provide an additional warning if a direct I/O write occurs
while the file is memory mapped. This may not catch all problematic
scenarios, but provides a hint that some known-to-be-problematic I/O
methods are in use.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
[bwh: Backported to 3.16:
 - Assign positive error code to error variable
 - Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
History 2019-03-25 17:32:31 +00:00
..
Kconfig xfs: introduce CONFIG_XFS_WARN 2013-05-07 18:45:36 -05:00
kmem.c xfs: use NOIO contexts for vm_map_ram 2014-03-07 16:19:14 +11:00
kmem.h xfs: simplify kmem_{zone_}zalloc 2013-11-06 16:31:27 -06:00
Makefile xfs: abstract the differences in dir2/dir3 via an ops vector 2013-10-30 13:37:38 -05:00
mrlock.h xfs: introduce CONFIG_XFS_WARN 2013-05-07 18:45:36 -05:00
time.h xfs: remove subdirectories 2011-08-12 16:21:35 -05:00
uuid.c xfs: remove subdirectories 2011-08-12 16:21:35 -05:00
uuid.h xfs: add CRC infrastructure 2012-11-19 20:11:24 -06:00
xfs.h xfs: introduce CONFIG_XFS_WARN 2013-05-07 18:45:36 -05:00
xfs_acl.c xfs: Don't clear SGID when inheriting ACLs 2017-10-12 15:27:53 +01:00
xfs_acl.h xfs: Don't clear SGID when inheriting ACLs 2017-10-12 15:27:53 +01:00
xfs_ag.h libxfs: pack the agfl header structure so XFS_AGFL_SIZE is correct 2016-02-02 19:09:15 +00:00
xfs_alloc.c xfs: Fix rounding in xfs_alloc_fix_len() 2014-06-06 16:06:37 +10:00
xfs_alloc.h xfs: create a shared header file for format-related information 2013-10-23 14:11:30 -05:00
xfs_alloc_btree.c xfs: remove unused length arg from alloc_block ops 2014-04-14 19:03:53 +10:00
xfs_alloc_btree.h xfs: decouple inode and bmap btree header files 2013-10-23 16:28:49 -05:00
xfs_aops.c xfs: don't BUG() on mixed direct and mapped I/O 2019-03-25 17:32:31 +00:00
xfs_aops.h direct-io: Implement generic deferred AIO completions 2013-09-04 09:23:46 -04:00
xfs_attr.c xfs: don't fail when converting shortform attr to long form during ATTR_REPLACE 2018-12-16 22:09:46 +00:00
xfs_attr.h xfs: kill xfs_vnodeops.[ch] 2013-08-12 16:53:39 -05:00
xfs_attr_inactive.c xfs: don't truncate attribute extents if no extents exist 2015-07-15 10:00:48 +01:00
xfs_attr_leaf.c xfs: don't call xfs_da_shrink_inode with NULL bp 2018-09-25 23:47:33 +01:00
xfs_attr_leaf.h xfs: xfs_attr_inactive leaves inconsistent attr fork state behind 2015-06-03 14:30:04 +01:00
xfs_attr_list.c xfs: fix two memory leaks in xfs_attr_list.c error paths 2016-05-01 00:05:52 +02:00
xfs_attr_remote.c xfs: remote attributes need to be considered data 2015-08-25 10:13:41 +01:00
xfs_attr_remote.h xfs: unify directory/attribute format definitions 2013-10-23 14:21:40 -05:00
xfs_attr_sf.h xfs: convert attr to use unsigned names 2010-01-20 10:47:48 +11:00
xfs_bit.c xfs: fix static and extern sparse warnings 2013-10-30 13:59:56 -05:00
xfs_bit.h xfs: small cleanup in xfs_lowbit64() 2014-06-06 16:04:42 +10:00
xfs_bmap.c xfs: set format back to extents if xfs_bmap_extents_to_btree 2018-09-25 23:47:26 +01:00
xfs_bmap.h xfs: refine the allocation stack switch 2014-07-15 07:08:24 +10:00
xfs_bmap_btree.c xfs: remove unused length arg from alloc_block ops 2014-04-14 19:03:53 +10:00
xfs_bmap_btree.h xfs: remove unused mp arg from xfs_bmdr_maxrecs() 2014-04-14 18:58:51 +10:00
xfs_bmap_util.c xfs: fix up xfs_swap_extent_forks inline extent handling 2017-03-16 02:26:19 +00:00
xfs_bmap_util.h xfs: refine the allocation stack switch 2014-07-15 07:08:24 +10:00
xfs_btree.c xfs: refine the allocation stack switch 2014-07-15 07:08:24 +10:00
xfs_btree.h Merge branch 'xfs-free-inode-btree' into for-next 2014-05-15 09:37:44 +10:00
xfs_buf.c xfs: inode recovery readahead can race with inode buffer creation 2016-02-02 19:09:27 +00:00
xfs_buf.h Merge branch 'xfs-misc-fixes-3-for-3.16' into for-next 2014-06-10 07:32:56 +10:00
xfs_buf_item.c xfs: ensure buffer types are set correctly 2015-02-24 10:01:07 +00:00
xfs_buf_item.h xfs: decouple inode and bmap btree header files 2013-10-23 16:28:49 -05:00
xfs_cksum.h xfs: add CRC infrastructure 2012-11-19 20:11:24 -06:00
xfs_da_btree.c Merge branch 'xfs-da-geom' into for-next 2014-06-10 07:32:41 +10:00
xfs_da_btree.h xfs: remove redundant geometry information from xfs_da_state 2014-06-06 15:22:04 +10:00
xfs_da_format.c xfs: convert m_dirblksize to xfs_da_geometry 2014-06-06 15:15:59 +10:00
xfs_da_format.h xfs: Fix xfs_attr_leafblock definition 2015-09-28 10:21:46 +01:00
xfs_dinode.h xfs: XFS_IS_REALTIME_INODE() should be false if no rt device present 2017-10-12 15:28:11 +01:00
xfs_dir2.c Merge branch 'xfs-da-geom' into for-next 2014-06-10 07:32:41 +10:00
xfs_dir2.h xfs: remove mp->m_dir_geo from directory logging 2014-06-06 15:20:54 +10:00
xfs_dir2_block.c xfs: remove mp->m_dir_geo from directory logging 2014-06-06 15:20:54 +10:00
xfs_dir2_data.c libxfs: readahead of dir3 data blocks should use the read verifier 2015-09-28 10:21:45 +01:00
xfs_dir2_leaf.c xfs: remove mp->m_dir_geo from directory logging 2014-06-06 15:20:54 +10:00
xfs_dir2_node.c xfs: Fix file type directory corruption for btree directories 2015-09-28 10:21:47 +01:00
xfs_dir2_priv.h xfs: remove mp->m_dir_geo from directory logging 2014-06-06 15:20:54 +10:00
xfs_dir2_readdir.c xfs: fix xfs_da_args sparse warning in xfs_readdir 2014-06-10 07:30:36 +10:00
xfs_dir2_sf.c xfs: convert m_dirblksize to xfs_da_geometry 2014-06-06 15:15:59 +10:00
xfs_discard.c xfs: don't perform discard if the given range length is less than block size 2013-12-10 10:00:33 -06:00
xfs_discard.h xfs: remove subdirectories 2011-08-12 16:21:35 -05:00
xfs_dquot.c xfs: quotacheck leaves dquot buffers without verifiers 2014-09-17 09:22:17 -07:00
xfs_dquot.h xfs: remove dquot hints 2014-05-05 17:30:15 +10:00
xfs_dquot_buf.c xfs: handle dquot buffer readahead in log recovery correctly 2016-02-02 19:09:28 +00:00
xfs_dquot_item.c xfs: remove the quotaoff log format from the quotaoff log item 2013-12-13 11:34:08 +11:00
xfs_dquot_item.h xfs: remove the quotaoff log format from the quotaoff log item 2013-12-13 11:34:08 +11:00
xfs_error.c xfs: print useful caller information in xfs_error_report 2014-02-27 15:21:37 +11:00
xfs_error.h xfs: add xfs_verifier_error() 2014-02-27 15:21:07 +11:00
xfs_export.c xfs: xfs_commit_metadata returns wrong errno 2014-05-15 09:21:52 +10:00
xfs_export.h xfs: remove subdirectories 2011-08-12 16:21:35 -05:00
xfs_extent_busy.c xfs: decouple inode and bmap btree header files 2013-10-23 16:28:49 -05:00
xfs_extent_busy.h xfs: decouple inode and bmap btree header files 2013-10-23 16:28:49 -05:00
xfs_extfree_item.c xfs: format log items write directly into the linear CIL buffer 2013-12-13 11:34:02 +11:00
xfs_extfree_item.h xfs: split out EFI/EFD log item format definition 2013-08-12 16:07:13 -05:00
xfs_file.c mm: drop vm_ops->remap_pages and generic_file_remap_pages() stub 2018-10-03 04:09:51 +01:00
xfs_filestream.c xfs: add filestream allocator tracepoints 2014-04-23 07:11:52 +10:00
xfs_filestream.h xfs: add filestream allocator tracepoints 2014-04-23 07:11:52 +10:00
xfs_format.h xfs: support the XFS_BTNUM_FINOBT free inode btree type 2014-04-24 16:00:52 +10:00
xfs_fs.h xfs: report finobt status in fs geometry 2014-04-24 16:01:41 +10:00
xfs_fsops.c Merge branch 'xfs-da-geom' into for-next 2014-06-10 07:32:41 +10:00
xfs_fsops.h xfs: ensure log covering transactions are synchronous 2011-01-11 20:28:17 -06:00
xfs_globals.c xfs: add background scanning to clear eofblocks inodes 2012-11-08 15:34:59 -06:00
xfs_ialloc.c xfs: fix inobt inode allocation search optimization 2017-11-11 13:33:20 +00:00
xfs_ialloc.h xfs: fix compile error when libxfs header used in C++ code 2014-05-20 08:52:21 +10:00
xfs_ialloc_btree.c Merge branch 'xfs-free-inode-btree' into for-next 2014-05-15 09:37:44 +10:00
xfs_ialloc_btree.h xfs: refactor xfs_ialloc_btree.c to support multiple inobt numbers 2014-04-24 16:00:50 +10:00
xfs_icache.c xfs: validate cached inodes are free when allocated 2018-09-25 23:47:33 +01:00
xfs_icache.h xfs: remove unused pag ptr arg from iterator execute functions 2014-04-14 19:04:19 +10:00
xfs_icreate_item.c xfs: format log items write directly into the linear CIL buffer 2013-12-13 11:34:02 +11:00
xfs_icreate_item.h xfs: separate icreate log format definitions from xfs_icreate_item.h 2013-08-12 16:10:35 -05:00
xfs_inode.c xfs: Propagate dentry down to inode_change_ok() 2017-02-23 03:53:52 +00:00
xfs_inode.h xfs: introduce mmap/truncate lock 2016-06-15 21:29:33 +01:00
xfs_inode_buf.c xfs: handle dquot buffer readahead in log recovery correctly 2016-02-02 19:09:28 +00:00
xfs_inode_buf.h xfs: create a shared header file for format-related information 2013-10-23 14:11:30 -05:00
xfs_inode_fork.c xfs: remove unused bp arg from xfs_iflush_fork() 2014-04-14 19:04:46 +10:00
xfs_inode_fork.h xfs: remove unused bp arg from xfs_iflush_fork() 2014-04-14 19:04:46 +10:00
xfs_inode_item.c xfs: turn NLINK feature on by default 2014-05-20 07:46:40 +10:00
xfs_inode_item.h xfs: remove the inode log format from the inode log item 2013-12-13 11:34:05 +11:00
xfs_inum.h xfs: move xfsagino_t to xfs_types.h 2012-05-14 16:20:54 -05:00
xfs_ioctl.c xfs: Propagate dentry down to inode_change_ok() 2017-02-23 03:53:52 +00:00
xfs_ioctl.h xfs: consolidate extent swap code 2013-08-12 16:56:06 -05:00
xfs_ioctl32.c xfs: Fix wrong error codes being returned 2014-05-05 17:30:20 +10:00
xfs_ioctl32.h xfs: remove subdirectories 2011-08-12 16:21:35 -05:00
xfs_iomap.c xfs: refine the allocation stack switch 2014-07-15 07:08:24 +10:00
xfs_iomap.h xfs: get rid of count from xfs_iomap_write_allocate() 2013-10-01 15:42:34 -05:00
xfs_iops.c xfs: Don't clear SGID when inheriting ACLs 2017-10-12 15:27:53 +01:00
xfs_iops.h xfs: Propagate dentry down to inode_change_ok() 2017-02-23 03:53:52 +00:00
xfs_itable.c xfs: refactor xfs_ialloc_btree.c to support multiple inobt numbers 2014-04-24 16:00:50 +10:00
xfs_itable.h xfs: remove block number from inode lookup code 2010-06-24 11:35:17 +10:00
xfs_linux.h xfs: add xfs_verifier_error() 2014-02-27 15:21:07 +11:00
xfs_log.c xfs: fix incorrect log_flushed on fsync 2017-11-26 13:50:29 +00:00
xfs_log.h xfs: log vector rounding leaks log space 2014-05-20 08:18:09 +10:00
xfs_log_cil.c Merge branch 'xfs-misc-fixes-2-for-3.16' into for-next 2014-05-20 08:56:00 +10:00
xfs_log_format.h xfs: create a shared header file for format-related information 2013-10-23 14:11:30 -05:00
xfs_log_priv.h xfs: decouple log and transaction headers 2013-10-23 16:17:44 -05:00
xfs_log_recover.c xfs: set AGI buffer type in xlog_recover_clear_agi_bucket 2017-03-16 02:26:28 +00:00
xfs_log_recover.h xfs: Clean up XFS_BLI_* flag namespace 2010-05-24 10:33:39 -05:00
xfs_log_rlimit.c xfs: use xfs_da_geometry for block size in attr code 2014-06-06 15:21:10 +10:00
xfs_message.c xfs: decouple log and transaction headers 2013-10-23 16:17:44 -05:00
xfs_message.h xfs: introduce CONFIG_XFS_WARN 2013-05-07 18:45:36 -05:00
xfs_mount.c xfs: allow inode allocations in post-growfs disk space 2015-12-18 16:06:25 +00:00
xfs_mount.h xfs: move node entry counts to xfs_da_geometry 2014-06-06 15:20:02 +10:00
xfs_mru_cache.c xfs: embedd mru_elem into parent structure 2014-04-23 07:11:51 +10:00
xfs_mru_cache.h xfs: embedd mru_elem into parent structure 2014-04-23 07:11:51 +10:00
xfs_qm.c xfs: Fix quota type in quota structures when reusing quota file 2015-03-18 09:58:46 +00:00
xfs_qm.h quota: Switch ->get_dqblk() and ->set_dqblk() to use bytes as space units 2015-02-04 10:58:23 +00:00
xfs_qm_bhv.c xfs: decouple inode and bmap btree header files 2013-10-23 16:28:49 -05:00
xfs_qm_syscalls.c quota: Switch ->get_dqblk() and ->set_dqblk() to use bytes as space units 2015-02-04 10:58:23 +00:00
xfs_quota.h xfs: split dquot buffer operations out 2013-10-23 14:28:35 -05:00
xfs_quota_defs.h xfs: handle dquot buffer readahead in log recovery correctly 2016-02-02 19:09:28 +00:00
xfs_quotaops.c quota: Switch ->get_dqblk() and ->set_dqblk() to use bytes as space units 2015-02-04 10:58:23 +00:00
xfs_rtalloc.c xfs: use tr_growrtalloc for growing rt files 2014-02-07 14:53:50 +11:00
xfs_rtalloc.h xfs: split xfs_rtalloc.c for userspace sanity 2013-10-23 17:16:32 -05:00
xfs_rtbitmap.c xfs: kill xfs_buf_geterror() 2014-06-06 16:02:12 +10:00
xfs_sb.c xfs: null unused quota inodes when quota is on 2014-07-15 07:28:41 +10:00
xfs_sb.h Merge branch 'xfs-feature-bit-cleanup' into for-next 2014-05-20 08:57:02 +10:00
xfs_shared.h xfs: handle dquot buffer readahead in log recovery correctly 2016-02-02 19:09:28 +00:00
xfs_stats.c xfs: Fix xqmstats offsets in /proc/fs/xfs/xqmstat 2019-02-11 17:53:37 +00:00
xfs_stats.h xfs: support the XFS_BTNUM_FINOBT free inode btree type 2014-04-24 16:00:52 +10:00
xfs_super.c xfs: disallow rw remount on fs with unknown ro-compat features 2016-08-22 22:37:49 +01:00
xfs_super.h xfs: allow inode allocations in post-growfs disk space 2015-12-18 16:06:25 +00:00
xfs_symlink.c xfs: fix remote symlinks on V5/CRC filesystems 2015-07-15 10:00:47 +01:00
xfs_symlink.h xfs: push down inactive transaction mgmt for remote symlinks 2013-10-08 14:53:02 -05:00
xfs_symlink_remote.c xfs: set buf types when converting extent formats 2015-02-24 10:01:07 +00:00
xfs_sysctl.c xfs: Convert use of typedef ctl_table to struct ctl_table 2013-06-17 17:42:25 -05:00
xfs_sysctl.h xfs: add background scanning to clear eofblocks inodes 2012-11-08 15:34:59 -06:00
xfs_trace.c xfs: add filestream allocator tracepoints 2014-04-23 07:11:52 +10:00
xfs_trace.h xfs: use i_mmaplock on write faults 2016-06-15 21:29:33 +01:00
xfs_trans.c xfs: set superblock buffer type correctly 2015-02-24 10:01:08 +00:00
xfs_trans.h xfs: format log items write directly into the linear CIL buffer 2013-12-13 11:34:02 +11:00
xfs_trans_ail.c xfs: remove unused ail pointer arg from xfs_trans_ail_cursor_done() 2014-04-14 19:06:05 +10:00
xfs_trans_buf.c xfs: don't leak EFSBADCRC to userspace 2014-03-07 16:19:14 +11:00
xfs_trans_dquot.c xfs: fix the comment explaining xfs_trans_dqlockedjoin 2013-12-04 14:26:57 -06:00
xfs_trans_extfree.c xfs: decouple log and transaction headers 2013-10-23 16:17:44 -05:00
xfs_trans_inode.c xfs: open code inc_inode_iversion when logging an inode 2013-11-18 09:42:08 -06:00
xfs_trans_priv.h xfs: remove unused ail pointer arg from xfs_trans_ail_cursor_done() 2014-04-14 19:06:05 +10:00
xfs_trans_resv.c xfs: convert m_dirblksize to xfs_da_geometry 2014-06-06 15:15:59 +10:00
xfs_trans_resv.h Merge branch 'xfs-O_TMPFILE-support' into for-next 2014-03-13 19:14:43 +11:00
xfs_trans_space.h xfs: convert m_dirblkfsbs to xfs_da_geometry 2014-06-06 15:14:11 +10:00
xfs_types.h xfs: support the XFS_BTNUM_FINOBT free inode btree type 2014-04-24 16:00:52 +10:00
xfs_vnode.h xfs: remove unused FI_ flags 2013-12-04 14:11:05 -06:00
xfs_xattr.c xfs: use generic posix ACL infrastructure 2014-01-25 23:58:21 -05:00