block: make blk_queue_zone_sectors() return sector_t type
Subsystems (3)
PATCH 1/1 block: make blk_queue_zone_sectors() return sector_t type
My static checker complains about this line from dmz_get_zoned_device()
aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);
The problem is that "aligned_capacity" and "dev->capacity" are sector_t type (which is a u64) but blk_queue_zone_sectors(q) returns a u32 so the higher 32 bits in aligned_capacity are always cleared to zero.
Declaring blk_queue_zone_sectors() as a sector_t addresses this warning and it feels intuitive based on the function name. I updated bdev_zone_sectors() as well just to be consistent.
---
Please review this one extra carefully. I'm not positive it's correct.
include/linux/blkdev.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/blkdev.h +2 -2
@@ -670,7 +670,7 @@ static inline bool blk_queue_is_zoned(struct request_queue *q) } } -static inline unsigned int blk_queue_zone_sectors (struct request_queue *q) +static inline sector_t blk_queue_zone_sectors (struct request_queue *q) {return blk_queue_is_zoned (q) ? q->limits.chunk_sectors :0 ; }
@@ -1419,7 +1419,7 @@ static inline bool bdev_is_zoned(struct block_device *bdev)return false; } -static inline unsigned int bdev_zone_sectors (struct block_device *bdev) +static inline sector_t bdev_zone_sectors (struct block_device *bdev) {struct request_queue *q =bdev_get_queue (bdev);
Signature · 1 line
2.17.1
Quoted 34 lines · Dan Carpenter
My static checker complains about this line from
dmz_get_zoned_device()aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);The problem is that "
aligned_capacity" and "dev->capacity" aresector_ttype (which is a u64) butblk_queue_zone_sectors(q)returns a u32 so the higher 32 bits inaligned_capacityare always cleared to zero.Declaring
blk_queue_zone_sectors()as asector_taddresses this warning and it feels intuitive based on the function name. I updatedbdev_zone_sectors()as well just to be consistent.Fixes 114e025968b5 ("dm zoned: ignore last smaller runt zone")Signed-off-by Dan Carpenter <[email protected]>---
Please review this one extra carefully. I'm not positive it's correct.include/linux/blkdev.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/blkdev.h +1
-1@@ -670,7 +670,7 @@ static inline bool blk_queue_is_zoned(struct request_queue *q) } } -static inline unsigned int blk_queue_zone_sectors (struct request_queue *q) +static inline sector_t blk_queue_zone_sectors (struct request_queue *q) {return blk_queue_is_zoned (q) ? q->limits.chunk_sectors :0 ; }
include/linux/blkdev.h static inline bool bdev_is_zoned(struct block_device *bdev) · line 1424
Quoted 7 lines
include/linux/blkdev.h +1
-1@@ -1419,7 +1419,7 @@ static inline bool bdev_is_zoned(struct block_device *bdev)return false; } -static inline unsigned int bdev_zone_sectors (struct block_device *bdev) +static inline sector_t bdev_zone_sectors (struct block_device *bdev) {struct request_queue *q =bdev_get_queue (bdev);
Indeed, using sector_t instead of unsigned int is more intuitive and changing to sector_t matches the 64bits zone length in struct blk_zone too, so no problem on this front.
However, q->limits.chunk_sectors is an unsigned int, which is why I used that type, to reflect the fact that even though the API allows values larger than 4G sectors, the handling through the queue limits truncates that to at most 4G-1 sectors. Furthermore, the unsigned int type is used wherever blk_queue_zone_sectors() and bdev_zone_sectors() are called (block/ioctl.c, block/blk-zoned.c, f2fs, etc). That needs in depth checking.
I would rather keep the unsigned int since the queue limits will give only 32 bit values anyway. What about a cast for the aligned capacity line ? Something like:
aligned_capacity = dev->capacity & ~((u64)blk_queue_zone_sectors(q) - 1);
Would that make your checker happy ?
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 54 lines · Damien Le Moal
Quoted 34 lines · Dan Carpenter
My static checker complains about this line from
dmz_get_zoned_device()aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);The problem is that "
aligned_capacity" and "dev->capacity" aresector_ttype (which is a u64) butblk_queue_zone_sectors(q)returns a u32 so the higher 32 bits inaligned_capacityare always cleared to zero.Declaring
blk_queue_zone_sectors()as asector_taddresses this warning and it feels intuitive based on the function name. I updatedbdev_zone_sectors()as well just to be consistent.Fixes 114e025968b5 ("dm zoned: ignore last smaller runt zone")Signed-off-by Dan Carpenter <[email protected]>---
Please review this one extra carefully. I'm not positive it's correct.include/linux/blkdev.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/blkdev.h +1
-1@@ -670,7 +670,7 @@ static inline bool blk_queue_is_zoned(struct request_queue *q) } } -static inline unsigned int blk_queue_zone_sectors (struct request_queue *q) +static inline sector_t blk_queue_zone_sectors (struct request_queue *q) {return blk_queue_is_zoned (q) ? q->limits.chunk_sectors :0 ; }include/linux/blkdev.h static inline bool bdev_is_zoned(struct block_device *bdev) · line 1424
Quoted 7 lines
include/linux/blkdev.h +1
-1@@ -1419,7 +1419,7 @@ static inline bool bdev_is_zoned(struct block_device *bdev)return false; } -static inline unsigned int bdev_zone_sectors (struct block_device *bdev) +static inline sector_t bdev_zone_sectors (struct block_device *bdev) {struct request_queue *q =bdev_get_queue (bdev);Indeed, using
sector_tinstead of unsigned int is more intuitive and changing tosector_tmatches the 64bits zone length in structblk_zonetoo, so no problem on this front.However,
q->limits.chunk_sectorsis an unsigned int, which is why I used that type, to reflect the fact that even though the API allows values larger than 4G sectors, the handling through the queue limits truncates that to at most 4G-1 sectors. Furthermore, the unsigned int type is used whereverblk_queue_zone_sectors()andbdev_zone_sectors()are called (block/ioctl.c,block/blk-zoned.c, f2fs, etc). That needs in depth checking.
Quoted 7 lines
I would rather keep the unsigned int since the queue limits will give only 32 bit values anyway. What about a cast for the aligned capacity line ? Something like:
aligned_capacity=dev->capacity& ~((u64)blk_queue_zone_sectors(q) - 1);Would that make your checker happy ?
Yeah. Or a sector_t cast.
aligned_capacity = dev->capacity & ~((sector_t)blk_queue_zone_sectors(q) - 1);
regards,
dan carpenter
PATCH v2 1/1 dm zoned: Silence a static checker warning
In reply to Damien Le MoalMy static checker complains about this line from dmz_get_zoned_device()
aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);
The problem is that "aligned_capacity" and "dev->capacity" are sector_t type (which is a u64) but blk_queue_zone_sectors(q) returns a u32 so the higher 32 bits in "aligned_capacity" are always cleared to zero. This patch adds a cast to u64 to address this issue.
---
v2: In v1 I changed blk_queue_zone_sectors() to return a sector_t type, but in v2 I just add a cast. The v2 fix would end up going through different maintainers and reviewers so the CC list has grown...
Original discussion: https://marc.info/?l=kernel-janitors&m=155487663405737&w=2
drivers/md/dm-zoned-target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-zoned-target.c +2 -1
@@ -643,7 +643,8 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path) q =bdev_get_queue (dev->bdev); dev->capacity =i_size_read (dev->bdev->bd_inode) >>SECTOR_SHIFT ; - aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors (q) -1 ); + aligned_capacity = dev->capacity & + ~((u64 )blk_queue_zone_sectors (q) -1 );if (ti->begin || ((ti->len != dev->capacity) && (ti->len != aligned_capacity))) { ti->error ="Partial mapping not supported" ;
Signature · 1 line
2.17.1
Re: [PATCH v2] dm zoned: Silence a static checker warning
Quoted 26 lines · Dan Carpenter
My static checker complains about this line from
dmz_get_zoned_device()aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);The problem is that "
aligned_capacity" and "dev->capacity" aresector_ttype (which is a u64) butblk_queue_zone_sectors(q)returns a u32 so the higher 32 bits in "aligned_capacity" are always cleared to zero. This patch adds a cast to u64 to address this issue.Fixes 114e025968b5 ("dm zoned: ignore last smaller runt zone")Signed-off-by Dan Carpenter <[email protected]>---
v2: In v1 I changedblk_queue_zone_sectors()to return asector_ttype, but in v2 I just add a cast. The v2 fix would end up going through different maintainers and reviewers so the CC list has grown...Original discussion: https://marc.info/?l=kernel-janitors&m=155487663405737&w=2
drivers/md/dm-zoned-target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/md/dm-zoned-target.c +0
-0
drivers/md/dm-zoned-target.c static int dmz_get_zoned_device(struct dm_target *ti, char *path) · line 647
Quoted 6 lines
drivers/md/dm-zoned-target.c +2
-1@@ -643,7 +643,8 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path) q =bdev_get_queue (dev->bdev); dev->capacity =i_size_read (dev->bdev->bd_inode) >>SECTOR_SHIFT ; - aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors (q) -1 ); + aligned_capacity = dev->capacity & + ~((u64 )blk_queue_zone_sectors (q) -1 );
sector_t is an u64 only if CONFIG_LBDAF is defined (I think this option is going away though). Otherwise it is an unsigned long which would be u32 on 32 bits arch. Not a problem in terms of arithmetic, but why not cast to sector_t directly ?
Quoted 4 lines
drivers/md/dm-zoned-target.c +0
-0if (ti->begin || ((ti->len != dev->capacity) && (ti->len != aligned_capacity))) { ti->error ="Partial mapping not supported" ;
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v2] dm zoned: Silence a static checker warning
Quoted 28 lines · Damien Le Moal
Quoted 27 lines · Dan Carpenter
My static checker complains about this line from
dmz_get_zoned_device()aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);The problem is that "
aligned_capacity" and "dev->capacity" aresector_ttype (which is a u64) butblk_queue_zone_sectors(q)returns a u32 so the higher 32 bits in "aligned_capacity" are always cleared to zero. This patch adds a cast to u64 to address this issue.Fixes 114e025968b5 ("dm zoned: ignore last smaller runt zone")Signed-off-by Dan Carpenter <[email protected]>---
v2: In v1 I changedblk_queue_zone_sectors()to return asector_ttype, but in v2 I just add a cast. The v2 fix would end up going through different maintainers and reviewers so the CC list has grown...Original discussion: https://marc.info/?l=kernel-janitors&m=155487663405737&w=2
drivers/md/dm-zoned-target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/md/dm-zoned-target.c +0
-0@@ -643,7 +643,8 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path)
Quoted 10 lines
drivers/md/dm-zoned-target.c static int dmz_get_zoned_device(struct dm_target *ti, char *path) · line 647
Quoted 5 lines
drivers/md/dm-zoned-target.c +2
-1q =bdev_get_queue (dev->bdev); dev->capacity =i_size_read (dev->bdev->bd_inode) >>SECTOR_SHIFT ; - aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors (q) -1 ); + aligned_capacity = dev->capacity & + ~((u64 )blk_queue_zone_sectors (q) -1 );
sector_tis an u64 only ifCONFIG_LBDAFis defined (I think this option is going away though). Otherwise it is an unsigned long which would be u32 on 32 bits arch. Not a problem in terms of arithmetic, but why not cast tosector_tdirectly ?
I would have prefered to do that but I didn't have strong feelings either way. I am always slight annoyed when people don't just copy and paste my code when I tell them how to fix a patch so I decided to go with your version... :P
regards,
dan carpenter
Re: [dm-devel] [PATCH v2] dm zoned: Silence a static checker warning
Quoted 40 lines · Dan Carpenter
Quoted 28 lines · Damien Le Moal
Quoted 27 lines · Dan Carpenter
My static checker complains about this line from
dmz_get_zoned_device()aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);The problem is that "
aligned_capacity" and "dev->capacity" aresector_ttype (which is a u64) butblk_queue_zone_sectors(q)returns a u32 so the higher 32 bits in "aligned_capacity" are always cleared to zero. This patch adds a cast to u64 to address this issue.Fixes 114e025968b5 ("dm zoned: ignore last smaller runt zone")Signed-off-by Dan Carpenter <[email protected]>---
v2: In v1 I changedblk_queue_zone_sectors()to return asector_ttype, but in v2 I just add a cast. The v2 fix would end up going through different maintainers and reviewers so the CC list has grown...Original discussion: https://marc.info/?l=kernel-janitors&m=155487663405737&w=2
drivers/md/dm-zoned-target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/md/dm-zoned-target.c +0
-0@@ -643,7 +643,8 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path)Quoted 10 lines
drivers/md/dm-zoned-target.c static int dmz_get_zoned_device(struct dm_target *ti, char *path) · line 647
Quoted 5 lines
drivers/md/dm-zoned-target.c +2
-1q =bdev_get_queue (dev->bdev); dev->capacity =i_size_read (dev->bdev->bd_inode) >>SECTOR_SHIFT ; - aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors (q) -1 ); + aligned_capacity = dev->capacity & + ~((u64 )blk_queue_zone_sectors (q) -1 );
sector_tis an u64 only ifCONFIG_LBDAFis defined (I think this option is going away though). Otherwise it is an unsigned long which would be u32 on 32 bits arch. Not a problem in terms of arithmetic, but why not cast tosector_tdirectly ?
Quoted 4 lines
I would have prefered to do that but I didn't have strong feelings either way. I am always slight annoyed when people don't just copy and paste my code when I tell them how to fix a patch so I decided to go with your version... :P
I proposed u64 cast without checking sector_t definition. After doing that, I liked your sector_t cast more than my own misinformed proposal :)
Signature · 2 lines
Damien Le Moal Western Digital Research
PATCH v3 1/1 dm zoned: Silence a static checker warning
In reply to Damien Le MoalMy static checker complains about this line from dmz_get_zoned_device()
aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);
The problem is that "aligned_capacity" and "dev->capacity" are sector_t type (which is a u64 under most configs) but blk_queue_zone_sectors(q) returns a u32 so the higher 32 bits in aligned_capacity are cleared to zero. This patch adds a cast to address the issue.
---
v2: The v1 patch declared blk_queue_zone_sectors() as sector_t but the
v2 cast added a cast to u64.
v3: Cast it to sector_t instead
drivers/md/dm-zoned-target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-zoned-target.c +2 -1
@@ -643,7 +643,8 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path) q =bdev_get_queue (dev->bdev); dev->capacity =i_size_read (dev->bdev->bd_inode) >>SECTOR_SHIFT ; - aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors (q) -1 ); + aligned_capacity = dev->capacity & + ~((sector_t )blk_queue_zone_sectors (q) -1 );if (ti->begin || ((ti->len != dev->capacity) && (ti->len != aligned_capacity))) { ti->error ="Partial mapping not supported" ;
Signature · 1 line
2.17.1
Re: [PATCH v3] dm zoned: Silence a static checker warning
Quoted 25 lines · Dan Carpenter
My static checker complains about this line from
dmz_get_zoned_device()aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors(q) - 1);The problem is that "
aligned_capacity" and "dev->capacity" aresector_ttype (which is a u64 under most configs) butblk_queue_zone_sectors(q)returns a u32 so the higher 32 bits inaligned_capacityare cleared to zero. This patch adds a cast to address the issue.Fixes 114e025968b5 ("dm zoned: ignore last smaller runt zone")Signed-off-by Dan Carpenter <[email protected]>---
v2: The v1 patch declaredblk_queue_zone_sectors()assector_tbut the
v2 cast added a cast to u64.
v3: Cast it tosector_tinsteaddrivers/md/dm-zoned-target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/md/dm-zoned-target.c +0
-0
drivers/md/dm-zoned-target.c static int dmz_get_zoned_device(struct dm_target *ti, char *path) · line 650
Quoted 9 lines
drivers/md/dm-zoned-target.c +2
-1@@ -643,7 +643,8 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path) q =bdev_get_queue (dev->bdev); dev->capacity =i_size_read (dev->bdev->bd_inode) >>SECTOR_SHIFT ; - aligned_capacity = dev->capacity & ~(blk_queue_zone_sectors (q) -1 ); + aligned_capacity = dev->capacity & + ~((sector_t )blk_queue_zone_sectors (q) -1 );if (ti->begin || ((ti->len != dev->capacity) && (ti->len != aligned_capacity))) { ti->error ="Partial mapping not supported" ;
Thanks for fixing this !
Signature · 2 lines
Damien Le Moal Western Digital Research