xfs: don't set bt_nr_sectors to a negative number
PATCH 1/1 xfs: don't set bt_nr_sectors to a negative number
From: Darrick J. Wong <[email protected]>
xfs_daddr_t is a signed type, which means that xfs_buf_map_verify is using a signed comparison. This causes problems if bt_nr_sectors is never overridden (e.g. in the case of an xfbtree for rmap btree repairs) because even daddr 0 can't pass the verifier test in that case.
Define an explicit max constant and set the initial bt_nr_sectors to a positive value.
Found by xfs/422.
--- fs/xfs/xfs_buf.h | 1 + fs/xfs/xfs_buf.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
fs/xfs/xfs_buf.h +1 -0
@@ -22,6 +22,7 @@ extern struct kmem_cache *xfs_buf_cache;*/ struct xfs_buf ; +#define XFS_BUF_DADDR_MAX ((xfs_daddr_t) S64_MAX)#define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))#define XBF_READ (1u << 0)/* buffer intended for reading from device */
fs/xfs/xfs_buf.c +1 -1
@@ -1751,7 +1751,7 @@ xfs_init_buftarg( const char *descr) {/* The maximum size of the buftarg is only known once the sb is read. */ - btp->bt_nr_sectors = (xfs_daddr_t)-1 ; + btp->bt_nr_sectors =XFS_BUF_DADDR_MAX ;/* Set up device logical sector size mask */ btp->bt_logical_sectorsize = logical_sectorsize;
Quoted 9 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
xfs_daddr_tis a signed type, which means thatxfs_buf_map_verifyis using a signed comparison. This causes problems ifbt_nr_sectorsis never overridden (e.g. in the case of an xfbtree for rmap btree repairs) because even daddr 0 can't pass the verifier test in that case.Define an explicit max constant and set the initial
bt_nr_sectorsto a positive value.
Looks good:
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
xfs_daddr_tis a signed type, which means thatxfs_buf_map_verifyis using a signed comparison. This causes problems ifbt_nr_sectorsis never overridden (e.g. in the case of an xfbtree for rmap btree repairs) because even daddr 0 can't pass the verifier test in that case.
Okay so the check "if (map->bm_bn < 0 || map->bm_bn >= btp->bt_nr_sectors) {" will be true of the default value of btp->bt_nr_sectors = -1 and the verifier will fail(incorrectly), right? Why would we not want to override bt_nr_sectors? If there is device, then shouldn't it always have a buffer target with a certain number of bt_nr_sectors?
--NR
Quoted 39 lines
Define an explicit max constant and set the initial
bt_nr_sectorsto a positive value.Found by xfs/422.
Cc <[email protected]> # v6.18-rc1Fixes 42852fe57c6d2a ("xfs: track the number of blocks in each buftarg")Signed-off-by "Darrick J. Wong" <[email protected]>--- fs/xfs/xfs_buf.h | 1 + fs/xfs/xfs_buf.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)fs/xfs/xfs_buf.h +1
-0@@ -22,6 +22,7 @@ extern struct kmem_cache *xfs_buf_cache;*/ struct xfs_buf ; +#define XFS_BUF_DADDR_MAX ((xfs_daddr_t) S64_MAX)#define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))#define XBF_READ (1u << 0)/* buffer intended for reading from device */ fs/xfs/xfs_buf.c +1
-1@@ -1751,7 +1751,7 @@ xfs_init_buftarg( const char *descr) {/* The maximum size of the buftarg is only known once the sb is read. */ - btp->bt_nr_sectors = (xfs_daddr_t)-1 ; + btp->bt_nr_sectors =XFS_BUF_DADDR_MAX ;/* Set up device logical sector size mask */ btp->bt_logical_sectorsize = logical_sectorsize;
Quoted 11 lines · Nirjhar Roy (IBM)
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
xfs_daddr_tis a signed type, which means thatxfs_buf_map_verifyis using a signed comparison. This causes problems ifbt_nr_sectorsis never overridden (e.g. in the case of an xfbtree for rmap btree repairs) because even daddr 0 can't pass the verifier test in that case.Okay so the check "if (
map->bm_bn< 0 ||map->bm_bn>=btp->bt_nr_sectors) {" will be true of the default value ofbtp->bt_nr_sectors= -1 and the verifier will fail(incorrectly), right? Why would we not want to overridebt_nr_sectors? If there is device, then shouldn't it always have a buffer target with a certain number ofbt_nr_sectors?
Online repair creates tmpfs files in which to stage repairs, and uses the xfbtree buftarg so that it can build a replacement rmapbt in a tmpfs file. I guess xfbtree should be setting bt_nr_sectors to (max pagecache size / 512) but in practicality nobody should ever have a 16TB rmap btree on 32-bit or an 8EB rmap btree on 64-bit.
--D
Quoted 42 lines
--NR
Quoted 39 lines
Define an explicit max constant and set the initial
bt_nr_sectorsto a positive value.Found by xfs/422.
Cc <[email protected]> # v6.18-rc1Fixes 42852fe57c6d2a ("xfs: track the number of blocks in each buftarg")Signed-off-by "Darrick J. Wong" <[email protected]>--- fs/xfs/xfs_buf.h | 1 + fs/xfs/xfs_buf.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)fs/xfs/xfs_buf.h +1
-0@@ -22,6 +22,7 @@ extern struct kmem_cache *xfs_buf_cache;*/ struct xfs_buf ; +#define XFS_BUF_DADDR_MAX ((xfs_daddr_t) S64_MAX)#define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))#define XBF_READ (1u << 0)/* buffer intended for reading from device */ fs/xfs/xfs_buf.c +1
-1@@ -1751,7 +1751,7 @@ xfs_init_buftarg( const char *descr) {/* The maximum size of the buftarg is only known once the sb is read. */ - btp->bt_nr_sectors = (xfs_daddr_t)-1 ; + btp->bt_nr_sectors =XFS_BUF_DADDR_MAX ;/* Set up device logical sector size mask */ btp->bt_logical_sectorsize = logical_sectorsize;
Quoted 12 lines · Darrick J. Wong
Quoted 11 lines · Nirjhar Roy (IBM)
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
xfs_daddr_tis a signed type, which means thatxfs_buf_map_verifyis using a signed comparison. This causes problems ifbt_nr_sectorsis never overridden (e.g. in the case of an xfbtree for rmap btree repairs) because even daddr 0 can't pass the verifier test in that case.Okay so the check "if (
map->bm_bn< 0 ||map->bm_bn>=btp->bt_nr_sectors) {" will be true of the default value ofbtp->bt_nr_sectors= -1 and the verifier will fail(incorrectly), right? Why would we not want to overridebt_nr_sectors? If there is device, then shouldn't it always have a buffer target with a certain number ofbt_nr_sectors?
Quoted 5 lines
Online repair creates tmpfs files in which to stage repairs, and uses the xfbtree buftarg so that it can build a replacement rmapbt in a tmpfs file. I guess xfbtree should be setting
bt_nr_sectorsto (max pagecache size / 512) but in practicality nobody should ever have a 16TB rmap btree on 32-bit or an 8EB rmap btree on 64-bit.
Okay, that makes sense. Thank you for the explanation.
--NR
Quoted 42 lines
--D
Quoted 40 lines
--NR
Quoted 38 lines
Define an explicit max constant and set the initial
bt_nr_sectorsto a positive value.Found by xfs/422.
Cc <[email protected]> # v6.18-rc1Fixes 42852fe57c6d2a ("xfs: track the number of blocks in each buftarg")Signed-off-by "Darrick J. Wong" <[email protected]>--- fs/xfs/xfs_buf.h | 1 + fs/xfs/xfs_buf.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)fs/xfs/xfs_buf.h +1
-0@@ -22,6 +22,7 @@ extern struct kmem_cache *xfs_buf_cache;*/ struct xfs_buf ; +#define XFS_BUF_DADDR_MAX ((xfs_daddr_t) S64_MAX)#define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))#define XBF_READ (1u << 0)/* buffer intended for reading from device */ fs/xfs/xfs_buf.c +1
-1@@ -1751,7 +1751,7 @@ xfs_init_buftarg( const char *descr) {/* The maximum size of the buftarg is only known once the sb is read. */ - btp->bt_nr_sectors = (xfs_daddr_t)-1 ; + btp->bt_nr_sectors =XFS_BUF_DADDR_MAX ;/* Set up device logical sector size mask */ btp->bt_logical_sectorsize = logical_sectorsize;
Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore