linux-stable/fs/f2fs
Hyeong-Jun Kim e3b49ea368 f2fs: invalidate META_MAPPING before IPU/DIO write
Encrypted pages during GC are read and cached in META_MAPPING.
However, due to cached pages in META_MAPPING, there is an issue where
newly written pages are lost by IPU or DIO writes.

Thread A - f2fs_gc()            Thread B
/* phase 3 */
down_write(i_gc_rwsem)
ra_data_block()       ---- (a)
up_write(i_gc_rwsem)
                                f2fs_direct_IO() :
                                 - down_read(i_gc_rwsem)
                                 - __blockdev_direct_io()
                                 - get_data_block_dio_write()
                                 - f2fs_dio_submit_bio()  ---- (b)
                                 - up_read(i_gc_rwsem)
/* phase 4 */
down_write(i_gc_rwsem)
move_data_block()     ---- (c)
up_write(i_gc_rwsem)

(a) In phase 3 of f2fs_gc(), up-to-date page is read from storage and
    cached in META_MAPPING.
(b) In thread B, writing new data by IPU or DIO write on same blkaddr as
    read in (a). cached page in META_MAPPING become out-dated.
(c) In phase 4 of f2fs_gc(), out-dated page in META_MAPPING is copied to
    new blkaddr. In conclusion, the newly written data in (b) is lost.

To address this issue, invalidating pages in META_MAPPING before IPU or
DIO write.

Fixes: 6aa58d8ad2 ("f2fs: readahead encrypted block during GC")
Signed-off-by: Hyeong-Jun Kim <hj514.kim@samsung.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2021-11-09 08:16:34 -08:00
..
acl.c vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
acl.h vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
checkpoint.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
compress.c f2fs: compress: fix overwrite may reduce compress ratio unproperly 2021-10-26 14:04:31 -07:00
data.c f2fs: invalidate META_MAPPING before IPU/DIO write 2021-11-09 08:16:34 -08:00
debug.c f2fs: convert S_IRUGO to 0444 2021-08-17 11:59:05 -07:00
dir.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
extent_cache.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
f2fs.h f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
file.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
gc.c f2fs: introduce fragment allocation mode mount option 2021-10-26 14:04:30 -07:00
gc.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
hash.c f2fs: Handle casefolding with Encryption 2020-12-02 22:00:21 -08:00
inline.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
inode.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
iostat.c f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
iostat.h f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
Kconfig f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
Makefile f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
namei.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
node.c f2fs: set SBI_NEED_FSCK flag when inconsistent node block found 2021-09-20 16:29:00 -07:00
node.h f2fs: introduce excess_dirty_threshold() 2021-09-20 16:12:51 -07:00
recovery.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
segment.c f2fs: invalidate META_MAPPING before IPU/DIO write 2021-11-09 08:16:34 -08:00
segment.h f2fs: introduce fragment allocation mode mount option 2021-10-26 14:04:30 -07:00
shrinker.c f2fs: avoid race condition for shrinker count 2020-12-03 00:59:26 -08:00
super.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
sysfs.c f2fs: introduce fragment allocation mode mount option 2021-10-26 14:04:30 -07:00
verity.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
xattr.c f2fs: support fault injection for dquot_initialize() 2021-10-29 10:38:53 -07:00
xattr.h f2fs: code cleanup by removing ifdef macro surrounding 2020-05-26 18:56:10 -07:00