]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/5.15.153/f2fs-invalidate-meta_mapping-before-ipu-dio-write.patch
Linux 6.1.83
[thirdparty/kernel/stable-queue.git] / releases / 5.15.153 / f2fs-invalidate-meta_mapping-before-ipu-dio-write.patch
1 From e8859acb23a33ce1eeee3c6cf6c15038198aa75a Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Tue, 2 Nov 2021 16:10:02 +0900
4 Subject: f2fs: invalidate META_MAPPING before IPU/DIO write
5
6 From: Hyeong-Jun Kim <hj514.kim@samsung.com>
7
8 [ Upstream commit e3b49ea36802053f312013fd4ccb6e59920a9f76 ]
9
10 Encrypted pages during GC are read and cached in META_MAPPING.
11 However, due to cached pages in META_MAPPING, there is an issue where
12 newly written pages are lost by IPU or DIO writes.
13
14 Thread A - f2fs_gc() Thread B
15 /* phase 3 */
16 down_write(i_gc_rwsem)
17 ra_data_block() ---- (a)
18 up_write(i_gc_rwsem)
19 f2fs_direct_IO() :
20 - down_read(i_gc_rwsem)
21 - __blockdev_direct_io()
22 - get_data_block_dio_write()
23 - f2fs_dio_submit_bio() ---- (b)
24 - up_read(i_gc_rwsem)
25 /* phase 4 */
26 down_write(i_gc_rwsem)
27 move_data_block() ---- (c)
28 up_write(i_gc_rwsem)
29
30 (a) In phase 3 of f2fs_gc(), up-to-date page is read from storage and
31 cached in META_MAPPING.
32 (b) In thread B, writing new data by IPU or DIO write on same blkaddr as
33 read in (a). cached page in META_MAPPING become out-dated.
34 (c) In phase 4 of f2fs_gc(), out-dated page in META_MAPPING is copied to
35 new blkaddr. In conclusion, the newly written data in (b) is lost.
36
37 To address this issue, invalidating pages in META_MAPPING before IPU or
38 DIO write.
39
40 Fixes: 6aa58d8ad20a ("f2fs: readahead encrypted block during GC")
41 Signed-off-by: Hyeong-Jun Kim <hj514.kim@samsung.com>
42 Reviewed-by: Chao Yu <chao@kernel.org>
43 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
44 Stable-dep-of: fd244524c2cf ("f2fs: compress: fix to cover normal cluster write with cp_rwsem")
45 Signed-off-by: Sasha Levin <sashal@kernel.org>
46 ---
47 fs/f2fs/data.c | 2 ++
48 fs/f2fs/segment.c | 3 +++
49 2 files changed, 5 insertions(+)
50
51 diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
52 index e005f97fd273e..25dafd1261d71 100644
53 --- a/fs/f2fs/data.c
54 +++ b/fs/f2fs/data.c
55 @@ -1711,6 +1711,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
56 */
57 f2fs_wait_on_block_writeback_range(inode,
58 map->m_pblk, map->m_len);
59 + invalidate_mapping_pages(META_MAPPING(sbi),
60 + map->m_pblk, map->m_pblk);
61
62 if (map->m_multidev_dio) {
63 block_t blk_addr = map->m_pblk;
64 diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
65 index 25d53617a50e6..5eca50e50e16b 100644
66 --- a/fs/f2fs/segment.c
67 +++ b/fs/f2fs/segment.c
68 @@ -3622,6 +3622,9 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
69 goto drop_bio;
70 }
71
72 + invalidate_mapping_pages(META_MAPPING(sbi),
73 + fio->new_blkaddr, fio->new_blkaddr);
74 +
75 stat_inc_inplace_blocks(fio->sbi);
76
77 if (fio->bio && !(SM_I(sbi)->ipu_policy & (1 << F2FS_IPU_NOCACHE)))
78 --
79 2.43.0
80