Commit 2e6dcc46 authored by Chao Yu's avatar Chao Yu Committed by Zizhi Wo
Browse files

f2fs: invalidate meta pages only for post_read required inode

mainline inclusion
from mainline-v6.0-rc1
commit 0d5b9d81
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9HKE5
CVE: CVE-2024-26869

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0d5b9d8156396bbe1c982708b38ab9e188c45ec9



--------------------------------

After commit e3b49ea3 ("f2fs: invalidate META_MAPPING before
IPU/DIO write"), invalidate_mapping_pages() will be called to
avoid race condition in between IPU/DIO and readahead for GC.

However, readahead flow is only used for post_read required inode,
so this patch adds check condition to avoids unnecessary page cache
invalidating for non-post_read inode.

Signed-off-by: default avatarChao Yu <chao.yu@oppo.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>

Conflicts:
	fs/f2fs/data.c
	fs/f2fs/segment.c
Signed-off-by: default avatarZizhi Wo <wozizhi@huawei.com>
parent 3fa39667
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -1536,12 +1536,9 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
			*map->m_next_extent = pgofs + map->m_len;

		/* for hardware encryption, but to avoid potential issue in future */
		if (flag == F2FS_GET_BLOCK_DIO) {
		if (flag == F2FS_GET_BLOCK_DIO)
			f2fs_wait_on_block_writeback_range(inode,
						map->m_pblk, map->m_len);
			invalidate_mapping_pages(META_MAPPING(sbi),
				map->m_pblk, map->m_pblk + map->m_len - 1);
		}
		goto out;
	}

@@ -1718,12 +1715,9 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
sync_out:

	/* for hardware encryption, but to avoid potential issue in future */
	if (flag == F2FS_GET_BLOCK_DIO && map->m_flags & F2FS_MAP_MAPPED) {
	if (flag == F2FS_GET_BLOCK_DIO && map->m_flags & F2FS_MAP_MAPPED)
		f2fs_wait_on_block_writeback_range(inode,
						map->m_pblk, map->m_len);
		invalidate_mapping_pages(META_MAPPING(sbi),
				map->m_pblk, map->m_pblk + map->m_len - 1);
	}

	if (flag == F2FS_GET_BLOCK_PRECACHE) {
		if (map->m_flags & F2FS_MAP_MAPPED) {
@@ -2805,6 +2799,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted,
		.submitted = false,
		.compr_blocks = compr_blocks,
		.need_lock = LOCK_RETRY,
		.post_read = f2fs_post_read_required(inode),
		.io_type = io_type,
		.io_wbc = wbc,
		.bio = bio,
+1 −0
Original line number Diff line number Diff line
@@ -1117,6 +1117,7 @@ struct f2fs_io_info {
	bool retry;		/* need to reallocate block address */
	int compr_blocks;	/* # of compressed block addresses */
	bool encrypted;		/* indicate file is encrypted */
	bool post_read;		/* require post read */
	enum iostat_type io_type;	/* io type */
	struct writeback_control *io_wbc; /* writeback control */
	struct bio **bio;		/* bio for ipu */
+8 −1
Original line number Diff line number Diff line
@@ -3554,6 +3554,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
		return -EFSCORRUPTED;
	}

	if (fio->post_read)
		invalidate_mapping_pages(META_MAPPING(sbi),
				fio->new_blkaddr, fio->new_blkaddr);

@@ -3723,10 +3724,16 @@ void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr)
void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr,
								block_t len)
{
	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
	block_t i;

	if (!f2fs_post_read_required(inode))
		return;

	for (i = 0; i < len; i++)
		f2fs_wait_on_block_writeback(inode, blkaddr + i);

	invalidate_mapping_pages(META_MAPPING(sbi), blkaddr, blkaddr + len - 1);
}

static int read_compacted_summaries(struct f2fs_sb_info *sbi)