Add stable@vger.kernel.org annotations
[ext4-patch-queue.git] / unmap-metadata-when-zeroing-blocks
bloba7c3fe969edb9e29e832b7dd957554b0fe8e5c29
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>
11 Cc: stable@kernel.org
12 ---
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
20 --- a/fs/ext4/inode.c
21 +++ b/fs/ext4/inode.c
22 @@ -647,11 +647,19 @@ found:
23                 /*
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.
30                  */
31                 if (flags & EXT4_GET_BLOCKS_ZERO &&
32                     map->m_flags & EXT4_MAP_MAPPED &&
33                     map->m_flags & EXT4_MAP_NEW) {
34 +                       ext4_lblk_t i;
36 +                       for (i = 0; i < map->m_len; i++) {
37 +                               unmap_underlying_metadata(inode->i_sb->s_bdev,
38 +                                                         map->m_pblk + i);
39 +                       }
40                         ret = ext4_issue_zeroout(inode, map->m_lblk,
41                                                  map->m_pblk, map->m_len);
42                         if (ret) {
43 -- 
44 2.6.6