ext4: fix accidental flag aliasing in ext4_map_blocks flags
Theodore Ts'o
maintainerPATCH 1/1 ext4: fix accidental flag aliasing in ext4_map_blocks flags
Commit b8a8684502a0f introduced an accidental flag aliasing between EXT4_EX_NOCACHE and EXT4_GET_BLOCKS_CONVERT_UNWRITTEN.
Fortunately, this didn't introduce any untorward side effects --- we got lucky. Nevertheless, fix this and leave a warning to hopefully avoid this from happening in the future.
--- fs/ext4/ext4.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ext4/ext4.h +3 -2
@@ -569,6 +569,7 @@ enum {#define EXT4_GET_BLOCKS_NO_PUT_HOLE 0x0200/* Convert written extents to unwritten */ #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0400 +/* DO NOT ASSIGN ADDITIONAL FLAG VALUES WITHOUT ADJUSTING THE FLAGS BELOW */ /* * The bit position of these flags must not overlap with any of the
@@ -579,8 +580,8 @@ enum {* caching the extents when reading from the extent tree while a * truncate or punch hole operation is in progress. */ -#define EXT4_EX_NOCACHE 0x0400 -#define EXT4_EX_FORCE_CACHE 0x0800 +#define EXT4_EX_NOCACHE 0x0800 +#define EXT4_EX_FORCE_CACHE 0x1000/* * Flags used by ext4_free_blocks
Signature · 1 line
2.1.0
Theodore Ts'o
maintainerPATCH 1/1 ext4: fix ZERO_RANGE bug hidden by flag aliasing
Quoted 8 lines · Theodore Ts'o
Commit
b8a8684502a0fintroduced an accidental flag aliasing betweenEXT4_EX_NOCACHEandEXT4_GET_BLOCKS_CONVERT_UNWRITTEN.Fortunately, this didn't introduce any untorward side effects --- we got lucky. Nevertheless, fix this and leave a warning to hopefully avoid this from happening in the future.
Signed-off-by Theodore Ts'o <[email protected]>
I spoke too soon. It turns out this flag aliasing was _hiding_ a bug. The following patch seems to address the problem. We probably need to do further cleanup of the extent handling code so it's clearer what's going on, so for now, I'm going to stick with a more conservative fix.
- Ted
commit 3d714c69e1beba1e07e64e9adc72d446b249be18
Author: Theodore Ts'o <[email protected]> Date: Mon Sep 1 14:32:09 2014 -0400
ext4: fix ZERO_RANGE bug hidden by flag aliasing
We accidently aliased EXT4_EX_NOCACHE and EXT4_GET_CONVERT_UNWRITTEN falgs, which apparently was hiding a bug that was unmasked when this flag aliasing issue was addressed (see the subsequent commit). The reproduction case was:
fsx -N 10000 -l 500000 -r 4096 -t 4096 -w 4096 -Z -R -W /vdb/junk
... which would cause fsx to report corruption in the data file.
The fix we have is a bit of an overkill, but I'd much rather be conservative for now, and we can optimize ZERO_RANGE_FL handling later. The fact that we need to zap the extent_status cache for the inode is unfortunate, but correctness is far more important than performance.
fs/ext4/extents.c +13 -4
@@ -4808,7 +4808,8 @@ static long ext4_zero_range(struct file *file, loff_t offset, max_blocks -= lblk; flags =EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT | -EXT4_GET_BLOCKS_CONVERT_UNWRITTEN ; +EXT4_GET_BLOCKS_CONVERT_UNWRITTEN | +EXT4_EX_NOCACHE ;if (mode &FALLOC_FL_KEEP_SIZE ) flags |=EXT4_GET_BLOCKS_KEEP_SIZE ;
@@ -4846,15 +4847,21 @@ static long ext4_zero_range(struct file *file, loff_t offset,ext4_inode_block_unlocked_dio (inode);inode_dio_wait (inode); + ret =ext4_alloc_file_blocks (file, lblk, max_blocks, new_size, + flags, mode); +if (ret) + goto out_dio;/* * Remove entire range from the extent status tree. +* +* ext4_es_remove_extent(inode, lblk, max_blocks) is +* NOT sufficient. I'm not sure why this is the case, +* but let's be conservative and remove the extent +* status tree for the entire inode. There should be +* no outstanding delalloc extents thanks to the +* filemap_write_and_wait_range() call above. */ - ret =ext4_es_remove_extent (inode, lblk, max_blocks); -if (ret) - goto out_dio;
Quoted 6 lines · Theodore Ts'o
Commit
b8a8684502a0fintroduced an accidental flag aliasing betweenEXT4_EX_NOCACHEandEXT4_GET_BLOCKS_CONVERT_UNWRITTEN.Fortunately, this didn't introduce any untorward side effects --- we got lucky. Nevertheless, fix this and leave a warning to hopefully avoid this from happening in the future.
Why not move EXT4_EX_*CACHE flags to the end of the range (e.g. 0x8000 and 0x4000) to minimize potential conflicts in the future?
Quoted 10 lines
Signed-off-by Theodore Ts'o <[email protected]>---
fs/ext4/ext4.h| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)fs/ext4/ext4.h +0
-0
fs/ext4/ext4.h enum { · line 572
Quoted 4 lines
fs/ext4/ext4.h +1
-0@@ -569,6 +569,7 @@ enum {#define EXT4_GET_BLOCKS_NO_PUT_HOLE 0x0200/* Convert written extents to unwritten */ #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0400 +/* DO NOT ASSIGN ADDITIONAL FLAG VALUES WITHOUT ADJUSTING THE FLAGS BELOW
It might be useful here to mention the EXT4_EX_* flags explicitly? In my experience, time and incremental changes will make it less clear what "FLAGS BELOW" means...
Cheers, Andreas
Quoted 20 lines
fs/ext4/ext4.h +2
-2/* * The bit position of these flags must not overlap with any of the @@ -579,8 +580,8 @@ enum {* caching the extents when reading from the extent tree while a * truncate or punch hole operation is in progress. */ -#define EXT4_EX_NOCACHE 0x0400 -#define EXT4_EX_FORCE_CACHE 0x0800 +#define EXT4_EX_NOCACHE 0x0800 +#define EXT4_EX_FORCE_CACHE 0x1000/* * Flags used by ext4_free_blocks Signature · 6 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers, Andreas
Theodore Ts'o
maintainerPATCH 1/1 ext4: renumber EXT4_EX_* flags to avoid flag aliasing problems flags
Quoted 2 lines · Andreas Dilger
Why not move EXT4_EX_*CACHE flags to the end of the range (e.g.
0x8000and0x4000) to minimize potential conflicts in the future?
Good idea, thanks!
- Ted
commit ef78955523bffe055035f0b3a98aba31534bf27c
Author: Theodore Ts'o <[email protected]> Date: Tue Sep 2 21:41:59 2014 -0400
ext4: renumber EXT4_EX_* flags to avoid flag aliasing problems
fs/ext4/ext4.h +2 -3
@@ -569,7 +569,6 @@ enum {#define EXT4_GET_BLOCKS_NO_PUT_HOLE 0x0200/* Convert written extents to unwritten */ #define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0400 -/* DO NOT ASSIGN ADDITIONAL FLAG VALUES WITHOUT ADJUSTING THE FLAGS BELOW */ /* * The bit position of these flags must not overlap with any of the
@@ -580,8 +579,8 @@ enum {* caching the extents when reading from the extent tree while a * truncate or punch hole operation is in progress. */ -#define EXT4_EX_NOCACHE 0x0800 -#define EXT4_EX_FORCE_CACHE 0x1000 +#define EXT4_EX_NOCACHE 0x40000000 +#define EXT4_EX_FORCE_CACHE 0x20000000/* * Flags used by ext4_free_blocks