aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaegeuk Kim2020-11-24 17:19:10 -0600
committerJaegeuk Kim2020-12-21 15:33:16 -0600
commitecc8b5c902bed99a0fd158082a839100b2231ed7 (patch)
treeeab2c5c6af4aa8ee6eb49544380cbbaba9534322
parentd763d7a72c25b7d6648f40a64ea3367971387d8e (diff)
downloadkernel-ecc8b5c902bed99a0fd158082a839100b2231ed7.tar.gz
kernel-ecc8b5c902bed99a0fd158082a839100b2231ed7.tar.xz
kernel-ecc8b5c902bed99a0fd158082a839100b2231ed7.zip
f2fs: remove buffer_head which has 32bits limit
This patch removes buffer_head dependency when getting block addresses. Light reported there's a 32bit issue in f2fs_fiemap where map_bh.b_size is 32bits while len is 64bits given by user. This will give wrong length to f2fs_map_block. Reported-by: Light Hsieh <Light.Hsieh@mediatek.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/data.c76
1 files changed, 34 insertions, 42 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index e49c14ccfafe..bfe0d787c9e6 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1783,15 +1783,6 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
1783 return err; 1783 return err;
1784} 1784}
1785 1785
1786static int get_data_block(struct inode *inode, sector_t iblock,
1787 struct buffer_head *bh_result, int create, int flag,
1788 pgoff_t *next_pgofs)
1789{
1790 return __get_data_block(inode, iblock, bh_result, create,
1791 flag, next_pgofs,
1792 NO_CHECK_TYPE, create);
1793}
1794
1795static int get_data_block_dio_write(struct inode *inode, sector_t iblock, 1786static int get_data_block_dio_write(struct inode *inode, sector_t iblock,
1796 struct buffer_head *bh_result, int create) 1787 struct buffer_head *bh_result, int create)
1797{ 1788{
@@ -1810,14 +1801,6 @@ static int get_data_block_dio(struct inode *inode, sector_t iblock,
1810 false); 1801 false);
1811} 1802}
1812 1803
1813static int get_data_block_bmap(struct inode *inode, sector_t iblock,
1814 struct buffer_head *bh_result, int create)
1815{
1816 return __get_data_block(inode, iblock, bh_result, create,
1817 F2FS_GET_BLOCK_BMAP, NULL,
1818 NO_CHECK_TYPE, create);
1819}
1820
1821static int f2fs_xattr_fiemap(struct inode *inode, 1804static int f2fs_xattr_fiemap(struct inode *inode,
1822 struct fiemap_extent_info *fieinfo) 1805 struct fiemap_extent_info *fieinfo)
1823{ 1806{
@@ -1913,7 +1896,7 @@ static loff_t max_inode_blocks(struct inode *inode)
1913int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 1896int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1914 u64 start, u64 len) 1897 u64 start, u64 len)
1915{ 1898{
1916 struct buffer_head map_bh; 1899 struct f2fs_map_blocks map;
1917 sector_t start_blk, last_blk; 1900 sector_t start_blk, last_blk;
1918 pgoff_t next_pgofs; 1901 pgoff_t next_pgofs;
1919 u64 logical = 0, phys = 0, size = 0; 1902 u64 logical = 0, phys = 0, size = 0;
@@ -1952,19 +1935,21 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1952 last_blk = bytes_to_blks(inode, start + len - 1); 1935 last_blk = bytes_to_blks(inode, start + len - 1);
1953 1936
1954next: 1937next:
1955 memset(&map_bh, 0, sizeof(struct buffer_head)); 1938 memset(&map, 0, sizeof(map));
1956 map_bh.b_size = len; 1939 map.m_lblk = start_blk;
1940 map.m_len = bytes_to_blks(inode, len);
1941 map.m_next_pgofs = &next_pgofs;
1942 map.m_seg_type = NO_CHECK_TYPE;
1957 1943
1958 if (compr_cluster) 1944 if (compr_cluster)
1959 map_bh.b_size = blks_to_bytes(inode, cluster_size - 1); 1945 map.m_len = cluster_size - 1;
1960 1946
1961 ret = get_data_block(inode, start_blk, &map_bh, 0, 1947 ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP);
1962 F2FS_GET_BLOCK_FIEMAP, &next_pgofs);
1963 if (ret) 1948 if (ret)
1964 goto out; 1949 goto out;
1965 1950
1966 /* HOLE */ 1951 /* HOLE */
1967 if (!buffer_mapped(&map_bh)) { 1952 if (!(map.m_flags & F2FS_MAP_FLAGS)) {
1968 start_blk = next_pgofs; 1953 start_blk = next_pgofs;
1969 1954
1970 if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode, 1955 if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
@@ -1994,7 +1979,7 @@ next:
1994 1979
1995 1980
1996 logical = blks_to_bytes(inode, start_blk - 1); 1981 logical = blks_to_bytes(inode, start_blk - 1);
1997 phys = blks_to_bytes(inode, map_bh.b_blocknr); 1982 phys = blks_to_bytes(inode, map.m_pblk);
1998 size = blks_to_bytes(inode, cluster_size); 1983 size = blks_to_bytes(inode, cluster_size);
1999 1984
2000 flags |= FIEMAP_EXTENT_ENCODED; 1985 flags |= FIEMAP_EXTENT_ENCODED;
@@ -2007,17 +1992,17 @@ next:
2007 goto prep_next; 1992 goto prep_next;
2008 } 1993 }
2009 1994
2010 if (map_bh.b_blocknr == COMPRESS_ADDR) { 1995 if (map.m_pblk == COMPRESS_ADDR) {
2011 compr_cluster = true; 1996 compr_cluster = true;
2012 start_blk++; 1997 start_blk++;
2013 goto prep_next; 1998 goto prep_next;
2014 } 1999 }
2015 2000
2016 logical = blks_to_bytes(inode, start_blk); 2001 logical = blks_to_bytes(inode, start_blk);
2017 phys = blks_to_bytes(inode, map_bh.b_blocknr); 2002 phys = blks_to_bytes(inode, map.m_pblk);
2018 size = map_bh.b_size; 2003 size = blks_to_bytes(inode, map.m_len);
2019 flags = 0; 2004 flags = 0;
2020 if (buffer_unwritten(&map_bh)) 2005 if (map.m_flags & F2FS_MAP_UNWRITTEN)
2021 flags = FIEMAP_EXTENT_UNWRITTEN; 2006 flags = FIEMAP_EXTENT_UNWRITTEN;
2022 2007
2023 start_blk += bytes_to_blks(inode, size); 2008 start_blk += bytes_to_blks(inode, size);
@@ -3797,9 +3782,6 @@ static sector_t f2fs_bmap_compress(struct inode *inode, sector_t block)
3797static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) 3782static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)
3798{ 3783{
3799 struct inode *inode = mapping->host; 3784 struct inode *inode = mapping->host;
3800 struct buffer_head tmp = {
3801 .b_size = i_blocksize(inode),
3802 };
3803 sector_t blknr = 0; 3785 sector_t blknr = 0;
3804 3786
3805 if (f2fs_has_inline_data(inode)) 3787 if (f2fs_has_inline_data(inode))
@@ -3816,8 +3798,16 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)
3816 if (f2fs_compressed_file(inode)) { 3798 if (f2fs_compressed_file(inode)) {
3817 blknr = f2fs_bmap_compress(inode, block); 3799 blknr = f2fs_bmap_compress(inode, block);
3818 } else { 3800 } else {
3819 if (!get_data_block_bmap(inode, block, &tmp, 0)) 3801 struct f2fs_map_blocks map;
3820 blknr = tmp.b_blocknr; 3802
3803 memset(&map, 0, sizeof(map));
3804 map.m_lblk = block;
3805 map.m_len = 1;
3806 map.m_next_pgofs = NULL;
3807 map.m_seg_type = NO_CHECK_TYPE;
3808
3809 if (!f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_BMAP))
3810 blknr = map.m_pblk;
3821 } 3811 }
3822out: 3812out:
3823 trace_f2fs_bmap(inode, block, blknr); 3813 trace_f2fs_bmap(inode, block, blknr);
@@ -3905,25 +3895,27 @@ static int check_swap_activate_fast(struct swap_info_struct *sis,
3905 len = i_size_read(inode); 3895 len = i_size_read(inode);
3906 3896
3907 while (cur_lblock <= last_lblock && cur_lblock < sis->max) { 3897 while (cur_lblock <= last_lblock && cur_lblock < sis->max) {
3908 struct buffer_head map_bh; 3898 struct f2fs_map_blocks map;
3909 pgoff_t next_pgofs; 3899 pgoff_t next_pgofs;
3910 3900
3911 cond_resched(); 3901 cond_resched();
3912 3902
3913 memset(&map_bh, 0, sizeof(struct buffer_head)); 3903 memset(&map, 0, sizeof(map));
3914 map_bh.b_size = len - blks_to_bytes(inode, cur_lblock); 3904 map.m_lblk = cur_lblock;
3905 map.m_len = bytes_to_blks(inode, len) - cur_lblock;
3906 map.m_next_pgofs = &next_pgofs;
3907 map.m_seg_type = NO_CHECK_TYPE;
3915 3908
3916 ret = get_data_block(inode, cur_lblock, &map_bh, 0, 3909 ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP);
3917 F2FS_GET_BLOCK_FIEMAP, &next_pgofs);
3918 if (ret) 3910 if (ret)
3919 goto err_out; 3911 goto err_out;
3920 3912
3921 /* hole */ 3913 /* hole */
3922 if (!buffer_mapped(&map_bh)) 3914 if (!(map.m_flags & F2FS_MAP_FLAGS))
3923 goto err_out; 3915 goto err_out;
3924 3916
3925 pblock = map_bh.b_blocknr; 3917 pblock = map.m_pblk;
3926 nr_pblocks = bytes_to_blks(inode, map_bh.b_size); 3918 nr_pblocks = map.m_len;
3927 3919
3928 if (cur_lblock + nr_pblocks >= sis->max) 3920 if (cur_lblock + nr_pblocks >= sis->max)
3929 nr_pblocks = sis->max - cur_lblock; 3921 nr_pblocks = sis->max - cur_lblock;