1 ext4: unmap metadata when zeroing blocks
3 From: Jan Kara <jack@suse.cz>
5 When zeroing blocks for DAX allocations, we also have to unmap aliases
6 in the block device mappings. Otherwise writeback can overwrite zeros
7 with stale data from block device page cache.
9 Signed-off-by: Jan Kara <jack@suse.cz>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 fs/ext4/inode.c | 10 +++++++++-
14 1 file changed, 9 insertions(+), 1 deletion(-)
16 Ted, can you merge this patch please? It's a data corruption issue for DAX.
18 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
19 index c6ea25a190f8..87150122d361 100644
22 @@ -647,11 +647,19 @@ found:
24 * We have to zeroout blocks before inserting them into extent
25 * status tree. Otherwise someone could look them up there and
26 - * use them before they are really zeroed.
27 + * use them before they are really zeroed. We also have to
28 + * unmap metadata before zeroing as otherwise writeback can
29 + * overwrite zeros with stale data from block device.
31 if (flags & EXT4_GET_BLOCKS_ZERO &&
32 map->m_flags & EXT4_MAP_MAPPED &&
33 map->m_flags & EXT4_MAP_NEW) {
36 + for (i = 0; i < map->m_len; i++) {
37 + unmap_underlying_metadata(inode->i_sb->s_bdev,
40 ret = ext4_issue_zeroout(inode, map->m_lblk,
41 map->m_pblk, map->m_len);